From 70f0d2f423f32d6a7ef23e6d9b202d3355d2ddd4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 11 Dec 2012 13:37:02 +0000 Subject: [PATCH 001/248] Beginnings of a new ML API Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_project.py | 1 + scripts/mk_util.py | 36 +- scripts/update_api.py | 207 ++++++++++ src/api/ml/README | 3 + .../ml/{ => old}/add_error_checking.V3.sed | 0 src/api/ml/{ => old}/add_error_checking.sed | 0 src/api/ml/{ => old}/build-lib.cmd | 0 src/api/ml/{ => old}/build-lib.sh | 0 src/api/ml/{ => old}/build-test.cmd | 0 src/api/ml/{ => old}/build-test.sh | 0 src/api/ml/{ => old}/build.cmd | 0 src/api/ml/{ => old}/clean.cmd | 0 src/api/ml/{ => old}/cleantmp.cmd | 0 src/api/ml/{ => old}/compile_mlapi.cmd | 0 src/api/ml/{ => old}/error_handling.idl | 0 src/api/ml/{ => old}/exec.cmd | 0 src/api/ml/{ => old}/exec.sh | 0 src/api/ml/{ => old}/generate_mlapi.cmd | 0 src/api/ml/{ => old}/generate_mlapi.sh | 0 src/api/ml/{ => old}/import.cmd | 0 src/api/ml/{ => old}/mlx_get_app_args.idl | 0 src/api/ml/{ => old}/mlx_get_array_sort.idl | 0 .../ml/{ => old}/mlx_get_datatype_sort.idl | 0 src/api/ml/{ => old}/mlx_get_domains.idl | 0 src/api/ml/{ => old}/mlx_get_error_msg.idl | 0 .../ml/{ => old}/mlx_get_pattern_terms.idl | 0 src/api/ml/{ => old}/mlx_get_tuple_sort.idl | 0 src/api/ml/{ => old}/mlx_mk_context_x.idl | 0 src/api/ml/{ => old}/mlx_mk_datatypes.idl | 0 src/api/ml/{ => old}/mlx_mk_numeral.idl | 0 src/api/ml/{ => old}/mlx_mk_sort.idl | 0 src/api/ml/{ => old}/mlx_mk_symbol.idl | 0 src/api/ml/{ => old}/mlx_model.idl | 0 src/api/ml/{ => old}/mlx_numeral_refine.idl | 0 src/api/ml/{ => old}/mlx_parse_smtlib.idl | 0 src/api/ml/{ => old}/mlx_sort_refine.idl | 0 src/api/ml/{ => old}/mlx_statistics.idl | 0 src/api/ml/{ => old}/mlx_symbol_refine.idl | 0 src/api/ml/{ => old}/mlx_term_refine.idl | 0 src/api/ml/{ => old}/postprocess.sed | 0 src/api/ml/{ => old}/preprocess.sed | 0 src/api/ml/{ => old}/queen.ml | 0 src/api/ml/{ => old}/queen.regress.err | 0 src/api/ml/{ => old}/queen.regress.out | 0 src/api/ml/{ => old}/reverse.sed | 0 src/api/ml/{ => old}/test_mlapi.cmd | 0 src/api/ml/{ => old}/test_theory.ml | 0 src/api/ml/{ => old}/update-ml-doc.cmd | 0 src/api/ml/{ => old}/x3V3.ml | 0 src/api/ml/{ => old}/x3V3.mli | 0 src/api/ml/{ => old}/z3.0.idl | 0 src/api/ml/test_capi.regress.err | 5 - src/api/ml/test_capi.regress.out | 386 ------------------ src/api/ml/test_mlapi.regress.err | 0 src/api/ml/test_mlapi.regress.out | 32 -- src/api/ml/test_mlapiV3.regress.err | 5 - src/api/ml/test_mlapiV3.regress.out | 315 -------------- 57 files changed, 245 insertions(+), 745 deletions(-) create mode 100644 src/api/ml/README rename src/api/ml/{ => old}/add_error_checking.V3.sed (100%) rename src/api/ml/{ => old}/add_error_checking.sed (100%) rename src/api/ml/{ => old}/build-lib.cmd (100%) rename src/api/ml/{ => old}/build-lib.sh (100%) rename src/api/ml/{ => old}/build-test.cmd (100%) rename src/api/ml/{ => old}/build-test.sh (100%) rename src/api/ml/{ => old}/build.cmd (100%) rename src/api/ml/{ => old}/clean.cmd (100%) rename src/api/ml/{ => old}/cleantmp.cmd (100%) rename src/api/ml/{ => old}/compile_mlapi.cmd (100%) rename src/api/ml/{ => old}/error_handling.idl (100%) rename src/api/ml/{ => old}/exec.cmd (100%) rename src/api/ml/{ => old}/exec.sh (100%) rename src/api/ml/{ => old}/generate_mlapi.cmd (100%) rename src/api/ml/{ => old}/generate_mlapi.sh (100%) rename src/api/ml/{ => old}/import.cmd (100%) rename src/api/ml/{ => old}/mlx_get_app_args.idl (100%) rename src/api/ml/{ => old}/mlx_get_array_sort.idl (100%) rename src/api/ml/{ => old}/mlx_get_datatype_sort.idl (100%) rename src/api/ml/{ => old}/mlx_get_domains.idl (100%) rename src/api/ml/{ => old}/mlx_get_error_msg.idl (100%) rename src/api/ml/{ => old}/mlx_get_pattern_terms.idl (100%) rename src/api/ml/{ => old}/mlx_get_tuple_sort.idl (100%) rename src/api/ml/{ => old}/mlx_mk_context_x.idl (100%) rename src/api/ml/{ => old}/mlx_mk_datatypes.idl (100%) rename src/api/ml/{ => old}/mlx_mk_numeral.idl (100%) rename src/api/ml/{ => old}/mlx_mk_sort.idl (100%) rename src/api/ml/{ => old}/mlx_mk_symbol.idl (100%) rename src/api/ml/{ => old}/mlx_model.idl (100%) rename src/api/ml/{ => old}/mlx_numeral_refine.idl (100%) rename src/api/ml/{ => old}/mlx_parse_smtlib.idl (100%) rename src/api/ml/{ => old}/mlx_sort_refine.idl (100%) rename src/api/ml/{ => old}/mlx_statistics.idl (100%) rename src/api/ml/{ => old}/mlx_symbol_refine.idl (100%) rename src/api/ml/{ => old}/mlx_term_refine.idl (100%) rename src/api/ml/{ => old}/postprocess.sed (100%) rename src/api/ml/{ => old}/preprocess.sed (100%) rename src/api/ml/{ => old}/queen.ml (100%) rename src/api/ml/{ => old}/queen.regress.err (100%) rename src/api/ml/{ => old}/queen.regress.out (100%) rename src/api/ml/{ => old}/reverse.sed (100%) rename src/api/ml/{ => old}/test_mlapi.cmd (100%) rename src/api/ml/{ => old}/test_theory.ml (100%) rename src/api/ml/{ => old}/update-ml-doc.cmd (100%) rename src/api/ml/{ => old}/x3V3.ml (100%) rename src/api/ml/{ => old}/x3V3.mli (100%) rename src/api/ml/{ => old}/z3.0.idl (100%) delete mode 100644 src/api/ml/test_capi.regress.err delete mode 100644 src/api/ml/test_capi.regress.out delete mode 100644 src/api/ml/test_mlapi.regress.err delete mode 100644 src/api/ml/test_mlapi.regress.out delete mode 100644 src/api/ml/test_mlapiV3.regress.err delete mode 100644 src/api/ml/test_mlapiV3.regress.out diff --git a/scripts/mk_project.py b/scripts/mk_project.py index b30bba609..e2b003d21 100644 --- a/scripts/mk_project.py +++ b/scripts/mk_project.py @@ -87,6 +87,7 @@ def init_project_def(): export_files=API_files) add_dot_net_dll('dotnet', ['api_dll'], 'api/dotnet', dll_name='Microsoft.Z3', assembly_info_dir='Properties') add_java_dll('java', ['api_dll'], 'api/java', dll_name='libz3java', package_name="com.microsoft.z3", manifest_file='manifest') + add_ml_lib('ml', ['api_dll'], 'api/ml', lib_name='libz3ml') add_hlib('cpp', 'api/c++', includes2install=['z3++.h']) set_z3py_dir('api/python') # Examples diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 4641a7b1b..cb6b17cce 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -65,6 +65,7 @@ VS_PROJ = False TRACE = False DOTNET_ENABLED=False JAVA_ENABLED=False +ML_ENABLED=False STATIC_LIB=False VER_MAJOR=None VER_MINOR=None @@ -476,13 +477,13 @@ def display_help(exit_code): # Parse configuration option for mk_make script def parse_options(): global VERBOSE, DEBUG_MODE, IS_WINDOWS, VS_X64, ONLY_MAKEFILES, SHOW_CPPS, VS_PROJ, TRACE, VS_PAR, VS_PAR_NUM - global DOTNET_ENABLED, JAVA_ENABLED, STATIC_LIB, PREFIX, GMP, FOCI2, FOCI2LIB, PYTHON_PACKAGE_DIR, GPROF, GIT_HASH + global DOTNET_ENABLED, JAVA_ENABLED, ML_ENABLED, STATIC_LIB, PREFIX, GMP, FOCI2, FOCI2LIB, PYTHON_PACKAGE_DIR, GPROF, GIT_HASH try: options, remainder = getopt.gnu_getopt(sys.argv[1:], 'b:df:sxhmcvtnp:gj', ['build=', 'debug', 'silent', 'x64', 'help', 'makefiles', 'showcpp', 'vsproj', 'trace', 'nodotnet', 'staticlib', 'prefix=', 'gmp', 'foci2=', 'java', 'parallel=', 'gprof', - 'githash=']) + 'githash=', 'ml']) except: print("ERROR: Invalid command line option") display_help(1) @@ -535,6 +536,8 @@ def parse_options(): GPROF = True elif opt == '--githash': GIT_HASH=arg + elif opt in ('', '--ml'): + ML_ENABLED = True else: print("ERROR: Invalid command line option '%s'" % opt) display_help(1) @@ -621,6 +624,9 @@ def is_verbose(): def is_java_enabled(): return JAVA_ENABLED +def is_ml_enabled(): + return ML_ENABLED + def is_compiler(given, expected): """ Return True if the 'given' compiler is the expected one. @@ -1268,6 +1274,26 @@ class JavaDLLComponent(Component): shutil.copy(os.path.join(build_path, 'libz3java.%s' % so), os.path.join(dist_path, 'bin', 'libz3java.%s' % so)) +class MLComponent(Component): + def __init__(self, name, lib_name, path, deps): + Component.__init__(self, name, path, deps) + if lib_name == None: + lib_name = name + self.lib_name = lib_name + + def mk_makefile(self, out): + if is_ml_enabled(): + mk_dir(os.path.join(BUILD_DIR, 'api', 'ml')) + libfile = '%s$(LIB_EXT)' % self.lib_name + out.write('%s: libz3$(SO_EXT) %s\n' % (libfile, os.path.join(self.to_src_dir, 'z3_native.c'))) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) %s/z3_native.c\n' % self.to_src_dir) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'z3_native')) + out.write('ml: %s\n' % libfile) + out.write('\n') + + def main_component(self): + return is_ml_enabled() + class ExampleComponent(Component): def __init__(self, name, path): Component.__init__(self, name, path, []) @@ -1430,6 +1456,10 @@ def add_java_dll(name, deps=[], path=None, dll_name=None, package_name=None, man c = JavaDLLComponent(name, dll_name, package_name, manifest_file, path, deps) reg_component(name, c) +def add_ml_lib(name, deps=[], path=None, lib_name=None): + c = MLComponent(name, lib_name, path, deps) + reg_component(name, c) + def add_cpp_example(name, path=None): c = CppExampleComponent(name, path) reg_component(name, c) @@ -1513,6 +1543,7 @@ def mk_config(): # End of Windows VS config.mk if is_verbose(): print('64-bit: %s' % is64()) + print('ML API: %s' % is_ml_enabled()) if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) @@ -1631,6 +1662,7 @@ def mk_config(): if GPROF: print('gprof: enabled') print('Python version: %s' % distutils.sysconfig.get_python_version()) + print('ML API: %s' % is_ml_enabled()) if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) diff --git a/scripts/update_api.py b/scripts/update_api.py index 2fbf42cca..9ef0ce9a2 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -155,6 +155,10 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I STRING : 'jstring', STRING_PTR : 'jobject', BOOL : 'jboolean', SYMBOL : 'jlong', PRINT_MODE : 'jint', ERROR_CODE : 'jint'} +# Mapping to ML types +Type2ML = { VOID : 'void', VOID_PTR : 'long', INT : 'int', UINT : 'int', INT64 : 'long', UINT64 : 'long', DOUBLE : 'double', + STRING : 'char*', STRING_PTR : 'char**', + BOOL : 'boolean', SYMBOL : 'long', PRINT_MODE : 'int', ERROR_CODE : 'int' } next_type_id = FIRST_OBJ_ID @@ -205,6 +209,13 @@ def type2javaw(ty): else: return Type2JavaW[ty] +def type2ml(ty): + global Type2ML + if (ty >= FIRST_OBJ_ID): + return 'long' + else: + return Type2ML[ty] + def _in(ty): return (IN, ty); @@ -313,6 +324,24 @@ def param2pystr(p): else: return type2pystr(param_type(p)) +def param2ml(p): + k = param_kind(p) + if k == OUT: + if param_type(p) == INT or param_type(p) == UINT: + return "int*" + elif param_type(p) == INT64 or param_type(p) == UINT64 or param_type(p) >= FIRST_OBJ_ID: + return "long*" + elif param_type(p) == STRING: + return "char*" + else: + print "ERROR: unreachable code" + assert(False) + exit(1) + if k == IN_ARRAY or k == INOUT_ARRAY or k == OUT_ARRAY: + return "%s[]" % type2ml(param_type(p)) + else: + return type2ml(param_type(p)) + # Save name, result, params to generate wrapper _API2PY = [] @@ -1039,6 +1068,183 @@ def mk_bindings(): exe_c.write(" in.register_cmd(%s, exec_%s);\n" % (key, val)) exe_c.write("}\n") +def ml_method_name(name): + result = '' + name = name[3:] # Remove Z3_ + return result + +def mk_ml(): + if not is_ml_enabled(): + return + ml_dir = get_component('ml').src_dir + ml_nativef = os.path.join(ml_dir, 'z3_native.ml') + ml_wrapperf = os.path.join(ml_dir, 'z3_native.c') + ml_native = open(ml_nativef, 'w') + ml_native.write('// Automatically generated file\n') + ml_native.write('\n') + for name, result, params in _dotnet_decls: + ml_native.write(' external %s : (' % ml_method_name(name)) + first = True + i = 0; + for param in params: + if first: + first = False + else: + ml_native.write(', ') + ml_native.write('%s a%d' % (param2ml(param), i)) + i = i + 1 + ml_native.write('%s)\n' % (type2ml(result))) + # ml_native.write(' = "NATIVE_%s"' % ml_method_name(name)) + # ml_native.write('\n\n') + # # Exception wrappers + # for name, result, params in _dotnet_decls: + # java_native.write(' public static %s %s(' % (type2java(result), java_method_name(name))) + # first = True + # i = 0; + # for param in params: + # if first: + # first = False + # else: + # java_native.write(', ') + # java_native.write('%s a%d' % (param2java(param), i)) + # i = i + 1 + # java_native.write(')') + # if len(params) > 0 and param_type(params[0]) == CONTEXT: + # java_native.write(' throws Z3Exception') + # java_native.write('\n') + # java_native.write(' {\n') + # java_native.write(' ') + # if result != VOID: + # java_native.write('%s res = ' % type2java(result)) + # java_native.write('INTERNAL%s(' % (java_method_name(name))) + # first = True + # i = 0; + # for param in params: + # if first: + # first = False + # else: + # java_native.write(', ') + # java_native.write('a%d' % i) + # i = i + 1 + # java_native.write(');\n') + # if len(params) > 0 and param_type(params[0]) == CONTEXT: + # java_native.write(' Z3_error_code err = Z3_error_code.fromInt(INTERNALgetErrorCode(a0));\n') + # java_native.write(' if (err != Z3_error_code.Z3_OK)\n') + # java_native.write(' throw new Z3Exception(INTERNALgetErrorMsgEx(a0, err.toInt()));\n') + # if result != VOID: + # java_native.write(' return res;\n') + # java_native.write(' }\n\n') + # java_native.write('}\n') + ml_wrapper = open(ml_wrapperf, 'w') + ml_wrapper.write('// Automatically generated file\n\n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#ifdef Custom_tag\n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n') + ml_wrapper.write('#endif\n') + # for name, result, params in _dotnet_decls: + # java_wrapper.write('JNIEXPORT %s JNICALL Java_%s_Native_INTERNAL%s(JNIEnv * jenv, jclass cls' % (type2javaw(result), pkg_str, java_method_name(name))) + # i = 0; + # for param in params: + # java_wrapper.write(', ') + # java_wrapper.write('%s a%d' % (param2javaw(param), i)) + # i = i + 1 + # java_wrapper.write(') {\n') + # # preprocess arrays, strings, in/out arguments + # i = 0 + # for param in params: + # k = param_kind(param) + # if k == OUT or k == INOUT: + # java_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) + # elif k == IN_ARRAY or k == INOUT_ARRAY: + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i)) + # else: + # java_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i)) + # elif k == OUT_ARRAY: + # java_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)), + # i, + # type2str(param_type(param)), + # param_array_capacity_pos(param), + # type2str(param_type(param)))) + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) + # else: + # java_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i)) + # elif k == IN and param_type(param) == STRING: + # java_wrapper.write(' Z3_string _a%s = (Z3_string) jenv->GetStringUTFChars(a%s, NULL);\n' % (i, i)) + # i = i + 1 + # # invoke procedure + # java_wrapper.write(' ') + # if result != VOID: + # java_wrapper.write('%s result = ' % type2str(result)) + # java_wrapper.write('%s(' % name) + # i = 0 + # first = True + # for param in params: + # if first: + # first = False + # else: + # java_wrapper.write(', ') + # k = param_kind(param) + # if k == OUT or k == INOUT: + # java_wrapper.write('&_a%s' % i) + # elif k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: + # java_wrapper.write('_a%s' % i) + # elif k == IN and param_type(param) == STRING: + # java_wrapper.write('_a%s' % i) + # else: + # java_wrapper.write('(%s)a%i' % (param2str(param), i)) + # i = i + 1 + # java_wrapper.write(');\n') + # # cleanup + # i = 0 + # for param in params: + # k = param_kind(param) + # if k == OUT_ARRAY: + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) + # else: + # java_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i)) + # java_wrapper.write(' free(_a%s);\n' % i) + # elif k == IN_ARRAY or k == OUT_ARRAY: + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i)) + # else: + # java_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i)) + + # elif k == OUT or k == INOUT: + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' {\n') + # java_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) + # java_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "I");\n') + # java_wrapper.write(' jenv->SetIntField(a%s, fid, (jint) _a%s);\n' % (i, i)) + # java_wrapper.write(' }\n') + # else: + # java_wrapper.write(' {\n') + # java_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) + # java_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "J");\n') + # java_wrapper.write(' jenv->SetLongField(a%s, fid, (jlong) _a%s);\n' % (i, i)) + # java_wrapper.write(' }\n') + # i = i + 1 + # # return + # if result == STRING: + # java_wrapper.write(' return jenv->NewStringUTF(result);\n') + # elif result != VOID: + # java_wrapper.write(' return (%s) result;\n' % type2javaw(result)) + # java_wrapper.write('}\n') + # java_wrapper.write('#ifdef __cplusplus\n') + # java_wrapper.write('}\n') + # java_wrapper.write('#endif\n') + if is_verbose(): + print "Generated '%s'" % ml_nativef + # Collect API(...) commands from def def_APIs(): pat1 = re.compile(" *def_API.*") @@ -1063,6 +1269,7 @@ mk_py_wrappers() mk_dotnet() mk_dotnet_wrappers() mk_java() +mk_ml() log_h.close() log_c.close() diff --git a/src/api/ml/README b/src/api/ml/README new file mode 100644 index 000000000..925fced59 --- /dev/null +++ b/src/api/ml/README @@ -0,0 +1,3 @@ +This directory is work in progress. + +We are currently working on a brand new ML API. diff --git a/src/api/ml/add_error_checking.V3.sed b/src/api/ml/old/add_error_checking.V3.sed similarity index 100% rename from src/api/ml/add_error_checking.V3.sed rename to src/api/ml/old/add_error_checking.V3.sed diff --git a/src/api/ml/add_error_checking.sed b/src/api/ml/old/add_error_checking.sed similarity index 100% rename from src/api/ml/add_error_checking.sed rename to src/api/ml/old/add_error_checking.sed diff --git a/src/api/ml/build-lib.cmd b/src/api/ml/old/build-lib.cmd similarity index 100% rename from src/api/ml/build-lib.cmd rename to src/api/ml/old/build-lib.cmd diff --git a/src/api/ml/build-lib.sh b/src/api/ml/old/build-lib.sh similarity index 100% rename from src/api/ml/build-lib.sh rename to src/api/ml/old/build-lib.sh diff --git a/src/api/ml/build-test.cmd b/src/api/ml/old/build-test.cmd similarity index 100% rename from src/api/ml/build-test.cmd rename to src/api/ml/old/build-test.cmd diff --git a/src/api/ml/build-test.sh b/src/api/ml/old/build-test.sh similarity index 100% rename from src/api/ml/build-test.sh rename to src/api/ml/old/build-test.sh diff --git a/src/api/ml/build.cmd b/src/api/ml/old/build.cmd similarity index 100% rename from src/api/ml/build.cmd rename to src/api/ml/old/build.cmd diff --git a/src/api/ml/clean.cmd b/src/api/ml/old/clean.cmd similarity index 100% rename from src/api/ml/clean.cmd rename to src/api/ml/old/clean.cmd diff --git a/src/api/ml/cleantmp.cmd b/src/api/ml/old/cleantmp.cmd similarity index 100% rename from src/api/ml/cleantmp.cmd rename to src/api/ml/old/cleantmp.cmd diff --git a/src/api/ml/compile_mlapi.cmd b/src/api/ml/old/compile_mlapi.cmd similarity index 100% rename from src/api/ml/compile_mlapi.cmd rename to src/api/ml/old/compile_mlapi.cmd diff --git a/src/api/ml/error_handling.idl b/src/api/ml/old/error_handling.idl similarity index 100% rename from src/api/ml/error_handling.idl rename to src/api/ml/old/error_handling.idl diff --git a/src/api/ml/exec.cmd b/src/api/ml/old/exec.cmd similarity index 100% rename from src/api/ml/exec.cmd rename to src/api/ml/old/exec.cmd diff --git a/src/api/ml/exec.sh b/src/api/ml/old/exec.sh similarity index 100% rename from src/api/ml/exec.sh rename to src/api/ml/old/exec.sh diff --git a/src/api/ml/generate_mlapi.cmd b/src/api/ml/old/generate_mlapi.cmd similarity index 100% rename from src/api/ml/generate_mlapi.cmd rename to src/api/ml/old/generate_mlapi.cmd diff --git a/src/api/ml/generate_mlapi.sh b/src/api/ml/old/generate_mlapi.sh similarity index 100% rename from src/api/ml/generate_mlapi.sh rename to src/api/ml/old/generate_mlapi.sh diff --git a/src/api/ml/import.cmd b/src/api/ml/old/import.cmd similarity index 100% rename from src/api/ml/import.cmd rename to src/api/ml/old/import.cmd diff --git a/src/api/ml/mlx_get_app_args.idl b/src/api/ml/old/mlx_get_app_args.idl similarity index 100% rename from src/api/ml/mlx_get_app_args.idl rename to src/api/ml/old/mlx_get_app_args.idl diff --git a/src/api/ml/mlx_get_array_sort.idl b/src/api/ml/old/mlx_get_array_sort.idl similarity index 100% rename from src/api/ml/mlx_get_array_sort.idl rename to src/api/ml/old/mlx_get_array_sort.idl diff --git a/src/api/ml/mlx_get_datatype_sort.idl b/src/api/ml/old/mlx_get_datatype_sort.idl similarity index 100% rename from src/api/ml/mlx_get_datatype_sort.idl rename to src/api/ml/old/mlx_get_datatype_sort.idl diff --git a/src/api/ml/mlx_get_domains.idl b/src/api/ml/old/mlx_get_domains.idl similarity index 100% rename from src/api/ml/mlx_get_domains.idl rename to src/api/ml/old/mlx_get_domains.idl diff --git a/src/api/ml/mlx_get_error_msg.idl b/src/api/ml/old/mlx_get_error_msg.idl similarity index 100% rename from src/api/ml/mlx_get_error_msg.idl rename to src/api/ml/old/mlx_get_error_msg.idl diff --git a/src/api/ml/mlx_get_pattern_terms.idl b/src/api/ml/old/mlx_get_pattern_terms.idl similarity index 100% rename from src/api/ml/mlx_get_pattern_terms.idl rename to src/api/ml/old/mlx_get_pattern_terms.idl diff --git a/src/api/ml/mlx_get_tuple_sort.idl b/src/api/ml/old/mlx_get_tuple_sort.idl similarity index 100% rename from src/api/ml/mlx_get_tuple_sort.idl rename to src/api/ml/old/mlx_get_tuple_sort.idl diff --git a/src/api/ml/mlx_mk_context_x.idl b/src/api/ml/old/mlx_mk_context_x.idl similarity index 100% rename from src/api/ml/mlx_mk_context_x.idl rename to src/api/ml/old/mlx_mk_context_x.idl diff --git a/src/api/ml/mlx_mk_datatypes.idl b/src/api/ml/old/mlx_mk_datatypes.idl similarity index 100% rename from src/api/ml/mlx_mk_datatypes.idl rename to src/api/ml/old/mlx_mk_datatypes.idl diff --git a/src/api/ml/mlx_mk_numeral.idl b/src/api/ml/old/mlx_mk_numeral.idl similarity index 100% rename from src/api/ml/mlx_mk_numeral.idl rename to src/api/ml/old/mlx_mk_numeral.idl diff --git a/src/api/ml/mlx_mk_sort.idl b/src/api/ml/old/mlx_mk_sort.idl similarity index 100% rename from src/api/ml/mlx_mk_sort.idl rename to src/api/ml/old/mlx_mk_sort.idl diff --git a/src/api/ml/mlx_mk_symbol.idl b/src/api/ml/old/mlx_mk_symbol.idl similarity index 100% rename from src/api/ml/mlx_mk_symbol.idl rename to src/api/ml/old/mlx_mk_symbol.idl diff --git a/src/api/ml/mlx_model.idl b/src/api/ml/old/mlx_model.idl similarity index 100% rename from src/api/ml/mlx_model.idl rename to src/api/ml/old/mlx_model.idl diff --git a/src/api/ml/mlx_numeral_refine.idl b/src/api/ml/old/mlx_numeral_refine.idl similarity index 100% rename from src/api/ml/mlx_numeral_refine.idl rename to src/api/ml/old/mlx_numeral_refine.idl diff --git a/src/api/ml/mlx_parse_smtlib.idl b/src/api/ml/old/mlx_parse_smtlib.idl similarity index 100% rename from src/api/ml/mlx_parse_smtlib.idl rename to src/api/ml/old/mlx_parse_smtlib.idl diff --git a/src/api/ml/mlx_sort_refine.idl b/src/api/ml/old/mlx_sort_refine.idl similarity index 100% rename from src/api/ml/mlx_sort_refine.idl rename to src/api/ml/old/mlx_sort_refine.idl diff --git a/src/api/ml/mlx_statistics.idl b/src/api/ml/old/mlx_statistics.idl similarity index 100% rename from src/api/ml/mlx_statistics.idl rename to src/api/ml/old/mlx_statistics.idl diff --git a/src/api/ml/mlx_symbol_refine.idl b/src/api/ml/old/mlx_symbol_refine.idl similarity index 100% rename from src/api/ml/mlx_symbol_refine.idl rename to src/api/ml/old/mlx_symbol_refine.idl diff --git a/src/api/ml/mlx_term_refine.idl b/src/api/ml/old/mlx_term_refine.idl similarity index 100% rename from src/api/ml/mlx_term_refine.idl rename to src/api/ml/old/mlx_term_refine.idl diff --git a/src/api/ml/postprocess.sed b/src/api/ml/old/postprocess.sed similarity index 100% rename from src/api/ml/postprocess.sed rename to src/api/ml/old/postprocess.sed diff --git a/src/api/ml/preprocess.sed b/src/api/ml/old/preprocess.sed similarity index 100% rename from src/api/ml/preprocess.sed rename to src/api/ml/old/preprocess.sed diff --git a/src/api/ml/queen.ml b/src/api/ml/old/queen.ml similarity index 100% rename from src/api/ml/queen.ml rename to src/api/ml/old/queen.ml diff --git a/src/api/ml/queen.regress.err b/src/api/ml/old/queen.regress.err similarity index 100% rename from src/api/ml/queen.regress.err rename to src/api/ml/old/queen.regress.err diff --git a/src/api/ml/queen.regress.out b/src/api/ml/old/queen.regress.out similarity index 100% rename from src/api/ml/queen.regress.out rename to src/api/ml/old/queen.regress.out diff --git a/src/api/ml/reverse.sed b/src/api/ml/old/reverse.sed similarity index 100% rename from src/api/ml/reverse.sed rename to src/api/ml/old/reverse.sed diff --git a/src/api/ml/test_mlapi.cmd b/src/api/ml/old/test_mlapi.cmd similarity index 100% rename from src/api/ml/test_mlapi.cmd rename to src/api/ml/old/test_mlapi.cmd diff --git a/src/api/ml/test_theory.ml b/src/api/ml/old/test_theory.ml similarity index 100% rename from src/api/ml/test_theory.ml rename to src/api/ml/old/test_theory.ml diff --git a/src/api/ml/update-ml-doc.cmd b/src/api/ml/old/update-ml-doc.cmd similarity index 100% rename from src/api/ml/update-ml-doc.cmd rename to src/api/ml/old/update-ml-doc.cmd diff --git a/src/api/ml/x3V3.ml b/src/api/ml/old/x3V3.ml similarity index 100% rename from src/api/ml/x3V3.ml rename to src/api/ml/old/x3V3.ml diff --git a/src/api/ml/x3V3.mli b/src/api/ml/old/x3V3.mli similarity index 100% rename from src/api/ml/x3V3.mli rename to src/api/ml/old/x3V3.mli diff --git a/src/api/ml/z3.0.idl b/src/api/ml/old/z3.0.idl similarity index 100% rename from src/api/ml/z3.0.idl rename to src/api/ml/old/z3.0.idl diff --git a/src/api/ml/test_capi.regress.err b/src/api/ml/test_capi.regress.err deleted file mode 100644 index 0c383b409..000000000 --- a/src/api/ml/test_capi.regress.err +++ /dev/null @@ -1,5 +0,0 @@ -WARNING: invalid function application, sort mismatch on argument at position 1 -WARNING: (define iff Bool Bool Bool) applied to: -x of sort Int -y of sort Bool - diff --git a/src/api/ml/test_capi.regress.out b/src/api/ml/test_capi.regress.out deleted file mode 100644 index 48870057c..000000000 --- a/src/api/ml/test_capi.regress.out +++ /dev/null @@ -1,386 +0,0 @@ -Z3 4.2.0.0 - -simple_example -CONTEXT: -(solver)END OF CONTEXT - -DeMorgan -DeMorgan is valid - -find_model_example1 -model for: x xor y -sat -y -> false -x -> true - - -find_model_example2 -model for: x < y + 1, x > 2 -sat -y -> 3 -x -> 3 - -model for: x < y + 1, x > 2, not(x = y) -sat -y -> 4 -x -> 3 - - -prove_example1 -prove: x = y implies g(x) = g(y) -valid -disprove: x = y implies g(g(x)) = g(y) -invalid -counterexample: -y -> U!val!0 -x -> U!val!0 -g -> { - U!val!0 -> U!val!1 - U!val!1 -> U!val!2 - else -> U!val!1 -} - - -prove_example2 -prove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0 -valid -disprove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < -1 -invalid -counterexample: -z -> (- 1) -y -> (- 7719) -x -> (- 7719) -g -> { - (- 7719) -> 0 - 0 -> 2 - (- 1) -> 3 - else -> 0 -} - - -push_pop_example1 -assert: x >= 'big number' -push -number of scopes: 1 -assert: x <= 3 -unsat -pop -number of scopes: 0 -sat -x = 1000000000000000000000000000000000000000000000000000000:int -function interpretations: -assert: y > x -sat -y = 1000000000000000000000000000000000000000000000000000001:int -x = 1000000000000000000000000000000000000000000000000000000:int -function interpretations: - -quantifier_example1 -pattern: {(f #0 #1)} - -assert axiom: -(forall (k!0 Int) (k!1 Int) (= (inv!0 (f k!1 k!0)) k!0) :pat {(f k!1 k!0)}) -prove: f(x, y) = f(w, v) implies y = v -valid -disprove: f(x, y) = f(w, v) implies x = w -that is: not(f(x, y) = f(w, v) implies x = w) is satisfiable -unknown -potential model: -w = 2:int -v = 1:int -y = 1:int -x = 0:int -function interpretations: -f = {(else|->(define f!52 Int Int Int)[(define k!50 Int Int)[#unknown], (define k!51 Int Int)[#unknown]])} -#51 = {(2:int|->2:int), (1:int|->1:int), (15:int|->15:int), (11:int|->11:int), (0:int|->0:int), (19:int|->19:int), (else|->2:int)} -f!52 = {(0:int, 1:int|->3:int), (2:int, 1:int|->3:int), (0:int, 0:int|->4:int), (2:int, 0:int|->5:int), (6:int, 2:int|->7:int), (2:int, 2:int|->8:int), (0:int, 2:int|->9:int), (6:int, 0:int|->10:int), (0:int, 11:int|->12:int), (2:int, 11:int|->13:int), (6:int, 11:int|->14:int), (0:int, 15:int|->16:int), (2:int, 15:int|->17:int), (6:int, 15:int|->18:int), (0:int, 19:int|->20:int), (6:int, 19:int|->21:int), (2:int, 19:int|->22:int), (else|->3:int)} -inv!0 = {(3:int|->1:int), (4:int|->0:int), (5:int|->0:int), (7:int|->2:int), (8:int|->2:int), (9:int|->2:int), (10:int|->0:int), (12:int|->11:int), (13:int|->11:int), (14:int|->11:int), (16:int|->15:int), (17:int|->15:int), (18:int|->15:int), (20:int|->19:int), (21:int|->19:int), (22:int|->19:int), (else|->2:int)} -#50 = {(2:int|->2:int), (6:int|->6:int), (0:int|->0:int), (else|->2:int)} -reason for last failure: 7 (7 = quantifiers) - -array_example1 -prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3)) -(=> (= (store a1 i1 v1) (store a2 i2 v2)) - (or (= i1 i3) (= i2 i3) (= (select a1 i3) (select a2 i3)))) -valid - -array_example2 -n = 2 -(distinct k!0 k!1) -sat -#0 = (define as-array[k!0] (Array Bool Bool)) -#1 = (define as-array[k!1] (Array Bool Bool)) -function interpretations: -#0 = {((define false Bool)|->(define true Bool)), (else|->(define true Bool))} -#1 = {((define false Bool)|->(define false Bool)), (else|->(define false Bool))} -n = 3 -(distinct k!0 k!1 k!2) -sat -#0 = (define as-array[k!0] (Array Bool Bool)) -#1 = (define as-array[k!1] (Array Bool Bool)) -#2 = (define as-array[k!2] (Array Bool Bool)) -function interpretations: -#0 = {((define true Bool)|->(define true Bool)), ((define false Bool)|->(define false Bool)), (else|->(define true Bool))} -#1 = {((define false Bool)|->(define true Bool)), (else|->(define true Bool))} -#2 = {((define true Bool)|->(define false Bool)), ((define false Bool)|->(define false Bool)), (else|->(define false Bool))} -n = 4 -(distinct k!0 k!1 k!2 k!3) -sat -#0 = (define as-array[k!0] (Array Bool Bool)) -#1 = (define as-array[k!1] (Array Bool Bool)) -#2 = (define as-array[k!2] (Array Bool Bool)) -#3 = (define as-array[k!3] (Array Bool Bool)) -function interpretations: -#0 = {((define true Bool)|->(define false Bool)), ((define false Bool)|->(define true Bool)), (else|->(define false Bool))} -#1 = {((define true Bool)|->(define true Bool)), ((define false Bool)|->(define false Bool)), (else|->(define true Bool))} -#2 = {((define true Bool)|->(define true Bool)), ((define false Bool)|->(define true Bool)), (else|->(define true Bool))} -#3 = {((define true Bool)|->(define false Bool)), ((define false Bool)|->(define false Bool)), (else|->(define false Bool))} -n = 5 -(distinct k!0 k!1 k!2 k!3 k!4) -unsat - -array_example3 -domain: int -range: bool - -tuple_example1 -tuple_sort: (real, real) -prove: get_x(mk_pair(x, y)) = 1 implies x = 1 -valid -disprove: get_x(mk_pair(x, y)) = 1 implies y = 1 -invalid -counterexample: -y -> 0 -x -> 1 - -prove: get_x(p1) = get_x(p2) and get_y(p1) = get_y(p2) implies p1 = p2 -valid -disprove: get_x(p1) = get_x(p2) implies p1 = p2 -invalid -counterexample: -p1 -> (mk_pair 1 0) -p2 -> (mk_pair 1 2) - -prove: p2 = update(p1, 0, 10) implies get_x(p2) = 10 -valid -disprove: p2 = update(p1, 0, 10) implies get_y(p2) = 10 -invalid -counterexample: -p2 -> (mk_pair 10 1) -p1 -> (mk_pair 0 1) - - -bitvector_example1 -disprove: x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers -invalid -counterexample: -x -> bv2147483656[32] - - -bitvector_example2 -find values of x and y, such that x ^ y - 103 == x * y -sat -y -> bv3905735879[32] -x -> bv3787456528[32] - - -eval_example1 -MODEL: -y -> 4 -x -> 3 - -evaluating x+y -result = 7:int - -two_contexts_example1 -k!0 - -error_code_example1 -last call succeeded. -last call failed. - -error_code_example2 -before Z3_mk_iff -Z3 error: type error. - -parser_example1 -formula 0: (> x y) -formula 1: (> x 0) -sat -y -> 0 -x -> 1 - - -parser_example2 -formula: (> x y) -sat -y -> (- 1) -x -> 0 - - -parser_example3 -assert axiom: -(forall (x Int) (y Int) (= (g x y) (g y x)) :qid {k!1}) -formula: (forall (x Int) (y Int) (=> (= x y) (= (g x 0) (g 0 y))) :qid {k!1}) -valid - -parser_example4 -declaration 0: (define y Int) -declaration 1: (define sk_hack Bool Bool) -declaration 2: (define x Int) -assumption 0: (= x 20) -formula 0: (> x y) -formula 1: (> x 0) - -parser_example5 -Z3 error: parser error. -Error message: 'ERROR: line 1 column 41: could not find sort symbol 'y'. -'. - -numeral_example -Numerals n1:1/2 n2:1/2 -valid -Numerals n1:(- 1/3) n2:(- 33333333333333333333333333333333333333333333333333/100000000000000000000000000000000000000000000000000) -valid - -ite_example -term: (if false 1 0) - -list_example -valid -valid -valid -valid -valid -valid -valid -Formula (=> (is_cons u) (= u (cons (head u) (tail u)))) -valid -invalid -counterexample: -u -> nil - - -tree_example -valid -valid -valid -valid -valid -Formula (=> (is_cons u) (= u (cons (car u) (cdr u)))) -valid -invalid -counterexample: -u -> nil - - -forest_example -valid -valid -valid -valid -valid -valid - -binary_tree_example -valid -valid -valid -valid -valid - -enum_example -(define apple[fruit:0] fruit) -(define banana[fruit:1] fruit) -(define orange[fruit:2] fruit) -(define is_apple[fruit:0] fruit Bool) -(define is_banana[fruit:1] fruit Bool) -(define is_orange[fruit:2] fruit Bool) -valid -valid -invalid -counterexample: - -valid -valid - -unsat_core_and_proof_example -unsat -proof: [unit-resolution - [def-axiom (or (or (not PredA) PredB (not PredC)) (not PredB))] - [unit-resolution - [def-axiom (or (or (not PredA) (not PredB) (not PredC)) PredB)] - [unit-resolution - [mp - [asserted (or (and PredA PredB PredC) P1)] - [monotonicity - [rewrite - (iff (and PredA PredB PredC) - (not (or (not PredA) (not PredB) (not PredC))))] - (iff (or (and PredA PredB PredC) P1) - (or (not (or (not PredA) (not PredB) (not PredC))) P1))] - (or (not (or (not PredA) (not PredB) (not PredC))) P1)] - [asserted (not P1)] - (not (or (not PredA) (not PredB) (not PredC)))] - PredB] - [unit-resolution - [mp - [asserted (or (and PredA (not PredB) PredC) P2)] - [monotonicity - [rewrite - (iff (and PredA (not PredB) PredC) - (not (or (not PredA) PredB (not PredC))))] - (iff (or (and PredA (not PredB) PredC) P2) - (or (not (or (not PredA) PredB (not PredC))) P2))] - (or (not (or (not PredA) PredB (not PredC))) P2)] - [asserted (not P2)] - (not (or (not PredA) PredB (not PredC)))] - false] - -core: -(not P1) -(not P2) - - -get_implied_equalities example -Class a |-> 0 -Class b |-> 0 -Class c |-> 0 -Class d |-> 3 -Class (f a) |-> 0 -Class (f b) |-> 0 -Class (f c) |-> 0 -asserting f(a) <= b -Class a |-> 0 -Class b |-> 0 -Class c |-> 0 -Class d |-> 3 -Class (f a) |-> 0 -Class (f b) |-> 0 -Class (f c) |-> 0 - -incremental_example1 -unsat core: 0 2 3 -unsat -sat -unsat core: 0 2 3 -unsat -unsat core: 0 2 3 -unsat -sat - -reference_counter_example -model for: x xor y -sat -y -> false -x -> true - - -smt2parser_example -formulas: (and (bvuge a bv16[8]) (bvule a bv240[8])) - -substitute_example -substitution result: (f (f a 0) 1) - -substitute_vars_example -substitution result: (f (f a (g b)) a) diff --git a/src/api/ml/test_mlapi.regress.err b/src/api/ml/test_mlapi.regress.err deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/api/ml/test_mlapi.regress.out b/src/api/ml/test_mlapi.regress.out deleted file mode 100644 index 1fb6289c7..000000000 --- a/src/api/ml/test_mlapi.regress.out +++ /dev/null @@ -1,32 +0,0 @@ -datatype created: -sort: tree -constructor: (define leaf[tree:0] Int tree) recognizer: (define is_leaf[tree:0] tree Bool) accessors: (define data[tree:0:0] tree Int) -constructor: (define node[tree:1] forest tree) recognizer: (define is_node[tree:1] tree Bool) accessors: (define children[tree:1:0] tree forest) -sort: forest -constructor: (define nil[forest:0] forest) recognizer: (define is_nil[forest:0] forest Bool) accessors: -constructor: (define cons[forest:1] tree forest forest) recognizer: (define is_cons[forest:1] forest Bool) accessors: (define hd[forest:1:0] forest tree) (define tl[forest:1:1] forest forest) - -t1: (node (cons (leaf 1) (cons (leaf 2) nil))) -t2: (node (cons (node (cons (leaf 1) (cons (leaf 2) nil))) (cons (leaf 3) nil))) -t3: (node (cons (node (cons (leaf 1) (cons (leaf 2) nil))) - (cons (node (cons (leaf 1) (cons (leaf 2) nil))) nil))) -t4: (node (cons (leaf 4) (cons (node (cons (leaf 1) (cons (leaf 2) nil))) nil))) -f1: (cons (leaf 0) nil) -f2: (cons (node (cons (leaf 1) (cons (leaf 2) nil))) nil) -f3: (cons (node (cons (leaf 1) (cons (leaf 2) nil))) (cons (leaf 0) nil)) -t1: (node (cons (leaf 1) (cons (leaf 2) nil))) -t2: (node (cons (node (cons (leaf 1) (cons (leaf 2) nil))) (cons (leaf 3) nil))) -t3: (node (cons (node (cons (leaf 1) (cons (leaf 2) nil))) - (cons (node (cons (leaf 1) (cons (leaf 2) nil))) nil))) -t4: (node (cons (leaf 4) (cons (node (cons (leaf 1) (cons (leaf 2) nil))) nil))) -f1: (cons (leaf 0) nil) -f2: (cons (node (cons (leaf 1) (cons (leaf 2) nil))) nil) -f3: (cons (node (cons (leaf 1) (cons (leaf 2) nil))) (cons (leaf 0) nil)) -valid -valid -l1: (cons x u) -l2: (cons y v) -valid -valid -valid -valid diff --git a/src/api/ml/test_mlapiV3.regress.err b/src/api/ml/test_mlapiV3.regress.err deleted file mode 100644 index 0c383b409..000000000 --- a/src/api/ml/test_mlapiV3.regress.err +++ /dev/null @@ -1,5 +0,0 @@ -WARNING: invalid function application, sort mismatch on argument at position 1 -WARNING: (define iff Bool Bool Bool) applied to: -x of sort Int -y of sort Bool - diff --git a/src/api/ml/test_mlapiV3.regress.out b/src/api/ml/test_mlapiV3.regress.out deleted file mode 100644 index efcc4388d..000000000 --- a/src/api/ml/test_mlapiV3.regress.out +++ /dev/null @@ -1,315 +0,0 @@ -Z3 4.2.0.0 - -simple_example -CONTEXT: -(solver)END OF CONTEXT - -DeMorgan -DeMorgan is valid - -find_model_example1 -model for: x xor y -sat -y -> false -x -> true - - -find_model_example2 -model for: x < y + 1, x > 2 -sat -y -> 3 -x -> 3 - -model for: x < y + 1, x > 2, not(x = y) -sat -y -> 4 -x -> 3 - - -prove_example1 -prove: x = y implies g(x) = g(y) -valid -disprove: x = y implies g(g(x)) = g(y) -invalid -counterexample: -y -> U!val!0 -x -> U!val!0 -g -> { - U!val!0 -> U!val!1 - U!val!1 -> U!val!2 - else -> U!val!1 -} - - -prove_example2 -prove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0 -valid -disprove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < -1 -invalid -counterexample: -z -> (- 1) -y -> (- 7719) -x -> (- 7719) -g -> { - (- 7719) -> 0 - 0 -> 2 - (- 1) -> 3 - else -> 0 -} - - -push_pop_example1 -assert: x >= 'big number' -push -number of scopes: 1 -assert: x <= 3 -unsat -pop -number of scopes: 0 -sat -x = 1000000000000000000000000000000000000000000000000000000:int -function interpretations: -assert: y > x -sat -y = 1000000000000000000000000000000000000000000000000000001:int -x = 1000000000000000000000000000000000000000000000000000000:int -function interpretations: - -quantifier_example1 -pattern: {(f #0 #1)} - -assert axiom: -(forall (k!0 Int) (k!1 Int) (= (inv!0 (f k!1 k!0)) k!0) :pat {(f k!1 k!0)}) -prove: f(x, y) = f(w, v) implies y = v -valid -disprove: f(x, y) = f(w, v) implies x = w -that is: not(f(x, y) = f(w, v) implies x = w) is satisfiable -unknown -potential model: -w = 2:int -v = 1:int -y = 1:int -x = 0:int -function interpretations: -f = {(else|->(define f!52 Int Int Int)[(define k!50 Int Int)[#unknown], (define k!51 Int Int)[#unknown]])} -#51 = {(2:int|->2:int), (1:int|->1:int), (15:int|->15:int), (11:int|->11:int), (0:int|->0:int), (19:int|->19:int), (else|->2:int)} -f!52 = {(0:int, 1:int|->3:int), (2:int, 1:int|->3:int), (0:int, 0:int|->4:int), (2:int, 0:int|->5:int), (6:int, 2:int|->7:int), (2:int, 2:int|->8:int), (0:int, 2:int|->9:int), (6:int, 0:int|->10:int), (0:int, 11:int|->12:int), (2:int, 11:int|->13:int), (6:int, 11:int|->14:int), (0:int, 15:int|->16:int), (2:int, 15:int|->17:int), (6:int, 15:int|->18:int), (0:int, 19:int|->20:int), (6:int, 19:int|->21:int), (2:int, 19:int|->22:int), (else|->3:int)} -inv!0 = {(3:int|->1:int), (4:int|->0:int), (5:int|->0:int), (7:int|->2:int), (8:int|->2:int), (9:int|->2:int), (10:int|->0:int), (12:int|->11:int), (13:int|->11:int), (14:int|->11:int), (16:int|->15:int), (17:int|->15:int), (18:int|->15:int), (20:int|->19:int), (21:int|->19:int), (22:int|->19:int), (else|->2:int)} -#50 = {(2:int|->2:int), (6:int|->6:int), (0:int|->0:int), (else|->2:int)} -reason for last failure: 7 (7 = quantifiers) - -array_example1 -prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3)) -(=> (= (store a1 i1 v1) (store a2 i2 v2)) - (or (= i1 i3) (= i2 i3) (= (select a1 i3) (select a2 i3)))) -valid - -array_example2 -n = 2 -(distinct k!0 k!1) -sat -#0 = (define as-array[k!0] (Array Bool Bool)) -#1 = (define as-array[k!1] (Array Bool Bool)) -function interpretations: -#0 = {((define false Bool)|->(define true Bool)), (else|->(define true Bool))} -#1 = {((define false Bool)|->(define false Bool)), (else|->(define false Bool))} -n = 3 -(distinct k!0 k!1 k!2) -sat -#0 = (define as-array[k!0] (Array Bool Bool)) -#1 = (define as-array[k!1] (Array Bool Bool)) -#2 = (define as-array[k!2] (Array Bool Bool)) -function interpretations: -#0 = {((define true Bool)|->(define true Bool)), ((define false Bool)|->(define false Bool)), (else|->(define true Bool))} -#1 = {((define false Bool)|->(define true Bool)), (else|->(define true Bool))} -#2 = {((define true Bool)|->(define false Bool)), ((define false Bool)|->(define false Bool)), (else|->(define false Bool))} -n = 4 -(distinct k!0 k!1 k!2 k!3) -sat -#0 = (define as-array[k!0] (Array Bool Bool)) -#1 = (define as-array[k!1] (Array Bool Bool)) -#2 = (define as-array[k!2] (Array Bool Bool)) -#3 = (define as-array[k!3] (Array Bool Bool)) -function interpretations: -#0 = {((define true Bool)|->(define false Bool)), ((define false Bool)|->(define true Bool)), (else|->(define false Bool))} -#1 = {((define true Bool)|->(define true Bool)), ((define false Bool)|->(define false Bool)), (else|->(define true Bool))} -#2 = {((define true Bool)|->(define true Bool)), ((define false Bool)|->(define true Bool)), (else|->(define true Bool))} -#3 = {((define true Bool)|->(define false Bool)), ((define false Bool)|->(define false Bool)), (else|->(define false Bool))} -n = 5 -(distinct k!0 k!1 k!2 k!3 k!4) -unsat - -array_example3 -domain: int -range: bool - -tuple_example1 -tuple_sort: (real, real) -prove: get_x(mk_pair(x, y)) = 1 implies x = 1 -valid -disprove: get_x(mk_pair(x, y)) = 1 implies y = 1 -invalid -counterexample: -y -> 0 -x -> 1 - -prove: get_x(p1) = get_x(p2) and get_y(p1) = get_y(p2) implies p1 = p2 -valid -disprove: get_x(p1) = get_x(p2) implies p1 = p2 -invalid -counterexample: -p1 -> (mk_pair 1 0) -p2 -> (mk_pair 1 2) - -prove: p2 = update(p1, 0, 10) implies get_x(p2) = 10 -valid -disprove: p2 = update(p1, 0, 10) implies get_y(p2) = 10 -invalid -counterexample: -p2 -> (mk_pair 10 1) -p1 -> (mk_pair 0 1) - - -bitvector_example1 -disprove: x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers -invalid -counterexample: -x -> bv2147483656[32] - - -bitvector_example2 -find values of x and y, such that x ^ y - 103 == x * y -sat -y -> bv3905735879[32] -x -> bv3787456528[32] - - -eval_example1 -MODEL: -y -> 4 -x -> 3 - -evaluating x+y -result = 7:int - -two_contexts_example1 -k!0 - -error_code_example1 -last call succeeded. -last call failed. - -error_code_example2 -before Z3_mk_iff -Z3 error: type error. - -parser_example1 -formula 0: (> x y) -formula 1: (> x 0) -sat -y -> 0 -x -> 1 - - -parser_example2 -formula: (> x y) -sat -y -> (- 1) -x -> 0 - - -parser_example3 -assert axiom: -(forall (x Int) (y Int) (= (g x y) (g y x)) :qid {k!1}) -formula: (forall (x Int) (y Int) (=> (= x y) (= (g x 0) (g 0 y))) :qid {k!1}) -valid - -parser_example4 -declaration 0: (define y Int) -declaration 1: (define sk_hack Bool Bool) -declaration 2: (define x Int) -assumption 0: (= x 20) -formula 0: (> x y) -formula 1: (> x 0) - -parser_example5 -Z3 error: parser error. -Error message: 'ERROR: line 1 column 41: could not find sort symbol 'y'. -'. - -ite_example -term: (if false 1 0) - -enum_example -(define apple[fruit:0] fruit) -(define banana[fruit:1] fruit) -(define orange[fruit:2] fruit) -(define is_apple[fruit:0] fruit Bool) -(define is_banana[fruit:1] fruit Bool) -(define is_orange[fruit:2] fruit Bool) -valid -valid -invalid -counterexample: - -valid -valid - -unsat_core_and_proof_example -unsat -proof: [unit-resolution - [def-axiom (or (or (not PredA) PredC (not PredB)) (not PredC))] - [unit-resolution - [def-axiom (or (or (not PredA) (not PredB) (not PredC)) PredC)] - [unit-resolution - [mp - [asserted (or (and PredA PredB PredC) P1)] - [monotonicity - [rewrite - (iff (and PredA PredB PredC) - (not (or (not PredA) (not PredB) (not PredC))))] - (iff (or (and PredA PredB PredC) P1) - (or (not (or (not PredA) (not PredB) (not PredC))) P1))] - (or (not (or (not PredA) (not PredB) (not PredC))) P1)] - [asserted (not P1)] - (not (or (not PredA) (not PredB) (not PredC)))] - PredC] - [unit-resolution - [mp - [asserted (or (and PredA (not PredC) PredB) P2)] - [monotonicity - [rewrite - (iff (and PredA (not PredC) PredB) - (not (or (not PredA) PredC (not PredB))))] - (iff (or (and PredA (not PredC) PredB) P2) - (or (not (or (not PredA) PredC (not PredB))) P2))] - (or (not (or (not PredA) PredC (not PredB))) P2)] - [asserted (not P2)] - (not (or (not PredA) PredC (not PredB)))] - false] - -core: -(not P2) -(not P1) - - -abstract_example -formula: (> x y) -abstracted formula: (> #0 y) - -get_implied_equalities example -Class a |-> 0 -Class b |-> 0 -Class c |-> 0 -Class d |-> 3 -Class (f a) |-> 0 -Class (f b) |-> 0 -Class (f c) |-> 0 -asserting f(a) <= b -Class a |-> 0 -Class b |-> 0 -Class c |-> 0 -Class d |-> 3 -Class (f a) |-> 0 -Class (f b) |-> 0 -Class (f c) |-> 0 From 03a5c88dedfc148308c04be596adc56ed251d674 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 11 Dec 2012 15:07:33 +0000 Subject: [PATCH 002/248] More new ML API Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 3 + scripts/mk_util.py | 89 ++++++++++++++++++++++++++++++ scripts/update_api.py | 125 ++++++++++++++++++++++++------------------ 3 files changed, 164 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 65a69bf51..3c4fb1218 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,6 @@ src/api/java/enumerations/*.java *.bak doc/api doc/code +src/api/ml/z3_native.c +src/api/ml/z3_native.ml +src/api/ml/z3_enums.ml diff --git a/scripts/mk_util.py b/scripts/mk_util.py index cb6b17cce..8543f1ffa 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -49,6 +49,7 @@ UTIL_COMPONENT='util' API_COMPONENT='api' DOTNET_COMPONENT='dotnet' JAVA_COMPONENT='java' +ML_COMPONENT='ml' CPP_COMPONENT='cpp' ##################### IS_WINDOWS=False @@ -2230,6 +2231,8 @@ def mk_bindings(api_files): if is_java_enabled(): check_java() mk_z3consts_java(api_files) + if is_ml_enabled(): + mk_z3consts_ml(api_files) _execfile(os.path.join('scripts', 'update_api.py'), g) # HACK cp_z3py_to_build() @@ -2503,6 +2506,92 @@ def mk_z3consts_java(api_files): if VERBOSE: print("Generated '%s'" % ('%s' % gendir)) +# Extract enumeration types from z3_api.h, and add ML definitions +def mk_z3consts_ml(api_files): + blank_pat = re.compile("^ *$") + comment_pat = re.compile("^ *//.*$") + typedef_pat = re.compile("typedef enum *") + typedef2_pat = re.compile("typedef enum { *") + openbrace_pat = re.compile("{ *") + closebrace_pat = re.compile("}.*;") + + ml = get_component(ML_COMPONENT) + + DeprecatedEnums = [ 'Z3_search_failure' ] + gendir = ml.src_dir + if not os.path.exists(gendir): + os.mkdir(gendir) + + efile = open('%s.ml' % os.path.join(gendir, "z3_enums"), 'w') + efile.write('(* Automatically generated file *)\n\n') + # efile.write('module z3_enums = struct\n\n'); + + + for api_file in api_files: + api_file_c = ml.find_file(api_file, ml.name) + api_file = os.path.join(api_file_c.src_dir, api_file) + + api = open(api_file, 'r') + + SEARCHING = 0 + FOUND_ENUM = 1 + IN_ENUM = 2 + + mode = SEARCHING + decls = {} + idx = 0 + + linenum = 1 + for line in api: + m1 = blank_pat.match(line) + m2 = comment_pat.match(line) + if m1 or m2: + # skip blank lines and comments + linenum = linenum + 1 + elif mode == SEARCHING: + m = typedef_pat.match(line) + if m: + mode = FOUND_ENUM + m = typedef2_pat.match(line) + if m: + mode = IN_ENUM + decls = {} + idx = 0 + elif mode == FOUND_ENUM: + m = openbrace_pat.match(line) + if m: + mode = IN_ENUM + decls = {} + idx = 0 + else: + assert False, "Invalid %s, line: %s" % (api_file, linenum) + else: + assert mode == IN_ENUM + words = re.split('[^\-a-zA-Z0-9_]+', line) + m = closebrace_pat.match(line) + if m: + name = words[1] + if name not in DeprecatedEnums: + efile.write('\n(* %s *)\n' % name) + efile.write('type %s =\n' % name[3:]) # strip Z3_ + efile.write + for k, i in decls.iteritems(): + efile.write(' | %s \n' % k[3:]) # strip Z3_ + mode = SEARCHING + else: + if words[2] != '': + if len(words[2]) > 1 and words[2][1] == 'x': + idx = int(words[2], 16) + else: + idx = int(words[2]) + decls[words[1]] = idx + idx = idx + 1 + linenum = linenum + 1 + efile.write('\n') + # efile.write'end\n'); + if VERBOSE: + print "Generated '%s/z3_enums.ml'" % ('%s' % gendir) + def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index 9ef0ce9a2..1e86dc0ef 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -156,9 +156,9 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I BOOL : 'jboolean', SYMBOL : 'jlong', PRINT_MODE : 'jint', ERROR_CODE : 'jint'} # Mapping to ML types -Type2ML = { VOID : 'void', VOID_PTR : 'long', INT : 'int', UINT : 'int', INT64 : 'long', UINT64 : 'long', DOUBLE : 'double', - STRING : 'char*', STRING_PTR : 'char**', - BOOL : 'boolean', SYMBOL : 'long', PRINT_MODE : 'int', ERROR_CODE : 'int' } +Type2ML = { VOID : 'unit', VOID_PTR : 'long', INT : 'int', UINT : 'int', INT64 : 'long', UINT64 : 'long', DOUBLE : 'double', + STRING : 'string', STRING_PTR : 'char**', + BOOL : 'lbool', SYMBOL : 'symbol', PRINT_MODE : 'ast_print_mode', ERROR_CODE : 'error_code' } next_type_id = FIRST_OBJ_ID @@ -332,13 +332,13 @@ def param2ml(p): elif param_type(p) == INT64 or param_type(p) == UINT64 or param_type(p) >= FIRST_OBJ_ID: return "long*" elif param_type(p) == STRING: - return "char*" + return "string" else: print "ERROR: unreachable code" assert(False) exit(1) if k == IN_ARRAY or k == INOUT_ARRAY or k == OUT_ARRAY: - return "%s[]" % type2ml(param_type(p)) + return "%s array" % type2ml(param_type(p)) else: return type2ml(param_type(p)) @@ -1069,9 +1069,7 @@ def mk_bindings(): exe_c.write("}\n") def ml_method_name(name): - result = '' - name = name[3:] # Remove Z3_ - return result + return name[3:] # Remove Z3_ def mk_ml(): if not is_ml_enabled(): @@ -1080,10 +1078,57 @@ def mk_ml(): ml_nativef = os.path.join(ml_dir, 'z3_native.ml') ml_wrapperf = os.path.join(ml_dir, 'z3_native.c') ml_native = open(ml_nativef, 'w') - ml_native.write('// Automatically generated file\n') + ml_native.write('(* Automatically generated file *)\n') ml_native.write('\n') + ml_native.write('module Z3 = struct\n\n') + ml_native.write('type context\n') + ml_native.write('and symbol\n') + ml_native.write('and ast\n') + ml_native.write('and sort = private ast\n') + ml_native.write('and func_decl = private ast\n') + ml_native.write('and app = private ast\n') + ml_native.write('and pattern = private ast\n') + ml_native.write('and params\n') + ml_native.write('and param_descrs\n') + ml_native.write('and model\n') + ml_native.write('and func_interp\n') + ml_native.write('and func_entry\n') + ml_native.write('and fixedpoint\n') + ml_native.write('and ast_vector\n') + ml_native.write('and ast_map\n') + ml_native.write('and goal\n') + ml_native.write('and tactic\n') + ml_native.write('and probe\n') + ml_native.write('and apply_result\n') + ml_native.write('and solver\n') + ml_native.write('and stats\n') + ml_native.write('\n') + ml_native.write(' exception Z3Exception of string\n\n') for name, result, params in _dotnet_decls: - ml_native.write(' external %s : (' % ml_method_name(name)) + ml_native.write(' external native_%s : ' % ml_method_name(name)) + i = 0; + for param in params: + ml_native.write('%s -> ' % param2ml(param)) + i = i + 1 + ml_native.write('%s\n' % (type2ml(result))) + ml_native.write(' = "Native_Z3_%s"\n\n' % ml_method_name(name)) + # Exception wrappers + for name, result, params in _dotnet_decls: + ml_native.write(' let %s ' % ml_method_name(name)) + first = True + i = 0; + for param in params: + if first: + first = False; + else: + ml_native.write(' ') + ml_native.write('a%d' % i) + i = i + 1 + ml_native.write(' = \n') + ml_native.write(' ') + if result != VOID: + ml_native.write('let res = ') + ml_native.write('n_%s(' % (ml_method_name(name))) first = True i = 0; for param in params: @@ -1091,50 +1136,24 @@ def mk_ml(): first = False else: ml_native.write(', ') - ml_native.write('%s a%d' % (param2ml(param), i)) + ml_native.write('a%d' % i) i = i + 1 - ml_native.write('%s)\n' % (type2ml(result))) - # ml_native.write(' = "NATIVE_%s"' % ml_method_name(name)) - # ml_native.write('\n\n') - # # Exception wrappers - # for name, result, params in _dotnet_decls: - # java_native.write(' public static %s %s(' % (type2java(result), java_method_name(name))) - # first = True - # i = 0; - # for param in params: - # if first: - # first = False - # else: - # java_native.write(', ') - # java_native.write('%s a%d' % (param2java(param), i)) - # i = i + 1 - # java_native.write(')') - # if len(params) > 0 and param_type(params[0]) == CONTEXT: - # java_native.write(' throws Z3Exception') - # java_native.write('\n') - # java_native.write(' {\n') - # java_native.write(' ') - # if result != VOID: - # java_native.write('%s res = ' % type2java(result)) - # java_native.write('INTERNAL%s(' % (java_method_name(name))) - # first = True - # i = 0; - # for param in params: - # if first: - # first = False - # else: - # java_native.write(', ') - # java_native.write('a%d' % i) - # i = i + 1 - # java_native.write(');\n') - # if len(params) > 0 and param_type(params[0]) == CONTEXT: - # java_native.write(' Z3_error_code err = Z3_error_code.fromInt(INTERNALgetErrorCode(a0));\n') - # java_native.write(' if (err != Z3_error_code.Z3_OK)\n') - # java_native.write(' throw new Z3Exception(INTERNALgetErrorMsgEx(a0, err.toInt()));\n') - # if result != VOID: - # java_native.write(' return res;\n') - # java_native.write(' }\n\n') - # java_native.write('}\n') + ml_native.write(')') + if result != VOID: + ml_native.write(' in\n') + else: + ml_native.write(';\n') + if len(params) > 0 and param_type(params[0]) == CONTEXT: + ml_native.write(' let err = error_code.fromInt(n_get_error_code(a0)) in \n') + ml_native.write(' if err <> Z3_enums.OK then\n') + ml_native.write(' raise (z3_exception n_get_error_msg_ex(a0, err.toInt()))\n') + ml_native.write(' else\n') + if result == VOID: + ml_native.write(' ()\n') + else: + ml_native.write(' res\n') + ml_native.write('\n') + ml_native.write('\nend\n') ml_wrapper = open(ml_wrapperf, 'w') ml_wrapper.write('// Automatically generated file\n\n') ml_wrapper.write('#include \n') From f5a0520b838fa04ba5336daf35ffa268b670c6db Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 11 Dec 2012 16:35:39 +0000 Subject: [PATCH 003/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 3 + scripts/mk_util.py | 6 +- scripts/update_api.py | 211 +++++++++++++------------ src/api/ml/{ => old}/Makefile | 0 src/api/ml/{ => old}/Makefile.build | 0 src/api/ml/{ => old}/test_mlapi.ml | 0 src/api/ml/{ => old}/test_mlapiV3.ml | 0 src/api/ml/{ => old}/x3.ml | 0 src/api/ml/{ => old}/z3_stubs.c | 0 src/api/ml/{ => old}/z3_theory_stubs.c | 0 10 files changed, 120 insertions(+), 100 deletions(-) rename src/api/ml/{ => old}/Makefile (100%) rename src/api/ml/{ => old}/Makefile.build (100%) rename src/api/ml/{ => old}/test_mlapi.ml (100%) rename src/api/ml/{ => old}/test_mlapiV3.ml (100%) rename src/api/ml/{ => old}/x3.ml (100%) rename src/api/ml/{ => old}/z3_stubs.c (100%) rename src/api/ml/{ => old}/z3_theory_stubs.c (100%) diff --git a/.gitignore b/.gitignore index 3c4fb1218..f2a31c21e 100644 --- a/.gitignore +++ b/.gitignore @@ -64,9 +64,12 @@ src/util/version.h src/api/java/Native.cpp src/api/java/Native.java src/api/java/enumerations/*.java + *.bak doc/api doc/code src/api/ml/z3_native.c src/api/ml/z3_native.ml +src/api/ml/native.c +src/api/ml/Z3.ml src/api/ml/z3_enums.ml diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8543f1ffa..4249a04b0 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1286,9 +1286,9 @@ class MLComponent(Component): if is_ml_enabled(): mk_dir(os.path.join(BUILD_DIR, 'api', 'ml')) libfile = '%s$(LIB_EXT)' % self.lib_name - out.write('%s: libz3$(SO_EXT) %s\n' % (libfile, os.path.join(self.to_src_dir, 'z3_native.c'))) - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) %s/z3_native.c\n' % self.to_src_dir) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'z3_native')) + out.write('%s: libz3$(SO_EXT) %s\n' % (libfile, os.path.join(self.to_src_dir, 'native.c'))) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) -I%s %s/native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'native')) out.write('ml: %s\n' % libfile) out.write('\n') diff --git a/scripts/update_api.py b/scripts/update_api.py index 1e86dc0ef..9acdf1040 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1075,12 +1075,12 @@ def mk_ml(): if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir - ml_nativef = os.path.join(ml_dir, 'z3_native.ml') - ml_wrapperf = os.path.join(ml_dir, 'z3_native.c') + ml_nativef = os.path.join(ml_dir, 'Z3.ml') + ml_wrapperf = os.path.join(ml_dir, 'native.c') ml_native = open(ml_nativef, 'w') ml_native.write('(* Automatically generated file *)\n') ml_native.write('\n') - ml_native.write('module Z3 = struct\n\n') + ml_native.write('module Z3Native = struct\n\n') ml_native.write('type context\n') ml_native.write('and symbol\n') ml_native.write('and ast\n') @@ -1166,101 +1166,118 @@ def mk_ml(): ml_wrapper.write('#ifdef Custom_tag\n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') - ml_wrapper.write('#endif\n') - # for name, result, params in _dotnet_decls: - # java_wrapper.write('JNIEXPORT %s JNICALL Java_%s_Native_INTERNAL%s(JNIEnv * jenv, jclass cls' % (type2javaw(result), pkg_str, java_method_name(name))) - # i = 0; - # for param in params: - # java_wrapper.write(', ') - # java_wrapper.write('%s a%d' % (param2javaw(param), i)) - # i = i + 1 - # java_wrapper.write(') {\n') - # # preprocess arrays, strings, in/out arguments - # i = 0 - # for param in params: - # k = param_kind(param) - # if k == OUT or k == INOUT: - # java_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) - # elif k == IN_ARRAY or k == INOUT_ARRAY: - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i)) - # else: - # java_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i)) - # elif k == OUT_ARRAY: - # java_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)), - # i, - # type2str(param_type(param)), - # param_array_capacity_pos(param), - # type2str(param_type(param)))) - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) - # else: - # java_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i)) - # elif k == IN and param_type(param) == STRING: - # java_wrapper.write(' Z3_string _a%s = (Z3_string) jenv->GetStringUTFChars(a%s, NULL);\n' % (i, i)) - # i = i + 1 - # # invoke procedure - # java_wrapper.write(' ') - # if result != VOID: - # java_wrapper.write('%s result = ' % type2str(result)) - # java_wrapper.write('%s(' % name) - # i = 0 - # first = True - # for param in params: - # if first: - # first = False - # else: - # java_wrapper.write(', ') - # k = param_kind(param) - # if k == OUT or k == INOUT: - # java_wrapper.write('&_a%s' % i) - # elif k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: - # java_wrapper.write('_a%s' % i) - # elif k == IN and param_type(param) == STRING: - # java_wrapper.write('_a%s' % i) - # else: - # java_wrapper.write('(%s)a%i' % (param2str(param), i)) - # i = i + 1 - # java_wrapper.write(');\n') - # # cleanup - # i = 0 - # for param in params: - # k = param_kind(param) - # if k == OUT_ARRAY: - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) - # else: - # java_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i)) - # java_wrapper.write(' free(_a%s);\n' % i) - # elif k == IN_ARRAY or k == OUT_ARRAY: - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i)) - # else: - # java_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i)) + ml_wrapper.write('#endif\n\n') + ml_wrapper.write('#include \n\n') + for name, result, params in _dotnet_decls: + #return type = type2ml(result) + ml_wrapper.write('CAMLprim value n_%s(' % ml_method_name(name)) + first = True + i = 0 + for param in params: + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('value a%d' % i) + # param type = param2ml(param) + i = i + 1 + ml_wrapper.write(') {\n') + ml_wrapper.write(' CAMLparam%d(' % len(params)) + i = 0 + first = True + for param in params: + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('a%d' % i) + i = i + 1 + ml_wrapper.write(');\n') + # preprocess arrays, strings, in/out arguments + i = 0 + for param in params: + k = param_kind(param) + if k == OUT or k == INOUT: + ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) + elif k == IN_ARRAY or k == INOUT_ARRAY: + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i)) + else: + ml_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i)) + elif k == OUT_ARRAY: + ml_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)), + i, + type2str(param_type(param)), + param_array_capacity_pos(param), + type2str(param_type(param)))) + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) + else: + ml_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i)) + elif k == IN and param_type(param) == STRING: + ml_wrapper.write(' Z3_string _a%s = (Z3_string) String_val(a%s);\n' % (i, i)) + i = i + 1 + # invoke procedure + ml_wrapper.write(' ') + if result != VOID: + ml_wrapper.write('%s result = ' % type2str(result)) + ml_wrapper.write('%s(' % name) + i = 0 + first = True + for param in params: + if first: + first = False + else: + ml_wrapper.write(', ') + k = param_kind(param) + if k == OUT or k == INOUT: + ml_wrapper.write('&_a%s' % i) + elif k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: + ml_wrapper.write('_a%s' % i) + elif k == IN and param_type(param) == STRING: + ml_wrapper.write('_a%s' % i) + else: + ml_wrapper.write('(%s)a%i' % (param2str(param), i)) + i = i + 1 + ml_wrapper.write(');\n') + # cleanup + i = 0 + for param in params: + k = param_kind(param) + if k == OUT_ARRAY: + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) + else: + ml_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i)) + ml_wrapper.write(' free(_a%s);\n' % i) + elif k == IN_ARRAY or k == OUT_ARRAY: + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i)) + else: + ml_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i)) - # elif k == OUT or k == INOUT: - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' {\n') - # java_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) - # java_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "I");\n') - # java_wrapper.write(' jenv->SetIntField(a%s, fid, (jint) _a%s);\n' % (i, i)) - # java_wrapper.write(' }\n') - # else: - # java_wrapper.write(' {\n') - # java_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) - # java_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "J");\n') - # java_wrapper.write(' jenv->SetLongField(a%s, fid, (jlong) _a%s);\n' % (i, i)) - # java_wrapper.write(' }\n') - # i = i + 1 - # # return - # if result == STRING: - # java_wrapper.write(' return jenv->NewStringUTF(result);\n') - # elif result != VOID: - # java_wrapper.write(' return (%s) result;\n' % type2javaw(result)) - # java_wrapper.write('}\n') - # java_wrapper.write('#ifdef __cplusplus\n') - # java_wrapper.write('}\n') - # java_wrapper.write('#endif\n') + elif k == OUT or k == INOUT: + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' {\n') + ml_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) + ml_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "I");\n') + ml_wrapper.write(' jenv->SetIntField(a%s, fid, (jint) _a%s);\n' % (i, i)) + ml_wrapper.write(' }\n') + else: + ml_wrapper.write(' {\n') + ml_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) + ml_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "J");\n') + ml_wrapper.write(' jenv->SetLongField(a%s, fid, (jlong) _a%s);\n' % (i, i)) + ml_wrapper.write(' }\n') + i = i + 1 + # return + if result == STRING: + ml_wrapper.write(' return caml_copy_string(result);\n') + elif result == VOID: + ml_wrapper.write(' CAMLreturn(Val_unit);\n') + elif result != VOID: + ml_wrapper.write(' return (value) result;\n') + ml_wrapper.write('}\n\n') if is_verbose(): print "Generated '%s'" % ml_nativef diff --git a/src/api/ml/Makefile b/src/api/ml/old/Makefile similarity index 100% rename from src/api/ml/Makefile rename to src/api/ml/old/Makefile diff --git a/src/api/ml/Makefile.build b/src/api/ml/old/Makefile.build similarity index 100% rename from src/api/ml/Makefile.build rename to src/api/ml/old/Makefile.build diff --git a/src/api/ml/test_mlapi.ml b/src/api/ml/old/test_mlapi.ml similarity index 100% rename from src/api/ml/test_mlapi.ml rename to src/api/ml/old/test_mlapi.ml diff --git a/src/api/ml/test_mlapiV3.ml b/src/api/ml/old/test_mlapiV3.ml similarity index 100% rename from src/api/ml/test_mlapiV3.ml rename to src/api/ml/old/test_mlapiV3.ml diff --git a/src/api/ml/x3.ml b/src/api/ml/old/x3.ml similarity index 100% rename from src/api/ml/x3.ml rename to src/api/ml/old/x3.ml diff --git a/src/api/ml/z3_stubs.c b/src/api/ml/old/z3_stubs.c similarity index 100% rename from src/api/ml/z3_stubs.c rename to src/api/ml/old/z3_stubs.c diff --git a/src/api/ml/z3_theory_stubs.c b/src/api/ml/old/z3_theory_stubs.c similarity index 100% rename from src/api/ml/z3_theory_stubs.c rename to src/api/ml/old/z3_theory_stubs.c From 65ddf2be491719af481c93c6140a17271fa201e4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 11 Dec 2012 21:39:52 +0000 Subject: [PATCH 004/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 5 ++-- scripts/mk_util.py | 42 +++++++++++++++++++++--------- scripts/update_api.py | 59 +++++++++++++++++++++++-------------------- 3 files changed, 65 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index f2a31c21e..95c44e557 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ callgrind.out.* # OCaml generated files *.a *.cma +*.cmo *.cmi *.cmxa ocamlz3 @@ -71,5 +72,5 @@ doc/code src/api/ml/z3_native.c src/api/ml/z3_native.ml src/api/ml/native.c -src/api/ml/Z3.ml -src/api/ml/z3_enums.ml +src/api/ml/z3.ml +src/api/ml/enumerations.ml diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 4249a04b0..31e64b10e 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -672,6 +672,9 @@ def get_cs_files(path): def get_java_files(path): return filter(lambda f: f.endswith('.java'), os.listdir(path)) +def get_ml_files(path): + return filter(lambda f: f.endswith('.ml'), os.listdir(path)) + def find_all_deps(name, deps): new_deps = [] for dep in deps: @@ -1284,9 +1287,17 @@ class MLComponent(Component): def mk_makefile(self, out): if is_ml_enabled(): - mk_dir(os.path.join(BUILD_DIR, 'api', 'ml')) + bld_dir = os.path.join(BUILD_DIR, 'api', 'ml') + mk_dir(bld_dir) libfile = '%s$(LIB_EXT)' % self.lib_name - out.write('%s: libz3$(SO_EXT) %s\n' % (libfile, os.path.join(self.to_src_dir, 'native.c'))) + for mlfile in get_ml_files(self.src_dir): + out.write('%si: %s\n' % (os.path.join('api', 'ml', mlfile),os.path.join(self.to_src_dir, mlfile))) + out.write('\tocamlopt -I %s -i %s > %si\n' % (os.path.join('api', 'ml'), os.path.join(self.to_src_dir, mlfile), os.path.join('api', 'ml', mlfile))) + out.write('\tocamlopt -I %s -c %si \n' % (os.path.join('api', 'ml'), os.path.join('api','ml', mlfile))) + out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'native.c'))) + for mlfile in get_ml_files(self.src_dir): + out.write(' %si' % os.path.join('api','ml', mlfile)) + out.write('\n') out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) -I%s %s/native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'native')) out.write('ml: %s\n' % libfile) @@ -2522,11 +2533,9 @@ def mk_z3consts_ml(api_files): if not os.path.exists(gendir): os.mkdir(gendir) - efile = open('%s.ml' % os.path.join(gendir, "z3_enums"), 'w') + efile = open('%s.ml' % os.path.join(gendir, "enumerations"), 'w') efile.write('(* Automatically generated file *)\n\n') - # efile.write('module z3_enums = struct\n\n'); - - + efile.write('module Enumerations = struct\n') for api_file in api_files: api_file_c = ml.find_file(api_file, ml.name) api_file = os.path.join(api_file_c.src_dir, api_file) @@ -2572,11 +2581,21 @@ def mk_z3consts_ml(api_files): if m: name = words[1] if name not in DeprecatedEnums: - efile.write('\n(* %s *)\n' % name) efile.write('type %s =\n' % name[3:]) # strip Z3_ - efile.write for k, i in decls.iteritems(): - efile.write(' | %s \n' % k[3:]) # strip Z3_ + efile.write(' | %s \n' % k[3:]) # strip Z3_ + efile.write('\n') + efile.write('let %s2int x : int =\n' % (name[3:])) # strip Z3_ + efile.write(' match x with\n') + for k, i in decls.iteritems(): + efile.write(' | %s -> %d\n' % (k[3:], i)) + efile.write('\n') + efile.write('let int2%s x : %s =\n' % (name[3:],name[3:])) # strip Z3_ + efile.write(' match x with\n') + for k, i in decls.iteritems(): + efile.write(' | %d -> %s\n' % (i, k[3:])) + # use Z3.Exception? + efile.write(' | _ -> raise (Failure "undefined enum value")\n\n') mode = SEARCHING else: if words[2] != '': @@ -2587,10 +2606,9 @@ def mk_z3consts_ml(api_files): decls[words[1]] = idx idx = idx + 1 linenum = linenum + 1 - efile.write('\n') - # efile.write'end\n'); + efile.write('end\n') if VERBOSE: - print "Generated '%s/z3_enums.ml'" % ('%s' % gendir) + print "Generated '%s/enumerations.ml'" % ('%s' % gendir) def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index 9acdf1040..b8295405e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -156,9 +156,9 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I BOOL : 'jboolean', SYMBOL : 'jlong', PRINT_MODE : 'jint', ERROR_CODE : 'jint'} # Mapping to ML types -Type2ML = { VOID : 'unit', VOID_PTR : 'long', INT : 'int', UINT : 'int', INT64 : 'long', UINT64 : 'long', DOUBLE : 'double', - STRING : 'string', STRING_PTR : 'char**', - BOOL : 'lbool', SYMBOL : 'symbol', PRINT_MODE : 'ast_print_mode', ERROR_CODE : 'error_code' } +Type2ML = { VOID : 'unit', VOID_PTR : 'VOIDP', INT : 'int', UINT : 'int', INT64 : 'int', UINT64 : 'int', DOUBLE : 'float', + STRING : 'string', STRING_PTR : 'char**', + BOOL : 'int', SYMBOL : 'symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } next_type_id = FIRST_OBJ_ID @@ -212,7 +212,7 @@ def type2javaw(ty): def type2ml(ty): global Type2ML if (ty >= FIRST_OBJ_ID): - return 'long' + return 'int' else: return Type2ML[ty] @@ -328,9 +328,9 @@ def param2ml(p): k = param_kind(p) if k == OUT: if param_type(p) == INT or param_type(p) == UINT: - return "int*" + return "int" elif param_type(p) == INT64 or param_type(p) == UINT64 or param_type(p) >= FIRST_OBJ_ID: - return "long*" + return "int" elif param_type(p) == STRING: return "string" else: @@ -1075,12 +1075,12 @@ def mk_ml(): if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir - ml_nativef = os.path.join(ml_dir, 'Z3.ml') + ml_nativef = os.path.join(ml_dir, 'z3.ml') ml_wrapperf = os.path.join(ml_dir, 'native.c') ml_native = open(ml_nativef, 'w') - ml_native.write('(* Automatically generated file *)\n') - ml_native.write('\n') - ml_native.write('module Z3Native = struct\n\n') + ml_native.write('(* Automatically generated file *)\n\n') + ml_native.write('open Enumerations\n\n') + ml_native.write('module Z3 = struct\n\n') ml_native.write('type context\n') ml_native.write('and symbol\n') ml_native.write('and ast\n') @@ -1103,15 +1103,17 @@ def mk_ml(): ml_native.write('and solver\n') ml_native.write('and stats\n') ml_native.write('\n') - ml_native.write(' exception Z3Exception of string\n\n') + ml_native.write(' exception Exception of string\n\n') for name, result, params in _dotnet_decls: - ml_native.write(' external native_%s : ' % ml_method_name(name)) + ml_native.write(' external n_%s : ' % ml_method_name(name)) i = 0; for param in params: ml_native.write('%s -> ' % param2ml(param)) i = i + 1 + if len(params) == 0: + ml_native.write(' unit -> ') ml_native.write('%s\n' % (type2ml(result))) - ml_native.write(' = "Native_Z3_%s"\n\n' % ml_method_name(name)) + ml_native.write(' = "n_%s"\n\n' % ml_method_name(name)) # Exception wrappers for name, result, params in _dotnet_decls: ml_native.write(' let %s ' % ml_method_name(name)) @@ -1128,25 +1130,28 @@ def mk_ml(): ml_native.write(' ') if result != VOID: ml_native.write('let res = ') - ml_native.write('n_%s(' % (ml_method_name(name))) - first = True - i = 0; - for param in params: - if first: - first = False - else: - ml_native.write(', ') - ml_native.write('a%d' % i) - i = i + 1 - ml_native.write(')') + if len(params) == 0: + ml_native.write('n_%s()' % (ml_method_name(name))) + else: + ml_native.write('(n_%s ' % (ml_method_name(name))) + first = True + i = 0; + for param in params: + if first: + first = False + else: + ml_native.write(' ') + ml_native.write('a%d' % i) + i = i + 1 + ml_native.write(')') if result != VOID: ml_native.write(' in\n') else: ml_native.write(';\n') if len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = error_code.fromInt(n_get_error_code(a0)) in \n') - ml_native.write(' if err <> Z3_enums.OK then\n') - ml_native.write(' raise (z3_exception n_get_error_msg_ex(a0, err.toInt()))\n') + ml_native.write(' let err = (Enumerations.int2error_code (n_get_error_code a0)) in \n') + ml_native.write(' if err <> Enumerations.OK then\n') + ml_native.write(' raise (Exception (n_get_error_msg_ex a0 (error_code2int err)))\n') ml_native.write(' else\n') if result == VOID: ml_native.write(' ()\n') From 8d30fabc0a556ba3ef239958fcf37feb096a257e Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 04:34:36 +0000 Subject: [PATCH 005/248] New native ML API layer. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 35 ++-- scripts/update_api.py | 400 +++++++++++++++++++++++++++--------------- 2 files changed, 286 insertions(+), 149 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 31e64b10e..962f15670 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1287,20 +1287,31 @@ class MLComponent(Component): def mk_makefile(self, out): if is_ml_enabled(): + deffile = open('%s.mllib' % os.path.join(self.src_dir, "z3"), 'w') + for mlfile in get_ml_files(self.src_dir): + deffile.write('%s\n' % (string.upper(mlfile[0]) + mlfile[1:-3])) + deffile.close() + bld_dir = os.path.join(BUILD_DIR, 'api', 'ml') mk_dir(bld_dir) - libfile = '%s$(LIB_EXT)' % self.lib_name + libfile = '%s$(SO_EXT)' % self.lib_name + # for mlfile in get_ml_files(self.src_dir): + # out.write('%si: libz3$(SO_EXT) %s\n' % (os.path.join('api', 'ml', mlfile),os.path.join(self.to_src_dir, mlfile))) + # out.write('\tocamlopt -I %s -i %s > %si\n' % (os.path.join('api', 'ml'), os.path.join(self.to_src_dir, mlfile), os.path.join('api', 'ml', mlfile))) + # out.write('\tocamlopt -I %s -c %si \n' % (os.path.join('api', 'ml'), os.path.join('api','ml', mlfile))) + out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'z3native.c'))) for mlfile in get_ml_files(self.src_dir): - out.write('%si: %s\n' % (os.path.join('api', 'ml', mlfile),os.path.join(self.to_src_dir, mlfile))) - out.write('\tocamlopt -I %s -i %s > %si\n' % (os.path.join('api', 'ml'), os.path.join(self.to_src_dir, mlfile), os.path.join('api', 'ml', mlfile))) - out.write('\tocamlopt -I %s -c %si \n' % (os.path.join('api', 'ml'), os.path.join('api','ml', mlfile))) - out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'native.c'))) - for mlfile in get_ml_files(self.src_dir): - out.write(' %si' % os.path.join('api','ml', mlfile)) + out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) -I%s %s/native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'native')) - out.write('ml: %s\n' % libfile) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) + out.write('z3.cmxa: %s\n' % libfile) + out.write('\tcd %s && ocamlbuild -lflags -cclib,../../../%s/libz3ml.so,-cclib,../../../%s/libz3.so -build-dir ../../../%s/api/ml z3.cmxa && cd -\n' % (self.to_src_dir,BUILD_DIR,BUILD_DIR,BUILD_DIR)) + out.write('\tcp api/ml/z3.cmxa .\n') + out.write('z3.cma: %s\n' % libfile) + out.write('\tcd %s && ocamlbuild -lflags -custom,-cclib,../../../%s/libz3ml.so,-cclib,../../../%s/libz3.so -build-dir ../../../%s/api/ml z3.cma && cd -\n' % (self.to_src_dir,BUILD_DIR,BUILD_DIR,BUILD_DIR)) + out.write('\tcp api/ml/z3.cma .\n') + out.write('ml: z3.cmxa z3.cma\n') out.write('\n') def main_component(self): @@ -2533,9 +2544,9 @@ def mk_z3consts_ml(api_files): if not os.path.exists(gendir): os.mkdir(gendir) - efile = open('%s.ml' % os.path.join(gendir, "enumerations"), 'w') + efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') - efile.write('module Enumerations = struct\n') + efile.write('module Z3enums = struct\n') for api_file in api_files: api_file_c = ml.find_file(api_file, ml.name) api_file = os.path.join(api_file_c.src_dir, api_file) diff --git a/scripts/update_api.py b/scripts/update_api.py index b8295405e..b613ce79d 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1071,98 +1071,145 @@ def mk_bindings(): def ml_method_name(name): return name[3:] # Remove Z3_ +def is_out_param(p): + if param_kind(p) == OUT or param_kind(p) == INOUT or param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: + return True + else: + return False + +def outparams(params): + op = [] + for param in params: + if is_out_param(param): + op.append(param) + return op + +def is_in_param(p): + if param_kind(p) == IN or param_kind(p) == INOUT or param_kind(p) == IN_ARRAY or param_kind(p) == INOUT_ARRAY: + return True + else: + return False + +def inparams(params): + ip = [] + for param in params: + if is_in_param(param): + ip.append(param) + return ip + +def is_array_param(p): + if param_kind(p) == IN_ARRAY or param_kind(p) == INOUT_ARRAY or param_kind(p) == OUT_ARRAY: + return True + else: + return False + def mk_ml(): if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir - ml_nativef = os.path.join(ml_dir, 'z3.ml') - ml_wrapperf = os.path.join(ml_dir, 'native.c') + ml_nativef = os.path.join(ml_dir, 'z3native.ml') + ml_wrapperf = os.path.join(ml_dir, 'z3native.c') ml_native = open(ml_nativef, 'w') ml_native.write('(* Automatically generated file *)\n\n') - ml_native.write('open Enumerations\n\n') - ml_native.write('module Z3 = struct\n\n') - ml_native.write('type context\n') - ml_native.write('and symbol\n') - ml_native.write('and ast\n') - ml_native.write('and sort = private ast\n') - ml_native.write('and func_decl = private ast\n') - ml_native.write('and app = private ast\n') - ml_native.write('and pattern = private ast\n') - ml_native.write('and params\n') - ml_native.write('and param_descrs\n') - ml_native.write('and model\n') - ml_native.write('and func_interp\n') - ml_native.write('and func_entry\n') - ml_native.write('and fixedpoint\n') - ml_native.write('and ast_vector\n') - ml_native.write('and ast_map\n') - ml_native.write('and goal\n') - ml_native.write('and tactic\n') - ml_native.write('and probe\n') - ml_native.write('and apply_result\n') - ml_native.write('and solver\n') - ml_native.write('and stats\n') - ml_native.write('\n') + ml_native.write('open Z3enums\n\n') + ml_native.write('module Z3native = struct\n\n') + ml_native.write(' type context\n') + ml_native.write(' and symbol\n') + ml_native.write(' and ast\n') + ml_native.write(' and sort = private ast\n') + ml_native.write(' and func_decl = private ast\n') + ml_native.write(' and app = private ast\n') + ml_native.write(' and pattern = private ast\n') + ml_native.write(' and params\n') + ml_native.write(' and param_descrs\n') + ml_native.write(' and model\n') + ml_native.write(' and func_interp\n') + ml_native.write(' and func_entry\n') + ml_native.write(' and fixedpoint\n') + ml_native.write(' and ast_vector\n') + ml_native.write(' and ast_map\n') + ml_native.write(' and goal\n') + ml_native.write(' and tactic\n') + ml_native.write(' and probe\n') + ml_native.write(' and apply_result\n') + ml_native.write(' and solver\n') + ml_native.write(' and stats\n\n') ml_native.write(' exception Exception of string\n\n') + + # ML declarations + ml_native.write(' module ML2C = struct\n\n') for name, result, params in _dotnet_decls: - ml_native.write(' external n_%s : ' % ml_method_name(name)) - i = 0; - for param in params: - ml_native.write('%s -> ' % param2ml(param)) - i = i + 1 - if len(params) == 0: + ml_native.write(' external n_%s : ' % ml_method_name(name)) + ip = inparams(params) + op = outparams(params) + if len(ip) == 0: ml_native.write(' unit -> ') - ml_native.write('%s\n' % (type2ml(result))) - ml_native.write(' = "n_%s"\n\n' % ml_method_name(name)) + for p in ip: + ml_native.write('%s -> ' % param2ml(p)) + if len(op) > 0: + ml_native.write('(') + ml_native.write('%s' % type2ml(result)) + for p in op: + ml_native.write(' * %s' % param2ml(p)) + if len(op) > 0: + ml_native.write(')') + ml_native.write('\n') + ml_native.write(' = "n_%s"\n' % ml_method_name(name)) + if len(ip) > 5: + ml_native.write(' "n_%s_bytecode"\n' % ml_method_name(name)) + ml_native.write('\n') + ml_native.write(' end\n\n') + # Exception wrappers for name, result, params in _dotnet_decls: - ml_native.write(' let %s ' % ml_method_name(name)) + ip = inparams(params) + op = outparams(params) + ml_native.write(' let %s ' % ml_method_name(name)) first = True i = 0; - for param in params: - if first: - first = False; - else: - ml_native.write(' ') - ml_native.write('a%d' % i) - i = i + 1 - ml_native.write(' = \n') - ml_native.write(' ') - if result != VOID: - ml_native.write('let res = ') - if len(params) == 0: - ml_native.write('n_%s()' % (ml_method_name(name))) - else: - ml_native.write('(n_%s ' % (ml_method_name(name))) - first = True - i = 0; - for param in params: + for p in params: + if is_in_param(p): if first: - first = False + first = False; else: ml_native.write(' ') ml_native.write('a%d' % i) - i = i + 1 - ml_native.write(')') - if result != VOID: - ml_native.write(' in\n') + i = i + 1 + ml_native.write(' = \n') + ml_native.write(' ') + if result == VOID: + ml_native.write('let _ = ') else: - ml_native.write(';\n') + ml_native.write('let res = ') + ml_native.write('(ML2C.n_%s' % (ml_method_name(name))) + first = True + i = 0; + for p in params: + if is_in_param(p): + ml_native.write(' a%d' % i) + i = i + 1 + ml_native.write(') in\n') if len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = (Enumerations.int2error_code (n_get_error_code a0)) in \n') - ml_native.write(' if err <> Enumerations.OK then\n') - ml_native.write(' raise (Exception (n_get_error_msg_ex a0 (error_code2int err)))\n') + ml_native.write(' let err = (Z3enums.int2error_code (ML2C.n_get_error_code a0)) in \n') + ml_native.write(' if err <> Z3enums.OK then\n') + ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (Z3enums.error_code2int err)))\n') ml_native.write(' else\n') if result == VOID: ml_native.write(' ()\n') else: ml_native.write(' res\n') ml_native.write('\n') - ml_native.write('\nend\n') + + ml_native.write('end\n') + + # C interface ml_wrapper = open(ml_wrapperf, 'w') ml_wrapper.write('// Automatically generated file\n\n') ml_wrapper.write('#include \n') - ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n\n') + ml_wrapper.write('#ifdef __cplusplus\n') + ml_wrapper.write('extern "C" {\n') + ml_wrapper.write('#endif\n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') @@ -1171,61 +1218,119 @@ def mk_ml(): ml_wrapper.write('#ifdef Custom_tag\n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') + ml_wrapper.write('#endif\n') + ml_wrapper.write('#ifdef __cplusplus\n') + ml_wrapper.write('}\n') ml_wrapper.write('#endif\n\n') ml_wrapper.write('#include \n\n') + ml_wrapper.write('#define CAMLlocal6(X1,X2,X3,X4,X5,X6) \\\n') + ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLlocal1(X6); \n') + ml_wrapper.write('#define CAMLlocal7(X1,X2,X3,X4,X5,X6,X7) \\\n') + ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLlocal2(X6,X7); \n') + ml_wrapper.write('#define CAMLlocal8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') + ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLlocal3(X6,X7,X8); \n') + ml_wrapper.write('\n') + ml_wrapper.write('#define CAMLparam7(X1,X2,X3,X4,X5,X6,X7) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam2(X6,X7); \n') + ml_wrapper.write('#define CAMLparam8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam3(X6,X7,X8); \n') + ml_wrapper.write('#define CAMLparam9(X1,X2,X3,X4,X5,X6,X7,X8,X9) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam4(X6,X7,X8,X9); \n') + ml_wrapper.write('#define CAMLparam12(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') + ml_wrapper.write(' CAMLxparam2(X11,X12); \n') + ml_wrapper.write('#define CAMLparam13(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') + ml_wrapper.write(' CAMLxparam3(X11,X12,X13); \n') + ml_wrapper.write('\n\n') + ml_wrapper.write('#ifdef __cplusplus\n') + ml_wrapper.write('extern "C" {\n') + ml_wrapper.write('#endif\n\n') for name, result, params in _dotnet_decls: - #return type = type2ml(result) + ip = inparams(params) + op = outparams(params) + ret_size = len(op) + if result != VOID: + ret_size = ret_size + 1 + + # Setup frame + n_locals = 0 + for p in params: + if is_out_param(p) or (is_in_param(p) and param_type(p) == STRING): + n_locals = n_locals + 1 ml_wrapper.write('CAMLprim value n_%s(' % ml_method_name(name)) first = True i = 0 - for param in params: - if first: - first = False - else: - ml_wrapper.write(', ') - ml_wrapper.write('value a%d' % i) - # param type = param2ml(param) + for p in params: + if is_in_param(p): + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('value a%d' % i) i = i + 1 ml_wrapper.write(') {\n') - ml_wrapper.write(' CAMLparam%d(' % len(params)) + ml_wrapper.write(' CAMLparam%d(' % len(ip)) i = 0 first = True - for param in params: - if first: - first = False - else: - ml_wrapper.write(', ') - ml_wrapper.write('a%d' % i) + for p in params: + if is_in_param(p): + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('a%d' % i) i = i + 1 ml_wrapper.write(');\n') + i = 0 + first = True + if result != VOID: + n_locals = n_locals + 1 + if ret_size > 1: + n_locals = n_locals + 1 + if n_locals > 0: + ml_wrapper.write(' CAMLlocal%s(' % (n_locals)) + if ret_size > 1: + if result != VOID: + ml_wrapper.write('result, ') + ml_wrapper.write('result_tuple') + first = False + elif result != VOID: + ml_wrapper.write('result') + first = False + for p in params: + if is_out_param(p) or (is_in_param(p) and param_type(p) == STRING): + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('_a%s' % i) + i = i + 1 + ml_wrapper.write(');\n') + # preprocess arrays, strings, in/out arguments i = 0 for param in params: - k = param_kind(param) - if k == OUT or k == INOUT: - ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) - elif k == IN_ARRAY or k == INOUT_ARRAY: - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i)) - else: - ml_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i)) - elif k == OUT_ARRAY: - ml_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)), - i, - type2str(param_type(param)), - param_array_capacity_pos(param), - type2str(param_type(param)))) - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) - else: - ml_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i)) - elif k == IN and param_type(param) == STRING: - ml_wrapper.write(' Z3_string _a%s = (Z3_string) String_val(a%s);\n' % (i, i)) + if param_kind(param) == OUT_ARRAY: + ml_wrapper.write(' _a%s = (long) malloc(sizeof(%s) * ((long)a%s));\n' % (i, + type2str(param_type(param)), + param_array_capacity_pos(param))) + elif param_kind(param) == IN and param_type(param) == STRING: + ml_wrapper.write(' _a%s = (value) String_val(a%s);\n' % (i, i)) i = i + 1 + # invoke procedure ml_wrapper.write(' ') if result != VOID: - ml_wrapper.write('%s result = ' % type2str(result)) + ml_wrapper.write('result = (value) ') ml_wrapper.write('%s(' % name) i = 0 first = True @@ -1236,53 +1341,74 @@ def mk_ml(): ml_wrapper.write(', ') k = param_kind(param) if k == OUT or k == INOUT: - ml_wrapper.write('&_a%s' % i) - elif k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: - ml_wrapper.write('_a%s' % i) + ml_wrapper.write('(%s)&_a%s' % (param2str(param), i)) + elif k == INOUT_ARRAY or k == IN_ARRAY: + ml_wrapper.write('(%s*)a%s' % (type2str(param_type(param)), i)) + elif k == OUT_ARRAY: + ml_wrapper.write('(%s*)_a%s' % (type2str(param_type(param)), i)) elif k == IN and param_type(param) == STRING: - ml_wrapper.write('_a%s' % i) + ml_wrapper.write('(Z3_string) _a%s' % i) else: ml_wrapper.write('(%s)a%i' % (param2str(param), i)) i = i + 1 ml_wrapper.write(');\n') - # cleanup - i = 0 - for param in params: - k = param_kind(param) - if k == OUT_ARRAY: - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) - else: - ml_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i)) - ml_wrapper.write(' free(_a%s);\n' % i) - elif k == IN_ARRAY or k == OUT_ARRAY: - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i)) - else: - ml_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i)) - elif k == OUT or k == INOUT: - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' {\n') - ml_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) - ml_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "I");\n') - ml_wrapper.write(' jenv->SetIntField(a%s, fid, (jint) _a%s);\n' % (i, i)) - ml_wrapper.write(' }\n') + # return tuples + if len(op) > 0: + ml_wrapper.write(' result_tuple = caml_alloc(%s, 0);\n' % ret_size) + i = j = 0 + if result != VOID: + if result == STRING: + ml_wrapper.write(' Store_field(result_tuple, 0, caml_copy_string(result));\n') else: - ml_wrapper.write(' {\n') - ml_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) - ml_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "J");\n') - ml_wrapper.write(' jenv->SetLongField(a%s, fid, (jlong) _a%s);\n' % (i, i)) - ml_wrapper.write(' }\n') + ml_wrapper.write(' Store_field(result_tuple, 0, result);\n') + j = j + 1 + for p in params: + if param_kind(p) == OUT_ARRAY or param_kind(p) == OUT: + ml_wrapper.write(' Store_field(result_tuple, %s, _a%s);\n' % (j, i)) + j = j + 1; + elif is_out_param(p): + if param_type(p) == STRING: + ml_wrapper.write(' Store_field(result_tuple, %s, caml_copy_string((const char *)_a%s));\n' % (j, i)) + else: + ml_wrapper.write(' Store_field(result_tuple, %s, a%s);\n' % (j, i)) + j = j + 1; + i = i + 1 + + # local array cleanup + i = 0 + for p in params: + if param_kind(p) == OUT_ARRAY: + ml_wrapper.write(' free((long*)_a%s);\n' % i) i = i + 1 + # return - if result == STRING: - ml_wrapper.write(' return caml_copy_string(result);\n') - elif result == VOID: - ml_wrapper.write(' CAMLreturn(Val_unit);\n') - elif result != VOID: - ml_wrapper.write(' return (value) result;\n') + if len(op) > 0: + ml_wrapper.write(' CAMLreturn(result_tuple);\n') + else: + if result == STRING: + ml_wrapper.write(' CAMLreturn(caml_copy_string((const char*) result));\n') + elif result == VOID: + ml_wrapper.write(' CAMLreturn(Val_unit);\n') + elif result != VOID: + ml_wrapper.write(' CAMLreturn(result);\n') + ml_wrapper.write('}\n\n') + if len(ip) > 5: + ml_wrapper.write('CAMLprim value n_%s_bytecode(value * argv, int argn) {\n' % ml_method_name(name)) + ml_wrapper.write(' return n_%s(' % ml_method_name(name)) + i = 0 + while i < len(ip): + if i == 0: + ml_wrapper.write('argv[0]') + else: + ml_wrapper.write(', argv[%s]' % i) + i = i + 1 + ml_wrapper.write(');\n}\n') + ml_wrapper.write('\n\n') + ml_wrapper.write('#ifdef __cplusplus\n') + ml_wrapper.write('}\n') + ml_wrapper.write('#endif\n') if is_verbose(): print "Generated '%s'" % ml_nativef From d5f135c4325772297fd49e24b22a0984044c6eb4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 04:37:32 +0000 Subject: [PATCH 006/248] More new ML API. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 705f9a3e7..61ac503a0 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,3 +1,4 @@ +<<<<<<< HEAD (* File generated from z3.idl *) type context @@ -3383,3 +3384,16 @@ let set_new_relevant_callback th cb = end +======= +(* + Author: CM Wintersteiger + (C) Microsoft Research, 2012 +*) + +open Z3enums +open Z3native + +module Z3 = struct + +end +>>>>>>> More new ML API. From a965d65901ba6698f3ac13a8dbcb69d23f8b2610 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 04:37:46 +0000 Subject: [PATCH 007/248] ML API temp files added to .gitignore Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 95c44e557..fccf9424d 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,6 @@ src/util/version.h src/api/java/Native.cpp src/api/java/Native.java src/api/java/enumerations/*.java - *.bak doc/api doc/code @@ -74,3 +73,7 @@ src/api/ml/z3_native.ml src/api/ml/native.c src/api/ml/z3.ml src/api/ml/enumerations.ml +src/api/ml/z3native.c +src/api/ml/z3native.ml +src/api/ml/z3enums.ml +src/api/ml/z3.mllib From 2dde851ed7ec60719efb3290999d0fb41a45e3c8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 08:06:10 +0000 Subject: [PATCH 008/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 5 ++- scripts/update_api.py | 58 +++++++++---------------------- src/api/ml/z3.ml | 80 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 47 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 962f15670..c17df82e6 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -458,7 +458,8 @@ def display_help(exit_code): if IS_WINDOWS: print(" -n, --nodotnet do not generate Microsoft.Z3.dll make rules.") print(" -j, --java generate Java bindings.") - print(" --staticlib build Z3 static library.") + print(" --ml generate Ocaml bindinds.") + print(" --staticlib build Z3 static library.") if not IS_WINDOWS: print(" -g, --gmp use GMP.") print(" --gprof enable gprof") @@ -2546,7 +2547,6 @@ def mk_z3consts_ml(api_files): efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') - efile.write('module Z3enums = struct\n') for api_file in api_files: api_file_c = ml.find_file(api_file, ml.name) api_file = os.path.join(api_file_c.src_dir, api_file) @@ -2617,7 +2617,6 @@ def mk_z3consts_ml(api_files): decls[words[1]] = idx idx = idx + 1 linenum = linenum + 1 - efile.write('end\n') if VERBOSE: print "Generated '%s/enumerations.ml'" % ('%s' % gendir) diff --git a/scripts/update_api.py b/scripts/update_api.py index b613ce79d..9eb7d1405 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -158,7 +158,7 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I # Mapping to ML types Type2ML = { VOID : 'unit', VOID_PTR : 'VOIDP', INT : 'int', UINT : 'int', INT64 : 'int', UINT64 : 'int', DOUBLE : 'float', STRING : 'string', STRING_PTR : 'char**', - BOOL : 'int', SYMBOL : 'symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } + BOOL : 'int', SYMBOL : 'z3_symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } next_type_id = FIRST_OBJ_ID @@ -182,6 +182,7 @@ def def_Types(): v = Type2Str[k] if is_obj(k): Type2Dotnet[k] = v + Type2ML[k] = v.lower() def type2str(ty): global Type2Str @@ -211,10 +212,7 @@ def type2javaw(ty): def type2ml(ty): global Type2ML - if (ty >= FIRST_OBJ_ID): - return 'int' - else: - return Type2ML[ty] + return Type2ML[ty] def _in(ty): return (IN, ty); @@ -327,17 +325,11 @@ def param2pystr(p): def param2ml(p): k = param_kind(p) if k == OUT: - if param_type(p) == INT or param_type(p) == UINT: - return "int" - elif param_type(p) == INT64 or param_type(p) == UINT64 or param_type(p) >= FIRST_OBJ_ID: - return "int" - elif param_type(p) == STRING: + if param_type(p) == STRING: return "string" else: - print "ERROR: unreachable code" - assert(False) - exit(1) - if k == IN_ARRAY or k == INOUT_ARRAY or k == OUT_ARRAY: + return "ptr" + elif k == IN_ARRAY or k == INOUT_ARRAY or k == OUT_ARRAY: return "%s array" % type2ml(param_type(p)) else: return type2ml(param_type(p)) @@ -1104,6 +1096,7 @@ def is_array_param(p): return False def mk_ml(): + global Type2Str if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir @@ -1112,29 +1105,12 @@ def mk_ml(): ml_native = open(ml_nativef, 'w') ml_native.write('(* Automatically generated file *)\n\n') ml_native.write('open Z3enums\n\n') - ml_native.write('module Z3native = struct\n\n') - ml_native.write(' type context\n') - ml_native.write(' and symbol\n') - ml_native.write(' and ast\n') - ml_native.write(' and sort = private ast\n') - ml_native.write(' and func_decl = private ast\n') - ml_native.write(' and app = private ast\n') - ml_native.write(' and pattern = private ast\n') - ml_native.write(' and params\n') - ml_native.write(' and param_descrs\n') - ml_native.write(' and model\n') - ml_native.write(' and func_interp\n') - ml_native.write(' and func_entry\n') - ml_native.write(' and fixedpoint\n') - ml_native.write(' and ast_vector\n') - ml_native.write(' and ast_map\n') - ml_native.write(' and goal\n') - ml_native.write(' and tactic\n') - ml_native.write(' and probe\n') - ml_native.write(' and apply_result\n') - ml_native.write(' and solver\n') - ml_native.write(' and stats\n\n') - ml_native.write(' exception Exception of string\n\n') + ml_native.write('type ptr\n') + ml_native.write('and z3_symbol = ptr\n') + for k, v in Type2Str.iteritems(): + if is_obj(k): + ml_native.write('and %s = ptr\n' % v.lower()) + ml_native.write('\nexception Exception of string\n\n') # ML declarations ml_native.write(' module ML2C = struct\n\n') @@ -1190,9 +1166,9 @@ def mk_ml(): i = i + 1 ml_native.write(') in\n') if len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = (Z3enums.int2error_code (ML2C.n_get_error_code a0)) in \n') - ml_native.write(' if err <> Z3enums.OK then\n') - ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (Z3enums.error_code2int err)))\n') + ml_native.write(' let err = (int2error_code (ML2C.n_get_error_code a0)) in \n') + ml_native.write(' if err <> OK then\n') + ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (error_code2int err)))\n') ml_native.write(' else\n') if result == VOID: ml_native.write(' ()\n') @@ -1200,8 +1176,6 @@ def mk_ml(): ml_native.write(' res\n') ml_native.write('\n') - ml_native.write('end\n') - # C interface ml_wrapper = open(ml_wrapperf, 'w') ml_wrapper.write('// Automatically generated file\n\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 61ac503a0..b00569da1 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -3388,12 +3388,88 @@ end (* Author: CM Wintersteiger (C) Microsoft Research, 2012 -*) + *) open Z3enums open Z3native -module Z3 = struct +class context = + object (self) + val m_n_ctx : Z3native.z3_context option = None + val mutable m_refCount : int = 0 + initializer Gc.finalise (fun self -> self#dispose ()) self + method dispose () = + Printf.printf "Disposing %d \n" (Oo.id self) ; + match m_n_ctx with + | Some(x) -> (del_context x) + | None -> () + method sub_one_ctx_obj = m_refCount <- m_refCount - 1 + method add_one_ctx_obj = m_refCount <- m_refCount + 1 + end +class virtual z3object ctx_init obj_init = + object (self) + val mutable m_ctx : context option = ctx_init + val mutable m_n_obj : Z3native.ptr option = obj_init + + initializer + (match m_n_obj with + | Some (x) -> self#incref x; + (match m_ctx with + | Some(x) -> x#add_one_ctx_obj + | None -> () + ) + | None -> () + ); + Gc.finalise (fun self -> self#dispose ()) self + + method virtual incref : Z3native.ptr -> unit + method virtual decref : Z3native.ptr -> unit + + (* + Disposes of the underlying native Z3 object. + *) + method dispose () = + Printf.printf "Disposing %d \n" (Oo.id self) ; + (match m_n_obj with + | Some (x) -> self#decref x; m_n_obj <- None + | None -> () + ); + (match m_ctx with + | Some (x) -> x#sub_one_ctx_obj + | None -> () + ); + m_ctx <- None + + + method get_native_object = m_n_obj + + method set_native_object x = + (match x with + | Some(x) -> self#incref x + | None -> () + ); + (match m_n_obj with + | Some(x) -> self#decref x + | None -> () + ); + m_n_obj <- x + + method get_context = m_ctx + + method array_to_native a = + let f e = e#get_native_object in + (Array.map f a) + + method array_length a = + match a with + | Some(x) -> (Array.length x) + | None -> 0 + + end + +<<<<<<< HEAD end >>>>>>> More new ML API. +======= +>>>>>>> More ML API From bea09539cfe19f58bf4c09dc33747fad3d5f2d23 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 16:33:51 +0000 Subject: [PATCH 009/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- examples/ml/MLExample.ml | 12 ++++++++ examples/ml/README | 14 ++++++++++ scripts/mk_project.py | 1 + scripts/mk_util.py | 22 +++++++++++++++ src/api/ml/z3.ml | 59 ++++++++++++++++++++++++++++++++-------- 5 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 examples/ml/MLExample.ml create mode 100644 examples/ml/README diff --git a/examples/ml/MLExample.ml b/examples/ml/MLExample.ml new file mode 100644 index 000000000..8cc248206 --- /dev/null +++ b/examples/ml/MLExample.ml @@ -0,0 +1,12 @@ +(* + Copyright (C) 2012 Microsoft Corporation + Author: CM Wintersteiger (cwinter) 2012-12-17 + *) + + open Z3 + + let _ = ignore(Log.open_ "z3.log") ; +let cfg = Some [("model", "true"); ("proof", "false")] in +let ctx = (new context cfg) in +ctx#dispose +;; diff --git a/examples/ml/README b/examples/ml/README new file mode 100644 index 000000000..a83400e99 --- /dev/null +++ b/examples/ml/README @@ -0,0 +1,14 @@ +### This is work-in-progress and does not work yet. + +Small example using the Z3 ML bindings. +To build the example execute + make examples +in the build directory. + +It will create MLExample in the build directory, +which can be run on Windows via +ocaml -I . MLExample + +On Linux and FreeBSD, we must use +?? + diff --git a/scripts/mk_project.py b/scripts/mk_project.py index e2b003d21..5bbc42da8 100644 --- a/scripts/mk_project.py +++ b/scripts/mk_project.py @@ -98,6 +98,7 @@ def init_project_def(): add_c_example('maxsat') add_dotnet_example('dotnet_example', 'dotnet') add_java_example('java_example', 'java') + add_ml_example('ml_example', 'ml') add_z3py_example('py_example', 'python') return API_files diff --git a/scripts/mk_util.py b/scripts/mk_util.py index c17df82e6..27913ab62 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1427,6 +1427,24 @@ class JavaExampleComponent(ExampleComponent): out.write(' -d .\n') out.write('_ex_%s: JavaExample.class\n\n' % (self.name)) +class MLExampleComponent(ExampleComponent): + def __init__(self, name, path): + ExampleComponent.__init__(self, name, path) + + def is_example(self): + return ML_ENABLED + + def mk_makefile(self, out): + if ML_ENABLED: + out.write('_ex_%s: z3.cmxa' % self.name) + deps = '' + for mlfile in get_ml_files(self.ex_dir): + out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) + if IS_WINDOWS: + deps = deps.replace('/', '\\') + out.write('%s\n' % deps) + out.write('\tcd %s && ocamlbuild -build-dir ../../%s -lib z3 MLExample.native && cd -\n\n' % (self.to_src_dir, BUILD_DIR)) + class PythonExampleComponent(ExampleComponent): def __init__(self, name, path): ExampleComponent.__init__(self, name, path) @@ -1500,6 +1518,10 @@ def add_java_example(name, path=None): c = JavaExampleComponent(name, path) reg_component(name, c) +def add_ml_example(name, path=None): + c = MLExampleComponent(name, path) + reg_component(name, c) + def add_z3py_example(name, path=None): c = PythonExampleComponent(name, path) reg_component(name, c) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index b00569da1..31c5aa342 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -3386,29 +3386,62 @@ end ======= (* - Author: CM Wintersteiger - (C) Microsoft Research, 2012 + Copyright (C) 2012 Microsoft Corporation + Author: CM Wintersteiger (cwinter) 2012-12-17 *) open Z3enums open Z3native -class context = +module Log = + struct + let m_is_open = false +(* CMW: "open" seems to be an invalid function name*) + let open_ fn = int2lbool(open_log fn) == L_TRUE + let close = (close_log) + let append s = (append_log s) + end + +class virtual idisposable = + object + method virtual dispose : unit + end + +class context settings = object (self) - val m_n_ctx : Z3native.z3_context option = None + inherit idisposable + val mutable m_n_ctx : Z3native.z3_context option = None val mutable m_refCount : int = 0 - initializer Gc.finalise (fun self -> self#dispose ()) self - method dispose () = - Printf.printf "Disposing %d \n" (Oo.id self) ; - match m_n_ctx with - | Some(x) -> (del_context x) - | None -> () + + initializer + let cfg = mk_config() in + (match settings with + | Some(x) -> + let f e = (set_param_value cfg (fst e) (snd e)) in + (List.iter f x) + | _ -> () + ) ; + m_n_ctx <- Some (mk_context_rc cfg) ; + del_config(cfg) ; + Gc.finalise (fun self -> self#dispose) self + + method dispose : unit = + if m_refCount == 0 then ( + Printf.printf "Disposing %d \n" (Oo.id self) ; + match m_n_ctx with + | Some(x) -> (del_context x) + | None -> () + ) else ( + (* re-queue for finalization? *) + ) + method sub_one_ctx_obj = m_refCount <- m_refCount - 1 method add_one_ctx_obj = m_refCount <- m_refCount + 1 end class virtual z3object ctx_init obj_init = object (self) + inherit idisposable val mutable m_ctx : context option = ctx_init val mutable m_n_obj : Z3native.ptr option = obj_init @@ -3421,7 +3454,7 @@ class virtual z3object ctx_init obj_init = ) | None -> () ); - Gc.finalise (fun self -> self#dispose ()) self + Gc.finalise (fun self -> self#dispose) self method virtual incref : Z3native.ptr -> unit method virtual decref : Z3native.ptr -> unit @@ -3429,7 +3462,7 @@ class virtual z3object ctx_init obj_init = (* Disposes of the underlying native Z3 object. *) - method dispose () = + method dispose = Printf.printf "Disposing %d \n" (Oo.id self) ; (match m_n_obj with | Some (x) -> self#decref x; m_n_obj <- None @@ -3457,6 +3490,7 @@ class virtual z3object ctx_init obj_init = method get_context = m_ctx +(* method array_to_native a = let f e = e#get_native_object in (Array.map f a) @@ -3465,6 +3499,7 @@ class virtual z3object ctx_init obj_init = match a with | Some(x) -> (Array.length x) | None -> 0 +*) end From 01dc79fcd44a03710c5b6e43284cdebd23b0aaa7 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 17:26:28 +0000 Subject: [PATCH 010/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 158 +++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 31c5aa342..fb8121c79 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -3388,120 +3388,120 @@ end (* Copyright (C) 2012 Microsoft Corporation Author: CM Wintersteiger (cwinter) 2012-12-17 - *) +*) open Z3enums open Z3native module Log = - struct - let m_is_open = false -(* CMW: "open" seems to be an invalid function name*) - let open_ fn = int2lbool(open_log fn) == L_TRUE - let close = (close_log) - let append s = (append_log s) - end - +struct + let m_is_open = false + (* CMW: "open" seems to be an invalid function name*) + let open_ fn = int2lbool(open_log fn) == L_TRUE + let close = (close_log) + let append s = (append_log s) +end + class virtual idisposable = - object - method virtual dispose : unit - end +object + method virtual dispose : unit +end class context settings = - object (self) - inherit idisposable - val mutable m_n_ctx : Z3native.z3_context option = None - val mutable m_refCount : int = 0 - - initializer - let cfg = mk_config() in - (match settings with - | Some(x) -> - let f e = (set_param_value cfg (fst e) (snd e)) in - (List.iter f x) - | _ -> () - ) ; - m_n_ctx <- Some (mk_context_rc cfg) ; - del_config(cfg) ; - Gc.finalise (fun self -> self#dispose) self - - method dispose : unit = - if m_refCount == 0 then ( - Printf.printf "Disposing %d \n" (Oo.id self) ; - match m_n_ctx with +object (self) + inherit idisposable + val mutable m_n_ctx : Z3native.z3_context option = None + val mutable m_refCount : int = 0 + + initializer + let cfg = mk_config() in + (match settings with + | Some(x) -> + let f e = (set_param_value cfg (fst e) (snd e)) in + (List.iter f x) + | _ -> () + ) ; + m_n_ctx <- Some (mk_context_rc cfg) ; + del_config(cfg) ; + Gc.finalise (fun self -> self#dispose) self + + method dispose : unit = + if m_refCount == 0 then ( + Printf.printf "Disposing %d \n" (Oo.id self) ; + match m_n_ctx with | Some(x) -> (del_context x) | None -> () - ) else ( - (* re-queue for finalization? *) - ) + ) else ( + (* re-queue for finalization? *) + ) - method sub_one_ctx_obj = m_refCount <- m_refCount - 1 - method add_one_ctx_obj = m_refCount <- m_refCount + 1 - end + method sub_one_ctx_obj = m_refCount <- m_refCount - 1 + method add_one_ctx_obj = m_refCount <- m_refCount + 1 +end class virtual z3object ctx_init obj_init = - object (self) - inherit idisposable - val mutable m_ctx : context option = ctx_init - val mutable m_n_obj : Z3native.ptr option = obj_init - - initializer - (match m_n_obj with +object (self) + inherit idisposable + val mutable m_ctx : context option = ctx_init + val mutable m_n_obj : Z3native.ptr option = obj_init + + initializer + (match m_n_obj with | Some (x) -> self#incref x; - (match m_ctx with + (match m_ctx with | Some(x) -> x#add_one_ctx_obj | None -> () - ) + ) | None -> () - ); - Gc.finalise (fun self -> self#dispose) self + ); + Gc.finalise (fun self -> self#dispose) self - method virtual incref : Z3native.ptr -> unit - method virtual decref : Z3native.ptr -> unit - - (* - Disposes of the underlying native Z3 object. - *) - method dispose = - Printf.printf "Disposing %d \n" (Oo.id self) ; - (match m_n_obj with + method virtual incref : Z3native.ptr -> unit + method virtual decref : Z3native.ptr -> unit + + (* + Disposes of the underlying native Z3 object. + *) + method dispose = + Printf.printf "Disposing %d \n" (Oo.id self) ; + (match m_n_obj with | Some (x) -> self#decref x; m_n_obj <- None | None -> () - ); - (match m_ctx with + ); + (match m_ctx with | Some (x) -> x#sub_one_ctx_obj | None -> () - ); - m_ctx <- None + ); + m_ctx <- None - method get_native_object = m_n_obj + method get_native_object = m_n_obj - method set_native_object x = - (match x with + method set_native_object x = + (match x with | Some(x) -> self#incref x | None -> () - ); - (match m_n_obj with + ); + (match m_n_obj with | Some(x) -> self#decref x | None -> () - ); - m_n_obj <- x + ); + m_n_obj <- x - method get_context = m_ctx + method get_context = m_ctx -(* + (* method array_to_native a = - let f e = e#get_native_object in - (Array.map f a) + let f e = e#get_native_object in + (Array.map f a) method array_length a = - match a with - | Some(x) -> (Array.length x) - | None -> 0 -*) + match a with + | Some(x) -> (Array.length x) + | None -> 0 + *) - end +end <<<<<<< HEAD end From e7e85dc7b4892f6a08c9f4ad56f55f342b0913f7 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 20:18:53 +0000 Subject: [PATCH 011/248] File renamed Signed-off-by: Christoph M. Wintersteiger --- examples/ml/{MLExample.ml => mlexample.ml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/ml/{MLExample.ml => mlexample.ml} (100%) diff --git a/examples/ml/MLExample.ml b/examples/ml/mlexample.ml similarity index 100% rename from examples/ml/MLExample.ml rename to examples/ml/mlexample.ml From c001da618826339103136692b90996f3b047dd4f Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 22:25:16 +0000 Subject: [PATCH 012/248] ML API and example compilation. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/README | 12 ++++++------ examples/ml/ml_example.ml | 14 ++++++++++++++ examples/ml/mlexample.ml | 12 ------------ scripts/mk_util.py | 33 ++++++++++++++++++--------------- src/api/ml/z3.ml | 2 +- 5 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 examples/ml/ml_example.ml delete mode 100644 examples/ml/mlexample.ml diff --git a/examples/ml/README b/examples/ml/README index a83400e99..3e1eb0d1c 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -5,10 +5,10 @@ To build the example execute make examples in the build directory. -It will create MLExample in the build directory, -which can be run on Windows via -ocaml -I . MLExample +It will create ml_example in the build directory, +which can be run in the build directory via +LD_LIBRARY_PATH=. ./ml_example +or +LD_LIBRARY_PATH=. ./ml_example.byte +for the byte-code version. -On Linux and FreeBSD, we must use -?? - diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml new file mode 100644 index 000000000..9c704e4d0 --- /dev/null +++ b/examples/ml/ml_example.ml @@ -0,0 +1,14 @@ +(* + Copyright (C) 2012 Microsoft Corporation + Author: CM Wintersteiger (cwinter) 2012-12-17 +*) + +open Z3 + +let _ = ignore(Log.open_ "z3.log") ; + let cfg = Some [("model", "true"); ("proof", "false")] in + let ctx = (new context cfg) in + Printf.printf "Disposing...\n"; + ctx#dispose ; + Printf.printf "Exiting.\n"; +;; diff --git a/examples/ml/mlexample.ml b/examples/ml/mlexample.ml deleted file mode 100644 index 8cc248206..000000000 --- a/examples/ml/mlexample.ml +++ /dev/null @@ -1,12 +0,0 @@ -(* - Copyright (C) 2012 Microsoft Corporation - Author: CM Wintersteiger (cwinter) 2012-12-17 - *) - - open Z3 - - let _ = ignore(Log.open_ "z3.log") ; -let cfg = Some [("model", "true"); ("proof", "false")] in -let ctx = (new context cfg) in -ctx#dispose -;; diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 27913ab62..da7d22d54 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1296,10 +1296,6 @@ class MLComponent(Component): bld_dir = os.path.join(BUILD_DIR, 'api', 'ml') mk_dir(bld_dir) libfile = '%s$(SO_EXT)' % self.lib_name - # for mlfile in get_ml_files(self.src_dir): - # out.write('%si: libz3$(SO_EXT) %s\n' % (os.path.join('api', 'ml', mlfile),os.path.join(self.to_src_dir, mlfile))) - # out.write('\tocamlopt -I %s -i %s > %si\n' % (os.path.join('api', 'ml'), os.path.join(self.to_src_dir, mlfile), os.path.join('api', 'ml', mlfile))) - # out.write('\tocamlopt -I %s -c %si \n' % (os.path.join('api', 'ml'), os.path.join('api','ml', mlfile))) out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'z3native.c'))) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) @@ -1307,11 +1303,9 @@ class MLComponent(Component): out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) out.write('z3.cmxa: %s\n' % libfile) - out.write('\tcd %s && ocamlbuild -lflags -cclib,../../../%s/libz3ml.so,-cclib,../../../%s/libz3.so -build-dir ../../../%s/api/ml z3.cmxa && cd -\n' % (self.to_src_dir,BUILD_DIR,BUILD_DIR,BUILD_DIR)) - out.write('\tcp api/ml/z3.cmxa .\n') + out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) out.write('z3.cma: %s\n' % libfile) - out.write('\tcd %s && ocamlbuild -lflags -custom,-cclib,../../../%s/libz3ml.so,-cclib,../../../%s/libz3.so -build-dir ../../../%s/api/ml z3.cma && cd -\n' % (self.to_src_dir,BUILD_DIR,BUILD_DIR,BUILD_DIR)) - out.write('\tcp api/ml/z3.cma .\n') + out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -custom,-cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3native$(OBJ_EXT) z3.cma && cd -\n' % (self.to_src_dir,BUILD_DIR)) out.write('ml: z3.cmxa z3.cma\n') out.write('\n') @@ -1436,14 +1430,23 @@ class MLExampleComponent(ExampleComponent): def mk_makefile(self, out): if ML_ENABLED: - out.write('_ex_%s: z3.cmxa' % self.name) - deps = '' + out.write('ml_example.byte: z3.cma ') for mlfile in get_ml_files(self.ex_dir): - out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) - if IS_WINDOWS: - deps = deps.replace('/', '\\') - out.write('%s\n' % deps) - out.write('\tcd %s && ocamlbuild -build-dir ../../%s -lib z3 MLExample.native && cd -\n\n' % (self.to_src_dir, BUILD_DIR)) + out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) + out.write('\n') + out.write('\tocamlc -g -o ml_example.byte -I . z3.cma -I api/ml') + for mlfile in get_ml_files(self.ex_dir): + out.write(' %s/%s' % (self.to_ex_dir, mlfile)) + out.write('\n') + out.write('ml_example($EXE_EXT): z3.cmxa ') + for mlfile in get_ml_files(self.ex_dir): + out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) + out.write('\n') + out.write('\tocamlopt -g -o ml_example -I . z3.cmxa -I api/ml') + for mlfile in get_ml_files(self.ex_dir): + out.write(' %s/%s' % (self.to_ex_dir, mlfile)) + out.write('\n') + out.write('_ex_%s: ml_example.byte ml_example($EXE_EXT)\n\n' % self.name) class PythonExampleComponent(ExampleComponent): def __init__(self, name, path): diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index fb8121c79..71e16898e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -3463,7 +3463,7 @@ object (self) Disposes of the underlying native Z3 object. *) method dispose = - Printf.printf "Disposing %d \n" (Oo.id self) ; + Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with | Some (x) -> self#decref x; m_n_obj <- None | None -> () From 0fad5abd199091ebbb7eb719d291aa359d547f32 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 23:31:42 +0000 Subject: [PATCH 013/248] more ML API Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 3486 +--------------------------------------------- 1 file changed, 68 insertions(+), 3418 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 71e16898e..55ffd91e8 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,3390 +1,3 @@ -<<<<<<< HEAD -(* File generated from z3.idl *) - -type context -and symbol -and ast -and sort = private ast -and func_decl = private ast -and app = private ast -and pattern = private ast -and params -and param_descrs -and model -and func_interp -and func_entry -and fixedpoint -and ast_vector -and ast_map -and goal -and tactic -and probe -and apply_result -and solver -and stats - - - -and constructor -and constructor_list - -and lbool = - | L_FALSE - | L_UNDEF - | L_TRUE - -and symbol_kind = - | INT_SYMBOL - | STRING_SYMBOL - -and parameter_kind = - | PARAMETER_INT - | PARAMETER_DOUBLE - | PARAMETER_RATIONAL - | PARAMETER_SYMBOL - | PARAMETER_SORT - | PARAMETER_AST - | PARAMETER_FUNC_DECL - -and sort_kind = - | UNINTERPRETED_SORT - | BOOL_SORT - | INT_SORT - | REAL_SORT - | BV_SORT - | ARRAY_SORT - | DATATYPE_SORT - | RELATION_SORT - | FINITE_DOMAIN_SORT - | UNKNOWN_SORT - -and ast_kind = - | NUMERAL_AST - | APP_AST - | VAR_AST - | QUANTIFIER_AST - | SORT_AST - | FUNC_DECL_AST - | UNKNOWN_AST - -and decl_kind = - | OP_TRUE - | OP_FALSE - | OP_EQ - | OP_DISTINCT - | OP_ITE - | OP_AND - | OP_OR - | OP_IFF - | OP_XOR - | OP_NOT - | OP_IMPLIES - | OP_OEQ - | OP_ANUM - | OP_AGNUM - | OP_LE - | OP_GE - | OP_LT - | OP_GT - | OP_ADD - | OP_SUB - | OP_UMINUS - | OP_MUL - | OP_DIV - | OP_IDIV - | OP_REM - | OP_MOD - | OP_TO_REAL - | OP_TO_INT - | OP_IS_INT - | OP_POWER - | OP_STORE - | OP_SELECT - | OP_CONST_ARRAY - | OP_ARRAY_MAP - | OP_ARRAY_DEFAULT - | OP_SET_UNION - | OP_SET_INTERSECT - | OP_SET_DIFFERENCE - | OP_SET_COMPLEMENT - | OP_SET_SUBSET - | OP_AS_ARRAY - | OP_BNUM - | OP_BIT1 - | OP_BIT0 - | OP_BNEG - | OP_BADD - | OP_BSUB - | OP_BMUL - | OP_BSDIV - | OP_BUDIV - | OP_BSREM - | OP_BUREM - | OP_BSMOD - | OP_BSDIV0 - | OP_BUDIV0 - | OP_BSREM0 - | OP_BUREM0 - | OP_BSMOD0 - | OP_ULEQ - | OP_SLEQ - | OP_UGEQ - | OP_SGEQ - | OP_ULT - | OP_SLT - | OP_UGT - | OP_SGT - | OP_BAND - | OP_BOR - | OP_BNOT - | OP_BXOR - | OP_BNAND - | OP_BNOR - | OP_BXNOR - | OP_CONCAT - | OP_SIGN_EXT - | OP_ZERO_EXT - | OP_EXTRACT - | OP_REPEAT - | OP_BREDOR - | OP_BREDAND - | OP_BCOMP - | OP_BSHL - | OP_BLSHR - | OP_BASHR - | OP_ROTATE_LEFT - | OP_ROTATE_RIGHT - | OP_EXT_ROTATE_LEFT - | OP_EXT_ROTATE_RIGHT - | OP_INT2BV - | OP_BV2INT - | OP_CARRY - | OP_XOR3 - | OP_PR_UNDEF - | OP_PR_TRUE - | OP_PR_ASSERTED - | OP_PR_GOAL - | OP_PR_MODUS_PONENS - | OP_PR_REFLEXIVITY - | OP_PR_SYMMETRY - | OP_PR_TRANSITIVITY - | OP_PR_TRANSITIVITY_STAR - | OP_PR_MONOTONICITY - | OP_PR_QUANT_INTRO - | OP_PR_DISTRIBUTIVITY - | OP_PR_AND_ELIM - | OP_PR_NOT_OR_ELIM - | OP_PR_REWRITE - | OP_PR_REWRITE_STAR - | OP_PR_PULL_QUANT - | OP_PR_PULL_QUANT_STAR - | OP_PR_PUSH_QUANT - | OP_PR_ELIM_UNUSED_VARS - | OP_PR_DER - | OP_PR_QUANT_INST - | OP_PR_HYPOTHESIS - | OP_PR_LEMMA - | OP_PR_UNIT_RESOLUTION - | OP_PR_IFF_TRUE - | OP_PR_IFF_FALSE - | OP_PR_COMMUTATIVITY - | OP_PR_DEF_AXIOM - | OP_PR_DEF_INTRO - | OP_PR_APPLY_DEF - | OP_PR_IFF_OEQ - | OP_PR_NNF_POS - | OP_PR_NNF_NEG - | OP_PR_NNF_STAR - | OP_PR_CNF_STAR - | OP_PR_SKOLEMIZE - | OP_PR_MODUS_PONENS_OEQ - | OP_PR_TH_LEMMA - | OP_PR_HYPER_RESOLVE - | OP_RA_STORE - | OP_RA_EMPTY - | OP_RA_IS_EMPTY - | OP_RA_JOIN - | OP_RA_UNION - | OP_RA_WIDEN - | OP_RA_PROJECT - | OP_RA_FILTER - | OP_RA_NEGATION_FILTER - | OP_RA_RENAME - | OP_RA_COMPLEMENT - | OP_RA_SELECT - | OP_RA_CLONE - | OP_FD_LT - | OP_LABEL - | OP_LABEL_LIT - | OP_DT_CONSTRUCTOR - | OP_DT_RECOGNISER - | OP_DT_ACCESSOR - | OP_UNINTERPRETED - -and param_kind = - | PK_UINT - | PK_BOOL - | PK_DOUBLE - | PK_SYMBOL - | PK_STRING - | PK_OTHER - | PK_INVALID - -and ast_print_mode = - | PRINT_SMTLIB_FULL - | PRINT_LOW_LEVEL - | PRINT_SMTLIB_COMPLIANT - | PRINT_SMTLIB2_COMPLIANT - -and error_code = - | OK - | SORT_ERROR - | IOB - | INVALID_ARG - | PARSER_ERROR - | NO_PARSER - | INVALID_PATTERN - | MEMOUT_FAIL - | FILE_ACCESS_ERROR - | INTERNAL_FATAL - | INVALID_USAGE - | DEC_REF_ERROR - | EXCEPTION - -and goal_prec = - | GOAL_PRECISE - | GOAL_UNDER - | GOAL_OVER - | GOAL_UNDER_OVER - - -external finalize_Z3_context : context -> unit = "finalize_Z3_context";; let _ = Callback.register "finalize_Z3_context" finalize_Z3_context -external finalize_Z3_ast : ast -> unit = "finalize_Z3_ast";; let _ = Callback.register "finalize_Z3_ast" finalize_Z3_ast -external finalize_Z3_params : params -> unit = "finalize_Z3_params";; let _ = Callback.register "finalize_Z3_params" finalize_Z3_params -external finalize_Z3_param_descrs : param_descrs -> unit = "finalize_Z3_param_descrs";; let _ = Callback.register "finalize_Z3_param_descrs" finalize_Z3_param_descrs -external finalize_Z3_model : model -> unit = "finalize_Z3_model";; let _ = Callback.register "finalize_Z3_model" finalize_Z3_model -external finalize_Z3_func_interp : func_interp -> unit = "finalize_Z3_func_interp";; let _ = Callback.register "finalize_Z3_func_interp" finalize_Z3_func_interp -external finalize_Z3_func_entry : func_entry -> unit = "finalize_Z3_func_entry";; let _ = Callback.register "finalize_Z3_func_entry" finalize_Z3_func_entry -external finalize_Z3_fixedpoint : fixedpoint -> unit = "finalize_Z3_fixedpoint";; let _ = Callback.register "finalize_Z3_fixedpoint" finalize_Z3_fixedpoint -external finalize_Z3_ast_vector : ast_vector -> unit = "finalize_Z3_ast_vector";; let _ = Callback.register "finalize_Z3_ast_vector" finalize_Z3_ast_vector -external finalize_Z3_ast_map : ast_map -> unit = "finalize_Z3_ast_map";; let _ = Callback.register "finalize_Z3_ast_map" finalize_Z3_ast_map -external finalize_Z3_goal : goal -> unit = "finalize_Z3_goal";; let _ = Callback.register "finalize_Z3_goal" finalize_Z3_goal -external finalize_Z3_tactic : tactic -> unit = "finalize_Z3_tactic";; let _ = Callback.register "finalize_Z3_tactic" finalize_Z3_tactic -external finalize_Z3_probe : probe -> unit = "finalize_Z3_probe";; let _ = Callback.register "finalize_Z3_probe" finalize_Z3_probe -external finalize_Z3_apply_result : apply_result -> unit = "finalize_Z3_apply_result";; let _ = Callback.register "finalize_Z3_apply_result" finalize_Z3_apply_result -external finalize_Z3_solver : solver -> unit = "finalize_Z3_solver";; let _ = Callback.register "finalize_Z3_solver" finalize_Z3_solver -external finalize_Z3_stats : stats -> unit = "finalize_Z3_stats";; let _ = Callback.register "finalize_Z3_stats" finalize_Z3_stats - -let del_constructor _ _ = () -let del_constructor_list _ _ = () -let del_model _ _ = () -let del_context _ = () -let reset_memory () = () - - -(** Exceptions raised by Z3. It is safe to continue interacting with Z3 after - catching [Error] exceptions. - - {b See also}: {!get_error_msg} -*) -exception Error of context * error_code - - -(* Register dynamically-generated exception tag for use from C *) -let _ = Callback.register_exception "Z3.Error" (Error (Obj.magic None, OK)) - -external mk_context: (string * string) list -> context = "caml_z3_mk_context" - -external update_param_value : context -> string -> string -> unit - = "camlidl_z3_Z3_update_param_value" - -external get_param_value : context -> string -> string option - = "camlidl_z3_Z3_get_param_value" - -external interrupt : context -> unit - = "camlidl_z3_Z3_interrupt" - -external mk_params : context -> params - = "camlidl_z3_Z3_mk_params" - -external params_set_bool : context -> params -> symbol -> bool -> unit - = "camlidl_z3_Z3_params_set_bool" - -external params_set_uint : context -> params -> symbol -> int -> unit - = "camlidl_z3_Z3_params_set_uint" - -external params_set_double : context -> params -> symbol -> float -> unit - = "camlidl_z3_Z3_params_set_double" - -external params_set_symbol : context -> params -> symbol -> symbol -> unit - = "camlidl_z3_Z3_params_set_symbol" - -external params_to_string : context -> params -> string - = "camlidl_z3_Z3_params_to_string" - -external params_validate : context -> params -> param_descrs -> unit - = "camlidl_z3_Z3_params_validate" - -external param_descrs_get_kind : context -> param_descrs -> symbol -> param_kind - = "camlidl_z3_Z3_param_descrs_get_kind" - -external param_descrs_size : context -> param_descrs -> int - = "camlidl_z3_Z3_param_descrs_size" - -external param_descrs_get_name : context -> param_descrs -> int -> symbol - = "camlidl_z3_Z3_param_descrs_get_name" - -external param_descrs_to_string : context -> param_descrs -> string - = "camlidl_z3_Z3_param_descrs_to_string" - - -(** - Refined view of a {!symbol}. - - {b See also}: {!mk_symbol} - - {b See also}: {!symbol_refine} -*) -type symbol_refined = - | Symbol_int of int - | Symbol_string of string - -external mk_int_symbol : context -> int -> symbol - = "camlidl_z3_Z3_mk_int_symbol" - -external mk_string_symbol : context -> string -> symbol - = "camlidl_z3_Z3_mk_string_symbol" - - -(** - A datatype constructor descriptor. -*) -type datatype_constructor_desc = { - constructor_desc : symbol; (** name of the constructor function *) - recognizer_desc : symbol; (** name of the recognizer function *) - accessor_descs : (symbol * sort) array; (** names and sorts of the fields *) -} -(** - A datatype is described by a name and constructor descriptors. -*) -type datatype_desc = symbol * datatype_constructor_desc array -(** - A datatype constructor representation. -*) -type datatype_constructor = { - constructor : func_decl; (** constructor function *) - recognizer : func_decl; (** recognizer function *) - accessors : func_decl array; (** field accessor functions *) -} -(** - A datatype is represented by a sort and constructors. -*) -type datatype = sort * datatype_constructor array -(** - Refined view of a {!sort}. - - {b See also}: {!mk_sort} - - {b See also}: {!sort_refine} -*) -type sort_refined = - | Sort_uninterpreted of symbol - | Sort_bool - | Sort_int - | Sort_bv of int - | Sort_finite_domain of symbol * int64 - | Sort_real - | Sort_array of sort * sort - | Sort_datatype of datatype_constructor array - | Sort_relation of sort array - | Sort_unknown - -external mk_uninterpreted_sort : context -> symbol -> sort - = "camlidl_z3_Z3_mk_uninterpreted_sort" - -external mk_bool_sort : context -> sort - = "camlidl_z3_Z3_mk_bool_sort" - -external mk_int_sort : context -> sort - = "camlidl_z3_Z3_mk_int_sort" - -external mk_real_sort : context -> sort - = "camlidl_z3_Z3_mk_real_sort" - -external mk_bv_sort : context -> int -> sort - = "camlidl_z3_Z3_mk_bv_sort" - -external mk_finite_domain_sort : context -> symbol -> int64 -> sort - = "camlidl_z3_Z3_mk_finite_domain_sort" - -external mk_array_sort : context -> sort -> sort -> sort - = "camlidl_z3_Z3_mk_array_sort" - -external mk_tuple_sort : context -> symbol -> symbol array -> sort array -> sort * func_decl * func_decl array - = "camlidl_z3_Z3_mk_tuple_sort" - -external mk_enumeration_sort : context -> symbol -> symbol array -> sort * func_decl array * func_decl array - = "camlidl_z3_Z3_mk_enumeration_sort" - -external mk_list_sort : context -> symbol -> sort -> sort * func_decl * func_decl * func_decl * func_decl * func_decl * func_decl - = "camlidl_z3_Z3_mk_list_sort" - -external mk_constructor : context -> symbol -> symbol -> symbol array -> sort option array -> int array -> constructor - = "camlidl_z3_Z3_mk_constructor_bytecode" "camlidl_z3_Z3_mk_constructor" - -external del_constructor : context -> constructor -> unit - = "camlidl_z3_Z3_del_constructor" - -external mk_datatype : context -> symbol -> constructor array -> sort * constructor array - = "camlidl_z3_Z3_mk_datatype" - -external mk_constructor_list : context -> constructor array -> constructor_list - = "camlidl_z3_Z3_mk_constructor_list" - -external del_constructor_list : context -> constructor_list -> unit - = "camlidl_z3_Z3_del_constructor_list" - -external mk_datatypes : context -> symbol array -> constructor_list array -> sort array * constructor_list array - = "camlidl_z3_Z3_mk_datatypes" - -external query_constructor : context -> constructor -> int -> func_decl * func_decl * func_decl array - = "camlidl_z3_Z3_query_constructor" - -external mk_func_decl : context -> symbol -> sort array -> sort -> func_decl - = "camlidl_z3_Z3_mk_func_decl" - -external mk_app : context -> func_decl -> ast array -> ast - = "camlidl_z3_Z3_mk_app" - -external mk_const : context -> symbol -> sort -> ast - = "camlidl_z3_Z3_mk_const" - -external mk_fresh_func_decl : context -> string -> sort array -> sort -> func_decl - = "camlidl_z3_Z3_mk_fresh_func_decl" - -external mk_fresh_const : context -> string -> sort -> ast - = "camlidl_z3_Z3_mk_fresh_const" - -external mk_true : context -> ast - = "camlidl_z3_Z3_mk_true" - -external mk_false : context -> ast - = "camlidl_z3_Z3_mk_false" - -external mk_eq : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_eq" - -external mk_distinct : context -> ast array -> ast - = "camlidl_z3_Z3_mk_distinct" - -external mk_not : context -> ast -> ast - = "camlidl_z3_Z3_mk_not" - -external mk_ite : context -> ast -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_ite" - -external mk_iff : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_iff" - -external mk_implies : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_implies" - -external mk_xor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_xor" - -external mk_and : context -> ast array -> ast - = "camlidl_z3_Z3_mk_and" - -external mk_or : context -> ast array -> ast - = "camlidl_z3_Z3_mk_or" - -external mk_add : context -> ast array -> ast - = "camlidl_z3_Z3_mk_add" - -external mk_mul : context -> ast array -> ast - = "camlidl_z3_Z3_mk_mul" - -external mk_sub : context -> ast array -> ast - = "camlidl_z3_Z3_mk_sub" - -external mk_unary_minus : context -> ast -> ast - = "camlidl_z3_Z3_mk_unary_minus" - -external mk_div : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_div" - -external mk_mod : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_mod" - -external mk_rem : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_rem" - -external mk_power : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_power" - -external mk_lt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_lt" - -external mk_le : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_le" - -external mk_gt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_gt" - -external mk_ge : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_ge" - -external mk_int2real : context -> ast -> ast - = "camlidl_z3_Z3_mk_int2real" - -external mk_real2int : context -> ast -> ast - = "camlidl_z3_Z3_mk_real2int" - -external mk_is_int : context -> ast -> ast - = "camlidl_z3_Z3_mk_is_int" - -external mk_bvnot : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvnot" - -external mk_bvredand : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvredand" - -external mk_bvredor : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvredor" - -external mk_bvand : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvand" - -external mk_bvor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvor" - -external mk_bvxor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvxor" - -external mk_bvnand : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvnand" - -external mk_bvnor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvnor" - -external mk_bvxnor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvxnor" - -external mk_bvneg : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvneg" - -external mk_bvadd : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvadd" - -external mk_bvsub : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsub" - -external mk_bvmul : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvmul" - -external mk_bvudiv : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvudiv" - -external mk_bvsdiv : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsdiv" - -external mk_bvurem : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvurem" - -external mk_bvsrem : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsrem" - -external mk_bvsmod : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsmod" - -external mk_bvult : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvult" - -external mk_bvslt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvslt" - -external mk_bvule : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvule" - -external mk_bvsle : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsle" - -external mk_bvuge : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvuge" - -external mk_bvsge : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsge" - -external mk_bvugt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvugt" - -external mk_bvsgt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsgt" - -external mk_concat : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_concat" - -external mk_extract : context -> int -> int -> ast -> ast - = "camlidl_z3_Z3_mk_extract" - -external mk_sign_ext : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_sign_ext" - -external mk_zero_ext : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_zero_ext" - -external mk_repeat : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_repeat" - -external mk_bvshl : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvshl" - -external mk_bvlshr : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvlshr" - -external mk_bvashr : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvashr" - -external mk_rotate_left : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_rotate_left" - -external mk_rotate_right : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_rotate_right" - -external mk_ext_rotate_left : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_ext_rotate_left" - -external mk_ext_rotate_right : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_ext_rotate_right" - -external mk_int2bv : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_int2bv" - -external mk_bv2int : context -> ast -> bool -> ast - = "camlidl_z3_Z3_mk_bv2int" - -external mk_bvadd_no_overflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3_Z3_mk_bvadd_no_overflow" - -external mk_bvadd_no_underflow : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvadd_no_underflow" - -external mk_bvsub_no_overflow : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsub_no_overflow" - -external mk_bvsub_no_underflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3_Z3_mk_bvsub_no_underflow" - -external mk_bvsdiv_no_overflow : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsdiv_no_overflow" - -external mk_bvneg_no_overflow : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvneg_no_overflow" - -external mk_bvmul_no_overflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3_Z3_mk_bvmul_no_overflow" - -external mk_bvmul_no_underflow : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvmul_no_underflow" - -external mk_select : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_select" - -external mk_store : context -> ast -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_store" - -external mk_const_array : context -> sort -> ast -> ast - = "camlidl_z3_Z3_mk_const_array" - -external mk_map : context -> func_decl -> int -> ast -> ast - = "camlidl_z3_Z3_mk_map" - -external mk_array_default : context -> ast -> ast - = "camlidl_z3_Z3_mk_array_default" - -external mk_set_sort : context -> sort -> sort - = "camlidl_z3_Z3_mk_set_sort" - -external mk_empty_set : context -> sort -> ast - = "camlidl_z3_Z3_mk_empty_set" - -external mk_full_set : context -> sort -> ast - = "camlidl_z3_Z3_mk_full_set" - -external mk_set_add : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_add" - -external mk_set_del : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_del" - -external mk_set_union : context -> ast array -> ast - = "camlidl_z3_Z3_mk_set_union" - -external mk_set_intersect : context -> ast array -> ast - = "camlidl_z3_Z3_mk_set_intersect" - -external mk_set_difference : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_difference" - -external mk_set_complement : context -> ast -> ast - = "camlidl_z3_Z3_mk_set_complement" - -external mk_set_member : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_member" - -external mk_set_subset : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_subset" - - -(** - Summary: \[ [ numeral_refined ] \] is the refined view of a numeral . -*) -type numeral_refined = - | Numeral_int of int * sort - | Numeral_int64 of int64 * sort - | Numeral_large of string * sort - | Numeral_rational of numeral_refined * numeral_refined - -external mk_numeral : context -> string -> sort -> ast - = "camlidl_z3_Z3_mk_numeral" - -external mk_real : context -> int -> int -> ast - = "camlidl_z3_Z3_mk_real" - -external mk_int : context -> int -> sort -> ast - = "camlidl_z3_Z3_mk_int" - -external mk_int64 : context -> int64 -> sort -> ast - = "camlidl_z3_Z3_mk_int64" - -external mk_pattern : context -> ast array -> pattern - = "camlidl_z3_Z3_mk_pattern" - -external mk_bound : context -> int -> sort -> ast - = "camlidl_z3_Z3_mk_bound" - -external mk_forall : context -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3_Z3_mk_forall_bytecode" "camlidl_z3_Z3_mk_forall" - -external mk_exists : context -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3_Z3_mk_exists_bytecode" "camlidl_z3_Z3_mk_exists" - -external mk_quantifier : context -> bool -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3_Z3_mk_quantifier_bytecode" "camlidl_z3_Z3_mk_quantifier" - -external mk_quantifier_ex : context -> bool -> int -> symbol -> symbol -> pattern array -> ast array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3_Z3_mk_quantifier_ex_bytecode" "camlidl_z3_Z3_mk_quantifier_ex" - -external mk_forall_const : context -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3_Z3_mk_forall_const" - -external mk_exists_const : context -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3_Z3_mk_exists_const" - -external mk_quantifier_const : context -> bool -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3_Z3_mk_quantifier_const_bytecode" "camlidl_z3_Z3_mk_quantifier_const" - -external mk_quantifier_const_ex : context -> bool -> int -> symbol -> symbol -> app array -> pattern array -> ast array -> ast -> ast - = "camlidl_z3_Z3_mk_quantifier_const_ex_bytecode" "camlidl_z3_Z3_mk_quantifier_const_ex" - -external get_symbol_kind : context -> symbol -> symbol_kind - = "camlidl_z3_Z3_get_symbol_kind" - -external get_symbol_int : context -> symbol -> int - = "camlidl_z3_Z3_get_symbol_int" - -external get_symbol_string : context -> symbol -> string - = "camlidl_z3_Z3_get_symbol_string" - -external get_sort_name : context -> sort -> symbol - = "camlidl_z3_Z3_get_sort_name" - -external get_sort_id : context -> sort -> int - = "camlidl_z3_Z3_get_sort_id" - -external sort_to_ast : context -> sort -> ast - = "camlidl_z3_Z3_sort_to_ast" - -external is_eq_sort : context -> sort -> sort -> bool - = "camlidl_z3_Z3_is_eq_sort" - -external get_sort_kind : context -> sort -> sort_kind - = "camlidl_z3_Z3_get_sort_kind" - -external get_bv_sort_size : context -> sort -> int - = "camlidl_z3_Z3_get_bv_sort_size" - -external get_finite_domain_sort_size : context -> sort -> int64 option - = "camlidl_z3_Z3_get_finite_domain_sort_size" - -external get_array_sort_domain : context -> sort -> sort - = "camlidl_z3_Z3_get_array_sort_domain" - -external get_array_sort_range : context -> sort -> sort - = "camlidl_z3_Z3_get_array_sort_range" - -external get_tuple_sort_mk_decl : context -> sort -> func_decl - = "camlidl_z3_Z3_get_tuple_sort_mk_decl" - -external get_tuple_sort_num_fields : context -> sort -> int - = "camlidl_z3_Z3_get_tuple_sort_num_fields" - -external get_tuple_sort_field_decl : context -> sort -> int -> func_decl - = "camlidl_z3_Z3_get_tuple_sort_field_decl" - -external get_datatype_sort_num_constructors : context -> sort -> int - = "camlidl_z3_Z3_get_datatype_sort_num_constructors" - -external get_datatype_sort_constructor : context -> sort -> int -> func_decl - = "camlidl_z3_Z3_get_datatype_sort_constructor" - -external get_datatype_sort_recognizer : context -> sort -> int -> func_decl - = "camlidl_z3_Z3_get_datatype_sort_recognizer" - -external get_datatype_sort_constructor_accessor : context -> sort -> int -> int -> func_decl - = "camlidl_z3_Z3_get_datatype_sort_constructor_accessor" - -external get_relation_arity : context -> sort -> int - = "camlidl_z3_Z3_get_relation_arity" - -external get_relation_column : context -> sort -> int -> sort - = "camlidl_z3_Z3_get_relation_column" - -external func_decl_to_ast : context -> func_decl -> ast - = "camlidl_z3_Z3_func_decl_to_ast" - -external is_eq_func_decl : context -> func_decl -> func_decl -> bool - = "camlidl_z3_Z3_is_eq_func_decl" - -external get_func_decl_id : context -> func_decl -> int - = "camlidl_z3_Z3_get_func_decl_id" - -external get_decl_name : context -> func_decl -> symbol - = "camlidl_z3_Z3_get_decl_name" - -external get_decl_kind : context -> func_decl -> decl_kind - = "camlidl_z3_Z3_get_decl_kind" - -external get_domain_size : context -> func_decl -> int - = "camlidl_z3_Z3_get_domain_size" - -external get_arity : context -> func_decl -> int - = "camlidl_z3_Z3_get_arity" - -external get_domain : context -> func_decl -> int -> sort - = "camlidl_z3_Z3_get_domain" - -external get_range : context -> func_decl -> sort - = "camlidl_z3_Z3_get_range" - -external get_decl_num_parameters : context -> func_decl -> int - = "camlidl_z3_Z3_get_decl_num_parameters" - -external get_decl_parameter_kind : context -> func_decl -> int -> parameter_kind - = "camlidl_z3_Z3_get_decl_parameter_kind" - -external get_decl_int_parameter : context -> func_decl -> int -> int - = "camlidl_z3_Z3_get_decl_int_parameter" - -external get_decl_double_parameter : context -> func_decl -> int -> float - = "camlidl_z3_Z3_get_decl_double_parameter" - -external get_decl_symbol_parameter : context -> func_decl -> int -> symbol - = "camlidl_z3_Z3_get_decl_symbol_parameter" - -external get_decl_sort_parameter : context -> func_decl -> int -> sort - = "camlidl_z3_Z3_get_decl_sort_parameter" - -external get_decl_ast_parameter : context -> func_decl -> int -> ast - = "camlidl_z3_Z3_get_decl_ast_parameter" - -external get_decl_func_decl_parameter : context -> func_decl -> int -> func_decl - = "camlidl_z3_Z3_get_decl_func_decl_parameter" - -external get_decl_rational_parameter : context -> func_decl -> int -> string - = "camlidl_z3_Z3_get_decl_rational_parameter" - -external app_to_ast : context -> app -> ast - = "camlidl_z3_Z3_app_to_ast" - -external get_app_decl : context -> app -> func_decl - = "camlidl_z3_Z3_get_app_decl" - -external get_app_num_args : context -> app -> int - = "camlidl_z3_Z3_get_app_num_args" - -external get_app_arg : context -> app -> int -> ast - = "camlidl_z3_Z3_get_app_arg" - - -(** - Summary: \[ [ binder_type ] \] is a universal or existential quantifier. - - {b See also}: {!term_refined} -*) -type binder_type = Forall | Exists -(** - Summary: \[ [ term_refined ] \] is the refinement of a {!ast} . - - {b See also}: {!term_refine} -*) -type term_refined = - | Term_numeral of numeral_refined - | Term_app of decl_kind * func_decl * ast array - | Term_quantifier of binder_type * int * ast array array * (symbol * sort) array * ast - | Term_var of int * sort - -external is_eq_ast : context -> ast -> ast -> bool - = "camlidl_z3_Z3_is_eq_ast" - -external get_ast_id : context -> ast -> int - = "camlidl_z3_Z3_get_ast_id" - -external get_ast_hash : context -> ast -> int - = "camlidl_z3_Z3_get_ast_hash" - -external get_sort : context -> ast -> sort - = "camlidl_z3_Z3_get_sort" - -external is_well_sorted : context -> ast -> bool - = "camlidl_z3_Z3_is_well_sorted" - -external get_bool_value : context -> ast -> lbool - = "camlidl_z3_Z3_get_bool_value" - -external get_ast_kind : context -> ast -> ast_kind - = "camlidl_z3_Z3_get_ast_kind" - -external is_app : context -> ast -> bool - = "camlidl_z3_Z3_is_app" - -external is_numeral_ast : context -> ast -> bool - = "camlidl_z3_Z3_is_numeral_ast" - -external is_algebraic_number : context -> ast -> bool - = "camlidl_z3_Z3_is_algebraic_number" - -external to_app : context -> ast -> app - = "camlidl_z3_Z3_to_app" - -external to_func_decl : context -> ast -> func_decl - = "camlidl_z3_Z3_to_func_decl" - -external get_numeral_string : context -> ast -> string - = "camlidl_z3_Z3_get_numeral_string" - -external get_numeral_decimal_string : context -> ast -> int -> string - = "camlidl_z3_Z3_get_numeral_decimal_string" - -external get_numerator : context -> ast -> ast - = "camlidl_z3_Z3_get_numerator" - -external get_denominator : context -> ast -> ast - = "camlidl_z3_Z3_get_denominator" - -external get_numeral_small : context -> ast -> bool * int64 * int64 - = "camlidl_z3_Z3_get_numeral_small" - -external get_numeral_int : context -> ast -> bool * int - = "camlidl_z3_Z3_get_numeral_int" - -external get_numeral_int64 : context -> ast -> bool * int64 - = "camlidl_z3_Z3_get_numeral_int64" - -external get_numeral_rational_int64 : context -> ast -> bool * int64 * int64 - = "camlidl_z3_Z3_get_numeral_rational_int64" - -external get_algebraic_number_lower : context -> ast -> int -> ast - = "camlidl_z3_Z3_get_algebraic_number_lower" - -external get_algebraic_number_upper : context -> ast -> int -> ast - = "camlidl_z3_Z3_get_algebraic_number_upper" - -external pattern_to_ast : context -> pattern -> ast - = "camlidl_z3_Z3_pattern_to_ast" - -external get_pattern_num_terms : context -> pattern -> int - = "camlidl_z3_Z3_get_pattern_num_terms" - -external get_pattern : context -> pattern -> int -> ast - = "camlidl_z3_Z3_get_pattern" - -external get_index_value : context -> ast -> int - = "camlidl_z3_Z3_get_index_value" - -external is_quantifier_forall : context -> ast -> bool - = "camlidl_z3_Z3_is_quantifier_forall" - -external get_quantifier_weight : context -> ast -> int - = "camlidl_z3_Z3_get_quantifier_weight" - -external get_quantifier_num_patterns : context -> ast -> int - = "camlidl_z3_Z3_get_quantifier_num_patterns" - -external get_quantifier_pattern_ast : context -> ast -> int -> pattern - = "camlidl_z3_Z3_get_quantifier_pattern_ast" - -external get_quantifier_num_no_patterns : context -> ast -> int - = "camlidl_z3_Z3_get_quantifier_num_no_patterns" - -external get_quantifier_no_pattern_ast : context -> ast -> int -> ast - = "camlidl_z3_Z3_get_quantifier_no_pattern_ast" - -external get_quantifier_num_bound : context -> ast -> int - = "camlidl_z3_Z3_get_quantifier_num_bound" - -external get_quantifier_bound_name : context -> ast -> int -> symbol - = "camlidl_z3_Z3_get_quantifier_bound_name" - -external get_quantifier_bound_sort : context -> ast -> int -> sort - = "camlidl_z3_Z3_get_quantifier_bound_sort" - -external get_quantifier_body : context -> ast -> ast - = "camlidl_z3_Z3_get_quantifier_body" - -external simplify : context -> ast -> ast - = "camlidl_z3_Z3_simplify" - -external simplify_ex : context -> ast -> params -> ast - = "camlidl_z3_Z3_simplify_ex" - -external simplify_get_help : context -> string - = "camlidl_z3_Z3_simplify_get_help" - -external simplify_get_param_descrs : context -> param_descrs - = "camlidl_z3_Z3_simplify_get_param_descrs" - -external update_term : context -> ast -> ast array -> ast - = "camlidl_z3_Z3_update_term" - -external substitute : context -> ast -> ast array -> ast array -> ast - = "camlidl_z3_Z3_substitute" - -external substitute_vars : context -> ast -> ast array -> ast - = "camlidl_z3_Z3_substitute_vars" - -external translate : context -> ast -> context -> ast - = "camlidl_z3_Z3_translate" - - -(** - A model assigns uninterpreted sorts to finite universes of distinct values, constants to values, - and arrays and functions to finite maps from argument values to result values plus a default - value for all other arguments. -*) -type model_refined = { - sorts : (sort, ast_vector) Hashtbl.t; - consts : (func_decl, ast) Hashtbl.t; - arrays : (func_decl, (ast, ast) Hashtbl.t * ast) Hashtbl.t; - funcs : (func_decl, (ast array, ast) Hashtbl.t * ast) Hashtbl.t; -} - -external model_eval : context -> model -> ast -> bool -> ast option - = "camlidl_z3_Z3_model_eval" - -external model_get_const_interp : context -> model -> func_decl -> ast option - = "camlidl_z3_Z3_model_get_const_interp" - -external model_get_func_interp : context -> model -> func_decl -> func_interp option - = "camlidl_z3_Z3_model_get_func_interp" - -external model_get_num_consts : context -> model -> int - = "camlidl_z3_Z3_model_get_num_consts" - -external model_get_const_decl : context -> model -> int -> func_decl - = "camlidl_z3_Z3_model_get_const_decl" - -external model_get_num_funcs : context -> model -> int - = "camlidl_z3_Z3_model_get_num_funcs" - -external model_get_func_decl : context -> model -> int -> func_decl - = "camlidl_z3_Z3_model_get_func_decl" - -external model_get_num_sorts : context -> model -> int - = "camlidl_z3_Z3_model_get_num_sorts" - -external model_get_sort : context -> model -> int -> sort - = "camlidl_z3_Z3_model_get_sort" - -external model_get_sort_universe : context -> model -> sort -> ast_vector - = "camlidl_z3_Z3_model_get_sort_universe" - -external is_as_array : context -> ast -> bool - = "camlidl_z3_Z3_is_as_array" - -external get_as_array_func_decl : context -> ast -> func_decl - = "camlidl_z3_Z3_get_as_array_func_decl" - -external func_interp_get_num_entries : context -> func_interp -> int - = "camlidl_z3_Z3_func_interp_get_num_entries" - -external func_interp_get_entry : context -> func_interp -> int -> func_entry - = "camlidl_z3_Z3_func_interp_get_entry" - -external func_interp_get_else : context -> func_interp -> ast - = "camlidl_z3_Z3_func_interp_get_else" - -external func_interp_get_arity : context -> func_interp -> int - = "camlidl_z3_Z3_func_interp_get_arity" - -external func_entry_get_value : context -> func_entry -> ast - = "camlidl_z3_Z3_func_entry_get_value" - -external func_entry_get_num_args : context -> func_entry -> int - = "camlidl_z3_Z3_func_entry_get_num_args" - -external func_entry_get_arg : context -> func_entry -> int -> ast - = "camlidl_z3_Z3_func_entry_get_arg" - -external open_log : string -> bool - = "camlidl_z3_Z3_open_log" - -external append_log : string -> unit - = "camlidl_z3_Z3_append_log" - -external close_log : unit -> unit - = "camlidl_z3_Z3_close_log" - -external toggle_warning_messages : bool -> unit - = "camlidl_z3_Z3_toggle_warning_messages" - -external set_ast_print_mode : context -> ast_print_mode -> unit - = "camlidl_z3_Z3_set_ast_print_mode" - -external ast_to_string : context -> ast -> string - = "camlidl_z3_Z3_ast_to_string" - -external pattern_to_string : context -> pattern -> string - = "camlidl_z3_Z3_pattern_to_string" - -external sort_to_string : context -> sort -> string - = "camlidl_z3_Z3_sort_to_string" - -external func_decl_to_string : context -> func_decl -> string - = "camlidl_z3_Z3_func_decl_to_string" - -external model_to_string : context -> model -> string - = "camlidl_z3_Z3_model_to_string" - -external benchmark_to_smtlib_string : context -> string -> string -> string -> string -> ast array -> ast -> string - = "camlidl_z3_Z3_benchmark_to_smtlib_string_bytecode" "camlidl_z3_Z3_benchmark_to_smtlib_string" - -external parse_smtlib2_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - = "camlidl_z3_Z3_parse_smtlib2_string_bytecode" "camlidl_z3_Z3_parse_smtlib2_string" - -external parse_smtlib2_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - = "camlidl_z3_Z3_parse_smtlib2_file_bytecode" "camlidl_z3_Z3_parse_smtlib2_file" - -external parse_smtlib_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - = "camlidl_z3_Z3_parse_smtlib_string_bytecode" "camlidl_z3_Z3_parse_smtlib_string" - -external parse_smtlib_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - = "camlidl_z3_Z3_parse_smtlib_file_bytecode" "camlidl_z3_Z3_parse_smtlib_file" - -external get_smtlib_num_formulas : context -> int - = "camlidl_z3_Z3_get_smtlib_num_formulas" - -external get_smtlib_formula : context -> int -> ast - = "camlidl_z3_Z3_get_smtlib_formula" - -external get_smtlib_num_assumptions : context -> int - = "camlidl_z3_Z3_get_smtlib_num_assumptions" - -external get_smtlib_assumption : context -> int -> ast - = "camlidl_z3_Z3_get_smtlib_assumption" - -external get_smtlib_num_decls : context -> int - = "camlidl_z3_Z3_get_smtlib_num_decls" - -external get_smtlib_decl : context -> int -> func_decl - = "camlidl_z3_Z3_get_smtlib_decl" - -external get_smtlib_num_sorts : context -> int - = "camlidl_z3_Z3_get_smtlib_num_sorts" - -external get_smtlib_sort : context -> int -> sort - = "camlidl_z3_Z3_get_smtlib_sort" - -external get_smtlib_error : context -> string - = "camlidl_z3_Z3_get_smtlib_error" - -external set_error : context -> error_code -> unit - = "camlidl_z3_Z3_set_error" - -external get_error_msg_ex : context -> error_code -> string - = "camlidl_z3_Z3_get_error_msg_ex" - -external get_version : unit -> int * int * int * int - = "camlidl_z3_Z3_get_version" - -external enable_trace : string -> unit - = "camlidl_z3_Z3_enable_trace" - -external disable_trace : string -> unit - = "camlidl_z3_Z3_disable_trace" - -external mk_fixedpoint : context -> fixedpoint - = "camlidl_z3_Z3_mk_fixedpoint" - -external fixedpoint_add_rule : context -> fixedpoint -> ast -> symbol -> unit - = "camlidl_z3_Z3_fixedpoint_add_rule" - -external fixedpoint_add_fact : context -> fixedpoint -> func_decl -> int array -> unit - = "camlidl_z3_Z3_fixedpoint_add_fact" - -external fixedpoint_assert : context -> fixedpoint -> ast -> unit - = "camlidl_z3_Z3_fixedpoint_assert" - -external fixedpoint_query : context -> fixedpoint -> ast -> lbool - = "camlidl_z3_Z3_fixedpoint_query" - -external fixedpoint_query_relations : context -> fixedpoint -> func_decl array -> lbool - = "camlidl_z3_Z3_fixedpoint_query_relations" - -external fixedpoint_get_answer : context -> fixedpoint -> ast - = "camlidl_z3_Z3_fixedpoint_get_answer" - -external fixedpoint_get_reason_unknown : context -> fixedpoint -> string - = "camlidl_z3_Z3_fixedpoint_get_reason_unknown" - -external fixedpoint_update_rule : context -> fixedpoint -> ast -> symbol -> unit - = "camlidl_z3_Z3_fixedpoint_update_rule" - -external fixedpoint_get_num_levels : context -> fixedpoint -> func_decl -> int - = "camlidl_z3_Z3_fixedpoint_get_num_levels" - -external fixedpoint_get_cover_delta : context -> fixedpoint -> int -> func_decl -> ast - = "camlidl_z3_Z3_fixedpoint_get_cover_delta" - -external fixedpoint_add_cover : context -> fixedpoint -> int -> func_decl -> ast -> unit - = "camlidl_z3_Z3_fixedpoint_add_cover" - -external fixedpoint_get_statistics : context -> fixedpoint -> stats - = "camlidl_z3_Z3_fixedpoint_get_statistics" - -external fixedpoint_register_relation : context -> fixedpoint -> func_decl -> unit - = "camlidl_z3_Z3_fixedpoint_register_relation" - -external fixedpoint_set_predicate_representation : context -> fixedpoint -> func_decl -> symbol array -> unit - = "camlidl_z3_Z3_fixedpoint_set_predicate_representation" - -external fixedpoint_get_rules : context -> fixedpoint -> ast_vector - = "camlidl_z3_Z3_fixedpoint_get_rules" - -external fixedpoint_get_assertions : context -> fixedpoint -> ast_vector - = "camlidl_z3_Z3_fixedpoint_get_assertions" - -external fixedpoint_set_params : context -> fixedpoint -> params -> unit - = "camlidl_z3_Z3_fixedpoint_set_params" - -external fixedpoint_get_help : context -> fixedpoint -> string - = "camlidl_z3_Z3_fixedpoint_get_help" - -external fixedpoint_get_param_descrs : context -> fixedpoint -> param_descrs - = "camlidl_z3_Z3_fixedpoint_get_param_descrs" - -external fixedpoint_to_string : context -> fixedpoint -> ast array -> string - = "camlidl_z3_Z3_fixedpoint_to_string" - -external fixedpoint_from_string : context -> fixedpoint -> string -> ast_vector - = "camlidl_z3_Z3_fixedpoint_from_string" - -external fixedpoint_from_file : context -> fixedpoint -> string -> ast_vector - = "camlidl_z3_Z3_fixedpoint_from_file" - -external fixedpoint_push : context -> fixedpoint -> unit - = "camlidl_z3_Z3_fixedpoint_push" - -external fixedpoint_pop : context -> fixedpoint -> unit - = "camlidl_z3_Z3_fixedpoint_pop" - -external mk_ast_vector : context -> ast_vector - = "camlidl_z3_Z3_mk_ast_vector" - -external ast_vector_size : context -> ast_vector -> int - = "camlidl_z3_Z3_ast_vector_size" - -external ast_vector_get : context -> ast_vector -> int -> ast - = "camlidl_z3_Z3_ast_vector_get" - -external ast_vector_set : context -> ast_vector -> int -> ast -> unit - = "camlidl_z3_Z3_ast_vector_set" - -external ast_vector_resize : context -> ast_vector -> int -> unit - = "camlidl_z3_Z3_ast_vector_resize" - -external ast_vector_push : context -> ast_vector -> ast -> unit - = "camlidl_z3_Z3_ast_vector_push" - -external ast_vector_translate : context -> ast_vector -> context -> ast_vector - = "camlidl_z3_Z3_ast_vector_translate" - -external ast_vector_to_string : context -> ast_vector -> string - = "camlidl_z3_Z3_ast_vector_to_string" - -external mk_ast_map : context -> ast_map - = "camlidl_z3_Z3_mk_ast_map" - -external ast_map_contains : context -> ast_map -> ast -> bool - = "camlidl_z3_Z3_ast_map_contains" - -external ast_map_find : context -> ast_map -> ast -> ast - = "camlidl_z3_Z3_ast_map_find" - -external ast_map_insert : context -> ast_map -> ast -> ast -> unit - = "camlidl_z3_Z3_ast_map_insert" - -external ast_map_erase : context -> ast_map -> ast -> unit - = "camlidl_z3_Z3_ast_map_erase" - -external ast_map_reset : context -> ast_map -> unit - = "camlidl_z3_Z3_ast_map_reset" - -external ast_map_size : context -> ast_map -> int - = "camlidl_z3_Z3_ast_map_size" - -external ast_map_keys : context -> ast_map -> ast_vector - = "camlidl_z3_Z3_ast_map_keys" - -external ast_map_to_string : context -> ast_map -> string - = "camlidl_z3_Z3_ast_map_to_string" - -external mk_goal : context -> bool -> bool -> bool -> goal - = "camlidl_z3_Z3_mk_goal" - -external goal_precision : context -> goal -> goal_prec - = "camlidl_z3_Z3_goal_precision" - -external goal_assert : context -> goal -> ast -> unit - = "camlidl_z3_Z3_goal_assert" - -external goal_inconsistent : context -> goal -> bool - = "camlidl_z3_Z3_goal_inconsistent" - -external goal_depth : context -> goal -> int - = "camlidl_z3_Z3_goal_depth" - -external goal_reset : context -> goal -> unit - = "camlidl_z3_Z3_goal_reset" - -external goal_size : context -> goal -> int - = "camlidl_z3_Z3_goal_size" - -external goal_formula : context -> goal -> int -> ast - = "camlidl_z3_Z3_goal_formula" - -external goal_num_exprs : context -> goal -> int - = "camlidl_z3_Z3_goal_num_exprs" - -external goal_is_decided_sat : context -> goal -> bool - = "camlidl_z3_Z3_goal_is_decided_sat" - -external goal_is_decided_unsat : context -> goal -> bool - = "camlidl_z3_Z3_goal_is_decided_unsat" - -external goal_translate : context -> goal -> context -> goal - = "camlidl_z3_Z3_goal_translate" - -external goal_to_string : context -> goal -> string - = "camlidl_z3_Z3_goal_to_string" - -external mk_tactic : context -> string -> tactic - = "camlidl_z3_Z3_mk_tactic" - -external mk_probe : context -> string -> probe - = "camlidl_z3_Z3_mk_probe" - -external tactic_and_then : context -> tactic -> tactic -> tactic - = "camlidl_z3_Z3_tactic_and_then" - -external tactic_or_else : context -> tactic -> tactic -> tactic - = "camlidl_z3_Z3_tactic_or_else" - -external tactic_par_or : context -> tactic array -> tactic - = "camlidl_z3_Z3_tactic_par_or" - -external tactic_par_and_then : context -> tactic -> tactic -> tactic - = "camlidl_z3_Z3_tactic_par_and_then" - -external tactic_try_for : context -> tactic -> int -> tactic - = "camlidl_z3_Z3_tactic_try_for" - -external tactic_when : context -> probe -> tactic -> tactic - = "camlidl_z3_Z3_tactic_when" - -external tactic_cond : context -> probe -> tactic -> tactic -> tactic - = "camlidl_z3_Z3_tactic_cond" - -external tactic_repeat : context -> tactic -> int -> tactic - = "camlidl_z3_Z3_tactic_repeat" - -external tactic_skip : context -> tactic - = "camlidl_z3_Z3_tactic_skip" - -external tactic_fail : context -> tactic - = "camlidl_z3_Z3_tactic_fail" - -external tactic_fail_if : context -> probe -> tactic - = "camlidl_z3_Z3_tactic_fail_if" - -external tactic_fail_if_not_decided : context -> tactic - = "camlidl_z3_Z3_tactic_fail_if_not_decided" - -external tactic_using_params : context -> tactic -> params -> tactic - = "camlidl_z3_Z3_tactic_using_params" - -external probe_const : context -> float -> probe - = "camlidl_z3_Z3_probe_const" - -external probe_lt : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_lt" - -external probe_gt : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_gt" - -external probe_le : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_le" - -external probe_ge : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_ge" - -external probe_eq : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_eq" - -external probe_and : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_and" - -external probe_or : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_or" - -external probe_not : context -> probe -> probe - = "camlidl_z3_Z3_probe_not" - -external get_num_tactics : context -> int - = "camlidl_z3_Z3_get_num_tactics" - -external get_tactic_name : context -> int -> string - = "camlidl_z3_Z3_get_tactic_name" - -external get_num_probes : context -> int - = "camlidl_z3_Z3_get_num_probes" - -external get_probe_name : context -> int -> string - = "camlidl_z3_Z3_get_probe_name" - -external tactic_get_help : context -> tactic -> string - = "camlidl_z3_Z3_tactic_get_help" - -external tactic_get_param_descrs : context -> tactic -> param_descrs - = "camlidl_z3_Z3_tactic_get_param_descrs" - -external tactic_get_descr : context -> string -> string - = "camlidl_z3_Z3_tactic_get_descr" - -external probe_get_descr : context -> string -> string - = "camlidl_z3_Z3_probe_get_descr" - -external probe_apply : context -> probe -> goal -> float - = "camlidl_z3_Z3_probe_apply" - -external tactic_apply : context -> tactic -> goal -> apply_result - = "camlidl_z3_Z3_tactic_apply" - -external tactic_apply_ex : context -> tactic -> goal -> params -> apply_result - = "camlidl_z3_Z3_tactic_apply_ex" - -external apply_result_to_string : context -> apply_result -> string - = "camlidl_z3_Z3_apply_result_to_string" - -external apply_result_get_num_subgoals : context -> apply_result -> int - = "camlidl_z3_Z3_apply_result_get_num_subgoals" - -external apply_result_get_subgoal : context -> apply_result -> int -> goal - = "camlidl_z3_Z3_apply_result_get_subgoal" - -external apply_result_convert_model : context -> apply_result -> int -> model -> model - = "camlidl_z3_Z3_apply_result_convert_model" - -external mk_solver : context -> solver - = "camlidl_z3_Z3_mk_solver" - -external mk_simple_solver : context -> solver - = "camlidl_z3_Z3_mk_simple_solver" - -external mk_solver_for_logic : context -> symbol -> solver - = "camlidl_z3_Z3_mk_solver_for_logic" - -external mk_solver_from_tactic : context -> tactic -> solver - = "camlidl_z3_Z3_mk_solver_from_tactic" - -external solver_get_help : context -> solver -> string - = "camlidl_z3_Z3_solver_get_help" - -external solver_get_param_descrs : context -> solver -> param_descrs - = "camlidl_z3_Z3_solver_get_param_descrs" - -external solver_set_params : context -> solver -> params -> unit - = "camlidl_z3_Z3_solver_set_params" - -external solver_push : context -> solver -> unit - = "camlidl_z3_Z3_solver_push" - -external solver_pop : context -> solver -> int -> unit - = "camlidl_z3_Z3_solver_pop" - -external solver_reset : context -> solver -> unit - = "camlidl_z3_Z3_solver_reset" - -external solver_get_num_scopes : context -> solver -> int - = "camlidl_z3_Z3_solver_get_num_scopes" - -external solver_assert : context -> solver -> ast -> unit - = "camlidl_z3_Z3_solver_assert" - -external solver_assert_and_track : context -> solver -> ast -> ast -> unit - = "camlidl_z3_Z3_solver_assert_and_track" - -external solver_get_assertions : context -> solver -> ast_vector - = "camlidl_z3_Z3_solver_get_assertions" - -external solver_check : context -> solver -> lbool - = "camlidl_z3_Z3_solver_check" - -external solver_check_assumptions : context -> solver -> ast array -> lbool - = "camlidl_z3_Z3_solver_check_assumptions" - -external solver_get_model : context -> solver -> model - = "camlidl_z3_Z3_solver_get_model" - -external solver_get_proof : context -> solver -> ast - = "camlidl_z3_Z3_solver_get_proof" - -external solver_get_unsat_core : context -> solver -> ast_vector - = "camlidl_z3_Z3_solver_get_unsat_core" - -external solver_get_reason_unknown : context -> solver -> string - = "camlidl_z3_Z3_solver_get_reason_unknown" - -external solver_get_statistics : context -> solver -> stats - = "camlidl_z3_Z3_solver_get_statistics" - -external solver_to_string : context -> solver -> string - = "camlidl_z3_Z3_solver_to_string" - - -type stat_datum = Stat_int of int | Stat_float of float -type stats_refined = (string, stat_datum) Hashtbl.t - -external stats_to_string : context -> stats -> string - = "camlidl_z3_Z3_stats_to_string" - -external stats_size : context -> stats -> int - = "camlidl_z3_Z3_stats_size" - -external stats_get_key : context -> stats -> int -> string - = "camlidl_z3_Z3_stats_get_key" - -external stats_is_uint : context -> stats -> int -> bool - = "camlidl_z3_Z3_stats_is_uint" - -external stats_is_double : context -> stats -> int -> bool - = "camlidl_z3_Z3_stats_is_double" - -external stats_get_uint_value : context -> stats -> int -> int - = "camlidl_z3_Z3_stats_get_uint_value" - -external stats_get_double_value : context -> stats -> int -> float - = "camlidl_z3_Z3_stats_get_double_value" - -external get_implied_equalities : context -> solver -> ast array -> lbool * int array - = "camlidl_z3_Z3_get_implied_equalities" - - -(* Internal auxiliary functions: *) -(* -(* Transform a pair of arrays into an array of pairs *) -let array_combine a b = - if Array.length a <> Array.length b then raise (Invalid_argument "array_combine"); - Array.init (Array.length a) (fun i -> (a.(i), b.(i))) -(* [a |> b] is the pipeline operator for [b(a)] *) -let ( |> ) x f = f x -*) -(* Find the index of an element in an array, raises Not_found is missing *) -let find equal x a = - let len = Array.length a in - let rec find_ i = - if i >= len then - raise Not_found - else - if equal x a.(i) then - i - else - find_ (i+1) - in - find_ 0 -(* Symbols *) -let symbol_refine c s = - match get_symbol_kind c s with - | INT_SYMBOL -> Symbol_int (get_symbol_int c s) - | STRING_SYMBOL -> Symbol_string (get_symbol_string c s) -let mk_symbol c = function - | Symbol_int(i) -> mk_int_symbol c i - | Symbol_string(s) -> mk_string_symbol c s -(* Sorts *) -let get_datatype_sort c s = - Array.init (get_datatype_sort_num_constructors c s) (fun i -> - let constructor = get_datatype_sort_constructor c s i in - let recognizer = get_datatype_sort_recognizer c s i in - let accessors = - Array.init (get_domain_size c constructor) (fun j -> - get_datatype_sort_constructor_accessor c s i j - ) in - {constructor; recognizer; accessors} - ) -let sort_refine c s = - match get_sort_kind c s with - | UNINTERPRETED_SORT -> Sort_uninterpreted (get_sort_name c s) - | BOOL_SORT -> Sort_bool - | INT_SORT -> Sort_int - | BV_SORT -> Sort_bv (get_bv_sort_size c s) - | FINITE_DOMAIN_SORT -> - (match get_finite_domain_sort_size c s with - | Some(sz) -> Sort_finite_domain (get_sort_name c s, sz) - | None -> failwith "Z3.sort_refine: failed to get size of finite-domain sort" - ) - | REAL_SORT -> Sort_real - | ARRAY_SORT -> Sort_array (get_array_sort_domain c s, get_array_sort_range c s) - | DATATYPE_SORT -> Sort_datatype (get_datatype_sort c s) - | RELATION_SORT -> Sort_relation (Array.init (get_relation_arity c s) (fun i -> get_relation_column c s i)) - | UNKNOWN_SORT -> Sort_unknown -let mk_sort c = function - | Sort_uninterpreted(s) -> mk_uninterpreted_sort c s - | Sort_bool -> mk_bool_sort c - | Sort_int -> mk_int_sort c - | Sort_bv(size) -> mk_bv_sort c size - | Sort_finite_domain(name,size) -> mk_finite_domain_sort c name size - | Sort_real -> mk_real_sort c - | Sort_array(domain,range) -> mk_array_sort c domain range - | Sort_datatype(constructors) -> get_range c constructors.(0).constructor - | Sort_relation(_) -> invalid_arg "Z3.mk_sort: cannot construct relation sorts" - | Sort_unknown(_) -> invalid_arg "Z3.mk_sort: cannot construct unknown sorts" -(* Replacement datatypes creation API *) -let mk_datatypes ctx generator = - let usort0 = mk_uninterpreted_sort ctx (mk_int_symbol ctx 0) - in - let rec find_num_sorts i = - if i = max_int then invalid_arg "mk_datatypes: too many sorts" - else - match generator (Array.make i usort0) with - | None -> find_num_sorts (i+1) - | Some(a) when Array.length a = i -> i - | Some _ -> invalid_arg "mk_datatypes: number of sorts and datatype descriptors must be equal" - in - let num_sorts = find_num_sorts 0 - in - let sorts0 = Array.init num_sorts (fun i -> mk_uninterpreted_sort ctx (mk_int_symbol ctx i)) - in - let ctorss_descriptors = - match generator sorts0 with - | Some(ctorss_descriptors) -> ctorss_descriptors - | None -> invalid_arg "mk_datatypes: generator failed" - in - let names = Array.map fst ctorss_descriptors - in - let ctorss = - Array.map (fun (_, ctors_descriptor) -> - Array.map (fun {constructor_desc; recognizer_desc; accessor_descs} -> - let field_names = Array.map fst accessor_descs - in - let sort_refs = Array.make (Array.length accessor_descs) 0 - in - let field_sorts = - Array.mapi (fun i (_, sort) -> - try - let j = find (fun s t -> is_eq_sort ctx s t) sort sorts0 in - sort_refs.(i) <- j ; - None - with Not_found -> - Some(sort) - ) accessor_descs - in - mk_constructor ctx constructor_desc recognizer_desc field_names field_sorts sort_refs - ) ctors_descriptor - ) ctorss_descriptors - in - let constructor_lists = Array.map (mk_constructor_list ctx) ctorss - in - let sorts,_ = mk_datatypes ctx names constructor_lists - in - let datatypes = - Array.mapi (fun i sort -> - (sort, - Array.mapi (fun j ctor -> - let num_fields = Array.length (snd ctorss_descriptors.(i)).(j).accessor_descs in - let constructor, recognizer, accessors = query_constructor ctx ctor num_fields in - {constructor; recognizer; accessors} - ) ctorss.(i)) - ) sorts - in - Array.iter (fun ctor_list -> - del_constructor_list ctx ctor_list - ) constructor_lists - ; - Array.iter (fun ctors -> - Array.iter (fun ctor -> - del_constructor ctx ctor - ) ctors - ) ctorss - ; - datatypes -(* Numerals *) -let rec numeral_refine c t = - assert( get_ast_kind c t = NUMERAL_AST ); - let sort = get_sort c t in - let is_int, i = get_numeral_int c t in - if is_int then - Numeral_int (i, sort) - else - let is_int64, i = get_numeral_int64 c t in - if is_int64 then - Numeral_int64 (i, sort) - else - if get_sort_kind c sort <> REAL_SORT then - Numeral_large (get_numeral_string c t, sort) - else - let n = numeral_refine c (get_numerator c t) in - let d = numeral_refine c (get_denominator c t) in - Numeral_rational (n, d) -let to_real c x = - if get_sort_kind c (get_sort c x) = REAL_SORT then - x - else - mk_int2real c x -let rec embed_numeral c = function - | Numeral_int (i, s) -> mk_int c i s - | Numeral_int64 (i, s) -> mk_int64 c i s - | Numeral_large (l, s) -> mk_numeral c l s - | Numeral_rational (Numeral_int(n,_), Numeral_int(d,_)) -> mk_real c n d - | Numeral_rational (n, d) -> - mk_div c (to_real c (embed_numeral c n)) (to_real c (embed_numeral c d)) - (* Or should the following be used instead? - let n_str = get_numeral_string c (embed_numeral c n) in - let d_str = get_numeral_string c (embed_numeral c d) in - mk_numeral c (n_str ^ " / " ^ d_str) (mk_real_sort c) - *) -(* Terms *) -let get_app_args c a = - Array.init (get_app_num_args c a) (get_app_arg c a);; -let get_domains c d = - Array.init (get_domain_size c d) (get_domain c d);; -let get_pattern_terms c p = - Array.init (get_pattern_num_terms c p) (get_pattern c p) -let term_refine c t = - match get_ast_kind c t with - | NUMERAL_AST -> - Term_numeral (numeral_refine c t) - | APP_AST -> - let t' = to_app c t in - let f = get_app_decl c t' in - let num_args = get_app_num_args c t' in - let args = Array.init num_args (get_app_arg c t') in - let k = get_decl_kind c f in - Term_app (k, f, args) - | QUANTIFIER_AST -> - let bt = if is_quantifier_forall c t then Forall else Exists in - let w = get_quantifier_weight c t in - let np = get_quantifier_num_patterns c t in - let pats = Array.init np (get_quantifier_pattern_ast c t) in - let pats = Array.map (get_pattern_terms c) pats in - let nb = get_quantifier_num_bound c t in - let bound = - Array.init nb (fun i -> - (get_quantifier_bound_name c t i, get_quantifier_bound_sort c t i) - ) in - let body = get_quantifier_body c t in - Term_quantifier (bt, w, pats, bound, body) - | VAR_AST -> - Term_var (get_index_value c t, get_sort c t) - | _ -> - assert false -(* let mk_term c = function *) -(* | Term_numeral (numeral, sort) -> mk_numeral c numeral sort *) -(* | Term_app (kind, decl, args) -> *) -(* | Term_quantifier (strength, weight, pats, bound, body) -> *) -(* | Term_var (index, sort) -> *) -(* Refined model API *) -let model_refine c m = - let num_sorts = model_get_num_sorts c m in - let sorts = Hashtbl.create num_sorts in - for i = 0 to num_sorts - 1 do - let sort = model_get_sort c m i in - let universe = model_get_sort_universe c m sort in - Hashtbl.add sorts sort universe - done; - let num_consts = model_get_num_consts c m in - let consts = Hashtbl.create num_consts in - let arrays = Hashtbl.create 0 in - for i = 0 to num_consts - 1 do - let const_decl = model_get_const_decl c m i in - match model_get_const_interp c m const_decl with - | Some(const_interp) -> - if is_as_array c const_interp then - let array_decl = get_as_array_func_decl c const_interp in - match model_get_func_interp c m array_decl with - | Some(array_interp) -> - let num_entries = func_interp_get_num_entries c array_interp in - let tbl = Hashtbl.create num_entries in - for i = 0 to num_entries - 1 do - let entry = func_interp_get_entry c array_interp i in - assert( func_entry_get_num_args c entry = 1 ); - let arg = func_entry_get_arg c entry 0 in - let value = func_entry_get_value c entry in - Hashtbl.add tbl arg value - done; - let default = func_interp_get_else c array_interp in - Hashtbl.add arrays const_decl (tbl, default) - | None -> - () - else - Hashtbl.add consts const_decl const_interp - | None -> - () - done; - let num_funcs = model_get_num_funcs c m in - let funcs = Hashtbl.create num_funcs in - for i = 0 to num_funcs - 1 do - let func_decl = model_get_func_decl c m i in - if not (Hashtbl.mem arrays func_decl) then - match model_get_func_interp c m func_decl with - | Some(func_interp) -> - let num_entries = func_interp_get_num_entries c func_interp in - let tbl = Hashtbl.create num_entries in - for i = 0 to num_entries - 1 do - let entry = func_interp_get_entry c func_interp i in - let num_args = func_entry_get_num_args c entry in - let args = Array.init num_args (fun i -> func_entry_get_arg c entry i) in - let value = func_entry_get_value c entry in - Hashtbl.add tbl args value - done; - let default = func_interp_get_else c func_interp in - Hashtbl.add funcs func_decl (tbl, default) - | None -> - () - done; - {sorts; consts; arrays; funcs} -(* Extended parser API *) -let get_smtlib_formulas c = - Array.init (get_smtlib_num_formulas c) (get_smtlib_formula c) -let get_smtlib_assumptions c = - Array.init (get_smtlib_num_assumptions c) (get_smtlib_assumption c) -let get_smtlib_decls c = - Array.init (get_smtlib_num_decls c) (get_smtlib_decl c) -let get_smtlib_parse_results c = - (get_smtlib_formulas c, get_smtlib_assumptions c, get_smtlib_decls c) -let parse_smtlib_string_x c a1 a2 a3 a4 a5 = - parse_smtlib_string c a1 a2 a3 a4 a5 ; - get_smtlib_parse_results c -let parse_smtlib_file_x c a1 a2 a3 a4 a5 = - parse_smtlib_file c a1 a2 a3 a4 a5 ; - get_smtlib_parse_results c -let parse_smtlib_string_formula c a1 a2 a3 a4 a5 = - parse_smtlib_string c a1 a2 a3 a4 a5 ; - match get_smtlib_formulas c with [|f|] -> f | _ -> failwith "Z3: parse_smtlib_string_formula" -let parse_smtlib_file_formula c a1 a2 a3 a4 a5 = - parse_smtlib_file c a1 a2 a3 a4 a5 ; - match get_smtlib_formulas c with [|f|] -> f | _ -> failwith "Z3: parse_smtlib_file_formula" -(* Error handling *) -let get_error_msg c e = - match e with - | PARSER_ERROR -> (get_error_msg_ex c e) ^ ": " ^ (get_smtlib_error c) - | _ -> get_error_msg_ex c e -(* Refined stats API *) -let stats_refine c s = - let num_stats = stats_size c s in - let tbl = Hashtbl.create num_stats in - for i = 0 to num_stats - 1 do - let key = stats_get_key c s i in - let datum = - if stats_is_uint c s i then - Stat_int(stats_get_uint_value c s i) - else - Stat_float(stats_get_double_value c s i) in - Hashtbl.add tbl key datum - done; - tbl - - -let _ = - Printexc.register_printer (function - | Error(c,e) -> Some ("Z3 "^(get_error_msg c e)) - | _ -> None - ) - - -module V3 = struct - -(* File generated from z3V3.idl *) - -type symbol -and literals -and theory -and config -and context -and sort -and func_decl -and ast -and app -and pattern -and model -and constructor -and constructor_list - -and lbool = - | L_FALSE - | L_UNDEF - | L_TRUE - -and symbol_kind = - | INT_SYMBOL - | STRING_SYMBOL - -and parameter_kind = - | PARAMETER_INT - | PARAMETER_DOUBLE - | PARAMETER_RATIONAL - | PARAMETER_SYMBOL - | PARAMETER_SORT - | PARAMETER_AST - | PARAMETER_FUNC_DECL - -and sort_kind = - | UNINTERPRETED_SORT - | BOOL_SORT - | INT_SORT - | REAL_SORT - | BV_SORT - | ARRAY_SORT - | DATATYPE_SORT - | RELATION_SORT - | FINITE_DOMAIN_SORT - | UNKNOWN_SORT - -and ast_kind = - | NUMERAL_AST - | APP_AST - | VAR_AST - | QUANTIFIER_AST - | SORT_AST - | FUNC_DECL_AST - | UNKNOWN_AST - -and decl_kind = - | OP_TRUE - | OP_FALSE - | OP_EQ - | OP_DISTINCT - | OP_ITE - | OP_AND - | OP_OR - | OP_IFF - | OP_XOR - | OP_NOT - | OP_IMPLIES - | OP_OEQ - | OP_ANUM - | OP_AGNUM - | OP_LE - | OP_GE - | OP_LT - | OP_GT - | OP_ADD - | OP_SUB - | OP_UMINUS - | OP_MUL - | OP_DIV - | OP_IDIV - | OP_REM - | OP_MOD - | OP_TO_REAL - | OP_TO_INT - | OP_IS_INT - | OP_POWER - | OP_STORE - | OP_SELECT - | OP_CONST_ARRAY - | OP_ARRAY_MAP - | OP_ARRAY_DEFAULT - | OP_SET_UNION - | OP_SET_INTERSECT - | OP_SET_DIFFERENCE - | OP_SET_COMPLEMENT - | OP_SET_SUBSET - | OP_AS_ARRAY - | OP_BNUM - | OP_BIT1 - | OP_BIT0 - | OP_BNEG - | OP_BADD - | OP_BSUB - | OP_BMUL - | OP_BSDIV - | OP_BUDIV - | OP_BSREM - | OP_BUREM - | OP_BSMOD - | OP_BSDIV0 - | OP_BUDIV0 - | OP_BSREM0 - | OP_BUREM0 - | OP_BSMOD0 - | OP_ULEQ - | OP_SLEQ - | OP_UGEQ - | OP_SGEQ - | OP_ULT - | OP_SLT - | OP_UGT - | OP_SGT - | OP_BAND - | OP_BOR - | OP_BNOT - | OP_BXOR - | OP_BNAND - | OP_BNOR - | OP_BXNOR - | OP_CONCAT - | OP_SIGN_EXT - | OP_ZERO_EXT - | OP_EXTRACT - | OP_REPEAT - | OP_BREDOR - | OP_BREDAND - | OP_BCOMP - | OP_BSHL - | OP_BLSHR - | OP_BASHR - | OP_ROTATE_LEFT - | OP_ROTATE_RIGHT - | OP_EXT_ROTATE_LEFT - | OP_EXT_ROTATE_RIGHT - | OP_INT2BV - | OP_BV2INT - | OP_CARRY - | OP_XOR3 - | OP_PR_UNDEF - | OP_PR_TRUE - | OP_PR_ASSERTED - | OP_PR_GOAL - | OP_PR_MODUS_PONENS - | OP_PR_REFLEXIVITY - | OP_PR_SYMMETRY - | OP_PR_TRANSITIVITY - | OP_PR_TRANSITIVITY_STAR - | OP_PR_MONOTONICITY - | OP_PR_QUANT_INTRO - | OP_PR_DISTRIBUTIVITY - | OP_PR_AND_ELIM - | OP_PR_NOT_OR_ELIM - | OP_PR_REWRITE - | OP_PR_REWRITE_STAR - | OP_PR_PULL_QUANT - | OP_PR_PULL_QUANT_STAR - | OP_PR_PUSH_QUANT - | OP_PR_ELIM_UNUSED_VARS - | OP_PR_DER - | OP_PR_QUANT_INST - | OP_PR_HYPOTHESIS - | OP_PR_LEMMA - | OP_PR_UNIT_RESOLUTION - | OP_PR_IFF_TRUE - | OP_PR_IFF_FALSE - | OP_PR_COMMUTATIVITY - | OP_PR_DEF_AXIOM - | OP_PR_DEF_INTRO - | OP_PR_APPLY_DEF - | OP_PR_IFF_OEQ - | OP_PR_NNF_POS - | OP_PR_NNF_NEG - | OP_PR_NNF_STAR - | OP_PR_CNF_STAR - | OP_PR_SKOLEMIZE - | OP_PR_MODUS_PONENS_OEQ - | OP_PR_TH_LEMMA - | OP_PR_HYPER_RESOLVE - | OP_RA_STORE - | OP_RA_EMPTY - | OP_RA_IS_EMPTY - | OP_RA_JOIN - | OP_RA_UNION - | OP_RA_WIDEN - | OP_RA_PROJECT - | OP_RA_FILTER - | OP_RA_NEGATION_FILTER - | OP_RA_RENAME - | OP_RA_COMPLEMENT - | OP_RA_SELECT - | OP_RA_CLONE - | OP_FD_LT - | OP_LABEL - | OP_LABEL_LIT - | OP_DT_CONSTRUCTOR - | OP_DT_RECOGNISER - | OP_DT_ACCESSOR - | OP_UNINTERPRETED - -and param_kind = - | PK_UINT - | PK_BOOL - | PK_DOUBLE - | PK_SYMBOL - | PK_STRING - | PK_OTHER - | PK_INVALID - -and search_failure = - | NO_FAILURE - | UNKNOWN - | TIMEOUT - | MEMOUT_WATERMARK - | CANCELED - | NUM_CONFLICTS - | THEORY - | QUANTIFIERS - -and ast_print_mode = - | PRINT_SMTLIB_FULL - | PRINT_LOW_LEVEL - | PRINT_SMTLIB_COMPLIANT - | PRINT_SMTLIB2_COMPLIANT - - -external global_param_set : string -> string -> unit - = "camlidl_z3V3_Z3_global_param_set" - -external global_param_reset_all : unit -> unit - = "camlidl_z3V3_Z3_global_param_reset_all" - -external global_param_get : string -> string option - = "camlidl_z3V3_Z3_global_param_get" - -external mk_config : unit -> config - = "camlidl_z3V3_Z3_mk_config" - -external del_config : config -> unit - = "camlidl_z3V3_Z3_del_config" - -external set_param_value : config -> string -> string -> unit - = "camlidl_z3V3_Z3_set_param_value" - -external mk_context : config -> context - = "camlidl_z3V3_Z3_mk_context" - -external del_context : context -> unit - = "camlidl_z3V3_Z3_del_context" - -external update_param_value : context -> string -> string -> unit - = "camlidl_z3V3_Z3_update_param_value" - -external get_param_value : context -> string -> string option - = "camlidl_z3V3_Z3_get_param_value" - -external mk_int_symbol : context -> int -> symbol - = "camlidl_z3V3_Z3_mk_int_symbol" - -external mk_string_symbol : context -> string -> symbol - = "camlidl_z3V3_Z3_mk_string_symbol" - -external mk_uninterpreted_sort : context -> symbol -> sort - = "camlidl_z3V3_Z3_mk_uninterpreted_sort" - -external mk_bool_sort : context -> sort - = "camlidl_z3V3_Z3_mk_bool_sort" - -external mk_int_sort : context -> sort - = "camlidl_z3V3_Z3_mk_int_sort" - -external mk_real_sort : context -> sort - = "camlidl_z3V3_Z3_mk_real_sort" - -external mk_bv_sort : context -> int -> sort - = "camlidl_z3V3_Z3_mk_bv_sort" - -external mk_finite_domain_sort : context -> symbol -> int64 -> sort - = "camlidl_z3V3_Z3_mk_finite_domain_sort" - -external mk_array_sort : context -> sort -> sort -> sort - = "camlidl_z3V3_Z3_mk_array_sort" - -external mk_tuple_sort : context -> symbol -> symbol array -> sort array -> sort * func_decl * func_decl array - = "camlidl_z3V3_Z3_mk_tuple_sort" - -external mk_enumeration_sort : context -> symbol -> symbol array -> sort * func_decl array * func_decl array - = "camlidl_z3V3_Z3_mk_enumeration_sort" - -external mk_list_sort : context -> symbol -> sort -> sort * func_decl * func_decl * func_decl * func_decl * func_decl * func_decl - = "camlidl_z3V3_Z3_mk_list_sort" - -external mk_constructor : context -> symbol -> symbol -> symbol array -> sort array -> int array -> constructor - = "camlidl_z3V3_Z3_mk_constructor_bytecode" "camlidl_z3V3_Z3_mk_constructor" - -external del_constructor : context -> constructor -> unit - = "camlidl_z3V3_Z3_del_constructor" - -external mk_datatype : context -> symbol -> constructor array -> sort * constructor array - = "camlidl_z3V3_Z3_mk_datatype" - -external mk_constructor_list : context -> constructor array -> constructor_list - = "camlidl_z3V3_Z3_mk_constructor_list" - -external del_constructor_list : context -> constructor_list -> unit - = "camlidl_z3V3_Z3_del_constructor_list" - -external mk_datatypes : context -> symbol array -> constructor_list array -> sort array * constructor_list array - = "camlidl_z3V3_Z3_mk_datatypes" - -external query_constructor : context -> constructor -> int -> func_decl * func_decl * func_decl array - = "camlidl_z3V3_Z3_query_constructor" - -external mk_func_decl : context -> symbol -> sort array -> sort -> func_decl - = "camlidl_z3V3_Z3_mk_func_decl" - -external mk_app : context -> func_decl -> ast array -> ast - = "camlidl_z3V3_Z3_mk_app" - -external mk_const : context -> symbol -> sort -> ast - = "camlidl_z3V3_Z3_mk_const" - -external mk_fresh_func_decl : context -> string -> sort array -> sort -> func_decl - = "camlidl_z3V3_Z3_mk_fresh_func_decl" - -external mk_fresh_const : context -> string -> sort -> ast - = "camlidl_z3V3_Z3_mk_fresh_const" - -external mk_true : context -> ast - = "camlidl_z3V3_Z3_mk_true" - -external mk_false : context -> ast - = "camlidl_z3V3_Z3_mk_false" - -external mk_eq : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_eq" - -external mk_distinct : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_distinct" - -external mk_not : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_not" - -external mk_ite : context -> ast -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_ite" - -external mk_iff : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_iff" - -external mk_implies : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_implies" - -external mk_xor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_xor" - -external mk_and : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_and" - -external mk_or : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_or" - -external mk_add : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_add" - -external mk_mul : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_mul" - -external mk_sub : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_sub" - -external mk_unary_minus : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_unary_minus" - -external mk_div : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_div" - -external mk_mod : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_mod" - -external mk_rem : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_rem" - -external mk_power : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_power" - -external mk_lt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_lt" - -external mk_le : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_le" - -external mk_gt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_gt" - -external mk_ge : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_ge" - -external mk_int2real : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_int2real" - -external mk_real2int : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_real2int" - -external mk_is_int : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_is_int" - -external mk_bvnot : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvnot" - -external mk_bvredand : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvredand" - -external mk_bvredor : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvredor" - -external mk_bvand : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvand" - -external mk_bvor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvor" - -external mk_bvxor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvxor" - -external mk_bvnand : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvnand" - -external mk_bvnor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvnor" - -external mk_bvxnor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvxnor" - -external mk_bvneg : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvneg" - -external mk_bvadd : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvadd" - -external mk_bvsub : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsub" - -external mk_bvmul : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvmul" - -external mk_bvudiv : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvudiv" - -external mk_bvsdiv : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsdiv" - -external mk_bvurem : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvurem" - -external mk_bvsrem : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsrem" - -external mk_bvsmod : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsmod" - -external mk_bvult : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvult" - -external mk_bvslt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvslt" - -external mk_bvule : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvule" - -external mk_bvsle : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsle" - -external mk_bvuge : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvuge" - -external mk_bvsge : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsge" - -external mk_bvugt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvugt" - -external mk_bvsgt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsgt" - -external mk_concat : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_concat" - -external mk_extract : context -> int -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_extract" - -external mk_sign_ext : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_sign_ext" - -external mk_zero_ext : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_zero_ext" - -external mk_repeat : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_repeat" - -external mk_bvshl : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvshl" - -external mk_bvlshr : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvlshr" - -external mk_bvashr : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvashr" - -external mk_rotate_left : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_rotate_left" - -external mk_rotate_right : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_rotate_right" - -external mk_ext_rotate_left : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_ext_rotate_left" - -external mk_ext_rotate_right : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_ext_rotate_right" - -external mk_int2bv : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_int2bv" - -external mk_bv2int : context -> ast -> bool -> ast - = "camlidl_z3V3_Z3_mk_bv2int" - -external mk_bvadd_no_overflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3V3_Z3_mk_bvadd_no_overflow" - -external mk_bvadd_no_underflow : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvadd_no_underflow" - -external mk_bvsub_no_overflow : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsub_no_overflow" - -external mk_bvsub_no_underflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3V3_Z3_mk_bvsub_no_underflow" - -external mk_bvsdiv_no_overflow : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsdiv_no_overflow" - -external mk_bvneg_no_overflow : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvneg_no_overflow" - -external mk_bvmul_no_overflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3V3_Z3_mk_bvmul_no_overflow" - -external mk_bvmul_no_underflow : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvmul_no_underflow" - -external mk_select : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_select" - -external mk_store : context -> ast -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_store" - -external mk_const_array : context -> sort -> ast -> ast - = "camlidl_z3V3_Z3_mk_const_array" - -external mk_map : context -> func_decl -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_map" - -external mk_array_default : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_array_default" - -external mk_set_sort : context -> sort -> sort - = "camlidl_z3V3_Z3_mk_set_sort" - -external mk_empty_set : context -> sort -> ast - = "camlidl_z3V3_Z3_mk_empty_set" - -external mk_full_set : context -> sort -> ast - = "camlidl_z3V3_Z3_mk_full_set" - -external mk_set_add : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_add" - -external mk_set_del : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_del" - -external mk_set_union : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_set_union" - -external mk_set_intersect : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_set_intersect" - -external mk_set_difference : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_difference" - -external mk_set_complement : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_complement" - -external mk_set_member : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_member" - -external mk_set_subset : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_subset" - -external mk_numeral : context -> string -> sort -> ast - = "camlidl_z3V3_Z3_mk_numeral" - -external mk_real : context -> int -> int -> ast - = "camlidl_z3V3_Z3_mk_real" - -external mk_int : context -> int -> sort -> ast - = "camlidl_z3V3_Z3_mk_int" - -external mk_int64 : context -> int64 -> sort -> ast - = "camlidl_z3V3_Z3_mk_int64" - -external mk_pattern : context -> ast array -> pattern - = "camlidl_z3V3_Z3_mk_pattern" - -external mk_bound : context -> int -> sort -> ast - = "camlidl_z3V3_Z3_mk_bound" - -external mk_forall : context -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3V3_Z3_mk_forall_bytecode" "camlidl_z3V3_Z3_mk_forall" - -external mk_exists : context -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3V3_Z3_mk_exists_bytecode" "camlidl_z3V3_Z3_mk_exists" - -external mk_quantifier : context -> bool -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3V3_Z3_mk_quantifier_bytecode" "camlidl_z3V3_Z3_mk_quantifier" - -external mk_quantifier_ex : context -> bool -> int -> symbol -> symbol -> pattern array -> ast array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3V3_Z3_mk_quantifier_ex_bytecode" "camlidl_z3V3_Z3_mk_quantifier_ex" - -external mk_forall_const : context -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3V3_Z3_mk_forall_const" - -external mk_exists_const : context -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3V3_Z3_mk_exists_const" - -external mk_quantifier_const : context -> bool -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3V3_Z3_mk_quantifier_const_bytecode" "camlidl_z3V3_Z3_mk_quantifier_const" - -external mk_quantifier_const_ex : context -> bool -> int -> symbol -> symbol -> app array -> pattern array -> ast array -> ast -> ast - = "camlidl_z3V3_Z3_mk_quantifier_const_ex_bytecode" "camlidl_z3V3_Z3_mk_quantifier_const_ex" - -external get_symbol_kind : context -> symbol -> symbol_kind - = "camlidl_z3V3_Z3_get_symbol_kind" - -external get_symbol_int : context -> symbol -> int - = "camlidl_z3V3_Z3_get_symbol_int" - -external get_symbol_string : context -> symbol -> string - = "camlidl_z3V3_Z3_get_symbol_string" - -external get_sort_name : context -> sort -> symbol - = "camlidl_z3V3_Z3_get_sort_name" - -external get_sort_id : context -> sort -> int - = "camlidl_z3V3_Z3_get_sort_id" - -external sort_to_ast : context -> sort -> ast - = "camlidl_z3V3_Z3_sort_to_ast" - -external is_eq_sort : context -> sort -> sort -> bool - = "camlidl_z3V3_Z3_is_eq_sort" - -external get_sort_kind : context -> sort -> sort_kind - = "camlidl_z3V3_Z3_get_sort_kind" - -external get_bv_sort_size : context -> sort -> int - = "camlidl_z3V3_Z3_get_bv_sort_size" - -external get_finite_domain_sort_size : context -> sort -> int64 option - = "camlidl_z3V3_Z3_get_finite_domain_sort_size" - -external get_array_sort_domain : context -> sort -> sort - = "camlidl_z3V3_Z3_get_array_sort_domain" - -external get_array_sort_range : context -> sort -> sort - = "camlidl_z3V3_Z3_get_array_sort_range" - -external get_tuple_sort_mk_decl : context -> sort -> func_decl - = "camlidl_z3V3_Z3_get_tuple_sort_mk_decl" - -external get_tuple_sort_num_fields : context -> sort -> int - = "camlidl_z3V3_Z3_get_tuple_sort_num_fields" - -external get_tuple_sort_field_decl : context -> sort -> int -> func_decl - = "camlidl_z3V3_Z3_get_tuple_sort_field_decl" - -external get_datatype_sort_num_constructors : context -> sort -> int - = "camlidl_z3V3_Z3_get_datatype_sort_num_constructors" - -external get_datatype_sort_constructor : context -> sort -> int -> func_decl - = "camlidl_z3V3_Z3_get_datatype_sort_constructor" - -external get_datatype_sort_recognizer : context -> sort -> int -> func_decl - = "camlidl_z3V3_Z3_get_datatype_sort_recognizer" - -external get_datatype_sort_constructor_accessor : context -> sort -> int -> int -> func_decl - = "camlidl_z3V3_Z3_get_datatype_sort_constructor_accessor" - -external get_relation_arity : context -> sort -> int - = "camlidl_z3V3_Z3_get_relation_arity" - -external get_relation_column : context -> sort -> int -> sort - = "camlidl_z3V3_Z3_get_relation_column" - -external func_decl_to_ast : context -> func_decl -> ast - = "camlidl_z3V3_Z3_func_decl_to_ast" - -external is_eq_func_decl : context -> func_decl -> func_decl -> bool - = "camlidl_z3V3_Z3_is_eq_func_decl" - -external get_func_decl_id : context -> func_decl -> int - = "camlidl_z3V3_Z3_get_func_decl_id" - -external get_decl_name : context -> func_decl -> symbol - = "camlidl_z3V3_Z3_get_decl_name" - -external get_decl_kind : context -> func_decl -> decl_kind - = "camlidl_z3V3_Z3_get_decl_kind" - -external get_domain_size : context -> func_decl -> int - = "camlidl_z3V3_Z3_get_domain_size" - -external get_arity : context -> func_decl -> int - = "camlidl_z3V3_Z3_get_arity" - -external get_domain : context -> func_decl -> int -> sort - = "camlidl_z3V3_Z3_get_domain" - -external get_range : context -> func_decl -> sort - = "camlidl_z3V3_Z3_get_range" - -external get_decl_num_parameters : context -> func_decl -> int - = "camlidl_z3V3_Z3_get_decl_num_parameters" - -external get_decl_parameter_kind : context -> func_decl -> int -> parameter_kind - = "camlidl_z3V3_Z3_get_decl_parameter_kind" - -external get_decl_int_parameter : context -> func_decl -> int -> int - = "camlidl_z3V3_Z3_get_decl_int_parameter" - -external get_decl_double_parameter : context -> func_decl -> int -> float - = "camlidl_z3V3_Z3_get_decl_double_parameter" - -external get_decl_symbol_parameter : context -> func_decl -> int -> symbol - = "camlidl_z3V3_Z3_get_decl_symbol_parameter" - -external get_decl_sort_parameter : context -> func_decl -> int -> sort - = "camlidl_z3V3_Z3_get_decl_sort_parameter" - -external get_decl_ast_parameter : context -> func_decl -> int -> ast - = "camlidl_z3V3_Z3_get_decl_ast_parameter" - -external get_decl_func_decl_parameter : context -> func_decl -> int -> func_decl - = "camlidl_z3V3_Z3_get_decl_func_decl_parameter" - -external get_decl_rational_parameter : context -> func_decl -> int -> string - = "camlidl_z3V3_Z3_get_decl_rational_parameter" - -external app_to_ast : context -> app -> ast - = "camlidl_z3V3_Z3_app_to_ast" - -external get_app_decl : context -> app -> func_decl - = "camlidl_z3V3_Z3_get_app_decl" - -external get_app_num_args : context -> app -> int - = "camlidl_z3V3_Z3_get_app_num_args" - -external get_app_arg : context -> app -> int -> ast - = "camlidl_z3V3_Z3_get_app_arg" - -external is_eq_ast : context -> ast -> ast -> bool - = "camlidl_z3V3_Z3_is_eq_ast" - -external get_ast_id : context -> ast -> int - = "camlidl_z3V3_Z3_get_ast_id" - -external get_ast_hash : context -> ast -> int - = "camlidl_z3V3_Z3_get_ast_hash" - -external get_sort : context -> ast -> sort - = "camlidl_z3V3_Z3_get_sort" - -external is_well_sorted : context -> ast -> bool - = "camlidl_z3V3_Z3_is_well_sorted" - -external get_bool_value : context -> ast -> lbool - = "camlidl_z3V3_Z3_get_bool_value" - -external get_ast_kind : context -> ast -> ast_kind - = "camlidl_z3V3_Z3_get_ast_kind" - -external is_app : context -> ast -> bool - = "camlidl_z3V3_Z3_is_app" - -external is_numeral_ast : context -> ast -> bool - = "camlidl_z3V3_Z3_is_numeral_ast" - -external is_algebraic_number : context -> ast -> bool - = "camlidl_z3V3_Z3_is_algebraic_number" - -external to_app : context -> ast -> app - = "camlidl_z3V3_Z3_to_app" - -external to_func_decl : context -> ast -> func_decl - = "camlidl_z3V3_Z3_to_func_decl" - -external get_numeral_string : context -> ast -> string - = "camlidl_z3V3_Z3_get_numeral_string" - -external get_numeral_decimal_string : context -> ast -> int -> string - = "camlidl_z3V3_Z3_get_numeral_decimal_string" - -external get_numerator : context -> ast -> ast - = "camlidl_z3V3_Z3_get_numerator" - -external get_denominator : context -> ast -> ast - = "camlidl_z3V3_Z3_get_denominator" - -external get_numeral_small : context -> ast -> bool * int64 * int64 - = "camlidl_z3V3_Z3_get_numeral_small" - -external get_numeral_int : context -> ast -> bool * int - = "camlidl_z3V3_Z3_get_numeral_int" - -external get_numeral_int64 : context -> ast -> bool * int64 - = "camlidl_z3V3_Z3_get_numeral_int64" - -external get_numeral_rational_int64 : context -> ast -> bool * int64 * int64 - = "camlidl_z3V3_Z3_get_numeral_rational_int64" - -external get_algebraic_number_lower : context -> ast -> int -> ast - = "camlidl_z3V3_Z3_get_algebraic_number_lower" - -external get_algebraic_number_upper : context -> ast -> int -> ast - = "camlidl_z3V3_Z3_get_algebraic_number_upper" - -external pattern_to_ast : context -> pattern -> ast - = "camlidl_z3V3_Z3_pattern_to_ast" - -external get_pattern_num_terms : context -> pattern -> int - = "camlidl_z3V3_Z3_get_pattern_num_terms" - -external get_pattern : context -> pattern -> int -> ast - = "camlidl_z3V3_Z3_get_pattern" - -external get_index_value : context -> ast -> int - = "camlidl_z3V3_Z3_get_index_value" - -external is_quantifier_forall : context -> ast -> bool - = "camlidl_z3V3_Z3_is_quantifier_forall" - -external get_quantifier_weight : context -> ast -> int - = "camlidl_z3V3_Z3_get_quantifier_weight" - -external get_quantifier_num_patterns : context -> ast -> int - = "camlidl_z3V3_Z3_get_quantifier_num_patterns" - -external get_quantifier_pattern_ast : context -> ast -> int -> pattern - = "camlidl_z3V3_Z3_get_quantifier_pattern_ast" - -external get_quantifier_num_no_patterns : context -> ast -> int - = "camlidl_z3V3_Z3_get_quantifier_num_no_patterns" - -external get_quantifier_no_pattern_ast : context -> ast -> int -> ast - = "camlidl_z3V3_Z3_get_quantifier_no_pattern_ast" - -external get_quantifier_num_bound : context -> ast -> int - = "camlidl_z3V3_Z3_get_quantifier_num_bound" - -external get_quantifier_bound_name : context -> ast -> int -> symbol - = "camlidl_z3V3_Z3_get_quantifier_bound_name" - -external get_quantifier_bound_sort : context -> ast -> int -> sort - = "camlidl_z3V3_Z3_get_quantifier_bound_sort" - -external get_quantifier_body : context -> ast -> ast - = "camlidl_z3V3_Z3_get_quantifier_body" - -external simplify : context -> ast -> ast - = "camlidl_z3V3_Z3_simplify" - -external update_term : context -> ast -> ast array -> ast - = "camlidl_z3V3_Z3_update_term" - -external substitute : context -> ast -> ast array -> ast array -> ast - = "camlidl_z3V3_Z3_substitute" - -external substitute_vars : context -> ast -> ast array -> ast - = "camlidl_z3V3_Z3_substitute_vars" - -external open_log : string -> bool - = "camlidl_z3V3_Z3_open_log" - -external append_log : string -> unit - = "camlidl_z3V3_Z3_append_log" - -external close_log : unit -> unit - = "camlidl_z3V3_Z3_close_log" - -external toggle_warning_messages : bool -> unit - = "camlidl_z3V3_Z3_toggle_warning_messages" - -external set_ast_print_mode : context -> ast_print_mode -> unit - = "camlidl_z3V3_Z3_set_ast_print_mode" - -external ast_to_string : context -> ast -> string - = "camlidl_z3V3_Z3_ast_to_string" - -external pattern_to_string : context -> pattern -> string - = "camlidl_z3V3_Z3_pattern_to_string" - -external sort_to_string : context -> sort -> string - = "camlidl_z3V3_Z3_sort_to_string" - -external func_decl_to_string : context -> func_decl -> string - = "camlidl_z3V3_Z3_func_decl_to_string" - -external model_to_string : context -> model -> string - = "camlidl_z3V3_Z3_model_to_string" - -external benchmark_to_smtlib_string : context -> string -> string -> string -> string -> ast array -> ast -> string - = "camlidl_z3V3_Z3_benchmark_to_smtlib_string_bytecode" "camlidl_z3V3_Z3_benchmark_to_smtlib_string" - -external parse_smtlib2_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - = "camlidl_z3V3_Z3_parse_smtlib2_string_bytecode" "camlidl_z3V3_Z3_parse_smtlib2_string" - -external parse_smtlib2_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - = "camlidl_z3V3_Z3_parse_smtlib2_file_bytecode" "camlidl_z3V3_Z3_parse_smtlib2_file" - -external parse_smtlib_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - = "camlidl_z3V3_Z3_parse_smtlib_string_bytecode" "camlidl_z3V3_Z3_parse_smtlib_string" - -external parse_smtlib_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - = "camlidl_z3V3_Z3_parse_smtlib_file_bytecode" "camlidl_z3V3_Z3_parse_smtlib_file" - -external get_smtlib_num_formulas : context -> int - = "camlidl_z3V3_Z3_get_smtlib_num_formulas" - -external get_smtlib_formula : context -> int -> ast - = "camlidl_z3V3_Z3_get_smtlib_formula" - -external get_smtlib_num_assumptions : context -> int - = "camlidl_z3V3_Z3_get_smtlib_num_assumptions" - -external get_smtlib_assumption : context -> int -> ast - = "camlidl_z3V3_Z3_get_smtlib_assumption" - -external get_smtlib_num_decls : context -> int - = "camlidl_z3V3_Z3_get_smtlib_num_decls" - -external get_smtlib_decl : context -> int -> func_decl - = "camlidl_z3V3_Z3_get_smtlib_decl" - -external get_smtlib_num_sorts : context -> int - = "camlidl_z3V3_Z3_get_smtlib_num_sorts" - -external get_smtlib_sort : context -> int -> sort - = "camlidl_z3V3_Z3_get_smtlib_sort" - -external get_smtlib_error : context -> string - = "camlidl_z3V3_Z3_get_smtlib_error" - -external get_version : unit -> int * int * int * int - = "camlidl_z3V3_Z3_get_version" - -external enable_trace : string -> unit - = "camlidl_z3V3_Z3_enable_trace" - -external disable_trace : string -> unit - = "camlidl_z3V3_Z3_disable_trace" - -external reset_memory : unit -> unit - = "camlidl_z3V3_Z3_reset_memory" - -external theory_mk_sort : context -> theory -> symbol -> sort - = "camlidl_z3V3_Z3_theory_mk_sort" - -external theory_mk_value : context -> theory -> symbol -> sort -> ast - = "camlidl_z3V3_Z3_theory_mk_value" - -external theory_mk_constant : context -> theory -> symbol -> sort -> ast - = "camlidl_z3V3_Z3_theory_mk_constant" - -external theory_mk_func_decl : context -> theory -> symbol -> sort array -> sort -> func_decl - = "camlidl_z3V3_Z3_theory_mk_func_decl" - -external theory_get_context : theory -> context - = "camlidl_z3V3_Z3_theory_get_context" - -external theory_assert_axiom : theory -> ast -> unit - = "camlidl_z3V3_Z3_theory_assert_axiom" - -external theory_assume_eq : theory -> ast -> ast -> unit - = "camlidl_z3V3_Z3_theory_assume_eq" - -external theory_enable_axiom_simplification : theory -> bool -> unit - = "camlidl_z3V3_Z3_theory_enable_axiom_simplification" - -external theory_get_eqc_root : theory -> ast -> ast - = "camlidl_z3V3_Z3_theory_get_eqc_root" - -external theory_get_eqc_next : theory -> ast -> ast - = "camlidl_z3V3_Z3_theory_get_eqc_next" - -external theory_get_num_parents : theory -> ast -> int - = "camlidl_z3V3_Z3_theory_get_num_parents" - -external theory_get_parent : theory -> ast -> int -> ast - = "camlidl_z3V3_Z3_theory_get_parent" - -external theory_is_value : theory -> ast -> bool - = "camlidl_z3V3_Z3_theory_is_value" - -external theory_is_decl : theory -> func_decl -> bool - = "camlidl_z3V3_Z3_theory_is_decl" - -external theory_get_num_elems : theory -> int - = "camlidl_z3V3_Z3_theory_get_num_elems" - -external theory_get_elem : theory -> int -> ast - = "camlidl_z3V3_Z3_theory_get_elem" - -external theory_get_num_apps : theory -> int - = "camlidl_z3V3_Z3_theory_get_num_apps" - -external theory_get_app : theory -> int -> ast - = "camlidl_z3V3_Z3_theory_get_app" - -external mk_injective_function : context -> symbol -> sort array -> sort -> func_decl - = "camlidl_z3V3_Z3_mk_injective_function" - -external set_logic : context -> string -> bool - = "camlidl_z3V3_Z3_set_logic" - -external push : context -> unit - = "camlidl_z3V3_Z3_push" - -external pop : context -> int -> unit - = "camlidl_z3V3_Z3_pop" - -external get_num_scopes : context -> int - = "camlidl_z3V3_Z3_get_num_scopes" - -external persist_ast : context -> ast -> int -> unit - = "camlidl_z3V3_Z3_persist_ast" - -external assert_cnstr : context -> ast -> unit - = "camlidl_z3V3_Z3_assert_cnstr" - -external check_and_get_model : context -> lbool * model - = "camlidl_z3V3_Z3_check_and_get_model" - -external check : context -> lbool - = "camlidl_z3V3_Z3_check" - -external check_assumptions : context -> ast array -> int -> ast array -> lbool * model * ast * int * ast array - = "camlidl_z3V3_Z3_check_assumptions" - -external del_model : context -> model -> unit - = "camlidl_z3V3_Z3_del_model" - -external soft_check_cancel : context -> unit - = "camlidl_z3V3_Z3_soft_check_cancel" - -external get_search_failure : context -> search_failure - = "camlidl_z3V3_Z3_get_search_failure" - -external mk_label : context -> symbol -> bool -> ast -> ast - = "camlidl_z3V3_Z3_mk_label" - -external get_relevant_labels : context -> literals - = "camlidl_z3V3_Z3_get_relevant_labels" - -external get_relevant_literals : context -> literals - = "camlidl_z3V3_Z3_get_relevant_literals" - -external get_guessed_literals : context -> literals - = "camlidl_z3V3_Z3_get_guessed_literals" - -external del_literals : context -> literals -> unit - = "camlidl_z3V3_Z3_del_literals" - -external get_num_literals : context -> literals -> int - = "camlidl_z3V3_Z3_get_num_literals" - -external get_label_symbol : context -> literals -> int -> symbol - = "camlidl_z3V3_Z3_get_label_symbol" - -external get_literal : context -> literals -> int -> ast - = "camlidl_z3V3_Z3_get_literal" - -external disable_literal : context -> literals -> int -> unit - = "camlidl_z3V3_Z3_disable_literal" - -external block_literals : context -> literals -> unit - = "camlidl_z3V3_Z3_block_literals" - -external get_model_num_constants : context -> model -> int - = "camlidl_z3V3_Z3_get_model_num_constants" - -external get_model_constant : context -> model -> int -> func_decl - = "camlidl_z3V3_Z3_get_model_constant" - -external get_model_num_funcs : context -> model -> int - = "camlidl_z3V3_Z3_get_model_num_funcs" - -external get_model_func_decl : context -> model -> int -> func_decl - = "camlidl_z3V3_Z3_get_model_func_decl" - -external eval_func_decl : context -> model -> func_decl -> bool * ast - = "camlidl_z3V3_Z3_eval_func_decl" - -external is_array_value : context -> model -> ast -> bool * int - = "camlidl_z3V3_Z3_is_array_value" - -external get_array_value : context -> model -> ast -> ast array -> ast array -> ast array * ast array * ast - = "camlidl_z3V3_Z3_get_array_value" - -external get_model_func_else : context -> model -> int -> ast - = "camlidl_z3V3_Z3_get_model_func_else" - -external get_model_func_num_entries : context -> model -> int -> int - = "camlidl_z3V3_Z3_get_model_func_num_entries" - -external get_model_func_entry_num_args : context -> model -> int -> int -> int - = "camlidl_z3V3_Z3_get_model_func_entry_num_args" - -external get_model_func_entry_arg : context -> model -> int -> int -> int -> ast - = "camlidl_z3V3_Z3_get_model_func_entry_arg" - -external get_model_func_entry_value : context -> model -> int -> int -> ast - = "camlidl_z3V3_Z3_get_model_func_entry_value" - -external eval : context -> model -> ast -> bool * ast - = "camlidl_z3V3_Z3_eval" - -external eval_decl : context -> model -> func_decl -> ast array -> bool * ast - = "camlidl_z3V3_Z3_eval_decl" - -external context_to_string : context -> string - = "camlidl_z3V3_Z3_context_to_string" - -external statistics_to_string : context -> string - = "camlidl_z3V3_Z3_statistics_to_string" - -external get_context_assignment : context -> ast - = "camlidl_z3V3_Z3_get_context_assignment" - - -(* Internal auxillary functions: *) -(* Transform a pair of arrays into an array of pairs *) -let array_combine a b = - if Array.length a <> Array.length b then raise (Invalid_argument "array_combine"); - Array.init (Array.length a) (fun i->(a.(i),b.(i)));; -(* [a |> b] is the pipeline operator for [b(a)] *) -let ( |> ) x f = f x;; -(* Extensions, except for refinement: *) -let mk_context_x configs = - let config = mk_config() in - let f(param_id,param_value) = set_param_value config param_id param_value in - Array.iter f configs; - let context = mk_context config in - del_config config; - context;; -let get_app_args c a = - Array.init (get_app_num_args c a) (get_app_arg c a);; -let get_domains c d = - Array.init (get_domain_size c d) (get_domain c d);; -let get_array_sort c t = (get_array_sort_domain c t, get_array_sort_range c t);; -let get_tuple_sort c ty = - (get_tuple_sort_mk_decl c ty, - Array.init (get_tuple_sort_num_fields c ty) (get_tuple_sort_field_decl c ty));; -type datatype_constructor_refined = { - constructor : func_decl; - recognizer : func_decl; - accessors : func_decl array -} -let get_datatype_sort c ty = - Array.init (get_datatype_sort_num_constructors c ty) - (fun idx_c -> - let constr = get_datatype_sort_constructor c ty idx_c in - let recog = get_datatype_sort_recognizer c ty idx_c in - let num_acc = get_domain_size c constr in - { constructor = constr; - recognizer = recog; - accessors = Array.init num_acc (get_datatype_sort_constructor_accessor c ty idx_c); - }) -let get_model_constants c m = - Array.init (get_model_num_constants c m) (get_model_constant c m);; -let get_model_func_entry c m i j = - (Array.init - (get_model_func_entry_num_args c m i j) - (get_model_func_entry_arg c m i j), - get_model_func_entry_value c m i j);; -let get_model_func_entries c m i = - Array.init (get_model_func_num_entries c m i) (get_model_func_entry c m i);; -let get_model_funcs c m = - Array.init (get_model_num_funcs c m) - (fun i->(get_model_func_decl c m i |> get_decl_name c, - get_model_func_entries c m i, - get_model_func_else c m i));; -let get_smtlib_formulas c = - Array.init (get_smtlib_num_formulas c) (get_smtlib_formula c);; -let get_smtlib_assumptions c = - Array.init (get_smtlib_num_assumptions c) (get_smtlib_assumption c);; -let get_smtlib_decls c = - Array.init (get_smtlib_num_decls c) (get_smtlib_decl c);; -let get_smtlib_parse_results c = - (get_smtlib_formulas c, get_smtlib_assumptions c, get_smtlib_decls c);; -let parse_smtlib_string_formula c a1 a2 a3 a4 a5 = - (parse_smtlib_string c a1 a2 a3 a4 a5; - match get_smtlib_formulas c with [|f|] -> f | _ -> failwith "Z3: parse_smtlib_string_formula");; -let parse_smtlib_file_formula c a1 a2 a3 a4 a5 = - (parse_smtlib_file c a1 a2 a3 a4 a5; - match get_smtlib_formulas c with [|f|] -> f | _ -> failwith "Z3: parse_smtlib_file_formula");; -let parse_smtlib_string_x c a1 a2 a3 a4 a5 = - (parse_smtlib_string c a1 a2 a3 a4 a5; get_smtlib_parse_results c);; -let parse_smtlib_file_x c a1 a2 a3 a4 a5 = - (parse_smtlib_file c a1 a2 a3 a4 a5; get_smtlib_parse_results c);; -(* Refinement: *) -type symbol_refined = - | Symbol_int of int - | Symbol_string of string - | Symbol_unknown;; -let symbol_refine c s = - match get_symbol_kind c s with - | INT_SYMBOL -> Symbol_int (get_symbol_int c s) - | STRING_SYMBOL -> Symbol_string (get_symbol_string c s);; -type sort_refined = - | Sort_uninterpreted of symbol - | Sort_bool - | Sort_int - | Sort_real - | Sort_bv of int - | Sort_array of (sort * sort) - | Sort_datatype of datatype_constructor_refined array - | Sort_relation - | Sort_finite_domain - | Sort_unknown of symbol;; -let sort_refine c ty = - match get_sort_kind c ty with - | UNINTERPRETED_SORT -> Sort_uninterpreted (get_sort_name c ty) - | BOOL_SORT -> Sort_bool - | INT_SORT -> Sort_int - | REAL_SORT -> Sort_real - | BV_SORT -> Sort_bv (get_bv_sort_size c ty) - | ARRAY_SORT -> Sort_array (get_array_sort_domain c ty, get_array_sort_range c ty) - | DATATYPE_SORT -> Sort_datatype (get_datatype_sort c ty) - | RELATION_SORT -> Sort_relation - | FINITE_DOMAIN_SORT -> Sort_finite_domain - | UNKNOWN_SORT -> Sort_unknown (get_sort_name c ty);; -let get_pattern_terms c p = - Array.init (get_pattern_num_terms c p) (get_pattern c p) -type binder_type = | Forall | Exists -type numeral_refined = - | Numeral_small of int64 * int64 - | Numeral_large of string -type term_refined = - | Term_app of decl_kind * func_decl * ast array - | Term_quantifier of binder_type * int * ast array array * (symbol *sort) array * ast - | Term_numeral of numeral_refined * sort - | Term_var of int * sort -let term_refine c t = - match get_ast_kind c t with - | NUMERAL_AST -> - let (is_small, n, d) = get_numeral_small c t in - if is_small then - Term_numeral(Numeral_small(n,d), get_sort c t) - else - Term_numeral(Numeral_large(get_numeral_string c t), get_sort c t) - | APP_AST -> - let t' = to_app c t in - let f = get_app_decl c t' in - let num_args = get_app_num_args c t' in - let args = Array.init num_args (get_app_arg c t') in - let k = get_decl_kind c f in - Term_app (k, f, args) - | QUANTIFIER_AST -> - let bt = if is_quantifier_forall c t then Forall else Exists in - let w = get_quantifier_weight c t in - let np = get_quantifier_num_patterns c t in - let pats = Array.init np (get_quantifier_pattern_ast c t) in - let pats = Array.map (get_pattern_terms c) pats in - let nb = get_quantifier_num_bound c t in - let bound = Array.init nb - (fun i -> (get_quantifier_bound_name c t i, get_quantifier_bound_sort c t i)) in - let body = get_quantifier_body c t in - Term_quantifier(bt, w, pats, bound, body) - | VAR_AST -> - Term_var(get_index_value c t, get_sort c t) - | _ -> assert false -type theory_callbacks = - { - mutable delete_theory : unit -> unit; - mutable reduce_eq : ast -> ast -> ast option; - mutable reduce_app : func_decl -> ast array -> ast option; - mutable reduce_distinct : ast array -> ast option; - mutable final_check : unit -> bool; - mutable new_app : ast -> unit; - mutable new_elem : ast -> unit; - mutable init_search: unit -> unit; - mutable push: unit -> unit; - mutable pop: unit -> unit; - mutable restart : unit -> unit; - mutable reset: unit -> unit; - mutable new_eq : ast -> ast -> unit; - mutable new_diseq : ast -> ast -> unit; - mutable new_assignment: ast -> bool -> unit; - mutable new_relevant : ast -> unit; - } -let mk_theory_callbacks() = - { - delete_theory = (fun () -> ()); - reduce_eq = (fun _ _ -> None); - reduce_app = (fun _ _ -> None); - reduce_distinct = (fun _ -> None); - final_check = (fun _ -> true); - new_app = (fun _ -> ()); - new_elem = (fun _ -> ()); - init_search= (fun () -> ()); - push= (fun () -> ()); - pop= (fun () -> ()); - restart = (fun () -> ()); - reset= (fun () -> ()); - new_eq = (fun _ _ -> ()); - new_diseq = (fun _ _ -> ()); - new_assignment = (fun _ _ -> ()); - new_relevant = (fun _ -> ()); - } -external get_theory_callbacks : theory -> theory_callbacks = "get_theory_callbacks" -external mk_theory_register : context -> string -> theory_callbacks -> theory = "mk_theory_register" -external set_delete_callback_register : theory -> unit = "set_delete_callback_register" -external set_reduce_app_callback_register : theory -> unit = "set_reduce_app_callback_register" -external set_reduce_eq_callback_register : theory -> unit = "set_reduce_eq_callback_register" -external set_reduce_distinct_callback_register : theory -> unit = "set_reduce_distinct_callback_register" -external set_new_app_callback_register : theory -> unit = "set_new_app_callback_register" -external set_new_elem_callback_register : theory -> unit = "set_new_elem_callback_register" -external set_init_search_callback_register : theory -> unit = "set_init_search_callback_register" -external set_push_callback_register : theory -> unit = "set_push_callback_register" -external set_pop_callback_register : theory -> unit = "set_pop_callback_register" -external set_restart_callback_register : theory -> unit = "set_restart_callback_register" -external set_reset_callback_register : theory -> unit = "set_reset_callback_register" -external set_final_check_callback_register : theory -> unit = "set_final_check_callback_register" -external set_new_eq_callback_register : theory -> unit = "set_new_eq_callback_register" -external set_new_diseq_callback_register : theory -> unit = "set_new_diseq_callback_register" -external set_new_assignment_callback_register : theory -> unit = "set_new_assignment_callback_register" -external set_new_relevant_callback_register : theory -> unit = "set_new_relevant_callback_register" -let is_some opt = - match opt with - | Some v -> true - | None -> false -let get_some opt = - match opt with - | Some v -> v - | None -> failwith "None unexpected" -let apply_delete (th:theory_callbacks) = th.delete_theory () -let set_delete_callback th cb = - let cbs = get_theory_callbacks th in - cbs.delete_theory <- cb; - set_delete_callback_register th -let mk_theory context name = - Callback.register "is_some" is_some; - Callback.register "get_some" get_some; - Callback.register "apply_delete" apply_delete; - let cbs = mk_theory_callbacks() in - mk_theory_register context name cbs -let apply_reduce_app (th:theory_callbacks) f args = th.reduce_app f args -let set_reduce_app_callback th cb = - Callback.register "apply_reduce_app" apply_reduce_app; - let cbs = get_theory_callbacks th in - cbs.reduce_app <- cb; - set_reduce_app_callback_register th -let apply_reduce_eq (th:theory_callbacks) a b = th.reduce_eq a b -let set_reduce_eq_callback th cb = - Callback.register "apply_reduce_eq" apply_reduce_eq; - let cbs = get_theory_callbacks th in - cbs.reduce_eq <- cb; - set_reduce_eq_callback_register th -let apply_reduce_distinct (th:theory_callbacks) args = th.reduce_distinct args -let set_reduce_distinct_callback th cb = - Callback.register "apply_reduce_distinct" apply_reduce_distinct; - let cbs = get_theory_callbacks th in - cbs.reduce_distinct <- cb; - set_reduce_distinct_callback_register th -let apply_new_app (th:theory_callbacks) a = th.new_app a -let set_new_app_callback th cb = - Callback.register "apply_new_app" apply_new_app; - let cbs = get_theory_callbacks th in - cbs.new_app <- cb; - set_new_app_callback_register th -let apply_new_elem (th:theory_callbacks) a = th.new_elem a -let set_new_elem_callback th cb = - Callback.register "apply_new_elem" apply_new_elem; - let cbs = get_theory_callbacks th in - cbs.new_elem <- cb; - set_new_elem_callback_register th -let apply_init_search (th:theory_callbacks) = th.init_search() -let set_init_search_callback th cb = - Callback.register "apply_init_search" apply_init_search; - let cbs = get_theory_callbacks th in - cbs.init_search <- cb; - set_init_search_callback_register th -let apply_push (th:theory_callbacks) = th.push() -let set_push_callback th cb = - Callback.register "apply_push" apply_push; - let cbs = get_theory_callbacks th in - cbs.push <- cb; - set_push_callback_register th -let apply_pop (th:theory_callbacks) = th.pop() -let set_pop_callback th cb = - Callback.register "apply_pop" apply_pop; - let cbs = get_theory_callbacks th in - cbs.pop <- cb; - set_pop_callback_register th -let apply_restart (th:theory_callbacks) = th.restart() -let set_restart_callback th cb = - Callback.register "apply_restart" apply_restart; - let cbs = get_theory_callbacks th in - cbs.restart <- cb; - set_restart_callback_register th -let apply_reset (th:theory_callbacks) = th.reset() -let set_reset_callback th cb = - Callback.register "apply_reset" apply_reset; - let cbs = get_theory_callbacks th in - cbs.reset <- cb; - set_reset_callback_register th -let apply_final_check (th:theory_callbacks) = th.final_check() -let set_final_check_callback th cb = - Callback.register "apply_final_check" apply_final_check; - let cbs = get_theory_callbacks th in - cbs.final_check <- cb; - set_final_check_callback_register th -let apply_new_eq (th:theory_callbacks) a b = th.new_eq a b -let set_new_eq_callback th cb = - Callback.register "apply_new_eq" apply_new_eq; - let cbs = get_theory_callbacks th in - cbs.new_eq <- cb; - set_new_eq_callback_register th -let apply_new_diseq (th:theory_callbacks) a b = th.new_diseq a b -let set_new_diseq_callback th cb = - Callback.register "apply_new_diseq" apply_new_diseq; - let cbs = get_theory_callbacks th in - cbs.new_diseq <- cb; - set_new_diseq_callback_register th -let apply_new_assignment (th:theory_callbacks) a b = th.new_assignment a b -let set_new_assignment_callback th cb = - Callback.register "apply_new_assignment" apply_new_assignment; - let cbs = get_theory_callbacks th in - cbs.new_assignment <- cb; - set_new_assignment_callback_register th -let apply_new_relevant (th:theory_callbacks) a = th.new_relevant a -let set_new_relevant_callback th cb = - Callback.register "apply_new_relevant" apply_new_relevant; - let cbs = get_theory_callbacks th in - cbs.new_relevant <- cb; - set_new_relevant_callback_register th - - -end - -======= (* Copyright (C) 2012 Microsoft Corporation Author: CM Wintersteiger (cwinter) 2012-12-17 @@ -3410,48 +23,42 @@ end class context settings = object (self) inherit idisposable - val mutable m_n_ctx : Z3native.z3_context option = None + + val mutable m_n_ctx : Z3native.z3_context = + let cfg = mk_config() in + let f e = (set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = mk_context_rc cfg in + del_config(cfg) ; + v + val mutable m_refCount : int = 0 - initializer - let cfg = mk_config() in - (match settings with - | Some(x) -> - let f e = (set_param_value cfg (fst e) (snd e)) in - (List.iter f x) - | _ -> () - ) ; - m_n_ctx <- Some (mk_context_rc cfg) ; - del_config(cfg) ; - Gc.finalise (fun self -> self#dispose) self + initializer Gc.finalise (fun self -> self#dispose) self method dispose : unit = if m_refCount == 0 then ( Printf.printf "Disposing %d \n" (Oo.id self) ; - match m_n_ctx with - | Some(x) -> (del_context x) - | None -> () + (del_context m_n_ctx) ) else ( (* re-queue for finalization? *) ) method sub_one_ctx_obj = m_refCount <- m_refCount - 1 method add_one_ctx_obj = m_refCount <- m_refCount + 1 + method get_native = m_n_ctx end class virtual z3object ctx_init obj_init = object (self) inherit idisposable - val mutable m_ctx : context option = ctx_init + val mutable m_ctx : context = ctx_init val mutable m_n_obj : Z3native.ptr option = obj_init initializer (match m_n_obj with | Some (x) -> self#incref x; - (match m_ctx with - | Some(x) -> x#add_one_ctx_obj - | None -> () - ) + m_ctx#add_one_ctx_obj | None -> () ); Gc.finalise (fun self -> self#dispose) self @@ -3465,15 +72,9 @@ object (self) method dispose = Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with - | Some (x) -> self#decref x; m_n_obj <- None + | Some (x) -> self#decref x; m_n_obj <- None; m_ctx#sub_one_ctx_obj | None -> () ); - (match m_ctx with - | Some (x) -> x#sub_one_ctx_obj - | None -> () - ); - m_ctx <- None - method get_native_object = m_n_obj @@ -3489,6 +90,7 @@ object (self) m_n_obj <- x method get_context = m_ctx + method get_native_context = m_ctx#get_native (* method array_to_native a = @@ -3500,11 +102,59 @@ object (self) | Some(x) -> (Array.length x) | None -> 0 *) +end + +class symbol ctx_init obj_init = +object (self) + inherit z3object ctx_init obj_init + + method incref o = () + method decref o = () + + method kind = match m_n_obj with + | Some(x) -> (int2symbol_kind (get_symbol_kind self#get_native_context x)) + | _ -> raise (Exception "Underlying object lost") + + method is_int_symbol = match m_n_obj with + | Some(x) -> self#kind == INT_SYMBOL + | _ -> false + + method is_string_symbol = match m_n_obj with + | Some(x) -> self#kind == STRING_SYMBOL + | _ -> false + + method to_string = match m_n_obj with + | Some(x) -> + ( + match self#kind with + | INT_SYMBOL -> (string_of_int (get_symbol_int self#get_native_context x)) + | STRING_SYMBOL -> (get_symbol_string self#get_native_context x) + ) + | None -> "" + + method create ctx obj = + match obj with + | Some(x) -> ( + match (int2symbol_kind (get_symbol_kind ctx#get_native x)) with + | INT_SYMBOL -> (new intsymbol ctx obj :> symbol) + | STRING_SYMBOL -> (new stringsymbol ctx obj :> symbol) + ) + | None -> raise (Exception "Can't create null objects") end -<<<<<<< HEAD end ->>>>>>> More new ML API. -======= ->>>>>>> More ML API + +and intsymbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init + + method get_int = match m_n_obj with + | Some(x) -> (get_symbol_int m_ctx#get_native x) + | None -> 0 +end + +and stringsymbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init +end From b193b827ed05770ee5171093a75a1a1cde8b05bc Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 20 Dec 2012 04:10:38 +0000 Subject: [PATCH 014/248] ML API bugfixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 20 +++++-- scripts/update_api.py | 21 +++++-- src/api/ml/z3.ml | 121 ++++++++++++++++++++++---------------- 3 files changed, 101 insertions(+), 61 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 9c704e4d0..c79b3cdaa 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,11 +4,19 @@ *) open Z3 - -let _ = ignore(Log.open_ "z3.log") ; - let cfg = Some [("model", "true"); ("proof", "false")] in - let ctx = (new context cfg) in - Printf.printf "Disposing...\n"; - ctx#dispose ; + +exception ExampleException of string + +let _ = + if not (Log.open_ "z3.log") then + raise (ExampleException "Log couldn't be opened.") + else + ( + Printf.printf "Running Z3 version %s\n" Version.to_string ; + let cfg = [("model", "true"); ("proof", "false")] in + let ctx = (new context cfg) in + Printf.printf "Disposing...\n"; + ctx#dispose (* can do, but we'd rather let it go out of scope *) ; + ); Printf.printf "Exiting.\n"; ;; diff --git a/scripts/update_api.py b/scripts/update_api.py index 9eb7d1405..25adce2af 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -325,7 +325,9 @@ def param2pystr(p): def param2ml(p): k = param_kind(p) if k == OUT: - if param_type(p) == STRING: + if param_type(p) == INT or param_type(p) == UINT or param_type(p) == INT64 or param_type(p) == UINT64: + return "int" + elif param_type(p) == STRING: return "string" else: return "ptr" @@ -1124,9 +1126,16 @@ def mk_ml(): ml_native.write('%s -> ' % param2ml(p)) if len(op) > 0: ml_native.write('(') - ml_native.write('%s' % type2ml(result)) + first = True + if result != VOID or len(op) == 0: + ml_native.write('%s' % type2ml(result)) + first = False for p in op: - ml_native.write(' * %s' % param2ml(p)) + if first: + first = False + else: + ml_native.write(' * ') + ml_native.write('%s' % param2ml(p)) if len(op) > 0: ml_native.write(')') ml_native.write('\n') @@ -1153,11 +1162,13 @@ def mk_ml(): i = i + 1 ml_native.write(' = \n') ml_native.write(' ') - if result == VOID: + if result == VOID and len(op) == 0: ml_native.write('let _ = ') else: ml_native.write('let res = ') ml_native.write('(ML2C.n_%s' % (ml_method_name(name))) + if len(ip) == 0: + ml_native.write(' ()') first = True i = 0; for p in params: @@ -1170,7 +1181,7 @@ def mk_ml(): ml_native.write(' if err <> OK then\n') ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (error_code2int err)))\n') ml_native.write(' else\n') - if result == VOID: + if result == VOID and len(op) == 0: ml_native.write(' ()\n') else: ml_native.write(' res\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 55ffd91e8..31bb7e5fc 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -9,12 +9,27 @@ open Z3native module Log = struct let m_is_open = false - (* CMW: "open" seems to be an invalid function name*) - let open_ fn = int2lbool(open_log fn) == L_TRUE - let close = (close_log) - let append s = (append_log s) + (* CMW: "open" seems to be an invalid function name*) + let open_ fn = let rv = (open_log fn) in + Printf.printf "ol returned %d\n" rv ; + ((int2lbool rv) == L_TRUE) + let close = close_log + let append s = append_log s end - + +module Version = +struct + let major = let (x, _, _, _) = get_version in x + let minor = let (_, x, _, _) = get_version in x + let build = let (_, _, x, _) = get_version in x + let revision = let (_, _, _, x) = get_version in x + let to_string = + string_of_int major ^ "." ^ + string_of_int minor ^ "." ^ + string_of_int build ^ "." ^ + string_of_int revision ^ "." +end + class virtual idisposable = object method virtual dispose : unit @@ -25,7 +40,7 @@ object (self) inherit idisposable val mutable m_n_ctx : Z3native.z3_context = - let cfg = mk_config() in + let cfg = mk_config in let f e = (set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; let v = mk_context_rc cfg in @@ -34,14 +49,15 @@ object (self) val mutable m_refCount : int = 0 - initializer Gc.finalise (fun self -> self#dispose) self + initializer + Gc.finalise (fun self -> self#dispose) self method dispose : unit = if m_refCount == 0 then ( Printf.printf "Disposing %d \n" (Oo.id self) ; (del_context m_n_ctx) ) else ( - (* re-queue for finalization? *) + (* re-queue for finalization? *) ) method sub_one_ctx_obj = m_refCount <- m_refCount - 1 @@ -66,9 +82,9 @@ object (self) method virtual incref : Z3native.ptr -> unit method virtual decref : Z3native.ptr -> unit - (* - Disposes of the underlying native Z3 object. - *) + (* + Disposes of the underlying native Z3 object. + *) method dispose = Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with @@ -92,16 +108,17 @@ object (self) method get_context = m_ctx method get_native_context = m_ctx#get_native - (* - method array_to_native a = +(* + method array_to_native a = let f e = e#get_native_object in (Array.map f a) - method array_length a = + method array_length a = match a with - | Some(x) -> (Array.length x) - | None -> 0 - *) + | Some(x) -> (Array.length x) + | None -> 0 +*) + end class symbol ctx_init obj_init = @@ -110,51 +127,55 @@ object (self) method incref o = () method decref o = () +end - method kind = match m_n_obj with - | Some(x) -> (int2symbol_kind (get_symbol_kind self#get_native_context x)) - | _ -> raise (Exception "Underlying object lost") +class int_symbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init +end - method is_int_symbol = match m_n_obj with - | Some(x) -> self#kind == INT_SYMBOL - | _ -> false +class string_symbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init +end - method is_string_symbol = match m_n_obj with - | Some(x) -> self#kind == STRING_SYMBOL - | _ -> false - - method to_string = match m_n_obj with - | Some(x) -> - ( - match self#kind with - | INT_SYMBOL -> (string_of_int (get_symbol_int self#get_native_context x)) - | STRING_SYMBOL -> (get_symbol_string self#get_native_context x) - ) - | None -> "" - - method create ctx obj = +module Symbol = +struct + let create ctx obj = match obj with | Some(x) -> ( match (int2symbol_kind (get_symbol_kind ctx#get_native x)) with - | INT_SYMBOL -> (new intsymbol ctx obj :> symbol) - | STRING_SYMBOL -> (new stringsymbol ctx obj :> symbol) + | INT_SYMBOL -> (new int_symbol ctx obj :> symbol) + | STRING_SYMBOL -> (new string_symbol ctx obj :> symbol) ) | None -> raise (Exception "Can't create null objects") -end + let kind o = match o#m_n_obj with + | Some(x) -> (int2symbol_kind (get_symbol_kind o#get_native_context x)) + | _ -> raise (Exception "Underlying object lost") -end + let is_int_symbol o = match o#m_n_obj with + | Some(x) -> x#kind == INT_SYMBOL + | _ -> false -and intsymbol ctx_init obj_init = -object(self) - inherit symbol ctx_init obj_init + let is_string_symbol o = match o#m_n_obj with + | Some(x) -> x#kind == STRING_SYMBOL + | _ -> false - method get_int = match m_n_obj with - | Some(x) -> (get_symbol_int m_ctx#get_native x) + let get_int o = match o#m_n_obj with + | Some(x) -> (get_symbol_int o#get_native_context x) | None -> 0 -end -and stringsymbol ctx_init obj_init = -object(self) - inherit symbol ctx_init obj_init + let get_string o = match o#m_n_obj with + | Some(x) -> (get_symbol_string o#get_native_context x) + | None -> "" + + let to_string o = match o#m_n_obj with + | Some(x) -> + ( + match (kind o) with + | INT_SYMBOL -> (string_of_int (get_symbol_int o#get_native_context x)) + | STRING_SYMBOL -> (get_symbol_string o#get_native_context x) + ) + | None -> "" end From e87feb8e456e91d05a14dee17d62f9cf1c531e27 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 20 Dec 2012 04:12:41 +0000 Subject: [PATCH 015/248] added temporary Makefile for ML annotations. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/api/ml/Makefile diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile new file mode 100644 index 000000000..f97a2dc30 --- /dev/null +++ b/src/api/ml/Makefile @@ -0,0 +1,6 @@ +# This is a temporary support file for emacs annotations. +# It does not compile the Z3 ML API; this will be built +# in the top-level build directory. + +all: + ocamlbuild -cflag -annot z3.cmxa \ No newline at end of file From 518da6b6e2b70ec17bda199f589d316605857fc1 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 20 Dec 2012 19:08:23 +0000 Subject: [PATCH 016/248] move old files Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/{ => old}/README-linux | 0 src/api/ml/{ => old}/README-osx | 0 src/api/ml/{ => old}/README-test-linux | 0 src/api/ml/{ => old}/README-test-osx | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename src/api/ml/{ => old}/README-linux (100%) rename src/api/ml/{ => old}/README-osx (100%) rename src/api/ml/{ => old}/README-test-linux (100%) rename src/api/ml/{ => old}/README-test-osx (100%) diff --git a/src/api/ml/README-linux b/src/api/ml/old/README-linux similarity index 100% rename from src/api/ml/README-linux rename to src/api/ml/old/README-linux diff --git a/src/api/ml/README-osx b/src/api/ml/old/README-osx similarity index 100% rename from src/api/ml/README-osx rename to src/api/ml/old/README-osx diff --git a/src/api/ml/README-test-linux b/src/api/ml/old/README-test-linux similarity index 100% rename from src/api/ml/README-test-linux rename to src/api/ml/old/README-test-linux diff --git a/src/api/ml/README-test-osx b/src/api/ml/old/README-test-osx similarity index 100% rename from src/api/ml/README-test-osx rename to src/api/ml/old/README-test-osx From 8e83f8d034949f3f4918267b014b647a3458d9c8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 20 Dec 2012 20:51:18 +0000 Subject: [PATCH 017/248] ML build system checks Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 62 +++++++++++++++++++++++++++++++++++++++++++--- src/api/ml/z3.ml | 8 +++--- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index da7d22d54..8848d4ce4 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -32,6 +32,10 @@ CXXFLAGS=getenv("CXXFLAGS", "") EXAMP_DEBUG_FLAG='' LDFLAGS=getenv("LDFLAGS", "") JNI_HOME=getenv("JNI_HOME", None) +OCAMLC=getenv("OCAMLC", "ocamlc") +OCAMLOPT=getenv("OCAMLC", "ocamlopt") +OCAMLBUILD=getenv("OCAMLBUILD", "ocamlbuild") +OCAML_LIB=getenv("OCAML_LIB", None) CXX_COMPILERS=['g++', 'clang++'] C_COMPILERS=['gcc', 'clang'] @@ -335,6 +339,43 @@ def check_java(): if JNI_HOME == None: raise MKException("Failed to detect jni.h. Possible solution: set JNI_HOME with the path to JDK.") +def check_ml(): + t = TempFile('hello.ml') + t.add('print_string "Hello world!\n";;') + t.commit() + if is_verbose(): + print "Testing %s..." % OCAMLC + r = exec_cmd([OCAMLC, 'hello.ml']) + if r != 0: + raise MKException('Failed testing ocamlc compiler. Set environment variable OCAMLC with the path to the Ocaml compiler') + if is_verbose(): + print "Testing %s..." % OCAMLOPT + r = exec_cmd([OCAMLC, 'hello.ml']) + if r != 0: + raise MKException('Failed testing ocamlopt compiler. Set environment variable OCAMLOPT with the path to the Ocaml native compiler') + r = exec_cmd([OCAMLBUILD]) + if r != 0: + raise MKException('Failed testing ocamlbuild. Set environment variable OCAMLBUILD with the path to ocamlbuild') + find_ml_lib() + +def find_ml_lib(): + global OCAML_LIB + if is_verbose(): + print "Finding OCAML_LIB..." + t = TempFile('output') + null = open(os.devnull, 'wb') + try: + subprocess.call([OCAMLC, '-where'], stdout=t.fname, stderr=null) + t.commit() + except: + raise MKException('Failed to find Ocaml library; please set OCAML_LIB') + t = open('output', 'r') + for line in t: + OCAML_LIB = line[:-1] + if is_verbose(): + print 'OCAML_LIB=%s' % OCAML_LIB + return + def is64(): return sys.maxsize >= 2**32 @@ -474,6 +515,10 @@ def display_help(exit_code): print(" CXXFLAGS C++ compiler flags") print(" JDK_HOME JDK installation directory (only relevant if -j or --java option is provided)") print(" JNI_HOME JNI bindings directory (only relevant if -j or --java option is provided)") + print(" OCAMLC Ocaml byte-code compiler (only relevant with --ml)") + print(" OCAMLOPT Ocaml native compiler (only relevant with --ml)") + print(" OCAMLBUILD Ocaml build system (only relevant with --ml)") + print(" OCAML_LIB Ocaml library directory (only relevant with --ml)") exit(exit_code) # Parse configuration option for mk_make script @@ -1300,7 +1345,7 @@ class MLComponent(Component): for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) out.write('z3.cmxa: %s\n' % libfile) out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) @@ -1438,7 +1483,7 @@ class MLExampleComponent(ExampleComponent): for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('ml_example($EXE_EXT): z3.cmxa ') + out.write('ml_example($EXE_EXT): z3.cmxa ml_example.byte') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') @@ -1596,6 +1641,11 @@ def mk_config(): if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) + if is_ml_enabled(): + print('Ocaml Compiler: %s' % OCAMLC) + print('Ocaml Native: %s' % OCAMLOPT) + print('Ocamlbuild: %s' % OCAMLBUILD) + print('Ocaml Library: %s' % OCAML_LIB) else: global CXX, CC, GMP, FOCI2, CPPFLAGS, CXXFLAGS, LDFLAGS, EXAMP_DEBUG_FLAG OS_DEFINES = "" @@ -1715,7 +1765,12 @@ def mk_config(): if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) - + if is_ml_enabled(): + print('Ocaml Compiler: %s' % OCAMLC) + print('Ocaml Native: %s' % OCAMLOPT) + print('Ocamlbuild: %s' % OCAMLBUILD) + print('Ocaml Library: %s' % OCAML_LIB) + def mk_install(out): out.write('install: ') for c in get_components(): @@ -2280,6 +2335,7 @@ def mk_bindings(api_files): check_java() mk_z3consts_java(api_files) if is_ml_enabled(): + check_ml() mk_z3consts_ml(api_files) _execfile(os.path.join('scripts', 'update_api.py'), g) # HACK cp_z3py_to_build() diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 31bb7e5fc..d901d09ef 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -10,11 +10,9 @@ module Log = struct let m_is_open = false (* CMW: "open" seems to be an invalid function name*) - let open_ fn = let rv = (open_log fn) in - Printf.printf "ol returned %d\n" rv ; - ((int2lbool rv) == L_TRUE) - let close = close_log - let append s = append_log s + let open_ fn = int2lbool(open_log fn) == L_TRUE + let close = (close_log) + let append s = (append_log s) end module Version = From 7efe7a2c16ad26a7021e7b0619a4450be2f8e6c7 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 21 Dec 2012 03:02:12 +0000 Subject: [PATCH 018/248] ML native layer bugfixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/Makefile | 7 ++ scripts/mk_util.py | 2 +- scripts/update_api.py | 165 +++++++++++++++++++++++++----------------- src/api/ml/z3.ml | 11 +-- 4 files changed, 113 insertions(+), 72 deletions(-) create mode 100644 examples/ml/Makefile diff --git a/examples/ml/Makefile b/examples/ml/Makefile new file mode 100644 index 000000000..4b3e7c4d2 --- /dev/null +++ b/examples/ml/Makefile @@ -0,0 +1,7 @@ +# This is a temporary support file for emacs annotations. +# It does not compile the Z3 ML example; this will be built +# in the top-level build directory. + +all: + OCAML_COMPAT=c ocamlc -g -annot -o ml_example.byte -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cma ml_example.ml + ocamlopt -g -annot -o ml_example -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cmxa ml_example.ml diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8848d4ce4..b6cf4dedc 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2699,7 +2699,7 @@ def mk_z3consts_ml(api_files): idx = idx + 1 linenum = linenum + 1 if VERBOSE: - print "Generated '%s/enumerations.ml'" % ('%s' % gendir) + print "Generated '%s/z3enums.ml'" % ('%s' % gendir) def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index 25adce2af..d0ef2ec86 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1,3 +1,4 @@ + ############################################ # Copyright (c) 2012 Microsoft Corporation # @@ -1097,6 +1098,45 @@ def is_array_param(p): else: return False +def arrayparams(params): + op = [] + for param in params: + if is_array_param(param): + op.append(param) + return op + + +def ml_unwrap(t): + if t == STRING: + return 'String_val' + elif t == BOOL or t == INT or PRINT_MODE or ERROR_CODE: + return 'Int_val' + elif t == UINT: + return 'Unsigned_int_val' + elif t == INT64: + return 'Long_val' + elif t == UINT64: + return 'Unsigned_long_val' + elif t == DOUBLE: + return 'Double_val' + else: + return 'Data_custom_val' + +def ml_set_wrap(t, d, n): + if t == VOID: + return d + ' = Val_unit;' + elif t == BOOL or t == INT or t == UINT or PRINT_MODE or ERROR_CODE: + return d + ' = Val_int(' + n + ');' + elif t == INT64 or t == UINT64: + return d + ' = Val_long(' + n + ');' + elif t == DOUBLE: + return 'Store_double_val(' + d + ', ' + n + ');' + elif t == STRING: + return d + ' = caml_copy_string((const char*) ' + n + ');' + else: + ts = type2str(t) + return d + ' = caml_alloc_custom(0, sizeof(' + ts + '), 0, 1); memcpy( Data_custom_val(' + d + '), &' + n + ', sizeof(' + ts + '));' + def mk_ml(): global Type2Str if not is_ml_enabled(): @@ -1242,15 +1282,12 @@ def mk_ml(): for name, result, params in _dotnet_decls: ip = inparams(params) op = outparams(params) + ap = arrayparams(params) ret_size = len(op) if result != VOID: ret_size = ret_size + 1 # Setup frame - n_locals = 0 - for p in params: - if is_out_param(p) or (is_in_param(p) and param_type(p) == STRING): - n_locals = n_locals + 1 ml_wrapper.write('CAMLprim value n_%s(' % ml_method_name(name)) first = True i = 0 @@ -1276,46 +1313,50 @@ def mk_ml(): i = i + 1 ml_wrapper.write(');\n') i = 0 - first = True - if result != VOID: - n_locals = n_locals + 1 - if ret_size > 1: - n_locals = n_locals + 1 - if n_locals > 0: - ml_wrapper.write(' CAMLlocal%s(' % (n_locals)) - if ret_size > 1: - if result != VOID: - ml_wrapper.write('result, ') - ml_wrapper.write('result_tuple') - first = False - elif result != VOID: - ml_wrapper.write('result') - first = False + if len(op) + len(ap) == 0: + ml_wrapper.write(' CAMLlocal1(result);\n') + else: + c = 0 for p in params: - if is_out_param(p) or (is_in_param(p) and param_type(p) == STRING): - if first: - first = False - else: - ml_wrapper.write(', ') - ml_wrapper.write('_a%s' % i) + if is_out_param(p) or is_array_param(p): + c = c + 1 + ml_wrapper.write(' CAMLlocal%s(result, res_val' % (c+2)) + for p in params: + if is_out_param(p) or is_array_param(p): + ml_wrapper.write(', _a%s_val' % i) i = i + 1 ml_wrapper.write(');\n') # preprocess arrays, strings, in/out arguments i = 0 for param in params: - if param_kind(param) == OUT_ARRAY: - ml_wrapper.write(' _a%s = (long) malloc(sizeof(%s) * ((long)a%s));\n' % (i, - type2str(param_type(param)), - param_array_capacity_pos(param))) - elif param_kind(param) == IN and param_type(param) == STRING: - ml_wrapper.write(' _a%s = (value) String_val(a%s);\n' % (i, i)) + k = param_kind(param) + if k == OUT_ARRAY: + ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * (_a%s));\n' % ( + type2str(param_type(param)), + i, + type2str(param_type(param)), + type2str(param_type(param)), + param_array_capacity_pos(param))) + elif k == IN_ARRAY or k == INOUT_ARRAY: + t = param_type(param) + ts = type2str(t) + ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) + ml_wrapper.write(' for (unsigned i = 0; i < a%s; i++) _a%s[i] = (%s) %s(Field(a%s, i));\n' % (param_array_capacity_pos(param), i, ts, ml_unwrap(t), i)) + elif k == IN: + t = param_type(param) + ml_wrapper.write(' %s _a%s = (%s) %s(a%s);\n' % (type2str(t), i, type2str(t), ml_unwrap(t), i)) + elif k == OUT: + ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) + elif k == INOUT: + ml_wrapper.write(' %s _a%s = a%s;\n' % (type2str(param_type(param)), i, i)) + i = i + 1 # invoke procedure ml_wrapper.write(' ') if result != VOID: - ml_wrapper.write('result = (value) ') + ml_wrapper.write('%s z3_result = ' % type2str(result)) ml_wrapper.write('%s(' % name) i = 0 first = True @@ -1326,58 +1367,50 @@ def mk_ml(): ml_wrapper.write(', ') k = param_kind(param) if k == OUT or k == INOUT: - ml_wrapper.write('(%s)&_a%s' % (param2str(param), i)) - elif k == INOUT_ARRAY or k == IN_ARRAY: - ml_wrapper.write('(%s*)a%s' % (type2str(param_type(param)), i)) - elif k == OUT_ARRAY: - ml_wrapper.write('(%s*)_a%s' % (type2str(param_type(param)), i)) - elif k == IN and param_type(param) == STRING: - ml_wrapper.write('(Z3_string) _a%s' % i) + ml_wrapper.write('&_a%s' % i) else: - ml_wrapper.write('(%s)a%i' % (param2str(param), i)) + ml_wrapper.write('_a%i' % i) i = i + 1 ml_wrapper.write(');\n') - # return tuples + # convert output params if len(op) > 0: - ml_wrapper.write(' result_tuple = caml_alloc(%s, 0);\n' % ret_size) + if result != VOID: + ml_wrapper.write(' %s\n' % ml_set_wrap(result, "res_val", "z3_result")) + i = 0; + for p in params: + if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: + ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) + ml_wrapper.write(' for (unsigned i = 0; i < _a%s; i++) { value t; %s Store_field(_a%s, i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[i]'), i)) + elif is_out_param(p): + ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) + i = i + 1 + + # return tuples + if len(op) == 0: + ml_wrapper.write(' %s\n' % ml_set_wrap(result, "result", "z3_result")) + else: + ml_wrapper.write(' result = caml_alloc(%s, 0);\n' % ret_size) i = j = 0 if result != VOID: - if result == STRING: - ml_wrapper.write(' Store_field(result_tuple, 0, caml_copy_string(result));\n') - else: - ml_wrapper.write(' Store_field(result_tuple, 0, result);\n') + ml_wrapper.write(' Store_field(result, 0, res_val);\n') j = j + 1 for p in params: - if param_kind(p) == OUT_ARRAY or param_kind(p) == OUT: - ml_wrapper.write(' Store_field(result_tuple, %s, _a%s);\n' % (j, i)) - j = j + 1; - elif is_out_param(p): - if param_type(p) == STRING: - ml_wrapper.write(' Store_field(result_tuple, %s, caml_copy_string((const char *)_a%s));\n' % (j, i)) - else: - ml_wrapper.write(' Store_field(result_tuple, %s, a%s);\n' % (j, i)) + if is_out_param(p): + ml_wrapper.write(' Store_field(result, %s, _a%s_val);\n' % (j, i)) j = j + 1; i = i + 1 # local array cleanup i = 0 for p in params: - if param_kind(p) == OUT_ARRAY: - ml_wrapper.write(' free((long*)_a%s);\n' % i) + k = param_kind(p) + if k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: + ml_wrapper.write(' free(_a%s);\n' % i) i = i + 1 # return - if len(op) > 0: - ml_wrapper.write(' CAMLreturn(result_tuple);\n') - else: - if result == STRING: - ml_wrapper.write(' CAMLreturn(caml_copy_string((const char*) result));\n') - elif result == VOID: - ml_wrapper.write(' CAMLreturn(Val_unit);\n') - elif result != VOID: - ml_wrapper.write(' CAMLreturn(result);\n') - + ml_wrapper.write(' CAMLreturn(result);\n') ml_wrapper.write('}\n\n') if len(ip) > 5: ml_wrapper.write('CAMLprim value n_%s_bytecode(value * argv, int argn) {\n' % ml_method_name(name)) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index d901d09ef..cc1429f14 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -22,10 +22,11 @@ struct let build = let (_, _, x, _) = get_version in x let revision = let (_, _, _, x) = get_version in x let to_string = - string_of_int major ^ "." ^ - string_of_int minor ^ "." ^ - string_of_int build ^ "." ^ - string_of_int revision ^ "." + let (mj, mn, bld, rev) = get_version in + string_of_int mj ^ "." ^ + string_of_int mn ^ "." ^ + string_of_int bld ^ "." ^ + string_of_int rev ^ "." end class virtual idisposable = @@ -52,7 +53,7 @@ object (self) method dispose : unit = if m_refCount == 0 then ( - Printf.printf "Disposing %d \n" (Oo.id self) ; + Printf.printf "Disposing context %d \n" (Oo.id self) ; (del_context m_n_ctx) ) else ( (* re-queue for finalization? *) From 794823ba6d149561eec5c168cc8e7cd9d9a1387c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 21 Dec 2012 07:18:46 +0000 Subject: [PATCH 019/248] More ML API: Fixes in native layer. Added symbols. Prepared code for automatic documentation. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 5 ++ scripts/mk_util.py | 4 + scripts/update_api.py | 37 ++++++--- src/api/ml/z3.ml | 168 ++++++++++++++++++++++++++------------ 4 files changed, 151 insertions(+), 63 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index c79b3cdaa..7046a92b0 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,6 +4,7 @@ *) open Z3 +open Z3.Context exception ExampleException of string @@ -15,6 +16,10 @@ let _ = Printf.printf "Running Z3 version %s\n" Version.to_string ; let cfg = [("model", "true"); ("proof", "false")] in let ctx = (new context cfg) in + let is = (mk_symbol_int ctx 42) in + let ss = (mk_symbol_string ctx "mySymbol") in + Printf.printf "int symbol: %s\n" (Symbol.to_string (is :> symbol)); + Printf.printf "string symbol: %s\n" (Symbol.to_string (ss :> symbol)); Printf.printf "Disposing...\n"; ctx#dispose (* can do, but we'd rather let it go out of scope *) ; ); diff --git a/scripts/mk_util.py b/scripts/mk_util.py index b6cf4dedc..68493b7b6 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2628,6 +2628,7 @@ def mk_z3consts_ml(api_files): efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') + efile.write('(** The enumeration types of Z3. *)\n\n') for api_file in api_files: api_file_c = ml.find_file(api_file, ml.name) api_file = os.path.join(api_file_c.src_dir, api_file) @@ -2673,15 +2674,18 @@ def mk_z3consts_ml(api_files): if m: name = words[1] if name not in DeprecatedEnums: + efile.write('(** %s *)\n' % name[3:]) efile.write('type %s =\n' % name[3:]) # strip Z3_ for k, i in decls.iteritems(): efile.write(' | %s \n' % k[3:]) # strip Z3_ efile.write('\n') + efile.write('(** Convert %s to int*)\n' % name[3:]) efile.write('let %s2int x : int =\n' % (name[3:])) # strip Z3_ efile.write(' match x with\n') for k, i in decls.iteritems(): efile.write(' | %s -> %d\n' % (k[3:], i)) efile.write('\n') + efile.write('(** Convert int to %s*)\n' % name[3:]) efile.write('let int2%s x : %s =\n' % (name[3:],name[3:])) # strip Z3_ efile.write(' match x with\n') for k, i in decls.iteritems(): diff --git a/scripts/update_api.py b/scripts/update_api.py index d0ef2ec86..c8cd05c7e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1106,26 +1106,26 @@ def arrayparams(params): return op -def ml_unwrap(t): +def ml_unwrap(t, ts, s): if t == STRING: - return 'String_val' - elif t == BOOL or t == INT or PRINT_MODE or ERROR_CODE: - return 'Int_val' + return '(' + ts + ') String_val(' + s + ')' + elif t == BOOL or t == INT or t == PRINT_MODE or t == ERROR_CODE: + return '(' + ts + ') Int_val(' + s + ')' elif t == UINT: - return 'Unsigned_int_val' + return '(' + ts + ') Unsigned_int_val(' + s + ')' elif t == INT64: - return 'Long_val' + return '(' + ts + ') Long_val(' + s + ')' elif t == UINT64: - return 'Unsigned_long_val' + return '(' + ts + ') Unsigned_long_val(' + s + ')' elif t == DOUBLE: - return 'Double_val' + return '(' + ts + ') Double_val(' + s + ')' else: - return 'Data_custom_val' + return '* (' + ts + '*) Data_custom_val(' + s + ')' def ml_set_wrap(t, d, n): if t == VOID: return d + ' = Val_unit;' - elif t == BOOL or t == INT or t == UINT or PRINT_MODE or ERROR_CODE: + elif t == BOOL or t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE: return d + ' = Val_int(' + n + ');' elif t == INT64 or t == UINT64: return d + ' = Val_long(' + n + ');' @@ -1135,7 +1135,7 @@ def ml_set_wrap(t, d, n): return d + ' = caml_copy_string((const char*) ' + n + ');' else: ts = type2str(t) - return d + ' = caml_alloc_custom(0, sizeof(' + ts + '), 0, 1); memcpy( Data_custom_val(' + d + '), &' + n + ', sizeof(' + ts + '));' + return d + ' = caml_alloc_custom(&default_custom_ops, sizeof(' + ts + '), 0, 1); memcpy( Data_custom_val(' + d + '), &' + n + ', sizeof(' + ts + '));' def mk_ml(): global Type2Str @@ -1146,7 +1146,9 @@ def mk_ml(): ml_wrapperf = os.path.join(ml_dir, 'z3native.c') ml_native = open(ml_nativef, 'w') ml_native.write('(* Automatically generated file *)\n\n') + ml_native.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') ml_native.write('open Z3enums\n\n') + ml_native.write('(**/**)\n') ml_native.write('type ptr\n') ml_native.write('and z3_symbol = ptr\n') for k, v in Type2Str.iteritems(): @@ -1226,6 +1228,7 @@ def mk_ml(): else: ml_native.write(' res\n') ml_native.write('\n') + ml_native.write('(**/**)\n') # C interface ml_wrapper = open(ml_wrapperf, 'w') @@ -1276,6 +1279,14 @@ def mk_ml(): ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') ml_wrapper.write(' CAMLxparam3(X11,X12,X13); \n') ml_wrapper.write('\n\n') + ml_wrapper.write('static struct custom_operations default_custom_ops = {\n') + ml_wrapper.write(' identifier: "default handling",\n') + ml_wrapper.write(' finalize: custom_finalize_default,\n') + ml_wrapper.write(' compare: custom_compare_default,\n') + ml_wrapper.write(' hash: custom_hash_default,\n') + ml_wrapper.write(' serialize: custom_serialize_default,\n') + ml_wrapper.write(' deserialize: custom_deserialize_default\n') + ml_wrapper.write('};\n\n') ml_wrapper.write('#ifdef __cplusplus\n') ml_wrapper.write('extern "C" {\n') ml_wrapper.write('#endif\n\n') @@ -1342,10 +1353,10 @@ def mk_ml(): t = param_type(param) ts = type2str(t) ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) - ml_wrapper.write(' for (unsigned i = 0; i < a%s; i++) _a%s[i] = (%s) %s(Field(a%s, i));\n' % (param_array_capacity_pos(param), i, ts, ml_unwrap(t), i)) + ml_wrapper.write(' for (unsigned i = 0; i < _a%s; i++) _a%s[i] = %s;\n' % (param_array_capacity_pos(param), i, ml_unwrap(t, ts, 'Field(a' + str(i) + ', i)'))) elif k == IN: t = param_type(param) - ml_wrapper.write(' %s _a%s = (%s) %s(a%s);\n' % (type2str(t), i, type2str(t), ml_unwrap(t), i)) + ml_wrapper.write(' %s _a%s = %s;\n' % (type2str(t), i, ml_unwrap(t, type2str(t), 'a' + str(i)))) elif k == OUT: ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) elif k == INOUT: diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index cc1429f14..321b17c82 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,33 +1,17 @@ -(* +(** + The Z3 ML/Ocaml Interface. + Copyright (C) 2012 Microsoft Corporation - Author: CM Wintersteiger (cwinter) 2012-12-17 + @author CM Wintersteiger (cwinter) 2012-12-17 *) open Z3enums open Z3native -module Log = -struct - let m_is_open = false - (* CMW: "open" seems to be an invalid function name*) - let open_ fn = int2lbool(open_log fn) == L_TRUE - let close = (close_log) - let append s = (append_log s) -end +(**/**) -module Version = -struct - let major = let (x, _, _, _) = get_version in x - let minor = let (_, x, _, _) = get_version in x - let build = let (_, _, x, _) = get_version in x - let revision = let (_, _, _, x) = get_version in x - let to_string = - let (mj, mn, bld, rev) = get_version in - string_of_int mj ^ "." ^ - string_of_int mn ^ "." ^ - string_of_int bld ^ "." ^ - string_of_int rev ^ "." -end +(* Object definitions. These are internal and should be interacted + with only via the corresponding functions from modules. *) class virtual idisposable = object @@ -61,7 +45,7 @@ object (self) method sub_one_ctx_obj = m_refCount <- m_refCount - 1 method add_one_ctx_obj = m_refCount <- m_refCount + 1 - method get_native = m_n_ctx + method gno = m_n_ctx end class virtual z3object ctx_init obj_init = @@ -91,9 +75,9 @@ object (self) | None -> () ); - method get_native_object = m_n_obj + method gno = m_n_obj - method set_native_object x = + method sno x = (match x with | Some(x) -> self#incref x | None -> () @@ -105,11 +89,11 @@ object (self) m_n_obj <- x method get_context = m_ctx - method get_native_context = m_ctx#get_native + method gnc = m_ctx#gno (* method array_to_native a = - let f e = e#get_native_object in + let f e = e#gno in (Array.map f a) method array_length a = @@ -120,61 +104,145 @@ object (self) end -class symbol ctx_init obj_init = +class symbol ctx obj = object (self) - inherit z3object ctx_init obj_init + inherit z3object ctx obj method incref o = () method decref o = () end -class int_symbol ctx_init obj_init = +class int_symbol ctx = object(self) - inherit symbol ctx_init obj_init + inherit symbol ctx None + method cnstr_obj obj = (self#sno obj) ; self + method cnstr_int i = (self#sno (Some (mk_int_symbol ctx#gno i))) ; self end -class string_symbol ctx_init obj_init = +class string_symbol ctx = object(self) - inherit symbol ctx_init obj_init + inherit symbol ctx None + method cnstr_obj obj = (self#sno obj) ; self + method cnstr_string name = (self#sno (Some (mk_string_symbol ctx#gno name))) ; self end +(**/**) + +(** 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. *) +module Log = +struct + (** Open an interaction log file. + @param filename the name of the file to open. + @return True if opening the log file succeeds, false otherwise. + *) + (* CMW: "open" seems to be a reserved keyword? *) + let open_ filename = ((int2lbool (open_log filename)) == L_TRUE) + + (** Closes the interaction log. *) + let close = close_log + + (** Appends a user-provided string to the interaction log. + @param s the string to append*) + let append s = append_log s +end + +(** Version information. *) +module Version = +struct + (** The major version. *) + let major = let (x, _, _, _) = get_version in x + + (** The minor version. *) + let minor = let (_, x, _, _) = get_version in x + + (** The build version. *) + let build = let (_, _, x, _) = get_version in x + + (** The revision. *) + let revision = let (_, _, _, x) = get_version in x + + (** A string representation of the version information. *) + let to_string = + let (mj, mn, bld, rev) = get_version in + string_of_int mj ^ "." ^ + string_of_int mn ^ "." ^ + string_of_int bld ^ "." ^ + string_of_int rev ^ "." +end + +(** Symbols are used to name several term and type constructors. *) module Symbol = struct +(**/**) let create ctx obj = match obj with | Some(x) -> ( - match (int2symbol_kind (get_symbol_kind ctx#get_native x)) with - | INT_SYMBOL -> (new int_symbol ctx obj :> symbol) - | STRING_SYMBOL -> (new string_symbol ctx obj :> symbol) + match (int2symbol_kind (get_symbol_kind ctx#gno x)) with + | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj obj) :> symbol) + | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj obj) :> symbol) ) | None -> raise (Exception "Can't create null objects") +(**/**) - let kind o = match o#m_n_obj with - | Some(x) -> (int2symbol_kind (get_symbol_kind o#get_native_context x)) + (** The kind of the symbol (int or string) *) + let kind (o : symbol) = match o#gno with + | Some(x) -> (int2symbol_kind (get_symbol_kind o#gnc x)) | _ -> raise (Exception "Underlying object lost") - let is_int_symbol o = match o#m_n_obj with - | Some(x) -> x#kind == INT_SYMBOL + (** Indicates whether the symbol is of Int kind *) + let is_int_symbol (o : symbol) = match o#gno with + | Some(x) -> (kind o) == INT_SYMBOL | _ -> false - let is_string_symbol o = match o#m_n_obj with - | Some(x) -> x#kind == STRING_SYMBOL + (** Indicates whether the symbol is of string kind. *) + let is_string_symbol (o : symbol) = match o#gno with + | Some(x) -> (kind o) == STRING_SYMBOL | _ -> false - let get_int o = match o#m_n_obj with - | Some(x) -> (get_symbol_int o#get_native_context x) + (** The int value of the symbol. *) + let get_int (o : int_symbol) = match o#gno with + | Some(x) -> (get_symbol_int o#gnc x) | None -> 0 - let get_string o = match o#m_n_obj with - | Some(x) -> (get_symbol_string o#get_native_context x) + (** The string value of the symbol. *) + let get_string (o : string_symbol) = match o#gno with + | Some(x) -> (get_symbol_string o#gnc x) | None -> "" - let to_string o = match o#m_n_obj with + (** A string representation of the symbol. *) + let to_string (o : symbol) = match o#gno with | Some(x) -> ( match (kind o) with - | INT_SYMBOL -> (string_of_int (get_symbol_int o#get_native_context x)) - | STRING_SYMBOL -> (get_symbol_string o#get_native_context x) + | INT_SYMBOL -> (string_of_int (get_symbol_int o#gnc x)) + | STRING_SYMBOL -> (get_symbol_string o#gnc x) ) | None -> "" end + +(** The main interaction with Z3 happens via the Context. *) +module Context = +struct + (** + 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. + *) + let mk_symbol_int ctx i = + (new int_symbol ctx)#cnstr_int i + + (** Creates a new symbol using a string. *) + let mk_symbol_string ctx s = + (new string_symbol ctx)#cnstr_string s + + (** + Create an array of symbols. + *) + let mk_symbols ctx names = + let f elem = mk_symbol_string ctx elem in + (Array.map f names) + +end From fc227e3c9613cb573a8048c68df0d70742c25dea Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 00:50:32 +0000 Subject: [PATCH 020/248] .NET API documentation bugfixes Signed-off-by: Christoph M. Wintersteiger --- src/api/dotnet/Expr.cs | 2 +- src/api/dotnet/Params.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/dotnet/Expr.cs b/src/api/dotnet/Expr.cs index f4a63a61b..53bf4d4f0 100644 --- a/src/api/dotnet/Expr.cs +++ b/src/api/dotnet/Expr.cs @@ -1311,7 +1311,7 @@ namespace Microsoft.Z3 #region Relational Terms /// - /// Indicates whether the term is of an array sort. + /// Indicates whether the term is of relation sort. /// public bool IsRelation { diff --git a/src/api/dotnet/Params.cs b/src/api/dotnet/Params.cs index c33728491..9a814b2ec 100644 --- a/src/api/dotnet/Params.cs +++ b/src/api/dotnet/Params.cs @@ -23,7 +23,7 @@ using System.Diagnostics.Contracts; namespace Microsoft.Z3 { /// - /// A ParameterSet represents a configuration in the form of Symbol/value pairs. + /// A Params objects represents a configuration in the form of Symbol/value pairs. /// [ContractVerification(true)] public class Params : Z3Object From dab162886e8036d59b5a853f99c8adc5d7ea0074 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 00:51:07 +0000 Subject: [PATCH 021/248] New ML API savepoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/Makefile | 6 +- src/api/ml/z3.ml | 5746 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 5659 insertions(+), 93 deletions(-) diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile index f97a2dc30..4d4a6c08f 100644 --- a/src/api/ml/Makefile +++ b/src/api/ml/Makefile @@ -3,4 +3,8 @@ # in the top-level build directory. all: - ocamlbuild -cflag -annot z3.cmxa \ No newline at end of file + ocamlbuild -cflag -annot z3.cmxa + +doc: *.ml + mkdir -p doc + ocamldoc -html -d doc -I ../../../bld_dbg/api/ml *.ml -hide Z3 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 321b17c82..2100f371e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -6,7 +6,6 @@ *) open Z3enums -open Z3native (**/**) @@ -18,27 +17,28 @@ object method virtual dispose : unit end +(** Context objects *) class context settings = object (self) inherit idisposable val mutable m_n_ctx : Z3native.z3_context = - let cfg = mk_config in - let f e = (set_param_value cfg (fst e) (snd e)) in + let cfg = Z3native.mk_config in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; - let v = mk_context_rc cfg in - del_config(cfg) ; + let v = Z3native.mk_context_rc cfg in + Z3native.del_config(cfg) ; v val mutable m_refCount : int = 0 initializer Gc.finalise (fun self -> self#dispose) self - + method dispose : unit = if m_refCount == 0 then ( Printf.printf "Disposing context %d \n" (Oo.id self) ; - (del_context m_n_ctx) + (Z3native.del_context m_n_ctx) ) else ( (* re-queue for finalization? *) ) @@ -48,6 +48,8 @@ object (self) method gno = m_n_ctx end + +(** Z3 objects *) class virtual z3object ctx_init obj_init = object (self) inherit idisposable @@ -56,14 +58,14 @@ object (self) initializer (match m_n_obj with - | Some (x) -> self#incref x; + | Some (x) -> self#incref m_ctx#gno x; m_ctx#add_one_ctx_obj | None -> () ); Gc.finalise (fun self -> self#dispose) self - method virtual incref : Z3native.ptr -> unit - method virtual decref : Z3native.ptr -> unit + method virtual incref : Z3native.ptr -> Z3native.ptr -> unit + method virtual decref : Z3native.ptr -> Z3native.ptr -> unit (* Disposes of the underlying native Z3 object. @@ -71,61 +73,415 @@ object (self) method dispose = Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with - | Some (x) -> self#decref x; m_n_obj <- None; m_ctx#sub_one_ctx_obj + | Some (x) -> self#decref m_ctx#gno x; m_n_obj <- None; m_ctx#sub_one_ctx_obj | None -> () ); - method gno = m_n_obj + method gno = match m_n_obj with + | Some(x) -> x + | None -> raise (Z3native.Exception "Z3 object lost") - method sno x = - (match x with - | Some(x) -> self#incref x - | None -> () - ); + method sno nc o = + self#incref nc o ; (match m_n_obj with - | Some(x) -> self#decref x + | Some(x) -> self#decref nc x | None -> () ); - m_n_obj <- x + m_n_obj <- Some o - method get_context = m_ctx + method gc = m_ctx method gnc = m_ctx#gno - -(* - method array_to_native a = - let f e = e#gno in - (Array.map f a) - - method array_length a = - match a with - | Some(x) -> (Array.length x) - | None -> 0 -*) - end -class symbol ctx obj = + +(** Parameter set objects *) +class params ctx obj = object (self) - inherit z3object ctx obj - - method incref o = () - method decref o = () + inherit z3object ctx obj as super + method incref ctx o = Z3native.params_inc_ref ctx o + method decref ctx o = Z3native.params_dec_ref ctx o end + +(** Symbol objects *) +class symbol ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method incref ctx o = () + method decref ctx o = () +end + +let symbolaton (a : symbol array) = + let f (e : symbol) = e#gno in + Array.map f a + +(** Int symbol objects *) class int_symbol ctx = object(self) - inherit symbol ctx None - method cnstr_obj obj = (self#sno obj) ; self - method cnstr_int i = (self#sno (Some (mk_int_symbol ctx#gno i))) ; self + inherit symbol ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_int i = (self#sno ctx#gno (Z3native.mk_int_symbol ctx#gno i)) ; self end +(** String symbol objects *) class string_symbol ctx = object(self) - inherit symbol ctx None - method cnstr_obj obj = (self#sno obj) ; self - method cnstr_string name = (self#sno (Some (mk_string_symbol ctx#gno name))) ; self + inherit symbol ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_string name = (self#sno ctx#gno (Z3native.mk_string_symbol ctx#gno name)) ; self end +let create_symbol ctx no = + match (int2symbol_kind (Z3native.get_symbol_kind ctx#gno no)) with + | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj no) :> symbol) + | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj no) :> symbol) + +(** AST objects *) +class ast ctx = +object (self) + inherit z3object ctx None as super (* CMW: derive from icomparable? *) + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + + method incref nc o = Z3native.inc_ref nc o + method decref nc o = Z3native.dec_ref nc o +end + +let astaton (a : ast array) = + let f (e : ast) = e#gno in + Array.map f a + +(** Sort objects *) +class sort ctx = +object (self) + inherit ast ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Arithmetic sort objects, i.e., Int or Real. *) +class arith_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Array sorts objects *) +class array_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx#gno (Z3native.mk_array_sort ctx#gno domain#gno range#gno)) ; self +end + +(** Bit-vector sort objects *) +class bitvec_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Boolean sort objects *) +class bool_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Datatype sort objects *) +class datatype_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_sc (name : symbol) constructors = (self#sno ctx#gno (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (astaton constructors)))) ; self +end + +(** Enum sort objects *) +class enum_sort ctx = +object (self) + inherit sort ctx as super + val mutable _constdecls = None + val mutable _testerdecls = None + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_ss (name : symbol) (enum_names : symbol array) = + let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in + _constdecls <- Some a ; + _testerdecls <- Some b ; + (self#sno ctx#gno r) ; + self + + method const_decls = match _constdecls with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing const decls") + + method tester_decls = match _testerdecls with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing tester decls") +end + +(** Int sort objects *) +class int_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Real sort objects *) +class real_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Uninterpreted sort objects *) +class uninterpreted_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_s (s : symbol) = (self #sno ctx#gno (Z3native.mk_uninterpreted_sort ctx#gno s#gno)) ; self +end + +(** Finite domain sort objects *) +class finite_domain_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx#gno (Z3native.mk_finite_domain_sort ctx#gno s#gno sz)) ; self +end + +(** Relation sort objects *) +class relation_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** List sort objects *) +class list_sort ctx = +object (self) + inherit sort ctx as super + val mutable _nildecl = None + val mutable _is_nildecl = None + val mutable _consdecl = None + val mutable _is_consdecl = None + val mutable _headdecl = None + val mutable _taildecl = None + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_ss (name : symbol) (elem_sort : sort) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in + _nildecl <- Some a ; + _is_nildecl <- Some b ; + _consdecl <- Some c ; + _is_consdecl <- Some d ; + _headdecl <- Some e ; + _taildecl <- Some f ; + (self#sno ctx#gno r) ; + self + + method nil_decl = match _nildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing nil decl") + + method is_nil_decl = match _is_nildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing is_nil decls") + + method cons_decl = match _consdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing cons decls") + + method is_cons_decl = match _is_consdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing is_cons decls") + + method head_decl = match _headdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing head decls") + + method tail_decl = match _taildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing tail decls") + +end + +(** Set sort objects *) +class set_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_s (s : sort) = (self#sno ctx#gno s#gno) ; self +end + +(** Tuple sort objects *) +class tuple_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_siss (name : symbol) (num_fields: int) (field_names : symbol array) (field_sorts : sort array) = + let (x,_,_) = (Z3native.mk_tuple_sort ctx#gno name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in + (self#sno ctx#gno x) ; + self +end + +let create_sort ctx obj = + match (int2sort_kind (Z3native.get_sort_kind ctx#gno obj)) with + | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) + | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) + | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) + | DATATYPE_SORT -> (((new datatype_sort ctx)#cnstr_obj obj) :> sort) + | INT_SORT -> (((new int_sort ctx)#cnstr_obj obj) :> sort) + | REAL_SORT -> (((new real_sort ctx)#cnstr_obj obj) :> sort) + | UNINTERPRETED_SORT -> (((new uninterpreted_sort ctx)#cnstr_obj obj) :> sort) + | FINITE_DOMAIN_SORT -> (((new finite_domain_sort ctx)#cnstr_obj obj) :> sort) + | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + +(** Function declaration objects *) +class func_decl ctx = +object (self) + inherit ast ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx#gno (Z3native.mk_func_decl ctx#gno name#gno (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx#gno (Z3native.mk_fresh_func_decl ctx#gno prefix (Array.length domain) (astaton domain) range#gno)) ; self + + method incref nc o = super#incref nc o + method decref nc o = super#decref nc o +end + +class parameter = +object (self) + val mutable m_kind : parameter_kind = PARAMETER_INT; + val mutable m_i : int = 0 + val mutable m_d : float = 0.0 + val mutable m_sym : symbol option = None + val mutable m_srt : sort option = None + val mutable m_ast : ast option = None + val mutable m_fd : func_decl option = None + val mutable m_r : string = "" + + method cnstr_int i = m_kind <- PARAMETER_INT; m_i <- i + method cnstr_double d = m_kind <- PARAMETER_DOUBLE; m_d <- d + method cnstr_symbol sym = m_kind <- PARAMETER_SYMBOL; m_sym <- sym + method cnstr_sort srt = m_kind <- PARAMETER_SORT; m_srt <- srt + method cnstr_ast ast = m_kind <- PARAMETER_AST; m_ast <- ast + method cnstr_func_decl fd = m_kind <- PARAMETER_FUNC_DECL; m_fd <- fd + method cnstr_rational r = m_kind <- PARAMETER_RATIONAL; m_r <- r + + method kind = m_kind + method int = m_i + method double = m_d + method symbol = match m_sym with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing parameter symbol") + method sort = match m_srt with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing parameter sort") + method ast = match m_ast with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing parameter ast") + method func_decl = match m_fd with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing parameter func_decl") + method rational = m_r +end + +(** Expression objects *) +class expr ctx = +object(self) + inherit ast ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +let expraton (a : expr array) = + let f (e : expr) = e#gno in + Array.map f a + +(** Boolean expression objects *) +class bool_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Arithmetic expression objects (int/real) *) +class arith_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Int expression objects *) +class int_expr ctx = +object (self) + inherit arith_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Real expression objects *) +class real_expr ctx = +object (self) + inherit arith_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Bit-vector expression objects *) +class bitvec_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Array expression objects *) +class array_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Datatype expression objects *) +class datatype_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Integer numeral expression objects *) +class int_num ctx = +object (self) + inherit int_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Rational numeral expression objects *) +class rat_num ctx = +object (self) + inherit real_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Bit-vector numeral expression objects *) +class bitvec_num ctx = +object (self) + inherit bitvec_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Algebraic numeral expression objects *) +class algebraic_num ctx = +object (self) + inherit arith_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + + +(** Quantifier objects *) +class quantifier ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + + + (**/**) (** Interaction logging for Z3. @@ -138,34 +494,34 @@ struct @return True if opening the log file succeeds, false otherwise. *) (* CMW: "open" seems to be a reserved keyword? *) - let open_ filename = ((int2lbool (open_log filename)) == L_TRUE) + let open_ filename = ((int2lbool (Z3native.open_log filename)) == L_TRUE) (** Closes the interaction log. *) - let close = close_log + let close = Z3native.close_log (** Appends a user-provided string to the interaction log. @param s the string to append*) - let append s = append_log s + let append s = Z3native.append_log s end (** Version information. *) module Version = struct (** The major version. *) - let major = let (x, _, _, _) = get_version in x + let major = let (x, _, _, _) = Z3native.get_version in x (** The minor version. *) - let minor = let (_, x, _, _) = get_version in x + let minor = let (_, x, _, _) = Z3native.get_version in x (** The build version. *) - let build = let (_, _, x, _) = get_version in x + let build = let (_, _, x, _) = Z3native.get_version in x (** The revision. *) - let revision = let (_, _, _, x) = get_version in x + let revision = let (_, _, _, x) = Z3native.get_version in x (** A string representation of the version information. *) let to_string = - let (mj, mn, bld, rev) = get_version in + let (mj, mn, bld, rev) = Z3native.get_version in string_of_int mj ^ "." ^ string_of_int mn ^ "." ^ string_of_int bld ^ "." ^ @@ -174,75 +530,5281 @@ end (** Symbols are used to name several term and type constructors. *) module Symbol = -struct -(**/**) - let create ctx obj = - match obj with - | Some(x) -> ( - match (int2symbol_kind (get_symbol_kind ctx#gno x)) with - | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj obj) :> symbol) - | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj obj) :> symbol) - ) - | None -> raise (Exception "Can't create null objects") -(**/**) - +struct (** The kind of the symbol (int or string) *) - let kind (o : symbol) = match o#gno with - | Some(x) -> (int2symbol_kind (get_symbol_kind o#gnc x)) - | _ -> raise (Exception "Underlying object lost") + let kind (o : symbol) = (int2symbol_kind (Z3native.get_symbol_kind o#gnc o#gno)) (** Indicates whether the symbol is of Int kind *) - let is_int_symbol (o : symbol) = match o#gno with - | Some(x) -> (kind o) == INT_SYMBOL - | _ -> false + let is_int_symbol (o : symbol) = (kind o) == INT_SYMBOL (** Indicates whether the symbol is of string kind. *) - let is_string_symbol (o : symbol) = match o#gno with - | Some(x) -> (kind o) == STRING_SYMBOL - | _ -> false + let is_string_symbol (o : symbol) = (kind o) == STRING_SYMBOL (** The int value of the symbol. *) - let get_int (o : int_symbol) = match o#gno with - | Some(x) -> (get_symbol_int o#gnc x) - | None -> 0 + let get_int (o : int_symbol) = Z3native.get_symbol_int o#gnc o#gno (** The string value of the symbol. *) - let get_string (o : string_symbol) = match o#gno with - | Some(x) -> (get_symbol_string o#gnc x) - | None -> "" + let get_string (o : string_symbol) = Z3native.get_symbol_string o#gnc o#gno (** A string representation of the symbol. *) - let to_string (o : symbol) = match o#gno with - | Some(x) -> - ( - match (kind o) with - | INT_SYMBOL -> (string_of_int (get_symbol_int o#gnc x)) - | STRING_SYMBOL -> (get_symbol_string o#gnc x) - ) - | None -> "" + let to_string (o : symbol) = + match (kind o) with + | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int o#gnc o#gno)) + | STRING_SYMBOL -> (Z3native.get_symbol_string o#gnc o#gno) end -(** The main interaction with Z3 happens via the Context. *) + +(** + The Sort module implements type information for ASTs. +*) +module Sort = +struct + (** + Comparison operator. + @param a A sort + @param b A sort + @return True if and are from the same context + and represent the same sort; false otherwise. + *) + let ( = ) (a : sort) (b : sort) = (a == b) || + if a#gnc != b#gnc then + false + else + ((int2lbool (Z3native.is_eq_sort a#gnc a#gno b#gno)) == L_TRUE) + + (** + Returns a unique identifier for the sort. + *) + let get_id (x : sort) = Z3native.get_sort_id x#gnc x#gno + + (** + The kind of the sort. + *) + let get_sort_kind (x : sort) = (int2sort_kind (Z3native.get_sort_kind x#gnc x#gno)) + + (** + The name of the sort + *) + let get_name (x : sort) = (create_symbol x#gc (Z3native.get_sort_name x#gnc x#gno)) + + (** + A string representation of the sort. + *) + let to_string (x : sort) = Z3native.sort_to_string x#gnc x#gno +end + +(** Array sorts *) +module ArraySort = +struct + (** The domain of the array sort. *) + let get_domain (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_domain x#gnc x#gno) + + (** The range of the array sort. *) + let get_range (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_range x#gnc x#gno) +end + +(** Bit-vector sorts *) +module BitVectorSort = +struct + (** The size of the bit-vector sort. *) + let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno +end + +(** Finite domain sorts. *) +module FiniteDomainSort = +struct + (** The size of the finite domain sort. *) + let get_size (x : finite_domain_sort) = + let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") +end + +(** Relation sorts. *) +module RelationSort = +struct + (** The arity of the relation sort. *) + let get_arity (x : relation_sort) = Z3native.get_relation_arity x#gnc x#gno + + (** The sorts of the columns of the relation sort. *) + let get_column_sorts (x : relation_sort) = + let n = get_arity x in + let f i = create_sort x#gc (Z3native.get_relation_column x#gnc x#gno i) in + Array.init n f + +end + +(**/**) +let create_expr ctx obj = + if int2ast_kind (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then + (((new quantifier ctx)#cnstr_obj obj) :> expr) + else + let s = Z3native.get_sort ctx#gno obj in + let sk = (int2sort_kind (Z3native.get_sort_kind ctx#gno s)) in + if (int2lbool (Z3native.is_algebraic_number ctx#gno obj) == L_TRUE) then + (((new algebraic_num ctx)#cnstr_obj obj) :> expr) + else + if ((int2lbool (Z3native.is_numeral_ast ctx#gno obj)) == L_TRUE) && + (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + match sk with + | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) + | REAL_SORT -> (((new rat_num ctx)#cnstr_obj obj) :> expr) + | BV_SORT -> (((new bitvec_num ctx)#cnstr_obj obj) :> expr) + | _ -> raise (Z3native.Exception "Unsupported numeral object") + else + match sk with + | BOOL_SORT -> (((new bool_expr ctx)#cnstr_obj obj) :> expr) + | INT_SORT -> (((new int_expr ctx)#cnstr_obj obj) :> expr) + | REAL_SORT -> (((new real_expr ctx)#cnstr_obj obj) :> expr) + | BV_SORT -> (((new bitvec_expr ctx)#cnstr_obj obj) :> expr) + | ARRAY_SORT -> (((new array_expr ctx)#cnstr_obj obj) :> expr) + | DATATYPE_SORT -> (((new datatype_expr ctx)#cnstr_obj obj) :> expr) + | _ -> (new expr ctx)#cnstr_obj obj + +let create_expr_fa (ctx : context) (f : func_decl) (args : expr array) = + let o = Z3native.mk_app ctx#gno f#gno (Array.length args) (astaton args) in + create_expr ctx o + +let create_ast ctx no = + match (int2ast_kind (Z3native.get_ast_kind ctx#gno no)) with + | FUNC_DECL_AST -> (((new func_decl ctx)#cnstr_obj no) :> ast) + | QUANTIFIER_AST -> (((new quantifier ctx)#cnstr_obj no) :> ast) + | SORT_AST -> ((create_sort ctx no) :> ast) + | APP_AST + | NUMERAL_AST + | VAR_AST -> ((create_expr ctx no) :> ast) + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") +(**/**) + +(** Function declarations. *) +module FuncDecl = +struct +(** Parameters of Func_Decls *) + module Parameter = + struct + (** + The kind of the parameter. + *) + let get_kind (x : parameter) = x#kind + + (**The int value of the parameter.*) + let get_int (x : parameter) = + if (x#kind != PARAMETER_INT) then + raise (Z3native.Exception "parameter is not an int") + else + x#int + + (**The double value of the parameter.*) + let get_double (x : parameter) = + if (x#kind != PARAMETER_DOUBLE) then + raise (Z3native.Exception "parameter is not a double") + else + x#double + + (**The Symbol value of the parameter.*) + let get_symbol (x : parameter) = + if (x#kind != PARAMETER_SYMBOL) then + raise (Z3native.Exception "parameter is not a symbol") + else + x#symbol + + (**The Sort value of the parameter.*) + let get_sort (x : parameter) = + if (x#kind != PARAMETER_SORT) then + raise (Z3native.Exception "parameter is not a sort") + else + x#sort + + (**The AST value of the parameter.*) + let get_ast (x : parameter) = + if (x#kind != PARAMETER_AST) then + raise (Z3native.Exception "parameter is not an ast") + else + x#ast + + (**The FunctionDeclaration value of the parameter.*) + let get_ast (x : parameter) = + if (x#kind != PARAMETER_FUNC_DECL) then + raise (Z3native.Exception "parameter is not an function declaration") + else + x#func_decl + + (**The rational string value of the parameter.*) + let get_rational (x : parameter) = + if (x#kind != PARAMETER_RATIONAL) then + raise (Z3native.Exception "parameter is not a ratinoal string") + else + x#rational + end + + (** + Comparison operator. + @param a A func_decl + @param b A func_decl + @return True if and are from the same context + and represent the same func_decl; false otherwise. + *) + let ( = ) (a : func_decl) (b : func_decl) = (a == b) || + if a#gnc == a#gnc then + false + else + ((int2lbool (Z3native.is_eq_func_decl a#gnc a#gno b#gno)) == L_TRUE) + (** + A string representations of the function declaration. + *) + let to_string (x : func_decl) = Z3native.func_decl_to_string x#gnc x#gno + + (** + Returns a unique identifier for the function declaration. + *) + let get_id (x : func_decl) = Z3native.get_func_decl_id x#gnc x#gno + + (** + The arity of the function declaration + *) + let get_arity (x : func_decl) = Z3native.get_arity x#gnc x#gno + + (** + The size of the domain of the function declaration + + *) + let get_domain_size (x : func_decl) = Z3native.get_domain_size x#gnc x#gno + + (** + The domain of the function declaration + *) + let get_domain (x : func_decl) = + let n = (get_domain_size x) in + let f i = create_sort x#gc (Z3native.get_domain x#gnc x#gno i) in + Array.init n f + + (** + The range of the function declaration + *) + let get_range (x : func_decl) = + create_sort x#gc (Z3native.get_range x#gnc x#gno) + + (** + The kind of the function declaration. + *) + let get_decl_kind (x : func_decl) = (int2decl_kind (Z3native.get_decl_kind x#gnc x#gno)) + + (** + The name of the function declaration + *) + let get_name (x : func_decl) = (create_symbol x#gc (Z3native.get_decl_name x#gnc x#gno)) + + (** + The number of parameters of the function declaration + *) + let get_num_parameters (x : func_decl) = (Z3native.get_decl_num_parameters x#gnc x#gno) + + (** + The parameters of the function declaration + *) + let get_parameters (x : func_decl) = + let n = (get_num_parameters x) in + let f i = ( + match (int2parameter_kind (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with + | PARAMETER_INT -> (new parameter)#cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) + | PARAMETER_DOUBLE -> (new parameter)#cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) + | PARAMETER_SYMBOL-> (new parameter)#cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) + | PARAMETER_SORT -> (new parameter)#cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) + | PARAMETER_AST -> (new parameter)#cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) + | PARAMETER_FUNC_DECL -> (new parameter)#cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) + | PARAMETER_RATIONAL -> (new parameter)#cnstr_rational (Z3native.get_decl_rational_parameter x#gnc x#gno i) + ) in + Array.init n f + + (** + Create expression that applies function to arguments. + + *) + let apply (x : func_decl) (args : expr array) = create_expr_fa x#gc x args + +end + +(** Datatype sorts *) +module DatatypeSort = +struct + (** The number of constructors of the datatype sort. *) + let get_num_constructors (x : datatype_sort) = Z3native.get_datatype_sort_num_constructors x#gnc x#gno + + (** The range of the array sort. *) + let get_constructors (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i) in + Array.init n f + + (** The recognizers. *) + let get_recognizers (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_recognizer x#gnc x#gno i) in + Array.init n f + + (** The constructor accessors. *) + let get_accessors (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = ( + let fd = ((new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i)) in + let ds = (Z3native.get_domain_size fd#gnc fd#gno) in + let g j = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor_accessor x#gnc x#gno i j) in + Array.init ds g + ) in + Array.init n f +end + +(** Enumeration sorts. *) +module EnumSort = +struct + (** The function declarations of the constants in the enumeration. *) + let get_const_decls (x : enum_sort) = + let f e = ((new func_decl x#gc)#cnstr_obj e) in + Array.map f x#const_decls + + (** The test predicates for the constants in the enumeration. *) + let get_tester_decls (x : enum_sort) = + let f e = ((new func_decl x#gc)#cnstr_obj e) in + Array.map f x#tester_decls +end + +(** List sorts. *) +module ListSort = +struct + (** The declaration of the nil function of this list sort. *) + let get_nil_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#nil_decl + + (** The declaration of the isNil function of this list sort. *) + let get_is_nil_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#is_nil_decl + + (** The declaration of the cons function of this list sort. *) + let get_cons_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#cons_decl + + (** The declaration of the isCons function of this list sort. *) + let get_is_cons_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#is_cons_decl + + (** The declaration of the head function of this list sort.*) + let get_head_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#head_decl + + (** The declaration of the tail function of this list sort. *) + let get_tail_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#tail_decl + + (** The empty list. *) + let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] +end + +module TupleSort = +struct + (** The constructor function of the tuple.*) + let get_mk_decl (x : tuple_sort) = + (new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_mk_decl x#gnc x#gno) + + (** The number of fields in the tuple. *) + let get_num_fields (x : tuple_sort) = Z3native.get_tuple_sort_num_fields x#gnc x#gno + + (** The field declarations. *) + let get_field_decls (x : tuple_sort) = + let n = get_num_fields x in + let f i = ((new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_field_decl x#gnc x#gno i)) in + Array.init n f +end + +(** The abstract syntax tree (AST) module. *) +module AST = +struct + (** + The AST's hash code. + @return A hash code + *) + let get_hash_code ( x : ast) = Z3native.get_ast_hash x#gnc x#gno + + (** + A unique identifier for the AST (unique among all ASTs). + *) + let get_id ( x : ast) = Z3native.get_ast_id x#gnc x#gno + + (** + The kind of the AST. + *) + let get_ast_kind ( x : ast) = (int2ast_kind (Z3native.get_ast_kind x#gnc x#gno)) + + (** + Indicates whether the AST is an Expr + *) + let is_expr ( x : ast) = + match get_ast_kind ( x : ast) with + | APP_AST + | NUMERAL_AST + | QUANTIFIER_AST + | VAR_AST -> true + | _ -> false + + (** + Indicates whether the AST is a BoundVariable + *) + let is_var ( x : ast) = (get_ast_kind x) == VAR_AST + + (** + Indicates whether the AST is a Quantifier + *) + let is_quantifier ( x : ast) = (get_ast_kind x) == QUANTIFIER_AST + + + (** + Indicates whether the AST is a Sort + *) + let is_sort ( x : ast) = (get_ast_kind x) == SORT_AST + + (** + Indicates whether the AST is a FunctionDeclaration + *) + let is_func_decl ( x : ast) = (get_ast_kind x) == FUNC_DECL_AST + + (** + A string representation of the AST. + *) + let to_string ( x : ast) = Z3native.ast_to_string x#gnc x#gno + + (** + A string representation of the AST in s-expression notation. + *) + let to_sexpr ( x : ast) = Z3native.ast_to_string x#gnc x#gno + + (** + Comparison operator. + @param a An AST + @param b An AST + @return True if and are from the same context + and represent the same sort; false otherwise. + *) + let ( = ) (a : expr) (b : expr) = (a == b) || + if a#gnc == b#gnc then + false + else + ((int2lbool (Z3native.is_eq_ast a#gnc a#gno b#gno)) == L_TRUE) + + (** + Object Comparison. + @param other Another ast + @return Negative if the object should be sorted before , positive if after else zero. + *) + let compare a b = + if (get_id a) < (get_id b) then -1 else + if (get_id a) > (get_id b) then 1 else + 0 + + (** Operator < *) + let ( < ) (a : ast) (b : ast) = (compare a b) + + (** + Translates (copies) the AST to the Context . + @param ctx A context + @return A copy of the AST which is associated with + *) + let translate ( x : ast) to_ctx = + if x#gc == to_ctx then + x + else + (create_ast to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno)) +end + +(** + Parameter sets + + A Params objects represents a configuration in the form of Symbol/value pairs. +*) +module Params = +struct + (** + Adds a parameter setting. + *) + let add_bool (p : params) (name : symbol) (value : bool) = + Z3native.params_set_bool p#gnc p#gno name#gno (lbool2int (if value then L_TRUE else L_FALSE)) + + (** + Adds a parameter setting. + *) + let add_int (p : params) (name : symbol) (value : int) = + Z3native.params_set_uint p#gnc p#gno name#gno value + + (** + Adds a parameter setting. + *) + let add_double (p : params) (name : symbol) (value : float) = + Z3native.params_set_double p#gnc p#gno name#gno value + + (** + Adds a parameter setting. + *) + let add_symbol (p : params) (name : symbol) (value : symbol) = + Z3native.params_set_symbol p#gnc p#gno name#gno value#gno + + (** + Adds a parameter setting. + *) + let add_s_bool (p : params) (name : string) (value : bool) = + add_bool p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_int (p : params) (name : string) (value : int) = + add_int p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_double (p : params) (name : string) (value : float) = + add_double p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_symbol (p : params) (name : string) (value : symbol) = + add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + A string representation of the parameter set. + *) + let to_string (p : params) = Z3native.params_to_string p#gnc p#gno +end + +(** Expressions (terms) *) +module Expr = +struct + (** + Returns a simplified version of the expression. + A set of parameters to configure the simplifier + + *) + let simplify ( x : expr ) ( p : params option ) = match p with + | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) + | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno pp#gno) + + (** + The function declaration of the function that is applied in this expression. + *) + let get_func_decl ( x : expr ) = (new func_decl x#gc)#cnstr_obj (Z3native.get_app_decl x#gnc x#gno) + + (** + Indicates whether the expression is the true or false expression + or something else (Z3_L_UNDEF). + *) + let get_bool_value ( x : expr ) = int2lbool (Z3native.get_bool_value x#gnc x#gno) + + (** + The number of arguments of the expression. + *) + let get_num_args ( x : expr ) = Z3native.get_app_num_args x#gnc x#gno + + (** + The arguments of the expression. + *) + let get_args ( x : expr ) = let n = (get_num_args x) in + let f i = create_expr x#gc (Z3native.get_app_arg x#gnc x#gno i) in + Array.init n f + + (** + Update the arguments of the expression using the arguments + The number of new arguments should coincide with the current number of arguments. + *) + let update ( x : expr ) args = + if (Array.length args <> (get_num_args x)) then + raise (Z3native.Exception "Number of arguments does not match") + else + x#sno x#gnc (Z3native.update_term x#gnc x#gno (Array.length args) (expraton 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]. + + *) + let substitute ( x : expr ) from to_ = + if (Array.length from) <> (Array.length to_) then + raise (Z3native.Exception "Argument sizes do not match") + else + create_expr x#gc (Z3native.substitute x#gnc x#gno (Array.length from) (expraton from) (expraton to_)) + + (** + Substitute every occurrence of from in the expression with to. + + *) + let substitute_one ( x : expr ) from to_ = + substitute ( x : expr ) [| from |] [| 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]. + + *) + let substitute_vars ( x : expr ) to_ = + create_expr x#gc (Z3native.substitute_vars x#gnc x#gno (Array.length to_) (expraton to_)) + + + (** + Translates (copies) the term to the Context . + A context + A copy of the term which is associated with + *) + let translate ( x : expr ) to_ctx = + if x#gc == to_ctx then + x + else + create_expr to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno) + + (** + Returns a string representation of the expression. + *) + let to_string ( x : expr ) = Z3native.ast_to_string x#gnc x#gno + + (** + Indicates whether the term is a numeral + *) + let is_numeral ( x : expr ) = int2lbool (Z3native.is_numeral_ast x#gnc x#gno) == L_TRUE + + (** + Indicates whether the term is well-sorted. + True if the term is well-sorted, false otherwise. + *) + let is_well_sorted ( x : expr ) = int2lbool (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE + + (** + The Sort of the term. + *) + let get_sort ( x : expr ) = create_sort x#gc (Z3native.get_sort x#gnc x#gno) + + (** + Indicates whether the term has Boolean sort. + *) + let is_bool ( x : expr ) = (AST.is_expr x) && + (int2lbool (Z3native.is_eq_sort x#gnc + (Z3native.mk_bool_sort x#gnc) + (Z3native.get_sort x#gnc x#gno))) == L_TRUE + + (** + Indicates whether the term is of integer sort. + *) + let is_int ( x : expr ) = + ((int2lbool (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && + ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) + + (** + Indicates whether the term is of sort real. + *) + let is_real ( x : expr ) = + ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) + + (** + Indicates whether the term is of an array sort. + *) + let is_array ( x : expr ) = + ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + + (** + Indicates whether the term represents a constant. + *) + let is_const ( x : expr ) = (AST.is_expr x) && + (get_num_args x) == 0 && + FuncDecl.get_domain_size(get_func_decl x) == 0 + + (** + Indicates whether the term is an integer numeral. + *) + let is_int_numeral ( x : expr ) = (is_numeral x) && (is_int x) + + (** + Indicates whether the term is a real numeral. + *) + let is_rat_num ( x : expr ) = (is_numeral x) && (is_real x) + + (** + Indicates whether the term is an algebraic number + *) + let is_algebraic_number ( x : expr ) = int2lbool(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE + + (** + Indicates whether the term is the constant true. + *) + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) + + (** + Indicates whether the term is the constant false. + *) + let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) + + (** + Indicates whether the term is an equality predicate. + *) + let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) + + (** + Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). + *) + let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) + + (** + Indicates whether the term is a ternary if-then-else term + *) + let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) + + (** + Indicates whether the term is an n-ary conjunction + *) + let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) + + (** + Indicates whether the term is an n-ary disjunction + *) + let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) + + (** + Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) + *) + let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) + + (** + Indicates whether the term is an exclusive or + *) + let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) + + (** + Indicates whether the term is a negation + *) + let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) + + (** + Indicates whether the term is an implication + *) + let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) + + (** + Indicates whether the term is an arithmetic numeral. + *) + let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ANUM) + + (** + Indicates whether the term is a less-than-or-equal + *) + let is_le ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LE) + + (** + Indicates whether the term is a greater-than-or-equal + *) + let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_GE) + + (** + Indicates whether the term is a less-than + *) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LT) + + (** + Indicates whether the term is a greater-than + *) + let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_GT) + + (** + Indicates whether the term is addition (binary) + *) + let is_add ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ADD) + + (** + Indicates whether the term is subtraction (binary) + *) + let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SUB) + + (** + Indicates whether the term is a unary minus + *) + let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UMINUS) + + (** + Indicates whether the term is multiplication (binary) + *) + let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_MUL) + + (** + Indicates whether the term is division (binary) + *) + let is_div ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DIV) + + (** + Indicates whether the term is integer division (binary) + *) + let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IDIV) + + (** + Indicates whether the term is remainder (binary) + *) + let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_REM) + + (** + Indicates whether the term is modulus (binary) + *) + let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_MOD) + + (** + Indicates whether the term is a coercion of integer to real (unary) + *) + let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TO_REAL) + + (** + Indicates whether the term is a coercion of real to integer (unary) + *) + let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TO_INT) + + (** + Indicates whether the term is a check that tests whether a real is integral (unary) + *) + let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IS_INT) + + (** + 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. + *) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_STORE) + + (** + Indicates whether the term is an array select. + *) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CONST_ARRAY) + + (** + Indicates whether the term is a default array. + For example default(const(v)) = v. The function is unary. + *) + let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AS_ARRAY) + + (** + Indicates whether the term is set union + *) + let is_set_union ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_UNION) + + (** + Indicates whether the term is set intersection + *) + let is_set_intersect ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_INTERSECT) + + (** + Indicates whether the term is set difference + *) + let is_set_difference ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_DIFFERENCE) + + (** + Indicates whether the term is set complement + *) + let is_set_complement ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_COMPLEMENT) + + (** + Indicates whether the term is set subset + *) + let is_set_subset ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_SUBSET) + + (** + Indicates whether the terms is of bit-vector sort. + *) + let is_bv ( x : expr ) = + ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == BV_SORT) + + (** + Indicates whether the term is a bit-vector numeral + *) + let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNUM) + + (** + Indicates whether the term is a one-bit bit-vector with value one + *) + let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BIT1) + + (** + Indicates whether the term is a one-bit bit-vector with value zero + *) + let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BIT0) + + (** + Indicates whether the term is a bit-vector unary minus + *) + let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNEG) + + (** + Indicates whether the term is a bit-vector addition (binary) + *) + let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BADD) + + (** + Indicates whether the term is a bit-vector subtraction (binary) + *) + let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSUB) + + (** + Indicates whether the term is a bit-vector multiplication (binary) + *) + let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BMUL) + + (** + Indicates whether the term is a bit-vector signed division (binary) + *) + let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSDIV) + + (** + Indicates whether the term is a bit-vector unsigned division (binary) + *) + let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUDIV) + + (** + Indicates whether the term is a bit-vector signed remainder (binary) + *) + let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSREM) + + (** + Indicates whether the term is a bit-vector unsigned remainder (binary) + *) + let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUREM) + + (** + Indicates whether the term is a bit-vector signed modulus + *) + let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSMOD) + + (** + Indicates whether the term is a bit-vector signed division by zero + *) + let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSDIV0) + + (** + Indicates whether the term is a bit-vector unsigned division by zero + *) + let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUDIV0) + + (** + Indicates whether the term is a bit-vector signed remainder by zero + *) + let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSREM0) + + (** + Indicates whether the term is a bit-vector unsigned remainder by zero + *) + let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUREM0) + + (** + Indicates whether the term is a bit-vector signed modulus by zero + *) + let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSMOD0) + + (** + Indicates whether the term is an unsigned bit-vector less-than-or-equal + *) + let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ULEQ) + + (** + Indicates whether the term is a signed bit-vector less-than-or-equal + *) + let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SLEQ) + + (** + Indicates whether the term is an unsigned bit-vector greater-than-or-equal + *) + let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UGEQ) + + (** + Indicates whether the term is a signed bit-vector greater-than-or-equal + *) + let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SGEQ) + + (** + Indicates whether the term is an unsigned bit-vector less-than + *) + let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ULT) + + (** + Indicates whether the term is a signed bit-vector less-than + *) + let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SLT) + + (** + Indicates whether the term is an unsigned bit-vector greater-than + *) + let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UGT) + + (** + Indicates whether the term is a signed bit-vector greater-than + *) + let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SGT) + + (** + Indicates whether the term is a bit-wise AND + *) + let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BAND) + + (** + Indicates whether the term is a bit-wise OR + *) + let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BOR) + + (** + Indicates whether the term is a bit-wise NOT + *) + let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNOT) + + (** + Indicates whether the term is a bit-wise XOR + *) + let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BXOR) + + (** + Indicates whether the term is a bit-wise NAND + *) + let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNAND) + + (** + Indicates whether the term is a bit-wise NOR + *) + let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNOR) + + (** + Indicates whether the term is a bit-wise XNOR + *) + let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BXNOR) + + (** + Indicates whether the term is a bit-vector concatenation (binary) + *) + let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CONCAT) + + (** + Indicates whether the term is a bit-vector sign extension + *) + let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SIGN_EXT) + + (** + Indicates whether the term is a bit-vector zero extension + *) + let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ZERO_EXT) + + (** + Indicates whether the term is a bit-vector extraction + *) + let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EXTRACT) + + (** + Indicates whether the term is a bit-vector repetition + *) + let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_REPEAT) + + (** + Indicates whether the term is a bit-vector reduce OR + *) + let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BREDOR) + + (** + Indicates whether the term is a bit-vector reduce AND + *) + let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BREDAND) + + (** + Indicates whether the term is a bit-vector comparison + *) + let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BCOMP) + + (** + Indicates whether the term is a bit-vector shift left + *) + let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSHL) + + (** + Indicates whether the term is a bit-vector logical shift right + *) + let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BLSHR) + + (** + Indicates whether the term is a bit-vector arithmetic shift left + *) + let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BASHR) + + (** + Indicates whether the term is a bit-vector rotate left + *) + let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ROTATE_LEFT) + + (** + Indicates whether the term is a bit-vector rotate right + *) + let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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))) + *) + let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + *) + let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) + + (** + Indicates whether the term is a Proof for the expression 'true'. + *) + let is_proof_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TRUE) + + (** + Indicates whether the term is a proof for a fact asserted by the user. + *) + let is_proof_asserted ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_ASSERTED) + + (** + Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. + *) + let is_proof_goal ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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). + *) + let is_proof_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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'. + *) + let is_proof_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + + *) + let is_proof_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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)) + + *) + let is_proof_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 + + *) + let is_proof_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + + *) + let is_proof_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) + + *) + let is_proof_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + + *) + let is_proof_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 + + *) + let is_proof_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 + + *) + let is_proof_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. + + This proof object has no antecedents. + + Several variables can be eliminated simultaneously. + + *) + let is_proof_der ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DER) + + (** + Indicates whether the term is a proof for quantifier instantiation + + A proof of (or (not (forall (x) (P x))) (P a)) + + *) + let is_proof_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_QUANT_INST) + + (** + Indicates whether the term is a hypthesis marker. + Mark a hypothesis in a natural deduction style proof. + *) + let is_proof_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_lemma ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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') + + *) + let is_proof_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_UNIT_RESOLUTION) + + (** + Indicates whether the term is a proof by iff-true + + T1: p + [iff-true T1]: (iff p true) + + *) + let is_proof_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_IFF_TRUE) + + (** + Indicates whether the term is a proof by iff-false + + T1: (not p) + [iff-false T1]: (iff p false) + + *) + let is_proof_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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). + + *) + let is_proof_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + + *) + let is_proof_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_APPLY_DEF) + + (** + Indicates whether the term is a proof iff-oeq + + T1: (iff p q) + [iff~ T1]: (~ p q) + + *) + let is_proof_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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'. + + *) + let is_proof_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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'))) + + *) + let is_proof_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_CNF_STAR) + + (** + Indicates whether the term is a proof for a Skolemization step + + Proof for: + + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + + This proof object has no antecedents. + + *) + let is_proof_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 + + *) + let is_proof_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TH_LEMMA) + + (** + Indicates whether the term is of a relation sort. + *) + let is_Relation ( x : expr ) = + ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == 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. + + *) + let is_relation_store ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_STORE) + + (** + Indicates whether the term is an empty relation + *) + let is_empty_relation ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_EMPTY) + + (** + Indicates whether the term is a test for the emptiness of a relation + *) + let is_is_empty_relation ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_IS_EMPTY) + + (** + Indicates whether the term is a relational join + *) + let is_relational_join ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_JOIN) + + (** + Indicates whether the term is the union or convex hull of two relations. + The function takes two arguments. + *) + let is_relation_union ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_UNION) + + (** + Indicates whether the term is the widening of two relations + The function takes two arguments. + *) + let is_relation_widen ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_WIDEN) + + (** + Indicates whether the term is a projection of columns (provided as numbers in the parameters). + The function takes one argument. + *) + let is_relation_project ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_relation_filter ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. + + *) + let is_relation_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_relation_rename ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_RENAME) + + (** + Indicates whether the term is the complement of a relation + *) + let is_relation_complement ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_relation_select ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_relation_clone ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_CLONE) + + (** + Indicates whether the term is of an array sort. + *) + let is_finite_domain ( x : expr ) = + ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) + + (** + Indicates whether the term is a less than predicate over a finite domain. + *) + let is_finite_domain_lt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) appears, the higher is its + index. + + *) + let get_index ( x : expr ) = + if not (AST.is_var x) then + raise (Z3native.Exception "Term is not a bound variable.") + else + Z3native.get_index_value x#gnc x#gno +end + +(* Integer Numerals *) +module IntNum = +struct + (** Retrieve the int value. *) + let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno +end + +(** Rational Numerals *) +module RatNum = +struct + + (** The numerator of a rational numeral. *) + let get_numerator ( x : rat_num ) = + (new int_num x#gc)#cnstr_obj (Z3native.get_numerator x#gnc x#gno) + + (** The denominator of a rational numeral. *) + let get_denominator ( x : rat_num ) = + (new int_num x#gc)#cnstr_obj (Z3native.get_denominator x#gnc x#gno) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : rat_num ) (precision : int) = + Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : rat_num ) = Z3native.get_numeral_string x#gnc x#gno +end + +(** Bit-vector numerals *) +module BitVecNum = +struct + (** Retrieve the int value. *) + let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno +end + +(** Algebraic numbers *) +module AlgebraicNum = +struct + (** + 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 + A numeral Expr of sort Real + *) + let to_upper ( x : algebraic_num ) ( precision : int ) = + (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) + + (** + Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + + + A numeral Expr of sort Real + *) + let to_lower ( x : algebraic_num ) precision = + (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : algebraic_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno +end + +(** The main interaction with Z3 happens via the Context module. *) module Context = struct + + (* SYMBOLS *) + (** Creates a new symbol using an integer. Not all integers can be passed to this function. The legal range of unsigned integers is 0 to 2^30-1. *) - let mk_symbol_int ctx i = + let mk_symbol_int ( ctx : context ) i = (new int_symbol ctx)#cnstr_int i - + (** Creates a new symbol using a string. *) - let mk_symbol_string ctx s = + let mk_symbol_string ( ctx : context ) s = (new string_symbol ctx)#cnstr_string s (** Create an array of symbols. *) - let mk_symbols ctx names = - let f elem = mk_symbol_string ctx elem in + let mk_symbols_int ( ctx : context ) names = + let f elem = mk_symbol_int ( ctx : context ) elem in + (Array.map f names) + + (** + Create an array of symbols. + *) + let mk_symbols_string ( ctx : context ) names = + let f elem = mk_symbol_string ( ctx : context ) elem in (Array.map f names) + + (* SORTS *) + + (** + Create a new Boolean sort. + *) + let mk_bool_sort ( ctx : context ) = + (new bool_sort ctx) + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted_sort ( ctx : context ) (s : symbol) = + (new uninterpreted_sort ctx)#cnstr_s s + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted_sort_s ( ctx : context ) (s : string) = + mk_uninterpreted_sort ctx ((mk_symbol_string ( ctx : context ) s) :> symbol) + + (** + Create a new integer sort. + *) + let mk_int_sort ( ctx : context ) = + (new int_sort ctx) + + (** + Create a real sort. + *) + let mk_real_sort ( ctx : context ) = + (new real_sort ctx) + + (** + Create a new bit-vector sort. + *) + let mk_bitvec_sort ( ctx : context ) size = + (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort ctx#gno size) + + (** + Create a new array sort. + *) + let mk_array_sort ( ctx : context ) domain range = + (new array_sort ctx)#cnstr_dr domain range + + (** + Create a new tuple sort. + *) + let mk_tuple_sort ( ctx : context ) name field_names field_sorts = + (new tuple_sort ctx)#cnstr_siss name (Array.length field_names) field_names field_sorts + + (** + Create a new enumeration sort. + *) + let mk_enum_sort ( ctx : context ) name enum_names = + (new enum_sort ctx)#cnstr_ss name enum_names + + (** + Create a new enumeration sort. + *) + let mk_enum_sort_s ( ctx : context ) name enum_names = + (new enum_sort ctx)#cnstr_ss + ((mk_symbol_string ( ctx : context ) name) :> symbol) + (let f e = (e :> symbol) in + (Array.map f (mk_symbols_string ( ctx : context ) enum_names)) + ) + + (** + Create a new list sort. + *) + let mk_list_sort ( ctx : context ) (name : symbol) elem_sort = + (new list_sort ctx)#cnstr_ss name elem_sort + + (** + Create a new list sort. + *) + let mk_list_sort_s ( ctx : context ) (name : string) elem_sort = + mk_list_sort ctx ((mk_symbol_string ctx name) :> symbol) elem_sort + + + (** + Create a new finite domain sort. + *) + let mk_finite_domain_sort ( ctx : context ) ( name : symbol ) size = + (new finite_domain_sort ctx)#cnstr_si name size + + (** + Create a new finite domain sort. + *) + let mk_finite_domain_sort_s ( ctx : context ) ( name : string ) size = + (new finite_domain_sort ctx)#cnstr_si ((mk_symbol_string ctx name) :> symbol) size + +(** + +(* DATATYPES *) +(** + Create a datatype constructor. +*) + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + public Constructor MkConstructor(Symbol name, Symbol recognizer, Symbol[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null) + { + + + + + return new Constructor(this, name, recognizer, fieldNames, sorts, sortRefs); + } + +(** + Create a datatype constructor. +*) + @param name + @param recognizer + @param fieldNames + @param sorts + @param sortRefs + @return + public Constructor MkConstructor(string name, string recognizer, string[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null) + { + + + return new Constructor(this, MkSymbol(name), MkSymbol(recognizer), MkSymbols(fieldNames), sorts, sortRefs); + } + +(** + Create a new datatype sort. +*) + let mk_Datatype_Sort(Symbol name, Constructor[] constructors) + { + + + + + + + CheckContextMatch(name); + CheckContextMatch(constructors); + return new DatatypeSort(this, name, constructors); + } + +(** + Create a new datatype sort. +*) + let mk_Datatype_Sort(string name, Constructor[] constructors) + { + + + + + CheckContextMatch(constructors); + return new DatatypeSort(this, MkSymbol(name), constructors); + } + +(** + Create mutually recursive datatypes. +*) + @param names names of datatype sorts + @param c list of constructors, one list per sort. + let mk_Datatype_Sorts(Symbol[] names, Constructor[][] c) + { + + + + + + + + CheckContextMatch(names); + uint n = (uint)names.Length; + ConstructorList[] cla = new ConstructorList[n]; + IntPtr[] n_constr = new IntPtr[n]; + for (uint i = 0; i < n; i++) + { + Constructor[] constructor = c[i]; + + CheckContextMatch(constructor); + cla[i] = new ConstructorList(this, constructor); + n_constr[i] = cla[i].x#gno; + } + IntPtr[] n_res = new IntPtr[n]; + Z3native.mk_datatypes(nCtx, n, Symbol.ArrayToNative(names), n_res, n_constr); + DatatypeSort[] res = new DatatypeSort[n]; + for (uint i = 0; i < n; i++) + res[i] = new DatatypeSort(this, n_res[i]); + return res; + } + +(** + Create mutually recursive data-types. +*) + @param names + @param c + @return + let mk_Datatype_Sorts(string[] names, Constructor[][] c) + { + + + + + + + + return MkDatatypeSorts(MkSymbols(names), c); + } + + + + +(* FUNCTION DECLARATIONS *) +(** + Creates a new function declaration. +*) + public Func_Decl MkFunc_Decl(Symbol name, Sort[] domain, Sort range) + { + + + + + + CheckContextMatch(name); + CheckContextMatch(domain); + CheckContextMatch(range); + return new Func_Decl(this, name, domain, range); + } + +(** + Creates a new function declaration. +*) + public Func_Decl MkFunc_Decl(Symbol name, Sort domain, Sort range) + { + + + + + + CheckContextMatch(name); + CheckContextMatch(domain); + CheckContextMatch(range); + Sort[] q = new Sort[] { domain }; + return new Func_Decl(this, name, q, range); + } + +(** + Creates a new function declaration. +*) + public Func_Decl MkFunc_Decl(string name, Sort[] domain, Sort range) + { + + + + + CheckContextMatch(domain); + CheckContextMatch(range); + return new Func_Decl(this, MkSymbol(name), domain, range); + } + +(** + Creates a new function declaration. +*) + public Func_Decl MkFunc_Decl(string name, Sort domain, Sort range) + { + + + + + CheckContextMatch(domain); + CheckContextMatch(range); + Sort[] q = new Sort[] { domain }; + return new Func_Decl(this, MkSymbol(name), q, range); + } + +(** + Creates a fresh function declaration with a name prefixed with . +*) + + + let mk_Fresh_Func_Decl(string prefix, Sort[] domain, Sort range) + { + + + + + CheckContextMatch(domain); + CheckContextMatch(range); + return new Func_Decl(this, prefix, domain, range); + } + +(** + Creates a new constant function declaration. +*) + let mk_Const_Decl(Symbol name, Sort range) + { + + + + + CheckContextMatch(name); + CheckContextMatch(range); + return new Func_Decl(this, name, null, range); + } + +(** + Creates a new constant function declaration. +*) + let mk_Const_Decl(string name, Sort range) + { + + + + CheckContextMatch(range); + return new Func_Decl(this, MkSymbol(name), null, range); + } + +(** + Creates a fresh constant function declaration with a name prefixed with . +*) + + + let mk_Fresh_ConstDecl(string prefix, Sort range) + { + + + + CheckContextMatch(range); + return new Func_Decl(this, prefix, null, range); + } + + +(* BOUND VARIABLES *) +(** + Creates a new bound variable. +*) + @param index The de-Bruijn index of the variable + @param ty The sort of the variable + public Expr MkBound(uint index, Sort ty) + { + + + + return Expr.Create(this, Z3native.mk_bound(nCtx, index, ty.x#gno)); + } + + +(* QUANTIFIER PATTERNS *) +(** + Create a quantifier pattern. +*) + public Pattern MkPattern(params 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, Z3native.mk_pattern(nCtx, (uint)terms.Length, termsNative)); + } + + +(* CONSTANTS *) +(** + Creates a new Constant of sort and named . +*) + public Expr MkConst(Symbol name, Sort range) + { + + + + + CheckContextMatch(name); + CheckContextMatch(range); + + return Expr.Create(this, Z3native.mk_const(nCtx, name.x#gno, range.x#gno)); + } + +(** + 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 . +*) + let mk_Fresh_Const(string prefix, Sort range) + { + + + + CheckContextMatch(range); + return Expr.Create(this, Z3native.mk_fresh_const(nCtx, prefix, range.x#gno)); + } + +(** + Creates a fresh constant from the Func_Decl . +*) + @param f A decl of a 0-arity function + public Expr MkConst(Func_Decl f) + { + + + + return MkApp(f); + } + +(** + Create a Boolean constant. +*) + let mk_Bool_Const(Symbol name) + { + + + + return (BoolExpr)MkConst(name, BoolSort); + } + +(** + Create a Boolean constant. +*) + let mk_Bool_Const(string name) + { + + + return (BoolExpr)MkConst(MkSymbol(name), BoolSort); + } + +(** + Creates an integer constant. +*) + let mk_Int_Const(Symbol name) + { + + + + return (IntExpr)MkConst(name, IntSort); + } + +(** + Creates an integer constant. +*) + let mk_Int_Const(string name) + { + + + + return (IntExpr)MkConst(name, IntSort); + } + +(** + Creates a real constant. +*) + let mk_Real_Const(Symbol name) + { + + + + return (RealExpr)MkConst(name, RealSort); + } + +(** + Creates a real constant. +*) + let mk_Real_Const(string name) + { + + + return (RealExpr)MkConst(name, RealSort); + } + +(** + Creates a bit-vector constant. +*) + let mk_B_VConst(Symbol name, uint size) + { + + + + return (BitVecExpr)MkConst(name, MkBitVecSort(size)); + } + +(** + Creates a bit-vector constant. +*) + let mk_B_VConst(string name, uint size) + { + + + return (BitVecExpr)MkConst(name, MkBitVecSort(size)); + } + + +(* TERMS *) +(** + Create a new function application. +*) + public Expr MkApp(Func_Decl f, params Expr[] args) + { + + + + + CheckContextMatch(f); + CheckContextMatch(args); + return Expr.Create(this, f, args); + } + +(* PROPOSITIONAL *) +(** + The true Term. +*) + public BoolExpr MkTrue ( ctx : context ) = + { + + + return new BoolExpr(this, Z3native.mk_true(nCtx)); + } + +(** + The false Term. +*) + public BoolExpr MkFalse ( ctx : context ) = + { + + + return new BoolExpr(this, Z3native.mk_false(nCtx)); + } + +(** + Creates a Boolean value. +*) + public BoolExpr MkBool(bool value) + { + + + return value ? MkTrue ( ctx : context ) = : MkFalse ( ctx : context ) =; + } + +(** + Creates the equality = . +*) + public BoolExpr MkEq(Expr x, Expr y) + { + + + + + CheckContextMatch(x); + CheckContextMatch(y); + return new BoolExpr(this, Z3native.mk_eq(nCtx, x.x#gno, y.x#gno)); + } + +(** + Creates a distinct term. +*) + public BoolExpr MkDistinct(params Expr[] args) + { + + + + + + CheckContextMatch(args); + return new BoolExpr(this, Z3native.mk_distinct(nCtx, (uint)args.Length, AST.ArrayToNative(args))); + } + +(** + Mk an expression representing not(a). +*) + public BoolExpr MkNot(BoolExpr a) + { + + + + CheckContextMatch(a); + return new BoolExpr(this, Z3native.mk_not(nCtx, a.x#gno)); + } + +(** + Create an expression representing an if-then-else: ite(t1, t2, t3). +*) + @param t1 An expression with Boolean sort + @param t2 An expression + @param t3 An expression with the same sort as + let mk_I_TE(BoolExpr t1, Expr t2, Expr t3) + { + + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + CheckContextMatch(t3); + return Expr.Create(this, Z3native.mk_ite(nCtx, t1.x#gno, t2.x#gno, t3.x#gno)); + } + +(** + Create an expression representing t1 iff t2. +*) + public BoolExpr MkIff(BoolExpr t1, BoolExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_iff(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 -> t2. +*) + public BoolExpr MkImplies(BoolExpr t1, BoolExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_implies(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 xor t2. +*) + public BoolExpr MkXor(BoolExpr t1, BoolExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_xor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t[0] and t[1] and .... +*) + public BoolExpr MkAnd(params BoolExpr[] t) + { + + + + + CheckContextMatch(t); + return new BoolExpr(this, Z3native.mk_and(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + +(** + Create an expression representing t[0] or t[1] or .... +*) + public BoolExpr MkOr(params BoolExpr[] t) + { + + + + + CheckContextMatch(t); + return new BoolExpr(this, Z3native.mk_or(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + + +(* ARITHMETIC *) +(** + Create an expression representing t[0] + t[1] + .... +*) + public ArithExpr MkAdd(params ArithExpr[] t) + { + + + + + CheckContextMatch(t); + return (ArithExpr)Expr.Create(this, Z3native.mk_add(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + +(** + Create an expression representing t[0] * t[1] * .... +*) + public ArithExpr MkMul(params ArithExpr[] t) + { + + + + + CheckContextMatch(t); + return (ArithExpr)Expr.Create(this, Z3native.mk_mul(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + +(** + Create an expression representing t[0] - t[1] - .... +*) + public ArithExpr MkSub(params ArithExpr[] t) + { + + + + + CheckContextMatch(t); + return (ArithExpr)Expr.Create(this, Z3native.mk_sub(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + +(** + Create an expression representing -t. +*) + let mk_Unary_Minus(ArithExpr t) + { + + + + CheckContextMatch(t); + return (ArithExpr)Expr.Create(this, Z3native.mk_unary_minus(nCtx, t.x#gno)); + } + +(** + Create an expression representing t1 / t2. +*) + public ArithExpr MkDiv(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return (ArithExpr)Expr.Create(this, Z3native.mk_div(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, Z3native.mk_mod(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, Z3native.mk_rem(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 ^ t2. +*) + public ArithExpr MkPower(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return (ArithExpr)Expr.Create(this, Z3native.mk_power(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 < t2 +*) + public BoolExpr MkLt(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_lt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 <= t2 +*) + public BoolExpr MkLe(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_le(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 > t2 +*) + public BoolExpr MkGt(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_gt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 >= t2 +*) + public BoolExpr MkGe(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_ge(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, Z3native.mk_int2real(nCtx, t.x#gno)); + } + +(** + 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, Z3native.mk_real2int(nCtx, t.x#gno)); + } + +(** + Creates an expression that checks whether a real number is an integer. +*) + let mk_Is_Integer(RealExpr t) + { + + + + CheckContextMatch(t); + return new BoolExpr(this, Z3native.mk_is_int(nCtx, t.x#gno)); + } + + +(* BIT-VECTORS *) +(** + Bitwise negation. +*) + The argument must have a bit-vector sort. + let mk_B_VNot(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_bvnot(nCtx, t.x#gno)); + } + +(** + Take conjunction of bits in a vector, return vector of length 1. +*) + The argument must have a bit-vector sort. + let mk_B_VRedAND(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_bvredand(nCtx, t.x#gno)); + } + +(** + Take disjunction of bits in a vector, return vector of length 1. +*) + The argument must have a bit-vector sort. + let mk_B_VRedOR(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_bvredor(nCtx, t.x#gno)); + } + +(** + Bitwise conjunction. +*) + The arguments must have a bit-vector sort. + let mk_B_VAND(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvand(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise disjunction. +*) + The arguments must have a bit-vector sort. + let mk_B_VOR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise XOR. +*) + The arguments must have a bit-vector sort. + let mk_B_VXOR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvxor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise NAND. +*) + The arguments must have a bit-vector sort. + let mk_B_VNAND(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvnand(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise NOR. +*) + The arguments must have a bit-vector sort. + let mk_B_VNOR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvnor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise XNOR. +*) + The arguments must have a bit-vector sort. + let mk_B_VXNOR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvxnor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Standard two's complement unary minus. +*) + The arguments must have a bit-vector sort. + let mk_B_VNeg(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_bvneg(nCtx, t.x#gno)); + } + +(** + Two's complement addition. +*) + The arguments must have the same bit-vector sort. + let mk_B_VAdd(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvadd(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement subtraction. +*) + The arguments must have the same bit-vector sort. + let mk_B_VSub(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvsub(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement multiplication. +*) + The arguments must have the same bit-vector sort. + let mk_B_VMul(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvmul(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VUDiv(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvudiv(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VSDiv(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvsdiv(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VURem(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvurem(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VSRem(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvsrem(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VSMod(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvsmod(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Unsigned less-than +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VULT(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvult(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement signed less-than +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VSLT(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvslt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Unsigned less-than or equal to. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VULE(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvule(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement signed less-than or equal to. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VSLE(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsle(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Unsigned greater than or equal to. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VUGE(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvuge(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement signed greater than or equal to. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VSGE(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsge(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Unsigned greater-than. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VUGT(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvugt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement signed greater-than. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VSGT(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsgt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, Z3native.mk_concat(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bit-vector extraction. +*) + + Extract the bits down to from a bitvector of + size m to yield a new bitvector of size n, where + n = high - low + 1. + The argument must have a bit-vector sort. + + public BitVecExpr MkExtract(uint high, uint low, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_extract(nCtx, high, low, t.x#gno)); + } + +(** + 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. + + let mk_Sign_Ext(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_sign_ext(nCtx, i, t.x#gno)); + } + +(** + 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. + + let mk_Zero_Ext(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_zero_ext(nCtx, i, t.x#gno)); + } + +(** + Bit-vector repetition. +*) + + The argument must have a bit-vector sort. + + public BitVecExpr MkRepeat(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_repeat(nCtx, i, t.x#gno)); + } + +(** + 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. + + let mk_B_VSHL(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvshl(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VLSHR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvlshr(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VASHR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvashr(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Rotate Left. +*) + + Rotate bits of \c t to the left \c i times. + The argument must have a bit-vector sort. + + let mk_B_VRotateLeft(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_rotate_left(nCtx, i, t.x#gno)); + } + +(** + Rotate Right. +*) + + Rotate bits of \c t to the right \c i times. + The argument must have a bit-vector sort. + + let mk_B_VRotateRight(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_rotate_right(nCtx, i, t.x#gno)); + } + +(** + Rotate Left. +*) + + Rotate bits of to the left times. + The arguments must have the same bit-vector sort. + + let mk_B_VRotateLeft(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_ext_rotate_left(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Rotate Right. +*) + + Rotate bits of to the right times. + The arguments must have the same bit-vector sort. + + let mk_B_VRotateRight(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_ext_rotate_right(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an bit bit-vector from the integer argument . +*) + + NB. This function is essentially treated as uninterpreted. + So you cannot expect Z3 to precisely reflect the semantics of this function + when solving constraints with this function. + + The argument must be of integer sort. + + public BitVecExpr MkInt2BV(uint n, IntExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_int2bv(nCtx, n, t.x#gno)); + } + +(** + 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. + + let mk_B_V2Int(BitVecExpr t, bool signed) + { + + + + CheckContextMatch(t); + return new IntExpr(this, Z3native.mk_bv2int(nCtx, t.x#gno, (signed) ? 1 : 0)); + } + +(** + Create a predicate that checks that the bit-wise addition does not overflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VAddNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvadd_no_overflow(nCtx, t1.x#gno, t2.x#gno, (isSigned) ? 1 : 0)); + } + +(** + Create a predicate that checks that the bit-wise addition does not underflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VAddNoUnderflow(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvadd_no_underflow(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create a predicate that checks that the bit-wise subtraction does not overflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VSubNoOverflow(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsub_no_overflow(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create a predicate that checks that the bit-wise subtraction does not underflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VSubNoUnderflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsub_no_underflow(nCtx, t1.x#gno, t2.x#gno, (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. + + let mk_B_VSDivNoOverflow(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsdiv_no_overflow(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create a predicate that checks that the bit-wise negation does not overflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VNegNoOverflow(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BoolExpr(this, Z3native.mk_bvneg_no_overflow(nCtx, t.x#gno)); + } + +(** + Create a predicate that checks that the bit-wise multiplication does not overflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VMulNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvmul_no_overflow(nCtx, t1.x#gno, t2.x#gno, (isSigned) ? 1 : 0)); + } + +(** + Create a predicate that checks that the bit-wise multiplication does not underflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VMulNoUnderflow(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvmul_no_underflow(nCtx, t1.x#gno, t2.x#gno)); + } + + +(* ARRAYS *) +(** + Create an array constant. +*) + let mk_Array_Const(Symbol name, Sort domain, Sort range) + { + + + + + + return (ArrayExpr)MkConst(name, MkArraySort(domain, range)); + } + +(** + Create an array constant. +*) + let mk_Array_Const(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, Z3native.mk_select(nCtx, a.x#gno, i.x#gno)); + } + +(** + 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, Z3native.mk_store(nCtx, a.x#gno, i.x#gno, v.x#gno)); + } + +(** + Create a constant array. +*) + + The resulting term is an array, such that a selecton an arbitrary index + produces the value v. + + + + let mk_Const_Array(Sort domain, Expr v) + { + + + + + CheckContextMatch(domain); + CheckContextMatch(v); + return new ArrayExpr(this, Z3native.mk_const_array(nCtx, domain.x#gno, v.x#gno)); + } + +(** + 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(Func_Decl f, params ArrayExpr[] args) + { + + + + + CheckContextMatch(f); + CheckContextMatch(args); + return (ArrayExpr)Expr.Create(this, Z3native.mk_map(nCtx, f.x#gno, 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. + + let mk_Term_Array(ArrayExpr array) + { + + + + CheckContextMatch(array); + return Expr.Create(this, Z3native.mk_array_default(nCtx, array.x#gno)); + } + + +(* SETS *) +(** + Create a set type. +*) + let mk_Set_Sort(Sort ty) + { + + + + CheckContextMatch(ty); + return new SetSort(this, ty); + } + +(** + Create an empty set. +*) + let mk_Empty_Set(Sort domain) + { + + + + CheckContextMatch(domain); + return Expr.Create(this, Z3native.mk_empty_set(nCtx, domain.x#gno)); + } + +(** + Create the full set. +*) + let mk_Full_Set(Sort domain) + { + + + + CheckContextMatch(domain); + return Expr.Create(this, Z3native.mk_full_set(nCtx, domain.x#gno)); + } + +(** + Add an element to the set. +*) + let mk_Set_Add(Expr set, Expr element) + { + + + + + CheckContextMatch(set); + CheckContextMatch(element); + return Expr.Create(this, Z3native.mk_set_add(nCtx, set.x#gno, element.x#gno)); + } + + +(** + Remove an element from a set. +*) + let mk_Set_Del(Expr set, Expr element) + { + + + + + CheckContextMatch(set); + CheckContextMatch(element); + return Expr.Create(this, Z3native.mk_set_del(nCtx, set.x#gno, element.x#gno)); + } + +(** + Take the union of a list of sets. +*) + let mk_Set_Union(params Expr[] args) + { + + + + CheckContextMatch(args); + return Expr.Create(this, Z3native.mk_set_union(nCtx, (uint)args.Length, AST.ArrayToNative(args))); + } + +(** + Take the intersection of a list of sets. +*) + let mk_Set_Intersection(params Expr[] args) + { + + + + + CheckContextMatch(args); + return Expr.Create(this, Z3native.mk_set_intersect(nCtx, (uint)args.Length, AST.ArrayToNative(args))); + } + +(** + Take the difference between two sets. +*) + let mk_Set_Difference(Expr arg1, Expr arg2) + { + + + + + CheckContextMatch(arg1); + CheckContextMatch(arg2); + return Expr.Create(this, Z3native.mk_set_difference(nCtx, arg1.x#gno, arg2.x#gno)); + } + +(** + Take the complement of a set. +*) + let mk_Set_Complement(Expr arg) + { + + + + CheckContextMatch(arg); + return Expr.Create(this, Z3native.mk_set_complement(nCtx, arg.x#gno)); + } + +(** + Check for set membership. +*) + let mk_Set_Membership(Expr elem, Expr set) + { + + + + + CheckContextMatch(elem); + CheckContextMatch(set); + return Expr.Create(this, Z3native.mk_set_member(nCtx, elem.x#gno, set.x#gno)); + } + +(** + Check for subsetness of sets. +*) + let mk_Set_Subset(Expr arg1, Expr arg2) + { + + + + + CheckContextMatch(arg1); + CheckContextMatch(arg2); + return Expr.Create(this, Z3native.mk_set_subset(nCtx, arg1.x#gno, arg2.x#gno)); + } + + +(* NUMERALS *) + +(* GENERAL NUMERALS *) +(** + Create a Term of a given sort. +*) + @param v 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]*. + @param ty 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, Z3native.mk_numeral(nCtx, v, ty.x#gno)); + } + +(** + 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. +*) + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(int v, Sort ty) + { + + + + CheckContextMatch(ty); + return Expr.Create(this, Z3native.mk_int(nCtx, v, ty.x#gno)); + } + +(** + 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. +*) + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(uint v, Sort ty) + { + + + + CheckContextMatch(ty); + return Expr.Create(this, Z3native.mk_unsigned_int(nCtx, v, ty.x#gno)); + } + +(** + 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. +*) + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(long v, Sort ty) + { + + + + CheckContextMatch(ty); + return Expr.Create(this, Z3native.mk_int64(nCtx, v, ty.x#gno)); + } + +(** + 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. +*) + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(ulong v, Sort ty) + { + + + + CheckContextMatch(ty); + return Expr.Create(this, Z3native.mk_unsigned_int64(nCtx, v, ty.x#gno)); + } + + +(* REALS *) +(** + Create a real from a fraction. +*) + @param num numerator of rational. + @param den 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, Z3native.mk_real(nCtx, num, den)); + } + +(** + Create a real numeral. +*) + @param v 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, Z3native.mk_numeral(nCtx, v, RealSort.x#gno)); + } + +(** + Create a real numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(int v) + { + + + return new RatNum(this, Z3native.mk_int(nCtx, v, RealSort.x#gno)); + } + +(** + Create a real numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(uint v) + { + + + return new RatNum(this, Z3native.mk_unsigned_int(nCtx, v, RealSort.x#gno)); + } + +(** + Create a real numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(long v) + { + + + return new RatNum(this, Z3native.mk_int64(nCtx, v, RealSort.x#gno)); + } + +(** + Create a real numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(ulong v) + { + + + return new RatNum(this, Z3native.mk_unsigned_int64(nCtx, v, RealSort.x#gno)); + } + + +(* INTEGERS *) +(** + Create an integer numeral. +*) + @param v A string representing the Term value in decimal notation. + public IntNum MkInt(string v) + { + + + return new IntNum(this, Z3native.mk_numeral(nCtx, v, IntSort.x#gno)); + } + +(** + Create an integer numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(int v) + { + + + return new IntNum(this, Z3native.mk_int(nCtx, v, IntSort.x#gno)); + } + +(** + Create an integer numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(uint v) + { + + + return new IntNum(this, Z3native.mk_unsigned_int(nCtx, v, IntSort.x#gno)); + } + +(** + Create an integer numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(long v) + { + + + return new IntNum(this, Z3native.mk_int64(nCtx, v, IntSort.x#gno)); + } + +(** + Create an integer numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(ulong v) + { + + + return new IntNum(this, Z3native.mk_unsigned_int64(nCtx, v, IntSort.x#gno)); + } + + +(* BIT-VECTORS *) +(** + Create a bit-vector numeral. +*) + @param v A string representing the value in decimal notation. + @param size the size of the bit-vector + let mk_B_V(string v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + +(** + Create a bit-vector numeral. +*) + @param v value of the numeral. + @param size the size of the bit-vector + let mk_B_V(int v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + +(** + Create a bit-vector numeral. +*) + @param v value of the numeral. + @param size the size of the bit-vector + let mk_B_V(uint v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + +(** + Create a bit-vector numeral. +*) + @param v value of the numeral. + @param size the size of the bit-vector + let mk_B_V(long v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + +(** + Create a bit-vector numeral. +*) + @param v value of the numeral. + @param size the size of the bit-vector + let mk_B_V(ulong v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + + + // Numerals + +(* QUANTIFIERS *) +(** + 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. + + @param sorts the sorts of the bound variables. + @param names names of the bound variables + @param body the body of the quantifier. + @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. + @param patterns array containing the patterns created using MkPattern. + @param noPatterns array containing the anti-patterns created using MkPattern. + @param quantifierID optional symbol to track quantifier. + @param skolemID optional symbol to track skolem constants. + public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + + + + + return new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); + } + + +(** + Create a universal Quantifier. +*) + public Quantifier MkForall(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + 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, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + + + + return new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); + } + +(** + Create an existential Quantifier. +*) + public Quantifier MkExists(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + return new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); + } + + +(** + Create a Quantifier. +*) + public Quantifier MkQuantifier(bool universal, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + + + + + 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(bool universal, Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + if (universal) + return MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); + else + return MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); + } + + + + // Expr + +(* OPTIONS *) + +(** + 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 Z3_ast_print_mode PrintMode + { + set { Z3native.set_ast_print_mode(nCtx, (uint)value); } + } + + +(* SMT Files & Strings *) +(** + Convert a benchmark into an SMT-LIB formatted string. +*) + @param name Name of the benchmark. The argument is optional. + @param logic The benchmark logic. + @param status The status string (sat, unsat, or unknown) + @param attributes Other attributes, such as source, difficulty or category. + @param assumptions Auxiliary assumptions. + @param formula 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 Z3native.benchmark_to_smtlib_string(nCtx, name, logic, status, attributes, + (uint)assumptions.Length, AST.ArrayToNative(assumptions), + formula.x#gno); + } + +(** + 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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + { + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_string(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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + { + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_file(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 uint NumSMTLIBFormulas { get { return Z3native.get_smtlib_num_formulas(nCtx)) + +(** + The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public BoolExpr[] SMTLIBFormulas + { + get + { + + + uint n = NumSMTLIBFormulas; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)Expr.Create(this, Z3native.get_smtlib_formula(nCtx, i)); + return res; + } + } + +(** + The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public uint NumSMTLIBAssumptions { get { return Z3native.get_smtlib_num_assumptions(nCtx)) + +(** + The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public BoolExpr[] SMTLIBAssumptions + { + get + { + + + uint n = NumSMTLIBAssumptions; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)Expr.Create(this, Z3native.get_smtlib_assumption(nCtx, i)); + return res; + } + } + +(** + The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public uint NumSMTLIBDecls { get { return Z3native.get_smtlib_num_decls(nCtx)) + +(** + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public Func_Decl[] SMTLIBDecls + { + get + { + + + uint n = NumSMTLIBDecls; + Func_Decl[] res = new Func_Decl[n]; + for (uint i = 0; i < n; i++) + res[i] = new Func_Decl(this, Z3native.get_smtlib_decl(nCtx, i)); + return res; + } + } + +(** + The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public uint NumSMTLIBSorts { get { return Z3native.get_smtlib_num_sorts(nCtx)) + +(** + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public Sort[] SMTLIBSorts + { + get + { + + + uint n = NumSMTLIBSorts; + Sort[] res = new Sort[n]; + for (uint i = 0; i < n; i++) + res[i] = Sort.Create(this, Z3native.get_smtlib_sort(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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + { + + + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + return (BoolExpr)Expr.Create(this, Z3native.parse_smtlib2_string(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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + { + + + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + return (BoolExpr)Expr.Create(this, Z3native.parse_smtlib2_file(nCtx, fileName, + AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); + } + + +(* GOALS *) +(** + Creates a new Goal. +*) + + Note that the Context must have been created with proof generation support if + is set to true here. + + @param models Indicates whether model generation should be enabled. + @param unsatCores Indicates whether unsat core generation should be enabled. + @param proofs Indicates whether proof generation should be enabled. + public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) + { + + + return new Goal(this, models, unsatCores, proofs); + } + + +(* PARAMETERSETS *) +(** + Creates a new ParameterSet. +*) + public Params MkParams ( ctx : context ) = + { + + + return new Params(this); + } + + +(* TACTICS *) +(** + The number of supported tactics. +*) + public uint NumTactics + { + get { return Z3native.get_num_tactics(nCtx); } + } + +(** + The names of all supported tactics. +*) + public string[] TacticNames + { + get + { + + + uint n = NumTactics; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_tactic_name(nCtx, i); + return res; + } + } + +(** + Returns a string containing a description of the tactic with the given name. +*) + public string TacticDescription(string name) + { + + + return Z3native.tactic_get_descr(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, params Tactic[] ts) + { + + + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + CheckContextMatch(ts); + + IntPtr last = IntPtr.Zero; + if (ts != null && ts.Length > 0) + { + last = ts[ts.Length - 1].x#gno; + for (int i = ts.Length - 2; i >= 0; i--) + last = Z3native.tactic_and_then(nCtx, ts[i].x#gno, last); + } + if (last != IntPtr.Zero) + { + last = Z3native.tactic_and_then(nCtx, t2.x#gno, last); + return new Tactic(this, Z3native.tactic_and_then(nCtx, t1.x#gno, last)); + } + else + return new Tactic(this, Z3native.tactic_and_then(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, params 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, Z3native.tactic_or_else(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create a tactic that applies to a goal for milliseconds. +*) + + If does not terminate within milliseconds, then it fails. + + public Tactic TryFor(Tactic t, uint ms) + { + + + + CheckContextMatch(t); + return new Tactic(this, Z3native.tactic_try_for(nCtx, t.x#gno, 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, Z3native.tactic_when(nCtx, p.x#gno, t.x#gno)); + } + +(** + 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, Z3native.tactic_cond(nCtx, p.x#gno, t1.x#gno, t2.x#gno)); + } + +(** + 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, uint max = uint.MaxValue) + { + + + + CheckContextMatch(t); + return new Tactic(this, Z3native.tactic_repeat(nCtx, t.x#gno, max)); + } + +(** + Create a tactic that just returns the given goal. +*) + public Tactic Skip ( ctx : context ) = + { + + + return new Tactic(this, Z3native.tactic_skip(nCtx)); + } + +(** + Create a tactic always fails. +*) + public Tactic Fail ( ctx : context ) = + { + + + return new Tactic(this, Z3native.tactic_fail(nCtx)); + } + +(** + Create a tactic that fails if the probe evaluates to false. +*) + public Tactic FailIf(Probe p) + { + + + + CheckContextMatch(p); + return new Tactic(this, Z3native.tactic_fail_if(nCtx, p.x#gno)); + } + +(** + 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 ( ctx : context ) = + { + + + return new Tactic(this, Z3native.tactic_fail_if_not_decided(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, Z3native.tactic_using_params(nCtx, t.x#gno, p.x#gno)); + } + +(** + 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(params Tactic[] t) + { + + + + CheckContextMatch(t); + return new Tactic(this, Z3native.tactic_par_or(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, Z3native.tactic_par_and_then(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Interrupt the execution of a Z3 procedure. +*) + This procedure can be used to interrupt: solvers, simplifiers and tactics. + public void Interrupt ( ctx : context ) = + { + Z3native.interrupt(nCtx); + } + + +(* PROBES *) +(** + The number of supported Probes. +*) + public uint NumProbes + { + get { return Z3native.get_num_probes(nCtx); } + } + +(** + The names of all supported Probes. +*) + public string[] ProbeNames + { + get + { + + + uint n = NumProbes; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_probe_name(nCtx, i); + return res; + } + } + +(** + Returns a string containing a description of the probe with the given name. +*) + public string ProbeDescription(string name) + { + + + return Z3native.probe_get_descr(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, Z3native.probe_const(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, Z3native.probe_lt(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_gt(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_le(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_ge(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_eq(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_and(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_or(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_not(nCtx, p.x#gno)); + } + + +(* SOLVERS *) +(** + 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 = null) + { + + + if (logic == null) + return new Solver(this, Z3native.mk_solver(nCtx)); + else + return new Solver(this, Z3native.mk_solver_for_logic(nCtx, logic.x#gno)); + } + +(** + Creates a new (incremental) solver. +*) + + public Solver MkSolver(string logic) + { + + + return MkSolver(MkSymbol(logic)); + } + +(** + Creates a new (incremental) solver. +*) + let mk_Simple_Solver ( ctx : context ) = + { + + + return new Solver(this, Z3native.mk_simple_solver(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, Z3native.mk_solver_from_tactic(nCtx, t.x#gno)); + } + + +(* FIXEDPOINTS *) +(** + Create a Fixedpoint context. +*) + public Fixedpoint MkFixedpoint ( ctx : context ) = + { + + + return new Fixedpoint(this); + } + + + +(* MISCELLANEOUS *) +(** + 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., + . + + @param nativeObject 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., + ). + + @param a The AST to unwrap. + public IntPtr UnwrapAST(AST a) + { + return a.x#gno; + } + +(** + Return a string describing all available parameters to Expr.Simplify. +*) + public string SimplifyHelp ( ctx : context ) = + { + + + return Z3native.simplify_get_help(nCtx); + } + +(** + Retrieves parameter descriptions for simplifier. +*) + public ParamDescrs SimplifyParameterDescriptions + { + get { return new ParamDescrs(this, Z3native.simplify_get_param_descrs(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(bool enabled) + { + Z3native.toggle_warning_messages((enabled) ? 1 : 0); + } + + +(* ERROR HANDLING *) + //(** + //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; + + +(* PARAMETERS *) +(** + 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) + { + Z3native.update_param_value(nCtx, id, value); + } + +(** + Get a configuration parameter. +*) + + Returns null if the parameter value does not exist. + + + public string GetParamValue(string id) + { + IntPtr res = IntPtr.Zero; + int r = Z3native.get_param_value(nCtx, id, out res); + if (r == (int)Z3_lbool.Z3_L_FALSE) + return null; + else + return Marshal.PtrToStringAnsi(res); + } + + + +(* INTERNAL *) + internal IntPtr m_ctx = IntPtr.Zero; + internal Z3native.error_handler m_n_err_handler = null; + internal IntPtr nCtx { get { return m_ctx) + + internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) + { + // Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. + } + + internal void InitContext ( ctx : context ) = + { + PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); // keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); + } +*) end From 2277ad3654e4778d6ca9b0a904c4ac8e637cce4f Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 01:45:10 +0000 Subject: [PATCH 022/248] ML API bugfixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 8 ++- scripts/update_api.py | 2 +- src/api/ml/z3.ml | 136 ++++++++++++++++++++------------------ 3 files changed, 80 insertions(+), 66 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 7046a92b0..f414e9d1a 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -18,10 +18,16 @@ let _ = let ctx = (new context cfg) in let is = (mk_symbol_int ctx 42) in let ss = (mk_symbol_string ctx "mySymbol") in + let bs = (mk_bool_sort ctx) in + let ints = (mk_int_sort ctx) in + let rs = (mk_real_sort ctx) in Printf.printf "int symbol: %s\n" (Symbol.to_string (is :> symbol)); Printf.printf "string symbol: %s\n" (Symbol.to_string (ss :> symbol)); + Printf.printf "bool sort: %s\n" (Sort.to_string bs); + Printf.printf "int sort: %s\n" (Sort.to_string ints); + Printf.printf "real sort: %s\n" (Sort.to_string rs); Printf.printf "Disposing...\n"; - ctx#dispose (* can do, but we'd rather let it go out of scope *) ; + Gc.full_major () ); Printf.printf "Exiting.\n"; ;; diff --git a/scripts/update_api.py b/scripts/update_api.py index c8cd05c7e..c3f2abce6 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1280,7 +1280,7 @@ def mk_ml(): ml_wrapper.write(' CAMLxparam3(X11,X12,X13); \n') ml_wrapper.write('\n\n') ml_wrapper.write('static struct custom_operations default_custom_ops = {\n') - ml_wrapper.write(' identifier: "default handling",\n') + ml_wrapper.write(' identifier: (char*) "default handling",\n') ml_wrapper.write(' finalize: custom_finalize_default,\n') ml_wrapper.write(' compare: custom_compare_default,\n') ml_wrapper.write(' hash: custom_hash_default,\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 2100f371e..3a0e9208e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -30,21 +30,25 @@ object (self) Z3native.del_config(cfg) ; v - val mutable m_refCount : int = 0 + val mutable m_obj_cnt : int = 0 initializer - Gc.finalise (fun self -> self#dispose) self + (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) + let f = fun o -> o#dispose in + let v = self in + Gc.finalise f v method dispose : unit = - if m_refCount == 0 then ( - Printf.printf "Disposing context %d \n" (Oo.id self) ; + if m_obj_cnt == 0 then ( + (* Printf.printf "Disposing context %d \n" (Oo.id self) ; *) (Z3native.del_context m_n_ctx) ) else ( + Printf.printf "NOT DISPOSING context %d because it still has %d objects alive\n" (Oo.id self) m_obj_cnt; (* re-queue for finalization? *) ) - method sub_one_ctx_obj = m_refCount <- m_refCount - 1 - method add_one_ctx_obj = m_refCount <- m_refCount + 1 + method add_one_ctx_obj = m_obj_cnt <- m_obj_cnt + 1 + method sub_one_ctx_obj = m_obj_cnt <- m_obj_cnt - 1 method gno = m_n_ctx end @@ -62,18 +66,21 @@ object (self) m_ctx#add_one_ctx_obj | None -> () ); - Gc.finalise (fun self -> self#dispose) self + (* Printf.printf "Installing finalizer on z3object %d \n" (Oo.id self) ; *) + let f = fun o -> o#dispose in + let v = self in + Gc.finalise f v method virtual incref : Z3native.ptr -> Z3native.ptr -> unit method virtual decref : Z3native.ptr -> Z3native.ptr -> unit - (* - Disposes of the underlying native Z3 object. - *) method dispose = - Printf.printf "Disposing z3object %d \n" (Oo.id self) ; + (* Printf.printf "Disposing z3object %d \n" (Oo.id self) ; *) (match m_n_obj with - | Some (x) -> self#decref m_ctx#gno x; m_n_obj <- None; m_ctx#sub_one_ctx_obj + | Some (x) -> + self#decref m_ctx#gno x; + m_ctx#sub_one_ctx_obj ; + m_n_obj <- None; | None -> () ); @@ -81,10 +88,11 @@ object (self) | Some(x) -> x | None -> raise (Z3native.Exception "Z3 object lost") - method sno nc o = - self#incref nc o ; + method sno (ctx : context) o = + m_ctx#add_one_ctx_obj ; + self#incref ctx#gno o ; (match m_n_obj with - | Some(x) -> self#decref nc x + | Some(x) -> self#decref ctx#gno x ; m_ctx#sub_one_ctx_obj | None -> () ); m_n_obj <- Some o @@ -107,7 +115,7 @@ end class symbol ctx = object (self) inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method incref ctx o = () method decref ctx o = () end @@ -120,16 +128,16 @@ let symbolaton (a : symbol array) = class int_symbol ctx = object(self) inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_int i = (self#sno ctx#gno (Z3native.mk_int_symbol ctx#gno i)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_int i = (self#sno ctx (Z3native.mk_int_symbol ctx#gno i)) ; self end (** String symbol objects *) class string_symbol ctx = object(self) inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_string name = (self#sno ctx#gno (Z3native.mk_string_symbol ctx#gno name)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_string name = (self#sno ctx (Z3native.mk_string_symbol ctx#gno name)) ; self end let create_symbol ctx no = @@ -141,7 +149,7 @@ let create_symbol ctx no = class ast ctx = object (self) inherit z3object ctx None as super (* CMW: derive from icomparable? *) - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method incref nc o = Z3native.inc_ref nc o method decref nc o = Z3native.dec_ref nc o @@ -155,44 +163,44 @@ let astaton (a : ast array) = class sort ctx = object (self) inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Arithmetic sort objects, i.e., Int or Real. *) class arith_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Array sorts objects *) class array_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx#gno (Z3native.mk_array_sort ctx#gno domain#gno range#gno)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx (Z3native.mk_array_sort ctx#gno domain#gno range#gno)) ; self end (** Bit-vector sort objects *) class bitvec_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Boolean sort objects *) class bool_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Datatype sort objects *) class datatype_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_sc (name : symbol) constructors = (self#sno ctx#gno (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (astaton constructors)))) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_sc (name : symbol) constructors = (self#sno ctx (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (astaton constructors)))) ; self end (** Enum sort objects *) @@ -201,12 +209,12 @@ object (self) inherit sort ctx as super val mutable _constdecls = None val mutable _testerdecls = None - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (enum_names : symbol array) = let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in _constdecls <- Some a ; _testerdecls <- Some b ; - (self#sno ctx#gno r) ; + (self#sno ctx r) ; self method const_decls = match _constdecls with @@ -222,37 +230,37 @@ end class int_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Real sort objects *) class real_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Uninterpreted sort objects *) class uninterpreted_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_s (s : symbol) = (self #sno ctx#gno (Z3native.mk_uninterpreted_sort ctx#gno s#gno)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_s (s : symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort ctx#gno s#gno)) ; self end (** Finite domain sort objects *) class finite_domain_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx#gno (Z3native.mk_finite_domain_sort ctx#gno s#gno sz)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort ctx#gno s#gno sz)) ; self end (** Relation sort objects *) class relation_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** List sort objects *) @@ -265,7 +273,7 @@ object (self) val mutable _is_consdecl = None val mutable _headdecl = None val mutable _taildecl = None - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (elem_sort : sort) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in _nildecl <- Some a ; @@ -274,7 +282,7 @@ object (self) _is_consdecl <- Some d ; _headdecl <- Some e ; _taildecl <- Some f ; - (self#sno ctx#gno r) ; + (self#sno ctx r) ; self method nil_decl = match _nildecl with @@ -307,18 +315,18 @@ end class set_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_s (s : sort) = (self#sno ctx#gno s#gno) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_s (s : sort) = (self#sno ctx s#gno) ; self end (** Tuple sort objects *) class tuple_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_siss (name : symbol) (num_fields: int) (field_names : symbol array) (field_sorts : sort array) = let (x,_,_) = (Z3native.mk_tuple_sort ctx#gno name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in - (self#sno ctx#gno x) ; + (self#sno ctx x) ; self end @@ -339,9 +347,9 @@ let create_sort ctx obj = class func_decl ctx = object (self) inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx#gno (Z3native.mk_func_decl ctx#gno name#gno (Array.length domain) (astaton domain) range#gno)) ; self - method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx#gno (Z3native.mk_fresh_func_decl ctx#gno prefix (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl ctx#gno name#gno (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl ctx#gno prefix (Array.length domain) (astaton domain) range#gno)) ; self method incref nc o = super#incref nc o method decref nc o = super#decref nc o @@ -388,7 +396,7 @@ end class expr ctx = object(self) inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end let expraton (a : expr array) = @@ -399,77 +407,77 @@ let expraton (a : expr array) = class bool_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Arithmetic expression objects (int/real) *) class arith_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Int expression objects *) class int_expr ctx = object (self) inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Real expression objects *) class real_expr ctx = object (self) inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Bit-vector expression objects *) class bitvec_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Array expression objects *) class array_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Datatype expression objects *) class datatype_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Integer numeral expression objects *) class int_num ctx = object (self) inherit int_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Rational numeral expression objects *) class rat_num ctx = object (self) inherit real_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Bit-vector numeral expression objects *) class bitvec_num ctx = object (self) inherit bitvec_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Algebraic numeral expression objects *) class algebraic_num ctx = object (self) inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end @@ -477,7 +485,7 @@ end class quantifier ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end @@ -1112,7 +1120,7 @@ struct if (Array.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - x#sno x#gnc (Z3native.update_term x#gnc x#gno (Array.length args) (expraton args)) + x#sno x#gc (Z3native.update_term x#gnc x#gno (Array.length args) (expraton args)) (** Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. @@ -2483,7 +2491,7 @@ struct Create a new Boolean sort. *) let mk_bool_sort ( ctx : context ) = - (new bool_sort ctx) + (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort ctx#gno) (** Create a new uninterpreted sort. @@ -2501,13 +2509,13 @@ struct Create a new integer sort. *) let mk_int_sort ( ctx : context ) = - (new int_sort ctx) + (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort ctx#gno) (** Create a real sort. *) let mk_real_sort ( ctx : context ) = - (new real_sort ctx) + (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort ctx#gno) (** Create a new bit-vector sort. From 524336ea3e21093639c54158f6c7b21b14811e02 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 03:57:18 +0000 Subject: [PATCH 023/248] New ML API savepoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 572 ++++++++++++++++++++++++++++++----------------- 1 file changed, 364 insertions(+), 208 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 3a0e9208e..116d7a230 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -33,11 +33,11 @@ object (self) val mutable m_obj_cnt : int = 0 initializer - (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) - let f = fun o -> o#dispose in - let v = self in - Gc.finalise f v - + (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) + let f = fun o -> o#dispose in + let v = self in + Gc.finalise f v + method dispose : unit = if m_obj_cnt == 0 then ( (* Printf.printf "Disposing context %d \n" (Oo.id self) ; *) @@ -110,7 +110,6 @@ object (self) method decref ctx o = Z3native.params_dec_ref ctx o end - (** Symbol objects *) class symbol ctx = object (self) @@ -166,6 +165,10 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end +let sortaton (a : sort array) = + let f (e : sort) = e#gno in + Array.map f a + (** Arithmetic sort objects, i.e., Int or Real. *) class arith_sort ctx = object (self) @@ -195,20 +198,12 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end -(** Datatype sort objects *) -class datatype_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_sc (name : symbol) constructors = (self#sno ctx (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (astaton constructors)))) ; self -end - (** Enum sort objects *) class enum_sort ctx = object (self) inherit sort ctx as super - val mutable _constdecls = None - val mutable _testerdecls = None + val mutable _constdecls : Z3native.ptr array option = None + val mutable _testerdecls : Z3native.ptr array option = None method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (enum_names : symbol array) = let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in @@ -267,12 +262,12 @@ end class list_sort ctx = object (self) inherit sort ctx as super - val mutable _nildecl = None - val mutable _is_nildecl = None - val mutable _consdecl = None - val mutable _is_consdecl = None - val mutable _headdecl = None - val mutable _taildecl = None + val mutable _nildecl : Z3native.ptr option = None + val mutable _is_nildecl : Z3native.ptr option = None + val mutable _consdecl : Z3native.ptr option = None + val mutable _is_consdecl : Z3native.ptr option = None + val mutable _headdecl : Z3native.ptr option = None + val mutable _taildecl : Z3native.ptr option = None method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (elem_sort : sort) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in @@ -291,23 +286,23 @@ object (self) method is_nil_decl = match _is_nildecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_nil decls") + | None -> raise (Z3native.Exception "Missing is_nil decl") method cons_decl = match _consdecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing cons decls") + | None -> raise (Z3native.Exception "Missing cons decl") method is_cons_decl = match _is_consdecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_cons decls") + | None -> raise (Z3native.Exception "Missing is_cons decl") method head_decl = match _headdecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing head decls") + | None -> raise (Z3native.Exception "Missing head decl") method tail_decl = match _taildecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tail decls") + | None -> raise (Z3native.Exception "Missing tail decl") end @@ -330,18 +325,6 @@ object (self) self end -let create_sort ctx obj = - match (int2sort_kind (Z3native.get_sort_kind ctx#gno obj)) with - | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) - | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) - | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) - | DATATYPE_SORT -> (((new datatype_sort ctx)#cnstr_obj obj) :> sort) - | INT_SORT -> (((new int_sort ctx)#cnstr_obj obj) :> sort) - | REAL_SORT -> (((new real_sort ctx)#cnstr_obj obj) :> sort) - | UNINTERPRETED_SORT -> (((new uninterpreted_sort ctx)#cnstr_obj obj) :> sort) - | FINITE_DOMAIN_SORT -> (((new finite_domain_sort ctx)#cnstr_obj obj) :> sort) - | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") (** Function declaration objects *) class func_decl ctx = @@ -392,6 +375,126 @@ object (self) method rational = m_r end + +(** Constructor objects *) +class constructor ctx = +object (self) + inherit z3object ctx None as super + val mutable m_n : int = 0 + val mutable m_tester_decl : func_decl option = None + val mutable m_constructor_decl : func_decl option = None + val mutable m_accessor_decls : func_decl array option = None + method incref ctx o = () + method decref ctx o = () + initializer + let f = fun o -> Z3native.del_constructor o#gnc o#gno in + let v = self in + Gc.finalise f v + + method cnstr_ssssi (name : symbol) (recognizer : symbol) (field_names : symbol array) (sorts : sort array) (sort_refs : int array) = + m_n <- (Array.length field_names) ; + if m_n != (Array.length sorts) then + raise (Z3native.Exception "Number of field names does not match number of sorts") + else + if m_n != (Array.length sort_refs) then + raise (Z3native.Exception "Number of field names does not match number of sort refs") + else + let o = (Z3native.mk_constructor ctx#gno name#gno recognizer#gno m_n (symbolaton field_names) + (sortaton sorts) + sort_refs) in + self#sno ctx o ; + self + + method private init = + match m_tester_decl with + | None -> + let (a, b, c) = (Z3native.query_constructor self#gnc self#gno m_n) in + m_constructor_decl <- Some ((new func_decl ctx)#cnstr_obj a) ; + m_tester_decl <- Some ((new func_decl ctx)#cnstr_obj b) ; + m_accessor_decls <- Some (let f e = ((new func_decl ctx)#cnstr_obj e) in Array.map f c) ; + () + | _ -> () + + method get_n = m_n + + method tester_decl = match m_tester_decl with + | Some(x) -> x + | None -> self#init ; self#tester_decl + + method constructor_decl = match m_constructor_decl with + | Some(x) -> x + | None -> self#init ; self#constructor_decl + + method accessor_decls = match m_accessor_decls with + | Some(x) -> x + | None -> self#init ; self#accessor_decls +end + +let constructoraton (a : constructor array) = + let f (e : constructor) = e#gno in + Array.map f a + +(** Constructor list objects *) +class constructor_list ctx = +object (self) + inherit z3object ctx None + method incref ctx o = () + method decref ctx o = () + initializer + let f = fun o -> Z3native.del_constructor_list o#gnc o#gno in + let v = self in + Gc.finalise f v + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_ca ( c : constructor array ) = + self#sno ctx (Z3native.mk_constructor_list ctx#gno (Array.length c) (constructoraton c)) ; + self +end + +let constructor_listaton (a : constructor_list array) = + let f (e : constructor_list) = e#gno in + Array.map f a + +(** Datatype sort objects *) +class datatype_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_sc (name : symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (constructoraton constructors)))) ; self +end + +let create_sort ctx obj = + match (int2sort_kind (Z3native.get_sort_kind ctx#gno obj)) with + | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) + | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) + | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) + | DATATYPE_SORT -> (((new datatype_sort ctx)#cnstr_obj obj) :> sort) + | INT_SORT -> (((new int_sort ctx)#cnstr_obj obj) :> sort) + | REAL_SORT -> (((new real_sort ctx)#cnstr_obj obj) :> sort) + | UNINTERPRETED_SORT -> (((new uninterpreted_sort ctx)#cnstr_obj obj) :> sort) + | FINITE_DOMAIN_SORT -> (((new finite_domain_sort ctx)#cnstr_obj obj) :> sort) + | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + +(** AST vector objects *) +class ast_vector ctx = +object (self) + inherit z3object ctx None + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref ctx o = Z3native.ast_vector_inc_ref ctx o + method decref ctx o = Z3native.ast_vector_dec_ref ctx o +end + + +(** AST map objects *) +class ast_map ctx = +object (self) + inherit z3object ctx None + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref ctx o = Z3native.ast_map_inc_ref ctx o + method decref ctx o = Z3native.ast_map_dec_ref ctx o +end + + (** Expression objects *) class expr ctx = object(self) @@ -492,7 +595,8 @@ end (**/**) -(** Interaction logging for 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. *) module Log = @@ -512,7 +616,7 @@ struct let append s = Z3native.append_log s end -(** Version information. *) +(** Version information *) module Version = struct (** The major version. *) @@ -536,7 +640,7 @@ struct string_of_int rev ^ "." end -(** Symbols are used to name several term and type constructors. *) +(** Symbols are used to name several term and type constructors *) module Symbol = struct (** The kind of the symbol (int or string) *) @@ -562,9 +666,7 @@ struct end -(** - The Sort module implements type information for ASTs. -*) +(** The Sort module implements type information for ASTs *) module Sort = struct (** @@ -612,13 +714,13 @@ struct end (** Bit-vector sorts *) -module BitVectorSort = +module BitVecSort = struct (** The size of the bit-vector sort. *) let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno end -(** Finite domain sorts. *) +(** Finite domain sorts *) module FiniteDomainSort = struct (** The size of the finite domain sort. *) @@ -628,7 +730,7 @@ struct else raise (Z3native.Exception "Conversion failed.") end -(** Relation sorts. *) +(** Relation sorts *) module RelationSort = struct (** The arity of the relation sort. *) @@ -684,60 +786,60 @@ let create_ast ctx no = | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") (**/**) -(** Function declarations. *) +(** Function declarations *) module FuncDecl = struct -(** Parameters of Func_Decls *) + (** Parameters of Func_Decls *) module Parameter = struct - (** - The kind of the parameter. - *) + (** + The kind of the parameter. + *) let get_kind (x : parameter) = x#kind - (**The int value of the parameter.*) + (**The int value of the parameter.*) let get_int (x : parameter) = if (x#kind != PARAMETER_INT) then raise (Z3native.Exception "parameter is not an int") else x#int - (**The double value of the parameter.*) + (**The double value of the parameter.*) let get_double (x : parameter) = if (x#kind != PARAMETER_DOUBLE) then raise (Z3native.Exception "parameter is not a double") else x#double - (**The Symbol value of the parameter.*) + (**The Symbol value of the parameter.*) let get_symbol (x : parameter) = if (x#kind != PARAMETER_SYMBOL) then raise (Z3native.Exception "parameter is not a symbol") else x#symbol - (**The Sort value of the parameter.*) + (**The Sort value of the parameter.*) let get_sort (x : parameter) = if (x#kind != PARAMETER_SORT) then raise (Z3native.Exception "parameter is not a sort") else x#sort - (**The AST value of the parameter.*) + (**The AST value of the parameter.*) let get_ast (x : parameter) = if (x#kind != PARAMETER_AST) then raise (Z3native.Exception "parameter is not an ast") else x#ast - (**The FunctionDeclaration value of the parameter.*) + (**The FunctionDeclaration value of the parameter.*) let get_ast (x : parameter) = if (x#kind != PARAMETER_FUNC_DECL) then raise (Z3native.Exception "parameter is not an function declaration") else x#func_decl - (**The rational string value of the parameter.*) + (**The rational string value of the parameter.*) let get_rational (x : parameter) = if (x#kind != PARAMETER_RATIONAL) then raise (Z3native.Exception "parameter is not a ratinoal string") @@ -826,7 +928,7 @@ struct (** Create expression that applies function to arguments. - + @param args The arguments *) let apply (x : func_decl) (args : expr array) = create_expr_fa x#gc x args @@ -862,7 +964,7 @@ struct Array.init n f end -(** Enumeration sorts. *) +(** Enumeration sorts *) module EnumSort = struct (** The function declarations of the constants in the enumeration. *) @@ -876,7 +978,7 @@ struct Array.map f x#tester_decls end -(** List sorts. *) +(** List sorts *) module ListSort = struct (** The declaration of the nil function of this list sort. *) @@ -901,6 +1003,7 @@ struct let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] end +(** Tuple sorts *) module TupleSort = struct (** The constructor function of the tuple.*) @@ -917,7 +1020,7 @@ struct Array.init n f end -(** The abstract syntax tree (AST) module. *) +(** The abstract syntax tree (AST) module *) module AST = struct (** @@ -1077,12 +1180,107 @@ struct let to_string (p : params) = Z3native.params_to_string p#gnc p#gno end +(** Vectors of ASTs *) +module ASTVector = +struct + (** The size of the vector *) + let get_size ( x : ast_vector ) = + Z3native.ast_vector_size x#gnc x#gno + + (** + Retrieves the i-th object in the vector. + @param i Index + @return An AST + *) + let get ( x : ast_vector ) ( i : int ) = + create_ast x#gc (Z3native.ast_vector_get x#gnc x#gno i) + + (** Sets the i-th object in the vector. *) + let set ( x : ast_vector ) ( i : int ) ( value : ast ) = + Z3native.ast_vector_set x#gnc x#gno i value#gno + + (** Resize the vector to . + @param newSize The new size of the vector. *) + let resize ( x : ast_vector ) ( new_size : int ) = + Z3native.ast_vector_resize x#gnc x#gno new_size + + (** + Add the AST to the back of the vector. The size + is increased by 1. + @param a An AST + *) + let push ( x : ast_vector ) ( a : ast ) = + Z3native.ast_vector_push x#gnc x#gno a#gno + + (** + Translates all ASTs in the vector to . + @param to_ctx A context + @return A new ASTVector + *) + let translate ( x : ast_vector ) ( to_ctx : context ) = + (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno to_ctx#gno) + + (** Retrieves a string representation of the vector. *) + let to_string ( x : ast_vector ) = + Z3native.ast_vector_to_string x#gnc x#gno +end + +(** Map from AST to AST *) +module ASTMap = +struct + (** Checks whether the map contains the key . + @param k An AST + @return True if is a key in the map, false otherwise. *) + let contains ( m : ast_map ) ( key : ast ) = + (int2lbool (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE + + (** Finds the value associated with the key . + + This function signs an error when is not a key in the map. + + @param k An AST + *) + let find ( m : ast_map ) ( key : ast ) = + create_ast m#gc (Z3native.ast_map_find m#gnc m#gno key#gno) + + (** + Stores or replaces a new key/value pair in the map. + @param k The key AST + @param v The value AST + *) + let insert ( m : ast_map ) ( key : ast ) ( value : ast) = + Z3native.ast_map_insert m#gnc m#gno key#gno value#gno + + (** + Erases the key from the map. + @param k An AST + *) + let erase ( m : ast_map ) ( key : ast ) = + Z3native.ast_map_erase m#gnc m#gno key#gno + + (** Removes all keys from the map. *) + let reset ( m : ast_map ) = + Z3native.ast_map_reset m#gnc m#gno + + (** The size of the map *) + let get_size ( m : ast_map ) = + Z3native.ast_map_size m#gnc m#gno + + (** The keys stored in the map. *) + let get_keys ( m : ast_map ) = + (new ast_vector m#gc)#cnstr_obj (Z3native.ast_map_keys m#gnc m#gno) + + (** Retrieves a string representation of the map.*) + let to_strnig ( m : ast_map ) = + Z3native.ast_map_to_string m#gnc m#gno +end + (** Expressions (terms) *) module Expr = struct (** Returns a simplified version of the expression. - A set of parameters to configure the simplifier + @param p A set of parameters to configure the simplifier *) let simplify ( x : expr ) ( p : params option ) = match p with @@ -1155,8 +1353,8 @@ struct (** Translates (copies) the term to the Context . - A context - A copy of the term which is associated with + @param ctx A context + @return A copy of the term which is associated with *) let translate ( x : expr ) to_ctx = if x#gc == to_ctx then @@ -1176,7 +1374,7 @@ struct (** Indicates whether the term is well-sorted. - True if the term is well-sorted, false otherwise. + @return True if the term is well-sorted, false otherwise. *) let is_well_sorted ( x : expr ) = int2lbool (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE @@ -2372,13 +2570,13 @@ struct Z3native.get_index_value x#gnc x#gno end -(* Integer Numerals *) +(** Integer Numerals *) module IntNum = struct (** Retrieve the int value. *) let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if int2lbool(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -2410,9 +2608,9 @@ module BitVecNum = struct (** Retrieve the int value. *) let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if int2lbool(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") - + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + (** Returns a string representation of the numeral. *) let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno end @@ -2424,9 +2622,8 @@ struct 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 - A numeral Expr of sort Real + @param precision the precision of the result + @return A numeral Expr of sort Real *) let to_upper ( x : algebraic_num ) ( precision : int ) = (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) @@ -2435,9 +2632,8 @@ struct Return a lower bound for the given real algebraic number. The interval isolating the number is smaller than 1/10^. - - - A numeral Expr of sort Real + @param precision the precision of the result + @return A numeral Expr of sort Real *) let to_lower ( x : algebraic_num ) precision = (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) @@ -2450,8 +2646,24 @@ struct (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno end + +(** Constructors are used for datatype sorts *) +module Constructor = +struct + (** The number of fields of the constructor. *) + let get_num_fields ( x : constructor ) = x#get_n + + (** The function declaration of the constructor. *) + let get_constructor_decl ( x : constructor ) = x#constructor_decl + + (** The function declaration of the tester. *) + let get_tester_decl ( x : constructor ) = x#tester_decl + + (** The function declarations of the accessors *) + let get_accessor_decls ( x : constructor ) = x#accessor_decls +end -(** The main interaction with Z3 happens via the Context module. *) +(** The main interaction with Z3 happens via the Context module *) module Context = struct @@ -2551,151 +2763,95 @@ struct (Array.map f (mk_symbols_string ( ctx : context ) enum_names)) ) - (** - Create a new list sort. - *) + (** + Create a new list sort. + *) let mk_list_sort ( ctx : context ) (name : symbol) elem_sort = - (new list_sort ctx)#cnstr_ss name elem_sort + (new list_sort ctx)#cnstr_ss name elem_sort - (** - Create a new list sort. - *) + (** + Create a new list sort. + *) let mk_list_sort_s ( ctx : context ) (name : string) elem_sort = mk_list_sort ctx ((mk_symbol_string ctx name) :> symbol) elem_sort - (** - Create a new finite domain sort. - *) + (** + Create a new finite domain sort. + *) let mk_finite_domain_sort ( ctx : context ) ( name : symbol ) size = (new finite_domain_sort ctx)#cnstr_si name size - (** - Create a new finite domain sort. - *) + (** + Create a new finite domain sort. + *) let mk_finite_domain_sort_s ( ctx : context ) ( name : string ) size = (new finite_domain_sort ctx)#cnstr_si ((mk_symbol_string ctx name) :> symbol) size -(** - -(* DATATYPES *) -(** - Create a datatype constructor. -*) - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - public Constructor MkConstructor(Symbol name, Symbol recognizer, Symbol[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null) - { + (* DATATYPES *) + (** + Create a datatype constructor. + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + *) + let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs + (** + Create a datatype constructor. + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + *) + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + mk_constructor ctx ((mk_symbol_string ctx name) :> symbol) recognizer field_names sorts sort_refs - return new Constructor(this, name, recognizer, fieldNames, sorts, sortRefs); - } + (** + Create a new datatype sort. + *) + let mk_datatype_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = + (new datatype_sort ctx)#cnstr_sc name constructors + + (** + Create a new datatype sort. + *) + let mk_datatype_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = + mk_datatype_sort ctx ((mk_symbol_string ctx name) :> symbol) constructors + + (** + Create mutually recursive datatypes. + @param names names of datatype sorts + @param c list of constructors, one list per sort. + *) + let mk_datatype_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = + let n = (Array.length names) in + let f e = ( (new constructor_list ctx)#cnstr_ca e ) in + let cla = (Array.map f c) in + let (r, a) = (Z3native.mk_datatypes ctx#gno n (symbolaton names) (constructor_listaton cla)) in + let g e = ( (new datatype_sort ctx)#cnstr_obj e) in + (Array.map g r) + + (** Create mutually recursive data-types. *) + let mk_datatype_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = + mk_datatype_sorts ctx + ( + let f e = ((mk_symbol_string ctx e) :> symbol) in + Array.map f names + ) + c (** - Create a datatype constructor. -*) - @param name - @param recognizer - @param fieldNames - @param sorts - @param sortRefs - @return - public Constructor MkConstructor(string name, string recognizer, string[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null) - { - - - return new Constructor(this, MkSymbol(name), MkSymbol(recognizer), MkSymbols(fieldNames), sorts, sortRefs); - } - -(** - Create a new datatype sort. -*) - let mk_Datatype_Sort(Symbol name, Constructor[] constructors) - { - - - - - - - CheckContextMatch(name); - CheckContextMatch(constructors); - return new DatatypeSort(this, name, constructors); - } - -(** - Create a new datatype sort. -*) - let mk_Datatype_Sort(string name, Constructor[] constructors) - { - - - - - CheckContextMatch(constructors); - return new DatatypeSort(this, MkSymbol(name), constructors); - } - -(** - Create mutually recursive datatypes. -*) - @param names names of datatype sorts - @param c list of constructors, one list per sort. - let mk_Datatype_Sorts(Symbol[] names, Constructor[][] c) - { - - - - - - - - CheckContextMatch(names); - uint n = (uint)names.Length; - ConstructorList[] cla = new ConstructorList[n]; - IntPtr[] n_constr = new IntPtr[n]; - for (uint i = 0; i < n; i++) - { - Constructor[] constructor = c[i]; - - CheckContextMatch(constructor); - cla[i] = new ConstructorList(this, constructor); - n_constr[i] = cla[i].x#gno; - } - IntPtr[] n_res = new IntPtr[n]; - Z3native.mk_datatypes(nCtx, n, Symbol.ArrayToNative(names), n_res, n_constr); - DatatypeSort[] res = new DatatypeSort[n]; - for (uint i = 0; i < n; i++) - res[i] = new DatatypeSort(this, n_res[i]); - return res; - } - -(** - Create mutually recursive data-types. -*) - @param names - @param c - @return - let mk_Datatype_Sorts(string[] names, Constructor[][] c) - { - - - - - - - - return MkDatatypeSorts(MkSymbols(names), c); - } - - (* FUNCTION DECLARATIONS *) From d6a2048785d3ad803c6af74fd632fab736fb53ef Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 21:06:13 +0000 Subject: [PATCH 024/248] More new ML API Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 4 +- scripts/update_api.py | 11 +- src/api/ml/Makefile | 2 +- src/api/ml/z3.ml | 1025 +++++++++++++++++++++++++++++++++++------ 4 files changed, 901 insertions(+), 141 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 68493b7b6..9b5ab1a7a 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2680,13 +2680,13 @@ def mk_z3consts_ml(api_files): efile.write(' | %s \n' % k[3:]) # strip Z3_ efile.write('\n') efile.write('(** Convert %s to int*)\n' % name[3:]) - efile.write('let %s2int x : int =\n' % (name[3:])) # strip Z3_ + efile.write('let int_of_%s x : int =\n' % (name[3:])) # strip Z3_ efile.write(' match x with\n') for k, i in decls.iteritems(): efile.write(' | %s -> %d\n' % (k[3:], i)) efile.write('\n') efile.write('(** Convert int to %s*)\n' % name[3:]) - efile.write('let int2%s x : %s =\n' % (name[3:],name[3:])) # strip Z3_ + efile.write('let %s_of_int x : %s =\n' % (name[3:],name[3:])) # strip Z3_ efile.write(' match x with\n') for k, i in decls.iteritems(): efile.write(' | %d -> %s\n' % (i, k[3:])) diff --git a/scripts/update_api.py b/scripts/update_api.py index c3f2abce6..27f7dd507 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1154,7 +1154,9 @@ def mk_ml(): for k, v in Type2Str.iteritems(): if is_obj(k): ml_native.write('and %s = ptr\n' % v.lower()) - ml_native.write('\nexception Exception of string\n\n') + ml_native.write('\nexternal is_null : ptr -> bool\n') + ml_native.write(' = "n_is_null"\n\n') + ml_native.write('exception Exception of string\n\n') # ML declarations ml_native.write(' module ML2C = struct\n\n') @@ -1219,9 +1221,9 @@ def mk_ml(): i = i + 1 ml_native.write(') in\n') if len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = (int2error_code (ML2C.n_get_error_code a0)) in \n') + ml_native.write(' let err = (error_code_of_int (ML2C.n_get_error_code a0)) in \n') ml_native.write(' if err <> OK then\n') - ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (error_code2int err)))\n') + ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (int_of_error_code err)))\n') ml_native.write(' else\n') if result == VOID and len(op) == 0: ml_native.write(' ()\n') @@ -1290,6 +1292,9 @@ def mk_ml(): ml_wrapper.write('#ifdef __cplusplus\n') ml_wrapper.write('extern "C" {\n') ml_wrapper.write('#endif\n\n') + ml_wrapper.write('CAMLprim value n_is_null(value p) {\n') + ml_wrapper.write(' return Val_bool(Data_custom_val(p) == 0);\n') + ml_wrapper.write('}\n\n') for name, result, params in _dotnet_decls: ip = inparams(params) op = outparams(params) diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile index 4d4a6c08f..ad5442327 100644 --- a/src/api/ml/Makefile +++ b/src/api/ml/Makefile @@ -7,4 +7,4 @@ all: doc: *.ml mkdir -p doc - ocamldoc -html -d doc -I ../../../bld_dbg/api/ml *.ml -hide Z3 + ocamldoc -html -d doc -I ../../../bld_dbg/api/ml -sort *.ml -hide Z3 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 116d7a230..c22ef869b 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -9,9 +9,6 @@ open Z3enums (**/**) -(* Object definitions. These are internal and should be interacted - with only via the corresponding functions from modules. *) - class virtual idisposable = object method virtual dispose : unit @@ -106,8 +103,8 @@ end class params ctx obj = object (self) inherit z3object ctx obj as super - method incref ctx o = Z3native.params_inc_ref ctx o - method decref ctx o = Z3native.params_dec_ref ctx o + method incref nc o = Z3native.params_inc_ref nc o + method decref nc o = Z3native.params_dec_ref nc o end (** Symbol objects *) @@ -115,8 +112,8 @@ class symbol ctx = object (self) inherit z3object ctx None as super method cnstr_obj obj = (self#sno ctx obj) ; self - method incref ctx o = () - method decref ctx o = () + method incref nc o = () + method decref nc o = () end let symbolaton (a : symbol array) = @@ -140,7 +137,7 @@ object(self) end let create_symbol ctx no = - match (int2symbol_kind (Z3native.get_symbol_kind ctx#gno no)) with + match (symbol_kind_of_int (Z3native.get_symbol_kind ctx#gno no)) with | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj no) :> symbol) | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj no) :> symbol) @@ -198,29 +195,6 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end -(** Enum sort objects *) -class enum_sort ctx = -object (self) - inherit sort ctx as super - val mutable _constdecls : Z3native.ptr array option = None - val mutable _testerdecls : Z3native.ptr array option = None - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : symbol) (enum_names : symbol array) = - let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in - _constdecls <- Some a ; - _testerdecls <- Some b ; - (self#sno ctx r) ; - self - - method const_decls = match _constdecls with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing const decls") - - method tester_decls = match _testerdecls with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tester decls") -end - (** Int sort objects *) class int_sort ctx = object (self) @@ -258,54 +232,6 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end -(** List sort objects *) -class list_sort ctx = -object (self) - inherit sort ctx as super - val mutable _nildecl : Z3native.ptr option = None - val mutable _is_nildecl : Z3native.ptr option = None - val mutable _consdecl : Z3native.ptr option = None - val mutable _is_consdecl : Z3native.ptr option = None - val mutable _headdecl : Z3native.ptr option = None - val mutable _taildecl : Z3native.ptr option = None - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : symbol) (elem_sort : sort) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in - _nildecl <- Some a ; - _is_nildecl <- Some b ; - _consdecl <- Some c ; - _is_consdecl <- Some d ; - _headdecl <- Some e ; - _taildecl <- Some f ; - (self#sno ctx r) ; - self - - method nil_decl = match _nildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing nil decl") - - method is_nil_decl = match _is_nildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_nil decl") - - method cons_decl = match _consdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing cons decl") - - method is_cons_decl = match _is_consdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_cons decl") - - method head_decl = match _headdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing head decl") - - method tail_decl = match _taildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tail decl") - -end - (** Set sort objects *) class set_sort ctx = object (self) @@ -376,6 +302,76 @@ object (self) end +(** Enum sort objects *) +class enum_sort ctx = +object (self) + inherit sort ctx as super + val mutable _constdecls : func_decl array option = None + val mutable _testerdecls : func_decl array option = None + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_ss (name : symbol) (enum_names : symbol array) = + let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in + _constdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f a)) ; + _testerdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f b)) ; + (self#sno ctx r) ; + self + + method const_decls = match _constdecls with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing const decls") + + method tester_decls = match _testerdecls with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing tester decls") +end + +(** List sort objects *) +class list_sort ctx = +object (self) + inherit sort ctx as super + val mutable _nildecl : func_decl option = None + val mutable _is_nildecl : func_decl option = None + val mutable _consdecl : func_decl option = None + val mutable _is_consdecl : func_decl option = None + val mutable _headdecl : func_decl option = None + val mutable _taildecl : func_decl option = None + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_ss (name : symbol) (elem_sort : sort) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in + _nildecl <- Some ((new func_decl ctx)#cnstr_obj a) ; + _is_nildecl <- Some ((new func_decl ctx)#cnstr_obj b) ; + _consdecl <- Some ((new func_decl ctx)#cnstr_obj c) ; + _is_consdecl <- Some ((new func_decl ctx)#cnstr_obj d) ; + _headdecl <- Some ((new func_decl ctx)#cnstr_obj e) ; + _taildecl <- Some ((new func_decl ctx)#cnstr_obj f) ; + (self#sno ctx r) ; + self + + method nil_decl = match _nildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing nil decl") + + method is_nil_decl = match _is_nildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing is_nil decl") + + method cons_decl = match _consdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing cons decl") + + method is_cons_decl = match _is_consdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing is_cons decl") + + method head_decl = match _headdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing head decl") + + method tail_decl = match _taildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing tail decl") +end + (** Constructor objects *) class constructor ctx = object (self) @@ -384,8 +380,8 @@ object (self) val mutable m_tester_decl : func_decl option = None val mutable m_constructor_decl : func_decl option = None val mutable m_accessor_decls : func_decl array option = None - method incref ctx o = () - method decref ctx o = () + method incref nc o = () + method decref nc o = () initializer let f = fun o -> Z3native.del_constructor o#gnc o#gno in let v = self in @@ -438,8 +434,8 @@ let constructoraton (a : constructor array) = class constructor_list ctx = object (self) inherit z3object ctx None - method incref ctx o = () - method decref ctx o = () + method incref nc o = () + method decref nc o = () initializer let f = fun o -> Z3native.del_constructor_list o#gnc o#gno in let v = self in @@ -463,7 +459,7 @@ object (self) end let create_sort ctx obj = - match (int2sort_kind (Z3native.get_sort_kind ctx#gno obj)) with + match (sort_kind_of_int (Z3native.get_sort_kind ctx#gno obj)) with | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) @@ -480,8 +476,8 @@ class ast_vector ctx = object (self) inherit z3object ctx None method cnstr_obj obj = (self#sno ctx obj) ; self - method incref ctx o = Z3native.ast_vector_inc_ref ctx o - method decref ctx o = Z3native.ast_vector_dec_ref ctx o + method incref nc o = Z3native.ast_vector_inc_ref nc o + method decref nc o = Z3native.ast_vector_dec_ref nc o end @@ -490,8 +486,8 @@ class ast_map ctx = object (self) inherit z3object ctx None method cnstr_obj obj = (self#sno ctx obj) ; self - method incref ctx o = Z3native.ast_map_inc_ref ctx o - method decref ctx o = Z3native.ast_map_dec_ref ctx o + method incref nc o = Z3native.ast_map_inc_ref nc o + method decref nc o = Z3native.ast_map_dec_ref nc o end @@ -583,7 +579,6 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end - (** Quantifier objects *) class quantifier ctx = object (self) @@ -591,10 +586,127 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end +(** Parameter description objects *) +class param_descrs ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.param_descrs_inc_ref nc o + method decref nc o = Z3native.param_descrs_dec_ref nc o +end +(** Goal objects *) +class goal ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.goal_inc_ref nc o + method decref nc o = Z3native.goal_dec_ref nc o +end + +(** Tactic objects *) +class tactic ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.tactic_inc_ref nc o + method decref nc o = Z3native.tactic_dec_ref nc o +end + +(** Function interpretation entry objects *) +class func_entry ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.func_entry_inc_ref nc o + method decref nc o = Z3native.func_entry_dec_ref nc o +end + +(** Function interpretation objects *) +class func_interp ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.func_interp_inc_ref nc o + method decref nc o = Z3native.func_interp_dec_ref nc o +end + +(** Model objects *) +class model ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.model_inc_ref nc o + method decref nc o = Z3native.model_dec_ref nc o +end + +(** Tactic application result objects *) +class apply_result ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.apply_result_inc_ref nc o + method decref nc o = Z3native.apply_result_dec_ref nc o +end + +(** Probe objects *) +class probe ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.probe_inc_ref nc o + method decref nc o = Z3native.probe_dec_ref nc o +end + +(** Statistical value objects *) +class statistics_entry = +object (self) + val mutable m_key : string = "" + val mutable m_is_int = false + val mutable m_is_float = false + val mutable m_int = 0 + val mutable m_float = 0.0 + + method cnstr_si k v = + m_key <- k; + m_is_int <- true; + m_int <- v; + self + + method cnstr_sd k v = + m_key <- k; + m_is_float <- true; + m_float <- v; + self + + method key = m_key + method int = m_int + method float = m_float + method is_int = m_is_int + method is_float = m_is_float +end + +(** Statistics objects *) +class statistics ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.stats_inc_ref nc o + method decref nc o = Z3native.stats_dec_ref nc o +end + +(** Solver objects *) +class solver ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.solver_inc_ref nc o + method decref nc o = Z3native.solver_dec_ref nc o +end (**/**) + (** Interaction logging for Z3 Note that this is a global, static log and if multiple Context @@ -606,7 +718,7 @@ struct @return True if opening the log file succeeds, false otherwise. *) (* CMW: "open" seems to be a reserved keyword? *) - let open_ filename = ((int2lbool (Z3native.open_log filename)) == L_TRUE) + let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) (** Closes the interaction log. *) let close = Z3native.close_log @@ -644,7 +756,7 @@ end module Symbol = struct (** The kind of the symbol (int or string) *) - let kind (o : symbol) = (int2symbol_kind (Z3native.get_symbol_kind o#gnc o#gno)) + let kind (o : symbol) = (symbol_kind_of_int (Z3native.get_symbol_kind o#gnc o#gno)) (** Indicates whether the symbol is of Int kind *) let is_int_symbol (o : symbol) = (kind o) == INT_SYMBOL @@ -680,7 +792,7 @@ struct if a#gnc != b#gnc then false else - ((int2lbool (Z3native.is_eq_sort a#gnc a#gno b#gno)) == L_TRUE) + ((lbool_of_int (Z3native.is_eq_sort a#gnc a#gno b#gno)) == L_TRUE) (** Returns a unique identifier for the sort. @@ -690,7 +802,7 @@ struct (** The kind of the sort. *) - let get_sort_kind (x : sort) = (int2sort_kind (Z3native.get_sort_kind x#gnc x#gno)) + let get_sort_kind (x : sort) = (sort_kind_of_int (Z3native.get_sort_kind x#gnc x#gno)) (** The name of the sort @@ -726,7 +838,7 @@ struct (** The size of the finite domain sort. *) let get_size (x : finite_domain_sort) = let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in - if int2lbool(r) == L_TRUE then v + if lbool_of_int(r) == L_TRUE then v else raise (Z3native.Exception "Conversion failed.") end @@ -746,15 +858,15 @@ end (**/**) let create_expr ctx obj = - if int2ast_kind (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then + if ast_kind_of_int (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then (((new quantifier ctx)#cnstr_obj obj) :> expr) else let s = Z3native.get_sort ctx#gno obj in - let sk = (int2sort_kind (Z3native.get_sort_kind ctx#gno s)) in - if (int2lbool (Z3native.is_algebraic_number ctx#gno obj) == L_TRUE) then + let sk = (sort_kind_of_int (Z3native.get_sort_kind ctx#gno s)) in + if (lbool_of_int (Z3native.is_algebraic_number ctx#gno obj) == L_TRUE) then (((new algebraic_num ctx)#cnstr_obj obj) :> expr) else - if ((int2lbool (Z3native.is_numeral_ast ctx#gno obj)) == L_TRUE) && + if ((lbool_of_int (Z3native.is_numeral_ast ctx#gno obj)) == L_TRUE) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) @@ -776,7 +888,7 @@ let create_expr_fa (ctx : context) (f : func_decl) (args : expr array) = create_expr ctx o let create_ast ctx no = - match (int2ast_kind (Z3native.get_ast_kind ctx#gno no)) with + match (ast_kind_of_int (Z3native.get_ast_kind ctx#gno no)) with | FUNC_DECL_AST -> (((new func_decl ctx)#cnstr_obj no) :> ast) | QUANTIFIER_AST -> (((new quantifier ctx)#cnstr_obj no) :> ast) | SORT_AST -> ((create_sort ctx no) :> ast) @@ -858,7 +970,7 @@ struct if a#gnc == a#gnc then false else - ((int2lbool (Z3native.is_eq_func_decl a#gnc a#gno b#gno)) == L_TRUE) + ((lbool_of_int (Z3native.is_eq_func_decl a#gnc a#gno b#gno)) == L_TRUE) (** A string representations of the function declaration. *) @@ -897,7 +1009,7 @@ struct (** The kind of the function declaration. *) - let get_decl_kind (x : func_decl) = (int2decl_kind (Z3native.get_decl_kind x#gnc x#gno)) + let get_decl_kind (x : func_decl) = (decl_kind_of_int (Z3native.get_decl_kind x#gnc x#gno)) (** The name of the function declaration @@ -915,7 +1027,7 @@ struct let get_parameters (x : func_decl) = let n = (get_num_parameters x) in let f i = ( - match (int2parameter_kind (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with + match (parameter_kind_of_int (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with | PARAMETER_INT -> (new parameter)#cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) | PARAMETER_DOUBLE -> (new parameter)#cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) | PARAMETER_SYMBOL-> (new parameter)#cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) @@ -968,36 +1080,32 @@ end module EnumSort = struct (** The function declarations of the constants in the enumeration. *) - let get_const_decls (x : enum_sort) = - let f e = ((new func_decl x#gc)#cnstr_obj e) in - Array.map f x#const_decls + let get_const_decls (x : enum_sort) = x#const_decls (** The test predicates for the constants in the enumeration. *) - let get_tester_decls (x : enum_sort) = - let f e = ((new func_decl x#gc)#cnstr_obj e) in - Array.map f x#tester_decls + let get_tester_decls (x : enum_sort) = x#tester_decls end (** List sorts *) module ListSort = struct (** The declaration of the nil function of this list sort. *) - let get_nil_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#nil_decl + let get_nil_decl (x : list_sort) = x#nil_decl (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#is_nil_decl + let get_is_nil_decl (x : list_sort) = x#is_nil_decl (** The declaration of the cons function of this list sort. *) - let get_cons_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#cons_decl + let get_cons_decl (x : list_sort) = x#cons_decl (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#is_cons_decl + let get_is_cons_decl (x : list_sort) = x#is_cons_decl (** The declaration of the head function of this list sort.*) - let get_head_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#head_decl + let get_head_decl (x : list_sort) = x#head_decl (** The declaration of the tail function of this list sort. *) - let get_tail_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#tail_decl + let get_tail_decl (x : list_sort) = x#tail_decl (** The empty list. *) let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] @@ -1037,7 +1145,7 @@ struct (** The kind of the AST. *) - let get_ast_kind ( x : ast) = (int2ast_kind (Z3native.get_ast_kind x#gnc x#gno)) + let get_ast_kind ( x : ast) = (ast_kind_of_int (Z3native.get_ast_kind x#gnc x#gno)) (** Indicates whether the AST is an Expr @@ -1092,7 +1200,7 @@ struct if a#gnc == b#gnc then false else - ((int2lbool (Z3native.is_eq_ast a#gnc a#gno b#gno)) == L_TRUE) + ((lbool_of_int (Z3native.is_eq_ast a#gnc a#gno b#gno)) == L_TRUE) (** Object Comparison. @@ -1130,7 +1238,7 @@ struct Adds a parameter setting. *) let add_bool (p : params) (name : symbol) (value : bool) = - Z3native.params_set_bool p#gnc p#gno name#gno (lbool2int (if value then L_TRUE else L_FALSE)) + Z3native.params_set_bool p#gnc p#gno name#gno (int_of_lbool (if value then L_TRUE else L_FALSE)) (** Adds a parameter setting. @@ -1232,7 +1340,7 @@ struct @param k An AST @return True if is a key in the map, false otherwise. *) let contains ( m : ast_map ) ( key : ast ) = - (int2lbool (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE + (lbool_of_int (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE (** Finds the value associated with the key . @@ -1296,7 +1404,7 @@ struct Indicates whether the expression is the true or false expression or something else (Z3_L_UNDEF). *) - let get_bool_value ( x : expr ) = int2lbool (Z3native.get_bool_value x#gnc x#gno) + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value x#gnc x#gno) (** The number of arguments of the expression. @@ -1370,13 +1478,13 @@ struct (** Indicates whether the term is a numeral *) - let is_numeral ( x : expr ) = int2lbool (Z3native.is_numeral_ast x#gnc x#gno) == L_TRUE + let is_numeral ( x : expr ) = lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno) == L_TRUE (** Indicates whether the term is well-sorted. @return True if the term is well-sorted, false otherwise. *) - let is_well_sorted ( x : expr ) = int2lbool (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE + let is_well_sorted ( x : expr ) = lbool_of_int (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE (** The Sort of the term. @@ -1387,7 +1495,7 @@ struct Indicates whether the term has Boolean sort. *) let is_bool ( x : expr ) = (AST.is_expr x) && - (int2lbool (Z3native.is_eq_sort x#gnc + (lbool_of_int (Z3native.is_eq_sort x#gnc (Z3native.mk_bool_sort x#gnc) (Z3native.get_sort x#gnc x#gno))) == L_TRUE @@ -1395,21 +1503,21 @@ struct Indicates whether the term is of integer sort. *) let is_int ( x : expr ) = - ((int2lbool (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && - ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) + ((lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) (** Indicates whether the term is of sort real. *) let is_real ( x : expr ) = - ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) (** Indicates whether the term is of an array sort. *) let is_array ( x : expr ) = - ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) (** Indicates whether the term represents a constant. @@ -1431,7 +1539,7 @@ struct (** Indicates whether the term is an algebraic number *) - let is_algebraic_number ( x : expr ) = int2lbool(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE + let is_algebraic_number ( x : expr ) = lbool_of_int(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE (** Indicates whether the term is the constant true. @@ -1634,7 +1742,7 @@ struct Indicates whether the terms is of bit-vector sort. *) let is_bv ( x : expr ) = - ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == BV_SORT) + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == BV_SORT) (** Indicates whether the term is a bit-vector numeral @@ -2422,8 +2530,8 @@ struct Indicates whether the term is of a relation sort. *) let is_Relation ( x : expr ) = - ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT) + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT) (** Indicates whether the term is an relation store @@ -2536,8 +2644,8 @@ struct Indicates whether the term is of an array sort. *) let is_finite_domain ( x : expr ) = - ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) (** Indicates whether the term is a less than predicate over a finite domain. @@ -2575,7 +2683,7 @@ module IntNum = struct (** Retrieve the int value. *) let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if int2lbool(r) == L_TRUE then v + if lbool_of_int(r) == L_TRUE then v else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) @@ -2608,7 +2716,7 @@ module BitVecNum = struct (** Retrieve the int value. *) let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if int2lbool(r) == L_TRUE then v + if lbool_of_int(r) == L_TRUE then v else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) @@ -2662,7 +2770,654 @@ struct (** The function declarations of the accessors *) let get_accessor_decls ( x : constructor ) = x#accessor_decls end + + +(** ParamDescrs describe sets of parameters.*) +module ParamDescrs = +struct + + (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno + + (** Retrieve kind of parameter. *) + let get_kind ( x : param_descrs ) ( name : symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) + + (** Retrieve all names of parameters. *) + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size x#gnc x#gno in + let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in + Array.init n f + + (** The size of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno + + (** Retrieves a string representation of the ParamDescrs. *) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno + +end + +(** Goals + + A goal (aka problem). A goal is essentially a + of formulas, that can be solved and/or transformed using + tactics and solvers. *) +module Goal = +struct + + (** 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. + *) + let get_precision ( x : goal ) = + goal_prec_of_int (Z3native.goal_precision x#gnc x#gno) + + (** Indicates whether the goal is precise. *) + let is_precise ( x : goal ) = + (get_precision x) == GOAL_PRECISE + + (** Indicates whether the goal is an under-approximation. *) + let is_underapproximation ( x : goal ) = + (get_precision x) == GOAL_UNDER + + (** Indicates whether the goal is an over-approximation. *) + let is_overapproximation ( x : goal ) = + (get_precision x) == GOAL_OVER + + (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) + let is_garbage ( x : goal ) = + (get_precision x) == GOAL_UNDER_OVER + + (** Adds the constraints to the given goal. *) + (* CMW: assert seems to be a keyword. *) + let assert_ ( x : goal ) ( constraints : bool_expr array ) = + let f e = Z3native.goal_assert x#gnc x#gno e#gno in + Array.map f constraints + + (** Indicates whether the goal contains `false'. *) + let is_inconsistent ( x : goal ) = + (lbool_of_int (Z3native.goal_inconsistent x#gnc x#gno)) == L_TRUE + + (** The depth of the goal. + This tracks how many transformations were applied to it. *) + let get_depth ( x : goal ) = Z3native.goal_depth x#gnc x#gno + + (** Erases all formulas from the given goal. *) + let reset ( x : goal ) = Z3native.goal_reset x#gnc x#gno + + (** The number of formulas in the goal. *) + let get_size ( x : goal ) = Z3native.goal_size x#gnc x#gno + + (** The formulas in the goal. *) + let get_formulas ( x : goal ) = + let n = get_size x in + let f i = (new bool_expr x#gc)#cnstr_obj (Z3native.goal_formula x#gnc x#gno i) in + Array.init n f + + (** The number of formulas, subformulas and terms in the goal. *) + let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs x#gnc x#gno + + (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) + let is_decided_sat ( x : goal ) = + (lbool_of_int (Z3native.goal_is_decided_sat x#gnc x#gno)) == L_TRUE + + (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) + let is_decided_unsat ( x : goal ) = + (lbool_of_int (Z3native.goal_is_decided_unsat x#gnc x#gno)) == L_TRUE + + (** Translates (copies) the Goal to the target Context . *) + let translate ( x : goal ) ( to_ctx : context ) = + (new goal to_ctx)#cnstr_obj (Z3native.goal_translate x#gnc x#gno to_ctx#gno) + + (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) + let simplify ( x : goal ) ( p : params option ) = + let tn = Z3native.mk_tactic x#gnc "simplify" in + Z3native.tactic_inc_ref x#gnc tn ; + let arn = match p with + | None -> Z3native.tactic_apply x#gnc tn x#gno + | Some(pn) -> Z3native.tactic_apply_ex x#gnc tn x#gno pn#gno + in + Z3native.apply_result_inc_ref x#gnc arn ; + let sg = Z3native.apply_result_get_num_subgoals x#gnc arn in + let res = if sg == 0 then + raise (Z3native.Exception "No subgoals") + else + Z3native.apply_result_get_subgoal x#gnc arn 0 in + Z3native.apply_result_dec_ref x#gnc arn ; + Z3native.tactic_dec_ref x#gnc tn ; + (new goal x#gc)#cnstr_obj res + + (** A string representation of the Goal. *) + let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno +end + + +(** Tactics + + Tactics are the basic building block for creating custom solvers for specific problem domains. + The complete list of tactics may be obtained using Context.get_num_tactics + and Context.get_tactic_names. + It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. +*) +module Tactic = +struct + (** A string containing a description of parameters accepted by the tactic. *) + let get_help ( x : tactic ) = Z3native.tactic_get_help x#gnc x#gno + + + (** Retrieves parameter descriptions for Tactics. *) + let get_param_descrs ( x : tactic ) = + (new param_descrs x#gc)#cnstr_obj (Z3native.tactic_get_param_descrs x#gnc x#gno) + + (** Apply the tactic to the goal. *) + let apply ( x : tactic ) ( g : goal ) ( p : params option ) = + match p with + | None -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply x#gnc x#gno g#gno) + | Some (pn) -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno) + + (** Creates a solver that is implemented using the given tactic. + *) + let get_solver ( x : tactic ) = + (new solver x#gc)#cnstr_obj (Z3native.mk_solver_from_tactic x#gnc x#gno) + +end + + +(** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. +*) +module FuncInterp = +struct + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. + *) + module FuncEntry = + struct + (** + Return the (symbolic) value of this entry. + *) + let get_value ( x : func_entry ) = + create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + + (** + The number of arguments of the entry. + *) + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + + (** + The arguments of the function entry. + *) + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the function entry. + *) + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]]") + end + + (** + The number of entries in the function interpretation. + *) + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + + (** + The entries in the function interpretation + *) + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + Array.init n f + + (** + The (symbolic) `else' value of the function interpretation. + *) + let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + + (** + The arity of the function interpretation + *) + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + + (** + A string representation of the function interpretation. + *) + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (Array.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") +end + +(** Models. + + A Model contains interpretations (assignments) of constants and functions. *) +module Model = +struct + (** Retrieves the interpretation (the assignment) of in the model. + A function declaration of zero arity + An expression if the function has an interpretation in the model, null otherwise. *) + let get_const_interp ( x : model ) ( f : func_decl ) = + if (FuncDecl.get_arity f) != 0 || + (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then + raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") + else + let np = Z3native.model_get_const_interp x#gnc x#gno f#gno in + if (Z3native.is_null np) then + None + else + Some (create_expr x#gc np) + + (** Retrieves the interpretation (the assignment) of in the model. + A Constant + An expression if the constant has an interpretation in the model, null otherwise. + *) + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + + + (** Retrieves the interpretation (the assignment) of a non-constant in the model. + A function declaration of non-zero arity + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + let rec get_func_interp ( x : model ) ( f : func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_range f#gnc f#gno))) in + if (FuncDecl.get_arity f) == 0 then + let n = Z3native.model_get_const_interp x#gnc x#gno f#gno in + if (Z3native.is_null n) then + None + else + match sk with + | ARRAY_SORT -> + if (lbool_of_int (Z3native.is_as_array x#gnc n)) == L_FALSE then + raise (Z3native.Exception "Argument was not an array constant") + else + let fd = Z3native.get_as_array_func_decl x#gnc n in + get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) + | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); + else + let n = (Z3native.model_get_func_interp x#gnc x#gno f#gno) in + if (Z3native.is_null n) then None else Some ((new func_interp x#gc)#cnstr_obj n) + + (** The number of constants that have an interpretation in the model. *) + let get_num_consts ( x : model ) = Z3native.model_get_num_consts x#gnc x#gno + + (** The function declarations of the constants in the model. *) + let get_const_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in + Array.init n f + + + (** The number of function interpretations in the model. *) + let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs x#gnc x#gno + + (** The function declarations of the function interpretations in the model. *) + let get_func_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in + Array.init n f + + (** All symbols that have an interpretation in the model. *) + let get_decls ( x : model ) = + let n_funcs = (get_num_funcs x) in + let n_consts = (get_num_consts x ) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in + let g i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in + Array.append (Array.init n_funcs f) (Array.init n_consts g) + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) + exception ModelEvaluationFailedException of string + + (** + 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. + + The evaluation of in the model. + *) + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno (int_of_lbool (if completion then L_TRUE else L_FALSE))) in + if (lbool_of_int r) == L_FALSE then + raise (ModelEvaluationFailedException "evaluation failed") + else + create_expr x#gc v + + (** Alias for eval. *) + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + eval x t completion + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts x#gnc x#gno + + (** 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. + + + + *) + let get_sorts ( x : model ) = + let n = (get_num_sorts x) in + let f i = (create_sort x#gc (Z3native.model_get_sort x#gnc x#gno i)) in + Array.init n f + + + (** The finite set of distinct values that represent the interpretation for sort . + + An uninterpreted sort + An array of expressions, where each is an element of the universe of + *) + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in + let n = (ASTVector.get_size n_univ) in + let f i = (ASTVector.get n_univ i) in + Array.init n f + + (** Conversion of models to strings. + A string representation of the model. + *) + let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno +end + +(** Tactic application results + + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) +module ApplyResult = +struct + (** The number of Subgoals. *) + let get_num_subgoals ( x : apply_result ) = + Z3native.apply_result_get_num_subgoals x#gnc x#gno + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoals ( x : apply_result ) = + let n = (get_num_subgoals x) in + let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in + Array.init n f + + (** 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 + *) + let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = + (new model x#gc)#cnstr_obj (Z3native.apply_result_convert_model x#gnc x#gno i m#gno) + + (** A string representation of the ApplyResult. *) + let to_string ( x : apply_result) = Z3native.apply_result_to_string x#gnc x#gno +end + +(** Objects that track statistical information about solvers. *) +module Statistics = +struct + + (** + Statistical data is organized into pairs of [Key, Entry], where every + Entry is either a DoubleEntry or a UIntEntry + *) + module Entry = + struct + (** The key of the entry. *) + let get_key (x : statistics_entry) = x#key + + (** The int-value of the entry. *) + let get_int (x : statistics_entry) = x#int + + (** The float-value of the entry. *) + let get_float (x : statistics_entry) = x#float + + (** True if the entry is uint-valued. *) + let is_int (x : statistics_entry) = x#is_int + + (** True if the entry is double-valued. *) + let is_float (x : statistics_entry) = x#is_float + + (** The string representation of the the entry's value. *) + let to_string_value (x : statistics_entry) = + if (is_int x) then + string_of_int (get_int x) + else if (is_float x) then + string_of_float (get_float x) + else + raise (Z3native.Exception "Unknown statistical entry type") + + (** The string representation of the entry (key and value) *) + let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) + end + + (** A string representation of the statistical data. *) + let to_string ( x : statistics ) = Z3native.stats_to_string x#gnc x#gno + + (** The number of statistical data. *) + let get_size ( x : statistics ) = Z3native.stats_size x#gnc x#gno + + (** The data entries. *) + let get_entries ( x : statistics ) = + let n = (get_size x ) in + let f i = ( + let k = Z3native.stats_get_key x#gnc x#gno i in + if (lbool_of_int (Z3native.stats_is_uint x#gnc x#gno i)) == L_TRUE then + ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) + else + ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) + ) in + Array.init n f + + (** + The statistical counters. + *) + let get_keys ( x : statistics ) = + let n = (get_size x) in + let f i = (Z3native.stats_get_key x#gnc x#gno i) in + Array.init n f + + (** + The value of a particular statistical counter. + *) + let get ( x : statistics ) ( key : string ) = + let f p c = (if (Entry.get_key c) = key then (Some c) else p) in + Array.fold_left f None (get_entries x) + +end + +(** Solvers *) +module Solver = +struct + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + + (** + A string that describes all available solver parameters. + *) + let get_help ( x : solver ) = Z3native.solver_get_help x#gnc x#gno + + (** + Sets the solver parameters. + *) + let set_parameters ( x : solver ) ( value : params )= + Z3native.solver_set_params x#gnc x#gno value#gno + + (** + Retrieves parameter descriptions for solver. + *) + let get_param_descrs ( x : solver ) = + (new param_descrs x#gc)#cnstr_obj (Z3native.solver_get_param_descrs x#gnc x#gno) + + (** + The current number of backtracking points (scopes). + + + *) + let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes x#gnc x#gno + + (** + Creates a backtracking point. + + *) + let push ( x : solver ) = Z3native.solver_push x#gnc x#gno + + (** + Backtracks backtracking points. + Note that an exception is thrown if is not smaller than NumScopes + + *) + let pop ( x : solver ) ( n : int ) = Z3native.solver_pop x#gnc x#gno n + + (** + Resets the Solver. + This removes all assertions from the solver. + *) + let reset ( x : solver ) = Z3native.solver_reset x#gnc x#gno + + (** + Assert a constraint (or multiple) into the solver. + *) + let assert_ ( x : solver ) ( constraints : bool_expr array ) = + let f e = (Z3native.solver_assert x#gnc x#gno e#gno) in + Array.map f constraints + + (** + The number of assertions in the solver. + *) + let get_num_assertions ( x : solver ) = + let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in + (ASTVector.get_size a) + + + (** + The set of asserted formulas. + *) + let get_assertions ( x : solver ) = + let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in + let n = (ASTVector.get_size a) in + let f i = ((new bool_expr x#gc)#cnstr_obj (ASTVector.get a i)#gno) in + Array.init n f + + (** + Checks whether the assertions in the solver are consistent or not. + + + + + + *) + let check ( x : solver ) ( assumptions : bool_expr array option) = + let r = + match assumptions with + | None -> lbool_of_int (Z3native.solver_check x#gnc x#gno) + | Some (ass) -> lbool_of_int (Z3native.solver_check_assumptions x#gnc x#gno (Array.length ass) (astaton ass)) + in + match r with + | L_TRUE -> SATISFIABLE + | L_FALSE -> UNSATISFIABLE + | _ -> UNKNOWN + + (** + The model of the last Check. + + The result is None if Check was not invoked before, + if its results was not SATISFIABLE, or if model production is not enabled. + + *) + let get_model ( x : solver ) = + let q = Z3native.solver_get_model x#gnc x#gno in + if (Z3native.is_null q) then + None + else + Some ((new model x#gc)#cnstr_obj q) + + (** + 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. + + *) + let get_proof ( x : solver ) = + let q = Z3native.solver_get_proof x#gnc x#gno in + if (Z3native.is_null q) then + None + else + Some (create_expr x#gc q) + + (** + 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. + + *) + let get_unsat_core ( x : solver ) = + let cn = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_unsat_core x#gnc x#gno) in + let n = (ASTVector.get_size cn) in + let f i = (ASTVector.get cn i) in + Array.init n f + + (** + A brief justification of why the last call to Check returned UNKNOWN. + *) + let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown x#gnc x#gno + + + (** + Solver statistics. + *) + let get_statistics ( x : solver ) = + (new statistics x#gc)#cnstr_obj (Z3native.solver_get_statistics x#gnc x#gno) + + (** + A string representation of the solver. + *) + let to_string ( x : solver ) = Z3native.solver_to_string x#gnc x#gno +end + +(** Probes + + 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. +*) +module Probe = +struct + (** + Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. + *) + let apply ( x : probe ) (g : goal) = + Z3native.probe_apply x#gnc x#gno g#gno +end + + (** The main interaction with Z3 happens via the Context module *) module Context = struct From 3684b3a87d438d0bd989752ad69268bbf9f37c51 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sun, 23 Dec 2012 02:20:24 +0000 Subject: [PATCH 025/248] New ML API savepoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 6488 +++++++++++++++++++--------------------------- 1 file changed, 2629 insertions(+), 3859 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c22ef869b..5f67e11e2 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -586,6 +586,13 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end +(** Quantifier pattern objects *) +class pattern ctx = +object (self) + inherit ast ctx as super + method cnstr_obj obj = (self#sno ctx obj) ; self +end + (** Parameter description objects *) class param_descrs ctx = object (self) @@ -775,6 +782,33 @@ struct match (kind o) with | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int o#gnc o#gno)) | STRING_SYMBOL -> (Z3native.get_symbol_string o#gnc o#gno) + + (** + 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. + *) + let mk_int ( ctx : context ) i = + (new int_symbol ctx)#cnstr_int i + + (** Creates a new symbol using a string. *) + let mk_string ( ctx : context ) s = + (new string_symbol ctx)#cnstr_string s + + (** + Create an array of symbols. + *) + let mk_ints ( ctx : context ) ( names : int array ) = + let f elem = mk_int ( ctx : context ) elem in + (Array.map f names) + + (** + Create an array of symbols. + *) + let mk_strings ( ctx : context ) ( names : string array ) = + let f elem = mk_string ( ctx : context ) elem in + (Array.map f names) end @@ -813,49 +847,26 @@ struct A string representation of the sort. *) let to_string (x : sort) = Z3native.sort_to_string x#gnc x#gno + + (** + Create a new Boolean sort. + *) + let mk_bool ( ctx : context ) = + (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort ctx#gno) + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted ( ctx : context ) (s : symbol) = + (new uninterpreted_sort ctx)#cnstr_s s + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted_s ( ctx : context ) (s : string) = + mk_uninterpreted ctx ((Symbol.mk_string ( ctx : context ) s) :> symbol) end -(** Array sorts *) -module ArraySort = -struct - (** The domain of the array sort. *) - let get_domain (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_domain x#gnc x#gno) - - (** The range of the array sort. *) - let get_range (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_range x#gnc x#gno) -end - -(** Bit-vector sorts *) -module BitVecSort = -struct - (** The size of the bit-vector sort. *) - let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno -end - -(** Finite domain sorts *) -module FiniteDomainSort = -struct - (** The size of the finite domain sort. *) - let get_size (x : finite_domain_sort) = - let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") -end - -(** Relation sorts *) -module RelationSort = -struct - (** The arity of the relation sort. *) - let get_arity (x : relation_sort) = Z3native.get_relation_arity x#gnc x#gno - - (** The sorts of the columns of the relation sort. *) - let get_column_sorts (x : relation_sort) = - let n = get_arity x in - let f i = create_sort x#gc (Z3native.get_relation_column x#gnc x#gno i) in - Array.init n f - -end - (**/**) let create_expr ctx obj = if ast_kind_of_int (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then @@ -957,6 +968,48 @@ struct raise (Z3native.Exception "parameter is not a ratinoal string") else x#rational + + (** + Creates a new function declaration. + *) + let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr name domain range + + (** + Creates a new function declaration. + *) + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = + mk_func_decl ctx ((Symbol.mk_string ctx name) :> symbol) domain range + + (** + Creates a fresh function declaration with a name prefixed with . + + + *) + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort) = + (new func_decl ctx)#cnstr_pdr prefix domain range + + (** + Creates a new constant function declaration. + *) + let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr name [||] range + + + (** + Creates a new constant function declaration. + *) + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr ((Symbol.mk_string ctx name) :> symbol) [||] range + + (** + Creates a fresh constant function declaration with a name prefixed with . + + + *) + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = + (new func_decl ctx)#cnstr_pdr prefix [||] range + end (** @@ -1046,91 +1099,103 @@ struct end -(** Datatype sorts *) -module DatatypeSort = -struct - (** The number of constructors of the datatype sort. *) - let get_num_constructors (x : datatype_sort) = Z3native.get_datatype_sort_num_constructors x#gnc x#gno - - (** The range of the array sort. *) - let get_constructors (x : datatype_sort) = - let n = (get_num_constructors x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i) in - Array.init n f - - (** The recognizers. *) - let get_recognizers (x : datatype_sort) = - let n = (get_num_constructors x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_recognizer x#gnc x#gno i) in - Array.init n f - - (** The constructor accessors. *) - let get_accessors (x : datatype_sort) = - let n = (get_num_constructors x) in - let f i = ( - let fd = ((new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i)) in - let ds = (Z3native.get_domain_size fd#gnc fd#gno) in - let g j = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor_accessor x#gnc x#gno i j) in - Array.init ds g - ) in - Array.init n f -end - -(** Enumeration sorts *) -module EnumSort = -struct - (** The function declarations of the constants in the enumeration. *) - let get_const_decls (x : enum_sort) = x#const_decls - - (** The test predicates for the constants in the enumeration. *) - let get_tester_decls (x : enum_sort) = x#tester_decls -end - -(** List sorts *) -module ListSort = -struct - (** The declaration of the nil function of this list sort. *) - let get_nil_decl (x : list_sort) = x#nil_decl - - (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl (x : list_sort) = x#is_nil_decl - - (** The declaration of the cons function of this list sort. *) - let get_cons_decl (x : list_sort) = x#cons_decl - - (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl (x : list_sort) = x#is_cons_decl - - (** The declaration of the head function of this list sort.*) - let get_head_decl (x : list_sort) = x#head_decl - - (** The declaration of the tail function of this list sort. *) - let get_tail_decl (x : list_sort) = x#tail_decl - - (** The empty list. *) - let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] -end - -(** Tuple sorts *) -module TupleSort = -struct - (** The constructor function of the tuple.*) - let get_mk_decl (x : tuple_sort) = - (new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_mk_decl x#gnc x#gno) - - (** The number of fields in the tuple. *) - let get_num_fields (x : tuple_sort) = Z3native.get_tuple_sort_num_fields x#gnc x#gno - - (** The field declarations. *) - let get_field_decls (x : tuple_sort) = - let n = get_num_fields x in - let f i = ((new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_field_decl x#gnc x#gno i)) in - Array.init n f -end - (** The abstract syntax tree (AST) module *) module AST = struct + (** Vectors of ASTs *) + module ASTVector = + struct + (** The size of the vector *) + let get_size ( x : ast_vector ) = + Z3native.ast_vector_size x#gnc x#gno + + (** + Retrieves the i-th object in the vector. + @param i Index + @return An AST + *) + let get ( x : ast_vector ) ( i : int ) = + create_ast x#gc (Z3native.ast_vector_get x#gnc x#gno i) + + (** Sets the i-th object in the vector. *) + let set ( x : ast_vector ) ( i : int ) ( value : ast ) = + Z3native.ast_vector_set x#gnc x#gno i value#gno + + (** Resize the vector to . + @param newSize The new size of the vector. *) + let resize ( x : ast_vector ) ( new_size : int ) = + Z3native.ast_vector_resize x#gnc x#gno new_size + + (** + Add the AST to the back of the vector. The size + is increased by 1. + @param a An AST + *) + let push ( x : ast_vector ) ( a : ast ) = + Z3native.ast_vector_push x#gnc x#gno a#gno + + (** + Translates all ASTs in the vector to . + @param to_ctx A context + @return A new ASTVector + *) + let translate ( x : ast_vector ) ( to_ctx : context ) = + (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno to_ctx#gno) + + (** Retrieves a string representation of the vector. *) + let to_string ( x : ast_vector ) = + Z3native.ast_vector_to_string x#gnc x#gno + end + + (** Map from AST to AST *) + module ASTMap = + struct + (** Checks whether the map contains the key . + @param k An AST + @return True if is a key in the map, false otherwise. *) + let contains ( m : ast_map ) ( key : ast ) = + (lbool_of_int (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE + + (** Finds the value associated with the key . + + This function signs an error when is not a key in the map. + @param k An AST + *) + let find ( m : ast_map ) ( key : ast ) = + create_ast m#gc (Z3native.ast_map_find m#gnc m#gno key#gno) + + (** + Stores or replaces a new key/value pair in the map. + @param k The key AST + @param v The value AST + *) + let insert ( m : ast_map ) ( key : ast ) ( value : ast) = + Z3native.ast_map_insert m#gnc m#gno key#gno value#gno + + (** + Erases the key from the map. + @param k An AST + *) + let erase ( m : ast_map ) ( key : ast ) = + Z3native.ast_map_erase m#gnc m#gno key#gno + + (** Removes all keys from the map. *) + let reset ( m : ast_map ) = + Z3native.ast_map_reset m#gnc m#gno + + (** The size of the map *) + let get_size ( m : ast_map ) = + Z3native.ast_map_size m#gnc m#gno + + (** The keys stored in the map. *) + let get_keys ( m : ast_map ) = + (new ast_vector m#gc)#cnstr_obj (Z3native.ast_map_keys m#gnc m#gno) + + (** Retrieves a string representation of the map.*) + let to_strnig ( m : ast_map ) = + Z3native.ast_map_to_string m#gnc m#gno + end + (** The AST's hash code. @return A hash code @@ -1159,7 +1224,7 @@ struct | _ -> false (** - Indicates whether the AST is a BoundVariable + Indicates whether the AST is a bound variable *) let is_var ( x : ast) = (get_ast_kind x) == VAR_AST @@ -1227,163 +1292,7 @@ struct (create_ast to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno)) end -(** - Parameter sets - - A Params objects represents a configuration in the form of Symbol/value pairs. -*) -module Params = -struct - (** - Adds a parameter setting. - *) - let add_bool (p : params) (name : symbol) (value : bool) = - Z3native.params_set_bool p#gnc p#gno name#gno (int_of_lbool (if value then L_TRUE else L_FALSE)) - - (** - Adds a parameter setting. - *) - let add_int (p : params) (name : symbol) (value : int) = - Z3native.params_set_uint p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_double (p : params) (name : symbol) (value : float) = - Z3native.params_set_double p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_symbol (p : params) (name : symbol) (value : symbol) = - Z3native.params_set_symbol p#gnc p#gno name#gno value#gno - - (** - Adds a parameter setting. - *) - let add_s_bool (p : params) (name : string) (value : bool) = - add_bool p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_int (p : params) (name : string) (value : int) = - add_int p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_double (p : params) (name : string) (value : float) = - add_double p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_symbol (p : params) (name : string) (value : symbol) = - add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - A string representation of the parameter set. - *) - let to_string (p : params) = Z3native.params_to_string p#gnc p#gno -end - -(** Vectors of ASTs *) -module ASTVector = -struct - (** The size of the vector *) - let get_size ( x : ast_vector ) = - Z3native.ast_vector_size x#gnc x#gno - - (** - Retrieves the i-th object in the vector. - @param i Index - @return An AST - *) - let get ( x : ast_vector ) ( i : int ) = - create_ast x#gc (Z3native.ast_vector_get x#gnc x#gno i) - - (** Sets the i-th object in the vector. *) - let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set x#gnc x#gno i value#gno - - (** Resize the vector to . - @param newSize The new size of the vector. *) - let resize ( x : ast_vector ) ( new_size : int ) = - Z3native.ast_vector_resize x#gnc x#gno new_size - - (** - Add the AST to the back of the vector. The size - is increased by 1. - @param a An AST - *) - let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push x#gnc x#gno a#gno - - (** - Translates all ASTs in the vector to . - @param to_ctx A context - @return A new ASTVector - *) - let translate ( x : ast_vector ) ( to_ctx : context ) = - (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno to_ctx#gno) - - (** Retrieves a string representation of the vector. *) - let to_string ( x : ast_vector ) = - Z3native.ast_vector_to_string x#gnc x#gno -end - -(** Map from AST to AST *) -module ASTMap = -struct - (** Checks whether the map contains the key . - @param k An AST - @return True if is a key in the map, false otherwise. *) - let contains ( m : ast_map ) ( key : ast ) = - (lbool_of_int (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE - - (** Finds the value associated with the key . - - This function signs an error when is not a key in the map. - - @param k An AST - *) - let find ( m : ast_map ) ( key : ast ) = - create_ast m#gc (Z3native.ast_map_find m#gnc m#gno key#gno) - - (** - Stores or replaces a new key/value pair in the map. - @param k The key AST - @param v The value AST - *) - let insert ( m : ast_map ) ( key : ast ) ( value : ast) = - Z3native.ast_map_insert m#gnc m#gno key#gno value#gno - - (** - Erases the key from the map. - @param k An AST - *) - let erase ( m : ast_map ) ( key : ast ) = - Z3native.ast_map_erase m#gnc m#gno key#gno - - (** Removes all keys from the map. *) - let reset ( m : ast_map ) = - Z3native.ast_map_reset m#gnc m#gno - - (** The size of the map *) - let get_size ( m : ast_map ) = - Z3native.ast_map_size m#gnc m#gno - - (** The keys stored in the map. *) - let get_keys ( m : ast_map ) = - (new ast_vector m#gc)#cnstr_obj (Z3native.ast_map_keys m#gnc m#gno) - - (** Retrieves a string representation of the map.*) - let to_strnig ( m : ast_map ) = - Z3native.ast_map_to_string m#gnc m#gno -end - -(** Expressions (terms) *) +(** General expressions (terms), including Boolean logic *) module Expr = struct (** @@ -1402,7 +1311,7 @@ struct (** Indicates whether the expression is the true or false expression - or something else (Z3_L_UNDEF). + or something else (L_UNDEF). *) let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value x#gnc x#gno) @@ -1434,7 +1343,6 @@ struct 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]. - *) let substitute ( x : expr ) from to_ = if (Array.length from) <> (Array.length to_) then @@ -1453,7 +1361,6 @@ struct 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]. - *) let substitute_vars ( x : expr ) to_ = create_expr x#gc (Z3native.substitute_vars x#gnc x#gno (Array.length to_) (expraton to_)) @@ -1496,28 +1403,8 @@ struct *) let is_bool ( x : expr ) = (AST.is_expr x) && (lbool_of_int (Z3native.is_eq_sort x#gnc - (Z3native.mk_bool_sort x#gnc) - (Z3native.get_sort x#gnc x#gno))) == L_TRUE - - (** - Indicates whether the term is of integer sort. - *) - let is_int ( x : expr ) = - ((lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) - - (** - Indicates whether the term is of sort real. - *) - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) - - (** - Indicates whether the term is of an array sort. - *) - let is_array ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + (Z3native.mk_bool_sort x#gnc) + (Z3native.get_sort x#gnc x#gno))) == L_TRUE (** Indicates whether the term represents a constant. @@ -1526,21 +1413,6 @@ struct (get_num_args x) == 0 && FuncDecl.get_domain_size(get_func_decl x) == 0 - (** - Indicates whether the term is an integer numeral. - *) - let is_int_numeral ( x : expr ) = (is_numeral x) && (is_int x) - - (** - Indicates whether the term is a real numeral. - *) - let is_rat_num ( x : expr ) = (is_numeral x) && (is_real x) - - (** - Indicates whether the term is an algebraic number - *) - let is_algebraic_number ( x : expr ) = lbool_of_int(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE - (** Indicates whether the term is the constant true. *) @@ -1597,146 +1469,1189 @@ struct let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) (** - Indicates whether the term is an arithmetic numeral. + 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. *) - let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ANUM) + let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) (** - Indicates whether the term is a less-than-or-equal + 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. + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) *) - let is_le ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LE) (** - Indicates whether the term is a greater-than-or-equal + 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. *) - let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_GE) + let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) (** - Indicates whether the term is a less-than + Creates a new Constant of sort and named . *) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LT) + let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = + create_expr ctx (Z3native.mk_const ctx#gno name#gno range#gno) + (** - Indicates whether the term is a greater-than + Creates a new Constant of sort and named . *) - let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_GT) + let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = + mk_const ctx ((Symbol.mk_string ctx name) :> symbol) range + (** - Indicates whether the term is addition (binary) + Creates a constant from the func_decl . + @param f An expression of a 0-arity function *) - let is_add ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ADD) + let mk_const_f ( ctx : context ) ( f : func_decl ) = + create_expr_fa ctx f [||] (** - Indicates whether the term is subtraction (binary) + Creates a fresh constant of sort and a + name prefixed with . *) - let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SUB) + let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort) = + create_expr ctx (Z3native.mk_fresh_const ctx#gno prefix range#gno) (** - Indicates whether the term is a unary minus - *) - let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UMINUS) + Create a Boolean constant. + *) + let mk_bool_const ( ctx : context ) ( name : symbol ) = + ((mk_const ctx name (Sort.mk_bool ctx)) :> bool_expr) + + (** + Create a Boolean constant. + *) + let mk_bool_const_s ( ctx : context ) ( name : string ) = + mk_bool_const ctx ((Symbol.mk_string ctx name) :> symbol) (** - Indicates whether the term is multiplication (binary) + Create a new function application. *) - let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_MUL) + let mk_app ( ctx : context ) ( f : func_decl ) ( args : expr array ) = + create_expr_fa ctx f args (** - Indicates whether the term is division (binary) - *) - let is_div ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DIV) + The true Term. + *) + let mk_true ( ctx : context ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_true ctx#gno) (** - Indicates whether the term is integer division (binary) - *) - let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IDIV) + The false Term. + *) + let mk_false ( ctx : context ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_false ctx#gno) (** - Indicates whether the term is remainder (binary) - *) - let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_REM) + Creates a Boolean value. + *) + let mk_bool ( ctx : context ) ( value : bool) = + if value then mk_true ctx else mk_false ctx (** - Indicates whether the term is modulus (binary) + Creates the equality = . *) - let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_MOD) + let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_eq ctx#gno x#gno y#gno) (** - Indicates whether the term is a coercion of integer to real (unary) + Creates a distinct term. *) - let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TO_REAL) + let mk_distinct ( ctx : context ) ( args : expr array ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_distinct ctx#gno (Array.length args) (astaton args)) + + (** + Mk an expression representing not(a). + *) + let mk_not ( ctx : context ) ( a : bool_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_not ctx#gno a#gno) + + (** + Create an expression representing an if-then-else: ite(t1, t2, t3). + @param t1 An expression with Boolean sort + @param t2 An expression + @param t3 An expression with the same sort as + *) + let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = + create_expr ctx (Z3native.mk_ite ctx#gno t1#gno t2#gno t3#gno) + + (** + Create an expression representing t1 iff t2. + *) + let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_iff ctx#gno t1#gno t2#gno) (** - Indicates whether the term is a coercion of real to integer (unary) + Create an expression representing t1 -> t2. *) - let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TO_INT) + let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_implies ctx#gno t1#gno t2#gno) (** - Indicates whether the term is a check that tests whether a real is integral (unary) + Create an expression representing t1 xor t2. *) - let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IS_INT) + let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_xor ctx#gno t1#gno t2#gno) + + (** + Create an expression representing the AND of args + *) + let mk_and ( ctx : context ) ( args : bool_expr array ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_and ctx#gno (Array.length args) (astaton args)) + + (** + Create an expression representing the OR of args + *) + let mk_or ( ctx : context ) ( args : bool_expr array ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_or ctx#gno (Array.length args) (astaton args)) +end + +(** Functions to manipulate Array expressions *) +module Arrays = +struct + (** + Create a new array sort. + *) + let mk_sort ( ctx : context ) domain range = + (new array_sort ctx)#cnstr_dr domain range (** 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. + Array store takes at least 3 arguments. *) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_STORE) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) (** Indicates whether the term is an array select. *) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SELECT) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + For example, select(const(v),i) = v holds for every v and i. The function is unary. *) - let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CONST_ARRAY) + let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) (** Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. + For example default(const(v)) = v. The function is unary. *) - let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ARRAY_DEFAULT) + let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + It satisfies map[f](a1,..,a_n)[i] = f(a1[i],...,a_n[i]) for every i. *) - let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ARRAY_MAP) + let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + function passed as parameter. *) - let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AS_ARRAY) + let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + (** + Indicates whether the term is of an array sort. + *) + let is_array ( x : expr ) = + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + + (** The domain of the array sort. *) + let get_domain (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_domain x#gnc x#gno) + + (** The range of the array sort. *) + let get_range (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_range x#gnc x#gno) + + + (** + Create an array constant. + *) + let mk_const ( ctx : context ) ( name : symbol ) ( domain : sort ) ( range : sort ) = + ((Expr.mk_const ctx name ((mk_sort ctx domain range) :> sort)) :> array_expr) + + (** + Create an array constant. + *) + let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = + mk_const ctx ((Symbol.mk_string ctx name) :> symbol) 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. + + + *) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = + ((create_expr ctx (Z3native.mk_select ctx#gno a#gno i#gno)) :> array_expr) + + (** + 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). + + + *) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr) = + (new array_expr ctx)#cnstr_obj (Z3native.mk_store ctx#gno a#gno i#gno v#gno) + + (** + Create a constant array. + + The resulting term is an array, such that a selecton an arbitrary index + produces the value v. + + + *) + let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = + (new array_expr ctx)#cnstr_obj (Z3native.mk_const_array ctx#gno domain#gno v#gno) + + (** + 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]. + + + + *) + let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = + ((create_expr ctx (Z3native.mk_map ctx#gno f#gno (Array.length args) (astaton args))) :> array_expr) + + (** + Access the array default value. + + Produces the default range value, for arrays that can be represented as + finite maps with a default range value. + *) + let mk_term_array ( ctx : context ) ( arg : array_expr ) = + ((create_expr ctx (Z3native.mk_array_default ctx#gno arg#gno)) :> array_expr) +end + +(** Functions to manipulate Set expressions *) +module Sets = +struct (** Indicates whether the term is set union *) - let is_set_union ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_UNION) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) (** Indicates whether the term is set intersection *) - let is_set_intersect ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_INTERSECT) + let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) (** Indicates whether the term is set difference *) - let is_set_difference ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_DIFFERENCE) + let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) (** Indicates whether the term is set complement *) - let is_set_complement ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_COMPLEMENT) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) (** Indicates whether the term is set subset *) - let is_set_subset ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_SUBSET) + let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + +(** + Create a set type. +*) +let mk_sort ( ctx : context ) ( ty : sort) = + (new set_sort ctx)#cnstr_s ty + +(** + Create an empty set. +*) +let mk_empty ( ctx : context ) ( domain : sort ) = + (create_expr ctx (Z3native.mk_empty_set ctx#gno domain#gno)) + + (** + Create the full set. + *) +let mk_full ( ctx : context ) ( domain : sort ) = + create_expr ctx (Z3native.mk_full_set ctx#gno domain#gno) + +(** + Add an element to the set. +*) +let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = + create_expr ctx (Z3native.mk_set_add ctx#gno set#gno element#gno) + + (** + Remove an element from a set. + *) +let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = + create_expr ctx (Z3native.mk_set_del ctx#gno set#gno element#gno) + + (** + Take the union of a list of sets. + *) +let mk_union ( ctx : context ) ( args : expr array ) = + create_expr ctx (Z3native.mk_set_union ctx#gno (Array.length args) (astaton args)) + +(** + Take the intersection of a list of sets. +*) +let mk_intersection ( ctx : context ) ( args : expr array ) = + create_expr ctx (Z3native.mk_set_intersect ctx#gno (Array.length args) (astaton args)) + +(** + Take the difference between two sets. +*) +let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = + create_expr ctx (Z3native.mk_set_difference ctx#gno arg1#gno arg2#gno) + +(** + Take the complement of a set. +*) +let mk_complement ( ctx : context ) ( arg : expr ) = + create_expr ctx (Z3native.mk_set_complement ctx#gno arg#gno) + +(** + Check for set membership. +*) +let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = + create_expr ctx (Z3native.mk_set_member ctx#gno elem#gno set#gno) + + (** + Check for subsetness of sets. + *) +let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = + create_expr ctx (Z3native.mk_set_subset ctx#gno arg1#gno arg2#gno) + +end + +(** Functions to manipulate Finite Domain expressions *) +module FiniteDomains = +struct + (** + Create a new finite domain sort. + *) + let mk_sort ( ctx : context ) ( name : symbol ) size = + (new finite_domain_sort ctx)#cnstr_si name size + + (** + Create a new finite domain sort. + *) + let mk_sort_s ( ctx : context ) ( name : string ) size = + (new finite_domain_sort ctx)#cnstr_si ((Symbol.mk_string ctx name) :> symbol) size + + + (** + Indicates whether the term is of an array sort. + *) + let is_finite_domain ( x : expr ) = + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) + + (** + Indicates whether the term is a less than predicate over a finite domain. + *) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + + (** The size of the finite domain sort. *) + let get_size (x : finite_domain_sort) = + let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in + if lbool_of_int(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") +end + +(** Functions to manipulate Relation expressions *) +module Relations = +struct + (** + Indicates whether the term is of a relation sort. + *) + let is_relation ( x : expr ) = + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == 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. + *) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + + (** + Indicates whether the term is an empty relation + *) + let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + + (** + Indicates whether the term is a test for the emptiness of a relation + *) + let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + + (** + Indicates whether the term is a relational join + *) + let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + + (** + Indicates whether the term is the union or convex hull of two relations. + The function takes two arguments. + *) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + + (** + Indicates whether the term is the widening of two relations + The function takes two arguments. + *) + let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + + (** + Indicates whether the term is a projection of columns (provided as numbers in the parameters). + The function takes one argument. + *) + let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + *) + let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. + *) + let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + *) + let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + + (** + Indicates whether the term is the complement of a relation + *) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + *) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + *) + let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + + (** The arity of the relation sort. *) + let get_arity (x : relation_sort) = Z3native.get_relation_arity x#gnc x#gno + + (** The sorts of the columns of the relation sort. *) + let get_column_sorts (x : relation_sort) = + let n = get_arity x in + let f i = create_sort x#gc (Z3native.get_relation_column x#gnc x#gno i) in + Array.init n f + +end + +(** Quantifier expressions *) +module Quantifiers = +struct + (** + 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 : expr ) appears, the higher is its + index. + *) + let get_index ( x : expr ) = + if not (AST.is_var x) then + raise (Z3native.Exception "Term is not a bound variable.") + else + Z3native.get_index_value x#gnc x#gno + + (** Quantifier patterns + + 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. + *) + module Pattern = + struct + (** + The number of terms in the pattern. + *) + let get_num_terms ( x : pattern ) = + Z3native.get_pattern_num_terms x#gnc x#gno + + (** + The terms in the pattern. + *) + let get_terms ( x : pattern ) = + let n = (get_num_terms x) in + let f i = (create_expr x#gc (Z3native.get_pattern x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the pattern. + *) + let to_string ( x : pattern ) = Z3native.pattern_to_string x#gnc x#gno + end + + (** + Indicates whether the quantifier is universal. + *) + let is_universal ( x : quantifier ) = + lbool_of_int (Z3native.is_quantifier_forall x#gnc x#gno) == L_TRUE + + (** + Indicates whether the quantifier is existential. + *) + let is_existential ( x : quantifier ) = not (is_universal x) + + (** + The weight of the quantifier. + *) + let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight x#gnc x#gno + + (** + The number of patterns. + *) + let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns x#gnc x#gno + + (** + The patterns. + *) + let get_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_pattern_ast x#gnc x#gno i)) in + Array.init n f + + (** + The number of no-patterns. + *) + let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns x#gnc x#gno + + (** + The no-patterns. + *) + let get_no_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_no_pattern_ast x#gnc x#gno i)) in + Array.init n f + + (** + The number of bound variables. + *) + let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound x#gnc x#gno + + (** + The symbols for the bound variables. + *) + let get_bound_variable_names ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (create_symbol x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in + Array.init n f + + (** + The sorts of the bound variables. + *) + let get_bound_variable_sorts ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (create_sort x#gc (Z3native.get_quantifier_bound_sort x#gnc x#gno i)) in + Array.init n f + + (** + The body of the quantifier. + *) + let get_body ( x : quantifier ) = + (new bool_expr x#gc)#cnstr_obj (Z3native.get_quantifier_body x#gnc x#gno) + + (** + Creates a new bound variable. + @param index The de-Bruijn index of the variable + @param ty The sort of the variable + *) + let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = + create_expr ctx (Z3native.mk_bound ctx#gno index ty#gno) + + (** + Create a quantifier pattern. + *) + let mk_pattern ( ctx : context ) ( terms : expr array ) = + if (Array.length terms) == 0 then + raise (Z3native.Exception "Cannot create a pattern from zero terms") + else + (new pattern ctx)#cnstr_obj (Z3native.mk_pattern ctx#gno (Array.length terms) (astaton terms)) +end + +(** Functions to manipulate Datatype expressions *) +module Datatypes = +struct + (** Constructors *) + module Constructor = + struct + (** The number of fields of the constructor. *) + let get_num_fields ( x : constructor ) = x#get_n + + (** The function declaration of the constructor. *) + let get_constructor_decl ( x : constructor ) = x#constructor_decl + + (** The function declaration of the tester. *) + let get_tester_decl ( x : constructor ) = x#tester_decl + + (** The function declarations of the accessors *) + let get_accessor_decls ( x : constructor ) = x#accessor_decls + end + + (* DATATYPES *) + (** + Create a datatype constructor. + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + *) + let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs + + + (** + Create a datatype constructor. + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + *) + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + mk_constructor ctx ((Symbol.mk_string ctx name) :> symbol) recognizer field_names sorts sort_refs + + + (** + Create a new datatype sort. + *) + let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = + (new datatype_sort ctx)#cnstr_sc name constructors + + (** + Create a new datatype sort. + *) + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = + mk_sort ctx ((Symbol.mk_string ctx name) :> symbol) constructors + + (** + Create mutually recursive datatypes. + @param names names of datatype sorts + @param c list of constructors, one list per sort. + *) + let mk_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = + let n = (Array.length names) in + let f e = ( (new constructor_list ctx)#cnstr_ca e ) in + let cla = (Array.map f c) in + let (r, a) = (Z3native.mk_datatypes ctx#gno n (symbolaton names) (constructor_listaton cla)) in + let g e = ( (new datatype_sort ctx)#cnstr_obj e) in + (Array.map g r) + + (** Create mutually recursive data-types. *) + let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = + mk_sorts ctx + ( + let f e = ((Symbol.mk_string ctx e) :> symbol) in + Array.map f names + ) + c + + (** The number of constructors of the datatype sort. *) + let get_num_constructors (x : datatype_sort) = Z3native.get_datatype_sort_num_constructors x#gnc x#gno + + (** The range of the array sort. *) + let get_constructors (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i) in + Array.init n f + + (** The recognizers. *) + let get_recognizers (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_recognizer x#gnc x#gno i) in + Array.init n f + + (** The constructor accessors. *) + let get_accessors (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = ( + let fd = ((new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i)) in + let ds = (Z3native.get_domain_size fd#gnc fd#gno) in + let g j = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor_accessor x#gnc x#gno i j) in + Array.init ds g + ) in + Array.init n f +end + +(** Functions to manipulate Enumeration expressions *) +module Enumerations = +struct + (** + Create a new enumeration sort. + *) + let mk_sort ( ctx : context ) name enum_names = + (new enum_sort ctx)#cnstr_ss name enum_names + + (** + Create a new enumeration sort. + *) + let mk_sort_s ( ctx : context ) name enum_names = + (new enum_sort ctx)#cnstr_ss + ((Symbol.mk_string ( ctx : context ) name) :> symbol) + (let f e = (e :> symbol) in + (Array.map f (Symbol.mk_strings ( ctx : context ) enum_names)) + ) + + (** The function declarations of the constants in the enumeration. *) + let get_const_decls (x : enum_sort) = x#const_decls + + (** The test predicates for the constants in the enumeration. *) + let get_tester_decls (x : enum_sort) = x#tester_decls +end + +(** Functions to manipulate List expressions *) +module Lists = +struct + (** + Create a new list sort. + *) + let mk_sort ( ctx : context ) (name : symbol) elem_sort = + (new list_sort ctx)#cnstr_ss name elem_sort + + (** + Create a new list sort. + *) + let mk_list_s ( ctx : context ) (name : string) elem_sort = + mk_sort ctx ((Symbol.mk_string ctx name) :> symbol) elem_sort + + + (** The declaration of the nil function of this list sort. *) + let get_nil_decl (x : list_sort) = x#nil_decl + + (** The declaration of the isNil function of this list sort. *) + let get_is_nil_decl (x : list_sort) = x#is_nil_decl + + (** The declaration of the cons function of this list sort. *) + let get_cons_decl (x : list_sort) = x#cons_decl + + (** The declaration of the isCons function of this list sort. *) + let get_is_cons_decl (x : list_sort) = x#is_cons_decl + + (** The declaration of the head function of this list sort. *) + let get_head_decl (x : list_sort) = x#head_decl + + (** The declaration of the tail function of this list sort. *) + let get_tail_decl (x : list_sort) = x#tail_decl + + (** The empty list. *) + let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] +end + +(** Functions to manipulate Tuple expressions *) +module Tuples = +struct + (** + Create a new tuple sort. + *) + let mk_sort ( ctx : context ) name field_names field_sorts = + (new tuple_sort ctx)#cnstr_siss name (Array.length field_names) field_names field_sorts + + (** The constructor function of the tuple. *) + let get_mk_decl (x : tuple_sort) = + (new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_mk_decl x#gnc x#gno) + + (** The number of fields in the tuple. *) + let get_num_fields (x : tuple_sort) = Z3native.get_tuple_sort_num_fields x#gnc x#gno + + (** The field declarations. *) + let get_field_decls (x : tuple_sort) = + let n = get_num_fields x in + let f i = ((new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_field_decl x#gnc x#gno i)) in + Array.init n f +end + +(** Functions to manipulate arithmetic expressions *) +module Arithmetic = +struct + (** + Create a new integer sort. + *) + let mk_int_sort ( ctx : context ) = + (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort ctx#gno) + + (** + Create a real sort. + *) + let mk_real_sort ( ctx : context ) = + (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort ctx#gno) + + (** + Indicates whether the term is of integer sort. + *) + let is_int ( x : expr ) = + ((lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) + + (** + Indicates whether the term is an arithmetic numeral. + *) + let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + + (** + Indicates whether the term is a less-than-or-equal + *) + let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + + (** + Indicates whether the term is a greater-than-or-equal + *) + let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + + (** + Indicates whether the term is a less-than + *) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + + (** + Indicates whether the term is a greater-than + *) + let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + + (** + Indicates whether the term is addition (binary) + *) + let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + + (** + Indicates whether the term is subtraction (binary) + *) + let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + + (** + Indicates whether the term is a unary minus + *) + let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + + (** + Indicates whether the term is multiplication (binary) + *) + let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + + (** + Indicates whether the term is division (binary) + *) + let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + + (** + Indicates whether the term is integer division (binary) + *) + let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + + (** + Indicates whether the term is remainder (binary) + *) + let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + + (** + Indicates whether the term is modulus (binary) + *) + let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + + (** + Indicates whether the term is a coercion of integer to real (unary) + *) + let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + + (** + Indicates whether the term is a coercion of real to integer (unary) + *) + let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + + (** + Indicates whether the term is a check that tests whether a real is integral (unary) + *) + let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + + (** + Indicates whether the term is of sort real. + *) + let is_real ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) + + (** + Indicates whether the term is an integer numeral. + *) + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) + + (** + Indicates whether the term is a real numeral. + *) + let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) + + (** + Indicates whether the term is an algebraic number + *) + let is_algebraic_number ( x : expr ) = lbool_of_int(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE + + (** Retrieve the int value. *) + let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if lbool_of_int(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno + + (** The numerator of a rational numeral. *) + let get_numerator ( x : rat_num ) = + (new int_num x#gc)#cnstr_obj (Z3native.get_numerator x#gnc x#gno) + + (** The denominator of a rational numeral. *) + let get_denominator ( x : rat_num ) = + (new int_num x#gc)#cnstr_obj (Z3native.get_denominator x#gnc x#gno) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : rat_num ) (precision : int) = + Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : rat_num ) = Z3native.get_numeral_string x#gnc x#gno + + (** + Creates an integer constant. + *) + let mk_int_const ( ctx : context ) ( name : symbol ) = + ((Expr.mk_const ctx name (mk_int_sort ctx)) :> int_expr) + + (** + Creates an integer constant. + *) + let mk_int_const_s ( ctx : context ) ( name : string ) = + mk_int_const ctx ((Symbol.mk_string ctx name) :> symbol) + + (** + Creates a real constant. + *) + let mk_real_const ( ctx : context ) ( name : symbol ) = + ((Expr.mk_const ctx name (mk_real_sort ctx)) :> real_expr) + + (** + Creates a real constant. + *) + let mk_real_const_s ( ctx : context ) ( name : string ) = + mk_real_const ctx ((Symbol.mk_string ctx name) :> symbol) + + (** + Create an expression representing t[0] + t[1] + .... + *) + let mk_add ( ctx : context ) ( t : arith_expr array ) = + (create_expr ctx (Z3native.mk_add ctx#gno (Array.length t) (astaton t)) :> arith_expr) + + (** + Create an expression representing t[0] * t[1] * .... + *) + let mk_mul ( ctx : context ) ( t : arith_expr array ) = + (create_expr ctx (Z3native.mk_mul ctx#gno (Array.length t) (astaton t)) :> arith_expr) + + (** + Create an expression representing t[0] - t[1] - .... + *) + let mk_sub ( ctx : context ) ( t : arith_expr array ) = + (create_expr ctx (Z3native.mk_sub ctx#gno (Array.length t) (astaton t)) :> arith_expr) + + (** + Create an expression representing -t. + *) + let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = + (create_expr ctx (Z3native.mk_unary_minus ctx#gno t#gno) :> arith_expr) + + (** + Create an expression representing t1 / t2. + *) + let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + (create_expr ctx (Z3native.mk_div ctx#gno t1#gno t2#gno) :> arith_expr) + + (** + Create an expression representing t1 mod t2. + The arguments must have int type. + *) + let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new int_expr ctx)#cnstr_obj (Z3native.mk_mod ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 rem t2. + The arguments must have int type. + *) + let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new int_expr ctx)#cnstr_obj (Z3native.mk_rem ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 ^ t2. + *) + let mk_Power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (create_expr ctx (Z3native.mk_power ctx#gno t1#gno t2#gno) :> arith_expr) + + (** + Create an expression representing t1 < t2 + *) + let mk_lt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_lt ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 <= t2 + *) + let mk_le ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_le ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 > t2 + *) + let mk_gt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_gt ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 >= t2 + *) + let mk_ge ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_ge ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_int2real ( ctx : context ) ( t : int_expr ) = + (new real_expr ctx)#cnstr_obj (Z3native.mk_int2real ctx#gno t#gno) + + (** + 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. + *) + let mk_real2int ( ctx : context ) ( t : real_expr ) = + (new int_expr ctx)#cnstr_obj (Z3native.mk_real2int ctx#gno t#gno) + + (** + Creates an expression that checks whether a real number is an integer. + *) + let mk_is_integer ( ctx : context ) ( t : real_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_is_int ctx#gno t#gno) + + (** + Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + @param precision the precision of the result + @return A numeral Expr of sort Real + *) + let to_upper ( x : algebraic_num ) ( precision : int ) = + (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) + + (** + Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + @param precision the precision of the result + @return A numeral Expr of sort Real + *) + let to_lower ( x : algebraic_num ) precision = + (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : algebraic_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno +end + + +(** Functions to manipulate bit-vector expressions *) +module BitVectors = +struct + (** + Create a new bit-vector sort. + *) + let mk_sort ( ctx : context ) size = + (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort ctx#gno size) (** Indicates whether the terms is of bit-vector sort. @@ -1747,300 +2662,750 @@ struct (** Indicates whether the term is a bit-vector numeral *) - let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNUM) + let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) (** Indicates whether the term is a one-bit bit-vector with value one *) - let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BIT1) + let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) (** Indicates whether the term is a one-bit bit-vector with value zero *) - let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BIT0) + let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) (** Indicates whether the term is a bit-vector unary minus *) - let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNEG) + let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) (** Indicates whether the term is a bit-vector addition (binary) *) - let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BADD) + let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) (** Indicates whether the term is a bit-vector subtraction (binary) *) - let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSUB) + let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) (** Indicates whether the term is a bit-vector multiplication (binary) *) - let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BMUL) + let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) (** Indicates whether the term is a bit-vector signed division (binary) *) - let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSDIV) + let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) (** Indicates whether the term is a bit-vector unsigned division (binary) *) - let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUDIV) + let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) (** Indicates whether the term is a bit-vector signed remainder (binary) *) - let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSREM) + let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUREM) + let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) (** Indicates whether the term is a bit-vector signed modulus *) - let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSMOD) + let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) (** Indicates whether the term is a bit-vector signed division by zero *) - let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSDIV0) + let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) (** Indicates whether the term is a bit-vector unsigned division by zero *) - let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUDIV0) + let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) (** Indicates whether the term is a bit-vector signed remainder by zero *) - let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSREM0) + let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUREM0) + let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) (** Indicates whether the term is a bit-vector signed modulus by zero *) - let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSMOD0) + let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ULEQ) + let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SLEQ) + let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UGEQ) + let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SGEQ) + let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) (** Indicates whether the term is an unsigned bit-vector less-than *) - let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ULT) + let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) (** Indicates whether the term is a signed bit-vector less-than *) - let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SLT) + let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) (** Indicates whether the term is an unsigned bit-vector greater-than *) - let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UGT) + let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) (** Indicates whether the term is a signed bit-vector greater-than *) - let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SGT) + let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) (** Indicates whether the term is a bit-wise AND *) - let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BAND) + let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) (** Indicates whether the term is a bit-wise OR *) - let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BOR) + let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) (** Indicates whether the term is a bit-wise NOT *) - let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNOT) + let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) (** Indicates whether the term is a bit-wise XOR *) - let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BXOR) + let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) (** Indicates whether the term is a bit-wise NAND *) - let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNAND) + let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) (** Indicates whether the term is a bit-wise NOR *) - let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNOR) + let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) (** Indicates whether the term is a bit-wise XNOR *) - let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BXNOR) + let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) (** Indicates whether the term is a bit-vector concatenation (binary) *) - let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CONCAT) + let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) (** Indicates whether the term is a bit-vector sign extension *) - let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SIGN_EXT) + let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) (** Indicates whether the term is a bit-vector zero extension *) - let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ZERO_EXT) + let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) (** Indicates whether the term is a bit-vector extraction *) - let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EXTRACT) + let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) (** Indicates whether the term is a bit-vector repetition *) - let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_REPEAT) + let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) (** Indicates whether the term is a bit-vector reduce OR *) - let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BREDOR) + let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) (** Indicates whether the term is a bit-vector reduce AND *) - let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BREDAND) + let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) (** Indicates whether the term is a bit-vector comparison *) - let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BCOMP) + let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) (** Indicates whether the term is a bit-vector shift left *) - let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSHL) + let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) (** Indicates whether the term is a bit-vector logical shift right *) - let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) (** Indicates whether the term is a bit-vector arithmetic shift left *) - let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BASHR) + let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) (** Indicates whether the term is a bit-vector rotate left *) - let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) (** Indicates whether the term is a bit-vector rotate right *) - let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + Similar to Z3_OP_ROTATE_LEFT, but it is a binary operator instead of a parametric one. *) - let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + Similar to Z3_OP_ROTATE_RIGHT, but it is a binary operator instead of a parametric one. *) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + rudimentary simplification rules are applied to this function. *) - let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_INT2BV) + let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + rudimentary simplification rules are applied to this function. *) - let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BV2INT) + let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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))) + equivalence (carry l1 l2 l3) <=> (or (and l1 l2) (and l1 l3) (and l2 l3))) *) - let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CARRY) + let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) + The meaning is given by the equivalence (xor3 l1 l2 l3) <=> (xor (xor l1 l2) l3) *) - let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR3) + let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + + (** The size of a bit-vector sort. *) + let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno + + (** Retrieve the int value. *) + let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if lbool_of_int(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno (** - 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. + Creates a bit-vector constant. *) - let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) + let mk_const ( ctx : context ) ( name : symbol ) ( size : int ) = + ((Expr.mk_const ctx name (mk_sort ctx size)) :> bitvec_expr) (** - 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. - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) + Creates a bit-vector constant. *) + let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = + mk_const ctx ((Symbol.mk_string ctx name) :> symbol) size (** - 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. + Bitwise negation. + The argument must have a bit-vector sort. *) - let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) + let mk_not ( ctx : context ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnot ctx#gno t#gno) + (** + Take conjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. + *) + let mk_redand ( ctx : context ) ( t : bitvec_expr) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredand ctx#gno t#gno) + + (** + Take disjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. + *) + let mk_redor ( ctx : context ) ( t : bitvec_expr) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredor ctx#gno t#gno) + + (** + Bitwise conjunction. + The arguments must have a bit-vector sort. + *) + let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvand ctx#gno t1#gno t2#gno) + + (** + Bitwise disjunction. + The arguments must have a bit-vector sort. + *) + let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvor ctx#gno t1#gno t2#gno) + + (** + Bitwise XOR. + The arguments must have a bit-vector sort. + *) + let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxor ctx#gno t1#gno t2#gno) + + (** + Bitwise NAND. + The arguments must have a bit-vector sort. + *) + let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnand ctx#gno t1#gno t2#gno) + + (** + Bitwise NOR. + The arguments must have a bit-vector sort. + *) + let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnor ctx#gno t1#gno t2#gno) + + (** + Bitwise XNOR. + The arguments must have a bit-vector sort. + *) + let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxnor ctx#gno t1#gno t2#gno) + + (** + Standard two's complement unary minus. + The arguments must have a bit-vector sort. + *) + let mk_neg ( ctx : context ) ( t : bitvec_expr) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvneg ctx#gno t#gno) + + (** + Two's complement addition. + The arguments must have the same bit-vector sort. + *) + let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvadd ctx#gno t1#gno t2#gno) + + (** + Two's complement subtraction. + The arguments must have the same bit-vector sort. + *) + let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsub ctx#gno t1#gno t2#gno) + + (** + Two's complement multiplication. + The arguments must have the same bit-vector sort. + *) + let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvmul ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvudiv ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvurem ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsrem ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsmod ctx#gno t1#gno t2#gno) + + (** + Unsigned less-than + + The arguments must have the same bit-vector sort. + *) + let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvult ctx#gno t1#gno t2#gno) + + (** + Two's complement signed less-than + + The arguments must have the same bit-vector sort. + *) + let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvslt ctx#gno t1#gno t2#gno) + + (** + Unsigned less-than or equal to. + + The arguments must have the same bit-vector sort. + *) + let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvule ctx#gno t1#gno t2#gno) + + (** + Two's complement signed less-than or equal to. + + The arguments must have the same bit-vector sort. + *) + let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsle ctx#gno t1#gno t2#gno) + + (** + Unsigned greater than or equal to. + + The arguments must have the same bit-vector sort. + *) + let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvuge ctx#gno t1#gno t2#gno) + + (** + Two's complement signed greater than or equal to. + + The arguments must have the same bit-vector sort. + *) + let mk_SGE ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsge ctx#gno t1#gno t2#gno) + + (** + Unsigned greater-than. + + The arguments must have the same bit-vector sort. + *) + let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvugt ctx#gno t1#gno t2#gno) + + (** + Two's complement signed greater-than. + + The arguments must have the same bit-vector sort. + *) + let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsgt ctx#gno t1#gno t2#gno) + + (** + 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). + *) + let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_concat ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_extract ctx#gno high low t#gno) + + (** + 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. + *) + let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_sign_ext ctx#gno i t#gno) + + (** + 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. + *) + let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_zero_ext ctx#gno i t#gno) + + (** + Bit-vector repetition. + + The argument must have a bit-vector sort. + *) + let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_repeat ctx#gno i t#gno) + + (** + 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. + *) + let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvshl ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvlshr ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvashr ctx#gno t1#gno t2#gno) + + (** + Rotate Left. + + Rotate bits of \c t to the left \c i times. + The argument must have a bit-vector sort. + *) + let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_left ctx#gno i t#gno) + + (** + Rotate Right. + + Rotate bits of \c t to the right \c i times. + The argument must have a bit-vector sort. + *) + let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_right ctx#gno i t#gno) + + (** + Rotate Left. + + Rotate bits of to the left times. + The arguments must have the same bit-vector sort. + *) + let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_left ctx#gno t1#gno t2#gno) + + (** + Rotate Right. + + + Rotate bits of to the right times. + The arguments must have the same bit-vector sort. + *) + let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_right ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_int2bv ctx#gno n t#gno) + + (** + 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. + *) + let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = + (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int ctx#gno t#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + + (** + Create a predicate that checks that the bit-wise addition does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + + (** + Create a predicate that checks that the bit-wise addition does not underflow. + + The arguments must be of bit-vector sort. + *) + let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_underflow ctx#gno t1#gno t2#gno) + + (** + Create a predicate that checks that the bit-wise subtraction does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_overflow ctx#gno t1#gno t2#gno) + + (** + Create a predicate that checks that the bit-wise subtraction does not underflow. + + The arguments must be of bit-vector sort. + *) + let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + + (** + Create a predicate that checks that the bit-wise signed division does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv_no_overflow ctx#gno t1#gno t2#gno) + + (** + Create a predicate that checks that the bit-wise negation does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvneg_no_overflow ctx#gno t#gno) + + (** + Create a predicate that checks that the bit-wise multiplication does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + + (** + Create a predicate that checks that the bit-wise multiplication does not underflow. + + The arguments must be of bit-vector sort. + *) + let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow ctx#gno t1#gno t2#gno) + +end + +(** Functions to manipulate Proof objects *) +module Proofs = +struct (** Indicates whether the term is a Proof for the expression 'true'. *) - let is_proof_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TRUE) + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) (** Indicates whether the term is a proof for a fact asserted by the user. *) - let is_proof_asserted ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_ASSERTED) + let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - let is_proof_goal ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_GOAL) + let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) (** Indicates whether the term is proof via modus ponens @@ -2049,18 +3414,18 @@ struct T1: p T2: (implies p q) [mp T1 T2]: q - The second antecedents may also be a proof for (iff p q). + The second antecedents may also be a proof for (iff p q). *) - let is_proof_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_MODUS_PONENS) + let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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'. + That is, R is either '~', '=' or 'iff'. *) - let is_proof_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_REFLEXIVITY) + let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) (** Indicates whether the term is proof by symmetricity of a relation @@ -2069,9 +3434,8 @@ struct T1: (R t s) [symmetry T1]: (R s t) T1 is the antecedent of this proof object. - *) - let is_proof_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_SYMMETRY) + let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) (** Indicates whether the term is a proof by transitivity of a relation @@ -2081,9 +3445,8 @@ struct T1: (R t s) T2: (R s u) [trans T1 T2]: (R t u) - *) - let is_proof_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TRANSITIVITY) + let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) (** Indicates whether the term is a proof by condensed transitivity of a relation @@ -2102,9 +3465,8 @@ struct 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. - *) - let is_proof_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) (** @@ -2116,9 +3478,8 @@ struct [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. - *) - let is_proof_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_MONOTONICITY) + let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) (** Indicates whether the term is a quant-intro proof @@ -2126,9 +3487,8 @@ struct 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)) - *) - let is_proof_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_QUANT_INTRO) + let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) (** Indicates whether the term is a distributivity proof object. @@ -2144,9 +3504,8 @@ struct This proof object has no antecedents. Remark. This rule is used by the CNF conversion pass and instantiated by f = or, and g = and. - *) - let is_proof_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) (** Indicates whether the term is a proof by elimination of AND @@ -2154,9 +3513,8 @@ struct 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 - *) - let is_proof_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_AND_ELIM) + let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) (** Indicates whether the term is a proof by eliminiation of not-or @@ -2164,9 +3522,8 @@ struct 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) - *) - let is_proof_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) (** Indicates whether the term is a proof by rewriting @@ -2183,9 +3540,8 @@ struct (= (+ ( x : expr ) 0) x) (= (+ ( x : expr ) 1 2) (+ 3 x)) (iff (or ( x : expr ) false) x) - *) - let is_proof_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_REWRITE) + let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) (** Indicates whether the term is a proof by rewriting @@ -2199,17 +3555,15 @@ struct - 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) - *) - let is_proof_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_REWRITE_STAR) + let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) - let is_proof_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) (** Indicates whether the term is a proof for pulling quantifiers out. @@ -2217,9 +3571,8 @@ struct 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 - *) - let is_proof_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) (** Indicates whether the term is a proof for pushing quantifiers in. @@ -2230,9 +3583,9 @@ struct ... (forall (x_1 ... x_m) p_n[x_1 ... x_m]))) This proof object has no antecedents - *) - let is_proof_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_PUSH_QUANT) + + let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) (** Indicates whether the term is a proof for elimination of unused variables. @@ -2242,9 +3595,9 @@ struct It is used to justify the elimination of unused variables. This proof object has no antecedents. - *) - let is_proof_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + + let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) (** Indicates whether the term is a proof for destructive equality resolution @@ -2256,23 +3609,22 @@ struct This proof object has no antecedents. Several variables can be eliminated simultaneously. - *) - let is_proof_der ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DER) + + let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) (** Indicates whether the term is a proof for quantifier instantiation A proof of (or (not (forall (x) (P x))) (P a)) - *) - let is_proof_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_QUANT_INST) + let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) (** Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. + Mark a hypothesis in a natural deduction style proof. *) - let is_proof_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_HYPOTHESIS) + let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) (** Indicates whether the term is a proof by lemma @@ -2283,9 +3635,8 @@ struct 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. - *) - let is_proof_lemma ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_LEMMA) + let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) (** Indicates whether the term is a proof by unit resolution @@ -2295,27 +3646,24 @@ struct ... T(n+1): (not l_n) [unit-resolution T1 ... T(n+1)]: (or l_1' ... l_m') - *) - let is_proof_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) (** Indicates whether the term is a proof by iff-true T1: p [iff-true T1]: (iff p true) - *) - let is_proof_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) (** Indicates whether the term is a proof by iff-false T1: (not p) [iff-false T1]: (iff p false) - *) - let is_proof_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_IFF_FALSE) + let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) (** Indicates whether the term is a proof by commutativity @@ -2326,9 +3674,8 @@ struct This proof object has no antecedents. Remark: if f is bool, then = is iff. - *) - let is_proof_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) (** Indicates whether the term is a proof for Tseitin-like axioms @@ -2362,9 +3709,8 @@ struct You can recover the propositional tautologies by unfolding the Boolean connectives in the axioms a small bounded number of steps (=3). - *) - let is_proof_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) (** Indicates whether the term is a proof for introduction of a name @@ -2385,9 +3731,8 @@ struct Otherwise: [def-intro]: (= n e) - *) - let is_proof_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DEF_INTRO) + let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) (** Indicates whether the term is a proof for application of a definition @@ -2395,18 +3740,16 @@ struct [apply-def T1]: F ~ n F is 'equivalent' to n, given that T1 is a proof that n is a name for F. - *) - let is_proof_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_APPLY_DEF) + let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) (** Indicates whether the term is a proof iff-oeq T1: (iff p q) [iff~ T1]: (~ p q) - *) - let is_proof_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_IFF_OEQ) + let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) (** Indicates whether the term is a proof for a positive NNF step @@ -2432,9 +3775,8 @@ struct for NNF_POS are 'implies', 'iff', 'xor', 'ite'. NNF_NEG furthermore handles the case where negation is pushed over Boolean connectives 'and' and 'or'. - *) - let is_proof_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) (** Indicates whether the term is a proof for a negative NNF step @@ -2457,9 +3799,8 @@ struct 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'))) - *) - let is_proof_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) (** Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form. @@ -2469,9 +3810,8 @@ struct 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. - *) - let is_proof_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_NNF_STAR) + let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) (** Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form. @@ -2479,9 +3819,8 @@ struct 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. - *) - let is_proof_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_CNF_STAR) + let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) (** Indicates whether the term is a proof for a Skolemization step @@ -2492,9 +3831,8 @@ struct [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) This proof object has no antecedents. - *) - let is_proof_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_SKOLEMIZE) + let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) (** Indicates whether the term is a proof by modus ponens for equi-satisfiability. @@ -2503,9 +3841,8 @@ struct T1: p T2: (~ p q) [mp~ T1 T2]: q - *) - let is_proof_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) (** Indicates whether the term is a proof for theory lemma @@ -2520,259 +3857,74 @@ struct - 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))) + (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. - *) - let is_proof_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TH_LEMMA) - - (** - Indicates whether the term is of a relation sort. - *) - let is_Relation ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == 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. - - *) - let is_relation_store ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_STORE) - - (** - Indicates whether the term is an empty relation - *) - let is_empty_relation ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_EMPTY) - - (** - Indicates whether the term is a test for the emptiness of a relation - *) - let is_is_empty_relation ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_IS_EMPTY) - - (** - Indicates whether the term is a relational join - *) - let is_relational_join ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_JOIN) - - (** - Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. - *) - let is_relation_union ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_UNION) - - (** - Indicates whether the term is the widening of two relations - The function takes two arguments. - *) - let is_relation_widen ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_WIDEN) - - (** - Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. - *) - let is_relation_project ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - - *) - let is_relation_filter ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. - - *) - let is_relation_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - - *) - let is_relation_rename ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_RENAME) - - (** - Indicates whether the term is the complement of a relation - *) - let is_relation_complement ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - - *) - let is_relation_select ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - - *) - let is_relation_clone ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_CLONE) - - (** - Indicates whether the term is of an array sort. - *) - let is_finite_domain ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) - - (** - Indicates whether the term is a less than predicate over a finite domain. - *) - let is_finite_domain_lt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) appears, the higher is its - index. - - *) - let get_index ( x : expr ) = - if not (AST.is_var x) then - raise (Z3native.Exception "Term is not a bound variable.") - else - Z3native.get_index_value x#gnc x#gno + let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end -(** Integer Numerals *) -module IntNum = -struct - (** Retrieve the int value. *) - let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") +(** + Parameter sets (of Solvers, Tactics, ...) - (** Returns a string representation of the numeral. *) - let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno -end - -(** Rational Numerals *) -module RatNum = -struct - - (** The numerator of a rational numeral. *) - let get_numerator ( x : rat_num ) = - (new int_num x#gc)#cnstr_obj (Z3native.get_numerator x#gnc x#gno) - - (** The denominator of a rational numeral. *) - let get_denominator ( x : rat_num ) = - (new int_num x#gc)#cnstr_obj (Z3native.get_denominator x#gnc x#gno) - - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) - let to_decimal_string ( x : rat_num ) (precision : int) = - Z3native.get_numeral_decimal_string x#gnc x#gno precision - - (** Returns a string representation of the numeral. *) - let to_string ( x : rat_num ) = Z3native.get_numeral_string x#gnc x#gno -end - -(** Bit-vector numerals *) -module BitVecNum = -struct - (** Retrieve the int value. *) - let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") - - (** Returns a string representation of the numeral. *) - let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno -end - -(** Algebraic numbers *) -module AlgebraicNum = + A Params objects represents a configuration in the form of symbol/value pairs. +*) +module Params = struct (** - Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real + Adds a parameter setting. *) - let to_upper ( x : algebraic_num ) ( precision : int ) = - (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) - - (** - Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) - let to_lower ( x : algebraic_num ) precision = - (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) + let add_bool (p : params) (name : symbol) (value : bool) = + Z3native.params_set_bool p#gnc p#gno name#gno (int_of_lbool (if value then L_TRUE else L_FALSE)) - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) - let to_decimal_string ( x : algebraic_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string x#gnc x#gno precision + (** + Adds a parameter setting. + *) + let add_int (p : params) (name : symbol) (value : int) = + Z3native.params_set_uint p#gnc p#gno name#gno value - (** Returns a string representation of the numeral. *) - let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno + (** + Adds a parameter setting. + *) + let add_double (p : params) (name : symbol) (value : float) = + Z3native.params_set_double p#gnc p#gno name#gno value + + (** + Adds a parameter setting. + *) + let add_symbol (p : params) (name : symbol) (value : symbol) = + Z3native.params_set_symbol p#gnc p#gno name#gno value#gno + + (** + Adds a parameter setting. + *) + let add_s_bool (p : params) (name : string) (value : bool) = + add_bool p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_int (p : params) (name : string) (value : int) = + add_int p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_double (p : params) (name : string) (value : float) = + add_double p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_symbol (p : params) (name : string) (value : symbol) = + add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + A string representation of the parameter set. + *) + let to_string (p : params) = Z3native.params_to_string p#gnc p#gno end -(** Constructors are used for datatype sorts *) -module Constructor = -struct - (** The number of fields of the constructor. *) - let get_num_fields ( x : constructor ) = x#get_n - - (** The function declaration of the constructor. *) - let get_constructor_decl ( x : constructor ) = x#constructor_decl - - (** The function declaration of the tester. *) - let get_tester_decl ( x : constructor ) = x#tester_decl - - (** The function declarations of the accessors *) - let get_accessor_decls ( x : constructor ) = x#accessor_decls -end - - -(** ParamDescrs describe sets of parameters.*) +(** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) module ParamDescrs = struct @@ -2917,102 +4069,100 @@ struct | None -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply x#gnc x#gno g#gno) | Some (pn) -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno) - (** Creates a solver that is implemented using the given tactic. + (** creates a solver that is implemented using the given tactic. *) let get_solver ( x : tactic ) = (new solver x#gc)#cnstr_obj (Z3native.mk_solver_from_tactic x#gnc x#gno) end - -(** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. -*) -module FuncInterp = -struct - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. - *) - module FuncEntry = - struct - (** - Return the (symbolic) value of this entry. - *) - let get_value ( x : func_entry ) = - create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) - - (** - The number of arguments of the entry. - *) - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno - - (** - The arguments of the function entry. - *) - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in - Array.init n f - - (** - A string representation of the function entry. - *) - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]]") - end - - (** - The number of entries in the function interpretation. - *) - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno - - (** - The entries in the function interpretation - *) - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in - Array.init n f - - (** - The (symbolic) `else' value of the function interpretation. - *) - let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) - - (** - The arity of the function interpretation - *) - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno - - (** - A string representation of the function interpretation. - *) - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (Array.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") -end - -(** Models. +(** Models A Model contains interpretations (assignments) of constants and functions. *) module Model = struct - + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. + *) + module FuncInterp = + struct + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. + *) + module FuncEntry = + struct + (** + Return the (symbolic) value of this entry. + *) + let get_value ( x : func_entry ) = + create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + + (** + The number of arguments of the entry. + *) + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + + (** + The arguments of the function entry. + *) + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the function entry. + *) + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]]") + end + + (** + The number of entries in the function interpretation. + *) + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + + (** + The entries in the function interpretation + *) + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + Array.init n f + + (** + The (symbolic) `else' value of the function interpretation. + *) + let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + + (** + The arity of the function interpretation + *) + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + + (** + A string representation of the function interpretation. + *) + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (Array.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + end + (** Retrieves the interpretation (the assignment) of in the model. A function declaration of zero arity An expression if the function has an interpretation in the model, null otherwise. *) @@ -3093,7 +4243,7 @@ struct 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 @@ -3120,7 +4270,6 @@ struct 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. - *) @@ -3137,8 +4286,8 @@ struct *) let sort_universe ( x : model ) ( s : sort ) = let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in - let n = (ASTVector.get_size n_univ) in - let f i = (ASTVector.get n_univ i) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in Array.init n f (** Conversion of models to strings. @@ -3174,84 +4323,85 @@ struct let to_string ( x : apply_result) = Z3native.apply_result_to_string x#gnc x#gno end -(** Objects that track statistical information about solvers. *) -module Statistics = -struct - - (** - Statistical data is organized into pairs of [Key, Entry], where every - Entry is either a DoubleEntry or a UIntEntry - *) - module Entry = - struct - (** The key of the entry. *) - let get_key (x : statistics_entry) = x#key - - (** The int-value of the entry. *) - let get_int (x : statistics_entry) = x#int - - (** The float-value of the entry. *) - let get_float (x : statistics_entry) = x#float - - (** True if the entry is uint-valued. *) - let is_int (x : statistics_entry) = x#is_int - - (** True if the entry is double-valued. *) - let is_float (x : statistics_entry) = x#is_float - - (** The string representation of the the entry's value. *) - let to_string_value (x : statistics_entry) = - if (is_int x) then - string_of_int (get_int x) - else if (is_float x) then - string_of_float (get_float x) - else - raise (Z3native.Exception "Unknown statistical entry type") - - (** The string representation of the entry (key and value) *) - let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) - end - - (** A string representation of the statistical data. *) - let to_string ( x : statistics ) = Z3native.stats_to_string x#gnc x#gno - - (** The number of statistical data. *) - let get_size ( x : statistics ) = Z3native.stats_size x#gnc x#gno - - (** The data entries. *) - let get_entries ( x : statistics ) = - let n = (get_size x ) in - let f i = ( - let k = Z3native.stats_get_key x#gnc x#gno i in - if (lbool_of_int (Z3native.stats_is_uint x#gnc x#gno i)) == L_TRUE then - ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) - else - ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) - ) in - Array.init n f - - (** - The statistical counters. - *) - let get_keys ( x : statistics ) = - let n = (get_size x) in - let f i = (Z3native.stats_get_key x#gnc x#gno i) in - Array.init n f - - (** - The value of a particular statistical counter. - *) - let get ( x : statistics ) ( key : string ) = - let f p c = (if (Entry.get_key c) = key then (Some c) else p) in - Array.fold_left f None (get_entries x) - -end - (** Solvers *) module Solver = struct type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + (** Objects that track statistical information about solvers. *) + module Statistics = + struct + + (** + Statistical data is organized into pairs of [Key, Entry], where every + Entry is either a DoubleEntry or a UIntEntry + *) + module Entry = + struct + (** The key of the entry. *) + let get_key (x : statistics_entry) = x#key + + (** The int-value of the entry. *) + let get_int (x : statistics_entry) = x#int + + (** The float-value of the entry. *) + let get_float (x : statistics_entry) = x#float + + (** True if the entry is uint-valued. *) + let is_int (x : statistics_entry) = x#is_int + + (** True if the entry is double-valued. *) + let is_float (x : statistics_entry) = x#is_float + + (** The string representation of the the entry's value. *) + let to_string_value (x : statistics_entry) = + if (is_int x) then + string_of_int (get_int x) + else if (is_float x) then + string_of_float (get_float x) + else + raise (Z3native.Exception "Unknown statistical entry type") + + (** The string representation of the entry (key and value) *) + let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) + end + + (** A string representation of the statistical data. *) + let to_string ( x : statistics ) = Z3native.stats_to_string x#gnc x#gno + + (** The number of statistical data. *) + let get_size ( x : statistics ) = Z3native.stats_size x#gnc x#gno + + (** The data entries. *) + let get_entries ( x : statistics ) = + let n = (get_size x ) in + let f i = ( + let k = Z3native.stats_get_key x#gnc x#gno i in + if (lbool_of_int (Z3native.stats_is_uint x#gnc x#gno i)) == L_TRUE then + ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) + else + ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) + ) in + Array.init n f + + (** + The statistical counters. + *) + let get_keys ( x : statistics ) = + let n = (get_size x) in + let f i = (Z3native.stats_get_key x#gnc x#gno i) in + Array.init n f + + (** + The value of a particular statistical counter. + *) + let get ( x : statistics ) ( key : string ) = + let f p c = (if (Entry.get_key c) = key then (Some c) else p) in + Array.fold_left f None (get_entries x) + + end + + (** A string that describes all available solver parameters. *) @@ -3284,14 +4434,14 @@ struct (** Backtracks backtracking points. - Note that an exception is thrown if is not smaller than NumScopes + Note that an exception is thrown if is not smaller than NumScopes *) let pop ( x : solver ) ( n : int ) = Z3native.solver_pop x#gnc x#gno n (** Resets the Solver. - This removes all assertions from the solver. + This removes all assertions from the solver. *) let reset ( x : solver ) = Z3native.solver_reset x#gnc x#gno @@ -3307,7 +4457,7 @@ struct *) let get_num_assertions ( x : solver ) = let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in - (ASTVector.get_size a) + (AST.ASTVector.get_size a) (** @@ -3315,8 +4465,8 @@ struct *) let get_assertions ( x : solver ) = let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in - let n = (ASTVector.get_size a) in - let f i = ((new bool_expr x#gc)#cnstr_obj (ASTVector.get a i)#gno) in + let n = (AST.ASTVector.get_size a) in + let f i = ((new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get a i)#gno) in Array.init n f (** @@ -3325,7 +4475,6 @@ struct - *) let check ( x : solver ) ( assumptions : bool_expr array option) = let r = @@ -3343,7 +4492,6 @@ struct The result is None if Check was not invoked before, if its results was not SATISFIABLE, or if model production is not enabled. - *) let get_model ( x : solver ) = let q = Z3native.solver_get_model x#gnc x#gno in @@ -3357,7 +4505,6 @@ struct The result is null if Check was not invoked before, if its results was not UNSATISFIABLE, or if proof production is disabled. - *) let get_proof ( x : solver ) = let q = Z3native.solver_get_proof x#gnc x#gno in @@ -3372,12 +4519,11 @@ struct 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. - *) let get_unsat_core ( x : solver ) = let cn = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_unsat_core x#gnc x#gno) in - let n = (ASTVector.get_size cn) in - let f i = (ASTVector.get cn i) in + let n = (AST.ASTVector.get_size cn) in + let f i = (AST.ASTVector.get cn i) in Array.init n f (** @@ -3418,3312 +4564,936 @@ struct end -(** The main interaction with Z3 happens via the Context module *) -module Context = -struct +(* STUFF FROM THE CONTEXT *) - (* SYMBOLS *) - - (** - Creates a new symbol using an integer. - - Not all integers can be passed to this function. - The legal range of unsigned integers is 0 to 2^30-1. - *) - let mk_symbol_int ( ctx : context ) i = - (new int_symbol ctx)#cnstr_int i - - (** Creates a new symbol using a string. *) - let mk_symbol_string ( ctx : context ) s = - (new string_symbol ctx)#cnstr_string s - - (** - Create an array of symbols. - *) - let mk_symbols_int ( ctx : context ) names = - let f elem = mk_symbol_int ( ctx : context ) elem in - (Array.map f names) - - (** - Create an array of symbols. - *) - let mk_symbols_string ( ctx : context ) names = - let f elem = mk_symbol_string ( ctx : context ) elem in - (Array.map f names) - - - (* SORTS *) - - (** - Create a new Boolean sort. - *) - let mk_bool_sort ( ctx : context ) = - (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort ctx#gno) - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted_sort ( ctx : context ) (s : symbol) = - (new uninterpreted_sort ctx)#cnstr_s s - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted_sort_s ( ctx : context ) (s : string) = - mk_uninterpreted_sort ctx ((mk_symbol_string ( ctx : context ) s) :> symbol) - - (** - Create a new integer sort. - *) - let mk_int_sort ( ctx : context ) = - (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort ctx#gno) - - (** - Create a real sort. - *) - let mk_real_sort ( ctx : context ) = - (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort ctx#gno) - - (** - Create a new bit-vector sort. - *) - let mk_bitvec_sort ( ctx : context ) size = - (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort ctx#gno size) - - (** - Create a new array sort. - *) - let mk_array_sort ( ctx : context ) domain range = - (new array_sort ctx)#cnstr_dr domain range - - (** - Create a new tuple sort. - *) - let mk_tuple_sort ( ctx : context ) name field_names field_sorts = - (new tuple_sort ctx)#cnstr_siss name (Array.length field_names) field_names field_sorts - - (** - Create a new enumeration sort. - *) - let mk_enum_sort ( ctx : context ) name enum_names = - (new enum_sort ctx)#cnstr_ss name enum_names - - (** - Create a new enumeration sort. - *) - let mk_enum_sort_s ( ctx : context ) name enum_names = - (new enum_sort ctx)#cnstr_ss - ((mk_symbol_string ( ctx : context ) name) :> symbol) - (let f e = (e :> symbol) in - (Array.map f (mk_symbols_string ( ctx : context ) enum_names)) - ) - - (** - Create a new list sort. - *) - let mk_list_sort ( ctx : context ) (name : symbol) elem_sort = - (new list_sort ctx)#cnstr_ss name elem_sort - - (** - Create a new list sort. - *) - let mk_list_sort_s ( ctx : context ) (name : string) elem_sort = - mk_list_sort ctx ((mk_symbol_string ctx name) :> symbol) elem_sort - - - (** - Create a new finite domain sort. - *) - let mk_finite_domain_sort ( ctx : context ) ( name : symbol ) size = - (new finite_domain_sort ctx)#cnstr_si name size - - (** - Create a new finite domain sort. - *) - let mk_finite_domain_sort_s ( ctx : context ) ( name : string ) size = - (new finite_domain_sort ctx)#cnstr_si ((mk_symbol_string ctx name) :> symbol) size - - (* DATATYPES *) - (** - Create a datatype constructor. - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - *) - let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = - (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs - - - (** - Create a datatype constructor. - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = - mk_constructor ctx ((mk_symbol_string ctx name) :> symbol) recognizer field_names sorts sort_refs - - - (** - Create a new datatype sort. - *) - let mk_datatype_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = - (new datatype_sort ctx)#cnstr_sc name constructors - - (** - Create a new datatype sort. - *) - let mk_datatype_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = - mk_datatype_sort ctx ((mk_symbol_string ctx name) :> symbol) constructors - - (** - Create mutually recursive datatypes. - @param names names of datatype sorts - @param c list of constructors, one list per sort. - *) - let mk_datatype_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = - let n = (Array.length names) in - let f e = ( (new constructor_list ctx)#cnstr_ca e ) in - let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes ctx#gno n (symbolaton names) (constructor_listaton cla)) in - let g e = ( (new datatype_sort ctx)#cnstr_obj e) in - (Array.map g r) - - (** Create mutually recursive data-types. *) - let mk_datatype_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = - mk_datatype_sorts ctx - ( - let f e = ((mk_symbol_string ctx e) :> symbol) in - Array.map f names - ) - c - -(** - - -(* FUNCTION DECLARATIONS *) -(** - Creates a new function declaration. -*) - public Func_Decl MkFunc_Decl(Symbol name, Sort[] domain, Sort range) - { - - - - - - CheckContextMatch(name); - CheckContextMatch(domain); - CheckContextMatch(range); - return new Func_Decl(this, name, domain, range); - } - -(** - Creates a new function declaration. -*) - public Func_Decl MkFunc_Decl(Symbol name, Sort domain, Sort range) - { - - - - - - CheckContextMatch(name); - CheckContextMatch(domain); - CheckContextMatch(range); - Sort[] q = new Sort[] { domain }; - return new Func_Decl(this, name, q, range); - } - -(** - Creates a new function declaration. -*) - public Func_Decl MkFunc_Decl(string name, Sort[] domain, Sort range) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(range); - return new Func_Decl(this, MkSymbol(name), domain, range); - } - -(** - Creates a new function declaration. -*) - public Func_Decl MkFunc_Decl(string name, Sort domain, Sort range) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(range); - Sort[] q = new Sort[] { domain }; - return new Func_Decl(this, MkSymbol(name), q, range); - } - -(** - Creates a fresh function declaration with a name prefixed with . -*) - - - let mk_Fresh_Func_Decl(string prefix, Sort[] domain, Sort range) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(range); - return new Func_Decl(this, prefix, domain, range); - } - -(** - Creates a new constant function declaration. -*) - let mk_Const_Decl(Symbol name, Sort range) - { - - - - - CheckContextMatch(name); - CheckContextMatch(range); - return new Func_Decl(this, name, null, range); - } - -(** - Creates a new constant function declaration. -*) - let mk_Const_Decl(string name, Sort range) - { - - - - CheckContextMatch(range); - return new Func_Decl(this, MkSymbol(name), null, range); - } - -(** - Creates a fresh constant function declaration with a name prefixed with . -*) - - - let mk_Fresh_ConstDecl(string prefix, Sort range) - { - - - - CheckContextMatch(range); - return new Func_Decl(this, prefix, null, range); - } - - -(* BOUND VARIABLES *) -(** - Creates a new bound variable. -*) - @param index The de-Bruijn index of the variable - @param ty The sort of the variable - public Expr MkBound(uint index, Sort ty) - { - - - - return Expr.Create(this, Z3native.mk_bound(nCtx, index, ty.x#gno)); - } - - -(* QUANTIFIER PATTERNS *) -(** - Create a quantifier pattern. -*) - public Pattern MkPattern(params 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, Z3native.mk_pattern(nCtx, (uint)terms.Length, termsNative)); - } - - -(* CONSTANTS *) -(** - Creates a new Constant of sort and named . -*) - public Expr MkConst(Symbol name, Sort range) - { - - - - - CheckContextMatch(name); - CheckContextMatch(range); - - return Expr.Create(this, Z3native.mk_const(nCtx, name.x#gno, range.x#gno)); - } - -(** - 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 . -*) - let mk_Fresh_Const(string prefix, Sort range) - { - - - - CheckContextMatch(range); - return Expr.Create(this, Z3native.mk_fresh_const(nCtx, prefix, range.x#gno)); - } - -(** - Creates a fresh constant from the Func_Decl . -*) - @param f A decl of a 0-arity function - public Expr MkConst(Func_Decl f) - { - - - - return MkApp(f); - } - -(** - Create a Boolean constant. -*) - let mk_Bool_Const(Symbol name) - { - - - - return (BoolExpr)MkConst(name, BoolSort); - } - -(** - Create a Boolean constant. -*) - let mk_Bool_Const(string name) - { - - - return (BoolExpr)MkConst(MkSymbol(name), BoolSort); - } - -(** - Creates an integer constant. -*) - let mk_Int_Const(Symbol name) - { - - - - return (IntExpr)MkConst(name, IntSort); - } - -(** - Creates an integer constant. -*) - let mk_Int_Const(string name) - { - - - - return (IntExpr)MkConst(name, IntSort); - } - -(** - Creates a real constant. -*) - let mk_Real_Const(Symbol name) - { - - - - return (RealExpr)MkConst(name, RealSort); - } - -(** - Creates a real constant. -*) - let mk_Real_Const(string name) - { - - - return (RealExpr)MkConst(name, RealSort); - } - -(** - Creates a bit-vector constant. -*) - let mk_B_VConst(Symbol name, uint size) - { - - - - return (BitVecExpr)MkConst(name, MkBitVecSort(size)); - } - -(** - Creates a bit-vector constant. -*) - let mk_B_VConst(string name, uint size) - { - - - return (BitVecExpr)MkConst(name, MkBitVecSort(size)); - } - - -(* TERMS *) -(** - Create a new function application. -*) - public Expr MkApp(Func_Decl f, params Expr[] args) - { - - - - - CheckContextMatch(f); - CheckContextMatch(args); - return Expr.Create(this, f, args); - } - -(* PROPOSITIONAL *) -(** - The true Term. -*) - public BoolExpr MkTrue ( ctx : context ) = - { - - - return new BoolExpr(this, Z3native.mk_true(nCtx)); - } - -(** - The false Term. -*) - public BoolExpr MkFalse ( ctx : context ) = - { - - - return new BoolExpr(this, Z3native.mk_false(nCtx)); - } - -(** - Creates a Boolean value. -*) - public BoolExpr MkBool(bool value) - { - - - return value ? MkTrue ( ctx : context ) = : MkFalse ( ctx : context ) =; - } - -(** - Creates the equality = . -*) - public BoolExpr MkEq(Expr x, Expr y) - { - - - - - CheckContextMatch(x); - CheckContextMatch(y); - return new BoolExpr(this, Z3native.mk_eq(nCtx, x.x#gno, y.x#gno)); - } - -(** - Creates a distinct term. -*) - public BoolExpr MkDistinct(params Expr[] args) - { - - - - - - CheckContextMatch(args); - return new BoolExpr(this, Z3native.mk_distinct(nCtx, (uint)args.Length, AST.ArrayToNative(args))); - } - -(** - Mk an expression representing not(a). -*) - public BoolExpr MkNot(BoolExpr a) - { - - - - CheckContextMatch(a); - return new BoolExpr(this, Z3native.mk_not(nCtx, a.x#gno)); - } - -(** - Create an expression representing an if-then-else: ite(t1, t2, t3). -*) - @param t1 An expression with Boolean sort - @param t2 An expression - @param t3 An expression with the same sort as - let mk_I_TE(BoolExpr t1, Expr t2, Expr t3) - { - - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - CheckContextMatch(t3); - return Expr.Create(this, Z3native.mk_ite(nCtx, t1.x#gno, t2.x#gno, t3.x#gno)); - } - -(** - Create an expression representing t1 iff t2. -*) - public BoolExpr MkIff(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_iff(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 -> t2. -*) - public BoolExpr MkImplies(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_implies(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 xor t2. -*) - public BoolExpr MkXor(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_xor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t[0] and t[1] and .... -*) - public BoolExpr MkAnd(params BoolExpr[] t) - { - - - - - CheckContextMatch(t); - return new BoolExpr(this, Z3native.mk_and(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - -(** - Create an expression representing t[0] or t[1] or .... -*) - public BoolExpr MkOr(params BoolExpr[] t) - { - - - - - CheckContextMatch(t); - return new BoolExpr(this, Z3native.mk_or(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - - -(* ARITHMETIC *) -(** - Create an expression representing t[0] + t[1] + .... -*) - public ArithExpr MkAdd(params ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Z3native.mk_add(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - -(** - Create an expression representing t[0] * t[1] * .... -*) - public ArithExpr MkMul(params ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Z3native.mk_mul(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - -(** - Create an expression representing t[0] - t[1] - .... -*) - public ArithExpr MkSub(params ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Z3native.mk_sub(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - -(** - Create an expression representing -t. -*) - let mk_Unary_Minus(ArithExpr t) - { - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Z3native.mk_unary_minus(nCtx, t.x#gno)); - } - -(** - Create an expression representing t1 / t2. -*) - public ArithExpr MkDiv(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return (ArithExpr)Expr.Create(this, Z3native.mk_div(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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, Z3native.mk_mod(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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, Z3native.mk_rem(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 ^ t2. -*) - public ArithExpr MkPower(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return (ArithExpr)Expr.Create(this, Z3native.mk_power(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 < t2 -*) - public BoolExpr MkLt(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_lt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 <= t2 -*) - public BoolExpr MkLe(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_le(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 > t2 -*) - public BoolExpr MkGt(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_gt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 >= t2 -*) - public BoolExpr MkGe(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_ge(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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, Z3native.mk_int2real(nCtx, t.x#gno)); - } - -(** - 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, Z3native.mk_real2int(nCtx, t.x#gno)); - } - -(** - Creates an expression that checks whether a real number is an integer. -*) - let mk_Is_Integer(RealExpr t) - { - - - - CheckContextMatch(t); - return new BoolExpr(this, Z3native.mk_is_int(nCtx, t.x#gno)); - } - - -(* BIT-VECTORS *) -(** - Bitwise negation. -*) - The argument must have a bit-vector sort. - let mk_B_VNot(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_bvnot(nCtx, t.x#gno)); - } - -(** - Take conjunction of bits in a vector, return vector of length 1. -*) - The argument must have a bit-vector sort. - let mk_B_VRedAND(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_bvredand(nCtx, t.x#gno)); - } - -(** - Take disjunction of bits in a vector, return vector of length 1. -*) - The argument must have a bit-vector sort. - let mk_B_VRedOR(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_bvredor(nCtx, t.x#gno)); - } - -(** - Bitwise conjunction. -*) - The arguments must have a bit-vector sort. - let mk_B_VAND(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvand(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise disjunction. -*) - The arguments must have a bit-vector sort. - let mk_B_VOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise XOR. -*) - The arguments must have a bit-vector sort. - let mk_B_VXOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvxor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise NAND. -*) - The arguments must have a bit-vector sort. - let mk_B_VNAND(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvnand(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise NOR. -*) - The arguments must have a bit-vector sort. - let mk_B_VNOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvnor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise XNOR. -*) - The arguments must have a bit-vector sort. - let mk_B_VXNOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvxnor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Standard two's complement unary minus. -*) - The arguments must have a bit-vector sort. - let mk_B_VNeg(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_bvneg(nCtx, t.x#gno)); - } - -(** - Two's complement addition. -*) - The arguments must have the same bit-vector sort. - let mk_B_VAdd(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvadd(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement subtraction. -*) - The arguments must have the same bit-vector sort. - let mk_B_VSub(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvsub(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement multiplication. -*) - The arguments must have the same bit-vector sort. - let mk_B_VMul(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvmul(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VUDiv(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvudiv(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VSDiv(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvsdiv(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VURem(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvurem(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VSRem(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvsrem(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VSMod(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvsmod(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Unsigned less-than -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VULT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvult(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement signed less-than -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VSLT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvslt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Unsigned less-than or equal to. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VULE(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvule(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement signed less-than or equal to. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VSLE(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsle(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Unsigned greater than or equal to. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VUGE(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvuge(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement signed greater than or equal to. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VSGE(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsge(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Unsigned greater-than. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VUGT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvugt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement signed greater-than. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VSGT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsgt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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, Z3native.mk_concat(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bit-vector extraction. -*) - - Extract the bits down to from a bitvector of - size m to yield a new bitvector of size n, where - n = high - low + 1. - The argument must have a bit-vector sort. - - public BitVecExpr MkExtract(uint high, uint low, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_extract(nCtx, high, low, t.x#gno)); - } - -(** - 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. - - let mk_Sign_Ext(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_sign_ext(nCtx, i, t.x#gno)); - } - -(** - 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. - - let mk_Zero_Ext(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_zero_ext(nCtx, i, t.x#gno)); - } - -(** - Bit-vector repetition. -*) - - The argument must have a bit-vector sort. - - public BitVecExpr MkRepeat(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_repeat(nCtx, i, t.x#gno)); - } - -(** - 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. - - let mk_B_VSHL(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvshl(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VLSHR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvlshr(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VASHR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvashr(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Rotate Left. -*) - - Rotate bits of \c t to the left \c i times. - The argument must have a bit-vector sort. - - let mk_B_VRotateLeft(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_rotate_left(nCtx, i, t.x#gno)); - } - -(** - Rotate Right. -*) - - Rotate bits of \c t to the right \c i times. - The argument must have a bit-vector sort. - - let mk_B_VRotateRight(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_rotate_right(nCtx, i, t.x#gno)); - } - -(** - Rotate Left. -*) - - Rotate bits of to the left times. - The arguments must have the same bit-vector sort. - - let mk_B_VRotateLeft(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_ext_rotate_left(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Rotate Right. -*) - - Rotate bits of to the right times. - The arguments must have the same bit-vector sort. - - let mk_B_VRotateRight(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_ext_rotate_right(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an bit bit-vector from the integer argument . -*) - - NB. This function is essentially treated as uninterpreted. - So you cannot expect Z3 to precisely reflect the semantics of this function - when solving constraints with this function. - - The argument must be of integer sort. - - public BitVecExpr MkInt2BV(uint n, IntExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_int2bv(nCtx, n, t.x#gno)); - } - -(** - 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. - - let mk_B_V2Int(BitVecExpr t, bool signed) - { - - - - CheckContextMatch(t); - return new IntExpr(this, Z3native.mk_bv2int(nCtx, t.x#gno, (signed) ? 1 : 0)); - } - -(** - Create a predicate that checks that the bit-wise addition does not overflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VAddNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvadd_no_overflow(nCtx, t1.x#gno, t2.x#gno, (isSigned) ? 1 : 0)); - } - -(** - Create a predicate that checks that the bit-wise addition does not underflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VAddNoUnderflow(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvadd_no_underflow(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create a predicate that checks that the bit-wise subtraction does not overflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VSubNoOverflow(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsub_no_overflow(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create a predicate that checks that the bit-wise subtraction does not underflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VSubNoUnderflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsub_no_underflow(nCtx, t1.x#gno, t2.x#gno, (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. - - let mk_B_VSDivNoOverflow(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsdiv_no_overflow(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create a predicate that checks that the bit-wise negation does not overflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VNegNoOverflow(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BoolExpr(this, Z3native.mk_bvneg_no_overflow(nCtx, t.x#gno)); - } - -(** - Create a predicate that checks that the bit-wise multiplication does not overflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VMulNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvmul_no_overflow(nCtx, t1.x#gno, t2.x#gno, (isSigned) ? 1 : 0)); - } - -(** - Create a predicate that checks that the bit-wise multiplication does not underflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VMulNoUnderflow(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvmul_no_underflow(nCtx, t1.x#gno, t2.x#gno)); - } - - -(* ARRAYS *) -(** - Create an array constant. -*) - let mk_Array_Const(Symbol name, Sort domain, Sort range) - { - - - - - - return (ArrayExpr)MkConst(name, MkArraySort(domain, range)); - } - -(** - Create an array constant. -*) - let mk_Array_Const(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, Z3native.mk_select(nCtx, a.x#gno, i.x#gno)); - } - -(** - 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, Z3native.mk_store(nCtx, a.x#gno, i.x#gno, v.x#gno)); - } - -(** - Create a constant array. -*) - - The resulting term is an array, such that a selecton an arbitrary index - produces the value v. - - - - let mk_Const_Array(Sort domain, Expr v) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(v); - return new ArrayExpr(this, Z3native.mk_const_array(nCtx, domain.x#gno, v.x#gno)); - } - -(** - 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(Func_Decl f, params ArrayExpr[] args) - { - - - - - CheckContextMatch(f); - CheckContextMatch(args); - return (ArrayExpr)Expr.Create(this, Z3native.mk_map(nCtx, f.x#gno, 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. - - let mk_Term_Array(ArrayExpr array) - { - - - - CheckContextMatch(array); - return Expr.Create(this, Z3native.mk_array_default(nCtx, array.x#gno)); - } - - -(* SETS *) -(** - Create a set type. -*) - let mk_Set_Sort(Sort ty) - { - - - - CheckContextMatch(ty); - return new SetSort(this, ty); - } - -(** - Create an empty set. -*) - let mk_Empty_Set(Sort domain) - { - - - - CheckContextMatch(domain); - return Expr.Create(this, Z3native.mk_empty_set(nCtx, domain.x#gno)); - } - -(** - Create the full set. -*) - let mk_Full_Set(Sort domain) - { - - - - CheckContextMatch(domain); - return Expr.Create(this, Z3native.mk_full_set(nCtx, domain.x#gno)); - } - -(** - Add an element to the set. -*) - let mk_Set_Add(Expr set, Expr element) - { - - - - - CheckContextMatch(set); - CheckContextMatch(element); - return Expr.Create(this, Z3native.mk_set_add(nCtx, set.x#gno, element.x#gno)); - } - - -(** - Remove an element from a set. -*) - let mk_Set_Del(Expr set, Expr element) - { - - - - - CheckContextMatch(set); - CheckContextMatch(element); - return Expr.Create(this, Z3native.mk_set_del(nCtx, set.x#gno, element.x#gno)); - } - -(** - Take the union of a list of sets. -*) - let mk_Set_Union(params Expr[] args) - { - - - - CheckContextMatch(args); - return Expr.Create(this, Z3native.mk_set_union(nCtx, (uint)args.Length, AST.ArrayToNative(args))); - } - -(** - Take the intersection of a list of sets. -*) - let mk_Set_Intersection(params Expr[] args) - { - - - - - CheckContextMatch(args); - return Expr.Create(this, Z3native.mk_set_intersect(nCtx, (uint)args.Length, AST.ArrayToNative(args))); - } - -(** - Take the difference between two sets. -*) - let mk_Set_Difference(Expr arg1, Expr arg2) - { - - - - - CheckContextMatch(arg1); - CheckContextMatch(arg2); - return Expr.Create(this, Z3native.mk_set_difference(nCtx, arg1.x#gno, arg2.x#gno)); - } - -(** - Take the complement of a set. -*) - let mk_Set_Complement(Expr arg) - { - - - - CheckContextMatch(arg); - return Expr.Create(this, Z3native.mk_set_complement(nCtx, arg.x#gno)); - } - -(** - Check for set membership. -*) - let mk_Set_Membership(Expr elem, Expr set) - { - - - - - CheckContextMatch(elem); - CheckContextMatch(set); - return Expr.Create(this, Z3native.mk_set_member(nCtx, elem.x#gno, set.x#gno)); - } - -(** - Check for subsetness of sets. -*) - let mk_Set_Subset(Expr arg1, Expr arg2) - { - - - - - CheckContextMatch(arg1); - CheckContextMatch(arg2); - return Expr.Create(this, Z3native.mk_set_subset(nCtx, arg1.x#gno, arg2.x#gno)); - } - +(** (* NUMERALS *) (* GENERAL NUMERALS *) (** - Create a Term of a given sort. + Create a Term of a given sort. *) - @param v 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]*. - @param ty 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) - { + @param v 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]*. + @param ty 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, Z3native.mk_numeral(nCtx, v, ty.x#gno)); - } + create_expr ctx (Z3native.mk_numeral ctx#gno v, ty#gno) (** - 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. + 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. *) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(int v, Sort ty) - { + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(int v, Sort ty) - - - CheckContextMatch(ty); - return Expr.Create(this, Z3native.mk_int(nCtx, v, ty.x#gno)); - } + create_expr ctx (Z3native.mk_int ctx#gno v, ty#gno) (** - 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. + 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. *) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(uint v, Sort ty) - { + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(uint v, Sort ty) - - - CheckContextMatch(ty); - return Expr.Create(this, Z3native.mk_unsigned_int(nCtx, v, ty.x#gno)); - } + create_expr ctx (Z3native.mk_unsigned_int ctx#gno v, ty#gno) (** - 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. + 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. *) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(long v, Sort ty) - { + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(long v, Sort ty) - - - CheckContextMatch(ty); - return Expr.Create(this, Z3native.mk_int64(nCtx, v, ty.x#gno)); - } + create_expr ctx (Z3native.mk_int64 ctx#gno v, ty#gno) (** - 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. + 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. *) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(ulong v, Sort ty) - { + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(ulong v, Sort ty) - - - CheckContextMatch(ty); - return Expr.Create(this, Z3native.mk_unsigned_int64(nCtx, v, ty.x#gno)); - } - + create_expr ctx (Z3native.mk_unsigned_int64 ctx#gno v, ty#gno) (* REALS *) (** - Create a real from a fraction. + Create a real from a fraction. *) - @param num numerator of rational. - @param den 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"); + @param num numerator of rational. + @param den 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, Z3native.mk_real(nCtx, num, den)); - } + new RatNum(this, Z3native.mk_real ctx#gno num, den) (** - Create a real numeral. + Create a real numeral. *) - @param v A string representing the Term value in decimal notation. - @return A Term with value and sort Real - public RatNum MkReal(string v) - { + @param v 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, Z3native.mk_numeral(nCtx, v, RealSort.x#gno)); - } + new RatNum(this, Z3native.mk_numeral ctx#gno v, RealSort#gno) (** - Create a real numeral. + Create a real numeral. *) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(int v) - { + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(int v) - - return new RatNum(this, Z3native.mk_int(nCtx, v, RealSort.x#gno)); - } + new RatNum(this, Z3native.mk_int ctx#gno v, RealSort#gno) (** - Create a real numeral. + Create a real numeral. *) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(uint v) - { + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(uint v) - - return new RatNum(this, Z3native.mk_unsigned_int(nCtx, v, RealSort.x#gno)); - } + new RatNum(this, Z3native.mk_unsigned_int ctx#gno v, RealSort#gno) (** - Create a real numeral. + Create a real numeral. *) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(long v) - { + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(long v) - - return new RatNum(this, Z3native.mk_int64(nCtx, v, RealSort.x#gno)); - } + new RatNum(this, Z3native.mk_int64 ctx#gno v, RealSort#gno) (** - Create a real numeral. + Create a real numeral. *) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(ulong v) - { + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(ulong v) - - return new RatNum(this, Z3native.mk_unsigned_int64(nCtx, v, RealSort.x#gno)); - } - + new RatNum(this, Z3native.mk_unsigned_int64 ctx#gno v, RealSort#gno) (* INTEGERS *) (** - Create an integer numeral. + Create an integer numeral. *) - @param v A string representing the Term value in decimal notation. - public IntNum MkInt(string v) - { + @param v A string representing the Term value in decimal notation. + public IntNum MkInt(string v) - - return new IntNum(this, Z3native.mk_numeral(nCtx, v, IntSort.x#gno)); - } + new IntNum(this, Z3native.mk_numeral ctx#gno v, IntSort#gno) (** - Create an integer numeral. + Create an integer numeral. *) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(int v) - { + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(int v) - - return new IntNum(this, Z3native.mk_int(nCtx, v, IntSort.x#gno)); - } + new IntNum(this, Z3native.mk_int ctx#gno v, IntSort#gno) (** - Create an integer numeral. + Create an integer numeral. *) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(uint v) - { + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(uint v) - - return new IntNum(this, Z3native.mk_unsigned_int(nCtx, v, IntSort.x#gno)); - } + new IntNum(this, Z3native.mk_unsigned_int ctx#gno v, IntSort#gno) (** - Create an integer numeral. + Create an integer numeral. *) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(long v) - { + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(long v) - - return new IntNum(this, Z3native.mk_int64(nCtx, v, IntSort.x#gno)); - } + new IntNum(this, Z3native.mk_int64 ctx#gno v, IntSort#gno) (** - Create an integer numeral. + Create an integer numeral. *) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(ulong v) - { + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(ulong v) - - return new IntNum(this, Z3native.mk_unsigned_int64(nCtx, v, IntSort.x#gno)); - } - + new IntNum(this, Z3native.mk_unsigned_int64 ctx#gno v, IntSort#gno) (* BIT-VECTORS *) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v A string representing the value in decimal notation. - @param size the size of the bit-vector - let mk_B_V(string v, uint size) - { + @param v A string representing the value in decimal notation. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) string v, uint size) - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } + (BitVecNum)MkNumeral(v, MkBitVecSort(size) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_B_V(int v, uint size) - { + @param v value of the numeral. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) int v, uint size) - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } + (BitVecNum)MkNumeral(v, MkBitVecSort(size) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_B_V(uint v, uint size) - { + @param v value of the numeral. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) uint v, uint size) - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } + (BitVecNum)MkNumeral(v, MkBitVecSort(size) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_B_V(long v, uint size) - { + @param v value of the numeral. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) long v, uint size) - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } + (BitVecNum)MkNumeral(v, MkBitVecSort(size) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_B_V(ulong v, uint size) - { + @param v value of the numeral. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) ulong v, uint size) + (BitVecNum)MkNumeral(v, MkBitVecSort(size) - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } - - - // Numerals + // Numerals (* QUANTIFIERS *) (** - Create a universal Quantifier. + 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. *) - - 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. - - @param sorts the sorts of the bound variables. - @param names names of the bound variables - @param body the body of the quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param patterns array containing the patterns created using MkPattern. - @param noPatterns array containing the anti-patterns created using MkPattern. - @param quantifierID optional symbol to track quantifier. - @param skolemID optional symbol to track skolem constants. - public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { - - - - - - - - - - - - return new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + @param sorts the sorts of the bound variables. + @param names names of the bound variables + @param body the body of the quantifier. + @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. + @param patterns array containing the patterns created using MkPattern. + @param noPatterns array containing the anti-patterns created using MkPattern. + @param quantifierID optional symbol to track quantifier. + @param skolemID optional symbol to track skolem constants. + public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create a universal Quantifier. + Create a universal Quantifier. *) - public Quantifier MkForall(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { + public Quantifier MkForall(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - - - - - - return new Quantifier(this, true, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + new Quantifier(this, true, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create an existential Quantifier. + Create an existential Quantifier. *) - - public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { + + public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - - - - - - - - - return new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create an existential Quantifier. + Create an existential Quantifier. *) - public Quantifier MkExists(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { - - - - - - - return new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + public Quantifier MkExists(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create a Quantifier. + Create a Quantifier. *) - public Quantifier MkQuantifier(bool universal, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { - - - - - - - - - - - - if (universal) - return MkForall(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - return MkExists(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + public Quantifier MkQuantifier(bool universal, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + if (universal) + MkForall(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); + else + MkExists(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create a Quantifier. + Create a Quantifier. *) - public Quantifier MkQuantifier(bool universal, Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { + public Quantifier MkQuantifier(bool universal, Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + if (universal) + MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); + else + MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - - - - - - if (universal) - return MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - return MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } - - - - // Expr + // Expr (* OPTIONS *) (** - Selects the format used for pretty-printing expressions. + 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. *) - - 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 Z3_ast_print_mode PrintMode - { - set { Z3native.set_ast_print_mode(nCtx, (uint)value); } - } - + + + + + public Z3_ast_print_mode PrintMode + + set { Z3native.set_ast_print_mode ctx#gno (uint)value); } (* SMT Files & Strings *) (** - Convert a benchmark into an SMT-LIB formatted string. + Convert a benchmark into an SMT-LIB formatted string. *) - @param name Name of the benchmark. The argument is optional. - @param logic The benchmark logic. - @param status The status string (sat, unsat, or unknown) - @param attributes Other attributes, such as source, difficulty or category. - @param assumptions Auxiliary assumptions. - @param formula 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) - { + @param name Name of the benchmark. The argument is optional. + @param logic The benchmark logic. + @param status The status string (sat, unsat, or unknown) + @param attributes Other attributes, such as source, difficulty or category. + @param assumptions Auxiliary assumptions. + @param formula 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 Z3native.benchmark_to_smtlib_string(nCtx, name, logic, status, attributes, - (uint)assumptions.Length, AST.ArrayToNative(assumptions), - formula.x#gno); - } + Z3native.benchmark_to_smtlib_string ctx#gno name, logic, status, attributes, + (uint)assumptions.Length, AST.ArrayToNative(assumptions), + formula#gno); (** - Parse the given string using the SMT-LIB parser. + 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. *) - - 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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - { - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_string(nCtx, str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)); - } + public void ParseSMTLIBString(string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_string ctx#gno 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. + Parse the given file using the SMT-LIB parser. *) - - public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - { - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_file(nCtx, fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)); - } + + public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_file ctx#gno 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. + The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBFormulas { get { return Z3native.get_smtlib_num_formulas(nCtx)) + public uint NumSMTLIBFormulas { get {Z3native.get_smtlib_num_formulas ctx#gno)) (** - The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public BoolExpr[] SMTLIBFormulas - { - get - { + let[] SMTLIBFormulas + get + + uint n = NumSMTLIBFormulas; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_formula ctx#gno i) + res; - uint n = NumSMTLIBFormulas; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)Expr.Create(this, Z3native.get_smtlib_formula(nCtx, i)); - return res; - } - } (** - The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBAssumptions { get { return Z3native.get_smtlib_num_assumptions(nCtx)) + public uint NumSMTLIBAssumptions { get {Z3native.get_smtlib_num_assumptions ctx#gno)) (** - The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public BoolExpr[] SMTLIBAssumptions - { - get - { + let[] SMTLIBAssumptions + get + + uint n = NumSMTLIBAssumptions; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i) + res; - uint n = NumSMTLIBAssumptions; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)Expr.Create(this, Z3native.get_smtlib_assumption(nCtx, i)); - return res; - } - } (** - The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBDecls { get { return Z3native.get_smtlib_num_decls(nCtx)) + public uint NumSMTLIBDecls { get {Z3native.get_smtlib_num_decls ctx#gno)) (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public Func_Decl[] SMTLIBDecls - { - get - { + public Func_Decl[] SMTLIBDecls + get + + uint n = NumSMTLIBDecls; + Func_Decl[] res = new Func_Decl[n]; + for (uint i = 0; i < n; i++) + res[i] = new Func_Decl(this, Z3native.get_smtlib_decl ctx#gno i) + res; - uint n = NumSMTLIBDecls; - Func_Decl[] res = new Func_Decl[n]; - for (uint i = 0; i < n; i++) - res[i] = new Func_Decl(this, Z3native.get_smtlib_decl(nCtx, i)); - return res; - } - } (** - The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBSorts { get { return Z3native.get_smtlib_num_sorts(nCtx)) + public uint NumSMTLIBSorts { get {Z3native.get_smtlib_num_sorts ctx#gno)) (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public Sort[] SMTLIBSorts - { - get - { + public Sort[] SMTLIBSorts + get + + uint n = NumSMTLIBSorts; + Sort[] res = new Sort[n]; + for (uint i = 0; i < n; i++) + res[i] = Sort.Create(this, Z3native.get_smtlib_sort ctx#gno i) + res; - uint n = NumSMTLIBSorts; - Sort[] res = new Sort[n]; - for (uint i = 0; i < n; i++) - res[i] = Sort.Create(this, Z3native.get_smtlib_sort(nCtx, i)); - return res; - } - } (** - Parse the given string using the SMT-LIB2 parser. + 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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - { + + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. + let ParseSMTLIB2String ( ctx : context ) string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - return (BoolExpr)Expr.Create(this, Z3native.parse_smtlib2_string(nCtx, str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); - } + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_string ctx#gno 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. + Parse the given file using the SMT-LIB2 parser. *) - - public BoolExpr ParseSMTLIB2File(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - { + + let ParseSMTLIB2File ( ctx : context ) string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - return (BoolExpr)Expr.Create(this, Z3native.parse_smtlib2_file(nCtx, fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); - } - + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_file ctx#gno fileName, + AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) (* GOALS *) (** - Creates a new Goal. + Creates a new Goal. + + Note that the Context must have been created with proof generation support if + is set to true here. *) - - Note that the Context must have been created with proof generation support if - is set to true here. - - @param models Indicates whether model generation should be enabled. - @param unsatCores Indicates whether unsat core generation should be enabled. - @param proofs Indicates whether proof generation should be enabled. - public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) - { + @param models Indicates whether model generation should be enabled. + @param unsatCores Indicates whether unsat core generation should be enabled. + @param proofs Indicates whether proof generation should be enabled. + public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) - - return new Goal(this, models, unsatCores, proofs); - } - + new Goal(this, models, unsatCores, proofs); (* PARAMETERSETS *) (** - Creates a new ParameterSet. + Creates a new ParameterSet. *) - public Params MkParams ( ctx : context ) = - { + public Params MkParams ( ctx : context ) = - - return new Params(this); - } - + new Params(this); (* TACTICS *) (** - The number of supported tactics. + The number of supported tactics. *) - public uint NumTactics - { - get { return Z3native.get_num_tactics(nCtx); } - } + public uint NumTactics + + get {Z3native.get_num_tactics ctx#gno); } (** - The names of all supported tactics. + The names of all supported tactics. *) - public string[] TacticNames - { - get - { + public string[] TacticNames + get + + uint n = NumTactics; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_tactic_name ctx#gno i); + res; - uint n = NumTactics; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_tactic_name(nCtx, i); - return res; - } - } (** - Returns a string containing a description of the tactic with the given name. + Returns a string containing a description of the tactic with the given name. *) - public string TacticDescription(string name) - { + public string TacticDescription(string name) - - return Z3native.tactic_get_descr(nCtx, name); - } + Z3native.tactic_get_descr ctx#gno name); (** - Creates a new Tactic. + Creates a new Tactic. *) - public Tactic MkTactic(string name) - { + public Tactic MkTactic(string name) - - return new Tactic(this, name); - } + new Tactic(this, name); (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . + Create a tactic that applies to a Goal and + then to every subgoal produced by . *) - public Tactic AndThen(Tactic t1, Tactic t2, params Tactic[] ts) - { + public Tactic AndThen(Tactic t1, Tactic t2, params Tactic[] ts) + IntPtr last = IntPtr.Zero; + if (ts != null && ts.Length > 0) + last = ts[ts.Length - 1]#gno; + for (int i = ts.Length - 2; i >= 0; i--) + last = Z3native.tactic_and_then ctx#gno ts[i]#gno last); + if (last != IntPtr.Zero) + last = Z3native.tactic_and_then ctx#gno t2#gno last); + new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno last) - - CheckContextMatch(t1); - CheckContextMatch(t2); - CheckContextMatch(ts); - - IntPtr last = IntPtr.Zero; - if (ts != null && ts.Length > 0) - { - last = ts[ts.Length - 1].x#gno; - for (int i = ts.Length - 2; i >= 0; i--) - last = Z3native.tactic_and_then(nCtx, ts[i].x#gno, last); - } - if (last != IntPtr.Zero) - { - last = Z3native.tactic_and_then(nCtx, t2.x#gno, last); - return new Tactic(this, Z3native.tactic_and_then(nCtx, t1.x#gno, last)); - } - else - return new Tactic(this, Z3native.tactic_and_then(nCtx, t1.x#gno, t2.x#gno)); - } + else + new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno t2#gno) (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . + Create a tactic that applies to a Goal and + then to every subgoal produced by . + + Shorthand for AndThen. *) - - Shorthand for AndThen. - - public Tactic Then(Tactic t1, Tactic t2, params Tactic[] ts) - { + public Tactic Then(Tactic t1, Tactic t2, params Tactic[] ts) - - - - - return AndThen(t1, t2, ts); - } + 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. + 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) - { + public Tactic OrElse(Tactic t1, Tactic t2) - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Z3native.tactic_or_else(nCtx, t1.x#gno, t2.x#gno)); - } + new Tactic(this, Z3native.tactic_or_else ctx#gno t1#gno t2#gno) (** - Create a tactic that applies to a goal for milliseconds. + Create a tactic that applies to a goal for milliseconds. + + If does not terminate within milliseconds, then it fails. *) - - If does not terminate within milliseconds, then it fails. - - public Tactic TryFor(Tactic t, uint ms) - { + public Tactic TryFor(Tactic t, uint ms) - - - CheckContextMatch(t); - return new Tactic(this, Z3native.tactic_try_for(nCtx, t.x#gno, ms)); - } + new Tactic(this, Z3native.tactic_try_for ctx#gno t#gno ms) (** - Create a tactic that applies to a given goal if the probe - evaluates to true. + 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. *) - - If evaluates to false, then the new tactic behaves like the skip tactic. - - public Tactic When(Probe p, Tactic t) - { + public Tactic When(Probe p, Tactic t) - - - - CheckContextMatch(t); - CheckContextMatch(p); - return new Tactic(this, Z3native.tactic_when(nCtx, p.x#gno, t.x#gno)); - } + new Tactic(this, Z3native.tactic_when ctx#gno p#gno t#gno) (** - Create a tactic that applies to a given goal if the probe - evaluates to true and otherwise. + 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) - { + public Tactic Cond(Probe p, Tactic t1, Tactic t2) - - - - - CheckContextMatch(p); - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Z3native.tactic_cond(nCtx, p.x#gno, t1.x#gno, t2.x#gno)); - } + new Tactic(this, Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) (** - Create a tactic that keeps applying until the goal is not - modified anymore or the maximum number of iterations is reached. + 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, uint max = uint.MaxValue) - { + public Tactic Repeat(Tactic t, uint max = uint.MaxValue) - - - CheckContextMatch(t); - return new Tactic(this, Z3native.tactic_repeat(nCtx, t.x#gno, max)); - } + new Tactic(this, Z3native.tactic_repeat ctx#gno t#gno max) (** - Create a tactic that just returns the given goal. + Create a tactic that just returns the given goal. *) - public Tactic Skip ( ctx : context ) = - { + public Tactic Skip ( ctx : context ) = - - return new Tactic(this, Z3native.tactic_skip(nCtx)); - } + new Tactic(this, Z3native.tactic_skip ctx#gno) (** - Create a tactic always fails. + Create a tactic always fails. *) - public Tactic Fail ( ctx : context ) = - { + public Tactic Fail ( ctx : context ) = - - return new Tactic(this, Z3native.tactic_fail(nCtx)); - } + new Tactic(this, Z3native.tactic_fail ctx#gno) (** - Create a tactic that fails if the probe evaluates to false. + Create a tactic that fails if the probe evaluates to false. *) - public Tactic FailIf(Probe p) - { + public Tactic FailIf(Probe p) - - - CheckContextMatch(p); - return new Tactic(this, Z3native.tactic_fail_if(nCtx, p.x#gno)); - } + new Tactic(this, Z3native.tactic_fail_if ctx#gno p#gno) (** - Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). + 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 ( ctx : context ) = - { + public Tactic FailIfNotDecided ( ctx : context ) = - - return new Tactic(this, Z3native.tactic_fail_if_not_decided(nCtx)); - } + new Tactic(this, Z3native.tactic_fail_if_not_decided ctx#gno) (** - Create a tactic that applies using the given set of parameters . + Create a tactic that applies using the given set of parameters . *) - public Tactic UsingParams(Tactic t, Params p) - { + public Tactic UsingParams(Tactic t, Params p) - - - - CheckContextMatch(t); - CheckContextMatch(p); - return new Tactic(this, Z3native.tactic_using_params(nCtx, t.x#gno, p.x#gno)); - } + new Tactic(this, Z3native.tactic_using_params ctx#gno t#gno p#gno) (** - Create a tactic that applies using the given set of parameters . -*) - Alias for UsingParams - public Tactic With(Tactic t, Params p) - { + 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); - } + UsingParams(t, p); (** - Create a tactic that applies the given tactics in parallel. + Create a tactic that applies the given tactics in parallel. *) - public Tactic ParOr(params Tactic[] t) - { + public Tactic ParOr(params Tactic[] t) - - - CheckContextMatch(t); - return new Tactic(this, Z3native.tactic_par_or(nCtx, Tactic.ArrayLength(t), Tactic.ArrayToNative(t))); - } + new Tactic(this, Z3native.tactic_par_or ctx#gno 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. + 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) - { + public Tactic ParAndThen(Tactic t1, Tactic t2) - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Z3native.tactic_par_and_then(nCtx, t1.x#gno, t2.x#gno)); - } + new Tactic(this, Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) (** - Interrupt the execution of a Z3 procedure. + Interrupt the execution of a Z3 procedure. *) - This procedure can be used to interrupt: solvers, simplifiers and tactics. - public void Interrupt ( ctx : context ) = - { - Z3native.interrupt(nCtx); - } - + This procedure can be used to interrupt: solvers, simplifiers and tactics. + public void Interrupt ( ctx : context ) = + + Z3native.interrupt ctx#gno); (* PROBES *) (** - The number of supported Probes. + The number of supported Probes. *) - public uint NumProbes - { - get { return Z3native.get_num_probes(nCtx); } - } + public uint NumProbes + + get {Z3native.get_num_probes ctx#gno); } (** - The names of all supported Probes. + The names of all supported Probes. *) - public string[] ProbeNames - { - get - { + public string[] ProbeNames + get + + uint n = NumProbes; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_probe_name ctx#gno i); + res; - uint n = NumProbes; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_probe_name(nCtx, i); - return res; - } - } (** - Returns a string containing a description of the probe with the given name. + Returns a string containing a description of the probe with the given name. *) - public string ProbeDescription(string name) - { + public string ProbeDescription(string name) - - return Z3native.probe_get_descr(nCtx, name); - } + Z3native.probe_get_descr ctx#gno name); (** - Creates a new Probe. + Creates a new Probe. *) - public Probe MkProbe(string name) - { + public Probe MkProbe(string name) - - return new Probe(this, name); - } + new Probe(this, name); (** - Create a probe that always evaluates to . + Create a probe that always evaluates to . *) - public Probe Const(double val) - { + public Probe Const(double val) - - return new Probe(this, Z3native.probe_const(nCtx, val)); - } + new Probe(this, Z3native.probe_const ctx#gno val) (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by + 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) - { + public Probe Lt(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_lt(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_lt ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by + 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) - { + public Probe Gt(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_gt(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_gt ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by + 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) - { + public Probe Le(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_le(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_le ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by + 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) - { + public Probe Ge(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_ge(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_ge ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by + 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) - { + public Probe Eq(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_eq(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_eq ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". + Create a probe that evaluates to "true" when the value + and evaluate to "true". *) - public Probe And(Probe p1, Probe p2) - { + public Probe And(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_and(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_and ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". + Create a probe that evaluates to "true" when the value + or evaluate to "true". *) - public Probe Or(Probe p1, Probe p2) - { + public Probe Or(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_or(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_or ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". + Create a probe that evaluates to "true" when the value + does not evaluate to "true". *) - public Probe Not(Probe p) - { + public Probe Not(Probe p) - - - CheckContextMatch(p); - return new Probe(this, Z3native.probe_not(nCtx, p.x#gno)); - } - + new Probe(this, Z3native.probe_not ctx#gno p#gno) (* SOLVERS *) (** - 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 = null) - { + 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 = null) - - if (logic == null) - return new Solver(this, Z3native.mk_solver(nCtx)); - else - return new Solver(this, Z3native.mk_solver_for_logic(nCtx, logic.x#gno)); - } + if (logic == null) + new Solver(this, Z3native.mk_solver ctx#gno) + else + new Solver(this, Z3native.mk_solver_for_logic ctx#gno logic#gno) (** - Creates a new (incremental) solver. + Creates a new (incremental) solver. *) - - public Solver MkSolver(string logic) - { + + public Solver MkSolver(string logic) - - return MkSolver(MkSymbol(logic)); - } + MkSolver(MkSymbol(logic) (** - Creates a new (incremental) solver. + Creates a new (incremental) solver. *) - let mk_Simple_Solver ( ctx : context ) = - { + let mk_Simple_Solver ( ctx : context ) ctx : context ) = - - return new Solver(this, Z3native.mk_simple_solver(nCtx)); - } + new Solver(this, Z3native.mk_simple_solver ctx#gno) (** - Creates a solver that is implemented using the given tactic. + 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. *) - - The solver supports the commands Push and Pop, but it - will always solve each check from scratch. - - public Solver MkSolver(Tactic t) - { + public Solver MkSolver(Tactic t) - - - return new Solver(this, Z3native.mk_solver_from_tactic(nCtx, t.x#gno)); - } - + new Solver(this, Z3native.mk_solver_from_tactic ctx#gno t#gno) (* FIXEDPOINTS *) (** - Create a Fixedpoint context. + Create a Fixedpoint context. *) - public Fixedpoint MkFixedpoint ( ctx : context ) = - { - - - return new Fixedpoint(this); - } - + public Fixedpoint MkFixedpoint ( ctx : context ) = + new Fixedpoint(this); (* MISCELLANEOUS *) (** - Wraps an AST. + 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., - . - - @param nativeObject The native pointer to wrap. - public AST WrapAST(IntPtr nativeObject) - { + 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., + . + + @param nativeObject The native pointer to wrap. + public AST WrapAST(IntPtr nativeObject) - return AST.Create(this, nativeObject); - } + AST.Create(this, nativeObject); (** - Unwraps an AST. + 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., - ). - - @param a The AST to unwrap. - public IntPtr UnwrapAST(AST a) - { - return a.x#gno; - } + 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., + ). + + @param a The AST to unwrap. + public IntPtr UnwrapAST(AST a) + + a#gno; (** - Return a string describing all available parameters to Expr.Simplify. + a string describing all available parameters to Expr.Simplify. *) - public string SimplifyHelp ( ctx : context ) = - { + public string SimplifyHelp ( ctx : context ) = - - return Z3native.simplify_get_help(nCtx); - } + Z3native.simplify_get_help ctx#gno); (** - Retrieves parameter descriptions for simplifier. + Retrieves parameter descriptions for simplifier. *) - public ParamDescrs SimplifyParameterDescriptions - { - get { return new ParamDescrs(this, Z3native.simplify_get_param_descrs(nCtx)); } - } + public ParamDescrs SimplifyParameterDescriptions + + get {new ParamDescrs(this, Z3native.simplify_get_param_descrs ctx#gno)); } (** - Enable/disable printing of warning messages to the console. + 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(bool enabled) - { - Z3native.toggle_warning_messages((enabled) ? 1 : 0); - } - + Note that this function is static and effects the behaviour of + all contexts globally. + public static void ToggleWarningMessages(bool enabled) + + Z3native.toggle_warning_messages((enabled) ? 1 : 0); (* ERROR HANDLING *) - //(** - //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); +(** + 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; - +(** + The OnError event. +*) + public event ErrorHandler OnError = null; (* PARAMETERS *) (** - Update a mutable configuration parameter. + 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. *) - - 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) - { - Z3native.update_param_value(nCtx, id, value); - } + + public void UpdateParamValue(string id, string value) + + Z3native.update_param_value ctx#gno id, value); (** - Get a configuration parameter. + Get a configuration parameter. + + Returns null if the parameter value does not exist. + *) - - Returns null if the parameter value does not exist. - - - public string GetParamValue(string id) - { - IntPtr res = IntPtr.Zero; - int r = Z3native.get_param_value(nCtx, id, out res); - if (r == (int)Z3_lbool.Z3_L_FALSE) - return null; - else - return Marshal.PtrToStringAnsi(res); - } + public string GetParamValue(string id) - + IntPtr res = IntPtr.Zero; + int r = Z3native.get_param_value ctx#gno id, out res); + if (r == (int)Z3_lbool.L_FALSE) + null; + else + Marshal.PtrToStringAnsi(res); (* INTERNAL *) - internal IntPtr m_ctx = IntPtr.Zero; - internal Z3native.error_handler m_n_err_handler = null; - internal IntPtr nCtx { get { return m_ctx) + internal IntPtr m_ctx = IntPtr.Zero; + internal Z3native.error_handler m_n_err_handler = null; + internal IntPtr nCtx { get {m_ctx) - internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) - { - // Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. - } + internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) + + Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. + + internal void InitContext ( ctx : context ) = + + PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); - internal void InitContext ( ctx : context ) = - { - PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); // keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); - } *) -end + From 371db347afe3bfa80568c5cd131ff50c98d6ed93 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sun, 23 Dec 2012 04:00:34 +0000 Subject: [PATCH 026/248] More new ML API. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 8 +- scripts/update_api.py | 13 +- src/api/ml/z3.ml | 1644 ++++++++++++++++++------------------- 3 files changed, 807 insertions(+), 858 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index f414e9d1a..dde9f944a 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,7 +4,7 @@ *) open Z3 -open Z3.Context +open Z3.Arithmetic exception ExampleException of string @@ -16,9 +16,9 @@ let _ = Printf.printf "Running Z3 version %s\n" Version.to_string ; let cfg = [("model", "true"); ("proof", "false")] in let ctx = (new context cfg) in - let is = (mk_symbol_int ctx 42) in - let ss = (mk_symbol_string ctx "mySymbol") in - let bs = (mk_bool_sort ctx) in + let is = (Symbol.mk_int ctx 42) in + let ss = (Symbol.mk_string ctx "mySymbol") in + let bs = (Sort.mk_bool ctx) in let ints = (mk_int_sort ctx) in let rs = (mk_real_sort ctx) in Printf.printf "int symbol: %s\n" (Symbol.to_string (is :> symbol)); diff --git a/scripts/update_api.py b/scripts/update_api.py index 27f7dd507..acaa9478e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1154,8 +1154,11 @@ def mk_ml(): for k, v in Type2Str.iteritems(): if is_obj(k): ml_native.write('and %s = ptr\n' % v.lower()) - ml_native.write('\nexternal is_null : ptr -> bool\n') + ml_native.write('\n') + ml_native.write('external is_null : ptr -> bool\n') ml_native.write(' = "n_is_null"\n\n') + ml_native.write('external mk_null : unit -> ptr\n') + ml_native.write(' = "n_mk_null"\n\n') ml_native.write('exception Exception of string\n\n') # ML declarations @@ -1295,6 +1298,14 @@ def mk_ml(): ml_wrapper.write('CAMLprim value n_is_null(value p) {\n') ml_wrapper.write(' return Val_bool(Data_custom_val(p) == 0);\n') ml_wrapper.write('}\n\n') + ml_wrapper.write('CAMLprim value n_mk_null( void ) {\n') + ml_wrapper.write(' CAMLparam0();\n') + ml_wrapper.write(' CAMLlocal1(result);\n') + ml_wrapper.write(' void * z3_result = 0;\n') + ml_wrapper.write(' result = caml_alloc_custom(&default_custom_ops, sizeof(void*), 0, 1);\n') + ml_wrapper.write(' memcpy( Data_custom_val(result), &z3_result, sizeof(void*));\n') + ml_wrapper.write(' CAMLreturn (result);\n') + ml_wrapper.write('}\n\n') for name, result, params in _dotnet_decls: ip = inparams(params) op = outparams(params) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 5f67e11e2..f6454b797 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -593,6 +593,10 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end +let patternaton (a : pattern array) = + let f (e : pattern) = e#gno in + Array.map f a + (** Parameter description objects *) class param_descrs ctx = object (self) @@ -1607,6 +1611,306 @@ struct *) let mk_or ( ctx : context ) ( args : bool_expr array ) = (new bool_expr ctx)#cnstr_obj (Z3native.mk_or ctx#gno (Array.length args) (astaton args)) + + (** + Create a numeral of a given sort. + @param v 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]*. + @param ty 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 + *) + let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = + create_expr ctx (Z3native.mk_numeral ctx#gno v ty#gno) + + (** + Create a numeral 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. + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + *) + let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = + create_expr ctx (Z3native.mk_int ctx#gno v ty#gno) +end + +(** Quantifier expressions *) +module Quantifiers = +struct + (** + 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 : expr ) appears, the higher is its + index. + *) + let get_index ( x : expr ) = + if not (AST.is_var x) then + raise (Z3native.Exception "Term is not a bound variable.") + else + Z3native.get_index_value x#gnc x#gno + + (** Quantifier patterns + + 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. + *) + module Pattern = + struct + (** + The number of terms in the pattern. + *) + let get_num_terms ( x : pattern ) = + Z3native.get_pattern_num_terms x#gnc x#gno + + (** + The terms in the pattern. + *) + let get_terms ( x : pattern ) = + let n = (get_num_terms x) in + let f i = (create_expr x#gc (Z3native.get_pattern x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the pattern. + *) + let to_string ( x : pattern ) = Z3native.pattern_to_string x#gnc x#gno + end + + (** + Indicates whether the quantifier is universal. + *) + let is_universal ( x : quantifier ) = + lbool_of_int (Z3native.is_quantifier_forall x#gnc x#gno) == L_TRUE + + (** + Indicates whether the quantifier is existential. + *) + let is_existential ( x : quantifier ) = not (is_universal x) + + (** + The weight of the quantifier. + *) + let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight x#gnc x#gno + + (** + The number of patterns. + *) + let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns x#gnc x#gno + + (** + The patterns. + *) + let get_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_pattern_ast x#gnc x#gno i)) in + Array.init n f + + (** + The number of no-patterns. + *) + let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns x#gnc x#gno + + (** + The no-patterns. + *) + let get_no_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_no_pattern_ast x#gnc x#gno i)) in + Array.init n f + + (** + The number of bound variables. + *) + let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound x#gnc x#gno + + (** + The symbols for the bound variables. + *) + let get_bound_variable_names ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (create_symbol x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in + Array.init n f + + (** + The sorts of the bound variables. + *) + let get_bound_variable_sorts ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (create_sort x#gc (Z3native.get_quantifier_bound_sort x#gnc x#gno i)) in + Array.init n f + + (** + The body of the quantifier. + *) + let get_body ( x : quantifier ) = + (new bool_expr x#gc)#cnstr_obj (Z3native.get_quantifier_body x#gnc x#gno) + + (** + Creates a new bound variable. + @param index The de-Bruijn index of the variable + @param ty The sort of the variable + *) + let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = + create_expr ctx (Z3native.mk_bound ctx#gno index ty#gno) + + (** + Create a quantifier pattern. + *) + let mk_pattern ( ctx : context ) ( terms : expr array ) = + if (Array.length terms) == 0 then + raise (Z3native.Exception "Cannot create a pattern from zero terms") + else + (new pattern ctx)#cnstr_obj (Z3native.mk_pattern ctx#gno (Array.length terms) (astaton terms)) + + (** + 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. + + @param sorts the sorts of the bound variables. + @param names names of the bound variables + @param body the body of the quantifier. + @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. + @param patterns array containing the patterns created using MkPattern. + @param noPatterns array containing the anti-patterns created using MkPattern. + @param quantifierID optional symbol to track quantifier. + @param skolemID optional symbol to track skolem constants. + *) + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (Array.length sorts) != (Array.length names) then + raise (Z3native.Exception "Number of sorts does not match number of names") + else if (nopatterns == None && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno (int_of_lbool L_TRUE) + (match weight with | None -> 1 | Some(x) -> x) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length sorts) (astaton sorts) + (astaton names) + body#gno) + else + let null = Z3native.mk_null() in + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno (int_of_lbool L_TRUE) + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> x#gno) + (match skolem_id with | None -> null | Some(x) -> x#gno) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) + (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length sorts) (astaton sorts) + (astaton names) + body#gno) + + (** + Create a universal Quantifier. + *) + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (nopatterns == None && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno (int_of_lbool L_TRUE) + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (expraton bound_constants) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + body#gno) + else + let null = Z3native.mk_null() in + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno (int_of_lbool L_TRUE) + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> x#gno) + (match skolem_id with | None -> null | Some(x) -> x#gno) + (Array.length bound_constants) (expraton bound_constants) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) + (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + body#gno) + (** + Create an existential Quantifier. + + *) + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (Array.length sorts) != (Array.length names) then + raise (Z3native.Exception "Number of sorts does not match number of names") + else if (nopatterns == None && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno (int_of_lbool L_FALSE) + (match weight with | None -> 1 | Some(x) -> x) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length sorts) (astaton sorts) + (astaton names) + body#gno) + else + let null = Z3native.mk_null() in + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno (int_of_lbool L_FALSE) + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> x#gno) + (match skolem_id with | None -> null | Some(x) -> x#gno) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) + (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length sorts) (astaton sorts) + (astaton names) + body#gno) + + (** + Create an existential Quantifier. + *) + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (nopatterns == None && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno (int_of_lbool L_FALSE) + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (expraton bound_constants) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + body#gno) + else + let null = Z3native.mk_null() in + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno (int_of_lbool L_FALSE) + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> x#gno) + (match skolem_id with | None -> null | Some(x) -> x#gno) + (Array.length bound_constants) (expraton bound_constants) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) + (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + body#gno) + + (** + Create a Quantifier. + *) + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (universal) then + (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) + else + (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) + + + (** + Create a Quantifier. + *) + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (universal) then + mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id + else + mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id end (** Functions to manipulate Array expressions *) @@ -1777,71 +2081,71 @@ struct *) let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) -(** - Create a set type. -*) -let mk_sort ( ctx : context ) ( ty : sort) = - (new set_sort ctx)#cnstr_s ty + (** + Create a set type. + *) + let mk_sort ( ctx : context ) ( ty : sort) = + (new set_sort ctx)#cnstr_s ty -(** - Create an empty set. -*) -let mk_empty ( ctx : context ) ( domain : sort ) = - (create_expr ctx (Z3native.mk_empty_set ctx#gno domain#gno)) - - (** - Create the full set. - *) -let mk_full ( ctx : context ) ( domain : sort ) = - create_expr ctx (Z3native.mk_full_set ctx#gno domain#gno) + (** + Create an empty set. + *) + let mk_empty ( ctx : context ) ( domain : sort ) = + (create_expr ctx (Z3native.mk_empty_set ctx#gno domain#gno)) + + (** + Create the full set. + *) + let mk_full ( ctx : context ) ( domain : sort ) = + create_expr ctx (Z3native.mk_full_set ctx#gno domain#gno) -(** - Add an element to the set. -*) -let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_add ctx#gno set#gno element#gno) - - (** - Remove an element from a set. - *) -let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_del ctx#gno set#gno element#gno) - - (** - Take the union of a list of sets. - *) -let mk_union ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_union ctx#gno (Array.length args) (astaton args)) - -(** - Take the intersection of a list of sets. -*) -let mk_intersection ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_intersect ctx#gno (Array.length args) (astaton args)) + (** + Add an element to the set. + *) + let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = + create_expr ctx (Z3native.mk_set_add ctx#gno set#gno element#gno) + + (** + Remove an element from a set. + *) + let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = + create_expr ctx (Z3native.mk_set_del ctx#gno set#gno element#gno) + + (** + Take the union of a list of sets. + *) + let mk_union ( ctx : context ) ( args : expr array ) = + create_expr ctx (Z3native.mk_set_union ctx#gno (Array.length args) (astaton args)) + + (** + Take the intersection of a list of sets. + *) + let mk_intersection ( ctx : context ) ( args : expr array ) = + create_expr ctx (Z3native.mk_set_intersect ctx#gno (Array.length args) (astaton args)) -(** - Take the difference between two sets. -*) -let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_difference ctx#gno arg1#gno arg2#gno) + (** + Take the difference between two sets. + *) + let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = + create_expr ctx (Z3native.mk_set_difference ctx#gno arg1#gno arg2#gno) -(** - Take the complement of a set. -*) -let mk_complement ( ctx : context ) ( arg : expr ) = - create_expr ctx (Z3native.mk_set_complement ctx#gno arg#gno) + (** + Take the complement of a set. + *) + let mk_complement ( ctx : context ) ( arg : expr ) = + create_expr ctx (Z3native.mk_set_complement ctx#gno arg#gno) -(** - Check for set membership. -*) -let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - create_expr ctx (Z3native.mk_set_member ctx#gno elem#gno set#gno) + (** + Check for set membership. + *) + let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = + create_expr ctx (Z3native.mk_set_member ctx#gno elem#gno set#gno) - (** - Check for subsetness of sets. - *) -let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_subset ctx#gno arg1#gno arg2#gno) + (** + Check for subsetness of sets. + *) + let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = + create_expr ctx (Z3native.mk_set_subset ctx#gno arg1#gno arg2#gno) end @@ -2001,148 +2305,6 @@ struct Array.init n f end - -(** Quantifier expressions *) -module Quantifiers = -struct - (** - 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 : expr ) appears, the higher is its - index. - *) - let get_index ( x : expr ) = - if not (AST.is_var x) then - raise (Z3native.Exception "Term is not a bound variable.") - else - Z3native.get_index_value x#gnc x#gno - - (** Quantifier patterns - - 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. - *) - module Pattern = - struct - (** - The number of terms in the pattern. - *) - let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms x#gnc x#gno - - (** - The terms in the pattern. - *) - let get_terms ( x : pattern ) = - let n = (get_num_terms x) in - let f i = (create_expr x#gc (Z3native.get_pattern x#gnc x#gno i)) in - Array.init n f - - (** - A string representation of the pattern. - *) - let to_string ( x : pattern ) = Z3native.pattern_to_string x#gnc x#gno - end - - (** - Indicates whether the quantifier is universal. - *) - let is_universal ( x : quantifier ) = - lbool_of_int (Z3native.is_quantifier_forall x#gnc x#gno) == L_TRUE - - (** - Indicates whether the quantifier is existential. - *) - let is_existential ( x : quantifier ) = not (is_universal x) - - (** - The weight of the quantifier. - *) - let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight x#gnc x#gno - - (** - The number of patterns. - *) - let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns x#gnc x#gno - - (** - The patterns. - *) - let get_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_pattern_ast x#gnc x#gno i)) in - Array.init n f - - (** - The number of no-patterns. - *) - let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns x#gnc x#gno - - (** - The no-patterns. - *) - let get_no_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_no_pattern_ast x#gnc x#gno i)) in - Array.init n f - - (** - The number of bound variables. - *) - let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound x#gnc x#gno - - (** - The symbols for the bound variables. - *) - let get_bound_variable_names ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (create_symbol x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in - Array.init n f - - (** - The sorts of the bound variables. - *) - let get_bound_variable_sorts ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (create_sort x#gc (Z3native.get_quantifier_bound_sort x#gnc x#gno i)) in - Array.init n f - - (** - The body of the quantifier. - *) - let get_body ( x : quantifier ) = - (new bool_expr x#gc)#cnstr_obj (Z3native.get_quantifier_body x#gnc x#gno) - - (** - Creates a new bound variable. - @param index The de-Bruijn index of the variable - @param ty The sort of the variable - *) - let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_bound ctx#gno index ty#gno) - - (** - Create a quantifier pattern. - *) - let mk_pattern ( ctx : context ) ( terms : expr array ) = - if (Array.length terms) == 0 then - raise (Z3native.Exception "Cannot create a pattern from zero terms") - else - (new pattern ctx)#cnstr_obj (Z3native.mk_pattern ctx#gno (Array.length terms) (astaton terms)) -end (** Functions to manipulate Datatype expressions *) module Datatypes = @@ -2638,7 +2800,54 @@ struct The result has at most decimal places.*) let to_decimal_string ( x : algebraic_num ) ( precision : int ) = Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** + Create a real from a fraction. + + @param num numerator of rational. + @param den denominator of rational. + @return A Term with value / and sort Real + + *) + let mk_real_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = + if (den == 0) then + raise (Z3native.Exception "Denominator is zero") + else + (new rat_num ctx)#cnstr_obj (Z3native.mk_real ctx#gno num den) + + (** + Create a real numeral. + @param v A string representing the Term value in decimal notation. + @return A Term with value and sort Real + *) + let mk_real_numeral_s ( ctx : context ) ( v : string ) = + (new rat_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_real_sort ctx)#gno) + + (** + Create a real numeral. + + @param v value of the numeral. + @return A Term with value and sort Real + *) + let mk_real_numeral_i ( ctx : context ) ( v : int ) = + (new rat_num ctx)#cnstr_obj (Z3native.mk_int ctx#gno v (mk_real_sort ctx)#gno) + + (** + Create an integer numeral. + @param v A string representing the Term value in decimal notation. + *) + let mk_int_numeral_s ( ctx : context ) ( v : string ) = + (new int_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_int_sort ctx)#gno) + + (** + Create an integer numeral. + @param v value of the numeral. + @return A Term with value and sort Integer + *) + let mk_int_numeral_i ( ctx : context ) ( v : int ) = + (new int_num ctx)#cnstr_obj (Z3native.mk_int ctx#gno v (mk_int_sort ctx)#gno) + (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno end @@ -3386,10 +3595,18 @@ struct *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow ctx#gno t1#gno t2#gno) - + + (** + Create a bit-vector numeral. + + @param v A string representing the value in decimal notation. + @param size the size of the bit-vector + *) + let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = + (new bitvec_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_sort ctx size)#gno) end -(** Functions to manipulate Proof objects *) +(** Functions to manipulate proof expressions *) module Proofs = struct (** @@ -4567,933 +4784,654 @@ end (* STUFF FROM THE CONTEXT *) (** - -(* NUMERALS *) - -(* GENERAL NUMERALS *) -(** - Create a Term of a given sort. -*) - @param v 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]*. - @param ty 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) - - create_expr ctx (Z3native.mk_numeral ctx#gno v, ty#gno) - -(** - 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. -*) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(int v, Sort ty) - - create_expr ctx (Z3native.mk_int ctx#gno v, ty#gno) - -(** - 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. -*) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(uint v, Sort ty) - - create_expr ctx (Z3native.mk_unsigned_int ctx#gno v, ty#gno) - -(** - 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. -*) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(long v, Sort ty) - - create_expr ctx (Z3native.mk_int64 ctx#gno v, ty#gno) - -(** - 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. -*) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(ulong v, Sort ty) - - create_expr ctx (Z3native.mk_unsigned_int64 ctx#gno v, ty#gno) - -(* REALS *) -(** - Create a real from a fraction. -*) - @param num numerator of rational. - @param den 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"); - - new RatNum(this, Z3native.mk_real ctx#gno num, den) - -(** - Create a real numeral. -*) - @param v A string representing the Term value in decimal notation. - @return A Term with value and sort Real - public RatNum MkReal(string v) - - new RatNum(this, Z3native.mk_numeral ctx#gno v, RealSort#gno) - -(** - Create a real numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(int v) - - new RatNum(this, Z3native.mk_int ctx#gno v, RealSort#gno) - -(** - Create a real numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(uint v) - - new RatNum(this, Z3native.mk_unsigned_int ctx#gno v, RealSort#gno) - -(** - Create a real numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(long v) - - new RatNum(this, Z3native.mk_int64 ctx#gno v, RealSort#gno) - -(** - Create a real numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(ulong v) - - new RatNum(this, Z3native.mk_unsigned_int64 ctx#gno v, RealSort#gno) - -(* INTEGERS *) -(** - Create an integer numeral. -*) - @param v A string representing the Term value in decimal notation. - public IntNum MkInt(string v) - - new IntNum(this, Z3native.mk_numeral ctx#gno v, IntSort#gno) - -(** - Create an integer numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(int v) - - new IntNum(this, Z3native.mk_int ctx#gno v, IntSort#gno) - -(** - Create an integer numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(uint v) - - new IntNum(this, Z3native.mk_unsigned_int ctx#gno v, IntSort#gno) - -(** - Create an integer numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(long v) - - new IntNum(this, Z3native.mk_int64 ctx#gno v, IntSort#gno) - -(** - Create an integer numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(ulong v) - - new IntNum(this, Z3native.mk_unsigned_int64 ctx#gno v, IntSort#gno) - -(* BIT-VECTORS *) -(** - Create a bit-vector numeral. -*) - @param v A string representing the value in decimal notation. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) string v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - -(** - Create a bit-vector numeral. -*) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) int v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - -(** - Create a bit-vector numeral. -*) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) uint v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - -(** - Create a bit-vector numeral. -*) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) long v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - -(** - Create a bit-vector numeral. -*) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) ulong v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - - // Numerals - -(* QUANTIFIERS *) -(** - 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. -*) - @param sorts the sorts of the bound variables. - @param names names of the bound variables - @param body the body of the quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param patterns array containing the patterns created using MkPattern. - @param noPatterns array containing the anti-patterns created using MkPattern. - @param quantifierID optional symbol to track quantifier. - @param skolemID optional symbol to track skolem constants. - public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create a universal Quantifier. -*) - public Quantifier MkForall(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - new Quantifier(this, true, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create an existential Quantifier. -*) - - public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create an existential Quantifier. -*) - public Quantifier MkExists(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create a Quantifier. -*) - public Quantifier MkQuantifier(bool universal, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - if (universal) - MkForall(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - MkExists(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create a Quantifier. -*) - public Quantifier MkQuantifier(bool universal, Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - if (universal) - MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - - // Expr - (* OPTIONS *) (** - 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. + 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 Z3_ast_print_mode PrintMode + + + + + public Z3_ast_print_mode PrintMode - set { Z3native.set_ast_print_mode ctx#gno (uint)value); } + set { Z3native.set_ast_print_mode ctx#gno (uint)value); } (* SMT Files & Strings *) (** - Convert a benchmark into an SMT-LIB formatted string. + Convert a benchmark into an SMT-LIB formatted string. *) - @param name Name of the benchmark. The argument is optional. - @param logic The benchmark logic. - @param status The status string (sat, unsat, or unknown) - @param attributes Other attributes, such as source, difficulty or category. - @param assumptions Auxiliary assumptions. - @param formula 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) + @param name Name of the benchmark. The argument is optional. + @param logic The benchmark logic. + @param status The status string (sat, unsat, or unknown) + @param attributes Other attributes, such as source, difficulty or category. + @param assumptions Auxiliary assumptions. + @param formula 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) - Z3native.benchmark_to_smtlib_string ctx#gno name, logic, status, attributes, - (uint)assumptions.Length, AST.ArrayToNative(assumptions), - formula#gno); + Z3native.benchmark_to_smtlib_string ctx#gno name, logic, status, attributes, + (uint)assumptions.Length, AST.ArrayToNative(assumptions), + formula#gno); (** - 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. + 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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + public void ParseSMTLIBString(string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_string ctx#gno str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls) + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_string ctx#gno 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. + Parse the given file using the SMT-LIB parser. *) - - public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_file ctx#gno fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls) + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_file ctx#gno 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. + The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBFormulas { get {Z3native.get_smtlib_num_formulas ctx#gno)) + public uint NumSMTLIBFormulas { get {Z3native.get_smtlib_num_formulas ctx#gno)) (** - The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let[] SMTLIBFormulas + let[] SMTLIBFormulas - get + get - uint n = NumSMTLIBFormulas; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_formula ctx#gno i) - res; + uint n = NumSMTLIBFormulas; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_formula ctx#gno i) + res; (** - The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBAssumptions { get {Z3native.get_smtlib_num_assumptions ctx#gno)) + public uint NumSMTLIBAssumptions { get {Z3native.get_smtlib_num_assumptions ctx#gno)) (** - The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let[] SMTLIBAssumptions + let[] SMTLIBAssumptions - get + get - uint n = NumSMTLIBAssumptions; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i) - res; + uint n = NumSMTLIBAssumptions; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i) + res; (** - The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBDecls { get {Z3native.get_smtlib_num_decls ctx#gno)) + public uint NumSMTLIBDecls { get {Z3native.get_smtlib_num_decls ctx#gno)) (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public Func_Decl[] SMTLIBDecls + public Func_Decl[] SMTLIBDecls - get + get - uint n = NumSMTLIBDecls; - Func_Decl[] res = new Func_Decl[n]; - for (uint i = 0; i < n; i++) - res[i] = new Func_Decl(this, Z3native.get_smtlib_decl ctx#gno i) - res; + uint n = NumSMTLIBDecls; + Func_Decl[] res = new Func_Decl[n]; + for (uint i = 0; i < n; i++) + res[i] = new Func_Decl(this, Z3native.get_smtlib_decl ctx#gno i) + res; (** - The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBSorts { get {Z3native.get_smtlib_num_sorts ctx#gno)) + public uint NumSMTLIBSorts { get {Z3native.get_smtlib_num_sorts ctx#gno)) (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public Sort[] SMTLIBSorts + public Sort[] SMTLIBSorts - get + get - uint n = NumSMTLIBSorts; - Sort[] res = new Sort[n]; - for (uint i = 0; i < n; i++) - res[i] = Sort.Create(this, Z3native.get_smtlib_sort ctx#gno i) - res; + uint n = NumSMTLIBSorts; + Sort[] res = new Sort[n]; + for (uint i = 0; i < n; i++) + res[i] = Sort.Create(this, Z3native.get_smtlib_sort ctx#gno i) + res; (** - Parse the given string using the SMT-LIB2 parser. + 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. - let ParseSMTLIB2String ( ctx : context ) string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. + let ParseSMTLIB2String ( ctx : context ) string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_string ctx#gno str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_string ctx#gno 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. + Parse the given file using the SMT-LIB2 parser. *) - - let ParseSMTLIB2File ( ctx : context ) string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + let ParseSMTLIB2File ( ctx : context ) string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_file ctx#gno fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_file ctx#gno fileName, + AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) (* GOALS *) (** - Creates a new Goal. - - Note that the Context must have been created with proof generation support if - is set to true here. + Creates a new Goal. + + Note that the Context must have been created with proof generation support if + is set to true here. *) - @param models Indicates whether model generation should be enabled. - @param unsatCores Indicates whether unsat core generation should be enabled. - @param proofs Indicates whether proof generation should be enabled. - public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) + @param models Indicates whether model generation should be enabled. + @param unsatCores Indicates whether unsat core generation should be enabled. + @param proofs Indicates whether proof generation should be enabled. + public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) - new Goal(this, models, unsatCores, proofs); + new Goal(this, models, unsatCores, proofs); (* PARAMETERSETS *) (** - Creates a new ParameterSet. + Creates a new ParameterSet. *) - public Params MkParams ( ctx : context ) = + public Params MkParams ( ctx : context ) = - new Params(this); + new Params(this); (* TACTICS *) (** - The number of supported tactics. + The number of supported tactics. *) - public uint NumTactics + public uint NumTactics - get {Z3native.get_num_tactics ctx#gno); } + get {Z3native.get_num_tactics ctx#gno); } (** - The names of all supported tactics. + The names of all supported tactics. *) - public string[] TacticNames + public string[] TacticNames - get + get - uint n = NumTactics; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_tactic_name ctx#gno i); - res; + uint n = NumTactics; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_tactic_name ctx#gno i); + res; (** - Returns a string containing a description of the tactic with the given name. + Returns a string containing a description of the tactic with the given name. *) - public string TacticDescription(string name) + public string TacticDescription(string name) - Z3native.tactic_get_descr ctx#gno name); + Z3native.tactic_get_descr ctx#gno name); (** - Creates a new Tactic. + Creates a new Tactic. *) - public Tactic MkTactic(string name) + public Tactic MkTactic(string name) - new Tactic(this, name); + new Tactic(this, name); (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . + Create a tactic that applies to a Goal and + then to every subgoal produced by . *) - public Tactic AndThen(Tactic t1, Tactic t2, params Tactic[] ts) + public Tactic AndThen(Tactic t1, Tactic t2, params Tactic[] ts) - IntPtr last = IntPtr.Zero; - if (ts != null && ts.Length > 0) + IntPtr last = IntPtr.Zero; + if (ts != null && ts.Length > 0) - last = ts[ts.Length - 1]#gno; - for (int i = ts.Length - 2; i >= 0; i--) - last = Z3native.tactic_and_then ctx#gno ts[i]#gno last); + last = ts[ts.Length - 1]#gno; + for (int i = ts.Length - 2; i >= 0; i--) + last = Z3native.tactic_and_then ctx#gno ts[i]#gno last); - if (last != IntPtr.Zero) + if (last != IntPtr.Zero) - last = Z3native.tactic_and_then ctx#gno t2#gno last); - new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno last) + last = Z3native.tactic_and_then ctx#gno t2#gno last); + new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno last) - else - new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno t2#gno) + else + new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno t2#gno) (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . - - Shorthand for AndThen. + 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, params Tactic[] ts) + public Tactic Then(Tactic t1, Tactic t2, params Tactic[] ts) - AndThen(t1, t2, ts); + 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. + 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) + public Tactic OrElse(Tactic t1, Tactic t2) - new Tactic(this, Z3native.tactic_or_else ctx#gno t1#gno t2#gno) + new Tactic(this, Z3native.tactic_or_else ctx#gno t1#gno t2#gno) (** - Create a tactic that applies to a goal for milliseconds. - - If does not terminate within milliseconds, then it fails. + Create a tactic that applies to a goal for milliseconds. + + If does not terminate within milliseconds, then it fails. *) - public Tactic TryFor(Tactic t, uint ms) + public Tactic TryFor(Tactic t, uint ms) - new Tactic(this, Z3native.tactic_try_for ctx#gno t#gno ms) + new Tactic(this, Z3native.tactic_try_for ctx#gno t#gno 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. + 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) + public Tactic When(Probe p, Tactic t) - new Tactic(this, Z3native.tactic_when ctx#gno p#gno t#gno) + new Tactic(this, Z3native.tactic_when ctx#gno p#gno t#gno) (** - Create a tactic that applies to a given goal if the probe - evaluates to true and otherwise. + 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) + public Tactic Cond(Probe p, Tactic t1, Tactic t2) - new Tactic(this, Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) + new Tactic(this, Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) (** - Create a tactic that keeps applying until the goal is not - modified anymore or the maximum number of iterations is reached. + 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, uint max = uint.MaxValue) + public Tactic Repeat(Tactic t, uint max = uint.MaxValue) - new Tactic(this, Z3native.tactic_repeat ctx#gno t#gno max) + new Tactic(this, Z3native.tactic_repeat ctx#gno t#gno max) (** - Create a tactic that just returns the given goal. + Create a tactic that just returns the given goal. *) - public Tactic Skip ( ctx : context ) = + public Tactic Skip ( ctx : context ) = - new Tactic(this, Z3native.tactic_skip ctx#gno) + new Tactic(this, Z3native.tactic_skip ctx#gno) (** - Create a tactic always fails. + Create a tactic always fails. *) - public Tactic Fail ( ctx : context ) = + public Tactic Fail ( ctx : context ) = - new Tactic(this, Z3native.tactic_fail ctx#gno) + new Tactic(this, Z3native.tactic_fail ctx#gno) (** - Create a tactic that fails if the probe evaluates to false. + Create a tactic that fails if the probe evaluates to false. *) - public Tactic FailIf(Probe p) + public Tactic FailIf(Probe p) - new Tactic(this, Z3native.tactic_fail_if ctx#gno p#gno) + new Tactic(this, Z3native.tactic_fail_if ctx#gno p#gno) (** - Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). + 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 ( ctx : context ) = + public Tactic FailIfNotDecided ( ctx : context ) = - new Tactic(this, Z3native.tactic_fail_if_not_decided ctx#gno) + new Tactic(this, Z3native.tactic_fail_if_not_decided ctx#gno) (** - Create a tactic that applies using the given set of parameters . + Create a tactic that applies using the given set of parameters . *) - public Tactic UsingParams(Tactic t, Params p) + public Tactic UsingParams(Tactic t, Params p) - new Tactic(this, Z3native.tactic_using_params ctx#gno t#gno p#gno) + new Tactic(this, Z3native.tactic_using_params ctx#gno t#gno p#gno) (** - Create a tactic that applies using the given set of parameters . - Alias for UsingParams*) - public Tactic With(Tactic t, Params p) + Create a tactic that applies using the given set of parameters . + Alias for UsingParams*) + public Tactic With(Tactic t, Params p) - UsingParams(t, p); + UsingParams(t, p); (** - Create a tactic that applies the given tactics in parallel. + Create a tactic that applies the given tactics in parallel. *) - public Tactic ParOr(params Tactic[] t) + public Tactic ParOr(params Tactic[] t) - new Tactic(this, Z3native.tactic_par_or ctx#gno Tactic.ArrayLength(t), Tactic.ArrayToNative(t)) + new Tactic(this, Z3native.tactic_par_or ctx#gno 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. + 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) + public Tactic ParAndThen(Tactic t1, Tactic t2) - new Tactic(this, Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) + new Tactic(this, Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) (** - Interrupt the execution of a Z3 procedure. + Interrupt the execution of a Z3 procedure. *) - This procedure can be used to interrupt: solvers, simplifiers and tactics. - public void Interrupt ( ctx : context ) = + This procedure can be used to interrupt: solvers, simplifiers and tactics. + public void Interrupt ( ctx : context ) = - Z3native.interrupt ctx#gno); + Z3native.interrupt ctx#gno); (* PROBES *) (** - The number of supported Probes. + The number of supported Probes. *) - public uint NumProbes + public uint NumProbes - get {Z3native.get_num_probes ctx#gno); } + get {Z3native.get_num_probes ctx#gno); } (** - The names of all supported Probes. + The names of all supported Probes. *) - public string[] ProbeNames + public string[] ProbeNames - get + get - uint n = NumProbes; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_probe_name ctx#gno i); - res; + uint n = NumProbes; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_probe_name ctx#gno i); + res; (** - Returns a string containing a description of the probe with the given name. + Returns a string containing a description of the probe with the given name. *) - public string ProbeDescription(string name) + public string ProbeDescription(string name) - Z3native.probe_get_descr ctx#gno name); + Z3native.probe_get_descr ctx#gno name); (** - Creates a new Probe. + Creates a new Probe. *) - public Probe MkProbe(string name) + public Probe MkProbe(string name) - new Probe(this, name); + new Probe(this, name); (** - Create a probe that always evaluates to . + Create a probe that always evaluates to . *) - public Probe Const(double val) + public Probe Const(double val) - new Probe(this, Z3native.probe_const ctx#gno val) + new Probe(this, Z3native.probe_const ctx#gno val) (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by + 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) + public Probe Lt(Probe p1, Probe p2) - new Probe(this, Z3native.probe_lt ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_lt ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by + 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) + public Probe Gt(Probe p1, Probe p2) - new Probe(this, Z3native.probe_gt ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_gt ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by + 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) + public Probe Le(Probe p1, Probe p2) - new Probe(this, Z3native.probe_le ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_le ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by + 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) + public Probe Ge(Probe p1, Probe p2) - new Probe(this, Z3native.probe_ge ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_ge ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by + 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) + public Probe Eq(Probe p1, Probe p2) - new Probe(this, Z3native.probe_eq ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_eq ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". + Create a probe that evaluates to "true" when the value + and evaluate to "true". *) - public Probe And(Probe p1, Probe p2) + public Probe And(Probe p1, Probe p2) - new Probe(this, Z3native.probe_and ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_and ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". + Create a probe that evaluates to "true" when the value + or evaluate to "true". *) - public Probe Or(Probe p1, Probe p2) + public Probe Or(Probe p1, Probe p2) - new Probe(this, Z3native.probe_or ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_or ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". + Create a probe that evaluates to "true" when the value + does not evaluate to "true". *) - public Probe Not(Probe p) + public Probe Not(Probe p) - new Probe(this, Z3native.probe_not ctx#gno p#gno) + new Probe(this, Z3native.probe_not ctx#gno p#gno) (* SOLVERS *) (** - 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. + 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 = null) + public Solver MkSolver(Symbol logic = null) - if (logic == null) - new Solver(this, Z3native.mk_solver ctx#gno) - else - new Solver(this, Z3native.mk_solver_for_logic ctx#gno logic#gno) + if (logic == null) + new Solver(this, Z3native.mk_solver ctx#gno) + else + new Solver(this, Z3native.mk_solver_for_logic ctx#gno logic#gno) (** - Creates a new (incremental) solver. + Creates a new (incremental) solver. *) - - public Solver MkSolver(string logic) + + public Solver MkSolver(string logic) - MkSolver(MkSymbol(logic) + MkSolver(MkSymbol(logic) (** - Creates a new (incremental) solver. + Creates a new (incremental) solver. *) - let mk_Simple_Solver ( ctx : context ) ctx : context ) = + let mk_Simple_Solver( ctx : context ) ctx : context ) = - new Solver(this, Z3native.mk_simple_solver ctx#gno) + new Solver(this, Z3native.mk_simple_solver ctx#gno) (** - 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. + 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) + public Solver MkSolver(Tactic t) - new Solver(this, Z3native.mk_solver_from_tactic ctx#gno t#gno) + new Solver(this, Z3native.mk_solver_from_tactic ctx#gno t#gno) (* FIXEDPOINTS *) (** - Create a Fixedpoint context. + Create a Fixedpoint context. *) - public Fixedpoint MkFixedpoint ( ctx : context ) = + public Fixedpoint MkFixedpoint ( ctx : context ) = - new Fixedpoint(this); + new Fixedpoint(this); (* MISCELLANEOUS *) (** - Wraps an AST. + 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., - . - - @param nativeObject The native pointer to wrap. - public AST WrapAST(IntPtr nativeObject) + 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., + . + + @param nativeObject The native pointer to wrap. + public AST WrapAST(IntPtr nativeObject) - AST.Create(this, nativeObject); + AST.Create(this, nativeObject); (** - Unwraps an AST. + 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., - ). - - @param a The AST to unwrap. - public IntPtr UnwrapAST(AST a) + 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., + ). + + @param a The AST to unwrap. + public IntPtr UnwrapAST(AST a) - a#gno; + a#gno; (** - a string describing all available parameters to Expr.Simplify. + a string describing all available parameters to Expr.Simplify. *) - public string SimplifyHelp ( ctx : context ) = + public string SimplifyHelp ( ctx : context ) = - Z3native.simplify_get_help ctx#gno); + Z3native.simplify_get_help ctx#gno); (** - Retrieves parameter descriptions for simplifier. + Retrieves parameter descriptions for simplifier. *) - public ParamDescrs SimplifyParameterDescriptions + public ParamDescrs SimplifyParameterDescriptions - get {new ParamDescrs(this, Z3native.simplify_get_param_descrs ctx#gno)); } + get {new ParamDescrs(this, Z3native.simplify_get_param_descrs ctx#gno)); } (** - Enable/disable printing of warning messages to the console. + 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(bool enabled) + Note that this function is static and effects the behaviour of + all contexts globally. + public static void ToggleWarningMessages(bool enabled) - Z3native.toggle_warning_messages((enabled) ? 1 : 0); + Z3native.toggle_warning_messages((enabled) ? 1 : 0); (* ERROR HANDLING *) (** - 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. + 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); + public delegate void ErrorHandler(Context ctx, Z3_error_code errorCode, string errorString); (** - The OnError event. + The OnError event. *) - public event ErrorHandler OnError = null; + public event ErrorHandler OnError = null; (* PARAMETERS *) (** - 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. + 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) + + public void UpdateParamValue(string id, string value) - Z3native.update_param_value ctx#gno id, value); + Z3native.update_param_value ctx#gno id, value); (** - Get a configuration parameter. - - Returns null if the parameter value does not exist. - + Get a configuration parameter. + + Returns null if the parameter value does not exist. + *) - public string GetParamValue(string id) + public string GetParamValue(string id) - IntPtr res = IntPtr.Zero; - int r = Z3native.get_param_value ctx#gno id, out res); - if (r == (int)Z3_lbool.L_FALSE) - null; - else - Marshal.PtrToStringAnsi(res); + IntPtr res = IntPtr.Zero; + int r = Z3native.get_param_value ctx#gno id, out res); + if (r == (int)Z3_lbool.L_FALSE) + null; + else + Marshal.PtrToStringAnsi(res); (* INTERNAL *) - internal IntPtr m_ctx = IntPtr.Zero; - internal Z3native.error_handler m_n_err_handler = null; - internal IntPtr nCtx { get {m_ctx) + internal IntPtr m_ctx = IntPtr.Zero; + internal Z3native.error_handler m_n_err_handler = null; + internal IntPtr nCtx { get {m_ctx) - internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) + internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) - Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. + Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. - internal void InitContext ( ctx : context ) = + internal void InitContext ( ctx : context ) = - PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); + PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); *) - From 39e538a8bc4bb2c1dbf7cbdd0b65576d101d5224 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 24 Dec 2012 02:47:41 +0000 Subject: [PATCH 027/248] More new ML API; Status: everything is there except for error handling. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 1498 +++++++++++++++++++++++++--------------------- 1 file changed, 809 insertions(+), 689 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index f6454b797..088bfbd6f 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,33 +7,52 @@ open Z3enums -(**/**) +(** Context objects. -class virtual idisposable = -object - method virtual dispose : unit -end +Most interactions with Z3 are interpreted in some context; most users will only +require one such object, but power users may require more than one. To start using +Z3, do -(** Context objects *) + + let ctx = (new context [||]) in + (...) + + +where [||] is a (possibly empty) list of pairs of strings, which can +be used to set options on the context, e.g., like so: + + + let cfg = [("model", "true"); ("...", "...")] in + let ctx = (new context cfg) in + (...) + + +*) class context settings = +(**/**) object (self) - inherit idisposable - val mutable m_n_ctx : Z3native.z3_context = let cfg = Z3native.mk_config in let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; let v = Z3native.mk_context_rc cfg in Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; v +(* CMW: Install error handler here! + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); +*) + val mutable m_obj_cnt : int = 0 initializer (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) let f = fun o -> o#dispose in let v = self in - Gc.finalise f v + Gc.finalise f v; method dispose : unit = if m_obj_cnt == 0 then ( @@ -47,13 +66,14 @@ object (self) method add_one_ctx_obj = m_obj_cnt <- m_obj_cnt + 1 method sub_one_ctx_obj = m_obj_cnt <- m_obj_cnt - 1 method gno = m_n_ctx +(**/**) end +(**/**) (** Z3 objects *) class virtual z3object ctx_init obj_init = object (self) - inherit idisposable val mutable m_ctx : context = ctx_init val mutable m_n_obj : Z3native.ptr option = obj_init @@ -100,9 +120,10 @@ end (** Parameter set objects *) -class params ctx obj = +class params ctx = object (self) - inherit z3object ctx obj as super + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self method incref nc o = Z3native.params_inc_ref nc o method decref nc o = Z3native.params_dec_ref nc o end @@ -264,6 +285,10 @@ object (self) method decref nc o = super#decref nc o end +let func_declaton (a : func_decl array) = + let f (e : func_decl) = e#gno in + Array.map f a + class parameter = object (self) val mutable m_kind : parameter_kind = PARAMETER_INT; @@ -624,6 +649,10 @@ object (self) method decref nc o = Z3native.tactic_dec_ref nc o end +let tacticaton (a : tactic array) = + let f (e : tactic) = e#gno in + Array.map f a + (** Function interpretation entry objects *) class func_entry ctx = object (self) @@ -715,6 +744,15 @@ object (self) method decref nc o = Z3native.solver_dec_ref nc o end +(** Fixedpoint objects *) +class fixedpoint ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.fixedpoint_inc_ref nc o + method decref nc o = Z3native.fixedpoint_dec_ref nc o +end + (**/**) @@ -1294,6 +1332,33 @@ struct x else (create_ast to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno)) + +(** + 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., + . + + @param nativeObject The native pointer to wrap. +*) + let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = + create_ast ctx ptr + +(** + 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., + ). + + @param a The AST to unwrap. +*) + let unwrap_ast ( a : ast ) = a#gno end (** General expressions (terms), including Boolean logic *) @@ -1308,6 +1373,18 @@ struct | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno pp#gno) +(** + a string describing all available parameters to Expr.Simplify. +*) + let get_simplify_help ( ctx : context ) = + Z3native.simplify_get_help ctx#gno + +(** + Retrieves parameter descriptions for simplifier. +*) + let get_simplify_parameter_descrs ( ctx : context ) = + (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs ctx#gno) + (** The function declaration of the function that is applied in this expression. *) @@ -4087,6 +4164,30 @@ end *) module Params = struct +(** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) +module ParamDescrs = +struct + + (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno + + (** Retrieve kind of parameter. *) + let get_kind ( x : param_descrs ) ( name : symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) + + (** Retrieve all names of parameters. *) + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size x#gnc x#gno in + let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in + Array.init n f + + (** The size of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno + + (** Retrieves a string representation of the ParamDescrs. *) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno +end + (** Adds a parameter setting. *) @@ -4135,37 +4236,18 @@ struct let add_s_symbol (p : params) (name : string) (value : symbol) = add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + (** + Creates a new parameter set + *) + let mk_params ( ctx : context ) = + (new params ctx)#cnstr_obj (Z3native.mk_params ctx#gno) + (** A string representation of the parameter set. *) let to_string (p : params) = Z3native.params_to_string p#gnc p#gno end -(** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) -module ParamDescrs = -struct - - (** Validate a set of parameters. *) - let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno - - (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) - - (** Retrieve all names of parameters. *) - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size x#gnc x#gno in - let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in - Array.init n f - - (** The size of the ParamDescrs. *) - let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno - - (** Retrieves a string representation of the ParamDescrs. *) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno - -end - (** Goals A goal (aka problem). A goal is essentially a @@ -4258,6 +4340,22 @@ struct Z3native.tactic_dec_ref x#gnc tn ; (new goal x#gc)#cnstr_obj res + + (** + Creates a new Goal. + + Note that the Context must have been created with proof generation support if + is set to true here. + @param models Indicates whether model generation should be enabled. + @param unsat_cores Indicates whether unsat core generation should be enabled. + @param proofs Indicates whether proof generation should be enabled. + *) + let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = + (new goal ctx)#cnstr_obj (Z3native.mk_goal ctx#gno + (int_of_lbool (if models then L_TRUE else L_FALSE)) + (int_of_lbool (if unsat_cores then L_TRUE else L_FALSE)) + (int_of_lbool (if proofs then L_TRUE else L_FALSE))) + (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno end @@ -4272,6 +4370,33 @@ end *) module Tactic = struct +(** Tactic application results + + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) +module ApplyResult = +struct + (** The number of Subgoals. *) + let get_num_subgoals ( x : apply_result ) = + Z3native.apply_result_get_num_subgoals x#gnc x#gno + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoals ( x : apply_result ) = + let n = (get_num_subgoals x) in + let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in + Array.init n f + + (** 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 + *) + let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = + (new model x#gc)#cnstr_obj (Z3native.apply_result_convert_model x#gnc x#gno i m#gno) + + (** A string representation of the ApplyResult. *) + let to_string ( x : apply_result ) = Z3native.apply_result_to_string x#gnc x#gno +end + (** A string containing a description of parameters accepted by the tactic. *) let get_help ( x : tactic ) = Z3native.tactic_get_help x#gnc x#gno @@ -4291,6 +4416,147 @@ struct let get_solver ( x : tactic ) = (new solver x#gc)#cnstr_obj (Z3native.mk_solver_from_tactic x#gnc x#gno) + (** + The number of supported tactics. + *) + let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics ctx#gno + + (** + The names of all supported tactics. + *) + let get_tactic_names ( ctx : context ) = + let n = (get_num_tactics ctx ) in + let f i = (Z3native.get_tactic_name ctx#gno i) in + Array.init n f + + + (** + Returns a string containing a description of the tactic with the given name. + *) + let get_tactic_description ( ctx : context ) ( name : string ) = + Z3native.tactic_get_descr ctx#gno name + + (** + Creates a new Tactic. + *) + let mk_tactic ( ctx : context ) ( name : string ) = + (new tactic ctx)#cnstr_obj (Z3native.mk_tactic ctx#gno name) + + (** + Create a tactic that applies to a Goal and + then to every subgoal produced by . + *) + let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array option ) = + match + match ts with + | None -> None + | Some(rts) -> ( + let f p c = (match p with + | None -> (Some c#gno) + | Some(x) -> (Some (Z3native.tactic_and_then ctx#gno c#gno x))) in + Array.fold_left f None rts) + with + | None -> (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then ctx#gno t1#gno t2#gno) + | Some(x) -> + let o = (Z3native.tactic_and_then ctx#gno t2#gno x) in + (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then ctx#gno t1#gno o) + + (** + Create a tactic that first applies to a Goal and + if it fails then returns the result of applied to the Goal. + *) + let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_or_else ctx#gno t1#gno t2#gno) + + (** + Create a tactic that applies to a goal for milliseconds. + + If does not terminate within milliseconds, then it fails. + *) + let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_try_for ctx#gno t#gno 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. + *) + (* CMW: when is a keyword *) + let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_when ctx#gno p#gno t#gno) + + (** + Create a tactic that applies to a given goal if the probe + evaluates to true and otherwise. + *) + let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) + + (** + Create a tactic that keeps applying until the goal is not + modified anymore or the maximum number of iterations is reached. + *) + let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_repeat ctx#gno t#gno max) + + (** + Create a tactic that just returns the given goal. + *) + let skip ( ctx : context ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_skip ctx#gno) + + (** + Create a tactic always fails. + *) + let fail ( ctx : context ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail ctx#gno) + + (** + Create a tactic that fails if the probe evaluates to false. + *) + let fail_if ( ctx : context ) ( p : probe ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if ctx#gno p#gno) + + (** + Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) + or trivially unsatisfiable (i.e., contains `false'). + *) + let fail_if_not_decided ( ctx : context ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if_not_decided ctx#gno) + + (** + Create a tactic that applies using the given set of parameters . + *) + let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_using_params ctx#gno t#gno p#gno) + + (** + Create a tactic that applies using the given set of parameters . + Alias for UsingParams*) + (* CMW: with is a keyword *) + let with_ ( ctx : context ) ( t : tactic ) ( p : params ) = + using_params ctx t p + + (** + Create a tactic that applies the given tactics in parallel. + *) + let par_or ( ctx : context ) ( t : tactic array ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_par_or ctx#gno (Array.length t) (tacticaton t)) + + (** + Create a tactic that applies to a given goal and then + to every subgoal produced by . The subgoals are processed in parallel. + *) + let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) + + (** + Interrupt the execution of a Z3 procedure. + This procedure can be used to interrupt: solvers, simplifiers and tactics. + *) + let interrupt ( ctx : context ) = + Z3native.interrupt ctx#gno end (** Models @@ -4337,7 +4603,7 @@ struct let to_string ( x : func_entry ) = let a = (get_args x) in let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]]") + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") end (** @@ -4513,33 +4779,6 @@ struct let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno end -(** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) -module ApplyResult = -struct - (** The number of Subgoals. *) - let get_num_subgoals ( x : apply_result ) = - Z3native.apply_result_get_num_subgoals x#gnc x#gno - - (** Retrieves the subgoals from the apply_result. *) - let get_subgoals ( x : apply_result ) = - let n = (get_num_subgoals x) in - let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in - Array.init n f - - (** 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 - *) - let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = - (new model x#gc)#cnstr_obj (Z3native.apply_result_convert_model x#gnc x#gno i m#gno) - - (** A string representation of the ApplyResult. *) - let to_string ( x : apply_result) = Z3native.apply_result_to_string x#gnc x#gno -end - (** Solvers *) module Solver = struct @@ -4615,10 +4854,8 @@ struct let get ( x : statistics ) ( key : string ) = let f p c = (if (Entry.get_key c) = key then (Some c) else p) in Array.fold_left f None (get_entries x) - end - (** A string that describes all available solver parameters. *) @@ -4755,12 +4992,222 @@ struct let get_statistics ( x : solver ) = (new statistics x#gc)#cnstr_obj (Z3native.solver_get_statistics x#gnc x#gno) + (** + 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. + *) + let mk_solver ( ctx : context ) ( logic : symbol option) = + match logic with + | None -> (new solver ctx)#cnstr_obj (Z3native.mk_solver ctx#gno) + | Some (x) -> (new solver ctx)#cnstr_obj (Z3native.mk_solver_for_logic ctx#gno x#gno) + + (** + Creates a new (incremental) solver. + + *) + let mk_solver_s ( ctx : context ) ( logic : string ) = + mk_solver ctx (Some ((Symbol.mk_string ctx logic) :> symbol)) + + (** + Creates a new (incremental) solver. + *) + let mk_simple_solver ( ctx : context ) = + (new solver ctx)#cnstr_obj (Z3native.mk_simple_solver ctx#gno) + + (** + 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. + *) + let mk_solver_t ( ctx : context ) ( t : tactic ) = + (new solver ctx)#cnstr_obj (Z3native.mk_solver_from_tactic ctx#gno t#gno) + (** A string representation of the solver. *) let to_string ( x : solver ) = Z3native.solver_to_string x#gnc x#gno end +(** Fixedpoint solving *) +module Fixedpoints = +struct + (** + A string that describes all available fixedpoint solver parameters. + *) + let get_help ( x : fixedpoint ) = + Z3native.fixedpoint_get_help x#gnc x#gno + + (** + Sets the fixedpoint solver parameters. + *) + let set_params ( x : fixedpoint ) ( p : params )= + Z3native.fixedpoint_set_params x#gnc x#gno p#gno + + (** + Retrieves parameter descriptions for Fixedpoint solver. + *) + let get_param_descrs ( x : fixedpoint ) = + (new param_descrs x#gc)#cnstr_obj (Z3native.fixedpoint_get_param_descrs x#gnc x#gno) + + (** + Assert a constraints into the fixedpoint solver. + *) + let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = + let f e = (Z3native.fixedpoint_assert x#gnc x#gno e#gno) in + Array.map f constraints + + (** + Register predicate as recursive relation. + *) + let register_relation ( x : fixedpoint ) ( f : func_decl ) = + Z3native.fixedpoint_register_relation x#gnc x#gno f#gno + + (** + Add rule into the fixedpoint solver. + *) + let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = + match name with + | None -> Z3native.fixedpoint_add_rule x#gnc x#gno rule#gno (Z3native.mk_null()) + | Some(y) -> Z3native.fixedpoint_add_rule x#gnc x#gno rule#gno y#gno + + (** + Add table fact to the fixedpoint solver. + *) + let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = + Z3native.fixedpoint_add_fact x#gnc x#gno pred#gno (Array.length args) 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. + *) + let query ( x : fixedpoint ) ( query : bool_expr ) = + match (lbool_of_int (Z3native.fixedpoint_query x#gnc x#gno query#gno)) with + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.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. + *) + let query_r ( x : fixedpoint ) ( relations : func_decl array ) = + match (lbool_of_int (Z3native.fixedpoint_query_relations x#gnc x#gno (Array.length relations) (func_declaton relations))) with + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN + + (** + Creates a backtracking point. + + *) + let push ( x : fixedpoint ) = + Z3native.fixedpoint_push x#gnc x#gno + + (** + Backtrack one backtracking point. + + Note that an exception is thrown if Pop is called without a corresponding Push + + *) + let pop ( x : fixedpoint ) = + Z3native.fixedpoint_pop x#gnc x#gno + + (** + Update named rule into in the fixedpoint solver. + *) + let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = + Z3native.fixedpoint_update_rule x#gnc x#gno rule#gno name#gno + + (** + Retrieve satisfying instance or instances of solver, + or definitions for the recursive predicates that show unsatisfiability. + *) + let get_answer ( x : fixedpoint ) = + let q = (Z3native.fixedpoint_get_answer x#gnc x#gno) in + if (Z3native.is_null q) then + None + else + Some (create_expr x#gc q) + + (** + Retrieve explanation why fixedpoint engine returned status Unknown. + *) + let get_reason_unknown ( x : fixedpoint ) = + Z3native.fixedpoint_get_reason_unknown x#gnc x#gno + + (** + Retrieve the number of levels explored for a given predicate. + *) + let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = + Z3native.fixedpoint_get_num_levels x#gnc x#gno predicate#gno + + (** + Retrieve the cover of a predicate. + *) + let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = + let q = (Z3native.fixedpoint_get_cover_delta x#gnc x#gno level predicate#gno) in + if (Z3native.is_null q) then + None + else + Some (create_expr x#gc q) + + (** + Add property about the predicate. + The property is added at level. + *) + let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = + Z3native.fixedpoint_add_cover x#gnc x#gno level predicate#gno, property#gno + + (** + Retrieve internal string representation of fixedpoint object. + *) + let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string x#gnc x#gno 0 [||] + + (** + Instrument the Datalog engine on which table representation to use for recursive predicate. + *) + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = + Z3native.fixedpoint_set_predicate_representation x#gnc x#gno f#gno (Array.length kinds) (symbolaton kinds) + + (** + Convert benchmark given as set of axioms, rules and queries to a string. + *) + let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = + Z3native.fixedpoint_to_string x#gnc x#gno (Array.length queries) (astaton queries) + + (** + Retrieve set of rules added to fixedpoint context. + *) + let get_rules ( x : fixedpoint ) = + let v = ((new ast_vector x#gc)#cnstr_obj (Z3native.fixedpoint_get_rules x#gnc x#gno)) in + let n = (AST.ASTVector.get_size v) in + let f i = (new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get v i)#gno in + Array.init n f + + (** + Retrieve set of assertions added to fixedpoint context. + *) + let get_assertions ( x : fixedpoint ) = + let v = ((new ast_vector x#gc)#cnstr_obj (Z3native.fixedpoint_get_assertions x#gnc x#gno)) in + let n = (AST.ASTVector.get_size v) in + let f i = (new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get v i)#gno in + Array.init n f + + (** + Create a Fixedpoint context. + *) + let mk_fixedpoint ( ctx : context ) = + (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint ctx#gno) +end + (** Probes Probes are used to inspect a goal (aka problem) and collect information that may be used to decide @@ -4778,660 +5225,333 @@ struct *) let apply ( x : probe ) (g : goal) = Z3native.probe_apply x#gnc x#gno g#gno + + (** + The number of supported Probes. + *) + let get_num_probes ( ctx : context ) = + Z3native.get_num_probes ctx#gno + + (** + The names of all supported Probes. + *) + let get_probe_names ( ctx : context ) = + let n = (get_num_probes ctx) in + let f i = (Z3native.get_probe_name ctx#gno i) in + Array.init n f + + (** + Returns a string containing a description of the probe with the given name. + *) + let get_probe_description ( ctx : context ) ( name : string ) = + Z3native.probe_get_descr ctx#gno name + + (** + Creates a new Probe. + *) + let mk_probe ( ctx : context ) ( name : string ) = + (new probe ctx)#cnstr_obj (Z3native.mk_probe ctx#gno name) + + (** + Create a probe that always evaluates to . + *) + let const ( ctx : context ) ( v : float ) = + (new probe ctx)#cnstr_obj (Z3native.probe_const ctx#gno v) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than the value returned by + *) + let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_lt ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than the value returned by + *) + let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_gt ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than or equal the value returned by + *) + let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_le ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than or equal the value returned by + *) + let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_ge ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is equal to the value returned by + *) + let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_eq ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + and evaluate to "true". + *) + (* CMW: and is a keyword *) + let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_and ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + or evaluate to "true". + *) + (* CMW: or is a keyword *) + let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_or ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + does not evaluate to "true". + *) + (* CMW: is not a keyword? *) + let not_ ( ctx : context ) ( p : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_not ctx#gno p#gno) end - -(* STUFF FROM THE CONTEXT *) - -(** -(* OPTIONS *) +(** Global and context options + + Note: This module contains functions that set parameters/options for context + objects as well as functions that set options that are used globally, across + contexts.*) +module Options = +struct (** - 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. + 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 Z3_ast_print_mode PrintMode + let update_param_value ( ctx : context ) ( id : string) ( value : string )= + Z3native.update_param_value ctx#gno id value - set { Z3native.set_ast_print_mode ctx#gno (uint)value); } - -(* SMT Files & Strings *) (** - Convert a benchmark into an SMT-LIB formatted string. + Get a configuration parameter. + + Returns None if the parameter value does not exist. + *) - @param name Name of the benchmark. The argument is optional. - @param logic The benchmark logic. - @param status The status string (sat, unsat, or unknown) - @param attributes Other attributes, such as source, difficulty or category. - @param assumptions Auxiliary assumptions. - @param formula 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) + let get_param_value ( ctx : context ) ( id : string ) = + let (r, v) = (Z3native.get_param_value ctx#gno id) in + if ((lbool_of_int r) == L_FALSE) then + None + else + Some v - Z3native.benchmark_to_smtlib_string ctx#gno name, logic, status, attributes, - (uint)assumptions.Length, AST.ArrayToNative(assumptions), - formula#gno); + (** + 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + + + + + *) + let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = + Z3native.set_ast_print_mode ctx#gno (int_of_ast_print_mode value) (** - 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. + Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) - public void ParseSMTLIBString(string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + let toggle_warning_messages ( enabled: bool ) = + Z3native.toggle_warning_messages (int_of_lbool (if enabled then L_TRUE else L_FALSE)) +end - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_string ctx#gno str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls) +(** Functions for handling SMT and SMT2 expressions and files *) +module SMT = +struct + (** + Convert a benchmark into an SMT-LIB formatted string. -(** - Parse the given file using the SMT-LIB parser. -*) - - public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_file ctx#gno 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 uint NumSMTLIBFormulas { get {Z3native.get_smtlib_num_formulas ctx#gno)) - -(** - The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - let[] SMTLIBFormulas - - get - - uint n = NumSMTLIBFormulas; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_formula ctx#gno i) - res; - - -(** - The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public uint NumSMTLIBAssumptions { get {Z3native.get_smtlib_num_assumptions ctx#gno)) - -(** - The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - let[] SMTLIBAssumptions - - get - - uint n = NumSMTLIBAssumptions; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i) - res; - - -(** - The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public uint NumSMTLIBDecls { get {Z3native.get_smtlib_num_decls ctx#gno)) - -(** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public Func_Decl[] SMTLIBDecls - - get - - uint n = NumSMTLIBDecls; - Func_Decl[] res = new Func_Decl[n]; - for (uint i = 0; i < n; i++) - res[i] = new Func_Decl(this, Z3native.get_smtlib_decl ctx#gno i) - res; - - -(** - The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public uint NumSMTLIBSorts { get {Z3native.get_smtlib_num_sorts ctx#gno)) - -(** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public Sort[] SMTLIBSorts - - get - - uint n = NumSMTLIBSorts; - Sort[] res = new Sort[n]; - for (uint i = 0; i < n; i++) - res[i] = Sort.Create(this, Z3native.get_smtlib_sort ctx#gno i) - 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. - let ParseSMTLIB2String ( ctx : context ) string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_string ctx#gno 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. -*) - - let ParseSMTLIB2File ( ctx : context ) string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_file ctx#gno fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) - -(* GOALS *) -(** - Creates a new Goal. - - Note that the Context must have been created with proof generation support if - is set to true here. -*) - @param models Indicates whether model generation should be enabled. - @param unsatCores Indicates whether unsat core generation should be enabled. - @param proofs Indicates whether proof generation should be enabled. - public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) - - new Goal(this, models, unsatCores, proofs); - -(* PARAMETERSETS *) -(** - Creates a new ParameterSet. -*) - public Params MkParams ( ctx : context ) = - - new Params(this); - -(* TACTICS *) -(** - The number of supported tactics. -*) - public uint NumTactics - - get {Z3native.get_num_tactics ctx#gno); } - -(** - The names of all supported tactics. -*) - public string[] TacticNames - - get - - uint n = NumTactics; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_tactic_name ctx#gno i); - res; - - -(** - Returns a string containing a description of the tactic with the given name. -*) - public string TacticDescription(string name) - - Z3native.tactic_get_descr ctx#gno name); - -(** - Creates a new Tactic. -*) - public Tactic MkTactic(string name) - - 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, params Tactic[] ts) - - IntPtr last = IntPtr.Zero; - if (ts != null && ts.Length > 0) - - last = ts[ts.Length - 1]#gno; - for (int i = ts.Length - 2; i >= 0; i--) - last = Z3native.tactic_and_then ctx#gno ts[i]#gno last); - - if (last != IntPtr.Zero) - - last = Z3native.tactic_and_then ctx#gno t2#gno last); - new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno last) + @param name Name of the benchmark. The argument is optional. + @param logic The benchmark logic. + @param status The status string (sat, unsat, or unknown) + @param attributes Other attributes, such as source, difficulty or category. + @param assumptions Auxiliary assumptions. + @param formula Formula to be checked for consistency in conjunction with assumptions. + @return A string representation of the benchmark. + *) + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = + Z3native.benchmark_to_smtlib_string ctx#gno name logic status attributes + (Array.length assumptions) (astaton assumptions) + formula#gno + (** + 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. + *) + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = + let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in + let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in + let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in + let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") else - new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno t2#gno) - -(** - 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, params Tactic[] ts) - - 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) - - new Tactic(this, Z3native.tactic_or_else ctx#gno t1#gno t2#gno) - -(** - Create a tactic that applies to a goal for milliseconds. - - If does not terminate within milliseconds, then it fails. -*) - public Tactic TryFor(Tactic t, uint ms) - - new Tactic(this, Z3native.tactic_try_for ctx#gno t#gno 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) - - new Tactic(this, Z3native.tactic_when ctx#gno p#gno t#gno) - -(** - 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) - - new Tactic(this, Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) - -(** - 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, uint max = uint.MaxValue) - - new Tactic(this, Z3native.tactic_repeat ctx#gno t#gno max) - -(** - Create a tactic that just returns the given goal. -*) - public Tactic Skip ( ctx : context ) = - - new Tactic(this, Z3native.tactic_skip ctx#gno) - -(** - Create a tactic always fails. -*) - public Tactic Fail ( ctx : context ) = - - new Tactic(this, Z3native.tactic_fail ctx#gno) - -(** - Create a tactic that fails if the probe evaluates to false. -*) - public Tactic FailIf(Probe p) - - new Tactic(this, Z3native.tactic_fail_if ctx#gno p#gno) - -(** - 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 ( ctx : context ) = - - new Tactic(this, Z3native.tactic_fail_if_not_decided ctx#gno) - -(** - Create a tactic that applies using the given set of parameters . -*) - public Tactic UsingParams(Tactic t, Params p) - - new Tactic(this, Z3native.tactic_using_params ctx#gno t#gno p#gno) - -(** - Create a tactic that applies using the given set of parameters . - Alias for UsingParams*) - public Tactic With(Tactic t, Params p) - - UsingParams(t, p); - -(** - Create a tactic that applies the given tactics in parallel. -*) - public Tactic ParOr(params Tactic[] t) - - new Tactic(this, Z3native.tactic_par_or ctx#gno 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) - - new Tactic(this, Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) - -(** - Interrupt the execution of a Z3 procedure. -*) - This procedure can be used to interrupt: solvers, simplifiers and tactics. - public void Interrupt ( ctx : context ) = - - Z3native.interrupt ctx#gno); - -(* PROBES *) -(** - The number of supported Probes. -*) - public uint NumProbes - - get {Z3native.get_num_probes ctx#gno); } - -(** - The names of all supported Probes. -*) - public string[] ProbeNames - - get - - uint n = NumProbes; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_probe_name ctx#gno i); - res; - - -(** - Returns a string containing a description of the probe with the given name. -*) - public string ProbeDescription(string name) - - Z3native.probe_get_descr ctx#gno name); - -(** - Creates a new Probe. -*) - public Probe MkProbe(string name) - - new Probe(this, name); - -(** - Create a probe that always evaluates to . -*) - public Probe Const(double val) - - new Probe(this, Z3native.probe_const ctx#gno 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) - - new Probe(this, Z3native.probe_lt ctx#gno p1#gno p2#gno) - -(** - 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) - - new Probe(this, Z3native.probe_gt ctx#gno p1#gno p2#gno) - -(** - 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) - - new Probe(this, Z3native.probe_le ctx#gno p1#gno p2#gno) - -(** - 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) - - new Probe(this, Z3native.probe_ge ctx#gno p1#gno p2#gno) - -(** - 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) - - new Probe(this, Z3native.probe_eq ctx#gno p1#gno p2#gno) - -(** - Create a probe that evaluates to "true" when the value - and evaluate to "true". -*) - public Probe And(Probe p1, Probe p2) - - new Probe(this, Z3native.probe_and ctx#gno p1#gno p2#gno) - -(** - Create a probe that evaluates to "true" when the value - or evaluate to "true". -*) - public Probe Or(Probe p1, Probe p2) - - new Probe(this, Z3native.probe_or ctx#gno p1#gno p2#gno) - -(** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". -*) - public Probe Not(Probe p) - - new Probe(this, Z3native.probe_not ctx#gno p#gno) - -(* SOLVERS *) -(** - 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 = null) - - if (logic == null) - new Solver(this, Z3native.mk_solver ctx#gno) + Z3native.parse_smtlib_string ctx#gno str + cs + (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match sorts with | None -> [||] | Some(x) -> (astaton x)) + cd + (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + + (** + Parse the given file using the SMT-LIB parser. + + *) + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array option) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = + let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in + let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in + let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in + let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") else - new Solver(this, Z3native.mk_solver_for_logic ctx#gno logic#gno) + Z3native.parse_smtlib_file ctx#gno file_name + cs + (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match sorts with | None -> [||] | Some(x) -> (astaton x)) + cd + (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (** + The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas ctx#gno -(** - Creates a new (incremental) solver. -*) - - public Solver MkSolver(string logic) + (** + The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_smtlib_formulas ( ctx : context ) = + let n = (get_num_smtlib_formulas ctx ) in + let f i = ((create_expr ctx (Z3native.get_smtlib_formula ctx#gno i)) :> bool_expr) in + Array.init n f - MkSolver(MkSymbol(logic) -(** - Creates a new (incremental) solver. -*) - let mk_Simple_Solver( ctx : context ) ctx : context ) = + (** + The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions ctx#gno - new Solver(this, Z3native.mk_simple_solver ctx#gno) + (** + The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_smtlib_assumptions ( ctx : context ) = + let n = (get_num_smtlib_assumptions ctx ) in + let f i = ((create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i)) :> bool_expr ) in + Array.init n f -(** - 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) + (** + The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls ctx#gno - new Solver(this, Z3native.mk_solver_from_tactic ctx#gno t#gno) + (** + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_smtlib_decls ( ctx : context ) = + let n = (get_num_smtlib_decls ctx) in + let f i = (new func_decl ctx)#cnstr_obj (Z3native.get_smtlib_decl ctx#gno i) in + Array.init n f -(* FIXEDPOINTS *) -(** - Create a Fixedpoint context. -*) - public Fixedpoint MkFixedpoint ( ctx : context ) = + (** + The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts ctx#gno - new Fixedpoint(this); + (** + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_smtlib_sorts ( ctx : context ) = + let n = (get_num_smtlib_sorts ctx) in + let f i = (create_sort ctx (Z3native.get_smtlib_sort ctx#gno i)) in + Array.init n f -(* MISCELLANEOUS *) -(** - 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., - . - - @param nativeObject The native pointer to wrap. - public AST WrapAST(IntPtr nativeObject) + (** + Parse the given string using the SMT-LIB2 parser. - 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., - ). - - @param a The AST to unwrap. - public IntPtr UnwrapAST(AST a) - - a#gno; - -(** - a string describing all available parameters to Expr.Simplify. -*) - public string SimplifyHelp ( ctx : context ) = - - Z3native.simplify_get_help ctx#gno); - -(** - Retrieves parameter descriptions for simplifier. -*) - public ParamDescrs SimplifyParameterDescriptions - - get {new ParamDescrs(this, Z3native.simplify_get_param_descrs ctx#gno)); } - -(** - 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(bool enabled) - - Z3native.toggle_warning_messages((enabled) ? 1 : 0); - -(* ERROR HANDLING *) -(** - 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; - -(* PARAMETERS *) -(** - 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) - - Z3native.update_param_value ctx#gno id, value); - -(** - Get a configuration parameter. - - Returns null if the parameter value does not exist. - -*) - public string GetParamValue(string id) - - IntPtr res = IntPtr.Zero; - int r = Z3native.get_param_value ctx#gno id, out res); - if (r == (int)Z3_lbool.L_FALSE) - null; + + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. + *) + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = + let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in + let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in + let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in + let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") else - Marshal.PtrToStringAnsi(res); + Z3native.parse_smtlib2_string ctx#gno str + cs + (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match sorts with | None -> [||] | Some(x) -> (astaton x)) + cd + (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match decls with | None -> [||] | Some(x) -> (func_declaton x)) -(* INTERNAL *) - internal IntPtr m_ctx = IntPtr.Zero; - internal Z3native.error_handler m_n_err_handler = null; - internal IntPtr nCtx { get {m_ctx) + (** + Parse the given file using the SMT-LIB2 parser. + + *) + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = + let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in + let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in + let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in + let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Z3native.parse_smtlib2_string ctx#gno file_name + cs + (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match sorts with | None -> [||] | Some(x) -> (astaton x)) + cd + (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match decls with | None -> [||] | Some(x) -> (func_declaton x)) +end - internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) +(* - Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. +(** + 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, error_code errorCode, string errorString); - internal void InitContext ( ctx : context ) = + internal Z3native.error_handler m_n_err_handler = null; - PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); + internal void NativeErrorHandler(IntPtr ctx, error_code errorCode) + + Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. *) From a42e21ede1c4fece515ee532be1b2ce80296e2df Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 24 Dec 2012 03:00:39 +0000 Subject: [PATCH 028/248] ML API: mk_context added. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 4 +- src/api/ml/z3.ml | 687 +++++++++++++++++++------------------- 2 files changed, 349 insertions(+), 342 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index dde9f944a..32c9458f5 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -14,8 +14,8 @@ let _ = else ( Printf.printf "Running Z3 version %s\n" Version.to_string ; - let cfg = [("model", "true"); ("proof", "false")] in - let ctx = (new context cfg) in + let cfg = (Some [("model", "true"); ("proof", "false")]) in + let ctx = (mk_context cfg) in let is = (Symbol.mk_int ctx 42) in let ss = (Symbol.mk_string ctx "mySymbol") in let bs = (Sort.mk_bool ctx) in diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 088bfbd6f..fee6f9fe0 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,29 +7,9 @@ open Z3enums -(** Context objects. - -Most interactions with Z3 are interpreted in some context; most users will only -require one such object, but power users may require more than one. To start using -Z3, do - - - let ctx = (new context [||]) in - (...) - - -where [||] is a (possibly empty) list of pairs of strings, which can -be used to set options on the context, e.g., like so: - - - let cfg = [("model", "true"); ("...", "...")] in - let ctx = (new context cfg) in - (...) - - -*) -class context settings = (**/**) + +class context settings = object (self) val mutable m_n_ctx : Z3native.z3_context = let cfg = Z3native.mk_config in @@ -66,11 +46,37 @@ object (self) method add_one_ctx_obj = m_obj_cnt <- m_obj_cnt + 1 method sub_one_ctx_obj = m_obj_cnt <- m_obj_cnt - 1 method gno = m_n_ctx -(**/**) end (**/**) +(** Create a context object. + +Most interactions with Z3 are interpreted in some context; many users will only +require one such object, but power users may require more than one. To start using +Z3, do + + + let ctx = (mk_context None) in + (...) + + +where a list of pairs of strings may be passed to set options on +the context, e.g., like so: + + + let cfg = (Some [("model", "true"); ("...", "...")]) in + let ctx = (mk_context cfg) in + (...) + +*) +let mk_context ( cfg : ( string * string ) list option ) = + match cfg with + | None -> new context [] + | Some(x) -> new context x + +(**/**) + (** Z3 objects *) class virtual z3object ctx_init obj_init = object (self) @@ -4559,224 +4565,114 @@ end Z3native.interrupt ctx#gno end -(** Models +(** Probes - A Model contains interpretations (assignments) of constants and functions. *) -module Model = + 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. +*) +module Probe = struct - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. - *) - module FuncInterp = - struct - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. - *) - module FuncEntry = - struct - (** - Return the (symbolic) value of this entry. - *) - let get_value ( x : func_entry ) = - create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) - - (** - The number of arguments of the entry. - *) - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno - - (** - The arguments of the function entry. - *) - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in - Array.init n f - - (** - A string representation of the function entry. - *) - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") - end - - (** - The number of entries in the function interpretation. - *) - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno - - (** - The entries in the function interpretation - *) - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in - Array.init n f - - (** - The (symbolic) `else' value of the function interpretation. - *) - let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) - - (** - The arity of the function interpretation - *) - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno - - (** - A string representation of the function interpretation. - *) - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (Array.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") - end - - (** Retrieves the interpretation (the assignment) of in the model. - A function declaration of zero arity - An expression if the function has an interpretation in the model, null otherwise. *) - let get_const_interp ( x : model ) ( f : func_decl ) = - if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then - raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") - else - let np = Z3native.model_get_const_interp x#gnc x#gno f#gno in - if (Z3native.is_null np) then - None - else - Some (create_expr x#gc np) - - (** Retrieves the interpretation (the assignment) of in the model. - A Constant - An expression if the constant has an interpretation in the model, null otherwise. - *) - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - - - (** Retrieves the interpretation (the assignment) of a non-constant in the model. - A function declaration of non-zero arity - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_range f#gnc f#gno))) in - if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp x#gnc x#gno f#gno in - if (Z3native.is_null n) then - None - else - match sk with - | ARRAY_SORT -> - if (lbool_of_int (Z3native.is_as_array x#gnc n)) == L_FALSE then - raise (Z3native.Exception "Argument was not an array constant") - else - let fd = Z3native.get_as_array_func_decl x#gnc n in - get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) - | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); - else - let n = (Z3native.model_get_func_interp x#gnc x#gno f#gno) in - if (Z3native.is_null n) then None else Some ((new func_interp x#gc)#cnstr_obj n) - - (** The number of constants that have an interpretation in the model. *) - let get_num_consts ( x : model ) = Z3native.model_get_num_consts x#gnc x#gno - - (** The function declarations of the constants in the model. *) - let get_const_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in - Array.init n f - - - (** The number of function interpretations in the model. *) - let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs x#gnc x#gno - - (** The function declarations of the function interpretations in the model. *) - let get_func_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in - Array.init n f - - (** All symbols that have an interpretation in the model. *) - let get_decls ( x : model ) = - let n_funcs = (get_num_funcs x) in - let n_consts = (get_num_consts x ) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in - let g i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in - Array.append (Array.init n_funcs f) (Array.init n_consts g) - - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) - exception ModelEvaluationFailedException of string - (** - 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. - - The evaluation of in the model. + Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno (int_of_lbool (if completion then L_TRUE else L_FALSE))) in - if (lbool_of_int r) == L_FALSE then - raise (ModelEvaluationFailedException "evaluation failed") - else - create_expr x#gc v + let apply ( x : probe ) (g : goal) = + Z3native.probe_apply x#gnc x#gno g#gno - (** Alias for eval. *) - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = - eval x t completion - - (** The number of uninterpreted sorts that the model has an interpretation for. *) - let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts x#gnc x#gno - - (** 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. - - + (** + The number of supported Probes. *) - let get_sorts ( x : model ) = - let n = (get_num_sorts x) in - let f i = (create_sort x#gc (Z3native.model_get_sort x#gnc x#gno i)) in + let get_num_probes ( ctx : context ) = + Z3native.get_num_probes ctx#gno + + (** + The names of all supported Probes. + *) + let get_probe_names ( ctx : context ) = + let n = (get_num_probes ctx) in + let f i = (Z3native.get_probe_name ctx#gno i) in Array.init n f + (** + Returns a string containing a description of the probe with the given name. + *) + let get_probe_description ( ctx : context ) ( name : string ) = + Z3native.probe_get_descr ctx#gno name - (** The finite set of distinct values that represent the interpretation for sort . - - An uninterpreted sort - An array of expressions, where each is an element of the universe of + (** + Creates a new Probe. + *) + let mk_probe ( ctx : context ) ( name : string ) = + (new probe ctx)#cnstr_obj (Z3native.mk_probe ctx#gno name) + + (** + Create a probe that always evaluates to . *) - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in - Array.init n f - - (** Conversion of models to strings. - A string representation of the model. + let const ( ctx : context ) ( v : float ) = + (new probe ctx)#cnstr_obj (Z3native.probe_const ctx#gno v) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than the value returned by *) - let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno + let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_lt ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than the value returned by + *) + let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_gt ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than or equal the value returned by + *) + let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_le ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than or equal the value returned by + *) + let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_ge ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is equal to the value returned by + *) + let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_eq ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + and evaluate to "true". + *) + (* CMW: and is a keyword *) + let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_and ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + or evaluate to "true". + *) + (* CMW: or is a keyword *) + let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_or ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + does not evaluate to "true". + *) + (* CMW: is not a keyword? *) + let not_ ( ctx : context ) ( p : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_not ctx#gno p#gno) end (** Solvers *) @@ -5032,6 +4928,227 @@ struct let to_string ( x : solver ) = Z3native.solver_to_string x#gnc x#gno end + +(** Models + + A Model contains interpretations (assignments) of constants and functions. *) +module Model = +struct + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. + *) + module FuncInterp = + struct + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. + *) + module FuncEntry = + struct + (** + Return the (symbolic) value of this entry. + *) + let get_value ( x : func_entry ) = + create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + + (** + The number of arguments of the entry. + *) + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + + (** + The arguments of the function entry. + *) + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the function entry. + *) + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") + end + + (** + The number of entries in the function interpretation. + *) + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + + (** + The entries in the function interpretation + *) + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + Array.init n f + + (** + The (symbolic) `else' value of the function interpretation. + *) + let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + + (** + The arity of the function interpretation + *) + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + + (** + A string representation of the function interpretation. + *) + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (Array.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + end + + (** Retrieves the interpretation (the assignment) of in the model. + A function declaration of zero arity + An expression if the function has an interpretation in the model, null otherwise. *) + let get_const_interp ( x : model ) ( f : func_decl ) = + if (FuncDecl.get_arity f) != 0 || + (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then + raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") + else + let np = Z3native.model_get_const_interp x#gnc x#gno f#gno in + if (Z3native.is_null np) then + None + else + Some (create_expr x#gc np) + + (** Retrieves the interpretation (the assignment) of in the model. + A Constant + An expression if the constant has an interpretation in the model, null otherwise. + *) + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + + + (** Retrieves the interpretation (the assignment) of a non-constant in the model. + A function declaration of non-zero arity + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + let rec get_func_interp ( x : model ) ( f : func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_range f#gnc f#gno))) in + if (FuncDecl.get_arity f) == 0 then + let n = Z3native.model_get_const_interp x#gnc x#gno f#gno in + if (Z3native.is_null n) then + None + else + match sk with + | ARRAY_SORT -> + if (lbool_of_int (Z3native.is_as_array x#gnc n)) == L_FALSE then + raise (Z3native.Exception "Argument was not an array constant") + else + let fd = Z3native.get_as_array_func_decl x#gnc n in + get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) + | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); + else + let n = (Z3native.model_get_func_interp x#gnc x#gno f#gno) in + if (Z3native.is_null n) then None else Some ((new func_interp x#gc)#cnstr_obj n) + + (** The number of constants that have an interpretation in the model. *) + let get_num_consts ( x : model ) = Z3native.model_get_num_consts x#gnc x#gno + + (** The function declarations of the constants in the model. *) + let get_const_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in + Array.init n f + + + (** The number of function interpretations in the model. *) + let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs x#gnc x#gno + + (** The function declarations of the function interpretations in the model. *) + let get_func_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in + Array.init n f + + (** All symbols that have an interpretation in the model. *) + let get_decls ( x : model ) = + let n_funcs = (get_num_funcs x) in + let n_consts = (get_num_consts x ) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in + let g i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in + Array.append (Array.init n_funcs f) (Array.init n_consts g) + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) + exception ModelEvaluationFailedException of string + + (** + 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. + + The evaluation of in the model. + *) + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno (int_of_lbool (if completion then L_TRUE else L_FALSE))) in + if (lbool_of_int r) == L_FALSE then + raise (ModelEvaluationFailedException "evaluation failed") + else + create_expr x#gc v + + (** Alias for eval. *) + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + eval x t completion + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts x#gnc x#gno + + (** 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. + + + *) + let get_sorts ( x : model ) = + let n = (get_num_sorts x) in + let f i = (create_sort x#gc (Z3native.model_get_sort x#gnc x#gno i)) in + Array.init n f + + + (** The finite set of distinct values that represent the interpretation for sort . + + An uninterpreted sort + An array of expressions, where each is an element of the universe of + *) + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in + Array.init n f + + (** Conversion of models to strings. + A string representation of the model. + *) + let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno +end + (** Fixedpoint solving *) module Fixedpoints = struct @@ -5208,116 +5325,6 @@ struct (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint ctx#gno) end -(** Probes - - 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. -*) -module Probe = -struct - (** - Execute the probe over the goal. - A probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. - *) - let apply ( x : probe ) (g : goal) = - Z3native.probe_apply x#gnc x#gno g#gno - - (** - The number of supported Probes. - *) - let get_num_probes ( ctx : context ) = - Z3native.get_num_probes ctx#gno - - (** - The names of all supported Probes. - *) - let get_probe_names ( ctx : context ) = - let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name ctx#gno i) in - Array.init n f - - (** - Returns a string containing a description of the probe with the given name. - *) - let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr ctx#gno name - - (** - Creates a new Probe. - *) - let mk_probe ( ctx : context ) ( name : string ) = - (new probe ctx)#cnstr_obj (Z3native.mk_probe ctx#gno name) - - (** - Create a probe that always evaluates to . - *) - let const ( ctx : context ) ( v : float ) = - (new probe ctx)#cnstr_obj (Z3native.probe_const ctx#gno v) - - (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by - *) - let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_lt ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by - *) - let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_gt ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by - *) - let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_le ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by - *) - let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_ge ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by - *) - let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_eq ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". - *) - (* CMW: and is a keyword *) - let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_and ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". - *) - (* CMW: or is a keyword *) - let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_or ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". - *) - (* CMW: is not a keyword? *) - let not_ ( ctx : context ) ( p : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_not ctx#gno p#gno) -end - (** Global and context options Note: This module contains functions that set parameters/options for context From bffef2e8083f2d42877a6701923c3792a41c23dd Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 24 Dec 2012 15:16:16 +0000 Subject: [PATCH 029/248] New ML API bugfixes and first example. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 122 ++++++++++++++++++++++++++++++++++++++ scripts/update_api.py | 10 +++- src/api/ml/z3.ml | 112 +++++++++++++++++----------------- 3 files changed, 186 insertions(+), 58 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 32c9458f5..945c9a494 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,10 +4,131 @@ *) open Z3 +open Z3.Symbol +open Z3.Sort +open Z3.Expr +open Z3.FuncDecl +open Z3.Goal +open Z3.Tactic +open Z3.Probe +open Z3.Solver open Z3.Arithmetic exception ExampleException of string + +(** + Some basic tests. +*) +let basic_tests ( ctx : context ) = + Printf.printf "BasicTests\n" ; + let qi = (mk_int ctx 1) in + let fname = ((mk_string ctx "f") :> symbol) in + let x = ((mk_string ctx "x") :> symbol) in + let y = ((mk_string ctx "y") :> symbol) in + let bs = (Sort.mk_bool ctx) in + let domain = [| bs; bs |] in + let f = (FuncDecl.mk_func_decl ctx fname domain bs) in + let fapp = (mk_app ctx f + [| (mk_const ctx x bs); (mk_const ctx y bs) |]) in + let fargs2 = [| (mk_fresh_const ctx "cp" bs) |] in + let domain2 = [| bs |] in + let fapp2 = (mk_app ctx (mk_fresh_func_decl ctx "fp" domain2 bs) fargs2) in + let trivial_eq = (mk_eq ctx fapp fapp) in + let nontrivial_eq = (mk_eq ctx fapp fapp2) in + let g = (mk_goal ctx true false false) in + (Goal.assert_ g [| trivial_eq |]) ; + (Goal.assert_ g [| nontrivial_eq |]) ; + Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; + let solver = (mk_solver ctx None) in + (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; + if (check solver None) != SATISFIABLE then + raise (ExampleException "") + else + Printf.printf "Test passed.\n" ; + () + +(* + ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g); + if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat)) + throw new TestFailedException(); + + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) + throw new TestFailedException(); + + g.Assert(ctx.MkEq(ctx.MkNumeral(1, ctx.MkBitVecSort(32)), + ctx.MkNumeral(2, ctx.MkBitVecSort(32)))); + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) + throw new TestFailedException(); + + + Goal g2 = ctx.MkGoal(true, true); + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) + throw new TestFailedException(); + + g2 = ctx.MkGoal(true, true); + g2.Assert(ctx.MkFalse()); + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) + throw new TestFailedException(); + + Goal g3 = ctx.MkGoal(true, true); + Expr xc = ctx.MkConst(ctx.MkSymbol("x"), ctx.IntSort); + Expr yc = ctx.MkConst(ctx.MkSymbol("y"), ctx.IntSort); + g3.Assert(ctx.MkEq(xc, ctx.MkNumeral(1, ctx.IntSort))); + g3.Assert(ctx.MkEq(yc, ctx.MkNumeral(2, ctx.IntSort))); + BoolExpr constr = ctx.MkEq(xc, yc); + g3.Assert(constr); + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g3); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) + throw new TestFailedException(); + + ModelConverterTest(ctx); + + // Real num/den test. + RatNum rn = ctx.MkReal(42, 43); + Expr inum = rn.Numerator; + Expr iden = rn.Denominator; + Console.WriteLine("Numerator: " + inum + " Denominator: " + iden); + if (inum.ToString() != "42" || iden.ToString() != "43") + throw new TestFailedException(); + + if (rn.ToDecimalString(3) != "0.976?") + throw new TestFailedException(); + + BigIntCheck(ctx, ctx.MkReal("-1231231232/234234333")); + BigIntCheck(ctx, ctx.MkReal("-123123234234234234231232/234234333")); + BigIntCheck(ctx, ctx.MkReal("-234234333")); + BigIntCheck(ctx, ctx.MkReal("234234333/2")); + + + string bn = "1234567890987654321"; + + if (ctx.MkInt(bn).BigInteger.ToString() != bn) + throw new TestFailedException(); + + if (ctx.MkBV(bn, 128).BigInteger.ToString() != bn) + throw new TestFailedException(); + + if (ctx.MkBV(bn, 32).BigInteger.ToString() == bn) + throw new TestFailedException(); + + // Error handling test. + try + { + IntExpr i = ctx.MkInt("1/2"); + throw new TestFailedException(); // unreachable + } + catch (Z3Exception) + { + } + } +*) + + let _ = if not (Log.open_ "z3.log") then raise (ExampleException "Log couldn't be opened.") @@ -27,6 +148,7 @@ let _ = Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); Printf.printf "Disposing...\n"; + basic_tests ctx ; Gc.full_major () ); Printf.printf "Exiting.\n"; diff --git a/scripts/update_api.py b/scripts/update_api.py index acaa9478e..5d95a12f8 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -159,7 +159,7 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I # Mapping to ML types Type2ML = { VOID : 'unit', VOID_PTR : 'VOIDP', INT : 'int', UINT : 'int', INT64 : 'int', UINT64 : 'int', DOUBLE : 'float', STRING : 'string', STRING_PTR : 'char**', - BOOL : 'int', SYMBOL : 'z3_symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } + BOOL : 'bool', SYMBOL : 'z3_symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } next_type_id = FIRST_OBJ_ID @@ -1109,7 +1109,9 @@ def arrayparams(params): def ml_unwrap(t, ts, s): if t == STRING: return '(' + ts + ') String_val(' + s + ')' - elif t == BOOL or t == INT or t == PRINT_MODE or t == ERROR_CODE: + elif t == BOOL: + return '(' + ts + ') Bool_val(' + s + ')' + elif t == INT or t == PRINT_MODE or t == ERROR_CODE: return '(' + ts + ') Int_val(' + s + ')' elif t == UINT: return '(' + ts + ') Unsigned_int_val(' + s + ')' @@ -1125,7 +1127,9 @@ def ml_unwrap(t, ts, s): def ml_set_wrap(t, d, n): if t == VOID: return d + ' = Val_unit;' - elif t == BOOL or t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE: + elif t == BOOL: + return d + ' = Val_bool(' + n + ');' + elif t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE: return d + ' = Val_int(' + n + ');' elif t == INT64 or t == UINT64: return d + ' = Val_long(' + n + ');' diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index fee6f9fe0..b4d58711c 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -874,7 +874,7 @@ struct if a#gnc != b#gnc then false else - ((lbool_of_int (Z3native.is_eq_sort a#gnc a#gno b#gno)) == L_TRUE) + (Z3native.is_eq_sort a#gnc a#gno b#gno) (** Returns a unique identifier for the sort. @@ -922,10 +922,10 @@ let create_expr ctx obj = else let s = Z3native.get_sort ctx#gno obj in let sk = (sort_kind_of_int (Z3native.get_sort_kind ctx#gno s)) in - if (lbool_of_int (Z3native.is_algebraic_number ctx#gno obj) == L_TRUE) then + if (Z3native.is_algebraic_number ctx#gno obj) then (((new algebraic_num ctx)#cnstr_obj obj) :> expr) else - if ((lbool_of_int (Z3native.is_numeral_ast ctx#gno obj)) == L_TRUE) && + if (Z3native.is_numeral_ast ctx#gno obj) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) @@ -1016,6 +1016,7 @@ struct raise (Z3native.Exception "parameter is not a ratinoal string") else x#rational + end (** Creates a new function declaration. @@ -1058,7 +1059,6 @@ struct let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = (new func_decl ctx)#cnstr_pdr prefix [||] range - end (** Comparison operator. @@ -1071,7 +1071,7 @@ struct if a#gnc == a#gnc then false else - ((lbool_of_int (Z3native.is_eq_func_decl a#gnc a#gno b#gno)) == L_TRUE) + (Z3native.is_eq_func_decl a#gnc a#gno b#gno) (** A string representations of the function declaration. *) @@ -1202,7 +1202,7 @@ struct @param k An AST @return True if is a key in the map, false otherwise. *) let contains ( m : ast_map ) ( key : ast ) = - (lbool_of_int (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE + (Z3native.ast_map_contains m#gnc m#gno key#gno) (** Finds the value associated with the key . @@ -1313,7 +1313,7 @@ struct if a#gnc == b#gnc then false else - ((lbool_of_int (Z3native.is_eq_ast a#gnc a#gno b#gno)) == L_TRUE) + (Z3native.is_eq_ast a#gnc a#gno b#gno) (** Object Comparison. @@ -1472,13 +1472,13 @@ struct (** Indicates whether the term is a numeral *) - let is_numeral ( x : expr ) = lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno) == L_TRUE + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast x#gnc x#gno) (** Indicates whether the term is well-sorted. @return True if the term is well-sorted, false otherwise. *) - let is_well_sorted ( x : expr ) = lbool_of_int (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted x#gnc x#gno (** The Sort of the term. @@ -1489,9 +1489,9 @@ struct Indicates whether the term has Boolean sort. *) let is_bool ( x : expr ) = (AST.is_expr x) && - (lbool_of_int (Z3native.is_eq_sort x#gnc - (Z3native.mk_bool_sort x#gnc) - (Z3native.get_sort x#gnc x#gno))) == L_TRUE + (Z3native.is_eq_sort x#gnc + (Z3native.mk_bool_sort x#gnc) + (Z3native.get_sort x#gnc x#gno)) (** Indicates whether the term represents a constant. @@ -1774,7 +1774,7 @@ struct Indicates whether the quantifier is universal. *) let is_universal ( x : quantifier ) = - lbool_of_int (Z3native.is_quantifier_forall x#gnc x#gno) == L_TRUE + Z3native.is_quantifier_forall x#gnc x#gno (** Indicates whether the quantifier is existential. @@ -1879,7 +1879,7 @@ struct if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno (int_of_lbool L_TRUE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno true (match weight with | None -> 1 | Some(x) -> x) (match patterns with | None -> 0 | Some(x) -> (Array.length x)) (match patterns with | None -> [||] | Some(x) -> (patternaton x)) @@ -1888,7 +1888,7 @@ struct body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno (int_of_lbool L_TRUE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) @@ -1905,7 +1905,7 @@ struct *) let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno (int_of_lbool L_TRUE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno true (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expraton bound_constants) (match patterns with | None -> 0 | Some(x) -> (Array.length x)) @@ -1913,7 +1913,7 @@ struct body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno (int_of_lbool L_TRUE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) @@ -1931,7 +1931,7 @@ struct if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno (int_of_lbool L_FALSE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno false (match weight with | None -> 1 | Some(x) -> x) (match patterns with | None -> 0 | Some(x) -> (Array.length x)) (match patterns with | None -> [||] | Some(x) -> (patternaton x)) @@ -1940,7 +1940,7 @@ struct body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno (int_of_lbool L_FALSE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) @@ -1957,7 +1957,7 @@ struct *) let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno (int_of_lbool L_FALSE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno false (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expraton bound_constants) (match patterns with | None -> 0 | Some(x) -> (Array.length x)) @@ -1965,7 +1965,7 @@ struct body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno (int_of_lbool L_FALSE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) @@ -2046,7 +2046,7 @@ struct Indicates whether the term is of an array sort. *) let is_array ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (Z3native.is_app x#gnc x#gno) && ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) (** The domain of the array sort. *) @@ -2252,7 +2252,7 @@ struct Indicates whether the term is of an array sort. *) let is_finite_domain ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (Z3native.is_app x#gnc x#gno) && (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) (** @@ -2263,7 +2263,7 @@ struct (** The size of the finite domain sort. *) let get_size (x : finite_domain_sort) = let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v + if r then v else raise (Z3native.Exception "Conversion failed.") end @@ -2274,8 +2274,8 @@ struct Indicates whether the term is of a relation sort. *) let is_relation ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT) + ((Z3native.is_app x#gnc x#gno) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT)) (** Indicates whether the term is an relation store @@ -2604,7 +2604,7 @@ struct Indicates whether the term is of integer sort. *) let is_int ( x : expr ) = - ((lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && + (Z3native.is_numeral_ast x#gnc x#gno) && ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) (** @@ -2706,12 +2706,13 @@ struct (** Indicates whether the term is an algebraic number *) - let is_algebraic_number ( x : expr ) = lbool_of_int(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number x#gnc x#gno (** Retrieve the int value. *) - let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") + let get_int ( x : int_num ) = + let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if r then v + else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -3219,9 +3220,10 @@ struct let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno (** Retrieve the int value. *) - let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") + let get_int ( x : bitvec_num ) = + let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if r then v + else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -3613,7 +3615,7 @@ struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int ctx#gno t#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int ctx#gno t#gno signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3621,7 +3623,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow ctx#gno t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3645,7 +3647,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow ctx#gno t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3669,7 +3671,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow ctx#gno t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -4198,7 +4200,7 @@ end Adds a parameter setting. *) let add_bool (p : params) (name : symbol) (value : bool) = - Z3native.params_set_bool p#gnc p#gno name#gno (int_of_lbool (if value then L_TRUE else L_FALSE)) + Z3native.params_set_bool p#gnc p#gno name#gno value (** Adds a parameter setting. @@ -4291,11 +4293,12 @@ struct (* CMW: assert seems to be a keyword. *) let assert_ ( x : goal ) ( constraints : bool_expr array ) = let f e = Z3native.goal_assert x#gnc x#gno e#gno in - Array.map f constraints + ignore (Array.map f constraints) ; + () (** Indicates whether the goal contains `false'. *) let is_inconsistent ( x : goal ) = - (lbool_of_int (Z3native.goal_inconsistent x#gnc x#gno)) == L_TRUE + Z3native.goal_inconsistent x#gnc x#gno (** The depth of the goal. This tracks how many transformations were applied to it. *) @@ -4318,11 +4321,11 @@ struct (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) let is_decided_sat ( x : goal ) = - (lbool_of_int (Z3native.goal_is_decided_sat x#gnc x#gno)) == L_TRUE + Z3native.goal_is_decided_sat x#gnc x#gno (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) let is_decided_unsat ( x : goal ) = - (lbool_of_int (Z3native.goal_is_decided_unsat x#gnc x#gno)) == L_TRUE + Z3native.goal_is_decided_unsat x#gnc x#gno (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = @@ -4357,10 +4360,7 @@ struct @param proofs Indicates whether proof generation should be enabled. *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - (new goal ctx)#cnstr_obj (Z3native.mk_goal ctx#gno - (int_of_lbool (if models then L_TRUE else L_FALSE)) - (int_of_lbool (if unsat_cores then L_TRUE else L_FALSE)) - (int_of_lbool (if proofs then L_TRUE else L_FALSE))) + (new goal ctx)#cnstr_obj (Z3native.mk_goal ctx#gno models unsat_cores proofs) (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno @@ -4729,7 +4729,7 @@ struct let n = (get_size x ) in let f i = ( let k = Z3native.stats_get_key x#gnc x#gno i in - if (lbool_of_int (Z3native.stats_is_uint x#gnc x#gno i)) == L_TRUE then + if (Z3native.stats_is_uint x#gnc x#gno i) then ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) else ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) @@ -4800,7 +4800,8 @@ struct *) let assert_ ( x : solver ) ( constraints : bool_expr array ) = let f e = (Z3native.solver_assert x#gnc x#gno e#gno) in - Array.map f constraints + ignore (Array.map f constraints) ; + () (** The number of assertions in the solver. @@ -5049,7 +5050,7 @@ struct else match sk with | ARRAY_SORT -> - if (lbool_of_int (Z3native.is_as_array x#gnc n)) == L_FALSE then + if not (Z3native.is_as_array x#gnc n) then raise (Z3native.Exception "Argument was not an array constant") else let fd = Z3native.get_as_array_func_decl x#gnc n in @@ -5105,8 +5106,8 @@ struct The evaluation of in the model. *) let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno (int_of_lbool (if completion then L_TRUE else L_FALSE))) in - if (lbool_of_int r) == L_FALSE then + let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno completion) in + if not r then raise (ModelEvaluationFailedException "evaluation failed") else create_expr x#gc v @@ -5175,7 +5176,8 @@ struct *) let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = let f e = (Z3native.fixedpoint_assert x#gnc x#gno e#gno) in - Array.map f constraints + ignore (Array.map f constraints) ; + () (** Register predicate as recursive relation. @@ -5353,7 +5355,7 @@ struct *) let get_param_value ( ctx : context ) ( id : string ) = let (r, v) = (Z3native.get_param_value ctx#gno id) in - if ((lbool_of_int r) == L_FALSE) then + if not r then None else Some v @@ -5383,7 +5385,7 @@ struct all contexts globally. *) let toggle_warning_messages ( enabled: bool ) = - Z3native.toggle_warning_messages (int_of_lbool (if enabled then L_TRUE else L_FALSE)) + Z3native.toggle_warning_messages enabled end (** Functions for handling SMT and SMT2 expressions and files *) From cef9c2fa6901b549d4459902a07409b35ba59353 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 26 Dec 2012 16:54:45 +0000 Subject: [PATCH 030/248] more ML Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 58 +++++++++++++++++++++------------------ src/api/ml/z3.ml | 4 +++ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 945c9a494..7fcd2e9f7 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -10,11 +10,12 @@ open Z3.Expr open Z3.FuncDecl open Z3.Goal open Z3.Tactic +open Z3.Tactic.ApplyResult open Z3.Probe open Z3.Solver open Z3.Arithmetic -exception ExampleException of string +exception TestFailedException of string (** @@ -43,32 +44,37 @@ let basic_tests ( ctx : context ) = let solver = (mk_solver ctx None) in (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; if (check solver None) != SATISFIABLE then - raise (ExampleException "") + raise (TestFailedException "") else Printf.printf "Test passed.\n" ; - () - -(* - ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g); - if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat)) - throw new TestFailedException(); - - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) - throw new TestFailedException(); - - g.Assert(ctx.MkEq(ctx.MkNumeral(1, ctx.MkBitVecSort(32)), - ctx.MkNumeral(2, ctx.MkBitVecSort(32)))); - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) - throw new TestFailedException(); - - - Goal g2 = ctx.MkGoal(true, true); - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) - throw new TestFailedException(); - + () ; + let ar = (Tactic.apply (mk_tactic ctx "simplify") g None) in + if ((get_num_subgoals ar) == 1 && + ((is_decided_sat (get_subgoal ar 0)) || + (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_sat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + (Goal.assert_ g [| (mk_eq ctx (mk_numeral_int ctx 1 (BitVectors.mk_sort ctx 32)) + (mk_numeral_int ctx 2 (BitVectors.mk_sort ctx 32))) |] ) + ; + let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + let g2 = (mk_goal ctx true true false) in + let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_sat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + () +(* g2 = ctx.MkGoal(true, true); g2.Assert(ctx.MkFalse()); ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); @@ -131,7 +137,7 @@ let basic_tests ( ctx : context ) = let _ = if not (Log.open_ "z3.log") then - raise (ExampleException "Log couldn't be opened.") + raise (TestFailedException "Log couldn't be opened.") else ( Printf.printf "Running Z3 version %s\n" Version.to_string ; diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index b4d58711c..8806a70ee 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -4391,6 +4391,10 @@ struct let n = (get_num_subgoals x) in let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in Array.init n f + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoal ( x : apply_result ) ( i : int ) = + (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) (** Convert a model for the subgoal into a model for the original goal g, that the ApplyResult was obtained from. From 597409c8acbb8df351c50b83f60c893efe033f2f Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 27 Dec 2012 15:51:42 +0000 Subject: [PATCH 031/248] ML API bugfixes More ML examples Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 165 ++++++++++++++++++++++++++------------ scripts/mk_util.py | 6 +- src/api/ml/z3.ml | 5 ++ 3 files changed, 124 insertions(+), 52 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 7fcd2e9f7..0e8122ae0 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -17,6 +17,50 @@ open Z3.Arithmetic exception TestFailedException of string +(** + Model Converter test +*) +let model_converter_test ( ctx : context ) = + Printf.printf "ModelConverterTest\n"; + let xr = ((mk_const ctx ((Symbol.mk_string ctx "x") :> symbol) (mk_real_sort ctx )) :> arith_expr) in + let yr = ((mk_const ctx ((Symbol.mk_string ctx "y") :> symbol) (mk_real_sort ctx )) :> arith_expr) in + let g4 = (mk_goal ctx true false false ) in + (Goal.assert_ g4 [| (mk_gt ctx xr (mk_real_numeral_nd ctx 10 1)) |]) ; + (Goal.assert_ g4 [| (mk_eq ctx yr (mk_add ctx [| xr; (mk_real_numeral_nd ctx 1 1) |] )) |] ) ; + (Goal.assert_ g4 [| (mk_gt ctx yr (mk_real_numeral_nd ctx 1 1)) |]) ; + ( + let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in + if ((get_num_subgoals ar) == 1 && + ((is_decided_sat (get_subgoal ar 0)) || + (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") None) g4 None) in + if ((get_num_subgoals ar) == 1 && + ((is_decided_sat (get_subgoal ar 0)) || + (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ; + let solver = (mk_solver ctx None) in + let f e = (Solver.assert_ solver [| e |]) in + ignore (Array.map f (get_formulas (get_subgoal ar 0))) ; + let q = (check solver None) in + if q != SATISFIABLE then + raise (TestFailedException "") + else + let m = (get_model solver) in + match m with + | None -> raise (TestFailedException "") + | Some (m) -> + Printf.printf "Solver says: %s\n" (string_of_status q) ; + Printf.printf "Model: \n%s\n" (Model.to_string m) ; + Printf.printf "Converted Model: \n%s\n" (Model.to_string (convert_model ar 0 m)) + ) (** Some basic tests. @@ -41,59 +85,78 @@ let basic_tests ( ctx : context ) = (Goal.assert_ g [| trivial_eq |]) ; (Goal.assert_ g [| nontrivial_eq |]) ; Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; - let solver = (mk_solver ctx None) in - (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; - if (check solver None) != SATISFIABLE then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" ; - () ; - let ar = (Tactic.apply (mk_tactic ctx "simplify") g None) in - if ((get_num_subgoals ar) == 1 && - ((is_decided_sat (get_subgoal ar 0)) || - (is_decided_unsat (get_subgoal ar 0)))) then + ( + let solver = (mk_solver ctx None) in + (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; + if (check solver None) != SATISFIABLE then raise (TestFailedException "") else - let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_sat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - (Goal.assert_ g [| (mk_eq ctx (mk_numeral_int ctx 1 (BitVectors.mk_sort ctx 32)) - (mk_numeral_int ctx 2 (BitVectors.mk_sort ctx 32))) |] ) - ; - let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_unsat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - let g2 = (mk_goal ctx true true false) in - let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_sat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - () -(* - g2 = ctx.MkGoal(true, true); - g2.Assert(ctx.MkFalse()); - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) - throw new TestFailedException(); - - Goal g3 = ctx.MkGoal(true, true); - Expr xc = ctx.MkConst(ctx.MkSymbol("x"), ctx.IntSort); - Expr yc = ctx.MkConst(ctx.MkSymbol("y"), ctx.IntSort); - g3.Assert(ctx.MkEq(xc, ctx.MkNumeral(1, ctx.IntSort))); - g3.Assert(ctx.MkEq(yc, ctx.MkNumeral(2, ctx.IntSort))); - BoolExpr constr = ctx.MkEq(xc, yc); - g3.Assert(constr); - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g3); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) - throw new TestFailedException(); - - ModelConverterTest(ctx); - + Printf.printf "Test passed.\n" + ); + ( + let ar = (Tactic.apply (mk_tactic ctx "simplify") g None) in + if ((get_num_subgoals ar) == 1 && + ((is_decided_sat (get_subgoal ar 0)) || + (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_sat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + (Goal.assert_ g [| (mk_eq ctx (mk_numeral_int ctx 1 (BitVectors.mk_sort ctx 32)) + (mk_numeral_int ctx 2 (BitVectors.mk_sort ctx 32))) |] ) + ; + ( + let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let g2 = (mk_goal ctx true true false) in + let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_sat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let g2 = (mk_goal ctx true true false) in + (Goal.assert_ g2 [| (mk_false ctx) |]) ; + let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let g3 = (mk_goal ctx true true false) in + let xc = (mk_const ctx ((Symbol.mk_string ctx "x") :> symbol) (mk_int_sort ctx)) in + let yc = (mk_const ctx ((Symbol.mk_string ctx "y") :> symbol) (mk_int_sort ctx)) in + (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (mk_int_sort ctx))) |]) ; + (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (mk_int_sort ctx))) |]) ; + let constr = (mk_eq ctx xc yc) in + (Goal.assert_ g3 [| constr |] ) ; + let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ) ; + model_converter_test ctx +(* // Real num/den test. RatNum rn = ctx.MkReal(42, 43); Expr inum = rn.Numerator; diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 9b5ab1a7a..9587951ba 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -353,9 +353,13 @@ def check_ml(): r = exec_cmd([OCAMLC, 'hello.ml']) if r != 0: raise MKException('Failed testing ocamlopt compiler. Set environment variable OCAMLOPT with the path to the Ocaml native compiler') + os.remove('hello.cmi') + os.remove('hello.cmo') + os.remove('a.out') r = exec_cmd([OCAMLBUILD]) if r != 0: raise MKException('Failed testing ocamlbuild. Set environment variable OCAMLBUILD with the path to ocamlbuild') + shutil.rmtree('_build') find_ml_lib() def find_ml_lib(): @@ -499,7 +503,7 @@ def display_help(exit_code): if IS_WINDOWS: print(" -n, --nodotnet do not generate Microsoft.Z3.dll make rules.") print(" -j, --java generate Java bindings.") - print(" --ml generate Ocaml bindinds.") + print(" --ml generate OCaml bindings.") print(" --staticlib build Z3 static library.") if not IS_WINDOWS: print(" -g, --gmp use GMP.") diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 8806a70ee..c0711b4eb 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -4684,6 +4684,11 @@ module Solver = struct type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + let string_of_status ( s : status) = match s with + | UNSATISFIABLE -> "unsatisfiable" + | SATISFIABLE -> "satisfiable" + | _ -> "unknown" + (** Objects that track statistical information about solvers. *) module Statistics = struct From d0591334a262679f0f9f72541fe2d28c4097a068 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 7 Jan 2013 15:32:25 +0000 Subject: [PATCH 032/248] ML API: made native layer ANSI-C compliant to avoid compilation issues. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 12 ++++++---- scripts/update_api.py | 55 ++++++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 9587951ba..028d6c8d7 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -345,21 +345,20 @@ def check_ml(): t.commit() if is_verbose(): print "Testing %s..." % OCAMLC - r = exec_cmd([OCAMLC, 'hello.ml']) + r = exec_cmd([OCAMLC, '-o', 'a.out', 'hello.ml']) if r != 0: raise MKException('Failed testing ocamlc compiler. Set environment variable OCAMLC with the path to the Ocaml compiler') if is_verbose(): print "Testing %s..." % OCAMLOPT - r = exec_cmd([OCAMLC, 'hello.ml']) + r = exec_cmd([OCAMLC, '-o', 'a.out', 'hello.ml']) if r != 0: raise MKException('Failed testing ocamlopt compiler. Set environment variable OCAMLOPT with the path to the Ocaml native compiler') os.remove('hello.cmi') os.remove('hello.cmo') os.remove('a.out') - r = exec_cmd([OCAMLBUILD]) + r = exec_cmd([OCAMLBUILD, '-version']) if r != 0: raise MKException('Failed testing ocamlbuild. Set environment variable OCAMLBUILD with the path to ocamlbuild') - shutil.rmtree('_build') find_ml_lib() def find_ml_lib(): @@ -1350,7 +1349,10 @@ class MLComponent(Component): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) + if WINDOWS: + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) + else: + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) out.write('z3.cmxa: %s\n' % libfile) out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) out.write('z3.cma: %s\n' % libfile) diff --git a/scripts/update_api.py b/scripts/update_api.py index 5d95a12f8..1986f4a7e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1262,39 +1262,39 @@ def mk_ml(): ml_wrapper.write('#include \n\n') ml_wrapper.write('#define CAMLlocal6(X1,X2,X3,X4,X5,X6) \\\n') ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal1(X6); \n') + ml_wrapper.write(' CAMLlocal1(X6) \n') ml_wrapper.write('#define CAMLlocal7(X1,X2,X3,X4,X5,X6,X7) \\\n') ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal2(X6,X7); \n') + ml_wrapper.write(' CAMLlocal2(X6,X7) \n') ml_wrapper.write('#define CAMLlocal8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal3(X6,X7,X8); \n') + ml_wrapper.write(' CAMLlocal3(X6,X7,X8) \n') ml_wrapper.write('\n') ml_wrapper.write('#define CAMLparam7(X1,X2,X3,X4,X5,X6,X7) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam2(X6,X7); \n') + ml_wrapper.write(' CAMLxparam2(X6,X7) \n') ml_wrapper.write('#define CAMLparam8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam3(X6,X7,X8); \n') + ml_wrapper.write(' CAMLxparam3(X6,X7,X8) \n') ml_wrapper.write('#define CAMLparam9(X1,X2,X3,X4,X5,X6,X7,X8,X9) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam4(X6,X7,X8,X9); \n') + ml_wrapper.write(' CAMLxparam4(X6,X7,X8,X9) \n') ml_wrapper.write('#define CAMLparam12(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') - ml_wrapper.write(' CAMLxparam2(X11,X12); \n') + ml_wrapper.write(' CAMLxparam2(X11,X12) \n') ml_wrapper.write('#define CAMLparam13(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') - ml_wrapper.write(' CAMLxparam3(X11,X12,X13); \n') + ml_wrapper.write(' CAMLxparam3(X11,X12,X13) \n') ml_wrapper.write('\n\n') ml_wrapper.write('static struct custom_operations default_custom_ops = {\n') - ml_wrapper.write(' identifier: (char*) "default handling",\n') - ml_wrapper.write(' finalize: custom_finalize_default,\n') - ml_wrapper.write(' compare: custom_compare_default,\n') - ml_wrapper.write(' hash: custom_hash_default,\n') - ml_wrapper.write(' serialize: custom_serialize_default,\n') - ml_wrapper.write(' deserialize: custom_deserialize_default\n') + ml_wrapper.write(' (char*) "default handling",\n') + ml_wrapper.write(' custom_finalize_default,\n') + ml_wrapper.write(' custom_compare_default,\n') + ml_wrapper.write(' custom_hash_default,\n') + ml_wrapper.write(' custom_serialize_default,\n') + ml_wrapper.write(' custom_deserialize_default\n') ml_wrapper.write('};\n\n') ml_wrapper.write('#ifdef __cplusplus\n') ml_wrapper.write('extern "C" {\n') @@ -1358,7 +1358,10 @@ def mk_ml(): i = i + 1 ml_wrapper.write(');\n') - # preprocess arrays, strings, in/out arguments + if len(ap) != 0: + ml_wrapper.write(' unsigned _i;\n') + + # declare locals, preprocess arrays, strings, in/out arguments i = 0 for param in params: k = param_kind(param) @@ -1372,22 +1375,32 @@ def mk_ml(): elif k == IN_ARRAY or k == INOUT_ARRAY: t = param_type(param) ts = type2str(t) - ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) - ml_wrapper.write(' for (unsigned i = 0; i < _a%s; i++) _a%s[i] = %s;\n' % (param_array_capacity_pos(param), i, ml_unwrap(t, ts, 'Field(a' + str(i) + ', i)'))) + ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * _a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) elif k == IN: t = param_type(param) ml_wrapper.write(' %s _a%s = %s;\n' % (type2str(t), i, ml_unwrap(t, type2str(t), 'a' + str(i)))) elif k == OUT: ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) elif k == INOUT: - ml_wrapper.write(' %s _a%s = a%s;\n' % (type2str(param_type(param)), i, i)) - + ml_wrapper.write(' %s _a%s = a%s;\n' % (type2str(param_type(param)), i, i)) + i = i + 1 + + if result != VOID: + ml_wrapper.write(' %s z3_result;\n' % type2str(result)) + + i = 0 + for param in params: + k = param_kind(param) + if k == IN_ARRAY or k == INOUT_ARRAY: + t = param_type(param) + ts = type2str(t) + ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { _a%s[_i] = %s; }\n' % (param_array_capacity_pos(param), i, ml_unwrap(t, ts, 'Field(a' + str(i) + ', _i)'))) i = i + 1 # invoke procedure ml_wrapper.write(' ') if result != VOID: - ml_wrapper.write('%s z3_result = ' % type2str(result)) + ml_wrapper.write('z3_result = ') ml_wrapper.write('%s(' % name) i = 0 first = True @@ -1412,7 +1425,7 @@ def mk_ml(): for p in params: if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) - ml_wrapper.write(' for (unsigned i = 0; i < _a%s; i++) { value t; %s Store_field(_a%s, i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[i]'), i)) + ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) elif is_out_param(p): ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) i = i + 1 From 297604bee2850a857acd7e0b278fc901165f1a98 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 7 Jan 2013 18:49:19 +0000 Subject: [PATCH 033/248] ML API: linker fix --- scripts/mk_util.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 028d6c8d7..ce4ed7118 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1349,10 +1349,7 @@ class MLComponent(Component): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) - if WINDOWS: - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) - else: - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT) -L%s -lcamlrun\n' % (libfile, os.path.join('api', 'ml', 'z3native'), OCAML_LIB)) out.write('z3.cmxa: %s\n' % libfile) out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) out.write('z3.cma: %s\n' % libfile) From 35ef2d1c407bf20da54dae59e892776542ba8034 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 7 Jan 2013 18:56:19 +0000 Subject: [PATCH 034/248] ML API: bugfix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index ce4ed7118..68ede3b81 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1349,7 +1349,10 @@ class MLComponent(Component): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT) -L%s -lcamlrun\n' % (libfile, os.path.join('api', 'ml', 'z3native'), OCAML_LIB)) + if IS_WINDOWS: + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) + else: + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT) -L%s -lcamlrun\n' % (libfile, os.path.join('api', 'ml', 'z3native'), OCAML_LIB)) out.write('z3.cmxa: %s\n' % libfile) out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) out.write('z3.cma: %s\n' % libfile) From 7aef3fa5c6eaebb3fe9651b734ee8b7d51f91c76 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 7 Jan 2013 22:44:55 +0000 Subject: [PATCH 035/248] ML API: bugfix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 68ede3b81..ae2418be1 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1348,7 +1348,7 @@ class MLComponent(Component): for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I"%s" -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) if IS_WINDOWS: out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) else: From 9eea0f3232dc554c12531c7398581eaad6cec17b Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 8 Jan 2013 20:56:49 +0000 Subject: [PATCH 036/248] ML API: build system changes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 65 +++++++++++++++++++++++----------------------- src/api/ml/README | 5 ++++ 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index ae2418be1..9edbf2658 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -33,8 +33,7 @@ EXAMP_DEBUG_FLAG='' LDFLAGS=getenv("LDFLAGS", "") JNI_HOME=getenv("JNI_HOME", None) OCAMLC=getenv("OCAMLC", "ocamlc") -OCAMLOPT=getenv("OCAMLC", "ocamlopt") -OCAMLBUILD=getenv("OCAMLBUILD", "ocamlbuild") +OCAMLOPT=getenv("OCAMLOPT", "ocamlopt") OCAML_LIB=getenv("OCAML_LIB", None) CXX_COMPILERS=['g++', 'clang++'] @@ -350,15 +349,12 @@ def check_ml(): raise MKException('Failed testing ocamlc compiler. Set environment variable OCAMLC with the path to the Ocaml compiler') if is_verbose(): print "Testing %s..." % OCAMLOPT - r = exec_cmd([OCAMLC, '-o', 'a.out', 'hello.ml']) + r = exec_cmd([OCAMLOPT, '-o', 'a.out', 'hello.ml']) if r != 0: raise MKException('Failed testing ocamlopt compiler. Set environment variable OCAMLOPT with the path to the Ocaml native compiler') os.remove('hello.cmi') os.remove('hello.cmo') os.remove('a.out') - r = exec_cmd([OCAMLBUILD, '-version']) - if r != 0: - raise MKException('Failed testing ocamlbuild. Set environment variable OCAMLBUILD with the path to ocamlbuild') find_ml_lib() def find_ml_lib(): @@ -520,7 +516,6 @@ def display_help(exit_code): print(" JNI_HOME JNI bindings directory (only relevant if -j or --java option is provided)") print(" OCAMLC Ocaml byte-code compiler (only relevant with --ml)") print(" OCAMLOPT Ocaml native compiler (only relevant with --ml)") - print(" OCAMLBUILD Ocaml build system (only relevant with --ml)") print(" OCAML_LIB Ocaml library directory (only relevant with --ml)") exit(exit_code) @@ -1336,27 +1331,29 @@ class MLComponent(Component): def mk_makefile(self, out): if is_ml_enabled(): - deffile = open('%s.mllib' % os.path.join(self.src_dir, "z3"), 'w') + src_dir = self.to_src_dir + sub_dir = os.path.join('api', 'ml') + mk_dir(os.path.join(BUILD_DIR, sub_dir)) + for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): + shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) + for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): + shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) + out.write('z3.cmxa:') for mlfile in get_ml_files(self.src_dir): - deffile.write('%s\n' % (string.upper(mlfile[0]) + mlfile[1:-3])) - deffile.close() - - bld_dir = os.path.join(BUILD_DIR, 'api', 'ml') - mk_dir(bld_dir) - libfile = '%s$(SO_EXT)' % self.lib_name - out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'z3native.c'))) + out.write(' %s' % os.path.join(src_dir, mlfile)) + out.write('\n') + out.write('\tpushd %s && %s ' % (sub_dir, OCAMLOPT)) + if DEBUG_MODE: + out.write('-g ') + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cmxa -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) + out.write('z3.cma:') for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I"%s" -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) - if IS_WINDOWS: - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) - else: - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT) -L%s -lcamlrun\n' % (libfile, os.path.join('api', 'ml', 'z3native'), OCAML_LIB)) - out.write('z3.cmxa: %s\n' % libfile) - out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) - out.write('z3.cma: %s\n' % libfile) - out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -custom,-cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3native$(OBJ_EXT) z3.cma && cd -\n' % (self.to_src_dir,BUILD_DIR)) + out.write('\tpushd %s && %s ' % (sub_dir, OCAMLC)) + if DEBUG_MODE: + out.write('-g ') + out.write('-custom -ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cma -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) out.write('ml: z3.cmxa z3.cma\n') out.write('\n') @@ -1485,7 +1482,10 @@ class MLExampleComponent(ExampleComponent): for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') - out.write('\tocamlc -g -o ml_example.byte -I . z3.cma -I api/ml') + out.write('\t%s ' % OCAMLC) + if DEBUG_MODE: + out.write('-g ') + out.write('-custom -o ml_example.byte -I . z3.cma -I api/ml') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') @@ -1493,7 +1493,10 @@ class MLExampleComponent(ExampleComponent): for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') - out.write('\tocamlopt -g -o ml_example -I . z3.cmxa -I api/ml') + out.write('\t%s ' % OCAMLOPT) + if DEBUG_MODE: + out.write('-g ') + out.write('-o ml_example($EXE_EXT) -I . z3.cmxa -I api/ml') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') @@ -1648,10 +1651,9 @@ def mk_config(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) if is_ml_enabled(): - print('Ocaml Compiler: %s' % OCAMLC) - print('Ocaml Native: %s' % OCAMLOPT) - print('Ocamlbuild: %s' % OCAMLBUILD) - print('Ocaml Library: %s' % OCAML_LIB) + print('OCaml Compiler: %s' % OCAMLC) + print('OCaml Native: %s' % OCAMLOPT) + print('OCaml Library: %s' % OCAML_LIB) else: global CXX, CC, GMP, FOCI2, CPPFLAGS, CXXFLAGS, LDFLAGS, EXAMP_DEBUG_FLAG OS_DEFINES = "" @@ -1774,9 +1776,8 @@ def mk_config(): if is_ml_enabled(): print('Ocaml Compiler: %s' % OCAMLC) print('Ocaml Native: %s' % OCAMLOPT) - print('Ocamlbuild: %s' % OCAMLBUILD) print('Ocaml Library: %s' % OCAML_LIB) - + def mk_install(out): out.write('install: ') for c in get_components(): diff --git a/src/api/ml/README b/src/api/ml/README index 925fced59..beee7d864 100644 --- a/src/api/ml/README +++ b/src/api/ml/README @@ -1,3 +1,8 @@ This directory is work in progress. We are currently working on a brand new ML API. + +On Windows, there are no less than four different ports of OCaml. The Z3 build +system assumes that either the win32 or the win64 port is installed. This means +that OCaml will use `cl' as the underlying C compiler and not the cygwin or +mingw compilers. \ No newline at end of file From 9d965b5fec5b4d28c86971d78b3391e39977e143 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 8 Jan 2013 21:02:44 +0000 Subject: [PATCH 037/248] ML API: build system fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 9edbf2658..34a25781a 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -354,7 +354,10 @@ def check_ml(): raise MKException('Failed testing ocamlopt compiler. Set environment variable OCAMLOPT with the path to the Ocaml native compiler') os.remove('hello.cmi') os.remove('hello.cmo') + os.remove('hello.cmx') + os.remove('hello.obj') os.remove('a.out') + t.__del__() find_ml_lib() def find_ml_lib(): From b48c4449788a25bd4e14887614569516fae54d18 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 8 Jan 2013 21:22:45 +0000 Subject: [PATCH 038/248] ML API: build system fix --- scripts/mk_util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 34a25781a..c1f899f6d 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -357,7 +357,6 @@ def check_ml(): os.remove('hello.cmx') os.remove('hello.obj') os.remove('a.out') - t.__del__() find_ml_lib() def find_ml_lib(): From 1865ca58c3b2b9dc4a33de0dd6537bdf0e0897e2 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 8 Jan 2013 21:34:40 +0000 Subject: [PATCH 039/248] ML API: build system fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index c1f899f6d..75e2af52d 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -355,7 +355,6 @@ def check_ml(): os.remove('hello.cmi') os.remove('hello.cmo') os.remove('hello.cmx') - os.remove('hello.obj') os.remove('a.out') find_ml_lib() From be3fb0ef18a95ac75e3595872ab3698f37f93c34 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 10 Jan 2013 17:25:55 +0000 Subject: [PATCH 040/248] ML API: build system fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 75e2af52d..5530a7afd 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1339,23 +1339,26 @@ class MLComponent(Component): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) - out.write('z3.cmxa:') + out.write('libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CXX) $(CXXFLAGS) -I %s api/ml/z3native.c $(CXX_OUTFLAG) api/ml/z3native$(OBJ_EXT)\n' % get_component(API_COMPONENT).to_src_dir) + out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG) libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') + out.write('api/ml/z3.cmxa: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(src_dir, mlfile)) out.write('\n') - out.write('\tpushd %s && %s ' % (sub_dir, OCAMLOPT)) + out.write('\tcd %s && %s ' % (sub_dir, OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cmxa -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) - out.write('z3.cma:') + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" z3enums.ml z3native.ml z3.ml -a -o z3.cmxa -linkall && cd ../..\n' % get_component(API_COMPONENT).to_src_dir) + out.write('api/ml/z3.cma: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\tpushd %s && %s ' % (sub_dir, OCAMLC)) + out.write('\tcd %s && %s ' % (sub_dir, OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-custom -ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cma -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) - out.write('ml: z3.cmxa z3.cma\n') + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" z3enums.ml z3native.ml z3.ml -a -o z3.cma -linkall && cd ../..\n' % get_component(API_COMPONENT).to_src_dir) + out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') out.write('\n') def main_component(self): @@ -1479,29 +1482,29 @@ class MLExampleComponent(ExampleComponent): def mk_makefile(self, out): if ML_ENABLED: - out.write('ml_example.byte: z3.cma ') + out.write('ml_example.byte: api/ml/z3.cma ') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') out.write('\t%s ' % OCAMLC) if DEBUG_MODE: out.write('-g ') - out.write('-custom -o ml_example.byte -I . z3.cma -I api/ml') + out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" z3.cma') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('ml_example($EXE_EXT): z3.cmxa ml_example.byte') + out.write('ml_example$(EXE_EXT): api/ml/z3.cmxa ml_example.byte') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') out.write('\t%s ' % OCAMLOPT) if DEBUG_MODE: out.write('-g ') - out.write('-o ml_example($EXE_EXT) -I . z3.cmxa -I api/ml') + out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" z3.cmxa') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('_ex_%s: ml_example.byte ml_example($EXE_EXT)\n\n' % self.name) + out.write('_ex_%s: ml_example.byte ml_example$(EXE_EXT)\n\n' % self.name) class PythonExampleComponent(ExampleComponent): def __init__(self, name, path): From 381d552f9676bee85cd22e5cf0aa931066d57ea1 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 10 Jan 2013 18:39:43 +0000 Subject: [PATCH 041/248] ML API: build system fixes --- scripts/mk_util.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 5530a7afd..554bb4259 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -351,11 +351,11 @@ def check_ml(): print "Testing %s..." % OCAMLOPT r = exec_cmd([OCAMLOPT, '-o', 'a.out', 'hello.ml']) if r != 0: - raise MKException('Failed testing ocamlopt compiler. Set environment variable OCAMLOPT with the path to the Ocaml native compiler') - os.remove('hello.cmi') - os.remove('hello.cmo') - os.remove('hello.cmx') - os.remove('a.out') + raise MKException('Failed testing ocamlopt compiler. Set environment variable OCAMLOPT with the path to the Ocaml native compiler. Note that ocamlopt may require flexlink to be in your path.') + rmf('hello.cmi') + rmf('hello.cmo') + rmf('hello.cmx') + rmf('a.out') find_ml_lib() def find_ml_lib(): @@ -1340,8 +1340,8 @@ class MLComponent(Component): for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) out.write('libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s api/ml/z3native.c $(CXX_OUTFLAG) api/ml/z3native$(OBJ_EXT)\n' % get_component(API_COMPONENT).to_src_dir) - out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG) libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') + out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s api/ml/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, get_component(API_COMPONENT).to_src_dir)) + out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') out.write('api/ml/z3.cmxa: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(src_dir, mlfile)) From 0e59d056298fc0eadeec20584f3c3d3cb31d5a26 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 11 Jan 2013 14:33:28 +0000 Subject: [PATCH 042/248] ML API: changed context from object to normal type. Removed optional array parameters. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 8 +- src/api/ml/z3.ml | 661 ++++++++++++++++++-------------------- 2 files changed, 323 insertions(+), 346 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 0e8122ae0..129f73d4d 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -38,7 +38,7 @@ let model_converter_test ( ctx : context ) = Printf.printf "Test passed.\n" ); ( - let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") None) g4 None) in + let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") [||]) g4 None) in if ((get_num_subgoals ar) == 1 && ((is_decided_sat (get_subgoal ar 0)) || (is_decided_unsat (get_subgoal ar 0)))) then @@ -49,7 +49,7 @@ let model_converter_test ( ctx : context ) = let solver = (mk_solver ctx None) in let f e = (Solver.assert_ solver [| e |]) in ignore (Array.map f (get_formulas (get_subgoal ar 0))) ; - let q = (check solver None) in + let q = (check solver [||]) in if q != SATISFIABLE then raise (TestFailedException "") else @@ -88,7 +88,7 @@ let basic_tests ( ctx : context ) = ( let solver = (mk_solver ctx None) in (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; - if (check solver None) != SATISFIABLE then + if (check solver [||]) != SATISFIABLE then raise (TestFailedException "") else Printf.printf "Test passed.\n" @@ -204,7 +204,7 @@ let _ = else ( Printf.printf "Running Z3 version %s\n" Version.to_string ; - let cfg = (Some [("model", "true"); ("proof", "false")]) in + let cfg = [("model", "true"); ("proof", "false")] in let ctx = (mk_context cfg) in let is = (Symbol.mk_int ctx 42) in let ss = (Symbol.mk_string ctx "mySymbol") in diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c0711b4eb..c91d909bc 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,46 +7,39 @@ open Z3enums +type context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } + (**/**) +let context_dispose ctx = + if ctx.m_n_obj_cnt == 0 then ( + (* Printf.printf "Disposing context \n" ; *) + (Z3native.del_context ctx.m_n_ctx) + ) else ( + Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; + (* re-queue for finalization? *) + ) -class context settings = -object (self) - val mutable m_n_ctx : Z3native.z3_context = - let cfg = Z3native.mk_config in - let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in - (List.iter f settings) ; - let v = Z3native.mk_context_rc cfg in - Z3native.del_config(cfg) ; - Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; - v - +let context_init settings = + let cfg = Z3native.mk_config in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = Z3native.mk_context_rc cfg in + Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + (* Printf.printf "Installing finalizer on context \n" ; *) + let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in + let f = fun o -> context_dispose o in + Gc.finalise f res; + res (* CMW: Install error handler here! m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. Z3native.set_error_handler(m_ctx, m_n_err_handler); GC.SuppressFinalize(this); *) - val mutable m_obj_cnt : int = 0 - - initializer - (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) - let f = fun o -> o#dispose in - let v = self in - Gc.finalise f v; - - method dispose : unit = - if m_obj_cnt == 0 then ( - (* Printf.printf "Disposing context %d \n" (Oo.id self) ; *) - (Z3native.del_context m_n_ctx) - ) else ( - Printf.printf "NOT DISPOSING context %d because it still has %d objects alive\n" (Oo.id self) m_obj_cnt; - (* re-queue for finalization? *) - ) - - method add_one_ctx_obj = m_obj_cnt <- m_obj_cnt + 1 - method sub_one_ctx_obj = m_obj_cnt <- m_obj_cnt - 1 - method gno = m_n_ctx -end +let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) +let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) +let context_gno ctx = ctx.m_n_ctx (**/**) @@ -70,10 +63,8 @@ the context, e.g., like so: (...) *) -let mk_context ( cfg : ( string * string ) list option ) = - match cfg with - | None -> new context [] - | Some(x) -> new context x +let mk_context ( cfg : ( string * string ) list ) = + context_init cfg (**/**) @@ -85,8 +76,8 @@ object (self) initializer (match m_n_obj with - | Some (x) -> self#incref m_ctx#gno x; - m_ctx#add_one_ctx_obj + | Some (x) -> self#incref (context_gno m_ctx) x; + (context_add1 m_ctx) | None -> () ); (* Printf.printf "Installing finalizer on z3object %d \n" (Oo.id self) ; *) @@ -101,8 +92,8 @@ object (self) (* Printf.printf "Disposing z3object %d \n" (Oo.id self) ; *) (match m_n_obj with | Some (x) -> - self#decref m_ctx#gno x; - m_ctx#sub_one_ctx_obj ; + self#decref (context_gno m_ctx) x; + (context_sub1 m_ctx) ; m_n_obj <- None; | None -> () ); @@ -112,16 +103,16 @@ object (self) | None -> raise (Z3native.Exception "Z3 object lost") method sno (ctx : context) o = - m_ctx#add_one_ctx_obj ; - self#incref ctx#gno o ; + (context_add1 m_ctx) ; + self#incref (context_gno ctx) o ; (match m_n_obj with - | Some(x) -> self#decref ctx#gno x ; m_ctx#sub_one_ctx_obj + | Some(x) -> self#decref (context_gno ctx) x ; (context_sub1 m_ctx) | None -> () ); m_n_obj <- Some o method gc = m_ctx - method gnc = m_ctx#gno + method gnc = (context_gno m_ctx) end @@ -134,37 +125,38 @@ object (self) method decref nc o = Z3native.params_dec_ref nc o end + (** Symbol objects *) -class symbol ctx = +class symbol ctx = object (self) - inherit z3object ctx None as super + inherit z3object ctx None as super method cnstr_obj obj = (self#sno ctx obj) ; self method incref nc o = () method decref nc o = () end +(** Int symbol objects *) +class int_symbol ctx = +object(self) + inherit symbol ctx as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_int i = (self#sno ctx (Z3native.mk_int_symbol (context_gno ctx) i)) ; self +end + +(** String symbol objects *) +class string_symbol ctx = +object(self) + inherit symbol ctx as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_string name = (self#sno ctx (Z3native.mk_string_symbol (context_gno ctx) name)) ; self +end + let symbolaton (a : symbol array) = let f (e : symbol) = e#gno in Array.map f a -(** Int symbol objects *) -class int_symbol ctx = -object(self) - inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_int i = (self#sno ctx (Z3native.mk_int_symbol ctx#gno i)) ; self -end - -(** String symbol objects *) -class string_symbol ctx = -object(self) - inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_string name = (self#sno ctx (Z3native.mk_string_symbol ctx#gno name)) ; self -end - let create_symbol ctx no = - match (symbol_kind_of_int (Z3native.get_symbol_kind ctx#gno no)) with + match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj no) :> symbol) | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj no) :> symbol) @@ -205,7 +197,7 @@ class array_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx (Z3native.mk_array_sort ctx#gno domain#gno range#gno)) ; self + method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx (Z3native.mk_array_sort (context_gno ctx) domain#gno range#gno)) ; self end (** Bit-vector sort objects *) @@ -241,7 +233,7 @@ class uninterpreted_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_s (s : symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort ctx#gno s#gno)) ; self + method cnstr_s (s : symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) s#gno)) ; self end (** Finite domain sort objects *) @@ -249,7 +241,7 @@ class finite_domain_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort ctx#gno s#gno sz)) ; self + method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort (context_gno ctx) s#gno sz)) ; self end (** Relation sort objects *) @@ -273,7 +265,7 @@ object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_siss (name : symbol) (num_fields: int) (field_names : symbol array) (field_sorts : sort array) = - let (x,_,_) = (Z3native.mk_tuple_sort ctx#gno name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in + let (x,_,_) = (Z3native.mk_tuple_sort (context_gno ctx) name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in (self#sno ctx x) ; self end @@ -284,8 +276,8 @@ class func_decl ctx = object (self) inherit ast ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl ctx#gno name#gno (Array.length domain) (astaton domain) range#gno)) ; self - method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl ctx#gno prefix (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl (context_gno ctx) name#gno (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (astaton domain) range#gno)) ; self method incref nc o = super#incref nc o method decref nc o = super#decref nc o @@ -341,7 +333,7 @@ object (self) val mutable _testerdecls : func_decl array option = None method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (enum_names : symbol array) = - let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in + let (r, a, b) = (Z3native.mk_enumeration_sort (context_gno ctx) name#gno (Array.length enum_names) (symbolaton enum_names)) in _constdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f a)) ; _testerdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f b)) ; (self#sno ctx r) ; @@ -368,7 +360,7 @@ object (self) val mutable _taildecl : func_decl option = None method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (elem_sort : sort) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) name#gno elem_sort#gno) in _nildecl <- Some ((new func_decl ctx)#cnstr_obj a) ; _is_nildecl <- Some ((new func_decl ctx)#cnstr_obj b) ; _consdecl <- Some ((new func_decl ctx)#cnstr_obj c) ; @@ -426,7 +418,7 @@ object (self) if m_n != (Array.length sort_refs) then raise (Z3native.Exception "Number of field names does not match number of sort refs") else - let o = (Z3native.mk_constructor ctx#gno name#gno recognizer#gno m_n (symbolaton field_names) + let o = (Z3native.mk_constructor (context_gno ctx) name#gno recognizer#gno m_n (symbolaton field_names) (sortaton sorts) sort_refs) in self#sno ctx o ; @@ -473,7 +465,7 @@ object (self) Gc.finalise f v method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ca ( c : constructor array ) = - self#sno ctx (Z3native.mk_constructor_list ctx#gno (Array.length c) (constructoraton c)) ; + self#sno ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (constructoraton c)) ; self end @@ -486,11 +478,11 @@ class datatype_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_sc (name : symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (constructoraton constructors)))) ; self + method cnstr_sc (name : symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype (context_gno ctx) name#gno (Array.length constructors) (constructoraton constructors)))) ; self end let create_sort ctx obj = - match (sort_kind_of_int (Z3native.get_sort_kind ctx#gno obj)) with + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) obj)) with | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) @@ -900,7 +892,7 @@ struct Create a new Boolean sort. *) let mk_bool ( ctx : context ) = - (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort ctx#gno) + (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort (context_gno ctx)) (** Create a new uninterpreted sort. @@ -917,15 +909,15 @@ end (**/**) let create_expr ctx obj = - if ast_kind_of_int (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then (((new quantifier ctx)#cnstr_obj obj) :> expr) else - let s = Z3native.get_sort ctx#gno obj in - let sk = (sort_kind_of_int (Z3native.get_sort_kind ctx#gno s)) in - if (Z3native.is_algebraic_number ctx#gno obj) then + let s = Z3native.get_sort (context_gno ctx) obj in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) obj) then (((new algebraic_num ctx)#cnstr_obj obj) :> expr) else - if (Z3native.is_numeral_ast ctx#gno obj) && + if (Z3native.is_numeral_ast (context_gno ctx) obj) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) @@ -943,11 +935,11 @@ let create_expr ctx obj = | _ -> (new expr ctx)#cnstr_obj obj let create_expr_fa (ctx : context) (f : func_decl) (args : expr array) = - let o = Z3native.mk_app ctx#gno f#gno (Array.length args) (astaton args) in + let o = Z3native.mk_app (context_gno ctx) f#gno (Array.length args) (astaton args) in create_expr ctx o let create_ast ctx no = - match (ast_kind_of_int (Z3native.get_ast_kind ctx#gno no)) with + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with | FUNC_DECL_AST -> (((new func_decl ctx)#cnstr_obj no) :> ast) | QUANTIFIER_AST -> (((new quantifier ctx)#cnstr_obj no) :> ast) | SORT_AST -> ((create_sort ctx no) :> ast) @@ -1188,7 +1180,7 @@ struct @return A new ASTVector *) let translate ( x : ast_vector ) ( to_ctx : context ) = - (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno to_ctx#gno) + (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno (context_gno to_ctx)) (** Retrieves a string representation of the vector. *) let to_string ( x : ast_vector ) = @@ -1337,7 +1329,7 @@ struct if x#gc == to_ctx then x else - (create_ast to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno)) + (create_ast to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx))) (** Wraps an AST. @@ -1383,13 +1375,13 @@ struct a string describing all available parameters to Expr.Simplify. *) let get_simplify_help ( ctx : context ) = - Z3native.simplify_get_help ctx#gno + Z3native.simplify_get_help (context_gno ctx) (** Retrieves parameter descriptions for simplifier. *) let get_simplify_parameter_descrs ( ctx : context ) = - (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs ctx#gno) + (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. @@ -1462,7 +1454,7 @@ struct if x#gc == to_ctx then x else - create_expr to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno) + create_expr to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx)) (** Returns a string representation of the expression. @@ -1578,7 +1570,7 @@ struct Creates a new Constant of sort and named . *) let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = - create_expr ctx (Z3native.mk_const ctx#gno name#gno range#gno) + create_expr ctx (Z3native.mk_const (context_gno ctx) name#gno range#gno) (** @@ -1600,7 +1592,7 @@ struct name prefixed with . *) let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort) = - create_expr ctx (Z3native.mk_fresh_const ctx#gno prefix range#gno) + create_expr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix range#gno) (** Create a Boolean constant. @@ -1624,13 +1616,13 @@ struct The true Term. *) let mk_true ( ctx : context ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_true ctx#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_true (context_gno ctx)) (** The false Term. *) let mk_false ( ctx : context ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_false ctx#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_false (context_gno ctx)) (** Creates a Boolean value. @@ -1642,19 +1634,19 @@ struct Creates the equality = . *) let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_eq ctx#gno x#gno y#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_eq (context_gno ctx) x#gno y#gno) (** Creates a distinct term. *) let mk_distinct ( ctx : context ) ( args : expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_distinct ctx#gno (Array.length args) (astaton args)) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_distinct (context_gno ctx) (Array.length args) (astaton args)) (** Mk an expression representing not(a). *) let mk_not ( ctx : context ) ( a : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_not ctx#gno a#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_not (context_gno ctx) a#gno) (** Create an expression representing an if-then-else: ite(t1, t2, t3). @@ -1663,37 +1655,37 @@ struct @param t3 An expression with the same sort as *) let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - create_expr ctx (Z3native.mk_ite ctx#gno t1#gno t2#gno t3#gno) + create_expr ctx (Z3native.mk_ite (context_gno ctx) t1#gno t2#gno t3#gno) (** Create an expression representing t1 iff t2. *) let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_iff ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_iff (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 -> t2. *) let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_implies ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_implies (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 xor t2. *) let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_xor ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_xor (context_gno ctx) t1#gno t2#gno) (** Create an expression representing the AND of args *) let mk_and ( ctx : context ) ( args : bool_expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_and ctx#gno (Array.length args) (astaton args)) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_and (context_gno ctx) (Array.length args) (astaton args)) (** Create an expression representing the OR of args *) let mk_or ( ctx : context ) ( args : bool_expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_or ctx#gno (Array.length args) (astaton args)) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_or (context_gno ctx) (Array.length args) (astaton args)) (** Create a numeral of a given sort. @@ -1702,7 +1694,7 @@ struct @return A Term with value and sort *) let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = - create_expr ctx (Z3native.mk_numeral ctx#gno v ty#gno) + create_expr ctx (Z3native.mk_numeral (context_gno ctx) v ty#gno) (** Create a numeral of a given sort. This function can be use to create numerals that fit in a machine integer. @@ -1712,7 +1704,7 @@ struct @return A Term with value and type *) let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_int ctx#gno v ty#gno) + create_expr ctx (Z3native.mk_int (context_gno ctx) v ty#gno) end (** Quantifier expressions *) @@ -1845,7 +1837,7 @@ struct @param ty The sort of the variable *) let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_bound ctx#gno index ty#gno) + create_expr ctx (Z3native.mk_bound (context_gno ctx) index ty#gno) (** Create a quantifier pattern. @@ -1854,7 +1846,7 @@ struct if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - (new pattern ctx)#cnstr_obj (Z3native.mk_pattern ctx#gno (Array.length terms) (astaton terms)) + (new pattern ctx)#cnstr_obj (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (astaton terms)) (** Create a universal Quantifier. @@ -1875,27 +1867,24 @@ struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") - else if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno true + else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) (Array.length sorts) (astaton sorts) (astaton names) body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno true + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) - (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) - (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) + (Array.length nopatterns) (patternaton nopatterns) (Array.length sorts) (astaton sorts) (astaton names) body#gno) @@ -1903,51 +1892,45 @@ struct (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = - if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno true + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expraton bound_constants) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno true + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) (Array.length bound_constants) (expraton bound_constants) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) - (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) - (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) + (Array.length nopatterns) (patternaton nopatterns) body#gno) (** Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") - else if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno false + else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) (Array.length sorts) (astaton sorts) (astaton names) body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno false + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) - (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) - (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) + (Array.length nopatterns) (patternaton nopatterns) (Array.length sorts) (astaton sorts) (astaton names) body#gno) @@ -1955,31 +1938,28 @@ struct (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = - if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno false + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expraton bound_constants) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno false + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) (Array.length bound_constants) (expraton bound_constants) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) - (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) - (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) + (Array.length nopatterns) (patternaton nopatterns) body#gno) (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -1989,7 +1969,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -2081,7 +2061,7 @@ struct *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - ((create_expr ctx (Z3native.mk_select ctx#gno a#gno i#gno)) :> array_expr) + ((create_expr ctx (Z3native.mk_select (context_gno ctx) a#gno i#gno)) :> array_expr) (** Array update. @@ -2100,7 +2080,7 @@ struct *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr) = - (new array_expr ctx)#cnstr_obj (Z3native.mk_store ctx#gno a#gno i#gno v#gno) + (new array_expr ctx)#cnstr_obj (Z3native.mk_store (context_gno ctx) a#gno i#gno v#gno) (** Create a constant array. @@ -2111,7 +2091,7 @@ struct *) let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - (new array_expr ctx)#cnstr_obj (Z3native.mk_const_array ctx#gno domain#gno v#gno) + (new array_expr ctx)#cnstr_obj (Z3native.mk_const_array (context_gno ctx) domain#gno v#gno) (** Maps f on the argument arrays. @@ -2124,7 +2104,7 @@ struct *) let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = - ((create_expr ctx (Z3native.mk_map ctx#gno f#gno (Array.length args) (astaton args))) :> array_expr) + ((create_expr ctx (Z3native.mk_map (context_gno ctx) f#gno (Array.length args) (astaton args))) :> array_expr) (** Access the array default value. @@ -2133,7 +2113,7 @@ struct finite maps with a default range value. *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = - ((create_expr ctx (Z3native.mk_array_default ctx#gno arg#gno)) :> array_expr) + ((create_expr ctx (Z3native.mk_array_default (context_gno ctx) arg#gno)) :> array_expr) end (** Functions to manipulate Set expressions *) @@ -2174,61 +2154,61 @@ struct Create an empty set. *) let mk_empty ( ctx : context ) ( domain : sort ) = - (create_expr ctx (Z3native.mk_empty_set ctx#gno domain#gno)) + (create_expr ctx (Z3native.mk_empty_set (context_gno ctx) domain#gno)) (** Create the full set. *) let mk_full ( ctx : context ) ( domain : sort ) = - create_expr ctx (Z3native.mk_full_set ctx#gno domain#gno) + create_expr ctx (Z3native.mk_full_set (context_gno ctx) domain#gno) (** Add an element to the set. *) let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_add ctx#gno set#gno element#gno) + create_expr ctx (Z3native.mk_set_add (context_gno ctx) set#gno element#gno) (** Remove an element from a set. *) let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_del ctx#gno set#gno element#gno) + create_expr ctx (Z3native.mk_set_del (context_gno ctx) set#gno element#gno) (** Take the union of a list of sets. *) let mk_union ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_union ctx#gno (Array.length args) (astaton args)) + create_expr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (astaton args)) (** Take the intersection of a list of sets. *) let mk_intersection ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_intersect ctx#gno (Array.length args) (astaton args)) + create_expr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (astaton args)) (** Take the difference between two sets. *) let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_difference ctx#gno arg1#gno arg2#gno) + create_expr ctx (Z3native.mk_set_difference (context_gno ctx) arg1#gno arg2#gno) (** Take the complement of a set. *) let mk_complement ( ctx : context ) ( arg : expr ) = - create_expr ctx (Z3native.mk_set_complement ctx#gno arg#gno) + create_expr ctx (Z3native.mk_set_complement (context_gno ctx) arg#gno) (** Check for set membership. *) let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - create_expr ctx (Z3native.mk_set_member ctx#gno elem#gno set#gno) + create_expr ctx (Z3native.mk_set_member (context_gno ctx) elem#gno set#gno) (** Check for subsetness of sets. *) let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_subset ctx#gno arg1#gno arg2#gno) + create_expr ctx (Z3native.mk_set_subset (context_gno ctx) arg1#gno arg2#gno) end @@ -2458,7 +2438,7 @@ struct let n = (Array.length names) in let f e = ( (new constructor_list ctx)#cnstr_ca e ) in let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes ctx#gno n (symbolaton names) (constructor_listaton cla)) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (symbolaton names) (constructor_listaton cla)) in let g e = ( (new datatype_sort ctx)#cnstr_obj e) in (Array.map g r) @@ -2592,13 +2572,13 @@ struct Create a new integer sort. *) let mk_int_sort ( ctx : context ) = - (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort ctx#gno) + (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort (context_gno ctx)) (** Create a real sort. *) let mk_real_sort ( ctx : context ) = - (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort ctx#gno) + (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort (context_gno ctx)) (** Indicates whether the term is of integer sort. @@ -2761,75 +2741,75 @@ struct Create an expression representing t[0] + t[1] + .... *) let mk_add ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_add ctx#gno (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) (** Create an expression representing t[0] * t[1] * .... *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_mul ctx#gno (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) (** Create an expression representing t[0] - t[1] - .... *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_sub ctx#gno (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) (** Create an expression representing -t. *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - (create_expr ctx (Z3native.mk_unary_minus ctx#gno t#gno) :> arith_expr) + (create_expr ctx (Z3native.mk_unary_minus (context_gno ctx) t#gno) :> arith_expr) (** Create an expression representing t1 / t2. *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - (create_expr ctx (Z3native.mk_div ctx#gno t1#gno t2#gno) :> arith_expr) + (create_expr ctx (Z3native.mk_div (context_gno ctx) t1#gno t2#gno) :> arith_expr) (** Create an expression representing t1 mod t2. The arguments must have int type. *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_mod ctx#gno t1#gno t2#gno) + (new int_expr ctx)#cnstr_obj (Z3native.mk_mod (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 rem t2. The arguments must have int type. *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_rem ctx#gno t1#gno t2#gno) + (new int_expr ctx)#cnstr_obj (Z3native.mk_rem (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 ^ t2. *) let mk_Power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (create_expr ctx (Z3native.mk_power ctx#gno t1#gno t2#gno) :> arith_expr) + (create_expr ctx (Z3native.mk_power (context_gno ctx) t1#gno t2#gno) :> arith_expr) (** Create an expression representing t1 < t2 *) let mk_lt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_lt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_lt (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 <= t2 *) let mk_le ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_le ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_le (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 > t2 *) let mk_gt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_gt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_gt (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 >= t2 *) let mk_ge ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_ge ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_ge (context_gno ctx) t1#gno t2#gno) (** Coerce an integer to a real. @@ -2842,7 +2822,7 @@ struct The argument must be of integer sort. *) let mk_int2real ( ctx : context ) ( t : int_expr ) = - (new real_expr ctx)#cnstr_obj (Z3native.mk_int2real ctx#gno t#gno) + (new real_expr ctx)#cnstr_obj (Z3native.mk_int2real (context_gno ctx) t#gno) (** Coerce a real to an integer. @@ -2852,13 +2832,13 @@ struct The argument must be of real sort. *) let mk_real2int ( ctx : context ) ( t : real_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_real2int ctx#gno t#gno) + (new int_expr ctx)#cnstr_obj (Z3native.mk_real2int (context_gno ctx) t#gno) (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_is_int ctx#gno t#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_is_int (context_gno ctx) t#gno) (** Return a upper bound for a given real algebraic number. @@ -2898,7 +2878,7 @@ struct raise (Z3native.Exception "Denominator is zero") else - (new rat_num ctx)#cnstr_obj (Z3native.mk_real ctx#gno num den) + (new rat_num ctx)#cnstr_obj (Z3native.mk_real (context_gno ctx) num den) (** Create a real numeral. @@ -2906,7 +2886,7 @@ struct @return A Term with value and sort Real *) let mk_real_numeral_s ( ctx : context ) ( v : string ) = - (new rat_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_real_sort ctx)#gno) + (new rat_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_real_sort ctx)#gno) (** Create a real numeral. @@ -2915,14 +2895,14 @@ struct @return A Term with value and sort Real *) let mk_real_numeral_i ( ctx : context ) ( v : int ) = - (new rat_num ctx)#cnstr_obj (Z3native.mk_int ctx#gno v (mk_real_sort ctx)#gno) + (new rat_num ctx)#cnstr_obj (Z3native.mk_int (context_gno ctx) v (mk_real_sort ctx)#gno) (** Create an integer numeral. @param v A string representing the Term value in decimal notation. *) let mk_int_numeral_s ( ctx : context ) ( v : string ) = - (new int_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_int_sort ctx)#gno) + (new int_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_int_sort ctx)#gno) (** Create an integer numeral. @@ -2930,7 +2910,7 @@ struct @return A Term with value and sort Integer *) let mk_int_numeral_i ( ctx : context ) ( v : int ) = - (new int_num ctx)#cnstr_obj (Z3native.mk_int ctx#gno v (mk_int_sort ctx)#gno) + (new int_num ctx)#cnstr_obj (Z3native.mk_int (context_gno ctx) v (mk_int_sort ctx)#gno) (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -2944,7 +2924,7 @@ struct Create a new bit-vector sort. *) let mk_sort ( ctx : context ) size = - (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort ctx#gno size) + (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort (context_gno ctx) size) (** Indicates whether the terms is of bit-vector sort. @@ -3245,91 +3225,91 @@ struct The argument must have a bit-vector sort. *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnot ctx#gno t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnot (context_gno ctx) t#gno) (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredand ctx#gno t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredand (context_gno ctx) t#gno) (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredor ctx#gno t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredor (context_gno ctx) t#gno) (** Bitwise conjunction. The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvand ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvand (context_gno ctx) t1#gno t2#gno) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvor ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvor (context_gno ctx) t1#gno t2#gno) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxor ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxor (context_gno ctx) t1#gno t2#gno) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnand ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnand (context_gno ctx) t1#gno t2#gno) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnor ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnor (context_gno ctx) t1#gno t2#gno) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxnor ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxnor (context_gno ctx) t1#gno t2#gno) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvneg ctx#gno t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvneg (context_gno ctx) t#gno) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvadd ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvadd (context_gno ctx) t1#gno t2#gno) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsub ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsub (context_gno ctx) t1#gno t2#gno) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvmul ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvmul (context_gno ctx) t1#gno t2#gno) (** Unsigned division. @@ -3341,7 +3321,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvudiv ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvudiv (context_gno ctx) t1#gno t2#gno) (** Signed division. @@ -3356,7 +3336,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv (context_gno ctx) t1#gno t2#gno) (** Unsigned remainder. @@ -3366,7 +3346,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvurem ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvurem (context_gno ctx) t1#gno t2#gno) (** Signed remainder. @@ -3378,7 +3358,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsrem ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsrem (context_gno ctx) t1#gno t2#gno) (** Two's complement signed remainder (sign follows divisor). @@ -3387,7 +3367,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsmod ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsmod (context_gno ctx) t1#gno t2#gno) (** Unsigned less-than @@ -3395,7 +3375,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvult ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvult (context_gno ctx) t1#gno t2#gno) (** Two's complement signed less-than @@ -3403,7 +3383,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvslt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvslt (context_gno ctx) t1#gno t2#gno) (** Unsigned less-than or equal to. @@ -3411,7 +3391,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvule ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvule (context_gno ctx) t1#gno t2#gno) (** Two's complement signed less-than or equal to. @@ -3419,7 +3399,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsle ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsle (context_gno ctx) t1#gno t2#gno) (** Unsigned greater than or equal to. @@ -3427,7 +3407,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvuge ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvuge (context_gno ctx) t1#gno t2#gno) (** Two's complement signed greater than or equal to. @@ -3435,7 +3415,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_SGE ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsge ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsge (context_gno ctx) t1#gno t2#gno) (** Unsigned greater-than. @@ -3443,7 +3423,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvugt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvugt (context_gno ctx) t1#gno t2#gno) (** Two's complement signed greater-than. @@ -3451,7 +3431,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsgt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsgt (context_gno ctx) t1#gno t2#gno) (** Bit-vector concatenation. @@ -3462,7 +3442,7 @@ struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_concat ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_concat (context_gno ctx) t1#gno t2#gno) (** Bit-vector extraction. @@ -3473,7 +3453,7 @@ struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_extract ctx#gno high low t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_extract (context_gno ctx) high low t#gno) (** Bit-vector sign extension. @@ -3483,7 +3463,7 @@ struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_sign_ext ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_sign_ext (context_gno ctx) i t#gno) (** Bit-vector zero extension. @@ -3494,7 +3474,7 @@ struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_zero_ext ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_zero_ext (context_gno ctx) i t#gno) (** Bit-vector repetition. @@ -3502,7 +3482,7 @@ struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_repeat ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_repeat (context_gno ctx) i t#gno) (** Shift left. @@ -3517,7 +3497,7 @@ struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvshl ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvshl (context_gno ctx) t1#gno t2#gno) (** Logical shift right @@ -3531,7 +3511,7 @@ struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvlshr ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvlshr (context_gno ctx) t1#gno t2#gno) (** Arithmetic shift right @@ -3547,7 +3527,7 @@ struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvashr ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvashr (context_gno ctx) t1#gno t2#gno) (** Rotate Left. @@ -3556,7 +3536,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_left ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_left (context_gno ctx) i t#gno) (** Rotate Right. @@ -3565,7 +3545,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_right ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_right (context_gno ctx) i t#gno) (** Rotate Left. @@ -3574,7 +3554,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_left ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_left (context_gno ctx) t1#gno t2#gno) (** Rotate Right. @@ -3584,7 +3564,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_right ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_right (context_gno ctx) t1#gno t2#gno) (** Create an bit bit-vector from the integer argument . @@ -3597,7 +3577,7 @@ struct The argument must be of integer sort. *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_int2bv ctx#gno n t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_int2bv (context_gno ctx) n t#gno) (** Create an integer from the bit-vector argument . @@ -3615,7 +3595,7 @@ struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int ctx#gno t#gno signed) + (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int (context_gno ctx) t#gno signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3623,7 +3603,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow ctx#gno t1#gno t2#gno signed) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow (context_gno ctx) t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3631,7 +3611,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_underflow ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_underflow (context_gno ctx) t1#gno t2#gno) (** Create a predicate that checks that the bit-wise subtraction does not overflow. @@ -3639,7 +3619,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_overflow ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_overflow (context_gno ctx) t1#gno t2#gno) (** Create a predicate that checks that the bit-wise subtraction does not underflow. @@ -3647,7 +3627,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow ctx#gno t1#gno t2#gno signed) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow (context_gno ctx) t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3655,7 +3635,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv_no_overflow ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) t1#gno t2#gno) (** Create a predicate that checks that the bit-wise negation does not overflow. @@ -3663,7 +3643,7 @@ struct The arguments must be of bit-vector sort. *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvneg_no_overflow ctx#gno t#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvneg_no_overflow (context_gno ctx) t#gno) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3671,7 +3651,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow ctx#gno t1#gno t2#gno signed) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow (context_gno ctx) t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3679,7 +3659,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow (context_gno ctx) t1#gno t2#gno) (** Create a bit-vector numeral. @@ -3688,7 +3668,7 @@ struct @param size the size of the bit-vector *) let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = - (new bitvec_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_sort ctx size)#gno) + (new bitvec_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_sort ctx size)#gno) end (** Functions to manipulate proof expressions *) @@ -4248,7 +4228,7 @@ end Creates a new parameter set *) let mk_params ( ctx : context ) = - (new params ctx)#cnstr_obj (Z3native.mk_params ctx#gno) + (new params ctx)#cnstr_obj (Z3native.mk_params (context_gno ctx)) (** A string representation of the parameter set. @@ -4329,7 +4309,7 @@ struct (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = - (new goal to_ctx)#cnstr_obj (Z3native.goal_translate x#gnc x#gno to_ctx#gno) + (new goal to_ctx)#cnstr_obj (Z3native.goal_translate x#gnc x#gno (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) let simplify ( x : goal ) ( p : params option ) = @@ -4360,7 +4340,7 @@ struct @param proofs Indicates whether proof generation should be enabled. *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - (new goal ctx)#cnstr_obj (Z3native.mk_goal ctx#gno models unsat_cores proofs) + (new goal ctx)#cnstr_obj (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno @@ -4429,14 +4409,14 @@ end (** The number of supported tactics. *) - let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics ctx#gno + let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) (** The names of all supported tactics. *) let get_tactic_names ( ctx : context ) = let n = (get_num_tactics ctx ) in - let f i = (Z3native.get_tactic_name ctx#gno i) in + let f i = (Z3native.get_tactic_name (context_gno ctx) i) in Array.init n f @@ -4444,39 +4424,34 @@ end Returns a string containing a description of the tactic with the given name. *) let get_tactic_description ( ctx : context ) ( name : string ) = - Z3native.tactic_get_descr ctx#gno name + Z3native.tactic_get_descr (context_gno ctx) name (** Creates a new Tactic. *) let mk_tactic ( ctx : context ) ( name : string ) = - (new tactic ctx)#cnstr_obj (Z3native.mk_tactic ctx#gno name) + (new tactic ctx)#cnstr_obj (Z3native.mk_tactic (context_gno ctx) name) (** Create a tactic that applies to a Goal and then to every subgoal produced by . *) - let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array option ) = - match - match ts with - | None -> None - | Some(rts) -> ( - let f p c = (match p with - | None -> (Some c#gno) - | Some(x) -> (Some (Z3native.tactic_and_then ctx#gno c#gno x))) in - Array.fold_left f None rts) - with - | None -> (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then ctx#gno t1#gno t2#gno) + let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array ) = + let f p c = (match p with + | None -> (Some c#gno) + | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) c#gno x))) in + match (Array.fold_left f None ts) with + | None -> (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then (context_gno ctx) t1#gno t2#gno) | Some(x) -> - let o = (Z3native.tactic_and_then ctx#gno t2#gno x) in - (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then ctx#gno t1#gno o) + let o = (Z3native.tactic_and_then (context_gno ctx) t2#gno x) in + (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then (context_gno ctx) t1#gno o) (** Create a tactic that first applies to a Goal and if it fails then returns the result of applied to the Goal. *) let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_or_else ctx#gno t1#gno t2#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_or_else (context_gno ctx) t1#gno t2#gno) (** Create a tactic that applies to a goal for milliseconds. @@ -4484,7 +4459,7 @@ end If does not terminate within milliseconds, then it fails. *) let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_try_for ctx#gno t#gno ms) + (new tactic ctx)#cnstr_obj (Z3native.tactic_try_for (context_gno ctx) t#gno ms) (** Create a tactic that applies to a given goal if the probe @@ -4494,52 +4469,52 @@ end *) (* CMW: when is a keyword *) let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_when ctx#gno p#gno t#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_when (context_gno ctx) p#gno t#gno) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_cond (context_gno ctx) p#gno t1#gno t2#gno) (** Create a tactic that keeps applying until the goal is not modified anymore or the maximum number of iterations is reached. *) let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_repeat ctx#gno t#gno max) + (new tactic ctx)#cnstr_obj (Z3native.tactic_repeat (context_gno ctx) t#gno max) (** Create a tactic that just returns the given goal. *) let skip ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_skip ctx#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_skip (context_gno ctx)) (** Create a tactic always fails. *) let fail ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail ctx#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail (context_gno ctx)) (** Create a tactic that fails if the probe evaluates to false. *) let fail_if ( ctx : context ) ( p : probe ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if ctx#gno p#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if (context_gno ctx) p#gno) (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) or trivially unsatisfiable (i.e., contains `false'). *) let fail_if_not_decided ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if_not_decided ctx#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if_not_decided (context_gno ctx)) (** Create a tactic that applies using the given set of parameters . *) let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_using_params ctx#gno t#gno p#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_using_params (context_gno ctx) t#gno p#gno) (** Create a tactic that applies using the given set of parameters . @@ -4552,21 +4527,21 @@ end Create a tactic that applies the given tactics in parallel. *) let par_or ( ctx : context ) ( t : tactic array ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_par_or ctx#gno (Array.length t) (tacticaton t)) + (new tactic ctx)#cnstr_obj (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (tacticaton t)) (** Create a tactic that applies to a given goal and then to every subgoal produced by . The subgoals are processed in parallel. *) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_par_and_then (context_gno ctx) t1#gno t2#gno) (** Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers, simplifiers and tactics. *) let interrupt ( ctx : context ) = - Z3native.interrupt ctx#gno + Z3native.interrupt (context_gno ctx) end (** Probes @@ -4591,68 +4566,68 @@ struct The number of supported Probes. *) let get_num_probes ( ctx : context ) = - Z3native.get_num_probes ctx#gno + Z3native.get_num_probes (context_gno ctx) (** The names of all supported Probes. *) let get_probe_names ( ctx : context ) = let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name ctx#gno i) in + let f i = (Z3native.get_probe_name (context_gno ctx) i) in Array.init n f (** Returns a string containing a description of the probe with the given name. *) let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr ctx#gno name + Z3native.probe_get_descr (context_gno ctx) name (** Creates a new Probe. *) let mk_probe ( ctx : context ) ( name : string ) = - (new probe ctx)#cnstr_obj (Z3native.mk_probe ctx#gno name) + (new probe ctx)#cnstr_obj (Z3native.mk_probe (context_gno ctx) name) (** Create a probe that always evaluates to . *) let const ( ctx : context ) ( v : float ) = - (new probe ctx)#cnstr_obj (Z3native.probe_const ctx#gno v) + (new probe ctx)#cnstr_obj (Z3native.probe_const (context_gno ctx) v) (** Create a probe that evaluates to "true" when the value returned by is less than the value returned by *) let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_lt ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_lt (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value returned by is greater than the value returned by *) let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_gt ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_gt (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value returned by is less than or equal the value returned by *) let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_le ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_le (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value returned by is greater than or equal the value returned by *) let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_ge ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_ge (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value returned by is equal to the value returned by *) let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_eq ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_eq (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value @@ -4660,7 +4635,7 @@ struct *) (* CMW: and is a keyword *) let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_and ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_and (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value @@ -4668,7 +4643,7 @@ struct *) (* CMW: or is a keyword *) let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_or ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_or (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value @@ -4676,7 +4651,7 @@ struct *) (* CMW: is not a keyword? *) let not_ ( ctx : context ) ( p : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_not ctx#gno p#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_not (context_gno ctx) p#gno) end (** Solvers *) @@ -4836,11 +4811,12 @@ struct *) - let check ( x : solver ) ( assumptions : bool_expr array option) = + let check ( x : solver ) ( assumptions : bool_expr array) = let r = - match assumptions with - | None -> lbool_of_int (Z3native.solver_check x#gnc x#gno) - | Some (ass) -> lbool_of_int (Z3native.solver_check_assumptions x#gnc x#gno (Array.length ass) (astaton ass)) + if ((Array.length assumptions) == 0) then + lbool_of_int (Z3native.solver_check x#gnc x#gno) + else + lbool_of_int (Z3native.solver_check_assumptions x#gnc x#gno (Array.length assumptions) (astaton assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -4907,8 +4883,8 @@ struct *) let mk_solver ( ctx : context ) ( logic : symbol option) = match logic with - | None -> (new solver ctx)#cnstr_obj (Z3native.mk_solver ctx#gno) - | Some (x) -> (new solver ctx)#cnstr_obj (Z3native.mk_solver_for_logic ctx#gno x#gno) + | None -> (new solver ctx)#cnstr_obj (Z3native.mk_solver (context_gno ctx)) + | Some (x) -> (new solver ctx)#cnstr_obj (Z3native.mk_solver_for_logic (context_gno ctx) x#gno) (** Creates a new (incremental) solver. @@ -4921,7 +4897,7 @@ struct Creates a new (incremental) solver. *) let mk_simple_solver ( ctx : context ) = - (new solver ctx)#cnstr_obj (Z3native.mk_simple_solver ctx#gno) + (new solver ctx)#cnstr_obj (Z3native.mk_simple_solver (context_gno ctx)) (** Creates a solver that is implemented using the given tactic. @@ -4930,7 +4906,7 @@ struct will always solve each check from scratch. *) let mk_solver_t ( ctx : context ) ( t : tactic ) = - (new solver ctx)#cnstr_obj (Z3native.mk_solver_from_tactic ctx#gno t#gno) + (new solver ctx)#cnstr_obj (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno) (** A string representation of the solver. @@ -5333,7 +5309,7 @@ struct Create a Fixedpoint context. *) let mk_fixedpoint ( ctx : context ) = - (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint ctx#gno) + (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint (context_gno ctx)) end (** Global and context options @@ -5354,7 +5330,7 @@ struct *) let update_param_value ( ctx : context ) ( id : string) ( value : string )= - Z3native.update_param_value ctx#gno id value + Z3native.update_param_value (context_gno ctx) id value (** Get a configuration parameter. @@ -5363,7 +5339,7 @@ struct *) let get_param_value ( ctx : context ) ( id : string ) = - let (r, v) = (Z3native.get_param_value ctx#gno id) in + let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in if not r then None else @@ -5385,7 +5361,7 @@ struct *) let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = - Z3native.set_ast_print_mode ctx#gno (int_of_ast_print_mode value) + Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) (** Enable/disable printing of warning messages to the console. @@ -5412,7 +5388,7 @@ struct @return A string representation of the benchmark. *) let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = - Z3native.benchmark_to_smtlib_string ctx#gno name logic status attributes + Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes (Array.length assumptions) (astaton assumptions) formula#gno @@ -5425,92 +5401,93 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = - let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in - let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in - let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in - let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let csn = (Array.length sort_names) in + let cs = (Array.length sorts) in + let cdn = (Array.length decl_names) in + let cd = (Array.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib_string ctx#gno str + Z3native.parse_smtlib_string (context_gno ctx) str cs - (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match sorts with | None -> [||] | Some(x) -> (astaton x)) + (symbolaton sort_names) + (astaton sorts) cd - (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (symbolaton decl_names) + (func_declaton decls) (** Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array option) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = - let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in - let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in - let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in - let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let csn = (Array.length sort_names) in + let cs = (Array.length sorts) in + let cdn = (Array.length decl_names) in + let cd = (Array.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib_file ctx#gno file_name + Z3native.parse_smtlib_file (context_gno ctx) file_name cs - (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match sorts with | None -> [||] | Some(x) -> (astaton x)) + (symbolaton sort_names) + (astaton sorts) cd - (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (symbolaton decl_names) + (func_declaton decls) + (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas ctx#gno + let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = ((create_expr ctx (Z3native.get_smtlib_formula ctx#gno i)) :> bool_expr) in + let f i = ((create_expr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) :> bool_expr) in Array.init n f (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions ctx#gno + let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = ((create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i)) :> bool_expr ) in + let f i = ((create_expr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) :> bool_expr ) in Array.init n f (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls ctx#gno + let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in - let f i = (new func_decl ctx)#cnstr_obj (Z3native.get_smtlib_decl ctx#gno i) in + let f i = (new func_decl ctx)#cnstr_obj (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts ctx#gno + let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in - let f i = (create_sort ctx (Z3native.get_smtlib_sort ctx#gno i)) in + let f i = (create_sort ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in Array.init n f (** @@ -5519,41 +5496,41 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = - let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in - let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in - let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in - let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let csn = (Array.length sort_names) in + let cs = (Array.length sorts) in + let cdn = (Array.length decl_names) in + let cd = (Array.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib2_string ctx#gno str + Z3native.parse_smtlib2_string (context_gno ctx) str cs - (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match sorts with | None -> [||] | Some(x) -> (astaton x)) + (symbolaton sort_names) + (astaton sorts) cd - (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (symbolaton decl_names) + (func_declaton decls) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = - let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in - let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in - let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in - let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let csn = (Array.length sort_names) in + let cs = (Array.length sorts) in + let cdn = (Array.length decl_names) in + let cd = (Array.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib2_string ctx#gno file_name + Z3native.parse_smtlib2_string (context_gno ctx) file_name cs - (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match sorts with | None -> [||] | Some(x) -> (astaton x)) + (symbolaton sort_names) + (astaton sorts) cd - (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (symbolaton decl_names) + (func_declaton decls) end (* From bbd1e465bb73b3dd8a757142b2c59c42552c2795 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 12 Jan 2013 00:01:50 +0000 Subject: [PATCH 043/248] ML API: bugfixes; starting to replace objects with normal types. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 3 +- scripts/update_api.py | 3 +- src/api/ml/z3.ml | 711 ++++++++++++++++++++------------------ 3 files changed, 382 insertions(+), 335 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 129f73d4d..97985a7bc 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -14,6 +14,7 @@ open Z3.Tactic.ApplyResult open Z3.Probe open Z3.Solver open Z3.Arithmetic +open Z3.Fixedpoints exception TestFailedException of string @@ -216,8 +217,8 @@ let _ = Printf.printf "bool sort: %s\n" (Sort.to_string bs); Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); - Printf.printf "Disposing...\n"; basic_tests ctx ; + Printf.printf "Disposing...\n"; Gc.full_major () ); Printf.printf "Exiting.\n"; diff --git a/scripts/update_api.py b/scripts/update_api.py index 1986f4a7e..c730a325e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1300,7 +1300,8 @@ def mk_ml(): ml_wrapper.write('extern "C" {\n') ml_wrapper.write('#endif\n\n') ml_wrapper.write('CAMLprim value n_is_null(value p) {\n') - ml_wrapper.write(' return Val_bool(Data_custom_val(p) == 0);\n') + ml_wrapper.write(' void * t = * (void**) Data_custom_val(p);\n') + ml_wrapper.write(' return Val_bool(t == 0);\n') ml_wrapper.write('}\n\n') ml_wrapper.write('CAMLprim value n_mk_null( void ) {\n') ml_wrapper.write(' CAMLparam0();\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c91d909bc..1e8ffe92e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,9 +7,13 @@ open Z3enums -type context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } +type context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } + +(**/**) + +let null = Z3native.mk_null() +let is_null o = (Z3native.is_null o) -(**/**) let context_dispose ctx = if ctx.m_n_obj_cnt == 0 then ( (* Printf.printf "Disposing context \n" ; *) @@ -19,7 +23,7 @@ let context_dispose ctx = (* re-queue for finalization? *) ) -let context_init settings = +let context_cnstr settings = let cfg = Z3native.mk_config in let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; @@ -50,7 +54,7 @@ require one such object, but power users may require more than one. To start usi Z3, do - let ctx = (mk_context None) in + let ctx = (mk_context []) in (...) @@ -58,17 +62,18 @@ where a list of pairs of strings may be passed to set options on the context, e.g., like so: - let cfg = (Some [("model", "true"); ("...", "...")]) in + let cfg = [("model", "true"); ("...", "...")] in let ctx = (mk_context cfg) in (...) *) let mk_context ( cfg : ( string * string ) list ) = - context_init cfg + context_cnstr cfg + + +(* type z3object = { m_ctx : context; m_n_obj : Z3native.ptr option; } *) (**/**) - -(** Z3 objects *) class virtual z3object ctx_init obj_init = object (self) val mutable m_ctx : context = ctx_init @@ -669,15 +674,6 @@ object (self) method decref nc o = Z3native.func_interp_dec_ref nc o end -(** Model objects *) -class model ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.model_inc_ref nc o - method decref nc o = Z3native.model_dec_ref nc o -end - (** Tactic application result objects *) class apply_result ctx = object (self) @@ -724,32 +720,38 @@ object (self) method is_float = m_is_float end -(** Statistics objects *) -class statistics ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.stats_inc_ref nc o - method decref nc o = Z3native.stats_dec_ref nc o -end -(** Solver objects *) -class solver ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.solver_inc_ref nc o - method decref nc o = Z3native.solver_dec_ref nc o -end +type z3_native_object = { + m_ctx : context ; + mutable m_n_obj : Z3native.ptr ; + inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; + dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } -(** Fixedpoint objects *) -class fixedpoint ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.fixedpoint_inc_ref nc o - method decref nc o = Z3native.fixedpoint_dec_ref nc o -end +let z3obj_gc o = o.m_ctx +let z3obj_gnc o = (context_gno o.m_ctx) + +let z3obj_gno o = o.m_n_obj +let z3obj_sno o ctx no = + (context_add1 ctx) ; + o.inc_ref (context_gno ctx) no ; + ( + if not (is_null o.m_n_obj) then + o.dec_ref (context_gno ctx) o.m_n_obj ; + (context_sub1 ctx) + ) ; + o.m_n_obj <- no + +let z3obj_dispose o = + if not (is_null o.m_n_obj) then + ( + o.dec_ref (z3obj_gnc o) o.m_n_obj ; + (context_sub1 (z3obj_gc o)) + ) ; + o.m_n_obj <- null + +let z3obj_cnstr o = + let f = fun o -> (z3obj_dispose o) in + Gc.finalise f o (**/**) @@ -1878,7 +1880,6 @@ struct (astaton names) body#gno) else - let null = Z3native.mk_null() in (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) @@ -1900,7 +1901,6 @@ struct (Array.length patterns) (patternaton patterns) body#gno) else - let null = Z3native.mk_null() in (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) @@ -1924,7 +1924,6 @@ struct (astaton names) body#gno) else - let null = Z3native.mk_null() in (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) @@ -1946,7 +1945,6 @@ struct (Array.length patterns) (patternaton patterns) body#gno) else - let null = Z3native.mk_null() in (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) @@ -4347,6 +4345,240 @@ struct end +(** Models + + A Model contains interpretations (assignments) of constants and functions. *) +module Model = +struct + type model = z3_native_object + + (**/**) + let model_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : model = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.model_inc_ref ; + dec_ref = Z3native.model_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. + *) + module FuncInterp = + struct + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. + *) + module FuncEntry = + struct + (** + Return the (symbolic) value of this entry. + *) + let get_value ( x : func_entry ) = + create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + + (** + The number of arguments of the entry. + *) + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + + (** + The arguments of the function entry. + *) + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the function entry. + *) + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") + end + + (** + The number of entries in the function interpretation. + *) + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + + (** + The entries in the function interpretation + *) + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + Array.init n f + + (** + The (symbolic) `else' value of the function interpretation. + *) + let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + + (** + The arity of the function interpretation + *) + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + + (** + A string representation of the function interpretation. + *) + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (Array.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + end + + (** Retrieves the interpretation (the assignment) of in the model. + A function declaration of zero arity + An expression if the function has an interpretation in the model, null otherwise. *) + let get_const_interp ( x : model ) ( f : func_decl ) = + if (FuncDecl.get_arity f) != 0 || + (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then + raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") + else + let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) f#gno in + if (Z3native.is_null np) then + None + else + Some (create_expr (z3obj_gc x) np) + + (** Retrieves the interpretation (the assignment) of in the model. + A Constant + An expression if the constant has an interpretation in the model, null otherwise. + *) + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + + + (** Retrieves the interpretation (the assignment) of a non-constant in the model. + A function declaration of non-zero arity + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + let rec get_func_interp ( x : model ) ( f : func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range f#gnc f#gno))) in + if (FuncDecl.get_arity f) == 0 then + let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) f#gno in + if (Z3native.is_null n) then + None + else + match sk with + | ARRAY_SORT -> + if not (Z3native.is_as_array (z3obj_gnc x) n) then + raise (Z3native.Exception "Argument was not an array constant") + else + let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in + get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) + | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); + else + let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) f#gno) in + if (Z3native.is_null n) then None else Some ((new func_interp (z3obj_gc x))#cnstr_obj n) + + (** The number of constants that have an interpretation in the model. *) + let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) + + (** The function declarations of the constants in the model. *) + let get_const_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + Array.init n f + + + (** The number of function interpretations in the model. *) + let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) + + (** The function declarations of the function interpretations in the model. *) + let get_func_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + Array.init n f + + (** All symbols that have an interpretation in the model. *) + let get_decls ( x : model ) = + let n_funcs = (get_num_funcs x) in + let n_consts = (get_num_consts x ) in + let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + Array.append (Array.init n_funcs f) (Array.init n_consts g) + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) + exception ModelEvaluationFailedException of string + + (** + 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. + + The evaluation of in the model. + *) + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) t#gno completion) in + if not r then + raise (ModelEvaluationFailedException "evaluation failed") + else + create_expr (z3obj_gc x) v + + (** Alias for eval. *) + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + eval x t completion + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) + + (** 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. + + + *) + let get_sorts ( x : model ) = + let n = (get_num_sorts x) in + let f i = (create_sort (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in + Array.init n f + + + (** The finite set of distinct values that represent the interpretation for sort . + + An uninterpreted sort + An array of expressions, where each is an element of the universe of + *) + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in + Array.init n f + + (** Conversion of models to strings. + A string representation of the model. + *) + let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) +end + + (** Tactics Tactics are the basic building block for creating custom solvers for specific problem domains. @@ -4380,8 +4612,8 @@ struct goal g, that the ApplyResult was obtained from. #return A model for g *) - let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = - (new model x#gc)#cnstr_obj (Z3native.apply_result_convert_model x#gnc x#gno i m#gno) + let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = + Model.model_cnstr x#gc (Z3native.apply_result_convert_model x#gnc x#gno i (z3obj_gno m)) (** A string representation of the ApplyResult. *) let to_string ( x : apply_result ) = Z3native.apply_result_to_string x#gnc x#gno @@ -4401,11 +4633,6 @@ end | None -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply x#gnc x#gno g#gno) | Some (pn) -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno) - (** creates a solver that is implemented using the given tactic. - *) - let get_solver ( x : tactic ) = - (new solver x#gc)#cnstr_obj (Z3native.mk_solver_from_tactic x#gnc x#gno) - (** The number of supported tactics. *) @@ -4654,9 +4881,23 @@ struct (new probe ctx)#cnstr_obj (Z3native.probe_not (context_gno ctx) p#gno) end + (** Solvers *) module Solver = struct + type solver = z3_native_object + +(**/**) + let solver_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : solver = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.solver_inc_ref ; + dec_ref = Z3native.solver_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res +(**/**) + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE let string_of_status ( s : status) = match s with @@ -4667,6 +4908,18 @@ struct (** Objects that track statistical information about solvers. *) module Statistics = struct + type statistics = z3_native_object + + (**/**) + let statistics_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : statistics = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.stats_inc_ref ; + dec_ref = Z3native.stats_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) (** Statistical data is organized into pairs of [Key, Entry], where every @@ -4703,20 +4956,20 @@ struct end (** A string representation of the statistical data. *) - let to_string ( x : statistics ) = Z3native.stats_to_string x#gnc x#gno + let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) (** The number of statistical data. *) - let get_size ( x : statistics ) = Z3native.stats_size x#gnc x#gno + let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) (** The data entries. *) let get_entries ( x : statistics ) = let n = (get_size x ) in let f i = ( - let k = Z3native.stats_get_key x#gnc x#gno i in - if (Z3native.stats_is_uint x#gnc x#gno i) then - ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) + let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in + if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then + ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) + ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in Array.init n f @@ -4725,7 +4978,7 @@ struct *) let get_keys ( x : statistics ) = let n = (get_size x) in - let f i = (Z3native.stats_get_key x#gnc x#gno i) in + let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** @@ -4739,51 +4992,51 @@ struct (** A string that describes all available solver parameters. *) - let get_help ( x : solver ) = Z3native.solver_get_help x#gnc x#gno + let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) (** Sets the solver parameters. *) let set_parameters ( x : solver ) ( value : params )= - Z3native.solver_set_params x#gnc x#gno value#gno + Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) value#gno (** Retrieves parameter descriptions for solver. *) let get_param_descrs ( x : solver ) = - (new param_descrs x#gc)#cnstr_obj (Z3native.solver_get_param_descrs x#gnc x#gno) + (new param_descrs (z3obj_gc x))#cnstr_obj (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** The current number of backtracking points (scopes). *) - let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes x#gnc x#gno + let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) (** Creates a backtracking point. *) - let push ( x : solver ) = Z3native.solver_push x#gnc x#gno + let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) (** Backtracks backtracking points. Note that an exception is thrown if is not smaller than NumScopes *) - let pop ( x : solver ) ( n : int ) = Z3native.solver_pop x#gnc x#gno n + let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n (** Resets the Solver. This removes all assertions from the solver. *) - let reset ( x : solver ) = Z3native.solver_reset x#gnc x#gno + let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) (** Assert a constraint (or multiple) into the solver. *) let assert_ ( x : solver ) ( constraints : bool_expr array ) = - let f e = (Z3native.solver_assert x#gnc x#gno e#gno) in + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in ignore (Array.map f constraints) ; () @@ -4791,7 +5044,7 @@ struct The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in + let a = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) @@ -4799,9 +5052,9 @@ struct The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in + let a = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in - let f i = ((new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get a i)#gno) in + let f i = ((new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get a i)#gno) in Array.init n f (** @@ -4814,9 +5067,9 @@ struct let check ( x : solver ) ( assumptions : bool_expr array) = let r = if ((Array.length assumptions) == 0) then - lbool_of_int (Z3native.solver_check x#gnc x#gno) + lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - lbool_of_int (Z3native.solver_check_assumptions x#gnc x#gno (Array.length assumptions) (astaton assumptions)) + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (astaton assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -4830,11 +5083,11 @@ struct if its results was not SATISFIABLE, or if model production is not enabled. *) let get_model ( x : solver ) = - let q = Z3native.solver_get_model x#gnc x#gno in + let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in if (Z3native.is_null q) then None else - Some ((new model x#gc)#cnstr_obj q) + Some (Model.model_cnstr (z3obj_gc x) q) (** The proof of the last Check. @@ -4843,11 +5096,11 @@ struct if its results was not UNSATISFIABLE, or if proof production is disabled. *) let get_proof ( x : solver ) = - let q = Z3native.solver_get_proof x#gnc x#gno in + let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in if (Z3native.is_null q) then None else - Some (create_expr x#gc q) + Some (create_expr (z3obj_gc x) q) (** The unsat core of the last Check. @@ -4857,7 +5110,7 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_unsat_core x#gnc x#gno) in + let cn = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f @@ -4865,14 +5118,14 @@ struct (** A brief justification of why the last call to Check returned UNKNOWN. *) - let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown x#gnc x#gno + let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) (** Solver statistics. *) let get_statistics ( x : solver ) = - (new statistics x#gc)#cnstr_obj (Z3native.solver_get_statistics x#gnc x#gno) + (Statistics.statistics_cnstr (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) (** Creates a new (incremental) solver. @@ -4883,8 +5136,8 @@ struct *) let mk_solver ( ctx : context ) ( logic : symbol option) = match logic with - | None -> (new solver ctx)#cnstr_obj (Z3native.mk_solver (context_gno ctx)) - | Some (x) -> (new solver ctx)#cnstr_obj (Z3native.mk_solver_for_logic (context_gno ctx) x#gno) + | None -> (solver_cnstr ctx (Z3native.mk_solver (context_gno ctx))) + | Some (x) -> (solver_cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) x#gno)) (** Creates a new (incremental) solver. @@ -4897,7 +5150,7 @@ struct Creates a new (incremental) solver. *) let mk_simple_solver ( ctx : context ) = - (new solver ctx)#cnstr_obj (Z3native.mk_simple_solver (context_gno ctx)) + (solver_cnstr ctx (Z3native.mk_simple_solver (context_gno ctx))) (** Creates a solver that is implemented using the given tactic. @@ -4906,261 +5159,54 @@ struct will always solve each check from scratch. *) let mk_solver_t ( ctx : context ) ( t : tactic ) = - (new solver ctx)#cnstr_obj (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno) + (solver_cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno)) (** A string representation of the solver. *) - let to_string ( x : solver ) = Z3native.solver_to_string x#gnc x#gno + let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) end -(** Models - - A Model contains interpretations (assignments) of constants and functions. *) -module Model = -struct - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. - *) - module FuncInterp = - struct - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. - *) - module FuncEntry = - struct - (** - Return the (symbolic) value of this entry. - *) - let get_value ( x : func_entry ) = - create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) - - (** - The number of arguments of the entry. - *) - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno - - (** - The arguments of the function entry. - *) - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in - Array.init n f - - (** - A string representation of the function entry. - *) - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") - end - - (** - The number of entries in the function interpretation. - *) - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno - - (** - The entries in the function interpretation - *) - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in - Array.init n f - - (** - The (symbolic) `else' value of the function interpretation. - *) - let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) - - (** - The arity of the function interpretation - *) - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno - - (** - A string representation of the function interpretation. - *) - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (Array.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") - end - - (** Retrieves the interpretation (the assignment) of in the model. - A function declaration of zero arity - An expression if the function has an interpretation in the model, null otherwise. *) - let get_const_interp ( x : model ) ( f : func_decl ) = - if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then - raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") - else - let np = Z3native.model_get_const_interp x#gnc x#gno f#gno in - if (Z3native.is_null np) then - None - else - Some (create_expr x#gc np) - - (** Retrieves the interpretation (the assignment) of in the model. - A Constant - An expression if the constant has an interpretation in the model, null otherwise. - *) - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - - - (** Retrieves the interpretation (the assignment) of a non-constant in the model. - A function declaration of non-zero arity - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_range f#gnc f#gno))) in - if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp x#gnc x#gno f#gno in - if (Z3native.is_null n) then - None - else - match sk with - | ARRAY_SORT -> - if not (Z3native.is_as_array x#gnc n) then - raise (Z3native.Exception "Argument was not an array constant") - else - let fd = Z3native.get_as_array_func_decl x#gnc n in - get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) - | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); - else - let n = (Z3native.model_get_func_interp x#gnc x#gno f#gno) in - if (Z3native.is_null n) then None else Some ((new func_interp x#gc)#cnstr_obj n) - - (** The number of constants that have an interpretation in the model. *) - let get_num_consts ( x : model ) = Z3native.model_get_num_consts x#gnc x#gno - - (** The function declarations of the constants in the model. *) - let get_const_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in - Array.init n f - - - (** The number of function interpretations in the model. *) - let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs x#gnc x#gno - - (** The function declarations of the function interpretations in the model. *) - let get_func_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in - Array.init n f - - (** All symbols that have an interpretation in the model. *) - let get_decls ( x : model ) = - let n_funcs = (get_num_funcs x) in - let n_consts = (get_num_consts x ) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in - let g i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in - Array.append (Array.init n_funcs f) (Array.init n_consts g) - - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) - exception ModelEvaluationFailedException of string - - (** - 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. - - The evaluation of in the model. - *) - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno completion) in - if not r then - raise (ModelEvaluationFailedException "evaluation failed") - else - create_expr x#gc v - - (** Alias for eval. *) - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = - eval x t completion - - (** The number of uninterpreted sorts that the model has an interpretation for. *) - let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts x#gnc x#gno - - (** 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. - - - *) - let get_sorts ( x : model ) = - let n = (get_num_sorts x) in - let f i = (create_sort x#gc (Z3native.model_get_sort x#gnc x#gno i)) in - Array.init n f - - - (** The finite set of distinct values that represent the interpretation for sort . - - An uninterpreted sort - An array of expressions, where each is an element of the universe of - *) - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in - Array.init n f - - (** Conversion of models to strings. - A string representation of the model. - *) - let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno -end - (** Fixedpoint solving *) module Fixedpoints = struct + type fixedpoint = z3_native_object + +(**/**) + let fixedpoint_cnstr ( ctx : context ) = + let res : fixedpoint = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.fixedpoint_inc_ref ; + dec_ref = Z3native.fixedpoint_dec_ref } in + (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; + (z3obj_cnstr res) ; + res +(**/**) + (** A string that describes all available fixedpoint solver parameters. *) let get_help ( x : fixedpoint ) = - Z3native.fixedpoint_get_help x#gnc x#gno + Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) (** Sets the fixedpoint solver parameters. *) let set_params ( x : fixedpoint ) ( p : params )= - Z3native.fixedpoint_set_params x#gnc x#gno p#gno + Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) p#gno (** Retrieves parameter descriptions for Fixedpoint solver. *) let get_param_descrs ( x : fixedpoint ) = - (new param_descrs x#gc)#cnstr_obj (Z3native.fixedpoint_get_param_descrs x#gnc x#gno) + (new param_descrs (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Assert a constraints into the fixedpoint solver. *) let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = - let f e = (Z3native.fixedpoint_assert x#gnc x#gno e#gno) in + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in ignore (Array.map f constraints) ; () @@ -5168,21 +5214,21 @@ struct Register predicate as recursive relation. *) let register_relation ( x : fixedpoint ) ( f : func_decl ) = - Z3native.fixedpoint_register_relation x#gnc x#gno f#gno + Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) f#gno (** Add rule into the fixedpoint solver. *) let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = match name with - | None -> Z3native.fixedpoint_add_rule x#gnc x#gno rule#gno (Z3native.mk_null()) - | Some(y) -> Z3native.fixedpoint_add_rule x#gnc x#gno rule#gno y#gno + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno y#gno (** Add table fact to the fixedpoint solver. *) let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = - Z3native.fixedpoint_add_fact x#gnc x#gno pred#gno (Array.length args) args + Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) pred#gno (Array.length args) args (** Query the fixedpoint solver. @@ -5191,7 +5237,7 @@ struct The query is unsatisfiable if there are no derivations satisfying the query variables. *) let query ( x : fixedpoint ) ( query : bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query x#gnc x#gno query#gno)) with + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) query#gno)) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -5203,7 +5249,7 @@ struct The query is unsatisfiable if there are no derivations satisfying any of the relations. *) let query_r ( x : fixedpoint ) ( relations : func_decl array ) = - match (lbool_of_int (Z3native.fixedpoint_query_relations x#gnc x#gno (Array.length relations) (func_declaton relations))) with + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (func_declaton relations))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -5213,7 +5259,7 @@ struct *) let push ( x : fixedpoint ) = - Z3native.fixedpoint_push x#gnc x#gno + Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) (** Backtrack one backtracking point. @@ -5222,94 +5268,93 @@ struct *) let pop ( x : fixedpoint ) = - Z3native.fixedpoint_pop x#gnc x#gno + Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) (** Update named rule into in the fixedpoint solver. *) let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = - Z3native.fixedpoint_update_rule x#gnc x#gno rule#gno name#gno + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) rule#gno name#gno (** Retrieve satisfying instance or instances of solver, or definitions for the recursive predicates that show unsatisfiability. *) let get_answer ( x : fixedpoint ) = - let q = (Z3native.fixedpoint_get_answer x#gnc x#gno) in + let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in if (Z3native.is_null q) then None else - Some (create_expr x#gc q) + Some (create_expr (z3obj_gc x) q) (** Retrieve explanation why fixedpoint engine returned status Unknown. *) let get_reason_unknown ( x : fixedpoint ) = - Z3native.fixedpoint_get_reason_unknown x#gnc x#gno + Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) (** Retrieve the number of levels explored for a given predicate. *) let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = - Z3native.fixedpoint_get_num_levels x#gnc x#gno predicate#gno + Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) predicate#gno (** Retrieve the cover of a predicate. *) let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = - let q = (Z3native.fixedpoint_get_cover_delta x#gnc x#gno level predicate#gno) in + let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level predicate#gno) in if (Z3native.is_null q) then None else - Some (create_expr x#gc q) + Some (create_expr (z3obj_gc x) q) (** Add property about the predicate. The property is added at level. *) let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover x#gnc x#gno level predicate#gno, property#gno + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level predicate#gno property#gno (** Retrieve internal string representation of fixedpoint object. *) - let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string x#gnc x#gno 0 [||] + let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = - Z3native.fixedpoint_set_predicate_representation x#gnc x#gno f#gno (Array.length kinds) (symbolaton kinds) + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) f#gno (Array.length kinds) (symbolaton kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. *) let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = - Z3native.fixedpoint_to_string x#gnc x#gno (Array.length queries) (astaton queries) + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (astaton queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = ((new ast_vector x#gc)#cnstr_obj (Z3native.fixedpoint_get_rules x#gnc x#gno)) in + let v = ((new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get v i)#gno in + let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = ((new ast_vector x#gc)#cnstr_obj (Z3native.fixedpoint_get_assertions x#gnc x#gno)) in + let v = ((new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get v i)#gno in + let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in Array.init n f (** Create a Fixedpoint context. *) - let mk_fixedpoint ( ctx : context ) = - (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint (context_gno ctx)) + let mk_fixedpoint ( ctx : context ) = fixedpoint_cnstr ctx end (** Global and context options From bcc0c14233fa0af46e95c945692726218d61eae3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 12 Jan 2013 01:15:23 +0000 Subject: [PATCH 044/248] ML API: moved more objects into normal types. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 1 - src/api/ml/z3.ml | 766 +++++++++++++++++++------------------- 2 files changed, 392 insertions(+), 375 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 97985a7bc..38b5fe642 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -14,7 +14,6 @@ open Z3.Tactic.ApplyResult open Z3.Probe open Z3.Solver open Z3.Arithmetic -open Z3.Fixedpoints exception TestFailedException of string diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 1e8ffe92e..545c7c227 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -20,7 +20,7 @@ let context_dispose ctx = (Z3native.del_context ctx.m_n_ctx) ) else ( Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; - (* re-queue for finalization? *) + (* re-queue for finalization? *) ) let context_cnstr settings = @@ -38,7 +38,7 @@ let context_cnstr settings = (* CMW: Install error handler here! m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); + GC.SuppressFinalize(this); *) let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) @@ -49,23 +49,23 @@ let context_gno ctx = ctx.m_n_ctx (** Create a context object. -Most interactions with Z3 are interpreted in some context; many users will only -require one such object, but power users may require more than one. To start using -Z3, do + Most interactions with Z3 are interpreted in some context; many users will only + require one such object, but power users may require more than one. To start using + Z3, do - + let ctx = (mk_context []) in (...) - + -where a list of pairs of strings may be passed to set options on -the context, e.g., like so: + where a list of pairs of strings may be passed to set options on + the context, e.g., like so: - + let cfg = [("model", "true"); ("...", "...")] in let ctx = (mk_context cfg) in (...) - + *) let mk_context ( cfg : ( string * string ) list ) = context_cnstr cfg @@ -656,70 +656,6 @@ let tacticaton (a : tactic array) = let f (e : tactic) = e#gno in Array.map f a -(** Function interpretation entry objects *) -class func_entry ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.func_entry_inc_ref nc o - method decref nc o = Z3native.func_entry_dec_ref nc o -end - -(** Function interpretation objects *) -class func_interp ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.func_interp_inc_ref nc o - method decref nc o = Z3native.func_interp_dec_ref nc o -end - -(** Tactic application result objects *) -class apply_result ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.apply_result_inc_ref nc o - method decref nc o = Z3native.apply_result_dec_ref nc o -end - -(** Probe objects *) -class probe ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.probe_inc_ref nc o - method decref nc o = Z3native.probe_dec_ref nc o -end - -(** Statistical value objects *) -class statistics_entry = -object (self) - val mutable m_key : string = "" - val mutable m_is_int = false - val mutable m_is_float = false - val mutable m_int = 0 - val mutable m_float = 0.0 - - method cnstr_si k v = - m_key <- k; - m_is_int <- true; - m_int <- v; - self - - method cnstr_sd k v = - m_key <- k; - m_is_float <- true; - m_float <- v; - self - - method key = m_key - method int = m_int - method float = m_float - method is_int = m_is_int - method is_float = m_is_float -end - type z3_native_object = { m_ctx : context ; @@ -1012,46 +948,46 @@ struct x#rational end - (** - Creates a new function declaration. - *) - let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr name domain range + (** + Creates a new function declaration. + *) + let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr name domain range - (** - Creates a new function declaration. - *) - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = - mk_func_decl ctx ((Symbol.mk_string ctx name) :> symbol) domain range + (** + Creates a new function declaration. + *) + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = + mk_func_decl ctx ((Symbol.mk_string ctx name) :> symbol) domain range - (** - Creates a fresh function declaration with a name prefixed with . - - - *) - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort) = - (new func_decl ctx)#cnstr_pdr prefix domain range + (** + Creates a fresh function declaration with a name prefixed with . + + + *) + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort) = + (new func_decl ctx)#cnstr_pdr prefix domain range - (** - Creates a new constant function declaration. - *) - let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr name [||] range + (** + Creates a new constant function declaration. + *) + let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr name [||] range - (** - Creates a new constant function declaration. - *) - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr ((Symbol.mk_string ctx name) :> symbol) [||] range + (** + Creates a new constant function declaration. + *) + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr ((Symbol.mk_string ctx name) :> symbol) [||] range - (** - Creates a fresh constant function declaration with a name prefixed with . - - - *) - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = - (new func_decl ctx)#cnstr_pdr prefix [||] range + (** + Creates a fresh constant function declaration with a name prefixed with . + + + *) + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = + (new func_decl ctx)#cnstr_pdr prefix [||] range (** @@ -1333,31 +1269,31 @@ struct else (create_ast to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx))) -(** - Wraps an AST. + (** + 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., - . - - @param nativeObject The native pointer to wrap. -*) + 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., + . + + @param nativeObject The native pointer to wrap. + *) let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = - create_ast ctx ptr + create_ast ctx ptr -(** - 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., - ). - - @param a The AST to unwrap. -*) + (** + 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., + ). + + @param a The AST to unwrap. + *) let unwrap_ast ( a : ast ) = a#gno end @@ -1373,17 +1309,17 @@ struct | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno pp#gno) -(** - a string describing all available parameters to Expr.Simplify. -*) + (** + a string describing all available parameters to Expr.Simplify. + *) let get_simplify_help ( ctx : context ) = Z3native.simplify_get_help (context_gno ctx) -(** - Retrieves parameter descriptions for simplifier. -*) - let get_simplify_parameter_descrs ( ctx : context ) = - (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs (context_gno ctx)) + (** + Retrieves parameter descriptions for simplifier. + *) + let get_simplify_parameter_descrs ( ctx : context ) = + (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. @@ -2691,7 +2627,7 @@ struct let (r, v) = Z3native.get_numeral_int x#gnc x#gno in if r then v else raise (Z3native.Exception "Conversion failed.") - + (** Returns a string representation of the numeral. *) let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -3202,7 +3138,7 @@ struct let (r, v) = Z3native.get_numeral_int x#gnc x#gno in if r then v else raise (Z3native.Exception "Conversion failed.") - + (** Returns a string representation of the numeral. *) let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -4150,29 +4086,29 @@ end *) module Params = struct -(** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) -module ParamDescrs = -struct + (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) + module ParamDescrs = + struct - (** Validate a set of parameters. *) - let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno - - (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) + (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno - (** Retrieve all names of parameters. *) - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size x#gnc x#gno in - let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in - Array.init n f + (** Retrieve kind of parameter. *) + let get_kind ( x : param_descrs ) ( name : symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) + + (** Retrieve all names of parameters. *) + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size x#gnc x#gno in + let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in + Array.init n f + + (** The size of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno - (** The size of the ParamDescrs. *) - let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno - - (** Retrieves a string representation of the ParamDescrs. *) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno -end + (** Retrieves a string representation of the ParamDescrs. *) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno + end (** Adds a parameter setting. @@ -4353,11 +4289,11 @@ struct type model = z3_native_object (**/**) - let model_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = let res : model = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.model_inc_ref ; - dec_ref = Z3native.model_dec_ref } in + m_n_obj = null ; + inc_ref = Z3native.model_inc_ref ; + dec_ref = Z3native.model_dec_ref } in (z3obj_sno res ctx no) ; (z3obj_cnstr res) ; res @@ -4370,6 +4306,18 @@ struct *) module FuncInterp = struct + type func_interp = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : func_interp = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.func_interp_inc_ref ; + dec_ref = Z3native.func_interp_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) (** Function interpretations entries @@ -4377,23 +4325,36 @@ struct *) module FuncEntry = struct + type func_entry = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : func_entry = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.func_entry_inc_ref ; + dec_ref = Z3native.func_entry_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + (** Return the (symbolic) value of this entry. *) let get_value ( x : func_entry ) = - create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + create_expr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) (** The number of arguments of the entry. *) - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) (** The arguments of the function entry. *) let get_args ( x : func_entry ) = let n = (get_num_args x) in - let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + let f i = (create_expr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** @@ -4408,25 +4369,25 @@ struct (** The number of entries in the function interpretation. *) - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) (** The entries in the function interpretation *) let get_entries ( x : func_interp ) = let n = (get_num_entries x) in - let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + let f i = (FuncEntry.cnstr (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** The (symbolic) `else' value of the function interpretation. *) - let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + let get_else ( x : func_interp ) = create_expr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) (** The arity of the function interpretation *) - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) (** A string representation of the function interpretation. @@ -4486,7 +4447,7 @@ struct | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); else let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) f#gno) in - if (Z3native.is_null n) then None else Some ((new func_interp (z3obj_gc x))#cnstr_obj n) + if (Z3native.is_null n) then None else Some (FuncInterp.cnstr (z3obj_gc x) n) (** The number of constants that have an interpretation in the model. *) let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) @@ -4579,6 +4540,130 @@ struct end +(** Probes + + 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. +*) +module Probe = +struct + type probe = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : probe = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.probe_inc_ref ; + dec_ref = Z3native.probe_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** + Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. + *) + let apply ( x : probe ) (g : goal) = + Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) g#gno + + (** + The number of supported Probes. + *) + let get_num_probes ( ctx : context ) = + Z3native.get_num_probes (context_gno ctx) + + (** + The names of all supported Probes. + *) + let get_probe_names ( ctx : context ) = + let n = (get_num_probes ctx) in + let f i = (Z3native.get_probe_name (context_gno ctx) i) in + Array.init n f + + (** + Returns a string containing a description of the probe with the given name. + *) + let get_probe_description ( ctx : context ) ( name : string ) = + Z3native.probe_get_descr (context_gno ctx) name + + (** + Creates a new Probe. + *) + let mk_probe ( ctx : context ) ( name : string ) = + (cnstr ctx (Z3native.mk_probe (context_gno ctx) name)) + + (** + Create a probe that always evaluates to . + *) + let const ( ctx : context ) ( v : float ) = + (cnstr ctx (Z3native.probe_const (context_gno ctx) v)) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than the value returned by + *) + let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than the value returned by + *) + let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than or equal the value returned by + *) + let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than or equal the value returned by + *) + let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value returned by + is equal to the value returned by + *) + let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value + and evaluate to "true". + *) + (* CMW: and is a keyword *) + let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value + or evaluate to "true". + *) + (* CMW: or is a keyword *) + let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value + does not evaluate to "true". + *) + (* CMW: is not a keyword? *) + let not_ ( ctx : context ) ( p : probe ) = + (cnstr ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) +end + + (** Tactics Tactics are the basic building block for creating custom solvers for specific problem domains. @@ -4588,36 +4673,49 @@ end *) module Tactic = struct -(** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) -module ApplyResult = -struct - (** The number of Subgoals. *) - let get_num_subgoals ( x : apply_result ) = - Z3native.apply_result_get_num_subgoals x#gnc x#gno + (** Tactic application results - (** Retrieves the subgoals from the apply_result. *) - let get_subgoals ( x : apply_result ) = - let n = (get_num_subgoals x) in - let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in - Array.init n f - - (** Retrieves the subgoals from the apply_result. *) - let get_subgoal ( x : apply_result ) ( i : int ) = - (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) - - (** 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 - *) - let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = - Model.model_cnstr x#gc (Z3native.apply_result_convert_model x#gnc x#gno i (z3obj_gno m)) - - (** A string representation of the ApplyResult. *) - let to_string ( x : apply_result ) = Z3native.apply_result_to_string x#gnc x#gno -end + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) + module ApplyResult = + struct + type apply_result = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : apply_result = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.apply_result_inc_ref ; + dec_ref = Z3native.apply_result_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** The number of Subgoals. *) + let get_num_subgoals ( x : apply_result ) = + Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoals ( x : apply_result ) = + let n = (get_num_subgoals x) in + let f i = (new goal (z3obj_gc x))#cnstr_obj (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in + Array.init n f + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoal ( x : apply_result ) ( i : int ) = + (new goal (z3obj_gc x))#cnstr_obj (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) + + (** 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 + *) + let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = + Model.cnstr (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) + + (** A string representation of the ApplyResult. *) + let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) + end (** A string containing a description of parameters accepted by the tactic. *) let get_help ( x : tactic ) = Z3native.tactic_get_help x#gnc x#gno @@ -4630,8 +4728,8 @@ end (** Apply the tactic to the goal. *) let apply ( x : tactic ) ( g : goal ) ( p : params option ) = match p with - | None -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply x#gnc x#gno g#gno) - | Some (pn) -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno) + | None -> (ApplyResult.cnstr x#gc (Z3native.tactic_apply x#gnc x#gno g#gno)) + | Some (pn) -> (ApplyResult.cnstr x#gc (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno)) (** The number of supported tactics. @@ -4695,15 +4793,15 @@ end If evaluates to false, then the new tactic behaves like the skip tactic. *) (* CMW: when is a keyword *) - let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_when (context_gno ctx) p#gno t#gno) + let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) t#gno) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) - let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_cond (context_gno ctx) p#gno t1#gno t2#gno) + let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) t1#gno t2#gno) (** Create a tactic that keeps applying until the goal is not @@ -4727,8 +4825,8 @@ end (** Create a tactic that fails if the probe evaluates to false. *) - let fail_if ( ctx : context ) ( p : probe ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if (context_gno ctx) p#gno) + let fail_if ( ctx : context ) ( p : Probe.probe ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) @@ -4771,124 +4869,14 @@ end Z3native.interrupt (context_gno ctx) end -(** Probes - - 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. -*) -module Probe = -struct - (** - Execute the probe over the goal. - A probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. - *) - let apply ( x : probe ) (g : goal) = - Z3native.probe_apply x#gnc x#gno g#gno - - (** - The number of supported Probes. - *) - let get_num_probes ( ctx : context ) = - Z3native.get_num_probes (context_gno ctx) - - (** - The names of all supported Probes. - *) - let get_probe_names ( ctx : context ) = - let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name (context_gno ctx) i) in - Array.init n f - - (** - Returns a string containing a description of the probe with the given name. - *) - let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr (context_gno ctx) name - - (** - Creates a new Probe. - *) - let mk_probe ( ctx : context ) ( name : string ) = - (new probe ctx)#cnstr_obj (Z3native.mk_probe (context_gno ctx) name) - - (** - Create a probe that always evaluates to . - *) - let const ( ctx : context ) ( v : float ) = - (new probe ctx)#cnstr_obj (Z3native.probe_const (context_gno ctx) v) - - (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by - *) - let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_lt (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by - *) - let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_gt (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by - *) - let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_le (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by - *) - let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_ge (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by - *) - let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_eq (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". - *) - (* CMW: and is a keyword *) - let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_and (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". - *) - (* CMW: or is a keyword *) - let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_or (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". - *) - (* CMW: is not a keyword? *) - let not_ ( ctx : context ) ( p : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_not (context_gno ctx) p#gno) -end - (** Solvers *) module Solver = struct type solver = z3_native_object -(**/**) - let solver_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = let res : solver = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.solver_inc_ref ; @@ -4896,7 +4884,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_cnstr res) ; res -(**/**) + (**/**) type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE @@ -4911,7 +4899,7 @@ struct type statistics = z3_native_object (**/**) - let statistics_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = let res : statistics = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.stats_inc_ref ; @@ -4919,28 +4907,58 @@ struct (z3obj_sno res ctx no) ; (z3obj_cnstr res) ; res - (**/**) + (**/**) (** - Statistical data is organized into pairs of [Key, Entry], where every - Entry is either a DoubleEntry or a UIntEntry + Statistical data is organized into pairs of \[Key, Entry\], where every + Entry is either a floating point or integer value. + *) module Entry = struct + type statistics_entry = { + mutable m_key : string; + mutable m_is_int : bool ; + mutable m_is_float : bool ; + mutable m_int : int ; + mutable m_float : float } + + (**/**) + let cnstr_si k v = + let res : statistics_entry = { + m_key = k ; + m_is_int = true ; + m_is_float = false ; + m_int = v ; + m_float = 0.0 + } in + res + + let cnstr_sd k v = + let res : statistics_entry = { + m_key = k ; + m_is_int = false ; + m_is_float = true ; + m_int = 0 ; + m_float = v + } in + res + (**/**) + (** The key of the entry. *) - let get_key (x : statistics_entry) = x#key + let get_key (x : statistics_entry) = x.m_key (** The int-value of the entry. *) - let get_int (x : statistics_entry) = x#int + let get_int (x : statistics_entry) = x.m_int (** The float-value of the entry. *) - let get_float (x : statistics_entry) = x#float + let get_float (x : statistics_entry) = x.m_float (** True if the entry is uint-valued. *) - let is_int (x : statistics_entry) = x#is_int + let is_int (x : statistics_entry) = x.m_is_int (** True if the entry is double-valued. *) - let is_float (x : statistics_entry) = x#is_float + let is_float (x : statistics_entry) = x.m_is_float (** The string representation of the the entry's value. *) let to_string_value (x : statistics_entry) = @@ -4967,9 +4985,9 @@ struct let f i = ( let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then - ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.cnstr_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.cnstr_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in Array.init n f @@ -5087,7 +5105,7 @@ struct if (Z3native.is_null q) then None else - Some (Model.model_cnstr (z3obj_gc x) q) + Some (Model.cnstr (z3obj_gc x) q) (** The proof of the last Check. @@ -5125,7 +5143,7 @@ struct Solver statistics. *) let get_statistics ( x : solver ) = - (Statistics.statistics_cnstr (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) + (Statistics.cnstr (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) (** Creates a new (incremental) solver. @@ -5136,8 +5154,8 @@ struct *) let mk_solver ( ctx : context ) ( logic : symbol option) = match logic with - | None -> (solver_cnstr ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (solver_cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) x#gno)) + | None -> (cnstr ctx (Z3native.mk_solver (context_gno ctx))) + | Some (x) -> (cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) x#gno)) (** Creates a new (incremental) solver. @@ -5150,7 +5168,7 @@ struct Creates a new (incremental) solver. *) let mk_simple_solver ( ctx : context ) = - (solver_cnstr ctx (Z3native.mk_simple_solver (context_gno ctx))) + (cnstr ctx (Z3native.mk_simple_solver (context_gno ctx))) (** Creates a solver that is implemented using the given tactic. @@ -5159,7 +5177,7 @@ struct will always solve each check from scratch. *) let mk_solver_t ( ctx : context ) ( t : tactic ) = - (solver_cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno)) + (cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno)) (** A string representation of the solver. @@ -5169,12 +5187,12 @@ end (** Fixedpoint solving *) -module Fixedpoints = +module Fixedpoint = struct type fixedpoint = z3_native_object -(**/**) - let fixedpoint_cnstr ( ctx : context ) = + (**/**) + let cnstr ( ctx : context ) = let res : fixedpoint = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.fixedpoint_inc_ref ; @@ -5182,7 +5200,7 @@ struct (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; (z3obj_cnstr res) ; res -(**/**) + (**/**) (** A string that describes all available fixedpoint solver parameters. @@ -5320,7 +5338,7 @@ struct Retrieve internal string representation of fixedpoint object. *) let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - + (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) @@ -5354,7 +5372,7 @@ struct (** Create a Fixedpoint context. *) - let mk_fixedpoint ( ctx : context ) = fixedpoint_cnstr ctx + let mk_fixedpoint ( ctx : context ) = cnstr ctx end (** Global and context options @@ -5365,24 +5383,24 @@ end module Options = struct -(** - 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. - -*) + (** + 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. + + *) let update_param_value ( ctx : context ) ( id : string) ( value : string )= Z3native.update_param_value (context_gno ctx) id value -(** - Get a configuration parameter. - - Returns None if the parameter value does not exist. - -*) + (** + Get a configuration parameter. + + Returns None if the parameter value does not exist. + + *) let get_param_value ( ctx : context ) ( id : string ) = let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in if not r then @@ -5408,12 +5426,12 @@ struct let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) -(** - Enable/disable printing of warning messages to the console. + (** + Enable/disable printing of warning messages to the console. - Note that this function is static and effects the behaviour of - all contexts globally. -*) + Note that this function is static and effects the behaviour of + all contexts globally. + *) let toggle_warning_messages ( enabled: bool ) = Z3native.toggle_warning_messages enabled end @@ -5581,17 +5599,17 @@ end (* (** - 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. + 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, error_code errorCode, string errorString); + public delegate void ErrorHandler(Context ctx, error_code errorCode, string errorString); - internal Z3native.error_handler m_n_err_handler = null; + internal Z3native.error_handler m_n_err_handler = null; - internal void NativeErrorHandler(IntPtr ctx, error_code errorCode) + internal void NativeErrorHandler(IntPtr ctx, error_code errorCode) - Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. + Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. *) From d0fea5e7404c9e99ace0930a80f8f207a67a25af Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 12 Jan 2013 23:18:05 +0000 Subject: [PATCH 045/248] ML API: moved more objects into normal types. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 734 ++++++++++++++++++++++++++--------------------- 1 file changed, 412 insertions(+), 322 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 545c7c227..8c0f24c4b 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,13 +7,30 @@ open Z3enums -type context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } - -(**/**) - +(**/**) +(* Some helpers. *) + let null = Z3native.mk_null() let is_null o = (Z3native.is_null o) +let mk_list ( f : int -> 'a ) ( n : int ) = + let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = + if (i >= n) then + tail + else + (mk_list' f (i+1) n ((f i) :: tail)) + in + mk_list' f 0 n [] +(**/**) + + +(**/**) +type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } +(**/**) +type context = z3_native_context + +(**/**) + let context_dispose ctx = if ctx.m_n_obj_cnt == 0 then ( (* Printf.printf "Disposing context \n" ; *) @@ -71,8 +88,6 @@ let mk_context ( cfg : ( string * string ) list ) = context_cnstr cfg -(* type z3object = { m_ctx : context; m_n_obj : Z3native.ptr option; } *) - (**/**) class virtual z3object ctx_init obj_init = object (self) @@ -120,17 +135,6 @@ object (self) method gnc = (context_gno m_ctx) end - -(** Parameter set objects *) -class params ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.params_inc_ref nc o - method decref nc o = Z3native.params_dec_ref nc o -end - - (** Symbol objects *) class symbol ctx = object (self) @@ -292,44 +296,6 @@ let func_declaton (a : func_decl array) = let f (e : func_decl) = e#gno in Array.map f a -class parameter = -object (self) - val mutable m_kind : parameter_kind = PARAMETER_INT; - val mutable m_i : int = 0 - val mutable m_d : float = 0.0 - val mutable m_sym : symbol option = None - val mutable m_srt : sort option = None - val mutable m_ast : ast option = None - val mutable m_fd : func_decl option = None - val mutable m_r : string = "" - - method cnstr_int i = m_kind <- PARAMETER_INT; m_i <- i - method cnstr_double d = m_kind <- PARAMETER_DOUBLE; m_d <- d - method cnstr_symbol sym = m_kind <- PARAMETER_SYMBOL; m_sym <- sym - method cnstr_sort srt = m_kind <- PARAMETER_SORT; m_srt <- srt - method cnstr_ast ast = m_kind <- PARAMETER_AST; m_ast <- ast - method cnstr_func_decl fd = m_kind <- PARAMETER_FUNC_DECL; m_fd <- fd - method cnstr_rational r = m_kind <- PARAMETER_RATIONAL; m_r <- r - - method kind = m_kind - method int = m_i - method double = m_d - method symbol = match m_sym with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing parameter symbol") - method sort = match m_srt with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing parameter sort") - method ast = match m_ast with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing parameter ast") - method func_decl = match m_fd with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing parameter func_decl") - method rational = m_r -end - - (** Enum sort objects *) class enum_sort ctx = object (self) @@ -499,26 +465,6 @@ let create_sort ctx obj = | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") -(** AST vector objects *) -class ast_vector ctx = -object (self) - inherit z3object ctx None - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.ast_vector_inc_ref nc o - method decref nc o = Z3native.ast_vector_dec_ref nc o -end - - -(** AST map objects *) -class ast_map ctx = -object (self) - inherit z3object ctx None - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.ast_map_inc_ref nc o - method decref nc o = Z3native.ast_map_dec_ref nc o -end - - (** Expression objects *) class expr ctx = object(self) @@ -625,37 +571,6 @@ let patternaton (a : pattern array) = let f (e : pattern) = e#gno in Array.map f a -(** Parameter description objects *) -class param_descrs ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.param_descrs_inc_ref nc o - method decref nc o = Z3native.param_descrs_dec_ref nc o -end - -(** Goal objects *) -class goal ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.goal_inc_ref nc o - method decref nc o = Z3native.goal_dec_ref nc o -end - -(** Tactic objects *) -class tactic ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.tactic_inc_ref nc o - method decref nc o = Z3native.tactic_dec_ref nc o -end - -let tacticaton (a : tactic array) = - let f (e : tactic) = e#gno in - Array.map f a - type z3_native_object = { m_ctx : context ; @@ -689,6 +604,10 @@ let z3obj_cnstr o = let f = fun o -> (z3obj_dispose o) in Gc.finalise f o +let array_to_native a = + let f e = (z3obj_gno e) in + Array.map f a + (**/**) @@ -890,62 +809,153 @@ let create_ast ctx no = (** Function declarations *) module FuncDecl = struct + (** Parameters of Func_Decls *) module Parameter = struct + type parameter = { + m_kind : parameter_kind ; + m_i : int ; + m_d : float ; + m_sym : symbol option ; + m_srt : sort option ; + m_ast : ast option ; + m_fd : func_decl option ; + m_r : string ; + } + + (**/**) + let cnstr_int i = { + m_kind = PARAMETER_INT ; + m_i = i ; + m_d = 0.0 ; + m_sym = None ; + m_srt = None ; + m_ast = None ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_double d = { + m_kind = PARAMETER_DOUBLE ; + m_i = 0 ; + m_d = d ; + m_sym = None ; + m_srt = None ; + m_ast = None ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_symbol sym = { + m_kind = PARAMETER_SYMBOL ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = sym ; + m_srt = None ; + m_ast = None ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_sort srt = { + m_kind = PARAMETER_SORT ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = None ; + m_srt = srt ; + m_ast = None ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_ast ast = { + m_kind = PARAMETER_AST ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = None ; + m_srt = None ; + m_ast = ast ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_func_decl fd ={ + m_kind = PARAMETER_FUNC_DECL ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = None ; + m_srt = None ; + m_ast = None ; + m_fd = fd ; + m_r = "" ; + } + + let cnstr_rational r = { + m_kind = PARAMETER_RATIONAL ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = None ; + m_srt = None ; + m_ast = None ; + m_fd = None ; + m_r = r ; + } + (**/**) + (** The kind of the parameter. *) - let get_kind (x : parameter) = x#kind + let get_kind ( x : parameter ) = x.m_kind (**The int value of the parameter.*) - let get_int (x : parameter) = - if (x#kind != PARAMETER_INT) then + let get_int ( x : parameter ) = + if ((get_kind x) != PARAMETER_INT) then raise (Z3native.Exception "parameter is not an int") else - x#int + x.m_i (**The double value of the parameter.*) - let get_double (x : parameter) = - if (x#kind != PARAMETER_DOUBLE) then + let get_double ( x : parameter ) = + if ((get_kind x) != PARAMETER_DOUBLE) then raise (Z3native.Exception "parameter is not a double") else - x#double + x.m_d (**The Symbol value of the parameter.*) - let get_symbol (x : parameter) = - if (x#kind != PARAMETER_SYMBOL) then + let get_symbol ( x : parameter ) = + if ((get_kind x) != PARAMETER_SYMBOL) then raise (Z3native.Exception "parameter is not a symbol") else - x#symbol + x.m_sym (**The Sort value of the parameter.*) - let get_sort (x : parameter) = - if (x#kind != PARAMETER_SORT) then + let get_sort ( x : parameter ) = + if ((get_kind x) != PARAMETER_SORT) then raise (Z3native.Exception "parameter is not a sort") else - x#sort + x.m_srt (**The AST value of the parameter.*) - let get_ast (x : parameter) = - if (x#kind != PARAMETER_AST) then + let get_ast ( x : parameter ) = + if ((get_kind x) != PARAMETER_AST) then raise (Z3native.Exception "parameter is not an ast") else - x#ast + x.m_ast (**The FunctionDeclaration value of the parameter.*) - let get_ast (x : parameter) = - if (x#kind != PARAMETER_FUNC_DECL) then + let get_ast ( x : parameter ) = + if ((get_kind x) != PARAMETER_FUNC_DECL) then raise (Z3native.Exception "parameter is not an function declaration") else - x#func_decl + x.m_fd (**The rational string value of the parameter.*) - let get_rational (x : parameter) = - if (x#kind != PARAMETER_RATIONAL) then + let get_rational ( x : parameter ) = + if ((get_kind x) != PARAMETER_RATIONAL) then raise (Z3native.Exception "parameter is not a ratinoal string") else - x#rational + x.m_r end (** @@ -1051,7 +1061,7 @@ struct The number of parameters of the function declaration *) let get_num_parameters (x : func_decl) = (Z3native.get_decl_num_parameters x#gnc x#gno) - + (** The parameters of the function declaration *) @@ -1059,15 +1069,15 @@ struct let n = (get_num_parameters x) in let f i = ( match (parameter_kind_of_int (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with - | PARAMETER_INT -> (new parameter)#cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) - | PARAMETER_DOUBLE -> (new parameter)#cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) - | PARAMETER_SYMBOL-> (new parameter)#cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) - | PARAMETER_SORT -> (new parameter)#cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) - | PARAMETER_AST -> (new parameter)#cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) - | PARAMETER_FUNC_DECL -> (new parameter)#cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) - | PARAMETER_RATIONAL -> (new parameter)#cnstr_rational (Z3native.get_decl_rational_parameter x#gnc x#gno i) + | PARAMETER_INT -> Parameter.cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) + | PARAMETER_DOUBLE -> Parameter.cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) + | PARAMETER_SYMBOL-> Parameter.cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) + | PARAMETER_SORT -> Parameter.cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) + | PARAMETER_AST -> Parameter.cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) + | PARAMETER_FUNC_DECL -> Parameter.cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) + | PARAMETER_RATIONAL -> Parameter.cnstr_rational (Z3native.get_decl_rational_parameter x#gnc x#gno i) ) in - Array.init n f + mk_list f n (** Create expression that applies function to arguments. @@ -1083,9 +1093,22 @@ struct (** Vectors of ASTs *) module ASTVector = struct + type ast_vector = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_vector = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_vector_inc_ref ; + dec_ref = Z3native.ast_vector_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + (** The size of the vector *) let get_size ( x : ast_vector ) = - Z3native.ast_vector_size x#gnc x#gno + Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) (** Retrieves the i-th object in the vector. @@ -1093,16 +1116,16 @@ struct @return An AST *) let get ( x : ast_vector ) ( i : int ) = - create_ast x#gc (Z3native.ast_vector_get x#gnc x#gno i) + create_ast (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) (** Sets the i-th object in the vector. *) let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set x#gnc x#gno i value#gno + Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i value#gno (** Resize the vector to . @param newSize The new size of the vector. *) let resize ( x : ast_vector ) ( new_size : int ) = - Z3native.ast_vector_resize x#gnc x#gno new_size + Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size (** Add the AST to the back of the vector. The size @@ -1110,7 +1133,7 @@ struct @param a An AST *) let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push x#gnc x#gno a#gno + Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) a#gno (** Translates all ASTs in the vector to . @@ -1118,60 +1141,73 @@ struct @return A new ASTVector *) let translate ( x : ast_vector ) ( to_ctx : context ) = - (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno (context_gno to_ctx)) + cnstr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Retrieves a string representation of the vector. *) let to_string ( x : ast_vector ) = - Z3native.ast_vector_to_string x#gnc x#gno + Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) end (** Map from AST to AST *) module ASTMap = struct + type ast_map = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_map = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_map_inc_ref ; + dec_ref = Z3native.ast_map_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + (** Checks whether the map contains the key . @param k An AST @return True if is a key in the map, false otherwise. *) - let contains ( m : ast_map ) ( key : ast ) = - (Z3native.ast_map_contains m#gnc m#gno key#gno) + let contains ( x : ast_map ) ( key : ast ) = + (Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) key#gno) (** Finds the value associated with the key . This function signs an error when is not a key in the map. @param k An AST *) - let find ( m : ast_map ) ( key : ast ) = - create_ast m#gc (Z3native.ast_map_find m#gnc m#gno key#gno) + let find ( x : ast_map ) ( key : ast ) = + create_ast (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) key#gno) (** Stores or replaces a new key/value pair in the map. @param k The key AST @param v The value AST *) - let insert ( m : ast_map ) ( key : ast ) ( value : ast) = - Z3native.ast_map_insert m#gnc m#gno key#gno value#gno + let insert ( x : ast_map ) ( key : ast ) ( value : ast) = + Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) key#gno value#gno (** Erases the key from the map. @param k An AST *) - let erase ( m : ast_map ) ( key : ast ) = - Z3native.ast_map_erase m#gnc m#gno key#gno + let erase ( x : ast_map ) ( key : ast ) = + Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) key#gno (** Removes all keys from the map. *) - let reset ( m : ast_map ) = - Z3native.ast_map_reset m#gnc m#gno + let reset ( x : ast_map ) = + Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) (** The size of the map *) - let get_size ( m : ast_map ) = - Z3native.ast_map_size m#gnc m#gno + let get_size ( x : ast_map ) = + Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) (** The keys stored in the map. *) - let get_keys ( m : ast_map ) = - (new ast_vector m#gc)#cnstr_obj (Z3native.ast_map_keys m#gnc m#gno) + let get_keys ( x : ast_map ) = + ASTVector.cnstr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) (** Retrieves a string representation of the map.*) - let to_strnig ( m : ast_map ) = - Z3native.ast_map_to_string m#gnc m#gno + let to_string ( x : ast_map ) = + Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) end (** @@ -1297,6 +1333,125 @@ struct let unwrap_ast ( a : ast ) = a#gno end + +(** + Parameter sets (of Solvers, Tactics, ...) + + A Params objects represents a configuration in the form of symbol/value pairs. +*) +module Params = +struct + type params = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : params = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.params_inc_ref ; + dec_ref = Z3native.params_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) + module ParamDescrs = + struct + type param_descrs = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : param_descrs = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.param_descrs_inc_ref ; + dec_ref = Z3native.param_descrs_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params ) = + Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) + + (** Retrieve kind of parameter. *) + let get_kind ( x : param_descrs ) ( name : symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) name#gno)) + + (** Retrieve all names of parameters. *) + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in + let f i = create_symbol (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in + Array.init n f + + (** The size of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) + + (** Retrieves a string representation of the ParamDescrs. *) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) + end + + (** + Adds a parameter setting. + *) + let add_bool ( x : params ) ( name : symbol ) ( value : bool ) = + Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) name#gno value + + (** + Adds a parameter setting. + *) + let add_int ( x : params ) (name : symbol ) ( value : int ) = + Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) name#gno value + + (** + Adds a parameter setting. + *) + let add_double ( x : params ) ( name : symbol ) ( value : float ) = + Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) name#gno value + + (** + Adds a parameter setting. + *) + let add_symbol ( x : params ) ( name : symbol ) ( value : symbol ) = + Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) name#gno value#gno + + (** + Adds a parameter setting. + *) + let add_s_bool ( x : params ) ( name : string) ( value : bool ) = + add_bool x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + + (** + Adds a parameter setting. + *) + let add_s_int ( x : params) ( name : string ) ( value : int ) = + add_int x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + + (** + Adds a parameter setting. + *) + let add_s_double ( x : params ) ( name : string ) ( value : float ) = + add_double x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + + (** + Adds a parameter setting. + *) + let add_s_symbol ( x : params ) ( name : string ) ( value : symbol ) = + add_symbol x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + + (** + Creates a new parameter set + *) + let mk_params ( ctx : context ) = + cnstr ctx (Z3native.mk_params (context_gno ctx)) + + (** + A string representation of the parameter set. + *) + let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) +end + + (** General expressions (terms), including Boolean logic *) module Expr = struct @@ -1305,9 +1460,9 @@ struct @param p A set of parameters to configure the simplifier *) - let simplify ( x : expr ) ( p : params option ) = match p with + let simplify ( x : expr ) ( p : Params.params option ) = match p with | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) - | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno pp#gno) + | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno (z3obj_gno pp)) (** a string describing all available parameters to Expr.Simplify. @@ -1319,7 +1474,7 @@ struct Retrieves parameter descriptions for simplifier. *) let get_simplify_parameter_descrs ( ctx : context ) = - (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs (context_gno ctx)) + Params.ParamDescrs.cnstr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. @@ -4079,96 +4234,6 @@ struct let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end -(** - Parameter sets (of Solvers, Tactics, ...) - - A Params objects represents a configuration in the form of symbol/value pairs. -*) -module Params = -struct - (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) - module ParamDescrs = - struct - - (** Validate a set of parameters. *) - let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno - - (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) - - (** Retrieve all names of parameters. *) - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size x#gnc x#gno in - let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in - Array.init n f - - (** The size of the ParamDescrs. *) - let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno - - (** Retrieves a string representation of the ParamDescrs. *) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno - end - - (** - Adds a parameter setting. - *) - let add_bool (p : params) (name : symbol) (value : bool) = - Z3native.params_set_bool p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_int (p : params) (name : symbol) (value : int) = - Z3native.params_set_uint p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_double (p : params) (name : symbol) (value : float) = - Z3native.params_set_double p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_symbol (p : params) (name : symbol) (value : symbol) = - Z3native.params_set_symbol p#gnc p#gno name#gno value#gno - - (** - Adds a parameter setting. - *) - let add_s_bool (p : params) (name : string) (value : bool) = - add_bool p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_int (p : params) (name : string) (value : int) = - add_int p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_double (p : params) (name : string) (value : float) = - add_double p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_symbol (p : params) (name : string) (value : symbol) = - add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Creates a new parameter set - *) - let mk_params ( ctx : context ) = - (new params ctx)#cnstr_obj (Z3native.mk_params (context_gno ctx)) - - (** - A string representation of the parameter set. - *) - let to_string (p : params) = Z3native.params_to_string p#gnc p#gno -end (** Goals @@ -4177,6 +4242,18 @@ end tactics and solvers. *) module Goal = struct + type goal = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : goal = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.goal_inc_ref ; + dec_ref = Z3native.goal_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) (** The precision of the goal. @@ -4185,7 +4262,7 @@ struct An over approximation is applied when the objective is to find a proof for a given goal. *) let get_precision ( x : goal ) = - goal_prec_of_int (Z3native.goal_precision x#gnc x#gno) + goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) (** Indicates whether the goal is precise. *) let is_precise ( x : goal ) = @@ -4206,62 +4283,62 @@ struct (** Adds the constraints to the given goal. *) (* CMW: assert seems to be a keyword. *) let assert_ ( x : goal ) ( constraints : bool_expr array ) = - let f e = Z3native.goal_assert x#gnc x#gno e#gno in + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) e#gno in ignore (Array.map f constraints) ; () (** Indicates whether the goal contains `false'. *) let is_inconsistent ( x : goal ) = - Z3native.goal_inconsistent x#gnc x#gno + Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) (** The depth of the goal. This tracks how many transformations were applied to it. *) - let get_depth ( x : goal ) = Z3native.goal_depth x#gnc x#gno + let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) (** Erases all formulas from the given goal. *) - let reset ( x : goal ) = Z3native.goal_reset x#gnc x#gno + let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) (** The number of formulas in the goal. *) - let get_size ( x : goal ) = Z3native.goal_size x#gnc x#gno + let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = (new bool_expr x#gc)#cnstr_obj (Z3native.goal_formula x#gnc x#gno i) in + let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) - let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs x#gnc x#gno + let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) let is_decided_sat ( x : goal ) = - Z3native.goal_is_decided_sat x#gnc x#gno + Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) let is_decided_unsat ( x : goal ) = - Z3native.goal_is_decided_unsat x#gnc x#gno + Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = - (new goal to_ctx)#cnstr_obj (Z3native.goal_translate x#gnc x#gno (context_gno to_ctx)) + cnstr to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - let simplify ( x : goal ) ( p : params option ) = - let tn = Z3native.mk_tactic x#gnc "simplify" in - Z3native.tactic_inc_ref x#gnc tn ; + let simplify ( x : goal ) ( p : Params.params option ) = + let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in + Z3native.tactic_inc_ref (z3obj_gnc x) tn ; let arn = match p with - | None -> Z3native.tactic_apply x#gnc tn x#gno - | Some(pn) -> Z3native.tactic_apply_ex x#gnc tn x#gno pn#gno + | None -> Z3native.tactic_apply (z3obj_gnc x) tn (z3obj_gno x) + | Some(pn) -> Z3native.tactic_apply_ex (z3obj_gnc x) tn (z3obj_gno x) (z3obj_gno pn) in - Z3native.apply_result_inc_ref x#gnc arn ; - let sg = Z3native.apply_result_get_num_subgoals x#gnc arn in + Z3native.apply_result_inc_ref (z3obj_gnc x) arn ; + let sg = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) arn in let res = if sg == 0 then raise (Z3native.Exception "No subgoals") else - Z3native.apply_result_get_subgoal x#gnc arn 0 in - Z3native.apply_result_dec_ref x#gnc arn ; - Z3native.tactic_dec_ref x#gnc tn ; - (new goal x#gc)#cnstr_obj res + Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in + Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; + Z3native.tactic_dec_ref (z3obj_gnc x) tn ; + cnstr (z3obj_gc x) res (** @@ -4274,10 +4351,10 @@ struct @param proofs Indicates whether proof generation should be enabled. *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - (new goal ctx)#cnstr_obj (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) + cnstr ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) (** A string representation of the Goal. *) - let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno + let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) end @@ -4326,7 +4403,7 @@ struct module FuncEntry = struct type func_entry = z3_native_object - + (**/**) let cnstr ( ctx : context ) ( no : Z3native.ptr ) = let res : func_entry = { m_ctx = ctx ; @@ -4528,7 +4605,7 @@ struct An array of expressions, where each is an element of the universe of *) let sort_universe ( x : model ) ( s : sort ) = - let n_univ = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in + let n_univ = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in Array.init n f @@ -4568,8 +4645,8 @@ struct A probe always produce a double value. "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - let apply ( x : probe ) (g : goal) = - Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) g#gno + let apply ( x : probe ) (g : Goal.goal) = + Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (** The number of supported Probes. @@ -4673,6 +4750,19 @@ end *) module Tactic = struct + type tactic = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : tactic = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.tactic_inc_ref ; + dec_ref = Z3native.tactic_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + (** Tactic application results ApplyResult objects represent the result of an application of a @@ -4699,12 +4789,12 @@ struct (** Retrieves the subgoals from the apply_result. *) let get_subgoals ( x : apply_result ) = let n = (get_num_subgoals x) in - let f i = (new goal (z3obj_gc x))#cnstr_obj (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in + let f i = Goal.cnstr (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** Retrieves the subgoals from the apply_result. *) let get_subgoal ( x : apply_result ) ( i : int ) = - (new goal (z3obj_gc x))#cnstr_obj (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) + Goal.cnstr (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) (** Convert a model for the subgoal into a model for the original goal g, that the ApplyResult was obtained from. @@ -4718,18 +4808,17 @@ struct end (** A string containing a description of parameters accepted by the tactic. *) - let get_help ( x : tactic ) = Z3native.tactic_get_help x#gnc x#gno - + let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) (** Retrieves parameter descriptions for Tactics. *) let get_param_descrs ( x : tactic ) = - (new param_descrs x#gc)#cnstr_obj (Z3native.tactic_get_param_descrs x#gnc x#gno) + Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Apply the tactic to the goal. *) - let apply ( x : tactic ) ( g : goal ) ( p : params option ) = + let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = match p with - | None -> (ApplyResult.cnstr x#gc (Z3native.tactic_apply x#gnc x#gno g#gno)) - | Some (pn) -> (ApplyResult.cnstr x#gc (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno)) + | None -> (ApplyResult.cnstr (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) + | Some (pn) -> (ApplyResult.cnstr (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) (** The number of supported tactics. @@ -4755,7 +4844,7 @@ struct Creates a new Tactic. *) let mk_tactic ( ctx : context ) ( name : string ) = - (new tactic ctx)#cnstr_obj (Z3native.mk_tactic (context_gno ctx) name) + cnstr ctx (Z3native.mk_tactic (context_gno ctx) name) (** Create a tactic that applies to a Goal and @@ -4763,20 +4852,21 @@ struct *) let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array ) = let f p c = (match p with - | None -> (Some c#gno) - | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) c#gno x))) in + | None -> (Some (z3obj_gno c)) + | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in match (Array.fold_left f None ts) with - | None -> (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then (context_gno ctx) t1#gno t2#gno) + | None -> + cnstr ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) | Some(x) -> - let o = (Z3native.tactic_and_then (context_gno ctx) t2#gno x) in - (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then (context_gno ctx) t1#gno o) + let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in + cnstr ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) (** Create a tactic that first applies to a Goal and if it fails then returns the result of applied to the Goal. *) let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_or_else (context_gno ctx) t1#gno t2#gno) + cnstr ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) (** Create a tactic that applies to a goal for milliseconds. @@ -4784,7 +4874,7 @@ struct If does not terminate within milliseconds, then it fails. *) let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_try_for (context_gno ctx) t#gno ms) + cnstr ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) (** Create a tactic that applies to a given goal if the probe @@ -4794,72 +4884,72 @@ struct *) (* CMW: when is a keyword *) let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) t#gno) + cnstr ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) t1#gno t2#gno) + cnstr ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) (** Create a tactic that keeps applying until the goal is not modified anymore or the maximum number of iterations is reached. *) let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_repeat (context_gno ctx) t#gno max) + cnstr ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) (** Create a tactic that just returns the given goal. *) let skip ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_skip (context_gno ctx)) + cnstr ctx (Z3native.tactic_skip (context_gno ctx)) (** Create a tactic always fails. *) let fail ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail (context_gno ctx)) + cnstr ctx (Z3native.tactic_fail (context_gno ctx)) (** Create a tactic that fails if the probe evaluates to false. *) let fail_if ( ctx : context ) ( p : Probe.probe ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) + cnstr ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) or trivially unsatisfiable (i.e., contains `false'). *) let fail_if_not_decided ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if_not_decided (context_gno ctx)) + cnstr ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) (** Create a tactic that applies using the given set of parameters . *) - let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_using_params (context_gno ctx) t#gno p#gno) + let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + cnstr ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) (** Create a tactic that applies using the given set of parameters . Alias for UsingParams*) (* CMW: with is a keyword *) - let with_ ( ctx : context ) ( t : tactic ) ( p : params ) = + let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = using_params ctx t p (** Create a tactic that applies the given tactics in parallel. *) let par_or ( ctx : context ) ( t : tactic array ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (tacticaton t)) + cnstr ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) (** Create a tactic that applies to a given goal and then to every subgoal produced by . The subgoals are processed in parallel. *) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_par_and_then (context_gno ctx) t1#gno t2#gno) + cnstr ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) (** Interrupt the execution of a Z3 procedure. @@ -5015,14 +5105,14 @@ struct (** Sets the solver parameters. *) - let set_parameters ( x : solver ) ( value : params )= - Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) value#gno + let set_parameters ( x : solver ) ( p : Params.params )= + Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** Retrieves parameter descriptions for solver. *) let get_param_descrs ( x : solver ) = - (new param_descrs (z3obj_gc x))#cnstr_obj (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** The current number of backtracking points (scopes). @@ -5062,7 +5152,7 @@ struct The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) @@ -5070,7 +5160,7 @@ struct The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in let f i = ((new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get a i)#gno) in Array.init n f @@ -5128,7 +5218,7 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let cn = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f @@ -5176,8 +5266,8 @@ struct The solver supports the commands Push and Pop, but it will always solve each check from scratch. *) - let mk_solver_t ( ctx : context ) ( t : tactic ) = - (cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno)) + let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = + (cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) (** A string representation of the solver. @@ -5211,14 +5301,14 @@ struct (** Sets the fixedpoint solver parameters. *) - let set_params ( x : fixedpoint ) ( p : params )= - Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) p#gno + let set_params ( x : fixedpoint ) ( p : Params.params )= + Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** Retrieves parameter descriptions for Fixedpoint solver. *) let get_param_descrs ( x : fixedpoint ) = - (new param_descrs (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Assert a constraints into the fixedpoint solver. @@ -5355,7 +5445,7 @@ struct Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = ((new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in Array.init n f @@ -5364,7 +5454,7 @@ struct Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = ((new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in Array.init n f From 69138924e5fd834f2890dceea371e503215ae3f7 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sun, 13 Jan 2013 00:02:38 +0000 Subject: [PATCH 046/248] ML API: Symbols are now normal types with visible hierarchy. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 468 ++++++++++++++++++++++++----------------------- 1 file changed, 241 insertions(+), 227 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 8c0f24c4b..378988d59 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -135,39 +135,145 @@ object (self) method gnc = (context_gno m_ctx) end -(** Symbol objects *) -class symbol ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = () - method decref nc o = () -end -(** Int symbol objects *) -class int_symbol ctx = -object(self) - inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_int i = (self#sno ctx (Z3native.mk_int_symbol (context_gno ctx) i)) ; self -end -(** String symbol objects *) -class string_symbol ctx = -object(self) - inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_string name = (self#sno ctx (Z3native.mk_string_symbol (context_gno ctx) name)) ; self -end +type z3_native_object = { + m_ctx : context ; + mutable m_n_obj : Z3native.ptr ; + inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; + dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } -let symbolaton (a : symbol array) = - let f (e : symbol) = e#gno in +let z3obj_gc o = o.m_ctx +let z3obj_gnc o = (context_gno o.m_ctx) + +let z3obj_gno o = o.m_n_obj +let z3obj_sno o ctx no = + (context_add1 ctx) ; + o.inc_ref (context_gno ctx) no ; + ( + if not (is_null o.m_n_obj) then + o.dec_ref (context_gno ctx) o.m_n_obj ; + (context_sub1 ctx) + ) ; + o.m_n_obj <- no + +let z3obj_dispose o = + if not (is_null o.m_n_obj) then + ( + o.dec_ref (z3obj_gnc o) o.m_n_obj ; + (context_sub1 (z3obj_gc o)) + ) ; + o.m_n_obj <- null + +let z3obj_cnstr o = + let f = fun o -> (z3obj_dispose o) in + Gc.finalise f o + +let z3obj_nil_ref x y = () + +let array_to_native a = + let f e = (z3obj_gno e) in Array.map f a +(**/**) -let create_symbol ctx no = - match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj no) :> symbol) - | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj no) :> symbol) + +(** Symbols are used to name several term and type constructors *) +module Symbol = +struct + (** Int symbol objects *) + type int_symbol = z3_native_object + + (** String symbol objects *) + and string_symbol = z3_native_object + + and symbol = + | IntSymbol of int_symbol + | StringSymbol of string_symbol + + (**/**) + let cnstr_i ( ctx : context ) ( no : Z3native.ptr ) = + let res : int_symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + let cnstr_s ( ctx : context ) ( no : Z3native.ptr ) = + let res : string_symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + + let gnc ( x : symbol ) = + match x with + | IntSymbol(n) -> (z3obj_gnc n) + | StringSymbol(n) -> (z3obj_gnc n) + + let gno ( x : symbol ) = + match x with + | IntSymbol(n) -> (z3obj_gno n) + | StringSymbol(n) -> (z3obj_gno n) + + let create ( ctx : context ) ( no : Z3native.ptr ) = + match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with + | INT_SYMBOL -> IntSymbol (cnstr_i ctx no) + | STRING_SYMBOL -> StringSymbol (cnstr_s ctx no) + + let aton a = + let f e = (gno e) in + Array.map f a + (**/**) + + (** The kind of the symbol (int or string) *) + let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) + + (** Indicates whether the symbol is of Int kind *) + let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL + + (** Indicates whether the symbol is of string kind. *) + let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL + + (** The int value of the symbol. *) + let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) + + (** The string value of the symbol. *) + let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) + + (** A string representation of the symbol. *) + let to_string ( o : symbol ) = + match (kind o) with + | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) + | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) + + (** + 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. + *) + let mk_int ( ctx : context ) ( i : int ) = + IntSymbol (cnstr_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) + + (** Creates a new symbol using a string. *) + let mk_string ( ctx : context ) ( s : string ) = + StringSymbol (cnstr_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) + + (** Create an array of symbols. *) + let mk_ints ( ctx : context ) ( names : int array ) = + let f elem = mk_int ( ctx : context ) elem in + (Array.map f names) + + (** Create an array of symbols. *) + let mk_strings ( ctx : context ) ( names : string array ) = + let f elem = mk_string ( ctx : context ) elem in + (Array.map f names) +end + +(**/**) (** AST objects *) class ast ctx = @@ -242,7 +348,7 @@ class uninterpreted_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_s (s : symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) s#gno)) ; self + method cnstr_s (s : Symbol.symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; self end (** Finite domain sort objects *) @@ -250,7 +356,7 @@ class finite_domain_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort (context_gno ctx) s#gno sz)) ; self + method cnstr_si (s : Symbol.symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno s) sz)) ; self end (** Relation sort objects *) @@ -273,8 +379,8 @@ class tuple_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_siss (name : symbol) (num_fields: int) (field_names : symbol array) (field_sorts : sort array) = - let (x,_,_) = (Z3native.mk_tuple_sort (context_gno ctx) name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in + method cnstr_siss (name : Symbol.symbol) (num_fields: int) (field_names : Symbol.symbol array) (field_sorts : sort array) = + let (x,_,_) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) num_fields (Symbol.aton field_names) (astaton field_sorts)) in (self#sno ctx x) ; self end @@ -285,7 +391,7 @@ class func_decl ctx = object (self) inherit ast ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl (context_gno ctx) name#gno (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_ndr (name : Symbol.symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (astaton domain) range#gno)) ; self method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (astaton domain) range#gno)) ; self method incref nc o = super#incref nc o @@ -303,8 +409,8 @@ object (self) val mutable _constdecls : func_decl array option = None val mutable _testerdecls : func_decl array option = None method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : symbol) (enum_names : symbol array) = - let (r, a, b) = (Z3native.mk_enumeration_sort (context_gno ctx) name#gno (Array.length enum_names) (symbolaton enum_names)) in + method cnstr_ss (name : Symbol.symbol) (enum_names : Symbol.symbol array) = + let (r, a, b) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Symbol.aton enum_names)) in _constdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f a)) ; _testerdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f b)) ; (self#sno ctx r) ; @@ -330,8 +436,8 @@ object (self) val mutable _headdecl : func_decl option = None val mutable _taildecl : func_decl option = None method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : symbol) (elem_sort : sort) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) name#gno elem_sort#gno) in + method cnstr_ss (name : Symbol.symbol) (elem_sort : sort) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) elem_sort#gno) in _nildecl <- Some ((new func_decl ctx)#cnstr_obj a) ; _is_nildecl <- Some ((new func_decl ctx)#cnstr_obj b) ; _consdecl <- Some ((new func_decl ctx)#cnstr_obj c) ; @@ -381,7 +487,7 @@ object (self) let v = self in Gc.finalise f v - method cnstr_ssssi (name : symbol) (recognizer : symbol) (field_names : symbol array) (sorts : sort array) (sort_refs : int array) = + method cnstr_ssssi (name : Symbol.symbol) (recognizer : Symbol.symbol) (field_names : Symbol.symbol array) (sorts : sort array) (sort_refs : int array) = m_n <- (Array.length field_names) ; if m_n != (Array.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -389,7 +495,7 @@ object (self) if m_n != (Array.length sort_refs) then raise (Z3native.Exception "Number of field names does not match number of sort refs") else - let o = (Z3native.mk_constructor (context_gno ctx) name#gno recognizer#gno m_n (symbolaton field_names) + let o = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) (Symbol.gno recognizer) m_n (Symbol.aton field_names) (sortaton sorts) sort_refs) in self#sno ctx o ; @@ -449,7 +555,7 @@ class datatype_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_sc (name : symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype (context_gno ctx) name#gno (Array.length constructors) (constructoraton constructors)))) ; self + method cnstr_sc (name : Symbol.symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (constructoraton constructors)))) ; self end let create_sort ctx obj = @@ -571,43 +677,6 @@ let patternaton (a : pattern array) = let f (e : pattern) = e#gno in Array.map f a - -type z3_native_object = { - m_ctx : context ; - mutable m_n_obj : Z3native.ptr ; - inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; - dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - -let z3obj_gc o = o.m_ctx -let z3obj_gnc o = (context_gno o.m_ctx) - -let z3obj_gno o = o.m_n_obj -let z3obj_sno o ctx no = - (context_add1 ctx) ; - o.inc_ref (context_gno ctx) no ; - ( - if not (is_null o.m_n_obj) then - o.dec_ref (context_gno ctx) o.m_n_obj ; - (context_sub1 ctx) - ) ; - o.m_n_obj <- no - -let z3obj_dispose o = - if not (is_null o.m_n_obj) then - ( - o.dec_ref (z3obj_gnc o) o.m_n_obj ; - (context_sub1 (z3obj_gc o)) - ) ; - o.m_n_obj <- null - -let z3obj_cnstr o = - let f = fun o -> (z3obj_dispose o) in - Gc.finalise f o - -let array_to_native a = - let f e = (z3obj_gno e) in - Array.map f a - (**/**) @@ -656,58 +725,6 @@ struct string_of_int rev ^ "." end -(** Symbols are used to name several term and type constructors *) -module Symbol = -struct - (** The kind of the symbol (int or string) *) - let kind (o : symbol) = (symbol_kind_of_int (Z3native.get_symbol_kind o#gnc o#gno)) - - (** Indicates whether the symbol is of Int kind *) - let is_int_symbol (o : symbol) = (kind o) == INT_SYMBOL - - (** Indicates whether the symbol is of string kind. *) - let is_string_symbol (o : symbol) = (kind o) == STRING_SYMBOL - - (** The int value of the symbol. *) - let get_int (o : int_symbol) = Z3native.get_symbol_int o#gnc o#gno - - (** The string value of the symbol. *) - let get_string (o : string_symbol) = Z3native.get_symbol_string o#gnc o#gno - - (** A string representation of the symbol. *) - let to_string (o : symbol) = - match (kind o) with - | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int o#gnc o#gno)) - | STRING_SYMBOL -> (Z3native.get_symbol_string o#gnc o#gno) - - (** - 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. - *) - let mk_int ( ctx : context ) i = - (new int_symbol ctx)#cnstr_int i - - (** Creates a new symbol using a string. *) - let mk_string ( ctx : context ) s = - (new string_symbol ctx)#cnstr_string s - - (** - Create an array of symbols. - *) - let mk_ints ( ctx : context ) ( names : int array ) = - let f elem = mk_int ( ctx : context ) elem in - (Array.map f names) - - (** - Create an array of symbols. - *) - let mk_strings ( ctx : context ) ( names : string array ) = - let f elem = mk_string ( ctx : context ) elem in - (Array.map f names) -end - (** The Sort module implements type information for ASTs *) module Sort = @@ -738,7 +755,7 @@ struct (** The name of the sort *) - let get_name (x : sort) = (create_symbol x#gc (Z3native.get_sort_name x#gnc x#gno)) + let get_name (x : sort) = (Symbol.create x#gc (Z3native.get_sort_name x#gnc x#gno)) (** A string representation of the sort. @@ -754,14 +771,14 @@ struct (** Create a new uninterpreted sort. *) - let mk_uninterpreted ( ctx : context ) (s : symbol) = + let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = (new uninterpreted_sort ctx)#cnstr_s s (** Create a new uninterpreted sort. *) - let mk_uninterpreted_s ( ctx : context ) (s : string) = - mk_uninterpreted ctx ((Symbol.mk_string ( ctx : context ) s) :> symbol) + let mk_uninterpreted_s ( ctx : context ) ( s : string ) = + mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) end (**/**) @@ -817,7 +834,7 @@ struct m_kind : parameter_kind ; m_i : int ; m_d : float ; - m_sym : symbol option ; + m_sym : Symbol.symbol option ; m_srt : sort option ; m_ast : ast option ; m_fd : func_decl option ; @@ -961,14 +978,14 @@ struct (** Creates a new function declaration. *) - let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort) = + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort) = (new func_decl ctx)#cnstr_ndr name domain range (** Creates a new function declaration. *) let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = - mk_func_decl ctx ((Symbol.mk_string ctx name) :> symbol) domain range + mk_func_decl ctx (Symbol.mk_string ctx name) domain range (** Creates a fresh function declaration with a name prefixed with . @@ -981,7 +998,7 @@ struct (** Creates a new constant function declaration. *) - let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort) = + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort) = (new func_decl ctx)#cnstr_ndr name [||] range @@ -989,7 +1006,7 @@ struct Creates a new constant function declaration. *) let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr ((Symbol.mk_string ctx name) :> symbol) [||] range + (new func_decl ctx)#cnstr_ndr (Symbol.mk_string ctx name) [||] range (** Creates a fresh constant function declaration with a name prefixed with . @@ -1055,7 +1072,7 @@ struct (** The name of the function declaration *) - let get_name (x : func_decl) = (create_symbol x#gc (Z3native.get_decl_name x#gnc x#gno)) + let get_name (x : func_decl) = (Symbol.create x#gc (Z3native.get_decl_name x#gnc x#gno)) (** The number of parameters of the function declaration @@ -1071,7 +1088,7 @@ struct match (parameter_kind_of_int (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with | PARAMETER_INT -> Parameter.cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) | PARAMETER_DOUBLE -> Parameter.cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) - | PARAMETER_SYMBOL-> Parameter.cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) + | PARAMETER_SYMBOL-> Parameter.cnstr_symbol (Some (Symbol.create x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) | PARAMETER_SORT -> Parameter.cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) | PARAMETER_AST -> Parameter.cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) | PARAMETER_FUNC_DECL -> Parameter.cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) @@ -1375,13 +1392,13 @@ struct Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) name#gno)) + let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) (** Retrieve all names of parameters. *) let get_names ( x : param_descrs ) = let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in - let f i = create_symbol (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in + let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** The size of the ParamDescrs. *) @@ -1394,50 +1411,50 @@ struct (** Adds a parameter setting. *) - let add_bool ( x : params ) ( name : symbol ) ( value : bool ) = - Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) name#gno value + let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = + Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_int ( x : params ) (name : symbol ) ( value : int ) = - Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) name#gno value + let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = + Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_double ( x : params ) ( name : symbol ) ( value : float ) = - Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) name#gno value + let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = + Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_symbol ( x : params ) ( name : symbol ) ( value : symbol ) = - Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) name#gno value#gno + let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = + Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) (** Adds a parameter setting. *) - let add_s_bool ( x : params ) ( name : string) ( value : bool ) = - add_bool x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = + add_bool x (Symbol.mk_string (z3obj_gc x) name) value (** Adds a parameter setting. *) let add_s_int ( x : params) ( name : string ) ( value : int ) = - add_int x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + add_int x (Symbol.mk_string (z3obj_gc x) name) value (** Adds a parameter setting. *) let add_s_double ( x : params ) ( name : string ) ( value : float ) = - add_double x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + add_double x (Symbol.mk_string (z3obj_gc x) name) value (** Adds a parameter setting. *) - let add_s_symbol ( x : params ) ( name : string ) ( value : symbol ) = - add_symbol x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = + add_symbol x (Symbol.mk_string (z3obj_gc x) name) value (** Creates a new parameter set @@ -1662,15 +1679,15 @@ struct (** Creates a new Constant of sort and named . *) - let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = - create_expr ctx (Z3native.mk_const (context_gno ctx) name#gno range#gno) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + create_expr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) range#gno) (** Creates a new Constant of sort and named . *) let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = - mk_const ctx ((Symbol.mk_string ctx name) :> symbol) range + mk_const ctx (Symbol.mk_string ctx name)range (** @@ -1690,14 +1707,14 @@ struct (** Create a Boolean constant. *) - let mk_bool_const ( ctx : context ) ( name : symbol ) = + let mk_bool_const ( ctx : context ) ( name : Symbol.symbol ) = ((mk_const ctx name (Sort.mk_bool ctx)) :> bool_expr) (** Create a Boolean constant. *) let mk_bool_const_s ( ctx : context ) ( name : string ) = - mk_bool_const ctx ((Symbol.mk_string ctx name) :> symbol) + mk_bool_const ctx (Symbol.mk_string ctx name) (** Create a new function application. @@ -1907,7 +1924,7 @@ struct *) let get_bound_variable_names ( x : quantifier ) = let n = (get_num_bound x) in - let f i = (create_symbol x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in + let f i = (Symbol.create x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in Array.init n f (** @@ -1960,7 +1977,7 @@ struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then @@ -1968,23 +1985,23 @@ struct (match weight with | None -> 1 | Some(x) -> x) (Array.length patterns) (patternaton patterns) (Array.length sorts) (astaton sorts) - (astaton names) + (Symbol.aton names) body#gno) else (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> x#gno) - (match skolem_id with | None -> null | Some(x) -> x#gno) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length patterns) (patternaton patterns) (Array.length nopatterns) (patternaton nopatterns) (Array.length sorts) (astaton sorts) - (astaton names) + (Symbol.aton names) body#gno) (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) @@ -1994,8 +2011,8 @@ struct else (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> x#gno) - (match skolem_id with | None -> null | Some(x) -> x#gno) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length bound_constants) (expraton bound_constants) (Array.length patterns) (patternaton patterns) (Array.length nopatterns) (patternaton nopatterns) @@ -2004,7 +2021,7 @@ struct Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then @@ -2012,23 +2029,23 @@ struct (match weight with | None -> 1 | Some(x) -> x) (Array.length patterns) (patternaton patterns) (Array.length sorts) (astaton sorts) - (astaton names) + (Symbol.aton names) body#gno) else (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> x#gno) - (match skolem_id with | None -> null | Some(x) -> x#gno) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length patterns) (patternaton patterns) (Array.length nopatterns) (patternaton nopatterns) (Array.length sorts) (astaton sorts) - (astaton names) + (Symbol.aton names) body#gno) (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) @@ -2038,8 +2055,8 @@ struct else (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> x#gno) - (match skolem_id with | None -> null | Some(x) -> x#gno) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length bound_constants) (expraton bound_constants) (Array.length patterns) (patternaton patterns) (Array.length nopatterns) (patternaton nopatterns) @@ -2048,7 +2065,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -2058,7 +2075,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -2128,14 +2145,14 @@ struct (** Create an array constant. *) - let mk_const ( ctx : context ) ( name : symbol ) ( domain : sort ) ( range : sort ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = ((Expr.mk_const ctx name ((mk_sort ctx domain range) :> sort)) :> array_expr) (** Create an array constant. *) let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = - mk_const ctx ((Symbol.mk_string ctx name) :> symbol) domain range + mk_const ctx (Symbol.mk_string ctx name) domain range (** Array read. @@ -2307,14 +2324,14 @@ struct (** Create a new finite domain sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) size = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) size = (new finite_domain_sort ctx)#cnstr_si name size (** Create a new finite domain sort. *) let mk_sort_s ( ctx : context ) ( name : string ) size = - (new finite_domain_sort ctx)#cnstr_si ((Symbol.mk_string ctx name) :> symbol) size + (new finite_domain_sort ctx)#cnstr_si (Symbol.mk_string ctx name) size (** @@ -2488,7 +2505,7 @@ struct 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. *) - let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array) = (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs @@ -2502,32 +2519,32 @@ struct 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. *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = - mk_constructor ctx ((Symbol.mk_string ctx name) :> symbol) recognizer field_names sorts sort_refs + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : constructor array) = (new datatype_sort ctx)#cnstr_sc name constructors (** Create a new datatype sort. *) let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = - mk_sort ctx ((Symbol.mk_string ctx name) :> symbol) constructors + mk_sort ctx (Symbol.mk_string ctx name) constructors (** Create mutually recursive datatypes. @param names names of datatype sorts @param c list of constructors, one list per sort. *) - let mk_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = + let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : constructor array array ) = let n = (Array.length names) in let f e = ( (new constructor_list ctx)#cnstr_ca e ) in let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (symbolaton names) (constructor_listaton cla)) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.aton names) (constructor_listaton cla)) in let g e = ( (new datatype_sort ctx)#cnstr_obj e) in (Array.map g r) @@ -2535,7 +2552,7 @@ struct let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = mk_sorts ctx ( - let f e = ((Symbol.mk_string ctx e) :> symbol) in + let f e = (Symbol.mk_string ctx e) in Array.map f names ) c @@ -2581,10 +2598,8 @@ struct *) let mk_sort_s ( ctx : context ) name enum_names = (new enum_sort ctx)#cnstr_ss - ((Symbol.mk_string ( ctx : context ) name) :> symbol) - (let f e = (e :> symbol) in - (Array.map f (Symbol.mk_strings ( ctx : context ) enum_names)) - ) + (Symbol.mk_string ctx name) + (Symbol.mk_strings ctx enum_names) (** The function declarations of the constants in the enumeration. *) let get_const_decls (x : enum_sort) = x#const_decls @@ -2599,15 +2614,14 @@ struct (** Create a new list sort. *) - let mk_sort ( ctx : context ) (name : symbol) elem_sort = + let mk_sort ( ctx : context ) (name : Symbol.symbol) elem_sort = (new list_sort ctx)#cnstr_ss name elem_sort (** Create a new list sort. *) let mk_list_s ( ctx : context ) (name : string) elem_sort = - mk_sort ctx ((Symbol.mk_string ctx name) :> symbol) elem_sort - + mk_sort ctx (Symbol.mk_string ctx name) elem_sort (** The declaration of the nil function of this list sort. *) let get_nil_decl (x : list_sort) = x#nil_decl @@ -2805,26 +2819,26 @@ struct (** Creates an integer constant. *) - let mk_int_const ( ctx : context ) ( name : symbol ) = + let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = ((Expr.mk_const ctx name (mk_int_sort ctx)) :> int_expr) (** Creates an integer constant. *) let mk_int_const_s ( ctx : context ) ( name : string ) = - mk_int_const ctx ((Symbol.mk_string ctx name) :> symbol) + mk_int_const ctx (Symbol.mk_string ctx name) (** Creates a real constant. *) - let mk_real_const ( ctx : context ) ( name : symbol ) = + let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = ((Expr.mk_const ctx name (mk_real_sort ctx)) :> real_expr) (** Creates a real constant. *) let mk_real_const_s ( ctx : context ) ( name : string ) = - mk_real_const ctx ((Symbol.mk_string ctx name) :> symbol) + mk_real_const ctx (Symbol.mk_string ctx name) (** Create an expression representing t[0] + t[1] + .... @@ -3300,14 +3314,14 @@ struct (** Creates a bit-vector constant. *) - let mk_const ( ctx : context ) ( name : symbol ) ( size : int ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = ((Expr.mk_const ctx name (mk_sort ctx size)) :> bitvec_expr) (** Creates a bit-vector constant. *) let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = - mk_const ctx ((Symbol.mk_string ctx name) :> symbol) size + mk_const ctx (Symbol.mk_string ctx name) size (** Bitwise negation. @@ -5242,17 +5256,17 @@ struct check-sat command, and check-sat commands that take more than a given number of milliseconds to be solved. *) - let mk_solver ( ctx : context ) ( logic : symbol option) = + let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = match logic with | None -> (cnstr ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) x#gno)) + | Some (x) -> (cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) (** Creates a new (incremental) solver. *) let mk_solver_s ( ctx : context ) ( logic : string ) = - mk_solver ctx (Some ((Symbol.mk_string ctx logic) :> symbol)) + mk_solver ctx (Some (Symbol.mk_string ctx logic)) (** Creates a new (incremental) solver. @@ -5327,10 +5341,10 @@ struct (** Add rule into the fixedpoint solver. *) - let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : Symbol.symbol option ) = match name with | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno y#gno + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno (Symbol.gno y) (** Add table fact to the fixedpoint solver. @@ -5381,8 +5395,8 @@ struct (** Update named rule into in the fixedpoint solver. *) - let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) rule#gno name#gno + let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : Symbol.symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) rule#gno (Symbol.gno name) (** Retrieve satisfying instance or instances of solver, @@ -5432,8 +5446,8 @@ struct (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) f#gno (Array.length kinds) (symbolaton kinds) + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) f#gno (Array.length kinds) (Symbol.aton kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. @@ -5554,7 +5568,7 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5564,17 +5578,17 @@ struct else Z3native.parse_smtlib_string (context_gno ctx) str cs - (symbolaton sort_names) + (Symbol.aton sort_names) (astaton sorts) cd - (symbolaton decl_names) + (Symbol.aton decl_names) (func_declaton decls) (** Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5584,10 +5598,10 @@ struct else Z3native.parse_smtlib_file (context_gno ctx) file_name cs - (symbolaton sort_names) + (Symbol.aton sort_names) (astaton sorts) cd - (symbolaton decl_names) + (Symbol.aton decl_names) (func_declaton decls) (** @@ -5649,7 +5663,7 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5659,17 +5673,17 @@ struct else Z3native.parse_smtlib2_string (context_gno ctx) str cs - (symbolaton sort_names) + (Symbol.aton sort_names) (astaton sorts) cd - (symbolaton decl_names) + (Symbol.aton decl_names) (func_declaton decls) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5679,10 +5693,10 @@ struct else Z3native.parse_smtlib2_string (context_gno ctx) file_name cs - (symbolaton sort_names) + (Symbol.aton sort_names) (astaton sorts) cd - (symbolaton decl_names) + (Symbol.aton decl_names) (func_declaton decls) end From 048e8c1a978101cb54654f95a92e30479015e1d8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Jan 2013 11:37:39 +0000 Subject: [PATCH 047/248] ML API: updated example Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 38b5fe642..3b13a2462 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -22,8 +22,8 @@ exception TestFailedException of string *) let model_converter_test ( ctx : context ) = Printf.printf "ModelConverterTest\n"; - let xr = ((mk_const ctx ((Symbol.mk_string ctx "x") :> symbol) (mk_real_sort ctx )) :> arith_expr) in - let yr = ((mk_const ctx ((Symbol.mk_string ctx "y") :> symbol) (mk_real_sort ctx )) :> arith_expr) in + let xr = ((mk_const ctx (Symbol.mk_string ctx "x") (mk_real_sort ctx )) :> arith_expr) in + let yr = ((mk_const ctx (Symbol.mk_string ctx "y") (mk_real_sort ctx )) :> arith_expr) in let g4 = (mk_goal ctx true false false ) in (Goal.assert_ g4 [| (mk_gt ctx xr (mk_real_numeral_nd ctx 10 1)) |]) ; (Goal.assert_ g4 [| (mk_eq ctx yr (mk_add ctx [| xr; (mk_real_numeral_nd ctx 1 1) |] )) |] ) ; @@ -68,9 +68,9 @@ let model_converter_test ( ctx : context ) = let basic_tests ( ctx : context ) = Printf.printf "BasicTests\n" ; let qi = (mk_int ctx 1) in - let fname = ((mk_string ctx "f") :> symbol) in - let x = ((mk_string ctx "x") :> symbol) in - let y = ((mk_string ctx "y") :> symbol) in + let fname = (mk_string ctx "f") in + let x = (mk_string ctx "x") in + let y = (mk_string ctx "y") in let bs = (Sort.mk_bool ctx) in let domain = [| bs; bs |] in let f = (FuncDecl.mk_func_decl ctx fname domain bs) in @@ -142,8 +142,8 @@ let basic_tests ( ctx : context ) = ); ( let g3 = (mk_goal ctx true true false) in - let xc = (mk_const ctx ((Symbol.mk_string ctx "x") :> symbol) (mk_int_sort ctx)) in - let yc = (mk_const ctx ((Symbol.mk_string ctx "y") :> symbol) (mk_int_sort ctx)) in + let xc = (mk_const ctx (Symbol.mk_string ctx "x") (mk_int_sort ctx)) in + let yc = (mk_const ctx (Symbol.mk_string ctx "y") (mk_int_sort ctx)) in (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (mk_int_sort ctx))) |]) ; (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (mk_int_sort ctx))) |]) ; let constr = (mk_eq ctx xc yc) in @@ -211,8 +211,8 @@ let _ = let bs = (Sort.mk_bool ctx) in let ints = (mk_int_sort ctx) in let rs = (mk_real_sort ctx) in - Printf.printf "int symbol: %s\n" (Symbol.to_string (is :> symbol)); - Printf.printf "string symbol: %s\n" (Symbol.to_string (ss :> symbol)); + Printf.printf "int symbol: %s\n" (Symbol.to_string is); + Printf.printf "string symbol: %s\n" (Symbol.to_string ss); Printf.printf "bool sort: %s\n" (Sort.to_string bs); Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); From 7befc262d13c02fe736fa49bf87dac2a777e84e2 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Jan 2013 17:51:16 +0000 Subject: [PATCH 048/248] ML API: added functions for global parameter management. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 378988d59..0dfb173c4 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -5700,6 +5700,53 @@ struct (func_declaton decls) end + +(* Global functions *) + +(** + * Set a global (or module) parameter, which is shared by all Z3 contexts. + * + * When a Z3 module is initialized it will use the value of these parameters + * when Z3_params objects are not provided. + * The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. + * The character '.' is a delimiter (more later). + * The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. + * Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". + * This function can be used to set parameters for a specific Z3 module. + * This can be done by using .. + * For example: + * (set_global_param "pp.decimal" "true") + * will set the parameter "decimal" in the module "pp" to true. +*) +let set_global_param ( id : string ) ( value : string ) = + (Z3native.global_param_set id value) + +(** + * Get a global (or module) parameter. + * + * Returns None if the parameter does not exist. + * The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. + * This function cannot be invoked simultaneously from different threads without synchronization. + * The result string stored in param_value is stored in a shared location. +*) +let get_global_param ( id : string ) = + let (r, v) = (Z3native.global_param_get id) in + if not r then + None + else + Some v + +(** + * Restore the value of all global (and module) parameters. + * + * This command will not affect already created objects (such as tactics and solvers) + * +*) +let global_param_reset_all = + Z3native.global_param_reset_all + + + (* (** From 1eae7a6bacb962d7ad109f73e0c778255f6d48cb Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 17 Jan 2013 19:47:51 +0000 Subject: [PATCH 049/248] ML API: Added Solver.assert_and_track Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 0dfb173c4..f5c3e3d82 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -5159,8 +5159,42 @@ struct *) let assert_ ( x : solver ) ( constraints : bool_expr array ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in - ignore (Array.map f constraints) ; - () + ignore (Array.map f constraints) + + (** + * Assert multiple constraints (cs) into the solver, and track them (in the + * unsat) core + * using the Boolean constants in ps. + * + * This API is an alternative to with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using + * and the Boolean literals + * provided using with assumptions. + *) + let assert_and_track ( x : solver ) ( cs : bool_expr array ) ( ps : bool_expr array ) = + if ((Array.length cs) != (Array.length ps)) then + raise (Z3native.Exception "Argument size mismatch") + else + let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) e#gno (Array.get ps i)#gno) in + ignore (Array.iteri f cs) + + (** + * Assert a constraint (c) into the solver, and track it (in the unsat) core + * using the Boolean constant p. + * + * This API is an alternative to with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using + * and the Boolean literals + * provided using with assumptions. + *) + let assert_and_track ( x : solver ) ( c : bool_expr ) ( p : bool_expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) c#gno p#gno (** The number of assertions in the solver. From 49cd4e2d3542f00e5be5f6bdafe0a4b5daa9fc00 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 31 Jan 2013 12:51:31 +0000 Subject: [PATCH 050/248] ML build Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 554bb4259..bea2939b6 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1335,29 +1335,30 @@ class MLComponent(Component): src_dir = self.to_src_dir sub_dir = os.path.join('api', 'ml') mk_dir(os.path.join(BUILD_DIR, sub_dir)) + api_src = get_component(API_COMPONENT).to_src_dir for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) - out.write('libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s api/ml/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, get_component(API_COMPONENT).to_src_dir)) - out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') - out.write('api/ml/z3.cmxa: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('api/ml/libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, src_dir)) + out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') + out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(src_dir, mlfile)) out.write('\n') - out.write('\tcd %s && %s ' % (sub_dir, OCAMLOPT)) + out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" z3enums.ml z3native.ml z3.ml -a -o z3.cmxa -linkall && cd ../..\n' % get_component(API_COMPONENT).to_src_dir) - out.write('api/ml/z3.cma: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) + out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\tcd %s && %s ' % (sub_dir, OCAMLC)) + out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" z3enums.ml z3native.ml z3.ml -a -o z3.cma -linkall && cd ../..\n' % get_component(API_COMPONENT).to_src_dir) + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') out.write('\n') From 7b51dc9bdd06e54b65229bdee9914367b665b23b Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 4 Feb 2013 21:18:25 +0000 Subject: [PATCH 051/248] Checkpoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2989 ++++++++++++++++++++++++---------------------- 1 file changed, 1544 insertions(+), 1445 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index f5c3e3d82..0e47912ae 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,6 +7,51 @@ open Z3enums +(** 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. *) +module Log = +struct + (** Open an interaction log file. + @param filename the name of the file to open. + @return True if opening the log file succeeds, false otherwise. + *) + (* CMW: "open" seems to be a reserved keyword? *) + let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) + + (** Closes the interaction log. *) + let close = Z3native.close_log + + (** Appends a user-provided string to the interaction log. + @param s the string to append*) + let append s = Z3native.append_log s +end + +(** Version information *) +module Version = +struct + (** The major version. *) + let major = let (x, _, _, _) = Z3native.get_version in x + + (** The minor version. *) + let minor = let (_, x, _, _) = Z3native.get_version in x + + (** The build version. *) + let build = let (_, _, x, _) = Z3native.get_version in x + + (** The revision. *) + let revision = let (_, _, _, x) = Z3native.get_version in x + + (** A string representation of the version information. *) + let to_string = + let (mj, mn, bld, rev) = Z3native.get_version in + string_of_int mj ^ "." ^ + string_of_int mn ^ "." ^ + string_of_int bld ^ "." ^ + string_of_int rev ^ "." +end + (**/**) (* Some helpers. *) @@ -40,7 +85,7 @@ let context_dispose ctx = (* re-queue for finalization? *) ) -let context_cnstr settings = +let context_create settings = let cfg = Z3native.mk_config in let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; @@ -85,7 +130,7 @@ let context_gno ctx = ctx.m_n_ctx *) let mk_context ( cfg : ( string * string ) list ) = - context_cnstr cfg + context_create cfg (**/**) @@ -165,7 +210,7 @@ let z3obj_dispose o = ) ; o.m_n_obj <- null -let z3obj_cnstr o = +let z3obj_create o = let f = fun o -> (z3obj_dispose o) in Gc.finalise f o @@ -184,44 +229,51 @@ struct type int_symbol = z3_native_object (** String symbol objects *) - and string_symbol = z3_native_object + type string_symbol = z3_native_object - and symbol = - | IntSymbol of int_symbol - | StringSymbol of string_symbol + (** Symbol Objects *) + type symbol = + | S_Int of int_symbol + | S_Str of string_symbol (**/**) - let cnstr_i ( ctx : context ) ( no : Z3native.ptr ) = + let create_i ( ctx : context ) ( no : Z3native.ptr ) = let res : int_symbol = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res - let cnstr_s ( ctx : context ) ( no : Z3native.ptr ) = + + let create_s ( ctx : context ) ( no : Z3native.ptr ) = let res : string_symbol = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res + + let gc ( x : symbol ) = + match x with + | S_Int(n) -> (z3obj_gc n) + | S_Str(n) -> (z3obj_gc n) let gnc ( x : symbol ) = match x with - | IntSymbol(n) -> (z3obj_gnc n) - | StringSymbol(n) -> (z3obj_gnc n) + | S_Int(n) -> (z3obj_gnc n) + | S_Str(n) -> (z3obj_gnc n) let gno ( x : symbol ) = match x with - | IntSymbol(n) -> (z3obj_gno n) - | StringSymbol(n) -> (z3obj_gno n) + | S_Int(n) -> (z3obj_gno n) + | S_Str(n) -> (z3obj_gno n) let create ( ctx : context ) ( no : Z3native.ptr ) = match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> IntSymbol (cnstr_i ctx no) - | STRING_SYMBOL -> StringSymbol (cnstr_s ctx no) + | INT_SYMBOL -> S_Int (create_i ctx no) + | STRING_SYMBOL -> S_Str (create_s ctx no) let aton a = let f e = (gno e) in @@ -256,11 +308,11 @@ struct The legal range of unsigned integers is 0 to 2^30-1. *) let mk_int ( ctx : context ) ( i : int ) = - IntSymbol (cnstr_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) + S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) (** Creates a new symbol using a string. *) let mk_string ( ctx : context ) ( s : string ) = - StringSymbol (cnstr_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) + S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) (** Create an array of symbols. *) let mk_ints ( ctx : context ) ( names : int array ) = @@ -273,853 +325,47 @@ struct (Array.map f names) end -(**/**) - -(** AST objects *) -class ast ctx = -object (self) - inherit z3object ctx None as super (* CMW: derive from icomparable? *) - method cnstr_obj obj = (self#sno ctx obj) ; self - - method incref nc o = Z3native.inc_ref nc o - method decref nc o = Z3native.dec_ref nc o -end - -let astaton (a : ast array) = - let f (e : ast) = e#gno in - Array.map f a - -(** Sort objects *) -class sort ctx = -object (self) - inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -let sortaton (a : sort array) = - let f (e : sort) = e#gno in - Array.map f a - -(** Arithmetic sort objects, i.e., Int or Real. *) -class arith_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Array sorts objects *) -class array_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx (Z3native.mk_array_sort (context_gno ctx) domain#gno range#gno)) ; self -end - -(** Bit-vector sort objects *) -class bitvec_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Boolean sort objects *) -class bool_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Int sort objects *) -class int_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Real sort objects *) -class real_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Uninterpreted sort objects *) -class uninterpreted_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_s (s : Symbol.symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; self -end - -(** Finite domain sort objects *) -class finite_domain_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_si (s : Symbol.symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno s) sz)) ; self -end - -(** Relation sort objects *) -class relation_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Set sort objects *) -class set_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_s (s : sort) = (self#sno ctx s#gno) ; self -end - -(** Tuple sort objects *) -class tuple_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_siss (name : Symbol.symbol) (num_fields: int) (field_names : Symbol.symbol array) (field_sorts : sort array) = - let (x,_,_) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) num_fields (Symbol.aton field_names) (astaton field_sorts)) in - (self#sno ctx x) ; - self -end - - -(** Function declaration objects *) -class func_decl ctx = -object (self) - inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ndr (name : Symbol.symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (astaton domain) range#gno)) ; self - method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (astaton domain) range#gno)) ; self - - method incref nc o = super#incref nc o - method decref nc o = super#decref nc o -end - -let func_declaton (a : func_decl array) = - let f (e : func_decl) = e#gno in - Array.map f a - -(** Enum sort objects *) -class enum_sort ctx = -object (self) - inherit sort ctx as super - val mutable _constdecls : func_decl array option = None - val mutable _testerdecls : func_decl array option = None - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : Symbol.symbol) (enum_names : Symbol.symbol array) = - let (r, a, b) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Symbol.aton enum_names)) in - _constdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f a)) ; - _testerdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f b)) ; - (self#sno ctx r) ; - self - - method const_decls = match _constdecls with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing const decls") - - method tester_decls = match _testerdecls with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tester decls") -end - -(** List sort objects *) -class list_sort ctx = -object (self) - inherit sort ctx as super - val mutable _nildecl : func_decl option = None - val mutable _is_nildecl : func_decl option = None - val mutable _consdecl : func_decl option = None - val mutable _is_consdecl : func_decl option = None - val mutable _headdecl : func_decl option = None - val mutable _taildecl : func_decl option = None - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : Symbol.symbol) (elem_sort : sort) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) elem_sort#gno) in - _nildecl <- Some ((new func_decl ctx)#cnstr_obj a) ; - _is_nildecl <- Some ((new func_decl ctx)#cnstr_obj b) ; - _consdecl <- Some ((new func_decl ctx)#cnstr_obj c) ; - _is_consdecl <- Some ((new func_decl ctx)#cnstr_obj d) ; - _headdecl <- Some ((new func_decl ctx)#cnstr_obj e) ; - _taildecl <- Some ((new func_decl ctx)#cnstr_obj f) ; - (self#sno ctx r) ; - self - - method nil_decl = match _nildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing nil decl") - - method is_nil_decl = match _is_nildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_nil decl") - - method cons_decl = match _consdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing cons decl") - - method is_cons_decl = match _is_consdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_cons decl") - - method head_decl = match _headdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing head decl") - - method tail_decl = match _taildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tail decl") -end - -(** Constructor objects *) -class constructor ctx = -object (self) - inherit z3object ctx None as super - val mutable m_n : int = 0 - val mutable m_tester_decl : func_decl option = None - val mutable m_constructor_decl : func_decl option = None - val mutable m_accessor_decls : func_decl array option = None - method incref nc o = () - method decref nc o = () - initializer - let f = fun o -> Z3native.del_constructor o#gnc o#gno in - let v = self in - Gc.finalise f v - - method cnstr_ssssi (name : Symbol.symbol) (recognizer : Symbol.symbol) (field_names : Symbol.symbol array) (sorts : sort array) (sort_refs : int array) = - m_n <- (Array.length field_names) ; - if m_n != (Array.length sorts) then - raise (Z3native.Exception "Number of field names does not match number of sorts") - else - if m_n != (Array.length sort_refs) then - raise (Z3native.Exception "Number of field names does not match number of sort refs") - else - let o = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) (Symbol.gno recognizer) m_n (Symbol.aton field_names) - (sortaton sorts) - sort_refs) in - self#sno ctx o ; - self - - method private init = - match m_tester_decl with - | None -> - let (a, b, c) = (Z3native.query_constructor self#gnc self#gno m_n) in - m_constructor_decl <- Some ((new func_decl ctx)#cnstr_obj a) ; - m_tester_decl <- Some ((new func_decl ctx)#cnstr_obj b) ; - m_accessor_decls <- Some (let f e = ((new func_decl ctx)#cnstr_obj e) in Array.map f c) ; - () - | _ -> () - - method get_n = m_n - - method tester_decl = match m_tester_decl with - | Some(x) -> x - | None -> self#init ; self#tester_decl - - method constructor_decl = match m_constructor_decl with - | Some(x) -> x - | None -> self#init ; self#constructor_decl - - method accessor_decls = match m_accessor_decls with - | Some(x) -> x - | None -> self#init ; self#accessor_decls -end - -let constructoraton (a : constructor array) = - let f (e : constructor) = e#gno in - Array.map f a - -(** Constructor list objects *) -class constructor_list ctx = -object (self) - inherit z3object ctx None - method incref nc o = () - method decref nc o = () - initializer - let f = fun o -> Z3native.del_constructor_list o#gnc o#gno in - let v = self in - Gc.finalise f v - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ca ( c : constructor array ) = - self#sno ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (constructoraton c)) ; - self -end - -let constructor_listaton (a : constructor_list array) = - let f (e : constructor_list) = e#gno in - Array.map f a - -(** Datatype sort objects *) -class datatype_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_sc (name : Symbol.symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (constructoraton constructors)))) ; self -end - -let create_sort ctx obj = - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) obj)) with - | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) - | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) - | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) - | DATATYPE_SORT -> (((new datatype_sort ctx)#cnstr_obj obj) :> sort) - | INT_SORT -> (((new int_sort ctx)#cnstr_obj obj) :> sort) - | REAL_SORT -> (((new real_sort ctx)#cnstr_obj obj) :> sort) - | UNINTERPRETED_SORT -> (((new uninterpreted_sort ctx)#cnstr_obj obj) :> sort) - | FINITE_DOMAIN_SORT -> (((new finite_domain_sort ctx)#cnstr_obj obj) :> sort) - | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - -(** Expression objects *) -class expr ctx = -object(self) - inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -let expraton (a : expr array) = - let f (e : expr) = e#gno in - Array.map f a - -(** Boolean expression objects *) -class bool_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Arithmetic expression objects (int/real) *) -class arith_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Int expression objects *) -class int_expr ctx = -object (self) - inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Real expression objects *) -class real_expr ctx = -object (self) - inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Bit-vector expression objects *) -class bitvec_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Array expression objects *) -class array_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Datatype expression objects *) -class datatype_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Integer numeral expression objects *) -class int_num ctx = -object (self) - inherit int_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Rational numeral expression objects *) -class rat_num ctx = -object (self) - inherit real_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Bit-vector numeral expression objects *) -class bitvec_num ctx = -object (self) - inherit bitvec_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Algebraic numeral expression objects *) -class algebraic_num ctx = -object (self) - inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Quantifier objects *) -class quantifier ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Quantifier pattern objects *) -class pattern ctx = -object (self) - inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -let patternaton (a : pattern array) = - let f (e : pattern) = e#gno in - Array.map f a - -(**/**) - - -(** 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. *) -module Log = -struct - (** Open an interaction log file. - @param filename the name of the file to open. - @return True if opening the log file succeeds, false otherwise. - *) - (* CMW: "open" seems to be a reserved keyword? *) - let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) - - (** Closes the interaction log. *) - let close = Z3native.close_log - - (** Appends a user-provided string to the interaction log. - @param s the string to append*) - let append s = Z3native.append_log s -end - -(** Version information *) -module Version = -struct - (** The major version. *) - let major = let (x, _, _, _) = Z3native.get_version in x - - (** The minor version. *) - let minor = let (_, x, _, _) = Z3native.get_version in x - - (** The build version. *) - let build = let (_, _, x, _) = Z3native.get_version in x - - (** The revision. *) - let revision = let (_, _, _, x) = Z3native.get_version in x - - (** A string representation of the version information. *) - let to_string = - let (mj, mn, bld, rev) = Z3native.get_version in - string_of_int mj ^ "." ^ - string_of_int mn ^ "." ^ - string_of_int bld ^ "." ^ - string_of_int rev ^ "." -end - - -(** The Sort module implements type information for ASTs *) -module Sort = -struct - (** - Comparison operator. - @param a A sort - @param b A sort - @return True if and are from the same context - and represent the same sort; false otherwise. - *) - let ( = ) (a : sort) (b : sort) = (a == b) || - if a#gnc != b#gnc then - false - else - (Z3native.is_eq_sort a#gnc a#gno b#gno) - - (** - Returns a unique identifier for the sort. - *) - let get_id (x : sort) = Z3native.get_sort_id x#gnc x#gno - - (** - The kind of the sort. - *) - let get_sort_kind (x : sort) = (sort_kind_of_int (Z3native.get_sort_kind x#gnc x#gno)) - - (** - The name of the sort - *) - let get_name (x : sort) = (Symbol.create x#gc (Z3native.get_sort_name x#gnc x#gno)) - - (** - A string representation of the sort. - *) - let to_string (x : sort) = Z3native.sort_to_string x#gnc x#gno - - (** - Create a new Boolean sort. - *) - let mk_bool ( ctx : context ) = - (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort (context_gno ctx)) - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = - (new uninterpreted_sort ctx)#cnstr_s s - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted_s ( ctx : context ) ( s : string ) = - mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) -end - -(**/**) -let create_expr ctx obj = - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then - (((new quantifier ctx)#cnstr_obj obj) :> expr) - else - let s = Z3native.get_sort (context_gno ctx) obj in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) obj) then - (((new algebraic_num ctx)#cnstr_obj obj) :> expr) - else - if (Z3native.is_numeral_ast (context_gno ctx) obj) && - (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then - match sk with - | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) - | REAL_SORT -> (((new rat_num ctx)#cnstr_obj obj) :> expr) - | BV_SORT -> (((new bitvec_num ctx)#cnstr_obj obj) :> expr) - | _ -> raise (Z3native.Exception "Unsupported numeral object") - else - match sk with - | BOOL_SORT -> (((new bool_expr ctx)#cnstr_obj obj) :> expr) - | INT_SORT -> (((new int_expr ctx)#cnstr_obj obj) :> expr) - | REAL_SORT -> (((new real_expr ctx)#cnstr_obj obj) :> expr) - | BV_SORT -> (((new bitvec_expr ctx)#cnstr_obj obj) :> expr) - | ARRAY_SORT -> (((new array_expr ctx)#cnstr_obj obj) :> expr) - | DATATYPE_SORT -> (((new datatype_expr ctx)#cnstr_obj obj) :> expr) - | _ -> (new expr ctx)#cnstr_obj obj - -let create_expr_fa (ctx : context) (f : func_decl) (args : expr array) = - let o = Z3native.mk_app (context_gno ctx) f#gno (Array.length args) (astaton args) in - create_expr ctx o - -let create_ast ctx no = - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST -> (((new func_decl ctx)#cnstr_obj no) :> ast) - | QUANTIFIER_AST -> (((new quantifier ctx)#cnstr_obj no) :> ast) - | SORT_AST -> ((create_sort ctx no) :> ast) - | APP_AST - | NUMERAL_AST - | VAR_AST -> ((create_expr ctx no) :> ast) - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") -(**/**) - -(** Function declarations *) -module FuncDecl = -struct - - (** Parameters of Func_Decls *) - module Parameter = - struct - type parameter = { - m_kind : parameter_kind ; - m_i : int ; - m_d : float ; - m_sym : Symbol.symbol option ; - m_srt : sort option ; - m_ast : ast option ; - m_fd : func_decl option ; - m_r : string ; - } - - (**/**) - let cnstr_int i = { - m_kind = PARAMETER_INT ; - m_i = i ; - m_d = 0.0 ; - m_sym = None ; - m_srt = None ; - m_ast = None ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_double d = { - m_kind = PARAMETER_DOUBLE ; - m_i = 0 ; - m_d = d ; - m_sym = None ; - m_srt = None ; - m_ast = None ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_symbol sym = { - m_kind = PARAMETER_SYMBOL ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = sym ; - m_srt = None ; - m_ast = None ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_sort srt = { - m_kind = PARAMETER_SORT ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = None ; - m_srt = srt ; - m_ast = None ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_ast ast = { - m_kind = PARAMETER_AST ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = None ; - m_srt = None ; - m_ast = ast ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_func_decl fd ={ - m_kind = PARAMETER_FUNC_DECL ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = None ; - m_srt = None ; - m_ast = None ; - m_fd = fd ; - m_r = "" ; - } - - let cnstr_rational r = { - m_kind = PARAMETER_RATIONAL ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = None ; - m_srt = None ; - m_ast = None ; - m_fd = None ; - m_r = r ; - } - (**/**) - - (** - The kind of the parameter. - *) - let get_kind ( x : parameter ) = x.m_kind - - (**The int value of the parameter.*) - let get_int ( x : parameter ) = - if ((get_kind x) != PARAMETER_INT) then - raise (Z3native.Exception "parameter is not an int") - else - x.m_i - - (**The double value of the parameter.*) - let get_double ( x : parameter ) = - if ((get_kind x) != PARAMETER_DOUBLE) then - raise (Z3native.Exception "parameter is not a double") - else - x.m_d - - (**The Symbol value of the parameter.*) - let get_symbol ( x : parameter ) = - if ((get_kind x) != PARAMETER_SYMBOL) then - raise (Z3native.Exception "parameter is not a symbol") - else - x.m_sym - - (**The Sort value of the parameter.*) - let get_sort ( x : parameter ) = - if ((get_kind x) != PARAMETER_SORT) then - raise (Z3native.Exception "parameter is not a sort") - else - x.m_srt - - (**The AST value of the parameter.*) - let get_ast ( x : parameter ) = - if ((get_kind x) != PARAMETER_AST) then - raise (Z3native.Exception "parameter is not an ast") - else - x.m_ast - - (**The FunctionDeclaration value of the parameter.*) - let get_ast ( x : parameter ) = - if ((get_kind x) != PARAMETER_FUNC_DECL) then - raise (Z3native.Exception "parameter is not an function declaration") - else - x.m_fd - - (**The rational string value of the parameter.*) - let get_rational ( x : parameter ) = - if ((get_kind x) != PARAMETER_RATIONAL) then - raise (Z3native.Exception "parameter is not a ratinoal string") - else - x.m_r - end - - (** - Creates a new function declaration. - *) - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr name domain range - - (** - Creates a new function declaration. - *) - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = - mk_func_decl ctx (Symbol.mk_string ctx name) domain range - - (** - Creates a fresh function declaration with a name prefixed with . - - - *) - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort) = - (new func_decl ctx)#cnstr_pdr prefix domain range - - (** - Creates a new constant function declaration. - *) - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr name [||] range - - - (** - Creates a new constant function declaration. - *) - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr (Symbol.mk_string ctx name) [||] range - - (** - Creates a fresh constant function declaration with a name prefixed with . - - - *) - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = - (new func_decl ctx)#cnstr_pdr prefix [||] range - - - (** - Comparison operator. - @param a A func_decl - @param b A func_decl - @return True if and are from the same context - and represent the same func_decl; false otherwise. - *) - let ( = ) (a : func_decl) (b : func_decl) = (a == b) || - if a#gnc == a#gnc then - false - else - (Z3native.is_eq_func_decl a#gnc a#gno b#gno) - (** - A string representations of the function declaration. - *) - let to_string (x : func_decl) = Z3native.func_decl_to_string x#gnc x#gno - - (** - Returns a unique identifier for the function declaration. - *) - let get_id (x : func_decl) = Z3native.get_func_decl_id x#gnc x#gno - - (** - The arity of the function declaration - *) - let get_arity (x : func_decl) = Z3native.get_arity x#gnc x#gno - - (** - The size of the domain of the function declaration - - *) - let get_domain_size (x : func_decl) = Z3native.get_domain_size x#gnc x#gno - - (** - The domain of the function declaration - *) - let get_domain (x : func_decl) = - let n = (get_domain_size x) in - let f i = create_sort x#gc (Z3native.get_domain x#gnc x#gno i) in - Array.init n f - - (** - The range of the function declaration - *) - let get_range (x : func_decl) = - create_sort x#gc (Z3native.get_range x#gnc x#gno) - - (** - The kind of the function declaration. - *) - let get_decl_kind (x : func_decl) = (decl_kind_of_int (Z3native.get_decl_kind x#gnc x#gno)) - - (** - The name of the function declaration - *) - let get_name (x : func_decl) = (Symbol.create x#gc (Z3native.get_decl_name x#gnc x#gno)) - - (** - The number of parameters of the function declaration - *) - let get_num_parameters (x : func_decl) = (Z3native.get_decl_num_parameters x#gnc x#gno) - - (** - The parameters of the function declaration - *) - let get_parameters (x : func_decl) = - let n = (get_num_parameters x) in - let f i = ( - match (parameter_kind_of_int (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with - | PARAMETER_INT -> Parameter.cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) - | PARAMETER_DOUBLE -> Parameter.cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) - | PARAMETER_SYMBOL-> Parameter.cnstr_symbol (Some (Symbol.create x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) - | PARAMETER_SORT -> Parameter.cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) - | PARAMETER_AST -> Parameter.cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) - | PARAMETER_FUNC_DECL -> Parameter.cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) - | PARAMETER_RATIONAL -> Parameter.cnstr_rational (Z3native.get_decl_rational_parameter x#gnc x#gno i) - ) in - mk_list f n - - (** - Create expression that applies function to arguments. - @param args The arguments - *) - let apply (x : func_decl) (args : expr array) = create_expr_fa x#gc x args - -end (** The abstract syntax tree (AST) module *) -module AST = -struct +module rec AST : +sig + type ast = z3_native_object + + val create : context -> Z3native.ptr -> ast + val aton : ast array -> Z3native.ptr array + + val is_expr : ast -> bool + val is_var : ast -> bool +end = struct + type ast = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let aton (a : ast array) = + let f (e : ast) = (z3obj_gno e) in + Array.map f a + + (** Vectors of ASTs *) module ASTVector = struct type ast_vector = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_vector_inc_ref ; dec_ref = Z3native.ast_vector_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -1133,11 +379,11 @@ struct @return An AST *) let get ( x : ast_vector ) ( i : int ) = - create_ast (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) + create (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) (** Sets the i-th object in the vector. *) let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i value#gno + Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) (** Resize the vector to . @param newSize The new size of the vector. *) @@ -1150,7 +396,7 @@ struct @param a An AST *) let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) a#gno + Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) (** Translates all ASTs in the vector to . @@ -1158,7 +404,7 @@ struct @return A new ASTVector *) let translate ( x : ast_vector ) ( to_ctx : context ) = - cnstr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Retrieves a string representation of the vector. *) let to_string ( x : ast_vector ) = @@ -1171,13 +417,13 @@ struct type ast_map = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_map = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_map_inc_ref ; dec_ref = Z3native.ast_map_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -1185,7 +431,7 @@ struct @param k An AST @return True if is a key in the map, false otherwise. *) let contains ( x : ast_map ) ( key : ast ) = - (Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) key#gno) + Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (** Finds the value associated with the key . @@ -1193,7 +439,7 @@ struct @param k An AST *) let find ( x : ast_map ) ( key : ast ) = - create_ast (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) key#gno) + create (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) (** Stores or replaces a new key/value pair in the map. @@ -1201,14 +447,14 @@ struct @param v The value AST *) let insert ( x : ast_map ) ( key : ast ) ( value : ast) = - Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) key#gno value#gno + Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) (** Erases the key from the map. @param k An AST *) let erase ( x : ast_map ) ( key : ast ) = - Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) key#gno + Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (** Removes all keys from the map. *) let reset ( x : ast_map ) = @@ -1220,7 +466,7 @@ struct (** The keys stored in the map. *) let get_keys ( x : ast_map ) = - ASTVector.cnstr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) (** Retrieves a string representation of the map.*) let to_string ( x : ast_map ) = @@ -1231,23 +477,23 @@ struct The AST's hash code. @return A hash code *) - let get_hash_code ( x : ast) = Z3native.get_ast_hash x#gnc x#gno + let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) (** A unique identifier for the AST (unique among all ASTs). *) - let get_id ( x : ast) = Z3native.get_ast_id x#gnc x#gno + let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) (** The kind of the AST. *) - let get_ast_kind ( x : ast) = (ast_kind_of_int (Z3native.get_ast_kind x#gnc x#gno)) + let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) (** Indicates whether the AST is an Expr *) - let is_expr ( x : ast) = - match get_ast_kind ( x : ast) with + let is_expr ( x : ast ) = + match get_ast_kind ( x : ast ) with | APP_AST | NUMERAL_AST | QUANTIFIER_AST @@ -1257,33 +503,33 @@ struct (** Indicates whether the AST is a bound variable *) - let is_var ( x : ast) = (get_ast_kind x) == VAR_AST + let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST (** Indicates whether the AST is a Quantifier *) - let is_quantifier ( x : ast) = (get_ast_kind x) == QUANTIFIER_AST + let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST (** Indicates whether the AST is a Sort *) - let is_sort ( x : ast) = (get_ast_kind x) == SORT_AST + let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST (** Indicates whether the AST is a FunctionDeclaration *) - let is_func_decl ( x : ast) = (get_ast_kind x) == FUNC_DECL_AST + let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST (** A string representation of the AST. *) - let to_string ( x : ast) = Z3native.ast_to_string x#gnc x#gno + let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) (** A string representation of the AST in s-expression notation. *) - let to_sexpr ( x : ast) = Z3native.ast_to_string x#gnc x#gno + let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) (** Comparison operator. @@ -1292,11 +538,11 @@ struct @return True if and are from the same context and represent the same sort; false otherwise. *) - let ( = ) (a : expr) (b : expr) = (a == b) || - if a#gnc == b#gnc then + let ( = ) ( a : ast ) ( b : ast ) = (a == b) || + if (z3obj_gnc a) != (z3obj_gnc b) then false else - (Z3native.is_eq_ast a#gnc a#gno b#gno) + Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) (** Object Comparison. @@ -1316,11 +562,11 @@ struct @param ctx A context @return A copy of the AST which is associated with *) - let translate ( x : ast) to_ctx = - if x#gc == to_ctx then + let translate ( x : ast ) ( to_ctx : context ) = + if (z3obj_gnc x) == (context_gno to_ctx) then x else - (create_ast to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx))) + create to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Wraps an AST. @@ -1334,7 +580,7 @@ struct @param nativeObject The native pointer to wrap. *) let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = - create_ast ctx ptr + create ctx ptr (** Unwraps an AST. @@ -1347,43 +593,413 @@ struct @param a The AST to unwrap. *) - let unwrap_ast ( a : ast ) = a#gno + let unwrap_ast ( x : ast ) = (z3obj_gno x) + + (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with + | FUNC_DECL_AST -> (match (FuncDecl.create ctx no) with FuncDecl.FuncDecl(x) -> x) + | SORT_AST -> (match (Sort.create ctx no) with Sort.Sort(x) -> x) + | QUANTIFIER_AST -> (match (Quantifiers.create ctx no) with Quantifiers.Quantifier(Expr.Expr(x)) -> x) + | APP_AST + | NUMERAL_AST + | VAR_AST -> (match (Expr.create ctx no) with Expr.Expr(x) -> x) + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") +(**/**) end +(** The Sort module implements type information for ASTs *) +and Sort : +sig + type sort = Sort of AST.ast + type bitvec_sort = BitvecSort of sort + type uninterpreted_sort = UninterpretedSort of sort + + val create : context -> Z3native.ptr -> sort + val gno : sort -> Z3native.ptr + val gnc : sort -> Z3native.ptr + val aton : sort array -> Z3native.ptr array +end = struct + type sort = Sort of AST.ast + type bitvec_sort = BitvecSort of sort + type uninterpreted_sort = UninterpretedSort of sort + + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) + let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) + let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) + + let aton : sort array -> Z3native.ptr array = fun a -> + let f e = (gno e) in + Array.map f a + + let create : context -> Z3native.ptr -> sort = fun ctx no -> + let q : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno q ctx no) ; + (z3obj_create q) ; + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with + | ARRAY_SORT + | BOOL_SORT + | BV_SORT + | DATATYPE_SORT + | INT_SORT + | REAL_SORT + | UNINTERPRETED_SORT + | FINITE_DOMAIN_SORT + | RELATION_SORT -> Sort(q) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + + + (** + Comparison operator. + @param a A sort + @param b A sort + @return True if and are from the same context + and represent the same sort; false otherwise. + *) + let ( = ) : sort -> sort -> bool = fun a b -> + (a == b) || + if (gnc a) != (gnc b) then + false + else + (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) + + (** + Returns a unique identifier for the sort. + *) + let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) + + (** + The kind of the sort. + *) + let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) + + (** + The name of the sort + *) + let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) + + (** + A string representation of the sort. + *) + let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; + (z3obj_create res) ; + UninterpretedSort(Sort(res)) + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted_s ( ctx : context ) ( s : string ) = + mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) +end + + +(** Function declarations *) +and FuncDecl : +sig + type func_decl = FuncDecl of AST.ast + + val create : context -> Z3native.ptr -> func_decl + val gno : func_decl -> Z3native.ptr + val gnc : func_decl -> Z3native.ptr + + val get_domain_size : func_decl -> int + val get_decl_kind : func_decl -> Z3enums.decl_kind +end = struct + open Sort + + type func_decl = FuncDecl of AST.ast + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + FuncDecl(res) + + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Sort.aton domain) (Sort.gno range))) ; + (z3obj_create res) ; + FuncDecl(res) + + let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Sort.aton domain) (Sort.gno range))) ; + (z3obj_create res) ; + FuncDecl(res) + + let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) + let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) + let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) + + let aton (a : func_decl array) = + let f (e : func_decl) = (gno e) in + Array.map f a + + (** Parameters of Func_Decls *) + module Parameter = + struct + type parameter = + | P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + (** The kind of the parameter. *) + let get_kind ( x : parameter ) = + (match x with + | P_Int(_) -> PARAMETER_INT + | P_Dbl(_) -> PARAMETER_DOUBLE + | P_Sym(_) -> PARAMETER_SYMBOL + | P_Srt(_) -> PARAMETER_SORT + | P_Ast(_) -> PARAMETER_AST + | P_Fdl(_) -> PARAMETER_FUNC_DECL + | P_Rat(_) -> PARAMETER_RATIONAL) + + (**The int value of the parameter.*) + let get_int ( x : parameter ) = + match x with + | P_Int(x) -> x + | _ -> raise (Z3native.Exception "parameter is not an int") + + (**The double value of the parameter.*) + let get_float ( x : parameter ) = + match x with + | P_Dbl(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a double") + + (**The Symbol value of the parameter.*) + let get_symbol ( x : parameter ) = + match x with + | P_Sym(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a symbol") + + (**The Sort value of the parameter.*) + let get_sort ( x : parameter ) = + match x with + | P_Srt(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a sort") + + (**The AST value of the parameter.*) + let get_ast ( x : parameter ) = + match x with + | P_Ast(x) -> x + | _ -> raise (Z3native.Exception "parameter is not an ast") + + (**The FunctionDeclaration value of the parameter.*) + let get_func_decl ( x : parameter ) = + match x with + | P_Fdl(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a func_decl") + + (**The rational string value of the parameter.*) + let get_func_decl ( x : parameter ) = + match x with + | P_Rat(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a rational string") + end + + open Parameter + + (** + Creates a new function declaration. + *) + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + create_ndr ctx name domain range + + (** + Creates a new function declaration. + *) + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = + mk_func_decl ctx (Symbol.mk_string ctx name) domain range + + (** + Creates a fresh function declaration with a name prefixed with . + + + *) + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + create_pdr ctx prefix domain range + + (** + Creates a new constant function declaration. + *) + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + create_ndr ctx name [||] range + + (** + Creates a new constant function declaration. + *) + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = + create_ndr ctx (Symbol.mk_string ctx name) [||] range + + (** + Creates a fresh constant function declaration with a name prefixed with . + + + *) + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = + create_pdr ctx prefix [||] range + + + (** + Comparison operator. + @param a A func_decl + @param b A func_decl + @return True if and are from the same context + and represent the same func_decl; false otherwise. + *) + let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || + if (gnc a) != (gnc b) then + false + else + (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) + + (** + A string representations of the function declaration. + *) + let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) + + (** + Returns a unique identifier for the function declaration. + *) + let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) + + (** + The arity of the function declaration + *) + let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) + + (** + The size of the domain of the function declaration + + *) + let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) + + (** + The domain of the function declaration + *) + let get_domain ( x : func_decl ) = + let n = (get_domain_size x) in + let f i = Sort.create (gc x) (Z3native.get_domain (gnc x) (gno x) i) in + Array.init n f + + (** + The range of the function declaration + *) + let get_range ( x : func_decl ) = + Sort.create (gc x) (Z3native.get_range (gnc x) (gno x)) + + (** + The kind of the function declaration. + *) + let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) + + (** + The name of the function declaration + *) + let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) + + (** + The number of parameters of the function declaration + *) + let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) + + (** + The parameters of the function declaration + *) + let get_parameters ( x : func_decl ) = + let n = (get_num_parameters x) in + let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with + | PARAMETER_INT -> P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> P_Srt (Sort.create (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> P_Ast (AST.create (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> P_Fdl (create (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + ) in + mk_list f n + + (** + Create expression that applies function to arguments. + @param args The arguments + *) + let apply ( x : func_decl ) ( args : Expr.expr array ) = Expr.create_fa (gc x) x args +end + (** Parameter sets (of Solvers, Tactics, ...) A Params objects represents a configuration in the form of symbol/value pairs. *) -module Params = -struct +and Params : +sig + type params = z3_native_object + + val create : context -> Z3native.ptr -> params + + module ParamDescrs : sig + type param_descrs = z3_native_object + + val create : context -> Z3native.ptr -> param_descrs + end +end = struct type params = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : params = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.params_inc_ref ; dec_ref = Z3native.params_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) - module ParamDescrs = - struct + module ParamDescrs : + sig + type param_descrs = z3_native_object + + val create : context -> Z3native.ptr -> param_descrs + end = struct type param_descrs = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : param_descrs = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.param_descrs_inc_ref ; dec_ref = Z3native.param_descrs_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -1449,7 +1065,6 @@ struct *) let add_s_double ( x : params ) ( name : string ) ( value : float ) = add_double x (Symbol.mk_string (z3obj_gc x) name) value - (** Adds a parameter setting. *) @@ -1460,7 +1075,7 @@ struct Creates a new parameter set *) let mk_params ( ctx : context ) = - cnstr ctx (Z3native.mk_params (context_gno ctx)) + create ctx (Z3native.mk_params (context_gno ctx)) (** A string representation of the parameter set. @@ -1468,18 +1083,69 @@ struct let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) end - (** General expressions (terms), including Boolean logic *) -module Expr = -struct +and Expr : +sig + type expr = Expr of AST.ast + + val create : context -> Z3native.ptr -> expr + val create_fa : context -> FuncDecl.func_decl -> expr array -> expr + val gc : expr -> context + val gno : expr -> Z3native.ptr + val gnc : expr -> Z3native.ptr + val aton : expr array -> Z3native.ptr array + + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + val get_func_decl : expr -> FuncDecl.func_decl +end = struct + type expr = Expr of AST.ast + + let create ( ctx : context ) ( obj : Z3native.ptr ) = + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then + (match (Quantifiers.create ctx obj) with Quantifiers.Quantifier(e) -> e) + else + let s = Z3native.get_sort (context_gno ctx) obj in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) obj) then + (match (Arithmetic.create_algebraic_num ctx obj) with Arithmetic.AlgebraicNum(Arithmetic.Expr(e)) -> e) + else + if (Z3native.is_numeral_ast (context_gno ctx) obj) && + (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + match sk with + | INT_SORT -> (match (Arithmetic.create_int_num ctx obj) with Arithmetic.IntNum(Arithmetic.IntExpr(Arithmetic.Expr(e))) -> e) + | REAL_SORT -> (match (Arithmetic.create_rat_num ctx obj) with Arithmetic.RatNum(Arithmetic.RealExpr(Arithmetic.Expr(e))) -> e) + | BV_SORT -> (match (BitVectors.create_num ctx obj) with BitVectors.BitVecNum(BitVectors.BitVecExpr(e)) -> e) + | _ -> raise (Z3native.Exception "Unsupported numeral object") + else + match sk with + | BOOL_SORT -> (match (Booleans.create ctx obj) with Booleans.BoolExpr(e) -> e) + | INT_SORT -> (match (Arithmetic.create_int_expr ctx obj) with Arithmetic.IntExpr(Arithmetic.Expr(e)) -> e) + | REAL_SORT -> (match (Arithmetic.create_real_expr ctx obj) with Arithmetic.RealExpr(Arithmetic.Expr(e)) -> e) + | BV_SORT -> (match (BitVectors.create_expr ctx obj) with BitVectors.BitVecExpr(e) -> e) + | ARRAY_SORT -> (match (Arrays.create_expr ctx obj) with Arrays.ArrayExpr(e) -> e) + | DATATYPE_SORT -> (match (Datatypes.create_expr ctx obj) with Datatypes.DatatypeExpr(e) -> e) + | _ -> Expr(AST.create ctx obj) + + let aton ( a : expr array ) = + let f ( e : expr ) = match e with Expr(a) -> (z3obj_gno a) in + Array.map f a + + let create_fa ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = + let o = Z3native.mk_app (context_gno ctx) (FuncDecl.gno f) (Array.length args) (aton args) in + Expr.create ctx o + + let gc ( x : expr ) = match x with Expr(a) -> (z3obj_gc a) + let gnc ( x : expr ) = match x with Expr(a) -> (z3obj_gnc a) + let gno ( x : expr ) = match x with Expr(a) -> (z3obj_gno a) + (** Returns a simplified version of the expression. @param p A set of parameters to configure the simplifier *) let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) - | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno (z3obj_gno pp)) + | None -> Expr.create (gc x) (Z3native.simplify (gnc x) (gno x)) + | Some pp -> Expr.create (gc x) (Z3native.simplify_ex (gnc x) (gno x) (z3obj_gno pp)) (** a string describing all available parameters to Expr.Simplify. @@ -1491,29 +1157,29 @@ struct Retrieves parameter descriptions for simplifier. *) let get_simplify_parameter_descrs ( ctx : context ) = - Params.ParamDescrs.cnstr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) + Params.ParamDescrs.create ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. *) - let get_func_decl ( x : expr ) = (new func_decl x#gc)#cnstr_obj (Z3native.get_app_decl x#gnc x#gno) + let get_func_decl ( x : expr ) = FuncDecl.create (gc x) (Z3native.get_app_decl (gnc x) (gno x)) (** Indicates whether the expression is the true or false expression or something else (L_UNDEF). *) - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value x#gnc x#gno) + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) (** The number of arguments of the expression. *) - let get_num_args ( x : expr ) = Z3native.get_app_num_args x#gnc x#gno + let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) (** The arguments of the expression. *) let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = create_expr x#gc (Z3native.get_app_arg x#gnc x#gno i) in + let f i = create (gc x) (Z3native.get_app_arg (gnc x) (gno x) i) in Array.init n f (** @@ -1524,7 +1190,7 @@ struct if (Array.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - x#sno x#gc (Z3native.update_term x#gnc x#gno (Array.length args) (expraton args)) + create (gc x) (Z3native.update_term (gnc x) (gno x) (Array.length args) (aton args)) (** Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. @@ -1537,7 +1203,7 @@ struct if (Array.length from) <> (Array.length to_) then raise (Z3native.Exception "Argument sizes do not match") else - create_expr x#gc (Z3native.substitute x#gnc x#gno (Array.length from) (expraton from) (expraton to_)) + create (gc x) (Z3native.substitute (gnc x) (gno x) (Array.length from) (aton from) (aton to_)) (** Substitute every occurrence of from in the expression with to. @@ -1552,7 +1218,7 @@ struct For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) let substitute_vars ( x : expr ) to_ = - create_expr x#gc (Z3native.substitute_vars x#gnc x#gno (Array.length to_) (expraton to_)) + create (gc x) (Z3native.substitute_vars (gnc x) (gno x) (Array.length to_) (aton to_)) (** @@ -1561,46 +1227,46 @@ struct @return A copy of the term which is associated with *) let translate ( x : expr ) to_ctx = - if x#gc == to_ctx then + if (gc x) == to_ctx then x else - create_expr to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx)) + create to_ctx (Z3native.translate (gnc x) (gno x) (context_gno to_ctx)) (** Returns a string representation of the expression. *) - let to_string ( x : expr ) = Z3native.ast_to_string x#gnc x#gno + let to_string ( x : expr ) = Z3native.ast_to_string (gnc x) (gno x) (** Indicates whether the term is a numeral *) - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast x#gnc x#gno) + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (gnc x) (gno x)) (** Indicates whether the term is well-sorted. @return True if the term is well-sorted, false otherwise. *) - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted x#gnc x#gno + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) (** The Sort of the term. *) - let get_sort ( x : expr ) = create_sort x#gc (Z3native.get_sort x#gnc x#gno) + let get_sort ( x : expr ) = Sort.create (gc x) (Z3native.get_sort (gnc x) (gno x)) (** Indicates whether the term has Boolean sort. *) - let is_bool ( x : expr ) = (AST.is_expr x) && - (Z3native.is_eq_sort x#gnc - (Z3native.mk_bool_sort x#gnc) - (Z3native.get_sort x#gnc x#gno)) - + let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + (Z3native.is_eq_sort (gnc x) + (Z3native.mk_bool_sort (gnc x)) + (Z3native.get_sort (gnc x) (gno x))) + (** Indicates whether the term represents a constant. *) - let is_const ( x : expr ) = (AST.is_expr x) && + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && (get_num_args x) == 0 && - FuncDecl.get_domain_size(get_func_decl x) == 0 + (FuncDecl.get_domain_size (get_func_decl x)) == 0 (** Indicates whether the term is the constant true. @@ -1679,123 +1345,36 @@ struct (** Creates a new Constant of sort and named . *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - create_expr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) range#gno) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : Sort.sort ) = + create ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) (** Creates a new Constant of sort and named . *) - let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = - mk_const ctx (Symbol.mk_string ctx name)range + let mk_const_s ( ctx : context ) ( name : string ) ( range : Sort.sort ) = + mk_const ctx (Symbol.mk_string ctx name) range (** Creates a constant from the func_decl . @param f An expression of a 0-arity function *) - let mk_const_f ( ctx : context ) ( f : func_decl ) = - create_expr_fa ctx f [||] + let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = + create_fa ctx f [||] (** Creates a fresh constant of sort and a name prefixed with . *) - let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort) = - create_expr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix range#gno) - - (** - Create a Boolean constant. - *) - let mk_bool_const ( ctx : context ) ( name : Symbol.symbol ) = - ((mk_const ctx name (Sort.mk_bool ctx)) :> bool_expr) - - (** - Create a Boolean constant. - *) - let mk_bool_const_s ( ctx : context ) ( name : string ) = - mk_bool_const ctx (Symbol.mk_string ctx name) + let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : Sort.sort ) = + create ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) (** Create a new function application. *) - let mk_app ( ctx : context ) ( f : func_decl ) ( args : expr array ) = - create_expr_fa ctx f args - - (** - The true Term. - *) - let mk_true ( ctx : context ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_true (context_gno ctx)) - - (** - The false Term. - *) - let mk_false ( ctx : context ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_false (context_gno ctx)) - - (** - Creates a Boolean value. - *) - let mk_bool ( ctx : context ) ( value : bool) = - if value then mk_true ctx else mk_false ctx - - (** - Creates the equality = . - *) - let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_eq (context_gno ctx) x#gno y#gno) - - (** - Creates a distinct term. - *) - let mk_distinct ( ctx : context ) ( args : expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_distinct (context_gno ctx) (Array.length args) (astaton args)) - - (** - Mk an expression representing not(a). - *) - let mk_not ( ctx : context ) ( a : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_not (context_gno ctx) a#gno) - - (** - Create an expression representing an if-then-else: ite(t1, t2, t3). - @param t1 An expression with Boolean sort - @param t2 An expression - @param t3 An expression with the same sort as - *) - let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - create_expr ctx (Z3native.mk_ite (context_gno ctx) t1#gno t2#gno t3#gno) - - (** - Create an expression representing t1 iff t2. - *) - let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_iff (context_gno ctx) t1#gno t2#gno) - - (** - Create an expression representing t1 -> t2. - *) - let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_implies (context_gno ctx) t1#gno t2#gno) - - (** - Create an expression representing t1 xor t2. - *) - let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_xor (context_gno ctx) t1#gno t2#gno) - - (** - Create an expression representing the AND of args - *) - let mk_and ( ctx : context ) ( args : bool_expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_and (context_gno ctx) (Array.length args) (astaton args)) - - (** - Create an expression representing the OR of args - *) - let mk_or ( ctx : context ) ( args : bool_expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_or (context_gno ctx) (Array.length args) (astaton args)) + let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = + create_fa ctx f args (** Create a numeral of a given sort. @@ -1803,8 +1382,8 @@ struct @param ty 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 *) - let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = - create_expr ctx (Z3native.mk_numeral (context_gno ctx) v ty#gno) + let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : Sort.sort ) = + create ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) (** Create a numeral of a given sort. This function can be use to create numerals that fit in a machine integer. @@ -1813,13 +1392,147 @@ struct @param ty Sort of the numeral @return A Term with value and type *) - let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_int (context_gno ctx) v ty#gno) + let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : Sort.sort ) = + create ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) + + let aton (a : expr array) = + let f (e : expr) = (gno e) in + Array.map f a +end + +(** Boolean expressions *) +and Booleans : +sig + type bool_expr = BoolExpr of Expr.expr + type bool_sort = BoolSort of Sort.sort + + val create : context -> Z3native.ptr -> bool_expr + val aton : bool_expr array -> Z3native.ptr array +end = struct + type bool_expr = BoolExpr of Expr.expr + type bool_sort = BoolSort of Sort.sort + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let a = (AST.create ctx no) in + BoolExpr(Expr.Expr(a)) + + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gc e) + let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gnc e) + let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gno e) + + let aton ( a : bool_expr array ) = + let f (e : bool_expr) = (gno e) in + Array.map f a + + let mk_sort ( ctx : context ) = + BoolSort(Sort.create ctx (Z3native.mk_bool_sort (context_gno ctx))) + + (** + Create a Boolean constant. + *) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = + let s = (match (mk_sort ctx) with BoolSort(q) -> q) in + BoolExpr(Expr.mk_const ctx name s) + + (** + Create a Boolean constant. + *) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) + + (** + The true Term. + *) + let mk_true ( ctx : context ) = + create ctx (Z3native.mk_true (context_gno ctx)) + + (** + The false Term. + *) + let mk_false ( ctx : context ) = + create ctx (Z3native.mk_false (context_gno ctx)) + + (** + Creates a Boolean value. + *) + let mk_val ( ctx : context ) ( value : bool ) = + if value then mk_true ctx else mk_false ctx + + (** + Creates the equality = . + *) + let mk_eq ( ctx : context ) ( x : Expr.expr ) ( y : Expr.expr ) = + create ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + + (** + Creates a distinct term. + *) + let mk_distinct ( ctx : context ) ( args : Expr.expr array ) = + create ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (Expr.aton args)) + + (** + Mk an expression representing not(a). + *) + let mk_not ( ctx : context ) ( a : bool_expr ) = + create ctx (Z3native.mk_not (context_gno ctx) (gno a)) + + (** + Create an expression representing an if-then-else: ite(t1, t2, t3). + @param t1 An expression with Boolean sort + @param t2 An expression + @param t3 An expression with the same sort as + *) + let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = + create ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + + (** + Create an expression representing t1 iff t2. + *) + let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + create ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + + (** + Create an expression representing t1 -> t2. + *) + let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + create ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + (** + Create an expression representing t1 xor t2. + *) + let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + create ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + + (** + Create an expression representing the AND of args + *) + let mk_and ( ctx : context ) ( args : bool_expr array ) = + create ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (aton args)) + + (** + Create an expression representing the OR of args + *) + let mk_or ( ctx : context ) ( args : bool_expr array ) = + create ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (aton args)) end (** Quantifier expressions *) -module Quantifiers = -struct +and Quantifiers : +sig + type quantifier = Quantifier of Expr.expr + + val create : context -> Z3native.ptr -> quantifier +end = struct + type quantifier = Quantifier of Expr.expr + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let a = (AST.create ctx no) in + Quantifier(Expr.Expr(a)) + + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) + let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) + let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) + + (** The de-Burijn index of a bound variable. @@ -1838,11 +1551,11 @@ struct on the scope in which it appears. The deeper ( x : expr ) appears, the higher is its index. *) - let get_index ( x : expr ) = - if not (AST.is_var x) then + let get_index ( x : Expr.expr ) = + if not (AST.is_var (match x with Expr.Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else - Z3native.get_index_value x#gnc x#gno + Z3native.get_index_value (Expr.gnc x) (Expr.gno x) (** Quantifier patterns @@ -1850,33 +1563,57 @@ struct non-empty. If the list comprises of more than one term, it is also called a multi-pattern. *) - module Pattern = - struct + module Patterns : + sig + type pattern = Pattern of AST.ast + + val create : context -> Z3native.ptr -> pattern + val aton : pattern array -> Z3native.ptr array + end = struct + type pattern = Pattern of AST.ast + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + Pattern(res) + + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) + let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) + let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) + (** The number of terms in the pattern. *) let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms x#gnc x#gno + Z3native.get_pattern_num_terms (gnc x) (gno x) (** The terms in the pattern. *) let get_terms ( x : pattern ) = let n = (get_num_terms x) in - let f i = (create_expr x#gc (Z3native.get_pattern x#gnc x#gno i)) in + let f i = (Expr.create (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in Array.init n f (** A string representation of the pattern. *) - let to_string ( x : pattern ) = Z3native.pattern_to_string x#gnc x#gno + let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) + + let aton (a : pattern array) = + let f (e : pattern) = (gno e) in + Array.map f a end (** Indicates whether the quantifier is universal. *) let is_universal ( x : quantifier ) = - Z3native.is_quantifier_forall x#gnc x#gno + Z3native.is_quantifier_forall (gnc x) (gno x) (** Indicates whether the quantifier is existential. @@ -1886,45 +1623,45 @@ struct (** The weight of the quantifier. *) - let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight x#gnc x#gno + let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) (** The number of patterns. *) - let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns x#gnc x#gno + let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) (** The patterns. *) let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_pattern_ast x#gnc x#gno i)) in + let f i = (Patterns.create (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** The number of no-patterns. *) - let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns x#gnc x#gno + let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) (** The no-patterns. *) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_no_pattern_ast x#gnc x#gno i)) in + let f i = (Patterns.create (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** The number of bound variables. *) - let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound x#gnc x#gno + let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) (** The symbols for the bound variables. *) let get_bound_variable_names ( x : quantifier ) = let n = (get_num_bound x) in - let f i = (Symbol.create x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in + let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in Array.init n f (** @@ -1932,31 +1669,31 @@ struct *) let get_bound_variable_sorts ( x : quantifier ) = let n = (get_num_bound x) in - let f i = (create_sort x#gc (Z3native.get_quantifier_bound_sort x#gnc x#gno i)) in + let f i = (Sort.create (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in Array.init n f (** The body of the quantifier. *) let get_body ( x : quantifier ) = - (new bool_expr x#gc)#cnstr_obj (Z3native.get_quantifier_body x#gnc x#gno) + Booleans.create (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) (** Creates a new bound variable. @param index The de-Bruijn index of the variable @param ty The sort of the variable *) - let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_bound (context_gno ctx) index ty#gno) + let mk_bound ( ctx : context ) ( index : int ) ( ty : Sort.sort ) = + Expr.create ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) (** Create a quantifier pattern. *) - let mk_pattern ( ctx : context ) ( terms : expr array ) = + let mk_pattern ( ctx : context ) ( terms : Expr.expr array ) = if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - (new pattern ctx)#cnstr_obj (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (astaton terms)) + Patterns.create ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (Expr.aton terms)) (** Create a universal Quantifier. @@ -1977,95 +1714,96 @@ struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_forall ( ctx : context ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (patternaton patterns) - (Array.length sorts) (astaton sorts) - (Symbol.aton names) - body#gno) + create ctx (Z3native.mk_quantifier (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (Array.length patterns) (Patterns.aton patterns) + (Array.length sorts) (Sort.aton sorts) + (Symbol.aton names) + (Expr.gno body)) else - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (patternaton patterns) - (Array.length nopatterns) (patternaton nopatterns) - (Array.length sorts) (astaton sorts) - (Symbol.aton names) - body#gno) + create ctx (Z3native.mk_quantifier_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length patterns) (Patterns.aton patterns) + (Array.length nopatterns) (Expr.aton nopatterns) + (Array.length sorts) (Sort.aton sorts) + (Symbol.aton names) + (Expr.gno body)) (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_forall_const ( ctx : context ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (expraton bound_constants) - (Array.length patterns) (patternaton patterns) - body#gno) + create ctx (Z3native.mk_quantifier_const (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (Expr.aton bound_constants) + (Array.length patterns) (Patterns.aton patterns) + (Expr.gno body)) else - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (expraton bound_constants) - (Array.length patterns) (patternaton patterns) - (Array.length nopatterns) (patternaton nopatterns) - body#gno) + create ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length bound_constants) (Expr.aton bound_constants) + (Array.length patterns) (Patterns.aton patterns) + (Array.length nopatterns) (Expr.aton nopatterns) + (Expr.gno body)) + (** Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_exists ( ctx : context ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (patternaton patterns) - (Array.length sorts) (astaton sorts) - (Symbol.aton names) - body#gno) + create ctx (Z3native.mk_quantifier (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (Array.length patterns) (Patterns.aton patterns) + (Array.length sorts) (Sort.aton sorts) + (Symbol.aton names) + (Expr.gno body)) else - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (patternaton patterns) - (Array.length nopatterns) (patternaton nopatterns) - (Array.length sorts) (astaton sorts) - (Symbol.aton names) - body#gno) - + create ctx (Z3native.mk_quantifier_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length patterns) (Patterns.aton patterns) + (Array.length nopatterns) (Expr.aton nopatterns) + (Array.length sorts) (Sort.aton sorts) + (Symbol.aton names) + (Expr.gno body)) + (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_exists_const ( ctx : context ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (expraton bound_constants) - (Array.length patterns) (patternaton patterns) - body#gno) + create ctx (Z3native.mk_quantifier_const (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (Expr.aton bound_constants) + (Array.length patterns) (Patterns.aton patterns) + (Expr.gno body)) else - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (expraton bound_constants) - (Array.length patterns) (patternaton patterns) - (Array.length nopatterns) (patternaton nopatterns) - body#gno) + create ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length bound_constants) (Expr.aton bound_constants) + (Array.length patterns) (Patterns.aton patterns) + (Array.length nopatterns) (Expr.aton nopatterns) + (Expr.gno body)) (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -2075,7 +1813,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -2083,75 +1821,104 @@ struct end (** Functions to manipulate Array expressions *) -module Arrays = -struct +and Arrays : +sig + type array_expr = ArrayExpr of Expr.expr + type array_sort = ArraySort of Sort.sort + + val create_expr : context -> Z3native.ptr -> array_expr +end = struct + type array_expr = ArrayExpr of Expr.expr + type array_sort = ArraySort of Sort.sort + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let e = (Expr.create ctx no) in + ArrayExpr(e) + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + ArraySort(s) + + let sgc ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gc s) + let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gnc s) + let sgno ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gno s) + + let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gc e) + let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gnc e) + let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gno e) + + let aton (a : array_expr array) = + let f (e : array_expr) = (egno e) in + Array.map f a + + (** Create a new array sort. *) - let mk_sort ( ctx : context ) domain range = - (new array_sort ctx)#cnstr_dr domain range + let mk_sort ( ctx : context ) ( domain : Sort.sort ) ( range : Sort.sort ) = + create_sort ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) (** 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. *) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) + let is_store ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) (** Indicates whether the term is an array select. *) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) + let is_select ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) + let is_constant_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) (** Indicates whether the term is a default array. For example default(const(v)) = v. The function is unary. *) - let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) + let is_default_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) + let is_array_map ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + let is_as_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) (** Indicates whether the term is of an array sort. *) - let is_array ( x : expr ) = - (Z3native.is_app x#gnc x#gno) && - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + let is_array ( x : Expr.expr ) = + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) (** The domain of the array sort. *) - let get_domain (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_domain x#gnc x#gno) + let get_domain ( x : array_sort ) = Sort.create (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) (** The range of the array sort. *) - let get_range (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_range x#gnc x#gno) + let get_range ( x : array_sort ) = Sort.create (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) (** Create an array constant. *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = - ((Expr.mk_const ctx name ((mk_sort ctx domain range) :> sort)) :> array_expr) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort ) ( range : Sort.sort ) = + ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) (** Create an array constant. *) - let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = + let mk_const_s ( ctx : context ) ( name : string ) ( domain : Sort.sort ) ( range : Sort.sort ) = mk_const ctx (Symbol.mk_string ctx name) domain range (** @@ -2166,8 +1933,8 @@ struct *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - ((create_expr ctx (Z3native.mk_select (context_gno ctx) a#gno i#gno)) :> array_expr) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : Expr.expr ) = + create_expr ctx (Z3native.mk_select (context_gno ctx) (egno a) (Expr.gno i)) (** Array update. @@ -2185,8 +1952,8 @@ struct *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr) = - (new array_expr ctx)#cnstr_obj (Z3native.mk_store (context_gno ctx) a#gno i#gno v#gno) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : Expr.expr ) ( v : Expr.expr ) = + create_expr ctx (Z3native.mk_store (context_gno ctx) (egno a) (Expr.gno i) (Expr.gno v)) (** Create a constant array. @@ -2196,8 +1963,8 @@ struct *) - let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - (new array_expr ctx)#cnstr_obj (Z3native.mk_const_array (context_gno ctx) domain#gno v#gno) + let mk_const_array ( ctx : context ) ( domain : Sort.sort ) ( v : Expr.expr ) = + create_expr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) (** Maps f on the argument arrays. @@ -2209,8 +1976,8 @@ struct *) - let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = - ((create_expr ctx (Z3native.mk_map (context_gno ctx) f#gno (Array.length args) (astaton args))) :> array_expr) + let mk_map ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : array_expr array ) = + create_expr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (aton args)) (** Access the array default value. @@ -2219,149 +1986,184 @@ struct finite maps with a default range value. *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = - ((create_expr ctx (Z3native.mk_array_default (context_gno ctx) arg#gno)) :> array_expr) + create_expr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) end (** Functions to manipulate Set expressions *) -module Sets = -struct +and Sets : +sig + type set_sort = SetSort of Sort.sort + +end = struct + type set_sort = SetSort of Sort.sort + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + SetSort(s) + (** Indicates whether the term is set union *) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_union ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) (** Indicates whether the term is set intersection *) - let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_intersect ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) (** Indicates whether the term is set difference *) - let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_difference ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) (** Indicates whether the term is set complement *) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_complement ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) (** Indicates whether the term is set subset *) - let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + let is_subset ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) (** Create a set type. *) - let mk_sort ( ctx : context ) ( ty : sort) = - (new set_sort ctx)#cnstr_s ty + let mk_sort ( ctx : context ) ( ty : Sort.sort ) = + create_sort ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) (** Create an empty set. *) - let mk_empty ( ctx : context ) ( domain : sort ) = - (create_expr ctx (Z3native.mk_empty_set (context_gno ctx) domain#gno)) + let mk_empty ( ctx : context ) ( domain : Sort.sort ) = + (Expr.create ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) (** Create the full set. *) - let mk_full ( ctx : context ) ( domain : sort ) = - create_expr ctx (Z3native.mk_full_set (context_gno ctx) domain#gno) + let mk_full ( ctx : context ) ( domain : Sort.sort ) = + Expr.create ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) (** Add an element to the set. *) - let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_add (context_gno ctx) set#gno element#gno) + let mk_set_add ( ctx : context ) ( set : Expr.expr ) ( element : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) (** Remove an element from a set. *) - let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_del (context_gno ctx) set#gno element#gno) + let mk_del ( ctx : context ) ( set : Expr.expr ) ( element : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) (** Take the union of a list of sets. *) - let mk_union ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (astaton args)) + let mk_union ( ctx : context ) ( args : Expr.expr array ) = + Expr.create ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (Expr.aton args)) (** Take the intersection of a list of sets. *) - let mk_intersection ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (astaton args)) + let mk_intersection ( ctx : context ) ( args : Expr.expr array ) = + Expr.create ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (Expr.aton args)) (** Take the difference between two sets. *) - let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_difference (context_gno ctx) arg1#gno arg2#gno) + let mk_difference ( ctx : context ) ( arg1 : Expr.expr ) ( arg2 : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) (** Take the complement of a set. *) - let mk_complement ( ctx : context ) ( arg : expr ) = - create_expr ctx (Z3native.mk_set_complement (context_gno ctx) arg#gno) + let mk_complement ( ctx : context ) ( arg : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) (** Check for set membership. *) - let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - create_expr ctx (Z3native.mk_set_member (context_gno ctx) elem#gno set#gno) + let mk_membership ( ctx : context ) ( elem : Expr.expr ) ( set : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) (** Check for subsetness of sets. *) - let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_subset (context_gno ctx) arg1#gno arg2#gno) + let mk_subset ( ctx : context ) ( arg1 : Expr.expr ) ( arg2 : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) end (** Functions to manipulate Finite Domain expressions *) -module FiniteDomains = -struct - (** - Create a new finite domain sort. - *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) size = - (new finite_domain_sort ctx)#cnstr_si name size +and FiniteDomains : +sig + type finite_domain_sort = FiniteDomainSort of Sort.sort + +end = struct + type finite_domain_sort = FiniteDomainSort of Sort.sort + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + FiniteDomainSort(s) + + let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gc s) + let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gnc s) + let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s))-> (z3obj_gno s) (** Create a new finite domain sort. *) - let mk_sort_s ( ctx : context ) ( name : string ) size = - (new finite_domain_sort ctx)#cnstr_si (Symbol.mk_string ctx name) size + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + create_sort ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size) + + (** + Create a new finite domain sort. + *) + let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = + mk_sort ctx (Symbol.mk_string ctx name) size (** Indicates whether the term is of an array sort. *) - let is_finite_domain ( x : expr ) = - (Z3native.is_app x#gnc x#gno) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) + let is_finite_domain ( x : Expr.expr ) = + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) == FINITE_DOMAIN_SORT) (** Indicates whether the term is a less than predicate over a finite domain. *) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + let is_lt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) (** The size of the finite domain sort. *) - let get_size (x : finite_domain_sort) = - let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in + let get_size ( x : finite_domain_sort ) = + let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in if r then v else raise (Z3native.Exception "Conversion failed.") end (** Functions to manipulate Relation expressions *) -module Relations = -struct +and Relations : +sig + type relation_sort = RelationSort of Sort.sort + +end = struct + type relation_sort = RelationSort of Sort.sort + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + RelationSort(s) + + let gc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gc s) + let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gnc s) + let gno ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s))-> (z3obj_gno s) + (** Indicates whether the term is of a relation sort. *) - let is_relation ( x : expr ) = - ((Z3native.is_app x#gnc x#gno) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT)) + let is_relation ( x : Expr.expr ) = + ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) == RELATION_SORT)) (** Indicates whether the term is an relation store @@ -2370,40 +2172,40 @@ struct 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. *) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + let is_store ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) (** Indicates whether the term is an empty relation *) - let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + let is_empty ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) (** Indicates whether the term is a test for the emptiness of a relation *) - let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + let is_is_empty ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) (** Indicates whether the term is a relational join *) - let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + let is_join ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) (** Indicates whether the term is the union or convex hull of two relations. The function takes two arguments. *) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + let is_union ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) (** Indicates whether the term is the widening of two relations The function takes two arguments. *) - let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + let is_widen ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). The function takes one argument. *) - let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) + let is_project ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) (** Indicates whether the term is a relation filter @@ -2414,7 +2216,7 @@ struct corresponding to the columns of the relation. So the first column in the relation has index 0. *) - let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) + let is_filter ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) (** Indicates whether the term is an intersection of a relation with the negation of another. @@ -2429,7 +2231,7 @@ struct target are elements in ( x : expr ) in pos, such that there is no y in neg that agrees with ( x : expr ) on the columns c1, d1, .., cN, dN. *) - let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) + let is_negation_filter ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) (** Indicates whether the term is the renaming of a column in a relation @@ -2437,12 +2239,12 @@ struct The function takes one argument. The parameters contain the renaming as a cycle. *) - let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + let is_rename ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) (** Indicates whether the term is the complement of a relation *) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) + let is_complement ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) (** Indicates whether the term is a relational select @@ -2451,7 +2253,7 @@ struct The function takes n+1 arguments, where the first argument is a relation, and the remaining n arguments correspond to a record. *) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) + let is_select ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) (** Indicates whether the term is a relational clone (copy) @@ -2462,38 +2264,153 @@ struct for terms of kind to perform destructive updates to the first argument. *) - let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + let is_clone ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) (** The arity of the relation sort. *) - let get_arity (x : relation_sort) = Z3native.get_relation_arity x#gnc x#gno + let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) (** The sorts of the columns of the relation sort. *) - let get_column_sorts (x : relation_sort) = + let get_column_sorts ( x : relation_sort ) = let n = get_arity x in - let f i = create_sort x#gc (Z3native.get_relation_column x#gnc x#gno i) in + let f i = (create_sort (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in Array.init n f end (** Functions to manipulate Datatype expressions *) -module Datatypes = -struct +and Datatypes : +sig + type datatype_expr = DatatypeExpr of Expr.expr + type datatype_sort = DatatypeSort of Sort.sort + + val create_expr : context -> Z3native.ptr -> datatype_expr +end = struct + type datatype_expr = DatatypeExpr of Expr.expr + type datatype_sort = DatatypeSort of Sort.sort + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let e = (Expr.create ctx no) in + DatatypeExpr(e) + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + DatatypeSort(s) + + let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gc s) + let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gnc s) + let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s))-> (z3obj_gno s) + + (** Constructors *) module Constructor = struct + type constructor_extra = { + m_n : int; + mutable m_tester_decl : FuncDecl.func_decl option; + mutable m_constructor_decl : FuncDecl.func_decl option ; + mutable m_accessor_decls : FuncDecl.func_decl array option} + type constructor = Constructor of (z3_native_object * constructor_extra) + + let create_ssssi ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = + let n = (Array.length field_names) in + if n != (Array.length sorts) then + raise (Z3native.Exception "Number of field names does not match number of sorts") + else + if n != (Array.length sort_refs) then + raise (Z3native.Exception "Number of field names does not match number of sort refs") + else + let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) + (Symbol.gno recognizer) + n + (Symbol.aton field_names) + (Sort.aton sorts) + sort_refs) in + let no : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + let ex : constructor_extra = { m_n = n; + m_tester_decl = None; + m_constructor_decl = None; + m_accessor_decls = None} in + (z3obj_sno no ctx ptr) ; + (z3obj_create no) ; + let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in + Gc.finalise f no ; + Constructor(no, ex) + + let init_extra ( x : constructor ) = + match x with Constructor(no, ex) -> + match ex.m_tester_decl with + | None -> + let (a, b, c) = (Z3native.query_constructor (z3obj_gnc no) (z3obj_gno no) ex.m_n) in + ex.m_constructor_decl <- Some (FuncDecl.create (z3obj_gc no) a) ; + ex.m_tester_decl <- Some (FuncDecl.create (z3obj_gc no) b) ; + ex.m_accessor_decls <- Some (let f e = (FuncDecl.create (z3obj_gc no) e) in Array.map f c) ; + () + | _ -> () + + let get_n ( x : constructor ) = + match x with Constructor(no, ex) -> + ex.m_n + + let rec tester_decl ( x : constructor ) = + match x with Constructor(no, ex) -> + match ex.m_tester_decl with + | Some(s) -> s + | None -> init_extra x ; tester_decl x + + let rec constructor_decl ( x : constructor ) = + match x with Constructor(no, ex) -> + match ex.m_constructor_decl with + | Some(s) -> s + | None -> init_extra x ; constructor_decl x + + let rec accessor_decls ( x : constructor ) = + match x with Constructor(no, ex) -> + match ex.m_accessor_decls with + | Some(s) -> s + | None -> init_extra x ; accessor_decls x + + let aton ( a : constructor array ) = + let f (e : constructor) = match e with Constructor(no, ex) -> (z3obj_gno no)in + Array.map f a + + (** The number of fields of the constructor. *) - let get_num_fields ( x : constructor ) = x#get_n + let get_num_fields ( x : constructor ) = get_n x (** The function declaration of the constructor. *) - let get_constructor_decl ( x : constructor ) = x#constructor_decl + let get_constructor_decl ( x : constructor ) = constructor_decl x (** The function declaration of the tester. *) - let get_tester_decl ( x : constructor ) = x#tester_decl + let get_tester_decl ( x : constructor ) = tester_decl x (** The function declarations of the accessors *) - let get_accessor_decls ( x : constructor ) = x#accessor_decls + let get_accessor_decls ( x : constructor ) = accessor_decls x end + (** Constructor list objects *) + module ConstructorList = + struct + type constructor_list = z3_native_object + + let create ( ctx : context )( c : Constructor.constructor array ) = + let res : constructor_list = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Constructor.aton c))) ; + (z3obj_create res) ; + let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in + Gc.finalise f res; + res + + let aton (a : constructor_list array) = + let f (e : constructor_list) = (z3obj_gno e) in + Array.map f a + end + (* DATATYPES *) (** Create a datatype constructor. @@ -2505,8 +2422,8 @@ struct 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. *) - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array) = - (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array) = + Constructor.create_ssssi ctx name recognizer field_names sorts sort_refs (** @@ -2519,20 +2436,21 @@ struct 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. *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : constructor array) = - (new datatype_sort ctx)#cnstr_sc name constructors + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array) = + let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Constructor.aton constructors)) in + create_sort ctx x (** Create a new datatype sort. *) - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = mk_sort ctx (Symbol.mk_string ctx name) constructors (** @@ -2540,16 +2458,16 @@ struct @param names names of datatype sorts @param c list of constructors, one list per sort. *) - let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : constructor array array ) = + let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = let n = (Array.length names) in - let f e = ( (new constructor_list ctx)#cnstr_ca e ) in + let f e = (ConstructorList.create ctx e) in let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.aton names) (constructor_listaton cla)) in - let g e = ( (new datatype_sort ctx)#cnstr_obj e) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.aton names) (ConstructorList.aton cla)) in + let g e = (create_sort ctx e) in (Array.map g r) (** Create mutually recursive data-types. *) - let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = + let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = mk_sorts ctx ( let f e = (Symbol.mk_string ctx e) in @@ -2558,130 +2476,230 @@ struct c (** The number of constructors of the datatype sort. *) - let get_num_constructors (x : datatype_sort) = Z3native.get_datatype_sort_num_constructors x#gnc x#gno + let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) (** The range of the array sort. *) - let get_constructors (x : datatype_sort) = + let get_constructors ( x : datatype_sort ) = let n = (get_num_constructors x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i) in + let f i = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in Array.init n f (** The recognizers. *) - let get_recognizers (x : datatype_sort) = + let get_recognizers ( x : datatype_sort ) = let n = (get_num_constructors x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_recognizer x#gnc x#gno i) in + let f i = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in Array.init n f (** The constructor accessors. *) - let get_accessors (x : datatype_sort) = + let get_accessors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = ( - let fd = ((new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i)) in - let ds = (Z3native.get_domain_size fd#gnc fd#gno) in - let g j = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor_accessor x#gnc x#gno i j) in + let fd = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in + let g j = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in Array.init ds g ) in Array.init n f end (** Functions to manipulate Enumeration expressions *) -module Enumerations = -struct - (** - Create a new enumeration sort. - *) - let mk_sort ( ctx : context ) name enum_names = - (new enum_sort ctx)#cnstr_ss name enum_names +and Enumerations : +sig + type enum_sort_data + type enum_sort = EnumSort of (Sort.sort * enum_sort_data) +end = struct + type enum_sort_data = { mutable _constdecls : FuncDecl.func_decl array ; + mutable _testerdecls : FuncDecl.func_decl array } + type enum_sort = EnumSort of (Sort.sort * enum_sort_data) + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = + let s = (Sort.create ctx no) in + let e = { _constdecls = (let f e = FuncDecl.create ctx e in (Array.map f cdecls)) ; + _testerdecls = (let f e = FuncDecl.create ctx e in (Array.map f tdecls)) } in + EnumSort(s, e) + + let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gc s) + let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gnc s) + let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_)-> (z3obj_gno s) + (** Create a new enumeration sort. *) - let mk_sort_s ( ctx : context ) name enum_names = - (new enum_sort ctx)#cnstr_ss - (Symbol.mk_string ctx name) - (Symbol.mk_strings ctx enum_names) + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = + let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Symbol.aton enum_names)) in + create_sort ctx a b c + + (** + Create a new enumeration sort. + *) + let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string array ) = + mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) (** The function declarations of the constants in the enumeration. *) - let get_const_decls (x : enum_sort) = x#const_decls + let get_const_decls ( x : enum_sort ) = match x with EnumSort(_,ex) -> ex._constdecls (** The test predicates for the constants in the enumeration. *) - let get_tester_decls (x : enum_sort) = x#tester_decls + let get_tester_decls ( x : enum_sort ) = match x with EnumSort(_,ex) -> ex._testerdecls end (** Functions to manipulate List expressions *) -module Lists = -struct - (** - Create a new list sort. - *) - let mk_sort ( ctx : context ) (name : Symbol.symbol) elem_sort = - (new list_sort ctx)#cnstr_ss name elem_sort +and Lists : +sig + type list_sort_data + type list_sort = ListSort of (Sort.sort * list_sort_data) - (** - Create a new list sort. - *) +end = struct + type list_sort_data = { _nildecl : FuncDecl.func_decl ; + _is_nildecl : FuncDecl.func_decl ; + _consdecl : FuncDecl.func_decl ; + _is_consdecl : FuncDecl.func_decl ; + _headdecl : FuncDecl.func_decl ; + _taildecl : FuncDecl.func_decl } + type list_sort = ListSort of (Sort.sort * list_sort_data) + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = + let s = (Sort.create ctx no) in + let e = {_nildecl = FuncDecl.create ctx nildecl; + _is_nildecl = FuncDecl.create ctx is_nildecl; + _consdecl = FuncDecl.create ctx consdecl; + _is_consdecl = FuncDecl.create ctx is_consdecl; + _headdecl = FuncDecl.create ctx headdecl; + _taildecl = FuncDecl.create ctx taildecl} in + ListSort(s, e) + + let sgc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gc s) + let sgnc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gnc s) + let sgno ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_)-> (z3obj_gno s) + + + (** Create a new list sort. *) + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : Sort.sort ) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in + create_sort ctx r a b c d e f + + (** Create a new list sort. *) let mk_list_s ( ctx : context ) (name : string) elem_sort = mk_sort ctx (Symbol.mk_string ctx name) elem_sort (** The declaration of the nil function of this list sort. *) - let get_nil_decl (x : list_sort) = x#nil_decl + let get_nil_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._nildecl (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl (x : list_sort) = x#is_nil_decl + let get_is_nil_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._is_nildecl (** The declaration of the cons function of this list sort. *) - let get_cons_decl (x : list_sort) = x#cons_decl + let get_cons_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._consdecl (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl (x : list_sort) = x#is_cons_decl + let get_is_cons_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._is_consdecl (** The declaration of the head function of this list sort. *) - let get_head_decl (x : list_sort) = x#head_decl + let get_head_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._headdecl (** The declaration of the tail function of this list sort. *) - let get_tail_decl (x : list_sort) = x#tail_decl + let get_tail_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._taildecl (** The empty list. *) - let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] + let nil ( x : list_sort ) = Expr.create_fa (sgc x) (get_nil_decl x) [||] end (** Functions to manipulate Tuple expressions *) -module Tuples = -struct - (** - Create a new tuple sort. - *) - let mk_sort ( ctx : context ) name field_names field_sorts = - (new tuple_sort ctx)#cnstr_siss name (Array.length field_names) field_names field_sorts +and Tuples : +sig + type tuple_sort = TupleSort of Sort.sort +end = struct + type tuple_sort = TupleSort of Sort.sort + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + TupleSort(s) + + let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gc s) + let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gnc s) + let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s))-> (z3obj_gno s) + + (** Create a new tuple sort. *) + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : Sort.sort array ) = + let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Symbol.aton field_names) (Sort.aton field_sorts)) in + (* CMW: leaks a,b? *) + create_sort ctx r (** The constructor function of the tuple. *) - let get_mk_decl (x : tuple_sort) = - (new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_mk_decl x#gnc x#gno) + let get_mk_decl ( x : tuple_sort ) = + FuncDecl.create (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) (** The number of fields in the tuple. *) - let get_num_fields (x : tuple_sort) = Z3native.get_tuple_sort_num_fields x#gnc x#gno + let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) (** The field declarations. *) - let get_field_decls (x : tuple_sort) = + let get_field_decls ( x : tuple_sort ) = let n = get_num_fields x in - let f i = ((new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_field_decl x#gnc x#gno i)) in + let f i = FuncDecl.create (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in Array.init n f end (** Functions to manipulate arithmetic expressions *) -module Arithmetic = -struct +and Arithmetic : +sig + type arith_sort = ArithSort of Sort.sort + type int_sort = IntSort of Sort.sort + type real_sort = RealSort of Sort.sort + + type arith_expr = Expr of Expr.expr + type int_expr = IntExpr of arith_expr + type real_expr = RealExpr of arith_expr + + type int_num = IntNum of int_expr + type rat_num = RatNum of real_expr + type algebraic_num = AlgebraicNum of arith_expr + + + val create_arith_expr : context -> Z3native.ptr -> arith_expr + val create_int_expr : context -> Z3native.ptr -> int_expr + val create_real_expr : context -> Z3native.ptr -> real_expr + val create_int_num : context -> Z3native.ptr -> int_num + val create_rat_num : context -> Z3native.ptr -> rat_num + val create_algebraic_num : context -> Z3native.ptr -> algebraic_num +end = struct + type arith_sort = ArithSort of Sort.sort + type int_sort = IntSort of Sort.sort + type real_sort = RealSort of Sort.sort + + type arith_expr = ArithExpr of Expr.expr + type int_expr = IntExpr of arith_expr + type real_expr = RealExpr of arith_expr + + type int_num = IntNum of int_expr + type rat_num = RatNum of real_expr + type algebraic_num = AlgebraicNum of arith_expr + + let create_arith_expr ( ctx : context ) ( no : Z3native.ptr ) = + ArithExpr(Expr.create ctx no) + + let create_int_expr ( ctx : context ) ( no : Z3native.ptr ) = + IntExpr(create_arith_expr ctx no) + + let create_real_expr ( ctx : context ) ( no : Z3native.ptr ) = + RealExpr(create_arith_expr ctx no) + + let create_int_num ( ctx : context ) ( no : Z3native.ptr ) = + IntNum(create_int_expr ctx no) + + let create_rat_num ( ctx : context ) ( no : Z3native.ptr ) = + RatNum(create_real_expr ctx no) + (** Create a new integer sort. *) let mk_int_sort ( ctx : context ) = - (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort (context_gno ctx)) + (new int_sort ctx)#create_obj (Z3native.mk_int_sort (context_gno ctx)) (** Create a real sort. *) let mk_real_sort ( ctx : context ) = - (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort (context_gno ctx)) + (new real_sort ctx)#create_obj (Z3native.mk_real_sort (context_gno ctx)) (** Indicates whether the term is of integer sort. @@ -2802,11 +2820,11 @@ struct (** The numerator of a rational numeral. *) let get_numerator ( x : rat_num ) = - (new int_num x#gc)#cnstr_obj (Z3native.get_numerator x#gnc x#gno) + (new int_num x#gc)#create_obj (Z3native.get_numerator x#gnc x#gno) (** The denominator of a rational numeral. *) let get_denominator ( x : rat_num ) = - (new int_num x#gc)#cnstr_obj (Z3native.get_denominator x#gnc x#gno) + (new int_num x#gc)#create_obj (Z3native.get_denominator x#gnc x#gno) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -2844,75 +2862,92 @@ struct Create an expression representing t[0] + t[1] + .... *) let mk_add ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) (** Create an expression representing t[0] * t[1] * .... *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) (** Create an expression representing t[0] - t[1] - .... *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) (** Create an expression representing -t. *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - (create_expr ctx (Z3native.mk_unary_minus (context_gno ctx) t#gno) :> arith_expr) + ArithExpr(create ctx (Z3native.mk_unary_minus (context_gno ctx) + (gno (match t with ArithExpr(b) -> b)))) (** Create an expression representing t1 / t2. *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - (create_expr ctx (Z3native.mk_div (context_gno ctx) t1#gno t2#gno) :> arith_expr) + ArithExpr(create ctx (Z3native.mk_div (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 mod t2. The arguments must have int type. *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_mod (context_gno ctx) t1#gno t2#gno) + IntExpr(create ctx (Z3native.mk_mod (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 rem t2. The arguments must have int type. *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_rem (context_gno ctx) t1#gno t2#gno) + IntExpr(create ctx (Z3native.mk_rem (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 ^ t2. *) - let mk_Power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (create_expr ctx (Z3native.mk_power (context_gno ctx) t1#gno t2#gno) :> arith_expr) + let mk_power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + ArithExpr(create_expr ctx (Z3native.mk_power (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 < t2 *) let mk_lt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_lt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_lt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 <= t2 *) let mk_le ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_le (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_le (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 > t2 *) let mk_gt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_gt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_gt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 >= t2 *) let mk_ge ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_ge (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_ge (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Coerce an integer to a real. @@ -2925,7 +2960,8 @@ struct The argument must be of integer sort. *) let mk_int2real ( ctx : context ) ( t : int_expr ) = - (new real_expr ctx)#cnstr_obj (Z3native.mk_int2real (context_gno ctx) t#gno) + RealExpr(create (Z3native.mk_int2real (context_gno ctx) + (gno (match t with BoolExpr(b) -> b)))) (** Coerce a real to an integer. @@ -2935,14 +2971,14 @@ struct The argument must be of real sort. *) let mk_real2int ( ctx : context ) ( t : real_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_real2int (context_gno ctx) t#gno) + (new int_expr ctx)#create_obj (Z3native.mk_real2int (context_gno ctx) t#gno) (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_is_int (context_gno ctx) t#gno) - + BoolExpr(create ctx (Z3native.mk_is_int (context_gno ctx) + (gno (match t with BoolExpr(b) -> b)))) (** Return a upper bound for a given real algebraic number. The interval isolating the number is smaller than 1/10^. @@ -2951,7 +2987,7 @@ struct @return A numeral Expr of sort Real *) let to_upper ( x : algebraic_num ) ( precision : int ) = - (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) + (new rat_num x#gc)#create_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) (** Return a lower bound for the given real algebraic number. @@ -2961,7 +2997,7 @@ struct @return A numeral Expr of sort Real *) let to_lower ( x : algebraic_num ) precision = - (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) + (new rat_num x#gc)#create_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -2981,7 +3017,7 @@ struct raise (Z3native.Exception "Denominator is zero") else - (new rat_num ctx)#cnstr_obj (Z3native.mk_real (context_gno ctx) num den) + (new rat_num ctx)#create_obj (Z3native.mk_real (context_gno ctx) num den) (** Create a real numeral. @@ -2989,7 +3025,7 @@ struct @return A Term with value and sort Real *) let mk_real_numeral_s ( ctx : context ) ( v : string ) = - (new rat_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_real_sort ctx)#gno) + (new rat_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_real_sort ctx)#gno) (** Create a real numeral. @@ -2998,14 +3034,14 @@ struct @return A Term with value and sort Real *) let mk_real_numeral_i ( ctx : context ) ( v : int ) = - (new rat_num ctx)#cnstr_obj (Z3native.mk_int (context_gno ctx) v (mk_real_sort ctx)#gno) + (new rat_num ctx)#create_obj (Z3native.mk_int (context_gno ctx) v (mk_real_sort ctx)#gno) (** Create an integer numeral. @param v A string representing the Term value in decimal notation. *) let mk_int_numeral_s ( ctx : context ) ( v : string ) = - (new int_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_int_sort ctx)#gno) + (new int_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_int_sort ctx)#gno) (** Create an integer numeral. @@ -3013,7 +3049,7 @@ struct @return A Term with value and sort Integer *) let mk_int_numeral_i ( ctx : context ) ( v : int ) = - (new int_num ctx)#cnstr_obj (Z3native.mk_int (context_gno ctx) v (mk_int_sort ctx)#gno) + (new int_num ctx)#create_obj (Z3native.mk_int (context_gno ctx) v (mk_int_sort ctx)#gno) (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -3021,13 +3057,30 @@ end (** Functions to manipulate bit-vector expressions *) -module BitVectors = -struct +and BitVectors : +sig + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val create_expr : context -> Z3native.ptr -> bitvec_expr + val create_num : context -> Z3native.ptr -> bitvec_num +end = struct + type bitvec_expr = Expr of Expr.expr + type bitvec_num = BitVecExpr of bitvec_expr + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let e = (Expr.create ctx no) in + BitVecExpr(e) + + let create_num ( ctx : context ) ( no : Z3native.ptr ) = + let e = (create_expr ctx no) in + BitVecNum(e) + (** Create a new bit-vector sort. *) let mk_sort ( ctx : context ) size = - (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort (context_gno ctx) size) + (new bitvec_sort ctx)#create_obj (Z3native.mk_bv_sort (context_gno ctx) size) (** Indicates whether the terms is of bit-vector sort. @@ -3328,91 +3381,91 @@ struct The argument must have a bit-vector sort. *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnot (context_gno ctx) t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnot (context_gno ctx) t#gno) (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredand (context_gno ctx) t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvredand (context_gno ctx) t#gno) (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredor (context_gno ctx) t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvredor (context_gno ctx) t#gno) (** Bitwise conjunction. The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvand (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvand (context_gno ctx) t1#gno t2#gno) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvor (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvor (context_gno ctx) t1#gno t2#gno) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxor (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvxor (context_gno ctx) t1#gno t2#gno) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnand (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnand (context_gno ctx) t1#gno t2#gno) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnor (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnor (context_gno ctx) t1#gno t2#gno) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxnor (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvxnor (context_gno ctx) t1#gno t2#gno) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvneg (context_gno ctx) t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvneg (context_gno ctx) t#gno) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvadd (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvadd (context_gno ctx) t1#gno t2#gno) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsub (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsub (context_gno ctx) t1#gno t2#gno) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvmul (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvmul (context_gno ctx) t1#gno t2#gno) (** Unsigned division. @@ -3424,7 +3477,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvudiv (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvudiv (context_gno ctx) t1#gno t2#gno) (** Signed division. @@ -3439,7 +3492,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsdiv (context_gno ctx) t1#gno t2#gno) (** Unsigned remainder. @@ -3449,7 +3502,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvurem (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvurem (context_gno ctx) t1#gno t2#gno) (** Signed remainder. @@ -3461,7 +3514,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsrem (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsrem (context_gno ctx) t1#gno t2#gno) (** Two's complement signed remainder (sign follows divisor). @@ -3470,7 +3523,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsmod (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsmod (context_gno ctx) t1#gno t2#gno) (** Unsigned less-than @@ -3478,7 +3531,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvult (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvult (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Two's complement signed less-than @@ -3486,7 +3541,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvslt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvslt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Unsigned less-than or equal to. @@ -3494,7 +3551,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvule (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvule (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Two's complement signed less-than or equal to. @@ -3502,7 +3561,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsle (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvsle (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Unsigned greater than or equal to. @@ -3510,7 +3571,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvuge (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvuge (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Two's complement signed greater than or equal to. @@ -3518,7 +3581,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_SGE ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsge (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvsge (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Unsigned greater-than. @@ -3526,7 +3591,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvugt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvugt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Two's complement signed greater-than. @@ -3534,7 +3601,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsgt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvsgt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Bit-vector concatenation. @@ -3545,7 +3614,9 @@ struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_concat (context_gno ctx) t1#gno t2#gno) + BitVectors.BitVecExpr(create ctx (Z3native.mk_concat (context_gno ctx) + (gno (match t1 with BitVecExpr(b) -> b)) + (gno (match t2 with BitVecExpr(b) -> b)))) (** Bit-vector extraction. @@ -3556,7 +3627,7 @@ struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_extract (context_gno ctx) high low t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_extract (context_gno ctx) high low t#gno) (** Bit-vector sign extension. @@ -3566,7 +3637,7 @@ struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_sign_ext (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_sign_ext (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) (** Bit-vector zero extension. @@ -3577,7 +3648,7 @@ struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_zero_ext (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_zero_ext (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) (** Bit-vector repetition. @@ -3585,7 +3656,7 @@ struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_repeat (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_repeat (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) (** Shift left. @@ -3600,7 +3671,9 @@ struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvshl (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_bvshl (context_gno ctx) + (gno (match t1 with BitVecExpr(b) -> b)) + (gno (match t2 with BitVecExpr(b) -> b)))) (** Logical shift right @@ -3614,7 +3687,9 @@ struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvlshr (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_bvlshr (context_gno ctx) + (gno (match t1 with BitVecExpr(b) -> b)) + (gno (match t2 with BitVecExpr(b) -> b)))) (** Arithmetic shift right @@ -3630,7 +3705,9 @@ struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvashr (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_bvashr (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Rotate Left. @@ -3639,7 +3716,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_left (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_rotate_left (context_gno ctx) i (gno (match t with BoolExpr(b) -> b)))) (** Rotate Right. @@ -3648,7 +3725,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_right (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_rotate_right (context_gno ctx) i (gno (match t with BoolExpr(b) -> b)))) (** Rotate Left. @@ -3657,7 +3734,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_left (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_ext_rotate_left (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Rotate Right. @@ -3667,7 +3746,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_right (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_ext_rotate_right (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an bit bit-vector from the integer argument . @@ -3680,7 +3761,7 @@ struct The argument must be of integer sort. *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_int2bv (context_gno ctx) n t#gno) + BitVecExpr(create ctx (Z3native.mk_int2bv (context_gno ctx) n (gno (match t with IntExpr(b) -> b)))) (** Create an integer from the bit-vector argument . @@ -3698,7 +3779,7 @@ struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int (context_gno ctx) t#gno signed) + (new int_expr ctx)#create_obj (Z3native.mk_bv2int (context_gno ctx) t#gno signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3706,7 +3787,10 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow (context_gno ctx) t1#gno t2#gno signed) + BoolExpr(create ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)) + signed)) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3714,23 +3798,30 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_underflow (context_gno ctx) t1#gno t2#gno) - + BoolExpr(create ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) + (** Create a predicate that checks that the bit-wise subtraction does not overflow. The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_overflow (context_gno ctx) t1#gno t2#gno) - + BoolExpr(create ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) + (** Create a predicate that checks that the bit-wise subtraction does not underflow. The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow (context_gno ctx) t1#gno t2#gno signed) + BoolExpr(create ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)) + signed)) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3738,7 +3829,9 @@ struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create a predicate that checks that the bit-wise negation does not overflow. @@ -3746,7 +3839,7 @@ struct The arguments must be of bit-vector sort. *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvneg_no_overflow (context_gno ctx) t#gno) + BoolExpr(create ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (gno (match t with BitVecExpr(b) -> b)))) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3754,7 +3847,10 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow (context_gno ctx) t1#gno t2#gno signed) + BoolExpr(create ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)) + signed)) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3762,7 +3858,9 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create a bit-vector numeral. @@ -3771,12 +3869,13 @@ struct @param size the size of the bit-vector *) let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = - (new bitvec_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_sort ctx size)#gno) + (new bitvec_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_sort ctx size)#gno) end (** Functions to manipulate proof expressions *) -module Proofs = -struct +and Proofs : +sig +end = struct (** Indicates whether the term is a Proof for the expression 'true'. *) @@ -4259,13 +4358,13 @@ struct type goal = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : goal = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.goal_inc_ref ; dec_ref = Z3native.goal_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4318,7 +4417,7 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in + let f i = (new bool_expr (z3obj_gc x))#create_obj (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) @@ -4334,7 +4433,7 @@ struct (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = - cnstr to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) let simplify ( x : goal ) ( p : Params.params option ) = @@ -4352,7 +4451,7 @@ struct Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; Z3native.tactic_dec_ref (z3obj_gnc x) tn ; - cnstr (z3obj_gc x) res + create (z3obj_gc x) res (** @@ -4365,7 +4464,7 @@ struct @param proofs Indicates whether proof generation should be enabled. *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - cnstr ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) + create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) @@ -4380,13 +4479,13 @@ struct type model = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : model = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.model_inc_ref ; dec_ref = Z3native.model_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4400,13 +4499,13 @@ struct type func_interp = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_interp = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.func_interp_inc_ref ; dec_ref = Z3native.func_interp_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4419,13 +4518,13 @@ struct type func_entry = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_entry = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.func_entry_inc_ref ; dec_ref = Z3native.func_entry_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4467,7 +4566,7 @@ struct *) let get_entries ( x : func_interp ) = let n = (get_num_entries x) in - let f i = (FuncEntry.cnstr (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** @@ -4534,11 +4633,11 @@ struct raise (Z3native.Exception "Argument was not an array constant") else let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) + get_func_interp x ((new func_decl f#gc)#create_obj fd) | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); else let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) f#gno) in - if (Z3native.is_null n) then None else Some (FuncInterp.cnstr (z3obj_gc x) n) + if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) (** The number of constants that have an interpretation in the model. *) let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) @@ -4546,7 +4645,7 @@ struct (** The function declarations of the constants in the model. *) let get_const_decls ( x : model ) = let n = (get_num_consts x) in - let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f @@ -4556,15 +4655,15 @@ struct (** The function declarations of the function interpretations in the model. *) let get_func_decls ( x : model ) = let n = (get_num_consts x) in - let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** All symbols that have an interpretation in the model. *) let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in - let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.append (Array.init n_funcs f) (Array.init n_consts g) (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) @@ -4619,7 +4718,7 @@ struct An array of expressions, where each is an element of the universe of *) let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in + let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in Array.init n f @@ -4644,13 +4743,13 @@ struct type probe = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : probe = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.probe_inc_ref ; dec_ref = Z3native.probe_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4686,48 +4785,48 @@ struct Creates a new Probe. *) let mk_probe ( ctx : context ) ( name : string ) = - (cnstr ctx (Z3native.mk_probe (context_gno ctx) name)) + (create ctx (Z3native.mk_probe (context_gno ctx) name)) (** Create a probe that always evaluates to . *) let const ( ctx : context ) ( v : float ) = - (cnstr ctx (Z3native.probe_const (context_gno ctx) v)) + (create ctx (Z3native.probe_const (context_gno ctx) v)) (** Create a probe that evaluates to "true" when the value returned by is less than the value returned by *) let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value returned by is greater than the value returned by *) let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value returned by is less than or equal the value returned by *) let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value returned by is greater than or equal the value returned by *) let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value returned by is equal to the value returned by *) let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value @@ -4735,7 +4834,7 @@ struct *) (* CMW: and is a keyword *) let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value @@ -4743,7 +4842,7 @@ struct *) (* CMW: or is a keyword *) let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value @@ -4751,7 +4850,7 @@ struct *) (* CMW: is not a keyword? *) let not_ ( ctx : context ) ( p : probe ) = - (cnstr ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) + (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) end @@ -4767,13 +4866,13 @@ struct type tactic = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : tactic = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.tactic_inc_ref ; dec_ref = Z3native.tactic_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4786,13 +4885,13 @@ struct type apply_result = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : apply_result = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.apply_result_inc_ref ; dec_ref = Z3native.apply_result_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4803,19 +4902,19 @@ struct (** Retrieves the subgoals from the apply_result. *) let get_subgoals ( x : apply_result ) = let n = (get_num_subgoals x) in - let f i = Goal.cnstr (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in + let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** Retrieves the subgoals from the apply_result. *) let get_subgoal ( x : apply_result ) ( i : int ) = - Goal.cnstr (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) + Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) (** 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 *) let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = - Model.cnstr (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) + Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) (** A string representation of the ApplyResult. *) let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) @@ -4826,13 +4925,13 @@ struct (** Retrieves parameter descriptions for Tactics. *) let get_param_descrs ( x : tactic ) = - Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.create (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Apply the tactic to the goal. *) let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = match p with - | None -> (ApplyResult.cnstr (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) - | Some (pn) -> (ApplyResult.cnstr (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) + | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) + | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) (** The number of supported tactics. @@ -4858,7 +4957,7 @@ struct Creates a new Tactic. *) let mk_tactic ( ctx : context ) ( name : string ) = - cnstr ctx (Z3native.mk_tactic (context_gno ctx) name) + create ctx (Z3native.mk_tactic (context_gno ctx) name) (** Create a tactic that applies to a Goal and @@ -4870,17 +4969,17 @@ struct | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in match (Array.fold_left f None ts) with | None -> - cnstr ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) | Some(x) -> let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in - cnstr ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) + create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) (** Create a tactic that first applies to a Goal and if it fails then returns the result of applied to the Goal. *) let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - cnstr ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) (** Create a tactic that applies to a goal for milliseconds. @@ -4888,7 +4987,7 @@ struct If does not terminate within milliseconds, then it fails. *) let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - cnstr ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) + create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) (** Create a tactic that applies to a given goal if the probe @@ -4898,52 +4997,52 @@ struct *) (* CMW: when is a keyword *) let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = - cnstr ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) + create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = - cnstr ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) + create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) (** Create a tactic that keeps applying until the goal is not modified anymore or the maximum number of iterations is reached. *) let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - cnstr ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) + create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) (** Create a tactic that just returns the given goal. *) let skip ( ctx : context ) = - cnstr ctx (Z3native.tactic_skip (context_gno ctx)) + create ctx (Z3native.tactic_skip (context_gno ctx)) (** Create a tactic always fails. *) let fail ( ctx : context ) = - cnstr ctx (Z3native.tactic_fail (context_gno ctx)) + create ctx (Z3native.tactic_fail (context_gno ctx)) (** Create a tactic that fails if the probe evaluates to false. *) let fail_if ( ctx : context ) ( p : Probe.probe ) = - cnstr ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) + create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) or trivially unsatisfiable (i.e., contains `false'). *) let fail_if_not_decided ( ctx : context ) = - cnstr ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) + create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) (** Create a tactic that applies using the given set of parameters . *) let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = - cnstr ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) + create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) (** Create a tactic that applies using the given set of parameters . @@ -4956,14 +5055,14 @@ struct Create a tactic that applies the given tactics in parallel. *) let par_or ( ctx : context ) ( t : tactic array ) = - cnstr ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) + create ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) (** Create a tactic that applies to a given goal and then to every subgoal produced by . The subgoals are processed in parallel. *) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - cnstr ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) (** Interrupt the execution of a Z3 procedure. @@ -4980,13 +5079,13 @@ struct type solver = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : solver = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.solver_inc_ref ; dec_ref = Z3native.solver_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -5003,13 +5102,13 @@ struct type statistics = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : statistics = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.stats_inc_ref ; dec_ref = Z3native.stats_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -5028,7 +5127,7 @@ struct mutable m_float : float } (**/**) - let cnstr_si k v = + let create_si k v = let res : statistics_entry = { m_key = k ; m_is_int = true ; @@ -5038,7 +5137,7 @@ struct } in res - let cnstr_sd k v = + let create_sd k v = let res : statistics_entry = { m_key = k ; m_is_int = false ; @@ -5089,9 +5188,9 @@ struct let f i = ( let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then - (Entry.cnstr_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - (Entry.cnstr_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in Array.init n f @@ -5126,7 +5225,7 @@ struct Retrieves parameter descriptions for solver. *) let get_param_descrs ( x : solver ) = - Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.create (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** The current number of backtracking points (scopes). @@ -5200,7 +5299,7 @@ struct The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) @@ -5208,9 +5307,9 @@ struct The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in - let f i = ((new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get a i)#gno) in + let f i = ((new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get a i)#gno) in Array.init n f (** @@ -5225,7 +5324,7 @@ struct if ((Array.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (astaton assumptions)) + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (AST.aton assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -5243,7 +5342,7 @@ struct if (Z3native.is_null q) then None else - Some (Model.cnstr (z3obj_gc x) q) + Some (Model.create (z3obj_gc x) q) (** The proof of the last Check. @@ -5266,7 +5365,7 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f @@ -5281,7 +5380,7 @@ struct Solver statistics. *) let get_statistics ( x : solver ) = - (Statistics.cnstr (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) + (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) (** Creates a new (incremental) solver. @@ -5292,8 +5391,8 @@ struct *) let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = match logic with - | None -> (cnstr ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) + | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) + | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) (** Creates a new (incremental) solver. @@ -5306,7 +5405,7 @@ struct Creates a new (incremental) solver. *) let mk_simple_solver ( ctx : context ) = - (cnstr ctx (Z3native.mk_simple_solver (context_gno ctx))) + (create ctx (Z3native.mk_simple_solver (context_gno ctx))) (** Creates a solver that is implemented using the given tactic. @@ -5315,7 +5414,7 @@ struct will always solve each check from scratch. *) let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = - (cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) + (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) (** A string representation of the solver. @@ -5330,13 +5429,13 @@ struct type fixedpoint = z3_native_object (**/**) - let cnstr ( ctx : context ) = + let create ( ctx : context ) = let res : fixedpoint = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.fixedpoint_inc_ref ; dec_ref = Z3native.fixedpoint_dec_ref } in (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -5356,7 +5455,7 @@ struct Retrieves parameter descriptions for Fixedpoint solver. *) let get_param_descrs ( x : fixedpoint ) = - Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.create (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Assert a constraints into the fixedpoint solver. @@ -5487,30 +5586,30 @@ struct Convert benchmark given as set of axioms, rules and queries to a string. *) let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (astaton queries) + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (AST.aton queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in + let f i = (new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get v i)#gno in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in + let f i = (new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get v i)#gno in Array.init n f (** Create a Fixedpoint context. *) - let mk_fixedpoint ( ctx : context ) = cnstr ctx + let mk_fixedpoint ( ctx : context ) = create ctx end (** Global and context options @@ -5590,7 +5689,7 @@ struct *) let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (astaton assumptions) + (Array.length assumptions) (AST.aton assumptions) formula#gno (** @@ -5613,7 +5712,7 @@ struct Z3native.parse_smtlib_string (context_gno ctx) str cs (Symbol.aton sort_names) - (astaton sorts) + (AST.aton sorts) cd (Symbol.aton decl_names) (func_declaton decls) @@ -5633,7 +5732,7 @@ struct Z3native.parse_smtlib_file (context_gno ctx) file_name cs (Symbol.aton sort_names) - (astaton sorts) + (AST.aton sorts) cd (Symbol.aton decl_names) (func_declaton decls) @@ -5675,7 +5774,7 @@ struct *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in - let f i = (new func_decl ctx)#cnstr_obj (Z3native.get_smtlib_decl (context_gno ctx) i) in + let f i = (new func_decl ctx)#create_obj (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f (** @@ -5708,7 +5807,7 @@ struct Z3native.parse_smtlib2_string (context_gno ctx) str cs (Symbol.aton sort_names) - (astaton sorts) + (Sort.aton sorts) cd (Symbol.aton decl_names) (func_declaton decls) @@ -5728,7 +5827,7 @@ struct Z3native.parse_smtlib2_string (context_gno ctx) file_name cs (Symbol.aton sort_names) - (astaton sorts) + (Sort.aton sorts) cd (Symbol.aton decl_names) (func_declaton decls) From 0138d0c11c283c1d3457055975df69fdac9b5410 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 4 Feb 2013 23:18:55 +0000 Subject: [PATCH 052/248] Checkpoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 643 ++++++++++++++++++++++++++--------------------- 1 file changed, 355 insertions(+), 288 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 0e47912ae..58c319d4d 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1097,6 +1097,7 @@ sig val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val get_func_decl : expr -> FuncDecl.func_decl + val is_numeral : expr -> bool end = struct type expr = Expr of AST.ast @@ -1107,20 +1108,20 @@ end = struct let s = Z3native.get_sort (context_gno ctx) obj in let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in if (Z3native.is_algebraic_number (context_gno ctx) obj) then - (match (Arithmetic.create_algebraic_num ctx obj) with Arithmetic.AlgebraicNum(Arithmetic.Expr(e)) -> e) + (match (Arithmetic.AlgebraicNumbers.create_num ctx obj) with Arithmetic.AlgebraicNumbers.AlgebraicNum(Arithmetic.Expr(e)) -> e) else if (Z3native.is_numeral_ast (context_gno ctx) obj) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with - | INT_SORT -> (match (Arithmetic.create_int_num ctx obj) with Arithmetic.IntNum(Arithmetic.IntExpr(Arithmetic.Expr(e))) -> e) - | REAL_SORT -> (match (Arithmetic.create_rat_num ctx obj) with Arithmetic.RatNum(Arithmetic.RealExpr(Arithmetic.Expr(e))) -> e) + | INT_SORT -> (match (Arithmetic.Integers.create_num ctx obj) with Arithmetic.Integers.IntNum(Arithmetic.Integers.IntExpr(Arithmetic.Expr(e))) -> e) + | REAL_SORT -> (match (Arithmetic.Reals.create_num ctx obj) with Arithmetic.Reals.RatNum(Arithmetic.Reals.RealExpr(Arithmetic.Expr(e))) -> e) | BV_SORT -> (match (BitVectors.create_num ctx obj) with BitVectors.BitVecNum(BitVectors.BitVecExpr(e)) -> e) | _ -> raise (Z3native.Exception "Unsupported numeral object") else match sk with - | BOOL_SORT -> (match (Booleans.create ctx obj) with Booleans.BoolExpr(e) -> e) - | INT_SORT -> (match (Arithmetic.create_int_expr ctx obj) with Arithmetic.IntExpr(Arithmetic.Expr(e)) -> e) - | REAL_SORT -> (match (Arithmetic.create_real_expr ctx obj) with Arithmetic.RealExpr(Arithmetic.Expr(e)) -> e) + | BOOL_SORT -> (match (Booleans.create_expr ctx obj) with Booleans.BoolExpr(e) -> e) + | INT_SORT -> (match (Arithmetic.Integers.create_expr ctx obj) with Arithmetic.Integers.IntExpr(Arithmetic.Expr(e)) -> e) + | REAL_SORT -> (match (Arithmetic.Reals.create_expr ctx obj) with Arithmetic.Reals.RealExpr(Arithmetic.Expr(e)) -> e) | BV_SORT -> (match (BitVectors.create_expr ctx obj) with BitVectors.BitVecExpr(e) -> e) | ARRAY_SORT -> (match (Arrays.create_expr ctx obj) with Arrays.ArrayExpr(e) -> e) | DATATYPE_SORT -> (match (Datatypes.create_expr ctx obj) with Datatypes.DatatypeExpr(e) -> e) @@ -1406,16 +1407,20 @@ sig type bool_expr = BoolExpr of Expr.expr type bool_sort = BoolSort of Sort.sort - val create : context -> Z3native.ptr -> bool_expr + val create_expr : context -> Z3native.ptr -> bool_expr + val create_sort : context -> Z3native.ptr -> bool_sort val aton : bool_expr array -> Z3native.ptr array end = struct type bool_expr = BoolExpr of Expr.expr type bool_sort = BoolSort of Sort.sort - let create ( ctx : context ) ( no : Z3native.ptr ) = + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = let a = (AST.create ctx no) in BoolExpr(Expr.Expr(a)) + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + BoolSort(Sort.create ctx no) + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gc e) let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gnc e) let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gno e) @@ -1444,13 +1449,13 @@ end = struct The true Term. *) let mk_true ( ctx : context ) = - create ctx (Z3native.mk_true (context_gno ctx)) + create_expr ctx (Z3native.mk_true (context_gno ctx)) (** The false Term. *) let mk_false ( ctx : context ) = - create ctx (Z3native.mk_false (context_gno ctx)) + create_expr ctx (Z3native.mk_false (context_gno ctx)) (** Creates a Boolean value. @@ -1462,19 +1467,19 @@ end = struct Creates the equality = . *) let mk_eq ( ctx : context ) ( x : Expr.expr ) ( y : Expr.expr ) = - create ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + create_expr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) (** Creates a distinct term. *) let mk_distinct ( ctx : context ) ( args : Expr.expr array ) = - create ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (Expr.aton args)) + create_expr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (Expr.aton args)) (** Mk an expression representing not(a). *) let mk_not ( ctx : context ) ( a : bool_expr ) = - create ctx (Z3native.mk_not (context_gno ctx) (gno a)) + create_expr ctx (Z3native.mk_not (context_gno ctx) (gno a)) (** Create an expression representing an if-then-else: ite(t1, t2, t3). @@ -1483,36 +1488,36 @@ end = struct @param t3 An expression with the same sort as *) let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - create ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + create_expr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) (** Create an expression representing t1 iff t2. *) let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + create_expr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing t1 -> t2. *) let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + create_expr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing t1 xor t2. *) let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + create_expr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing the AND of args *) let mk_and ( ctx : context ) ( args : bool_expr array ) = - create ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (aton args)) + create_expr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (aton args)) (** Create an expression representing the OR of args *) let mk_or ( ctx : context ) ( args : bool_expr array ) = - create ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (aton args)) + create_expr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (aton args)) end (** Quantifier expressions *) @@ -1676,7 +1681,7 @@ end = struct The body of the quantifier. *) let get_body ( x : quantifier ) = - Booleans.create (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) + Booleans.create_expr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) (** Creates a new bound variable. @@ -2643,416 +2648,478 @@ end and Arithmetic : sig type arith_sort = ArithSort of Sort.sort - type int_sort = IntSort of Sort.sort - type real_sort = RealSort of Sort.sort - type arith_expr = Expr of Expr.expr - type int_expr = IntExpr of arith_expr - type real_expr = RealExpr of arith_expr - - type int_num = IntNum of int_expr - type rat_num = RatNum of real_expr - type algebraic_num = AlgebraicNum of arith_expr - - val create_arith_expr : context -> Z3native.ptr -> arith_expr - val create_int_expr : context -> Z3native.ptr -> int_expr - val create_real_expr : context -> Z3native.ptr -> real_expr - val create_int_num : context -> Z3native.ptr -> int_num - val create_rat_num : context -> Z3native.ptr -> rat_num - val create_algebraic_num : context -> Z3native.ptr -> algebraic_num + val create_expr : context -> Z3native.ptr -> arith_expr + val aton : arith_expr array -> Z3native.ptr array + + module Integers : sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val create_sort : context -> Z3native.ptr -> int_sort + val create_expr : context -> Z3native.ptr -> int_expr + val create_num : context -> Z3native.ptr -> int_num + end + + module Reals : sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val create_sort : context -> Z3native.ptr -> real_sort + val create_expr : context -> Z3native.ptr -> real_expr + val create_num : context -> Z3native.ptr -> rat_num + end + + module AlgebraicNumbers : sig + type algebraic_num = AlgebraicNum of arith_expr + + val create_num : context -> Z3native.ptr -> algebraic_num + end + end = struct type arith_sort = ArithSort of Sort.sort - type int_sort = IntSort of Sort.sort - type real_sort = RealSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - type int_expr = IntExpr of arith_expr - type real_expr = RealExpr of arith_expr - - type int_num = IntNum of int_expr - type rat_num = RatNum of real_expr - type algebraic_num = AlgebraicNum of arith_expr let create_arith_expr ( ctx : context ) ( no : Z3native.ptr ) = ArithExpr(Expr.create ctx no) - let create_int_expr ( ctx : context ) ( no : Z3native.ptr ) = - IntExpr(create_arith_expr ctx no) + let create_arith_sort ( ctx : context ) ( no : Z3native.ptr ) = + ArithSort(Sort.create ctx no) - let create_real_expr ( ctx : context ) ( no : Z3native.ptr ) = - RealExpr(create_arith_expr ctx no) + let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gc s) + let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gnc s) + let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gno s) + let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gc e) + let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) + let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) - let create_int_num ( ctx : context ) ( no : Z3native.ptr ) = - IntNum(create_int_expr ctx no) - let create_rat_num ( ctx : context ) ( no : Z3native.ptr ) = - RatNum(create_real_expr ctx no) - - (** - Create a new integer sort. - *) - let mk_int_sort ( ctx : context ) = - (new int_sort ctx)#create_obj (Z3native.mk_int_sort (context_gno ctx)) + module rec Integers : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr - (** - Create a real sort. - *) - let mk_real_sort ( ctx : context ) = - (new real_sort ctx)#create_obj (Z3native.mk_real_sort (context_gno ctx)) + val create_sort : context -> Z3native.ptr -> int_sort + val create_expr : context -> Z3native.ptr -> int_expr + val create_num : context -> Z3native.ptr -> int_num + end = struct + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + IntSort(create_arith_sort ctx no) + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + IntExpr(create_arith_expr ctx no) + + let create_num ( ctx : context ) ( no : Z3native.ptr ) = + IntNum(create_expr ctx no) + + let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) + let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) + let sgno ( x : int_sort ) = match (x) with IntSort(s) -> (sgno s) + let egc ( x : int_expr ) = match (x) with IntExpr(e) -> (egc e) + let egnc ( x : int_expr ) = match (x) with IntExpr(e) -> (egnc e) + let egno ( x : int_expr ) = match (x) with IntExpr(e) -> (egno e) + let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) + let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) + let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) + + (** Create a new integer sort. *) + let mk_sort ( ctx : context ) = + create_sort ctx (Z3native.mk_int_sort (context_gno ctx)) + + (** Retrieve the int value. *) + let get_int ( x : int_num ) = + let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + if r then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + + (** + Creates an integer constant. + *) + let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) + + (** + Creates an integer constant. + *) + let mk_int_const_s ( ctx : context ) ( name : string ) = + mk_int_const ctx (Symbol.mk_string ctx name) + + (** + Create an expression representing t1 mod t2. + The arguments must have int type. + *) + let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + create_expr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + + (** + Create an expression representing t1 rem t2. + The arguments must have int type. + *) + let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + create_expr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + + (** + Create an integer numeral. + @param v A string representing the Term value in decimal notation. + *) + let mk_int_numeral_s ( ctx : context ) ( v : string ) = + create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + + (** + Create an integer numeral. + @param v value of the numeral. + @return A Term with value and sort Integer + *) + let mk_int_numeral_i ( ctx : context ) ( v : int ) = + create_num ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + + (** + 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. + *) + let mk_int2real ( ctx : context ) ( t : int_expr ) = + Reals.create_expr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)) + end + + and Reals : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val create_sort : context -> Z3native.ptr -> real_sort + val create_expr : context -> Z3native.ptr -> real_expr + val create_num : context -> Z3native.ptr -> rat_num + end = struct + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + RealSort(create_arith_sort ctx no) + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + RealExpr(create_arith_expr ctx no) + + let create_num ( ctx : context ) ( no : Z3native.ptr ) = + RatNum(create_expr ctx no) + + let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) + let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) + let sgno ( x : real_sort ) = match (x) with RealSort(s) -> (sgno s) + let egc ( x : real_expr ) = match (x) with RealExpr(e) -> (egc e) + let egnc ( x : real_expr ) = match (x) with RealExpr(e) -> (egnc e) + let egno ( x : real_expr ) = match (x) with RealExpr(e) -> (egno e) + let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) + let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) + let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) + + (** Create a real sort. *) + let mk_sort ( ctx : context ) = + create_sort ctx (Z3native.mk_real_sort (context_gno ctx)) + + (** The numerator of a rational numeral. *) + let get_numerator ( x : rat_num ) = + Integers.create_num (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + + (** The denominator of a rational numeral. *) + let get_denominator ( x : rat_num ) = + Integers.create_num (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : rat_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + + (** Creates a real constant. *) + let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) + + (** Creates a real constant. *) + let mk_real_const_s ( ctx : context ) ( name : string ) = + mk_real_const ctx (Symbol.mk_string ctx name) + + (** + Create a real from a fraction. + + @param num numerator of rational. + @param den denominator of rational. + @return A Term with value / and sort Real + + *) + let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = + if (den == 0) then + raise (Z3native.Exception "Denominator is zero") + else + create_num ctx (Z3native.mk_real (context_gno ctx) num den) + + (** + Create a real numeral. + @param v A string representing the Term value in decimal notation. + @return A Term with value and sort Real + *) + let mk_numeral_s ( ctx : context ) ( v : string ) = + create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + + (** + Create a real numeral. + + @param v value of the numeral. + @return A Term with value and sort Real + *) + let mk_numeral_i ( ctx : context ) ( v : int ) = + create_num ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + + (** Creates an expression that checks whether a real number is an integer. *) + let mk_is_integer ( ctx : context ) ( t : real_expr ) = + Booleans.create_expr ctx (Z3native.mk_is_int (context_gno ctx) (egno t)) + + (** + 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. + *) + let mk_real2int ( ctx : context ) ( t : real_expr ) = + Integers.create_expr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)) + end + + and AlgebraicNumbers : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val create_num : context -> Z3native.ptr -> algebraic_num + end = struct + type algebraic_num = AlgebraicNum of arith_expr + + let create_num ( ctx : context ) ( no : Z3native.ptr ) = + AlgebraicNum(create_arith_expr ctx no) + + let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) + let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) + let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) + + (** + Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + @param precision the precision of the result + @return A numeral Expr of sort Real + *) + let to_upper ( x : algebraic_num ) ( precision : int ) = + Reals.create_num (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + + (** + Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + @param precision the precision of the result + @return A numeral Expr of sort Real + *) + let to_lower ( x : algebraic_num ) precision = + Reals.create_num (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : algebraic_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + end + + let aton (a : arith_expr array) = + let f (e : arith_expr) = (egno e) in + Array.map f a (** Indicates whether the term is of integer sort. *) - let is_int ( x : expr ) = - (Z3native.is_numeral_ast x#gnc x#gno) && - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) + let is_int ( x : Expr.expr ) = + (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) (** Indicates whether the term is an arithmetic numeral. *) - let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + let is_arithmetic_numeral ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) (** Indicates whether the term is a less-than-or-equal *) - let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + let is_le ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) (** Indicates whether the term is a greater-than-or-equal *) - let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + let is_ge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) (** Indicates whether the term is a less-than *) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + let is_lt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) (** Indicates whether the term is a greater-than *) - let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + let is_gt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) (** Indicates whether the term is addition (binary) *) - let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + let is_add ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) (** Indicates whether the term is subtraction (binary) *) - let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + let is_sub ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) (** Indicates whether the term is a unary minus *) - let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + let is_uminus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) (** Indicates whether the term is multiplication (binary) *) - let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + let is_mul ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) (** Indicates whether the term is division (binary) *) - let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + let is_div ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) (** Indicates whether the term is integer division (binary) *) - let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + let is_idiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) (** Indicates whether the term is remainder (binary) *) - let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + let is_remainder ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) (** Indicates whether the term is modulus (binary) *) - let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + let is_modulus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) (** Indicates whether the term is a coercion of integer to real (unary) *) - let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + let is_inttoreal ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) (** Indicates whether the term is a coercion of real to integer (unary) *) - let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + let is_real_to_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) (** Indicates whether the term is a check that tests whether a real is integral (unary) *) - let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + let is_real_is_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) (** Indicates whether the term is of sort real. *) - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) + let is_real ( x : Expr.expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) (** Indicates whether the term is an integer numeral. *) - let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) + let is_int_numeral ( x : Expr.expr ) = (Expr.is_numeral x) && (is_int x) (** Indicates whether the term is a real numeral. *) - let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) + let is_rat_num ( x : Expr.expr ) = (Expr.is_numeral x) && (is_real x) (** Indicates whether the term is an algebraic number *) - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number x#gnc x#gno - - (** Retrieve the int value. *) - let get_int ( x : int_num ) = - let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if r then v - else raise (Z3native.Exception "Conversion failed.") - - (** Returns a string representation of the numeral. *) - let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno - - (** The numerator of a rational numeral. *) - let get_numerator ( x : rat_num ) = - (new int_num x#gc)#create_obj (Z3native.get_numerator x#gnc x#gno) - - (** The denominator of a rational numeral. *) - let get_denominator ( x : rat_num ) = - (new int_num x#gc)#create_obj (Z3native.get_denominator x#gnc x#gno) - - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) - let to_decimal_string ( x : rat_num ) (precision : int) = - Z3native.get_numeral_decimal_string x#gnc x#gno precision - - (** Returns a string representation of the numeral. *) - let to_string ( x : rat_num ) = Z3native.get_numeral_string x#gnc x#gno - - (** - Creates an integer constant. - *) - let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = - ((Expr.mk_const ctx name (mk_int_sort ctx)) :> int_expr) - - (** - Creates an integer constant. - *) - let mk_int_const_s ( ctx : context ) ( name : string ) = - mk_int_const ctx (Symbol.mk_string ctx name) - - (** - Creates a real constant. - *) - let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = - ((Expr.mk_const ctx name (mk_real_sort ctx)) :> real_expr) - - (** - Creates a real constant. - *) - let mk_real_const_s ( ctx : context ) ( name : string ) = - mk_real_const ctx (Symbol.mk_string ctx name) + let is_algebraic_number ( x : Expr.expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) (** Create an expression representing t[0] + t[1] + .... *) let mk_add ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) + Arithmetic.create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Arithmetic.aton t)) (** Create an expression representing t[0] * t[1] * .... *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) + Arithmetic.create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Arithmetic.aton t)) (** Create an expression representing t[0] - t[1] - .... *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) + Arithmetic.create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Arithmetic.aton t)) (** Create an expression representing -t. *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - ArithExpr(create ctx (Z3native.mk_unary_minus (context_gno ctx) - (gno (match t with ArithExpr(b) -> b)))) + Arithmetic.create_expr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t)) (** Create an expression representing t1 / t2. *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - ArithExpr(create ctx (Z3native.mk_div (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - - (** - Create an expression representing t1 mod t2. - The arguments must have int type. - *) - let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - IntExpr(create ctx (Z3native.mk_mod (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - - (** - Create an expression representing t1 rem t2. - The arguments must have int type. - *) - let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - IntExpr(create ctx (Z3native.mk_rem (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Arithmetic.create_expr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 ^ t2. *) - let mk_power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - ArithExpr(create_expr ctx (Z3native.mk_power (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Arithmetic.create_expr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 < t2 *) - let mk_lt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - BoolExpr(create ctx (Z3native.mk_lt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Booleans.create_expr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 <= t2 *) - let mk_le ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - BoolExpr(create ctx (Z3native.mk_le (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Booleans.create_expr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 > t2 *) - let mk_gt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - BoolExpr(create ctx (Z3native.mk_gt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Booleans.create_expr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 >= t2 *) - let mk_ge ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - BoolExpr(create ctx (Z3native.mk_ge (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - - (** - 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. - *) - let mk_int2real ( ctx : context ) ( t : int_expr ) = - RealExpr(create (Z3native.mk_int2real (context_gno ctx) - (gno (match t with BoolExpr(b) -> b)))) - - (** - 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. - *) - let mk_real2int ( ctx : context ) ( t : real_expr ) = - (new int_expr ctx)#create_obj (Z3native.mk_real2int (context_gno ctx) t#gno) - - (** - Creates an expression that checks whether a real number is an integer. - *) - let mk_is_integer ( ctx : context ) ( t : real_expr ) = - BoolExpr(create ctx (Z3native.mk_is_int (context_gno ctx) - (gno (match t with BoolExpr(b) -> b)))) - (** - Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) - let to_upper ( x : algebraic_num ) ( precision : int ) = - (new rat_num x#gc)#create_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) - - (** - Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) - let to_lower ( x : algebraic_num ) precision = - (new rat_num x#gc)#create_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) - - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) - let to_decimal_string ( x : algebraic_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string x#gnc x#gno precision - - (** - Create a real from a fraction. - - @param num numerator of rational. - @param den denominator of rational. - @return A Term with value / and sort Real - - *) - let mk_real_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = - if (den == 0) then - raise (Z3native.Exception "Denominator is zero") - else - - (new rat_num ctx)#create_obj (Z3native.mk_real (context_gno ctx) num den) - - (** - Create a real numeral. - @param v A string representing the Term value in decimal notation. - @return A Term with value and sort Real - *) - let mk_real_numeral_s ( ctx : context ) ( v : string ) = - (new rat_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_real_sort ctx)#gno) - - (** - Create a real numeral. - - @param v value of the numeral. - @return A Term with value and sort Real - *) - let mk_real_numeral_i ( ctx : context ) ( v : int ) = - (new rat_num ctx)#create_obj (Z3native.mk_int (context_gno ctx) v (mk_real_sort ctx)#gno) - - (** - Create an integer numeral. - @param v A string representing the Term value in decimal notation. - *) - let mk_int_numeral_s ( ctx : context ) ( v : string ) = - (new int_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_int_sort ctx)#gno) - - (** - Create an integer numeral. - @param v value of the numeral. - @return A Term with value and sort Integer - *) - let mk_int_numeral_i ( ctx : context ) ( v : int ) = - (new int_num ctx)#create_obj (Z3native.mk_int (context_gno ctx) v (mk_int_sort ctx)#gno) - - (** Returns a string representation of the numeral. *) - let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno + let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Booleans.create_expr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2)) end From 276c5a5cdcab12fe3df8eb8b2aacceeed117d74f Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 5 Feb 2013 00:19:06 +0000 Subject: [PATCH 053/248] ML API: No more objects; type hierarchy exposed; clean separation into modules. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 691 ++++++++++++++++++++++++----------------------- 1 file changed, 357 insertions(+), 334 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 58c319d4d..4cf41f420 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -334,6 +334,13 @@ sig val create : context -> Z3native.ptr -> ast val aton : ast array -> Z3native.ptr array + module ASTVectors : sig + type ast_vector + val create : context -> Z3native.ptr -> ast_vector + val get_size : ast_vector -> int + val get : ast_vector -> int -> ast + end + val is_expr : ast -> bool val is_var : ast -> bool end = struct @@ -354,7 +361,7 @@ end = struct (** Vectors of ASTs *) - module ASTVector = + module ASTVectors = struct type ast_vector = z3_native_object @@ -401,7 +408,7 @@ end = struct (** Translates all ASTs in the vector to . @param to_ctx A context - @return A new ASTVector + @return A new ASTVectors *) let translate ( x : ast_vector ) ( to_ctx : context ) = create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) @@ -466,7 +473,7 @@ end = struct (** The keys stored in the map. *) let get_keys ( x : ast_map ) = - ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + ASTVectors.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) (** Retrieves a string representation of the map.*) let to_string ( x : ast_map ) = @@ -613,16 +620,15 @@ end and Sort : sig type sort = Sort of AST.ast - type bitvec_sort = BitvecSort of sort type uninterpreted_sort = UninterpretedSort of sort val create : context -> Z3native.ptr -> sort - val gno : sort -> Z3native.ptr + val gc : sort -> context val gnc : sort -> Z3native.ptr + val gno : sort -> Z3native.ptr val aton : sort array -> Z3native.ptr array end = struct type sort = Sort of AST.ast - type bitvec_sort = BitvecSort of sort type uninterpreted_sort = UninterpretedSort of sort let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) @@ -713,11 +719,14 @@ sig type func_decl = FuncDecl of AST.ast val create : context -> Z3native.ptr -> func_decl + val gc : func_decl -> context val gno : func_decl -> Z3native.ptr val gnc : func_decl -> Z3native.ptr + val aton : func_decl array -> Z3native.ptr array val get_domain_size : func_decl -> int val get_decl_kind : func_decl -> Z3enums.decl_kind + val get_arity : func_decl -> int end = struct open Sort @@ -1098,6 +1107,7 @@ sig val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val get_func_decl : expr -> FuncDecl.func_decl val is_numeral : expr -> bool + val to_string : expr -> string end = struct type expr = Expr of AST.ast @@ -1108,20 +1118,20 @@ end = struct let s = Z3native.get_sort (context_gno ctx) obj in let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in if (Z3native.is_algebraic_number (context_gno ctx) obj) then - (match (Arithmetic.AlgebraicNumbers.create_num ctx obj) with Arithmetic.AlgebraicNumbers.AlgebraicNum(Arithmetic.Expr(e)) -> e) + (match (Arithmetic.AlgebraicNumbers.create_num ctx obj) with Arithmetic.AlgebraicNumbers.AlgebraicNum(Arithmetic.ArithExpr(e)) -> e) else if (Z3native.is_numeral_ast (context_gno ctx) obj) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with - | INT_SORT -> (match (Arithmetic.Integers.create_num ctx obj) with Arithmetic.Integers.IntNum(Arithmetic.Integers.IntExpr(Arithmetic.Expr(e))) -> e) - | REAL_SORT -> (match (Arithmetic.Reals.create_num ctx obj) with Arithmetic.Reals.RatNum(Arithmetic.Reals.RealExpr(Arithmetic.Expr(e))) -> e) + | INT_SORT -> (match (Arithmetic.Integers.create_num ctx obj) with Arithmetic.Integers.IntNum(Arithmetic.Integers.IntExpr(Arithmetic.ArithExpr(e))) -> e) + | REAL_SORT -> (match (Arithmetic.Reals.create_num ctx obj) with Arithmetic.Reals.RatNum(Arithmetic.Reals.RealExpr(Arithmetic.ArithExpr(e))) -> e) | BV_SORT -> (match (BitVectors.create_num ctx obj) with BitVectors.BitVecNum(BitVectors.BitVecExpr(e)) -> e) | _ -> raise (Z3native.Exception "Unsupported numeral object") else match sk with | BOOL_SORT -> (match (Booleans.create_expr ctx obj) with Booleans.BoolExpr(e) -> e) - | INT_SORT -> (match (Arithmetic.Integers.create_expr ctx obj) with Arithmetic.Integers.IntExpr(Arithmetic.Expr(e)) -> e) - | REAL_SORT -> (match (Arithmetic.Reals.create_expr ctx obj) with Arithmetic.Reals.RealExpr(Arithmetic.Expr(e)) -> e) + | INT_SORT -> (match (Arithmetic.Integers.create_expr ctx obj) with Arithmetic.Integers.IntExpr(Arithmetic.ArithExpr(e)) -> e) + | REAL_SORT -> (match (Arithmetic.Reals.create_expr ctx obj) with Arithmetic.Reals.RealExpr(Arithmetic.ArithExpr(e)) -> e) | BV_SORT -> (match (BitVectors.create_expr ctx obj) with BitVectors.BitVecExpr(e) -> e) | ARRAY_SORT -> (match (Arrays.create_expr ctx obj) with Arrays.ArrayExpr(e) -> e) | DATATYPE_SORT -> (match (Datatypes.create_expr ctx obj) with Datatypes.DatatypeExpr(e) -> e) @@ -1409,6 +1419,9 @@ sig val create_expr : context -> Z3native.ptr -> bool_expr val create_sort : context -> Z3native.ptr -> bool_sort + val gc : bool_expr -> context + val gnc : bool_expr -> Z3native.ptr + val gno : bool_expr -> Z3native.ptr val aton : bool_expr array -> Z3native.ptr array end = struct type bool_expr = BoolExpr of Expr.expr @@ -2648,9 +2661,10 @@ end and Arithmetic : sig type arith_sort = ArithSort of Sort.sort - type arith_expr = Expr of Expr.expr + type arith_expr = ArithExpr of Expr.expr val create_expr : context -> Z3native.ptr -> arith_expr + val create_sort : context -> Z3native.ptr -> arith_sort val aton : arith_expr array -> Z3native.ptr array module Integers : sig @@ -2679,14 +2693,53 @@ sig val create_num : context -> Z3native.ptr -> algebraic_num end + val is_int : Expr.expr -> bool + val is_arithmetic_numeral : Expr.expr -> bool + val is_le : Expr.expr -> bool + val is_ge : Expr.expr -> bool + val is_lt : Expr.expr -> bool + val is_gt : Expr.expr -> bool + val is_add : Expr.expr -> bool + val is_sub : Expr.expr -> bool + val is_uminus : Expr.expr -> bool + val is_mul : Expr.expr -> bool + val is_div : Expr.expr -> bool + val is_idiv : Expr.expr -> bool + val is_remainder : Expr.expr -> bool + val is_modulus : Expr.expr -> bool + val is_inttoreal : Expr.expr -> bool + val is_real_to_int : Expr.expr -> bool + val is_real_is_int : Expr.expr -> bool + val is_real : Expr.expr -> bool + val is_int_numeral : Expr.expr -> bool + val is_rat_num : Expr.expr -> bool + val is_algebraic_number : Expr.expr -> bool + val mk_add : context -> arith_expr array -> Arithmetic.arith_expr + val mk_mul : context -> arith_expr array -> Arithmetic.arith_expr + val mk_sub : context -> arith_expr array -> Arithmetic.arith_expr + val mk_unary_minus : + context -> arith_expr -> Arithmetic.arith_expr + val mk_div : + context -> arith_expr -> arith_expr -> Arithmetic.arith_expr + val mk_power : + context -> arith_expr -> arith_expr -> Arithmetic.arith_expr + val mk_lt : + context -> arith_expr -> arith_expr -> Booleans.bool_expr + val mk_le : + context -> arith_expr -> arith_expr -> Booleans.bool_expr + val mk_gt : + context -> arith_expr -> arith_expr -> Booleans.bool_expr + val mk_ge : + context -> arith_expr -> arith_expr -> Booleans.bool_expr + end = struct type arith_sort = ArithSort of Sort.sort type arith_expr = ArithExpr of Expr.expr - let create_arith_expr ( ctx : context ) ( no : Z3native.ptr ) = + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = ArithExpr(Expr.create ctx no) - let create_arith_sort ( ctx : context ) ( no : Z3native.ptr ) = + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = ArithSort(Sort.create ctx no) let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gc s) @@ -2712,10 +2765,10 @@ end = struct type int_num = IntNum of int_expr let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - IntSort(create_arith_sort ctx no) + IntSort(Arithmetic.create_sort ctx no) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - IntExpr(create_arith_expr ctx no) + IntExpr(Arithmetic.create_expr ctx no) let create_num ( ctx : context ) ( no : Z3native.ptr ) = IntNum(create_expr ctx no) @@ -2796,6 +2849,19 @@ end = struct *) let mk_int2real ( ctx : context ) ( t : int_expr ) = Reals.create_expr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)) + + (** + 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. + *) + let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = + BitVectors.create_expr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t)) end and Reals : @@ -2813,10 +2879,10 @@ end = struct type rat_num = RatNum of real_expr let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - RealSort(create_arith_sort ctx no) + RealSort(Arithmetic.create_sort ctx no) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - RealExpr(create_arith_expr ctx no) + RealExpr(Arithmetic.create_expr ctx no) let create_num ( ctx : context ) ( no : Z3native.ptr ) = RatNum(create_expr ctx no) @@ -2914,7 +2980,7 @@ end = struct type algebraic_num = AlgebraicNum of arith_expr let create_num ( ctx : context ) ( no : Z3native.ptr ) = - AlgebraicNum(create_arith_expr ctx no) + AlgebraicNum(Arithmetic.create_expr ctx no) let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) @@ -3126,316 +3192,330 @@ end (** Functions to manipulate bit-vector expressions *) and BitVectors : sig + type bitvec_sort = BitVecSort of Sort.sort type bitvec_expr = BitVecExpr of Expr.expr type bitvec_num = BitVecNum of bitvec_expr + val create_sort : context -> Z3native.ptr -> bitvec_sort val create_expr : context -> Z3native.ptr -> bitvec_expr val create_num : context -> Z3native.ptr -> bitvec_num end = struct - type bitvec_expr = Expr of Expr.expr - type bitvec_num = BitVecExpr of bitvec_expr + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + BitVecSort(Sort.create ctx no) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (Expr.create ctx no) in - BitVecExpr(e) + BitVecExpr(Expr.create ctx no) let create_num ( ctx : context ) ( no : Z3native.ptr ) = - let e = (create_expr ctx no) in - BitVecNum(e) + BitVecNum(create_expr ctx no) + + let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) + let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) + let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) + let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gc e) + let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gnc e) + let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gno e) + let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) + let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) + let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) (** Create a new bit-vector sort. *) let mk_sort ( ctx : context ) size = - (new bitvec_sort ctx)#create_obj (Z3native.mk_bv_sort (context_gno ctx) size) + create_sort ctx (Z3native.mk_bv_sort (context_gno ctx) size) (** Indicates whether the terms is of bit-vector sort. *) - let is_bv ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == BV_SORT) + let is_bv ( x : Expr.expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) (** Indicates whether the term is a bit-vector numeral *) - let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) + let is_bv_numeral ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) (** Indicates whether the term is a one-bit bit-vector with value one *) - let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) + let is_bv_bit1 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) (** Indicates whether the term is a one-bit bit-vector with value zero *) - let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) + let is_bv_bit0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) (** Indicates whether the term is a bit-vector unary minus *) - let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) + let is_bv_uminus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) (** Indicates whether the term is a bit-vector addition (binary) *) - let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) + let is_bv_add ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) (** Indicates whether the term is a bit-vector subtraction (binary) *) - let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) + let is_bv_sub ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) (** Indicates whether the term is a bit-vector multiplication (binary) *) - let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) + let is_bv_mul ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) (** Indicates whether the term is a bit-vector signed division (binary) *) - let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) + let is_bv_sdiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) (** Indicates whether the term is a bit-vector unsigned division (binary) *) - let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) + let is_bv_udiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) (** Indicates whether the term is a bit-vector signed remainder (binary) *) - let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) + let is_bv_SRem ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) + let is_bv_urem ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) (** Indicates whether the term is a bit-vector signed modulus *) - let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) + let is_bv_smod ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) (** Indicates whether the term is a bit-vector signed division by zero *) - let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) + let is_bv_sdiv0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) (** Indicates whether the term is a bit-vector unsigned division by zero *) - let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) + let is_bv_udiv0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) (** Indicates whether the term is a bit-vector signed remainder by zero *) - let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) + let is_bv_srem0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) + let is_bv_urem0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) (** Indicates whether the term is a bit-vector signed modulus by zero *) - let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) + let is_bv_smod0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) + let is_bv_ule ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) + let is_bv_sle ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) + let is_bv_uge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) + let is_bv_sge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) (** Indicates whether the term is an unsigned bit-vector less-than *) - let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) + let is_bv_ult ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) (** Indicates whether the term is a signed bit-vector less-than *) - let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) + let is_bv_slt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) (** Indicates whether the term is an unsigned bit-vector greater-than *) - let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) + let is_bv_ugt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) (** Indicates whether the term is a signed bit-vector greater-than *) - let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) + let is_bv_sgt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) (** Indicates whether the term is a bit-wise AND *) - let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) + let is_bv_and ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) (** Indicates whether the term is a bit-wise OR *) - let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) + let is_bv_or ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) (** Indicates whether the term is a bit-wise NOT *) - let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) + let is_bv_not ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) (** Indicates whether the term is a bit-wise XOR *) - let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) + let is_bv_xor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) (** Indicates whether the term is a bit-wise NAND *) - let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) + let is_bv_nand ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) (** Indicates whether the term is a bit-wise NOR *) - let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) + let is_bv_nor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) (** Indicates whether the term is a bit-wise XNOR *) - let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) + let is_bv_xnor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) (** Indicates whether the term is a bit-vector concatenation (binary) *) - let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) + let is_bv_concat ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) (** Indicates whether the term is a bit-vector sign extension *) - let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) + let is_bv_signextension ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) (** Indicates whether the term is a bit-vector zero extension *) - let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) + let is_bv_zeroextension ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) (** Indicates whether the term is a bit-vector extraction *) - let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) + let is_bv_extract ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) (** Indicates whether the term is a bit-vector repetition *) - let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) + let is_bv_repeat ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) (** Indicates whether the term is a bit-vector reduce OR *) - let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) + let is_bv_reduceor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) (** Indicates whether the term is a bit-vector reduce AND *) - let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) + let is_bv_reduceand ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) (** Indicates whether the term is a bit-vector comparison *) - let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) + let is_bv_comp ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) (** Indicates whether the term is a bit-vector shift left *) - let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) + let is_bv_shiftleft ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) (** Indicates whether the term is a bit-vector logical shift right *) - let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightlogical ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) (** Indicates whether the term is a bit-vector arithmetic shift left *) - let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) + let is_bv_shiftrightarithmetic ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) (** Indicates whether the term is a bit-vector rotate left *) - let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateleft ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) (** Indicates whether the term is a bit-vector rotate right *) - let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateright ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotateleftextended ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_bv_rotaterightextended ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_int_to_bv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_bv_to_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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))) *) - let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) + let is_bv_carry ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) *) - let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + let is_bv_xor3 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) (** The size of a bit-vector sort. *) - let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno + let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) (** Retrieve the int value. *) let get_int ( x : bitvec_num ) = - let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in if r then v else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) - let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno + let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) (** Creates a bit-vector constant. *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - ((Expr.mk_const ctx name (mk_sort ctx size)) :> bitvec_expr) + BitVecExpr(Expr.mk_const ctx name (match (mk_sort ctx size) with BitVecSort(s) -> s)) (** Creates a bit-vector constant. @@ -3448,91 +3528,91 @@ end = struct The argument must have a bit-vector sort. *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnot (context_gno ctx) t#gno) + create_expr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvredand (context_gno ctx) t#gno) + create_expr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvredor (context_gno ctx) t#gno) + create_expr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) (** Bitwise conjunction. The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvand (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvor (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvxor (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnand (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnor (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvxnor (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvneg (context_gno ctx) t#gno) + create_expr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvadd (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsub (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvmul (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) (** Unsigned division. @@ -3544,7 +3624,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvudiv (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) (** Signed division. @@ -3559,7 +3639,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsdiv (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) (** Unsigned remainder. @@ -3569,7 +3649,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvurem (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) (** Signed remainder. @@ -3581,7 +3661,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsrem (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed remainder (sign follows divisor). @@ -3590,7 +3670,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsmod (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) (** Unsigned less-than @@ -3598,9 +3678,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvult (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed less-than @@ -3608,9 +3686,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvslt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2)) (** Unsigned less-than or equal to. @@ -3618,9 +3694,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvule (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed less-than or equal to. @@ -3628,9 +3702,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsle (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2)) (** Unsigned greater than or equal to. @@ -3638,19 +3710,15 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvuge (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed greater than or equal to. The arguments must have the same bit-vector sort. *) - let mk_SGE ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsge (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Booleans.create_expr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2)) (** Unsigned greater-than. @@ -3658,9 +3726,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvugt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed greater-than. @@ -3668,9 +3734,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsgt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2)) (** Bit-vector concatenation. @@ -3681,9 +3745,7 @@ end = struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVectors.BitVecExpr(create ctx (Z3native.mk_concat (context_gno ctx) - (gno (match t1 with BitVecExpr(b) -> b)) - (gno (match t2 with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) (** Bit-vector extraction. @@ -3694,7 +3756,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_extract (context_gno ctx) high low t#gno) + create_expr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) (** Bit-vector sign extension. @@ -3704,7 +3766,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_sign_ext (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) (** Bit-vector zero extension. @@ -3715,7 +3777,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_zero_ext (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) (** Bit-vector repetition. @@ -3723,7 +3785,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_repeat (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) (** Shift left. @@ -3738,9 +3800,8 @@ end = struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_bvshl (context_gno ctx) - (gno (match t1 with BitVecExpr(b) -> b)) - (gno (match t2 with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) + (** Logical shift right @@ -3754,9 +3815,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_bvlshr (context_gno ctx) - (gno (match t1 with BitVecExpr(b) -> b)) - (gno (match t2 with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) (** Arithmetic shift right @@ -3772,9 +3831,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_bvashr (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + create_expr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) (** Rotate Left. @@ -3783,7 +3840,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_rotate_left (context_gno ctx) i (gno (match t with BoolExpr(b) -> b)))) + create_expr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) (** Rotate Right. @@ -3792,7 +3849,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_rotate_right (context_gno ctx) i (gno (match t with BoolExpr(b) -> b)))) + create_expr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) (** Rotate Left. @@ -3801,9 +3858,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_ext_rotate_left (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + create_expr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) (** Rotate Right. @@ -3813,22 +3868,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_ext_rotate_right (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - - (** - 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. - *) - let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - BitVecExpr(create ctx (Z3native.mk_int2bv (context_gno ctx) n (gno (match t with IntExpr(b) -> b)))) + create_expr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) (** Create an integer from the bit-vector argument . @@ -3845,8 +3885,8 @@ end = struct The argument must be of bit-vector sort. *) - let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = - (new int_expr ctx)#create_obj (Z3native.mk_bv2int (context_gno ctx) t#gno signed) + let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = + Arithmetic.Integers.create_expr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3854,10 +3894,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - BoolExpr(create ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)) - signed)) + Booleans.create_expr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3865,19 +3902,15 @@ end = struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - + Booleans.create_expr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2)) + (** Create a predicate that checks that the bit-wise subtraction does not overflow. The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2)) (** Create a predicate that checks that the bit-wise subtraction does not underflow. @@ -3885,10 +3918,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - BoolExpr(create ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)) - signed)) + Booleans.create_expr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3896,17 +3926,15 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2)) (** Create a predicate that checks that the bit-wise negation does not overflow. The arguments must be of bit-vector sort. *) - let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr) = - BoolExpr(create ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (gno (match t with BitVecExpr(b) -> b)))) + let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = + Booleans.create_expr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t)) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3914,10 +3942,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - BoolExpr(create ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)) - signed)) + Booleans.create_expr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3925,9 +3950,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2)) (** Create a bit-vector numeral. @@ -3936,7 +3959,7 @@ end = struct @param size the size of the bit-vector *) let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = - (new bitvec_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_sort ctx size)#gno) + create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx size))) end (** Functions to manipulate proof expressions *) @@ -3946,17 +3969,17 @@ end = struct (** Indicates whether the term is a Proof for the expression 'true'. *) - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) + let is_true ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) (** Indicates whether the term is a proof for a fact asserted by the user. *) - let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) + let is_asserted ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_goal ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) (** Indicates whether the term is proof via modus ponens @@ -3967,7 +3990,7 @@ end = struct [mp T1 T2]: q The second antecedents may also be a proof for (iff p q). *) - let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) + let is_modus_ponens ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) (** Indicates whether the term is a proof for (R t t), where R is a reflexive relation. @@ -3976,7 +3999,7 @@ end = struct equivalence modulo namings, equality and equivalence. That is, R is either '~', '=' or 'iff'. *) - let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) + let is_reflexivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) (** Indicates whether the term is proof by symmetricity of a relation @@ -3986,7 +4009,7 @@ end = struct [symmetry T1]: (R s t) T1 is the antecedent of this proof object. *) - let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) + let is_symmetry ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) (** Indicates whether the term is a proof by transitivity of a relation @@ -3997,7 +4020,7 @@ end = struct T2: (R s u) [trans T1 T2]: (R t u) *) - let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) + let is_transitivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) (** Indicates whether the term is a proof by condensed transitivity of a relation @@ -4017,7 +4040,7 @@ end = struct if there is a path from s to t, if we view every antecedent (R a b) as an edge between a and b. *) - let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_Transitivity_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) (** @@ -4030,7 +4053,7 @@ end = struct Remark: if t_i == s_i, then the antecedent Ti is suppressed. That is, reflexivity proofs are supressed to save space. *) - let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) + let is_monotonicity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) (** Indicates whether the term is a quant-intro proof @@ -4039,7 +4062,7 @@ end = struct T1: (~ p q) [quant-intro T1]: (~ (forall (x) p) (forall (x) q)) *) - let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) + let is_quant_intro ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) (** Indicates whether the term is a distributivity proof object. @@ -4056,7 +4079,7 @@ end = struct Remark. This rule is used by the CNF conversion pass and instantiated by f = or, and g = and. *) - let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_distributivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) (** Indicates whether the term is a proof by elimination of AND @@ -4065,7 +4088,7 @@ end = struct T1: (and l_1 ... l_n) [and-elim T1]: l_i *) - let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) + let is_and_elimination ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) (** Indicates whether the term is a proof by eliminiation of not-or @@ -4074,7 +4097,7 @@ end = struct T1: (not (or l_1 ... l_n)) [not-or-elim T1]: (not l_i) *) - let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_or_elimination ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) (** Indicates whether the term is a proof by rewriting @@ -4088,11 +4111,11 @@ end = struct Remark: if f is bool, then = is iff. Examples: - (= (+ ( x : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) + (= (+ ( x : Expr.expr ) 0) x) + (= (+ ( x : Expr.expr ) 1 2) (+ 3 x)) + (iff (or ( x : Expr.expr ) false) x) *) - let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) + let is_rewrite ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) (** Indicates whether the term is a proof by rewriting @@ -4107,14 +4130,14 @@ end = struct - When converting bit-vectors to Booleans (BIT2BOOL=true) - When pulling ite expression up (PULL_CHEAP_ITE_TREES=true) *) - let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) + let is_rewrite_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) (** Indicates whether the term is a proof for pulling quantifiers out. @@ -4123,7 +4146,7 @@ end = struct This proof object is only used if the parameter PROOF_MODE is 1. This proof object has no antecedents *) - let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_pull_quant_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) (** Indicates whether the term is a proof for pushing quantifiers in. @@ -4136,7 +4159,7 @@ end = struct This proof object has no antecedents *) - let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) + let is_push_quant ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) (** Indicates whether the term is a proof for elimination of unused variables. @@ -4148,34 +4171,34 @@ end = struct This proof object has no antecedents. *) - let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + let is_elim_unused_vars ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. + (iff (forall (x) (or (not (= ( x : Expr.expr ) t)) P[x])) P[t]) + if ( x : Expr.expr ) does not occur in t. This proof object has no antecedents. Several variables can be eliminated simultaneously. *) - let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) + let is_der ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) (** Indicates whether the term is a proof for quantifier instantiation A proof of (or (not (forall (x) (P x))) (P a)) *) - let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) + let is_quant_inst ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) (** Indicates whether the term is a hypthesis marker. Mark a hypothesis in a natural deduction style proof. *) - let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) + let is_hypothesis ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) (** Indicates whether the term is a proof by lemma @@ -4187,7 +4210,7 @@ end = struct It converts the proof in a proof for (or (not l_1) ... (not l_n)), when T1 contains the hypotheses: l_1, ..., l_n. *) - let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) + let is_lemma ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) (** Indicates whether the term is a proof by unit resolution @@ -4198,7 +4221,7 @@ end = struct T(n+1): (not l_n) [unit-resolution T1 ... T(n+1)]: (or l_1' ... l_m') *) - let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_unit_resolution ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) (** Indicates whether the term is a proof by iff-true @@ -4206,7 +4229,7 @@ end = struct T1: p [iff-true T1]: (iff p true) *) - let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_true ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) (** Indicates whether the term is a proof by iff-false @@ -4214,7 +4237,7 @@ end = struct T1: (not p) [iff-false T1]: (iff p false) *) - let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) + let is_iff_false ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) (** Indicates whether the term is a proof by commutativity @@ -4226,7 +4249,7 @@ end = struct This proof object has no antecedents. Remark: if f is bool, then = is iff. *) - let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_commutativity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) (** Indicates whether the term is a proof for Tseitin-like axioms @@ -4261,7 +4284,7 @@ end = struct unfolding the Boolean connectives in the axioms a small bounded number of steps (=3). *) - let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_axiom ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) (** Indicates whether the term is a proof for introduction of a name @@ -4283,7 +4306,7 @@ end = struct Otherwise: [def-intro]: (= n e) *) - let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) + let is_def_intro ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) (** Indicates whether the term is a proof for application of a definition @@ -4292,7 +4315,7 @@ end = struct F is 'equivalent' to n, given that T1 is a proof that n is a name for F. *) - let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) + let is_apply_def ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) (** Indicates whether the term is a proof iff-oeq @@ -4300,7 +4323,7 @@ end = struct T1: (iff p q) [iff~ T1]: (~ p q) *) - let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) + let is_iff_oeq ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) (** Indicates whether the term is a proof for a positive NNF step @@ -4327,7 +4350,7 @@ end = struct NNF_NEG furthermore handles the case where negation is pushed over Boolean connectives 'and' and 'or'. *) - let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_pos ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) (** Indicates whether the term is a proof for a negative NNF step @@ -4351,7 +4374,7 @@ end = struct [nnf-neg T1 T2 T3 T4]: (~ (not (iff s_1 s_2)) (and (or r_1 r_2) (or r_1' r_2'))) *) - let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_neg ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) (** Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form. @@ -4362,7 +4385,7 @@ end = struct This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO. *) - let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) + let is_nnf_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) (** Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form. @@ -4371,19 +4394,19 @@ end = struct 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. *) - let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) + let is_cnf_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) (** Indicates whether the term is a proof for a Skolemization step Proof for: - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + [sk]: (~ (not (forall ( x : Expr.expr ) (p ( x : Expr.expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : Expr.expr ) (p ( x : Expr.expr ) y)) (p (sk y) y)) This proof object has no antecedents. *) - let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) + let is_skolemize ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) (** Indicates whether the term is a proof by modus ponens for equi-satisfiability. @@ -4393,7 +4416,7 @@ end = struct T2: (~ p q) [mp~ T1 T2]: q *) - let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_modus_ponens_oeq ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) (** Indicates whether the term is a proof for theory lemma @@ -4411,7 +4434,7 @@ end = struct (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. *) - let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) + let is_theory_lemma ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end @@ -4462,8 +4485,8 @@ struct (** Adds the constraints to the given goal. *) (* CMW: assert seems to be a keyword. *) - let assert_ ( x : goal ) ( constraints : bool_expr array ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) e#gno in + let assert_ ( x : goal ) ( constraints : Booleans.bool_expr array ) = + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e) in ignore (Array.map f constraints) ; () @@ -4484,7 +4507,7 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = (new bool_expr (z3obj_gc x))#create_obj (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in + let f i = Booleans.create_expr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) @@ -4599,7 +4622,7 @@ struct Return the (symbolic) value of this entry. *) let get_value ( x : func_entry ) = - create_expr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) + Expr.create (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) (** The number of arguments of the entry. @@ -4611,7 +4634,7 @@ struct *) let get_args ( x : func_entry ) = let n = (get_num_args x) in - let f i = (create_expr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (Expr.create (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** @@ -4639,7 +4662,7 @@ struct (** The (symbolic) `else' value of the function interpretation. *) - let get_else ( x : func_interp ) = create_expr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) + let get_else ( x : func_interp ) = Expr.create (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) (** The arity of the function interpretation @@ -4666,31 +4689,31 @@ struct (** Retrieves the interpretation (the assignment) of in the model. A function declaration of zero arity An expression if the function has an interpretation in the model, null otherwise. *) - let get_const_interp ( x : model ) ( f : func_decl ) = + let get_const_interp ( x : model ) ( f : FuncDecl.func_decl ) = if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then + (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") else - let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) f#gno in + let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in if (Z3native.is_null np) then None else - Some (create_expr (z3obj_gc x) np) + Some (Expr.create (z3obj_gc x) np) (** Retrieves the interpretation (the assignment) of in the model. A Constant An expression if the constant has an interpretation in the model, null otherwise. *) - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + let get_const_interp_e ( x : model ) ( a : Expr.expr ) = get_const_interp x (Expr.get_func_decl a) (** Retrieves the interpretation (the assignment) of a non-constant in the model. A function declaration of non-zero arity A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range f#gnc f#gno))) in + let rec get_func_interp ( x : model ) ( f : FuncDecl.func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) f#gno in + let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in if (Z3native.is_null n) then None else @@ -4700,10 +4723,10 @@ struct raise (Z3native.Exception "Argument was not an array constant") else let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x ((new func_decl f#gc)#create_obj fd) + get_func_interp x (FuncDecl.create (z3obj_gc x) fd) | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); else - let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) f#gno) in + let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) (** The number of constants that have an interpretation in the model. *) @@ -4712,7 +4735,7 @@ struct (** The function declarations of the constants in the model. *) let get_const_decls ( x : model ) = let n = (get_num_consts x) in - let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f @@ -4722,15 +4745,15 @@ struct (** The function declarations of the function interpretations in the model. *) let get_func_decls ( x : model ) = let n = (get_num_consts x) in - let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** All symbols that have an interpretation in the model. *) let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in - let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.append (Array.init n_funcs f) (Array.init n_consts g) (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) @@ -4751,15 +4774,15 @@ struct The evaluation of in the model. *) - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) t#gno completion) in + let eval ( x : model ) ( t : Expr.expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in if not r then raise (ModelEvaluationFailedException "evaluation failed") else - create_expr (z3obj_gc x) v + Expr.create (z3obj_gc x) v (** Alias for eval. *) - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + let evaluate ( x : model ) ( t : Expr.expr ) ( completion : bool ) = eval x t completion (** The number of uninterpreted sorts that the model has an interpretation for. *) @@ -4775,7 +4798,7 @@ struct *) let get_sorts ( x : model ) = let n = (get_num_sorts x) in - let f i = (create_sort (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (Sort.create (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f @@ -4784,10 +4807,10 @@ struct An uninterpreted sort An array of expressions, where each is an element of the universe of *) - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in + let sort_universe ( x : model ) ( s : Sort.sort ) = + let n_univ = AST.ASTVectors.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n = (AST.ASTVectors.get_size n_univ) in + let f i = (AST.ASTVectors.get n_univ i) in Array.init n f (** Conversion of models to strings. @@ -5323,8 +5346,8 @@ struct (** Assert a constraint (or multiple) into the solver. *) - let assert_ ( x : solver ) ( constraints : bool_expr array ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in + let assert_ ( x : solver ) ( constraints : Booleans.bool_expr array ) = + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e)) in ignore (Array.map f constraints) (** @@ -5340,11 +5363,11 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( cs : bool_expr array ) ( ps : bool_expr array ) = + let assert_and_track ( x : solver ) ( cs : Booleans.bool_expr array ) ( ps : Booleans.bool_expr array ) = if ((Array.length cs) != (Array.length ps)) then raise (Z3native.Exception "Argument size mismatch") else - let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) e#gno (Array.get ps i)#gno) in + let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e) (Booleans.gno (Array.get ps i))) in ignore (Array.iteri f cs) (** @@ -5359,24 +5382,24 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( c : bool_expr ) ( p : bool_expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) c#gno p#gno + let assert_and_track ( x : solver ) ( c : Booleans.bool_expr ) ( p : Booleans.bool_expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Booleans.gno c) (Booleans.gno p) (** The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - (AST.ASTVector.get_size a) + let a = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + (AST.ASTVectors.get_size a) (** The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size a) in - let f i = ((new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get a i)#gno) in + let a = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVectors.get_size a) in + let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get a i)) in Array.init n f (** @@ -5386,12 +5409,12 @@ struct *) - let check ( x : solver ) ( assumptions : bool_expr array) = + let check ( x : solver ) ( assumptions : Booleans.bool_expr array) = let r = if ((Array.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (AST.aton assumptions)) + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Booleans.aton assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -5422,7 +5445,7 @@ struct if (Z3native.is_null q) then None else - Some (create_expr (z3obj_gc x) q) + Some (Expr.create (z3obj_gc x) q) (** The unsat core of the last Check. @@ -5432,9 +5455,9 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size cn) in - let f i = (AST.ASTVector.get cn i) in + let cn = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVectors.get_size cn) in + let f i = (AST.ASTVectors.get cn i) in Array.init n f (** @@ -5527,30 +5550,30 @@ struct (** Assert a constraints into the fixedpoint solver. *) - let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in + let assert_ ( x : fixedpoint ) ( constraints : Booleans.bool_expr array ) = + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e)) in ignore (Array.map f constraints) ; () (** Register predicate as recursive relation. *) - let register_relation ( x : fixedpoint ) ( f : func_decl ) = - Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) f#gno + let register_relation ( x : fixedpoint ) ( f : FuncDecl.func_decl ) = + Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (** Add rule into the fixedpoint solver. *) - let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : Symbol.symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : Booleans.bool_expr ) ( name : Symbol.symbol option ) = match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno (Symbol.gno y) + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) (Symbol.gno y) (** Add table fact to the fixedpoint solver. *) - let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = - Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) pred#gno (Array.length args) args + let add_fact ( x : fixedpoint ) ( pred : FuncDecl.func_decl ) ( args : int array ) = + Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (Array.length args) args (** Query the fixedpoint solver. @@ -5558,8 +5581,8 @@ struct 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. *) - let query ( x : fixedpoint ) ( query : bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) query#gno)) with + let query ( x : fixedpoint ) ( query : Booleans.bool_expr ) = + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Booleans.gno query))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -5570,8 +5593,8 @@ struct 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. *) - let query_r ( x : fixedpoint ) ( relations : func_decl array ) = - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (func_declaton relations))) with + let query_r ( x : fixedpoint ) ( relations : FuncDecl.func_decl array ) = + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (FuncDecl.aton relations))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -5595,8 +5618,8 @@ struct (** Update named rule into in the fixedpoint solver. *) - let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) rule#gno (Symbol.gno name) + let update_rule ( x : fixedpoint ) ( rule : Booleans.bool_expr ) ( name : Symbol.symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) (Symbol.gno name) (** Retrieve satisfying instance or instances of solver, @@ -5607,7 +5630,7 @@ struct if (Z3native.is_null q) then None else - Some (create_expr (z3obj_gc x) q) + Some (Expr.create (z3obj_gc x) q) (** Retrieve explanation why fixedpoint engine returned status Unknown. @@ -5618,25 +5641,25 @@ struct (** Retrieve the number of levels explored for a given predicate. *) - let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = - Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) predicate#gno + let get_num_levels ( x : fixedpoint ) ( predicate : FuncDecl.func_decl ) = + Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) (** Retrieve the cover of a predicate. *) - let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = - let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level predicate#gno) in + let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : FuncDecl.func_decl ) = + let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in if (Z3native.is_null q) then None else - Some (create_expr (z3obj_gc x) q) + Some (Expr.create (z3obj_gc x) q) (** Add property about the predicate. The property is added at level. *) - let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level predicate#gno property#gno + let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : FuncDecl.func_decl ) ( property : Expr.expr ) = + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) (** Retrieve internal string representation of fixedpoint object. @@ -5646,31 +5669,31 @@ struct (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) f#gno (Array.length kinds) (Symbol.aton kinds) + let set_predicate_representation ( x : fixedpoint ) ( f : FuncDecl.func_decl ) ( kinds : Symbol.symbol array ) = + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Symbol.aton kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. *) - let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (AST.aton queries) + let to_string_q ( x : fixedpoint ) ( queries : Booleans.bool_expr array ) = + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Booleans.aton queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get v i)#gno in + let v = (AST.ASTVectors.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVectors.get_size v) in + let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get v i)) in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get v i)#gno in + let v = (AST.ASTVectors.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVectors.get_size v) in + let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get v i)) in Array.init n f (** @@ -5754,10 +5777,10 @@ struct @param formula Formula to be checked for consistency in conjunction with assumptions. @return A string representation of the benchmark. *) - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Booleans.bool_expr array ) ( formula : Booleans.bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (AST.aton assumptions) - formula#gno + (Array.length assumptions) (Booleans.aton assumptions) + (Booleans.gno formula) (** Parse the given string using the SMT-LIB parser. @@ -5768,7 +5791,7 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5779,16 +5802,16 @@ struct Z3native.parse_smtlib_string (context_gno ctx) str cs (Symbol.aton sort_names) - (AST.aton sorts) + (Sort.aton sorts) cd (Symbol.aton decl_names) - (func_declaton decls) + (FuncDecl.aton decls) (** Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5799,10 +5822,10 @@ struct Z3native.parse_smtlib_file (context_gno ctx) file_name cs (Symbol.aton sort_names) - (AST.aton sorts) + (Sort.aton sorts) cd (Symbol.aton decl_names) - (func_declaton decls) + (FuncDecl.aton decls) (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. @@ -5814,7 +5837,7 @@ struct *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = ((create_expr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) :> bool_expr) in + let f i = Booleans.create_expr ctx (Z3native.get_smtlib_formula (context_gno ctx) i) in Array.init n f @@ -5828,7 +5851,7 @@ struct *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = ((create_expr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) :> bool_expr ) in + let f i = Booleans.create_expr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i) in Array.init n f (** @@ -5841,7 +5864,7 @@ struct *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in - let f i = (new func_decl ctx)#create_obj (Z3native.get_smtlib_decl (context_gno ctx) i) in + let f i = FuncDecl.create ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f (** @@ -5854,7 +5877,7 @@ struct *) let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in - let f i = (create_sort ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in + let f i = (Sort.create ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in Array.init n f (** @@ -5863,7 +5886,7 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5877,13 +5900,13 @@ struct (Sort.aton sorts) cd (Symbol.aton decl_names) - (func_declaton decls) + (FuncDecl.aton decls) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5897,7 +5920,7 @@ struct (Sort.aton sorts) cd (Symbol.aton decl_names) - (func_declaton decls) + (FuncDecl.aton decls) end From 34a72942bfbf752e7eb02e81672539fd31252620 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 5 Feb 2013 00:51:20 +0000 Subject: [PATCH 054/248] ML API: documentation fixes. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 246 +++++++++++++++++++++++++++-------------------- 1 file changed, 141 insertions(+), 105 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 4cf41f420..aeb9c0d03 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -331,8 +331,10 @@ module rec AST : sig type ast = z3_native_object +(**/**) val create : context -> Z3native.ptr -> ast val aton : ast array -> Z3native.ptr array +(**/**) module ASTVectors : sig type ast_vector @@ -346,6 +348,7 @@ sig end = struct type ast = z3_native_object + (**/**) let create ( ctx : context ) ( no : Z3native.ptr ) = let res : z3_native_object = { m_ctx = ctx ; m_n_obj = null ; @@ -358,7 +361,7 @@ end = struct let aton (a : ast array) = let f (e : ast) = (z3obj_gno e) in Array.map f a - + (**/**) (** Vectors of ASTs *) module ASTVectors = @@ -615,7 +618,6 @@ end = struct (**/**) end - (** The Sort module implements type information for ASTs *) and Sort : sig @@ -631,6 +633,7 @@ end = struct type sort = Sort of AST.ast type uninterpreted_sort = UninterpretedSort of sort + (**/**) let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) @@ -657,6 +660,7 @@ end = struct | FINITE_DOMAIN_SORT | RELATION_SORT -> Sort(q) | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + (**/**) (** @@ -728,10 +732,9 @@ sig val get_decl_kind : func_decl -> Z3enums.decl_kind val get_arity : func_decl -> int end = struct - open Sort - type func_decl = FuncDecl of AST.ast + (**/**) let create ( ctx : context ) ( no : Z3native.ptr ) = let res = { m_ctx = ctx ; m_n_obj = null ; @@ -741,7 +744,7 @@ end = struct (z3obj_create res) ; FuncDecl(res) - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort array ) ( range : Sort.sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; @@ -750,7 +753,7 @@ end = struct (z3obj_create res) ; FuncDecl(res) - let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let create_pdr ( ctx : context) ( prefix : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; @@ -766,7 +769,8 @@ end = struct let aton (a : func_decl array) = let f (e : func_decl) = (gno e) in Array.map f a - + (**/**) + (** Parameters of Func_Decls *) module Parameter = struct @@ -833,18 +837,16 @@ end = struct | _ -> raise (Z3native.Exception "parameter is not a rational string") end - open Parameter - (** Creates a new function declaration. *) - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort array ) ( range : Sort.sort ) = create_ndr ctx name domain range (** Creates a new function declaration. *) - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = mk_func_decl ctx (Symbol.mk_string ctx name) domain range (** @@ -852,19 +854,19 @@ end = struct *) - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = create_pdr ctx prefix domain range (** Creates a new constant function declaration. *) - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : Sort.sort ) = create_ndr ctx name [||] range (** Creates a new constant function declaration. *) - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : Sort.sort ) = create_ndr ctx (Symbol.mk_string ctx name) [||] range (** @@ -872,7 +874,7 @@ end = struct *) - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : Sort.sort ) = create_pdr ctx prefix [||] range @@ -945,13 +947,13 @@ end = struct let get_parameters ( x : func_decl ) = let n = (get_num_parameters x) in let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> P_Srt (Sort.create (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> P_Ast (AST.create (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> P_Fdl (create (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> Parameter.P_Srt (Sort.create (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> Parameter.P_Ast (AST.create (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (create (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) ) in mk_list f n @@ -977,6 +979,7 @@ sig type param_descrs = z3_native_object val create : context -> Z3native.ptr -> param_descrs + val validate : param_descrs -> params -> unit end end = struct type params = z3_native_object @@ -998,6 +1001,7 @@ end = struct type param_descrs = z3_native_object val create : context -> Z3native.ptr -> param_descrs + val validate : param_descrs -> params -> unit end = struct type param_descrs = z3_native_object @@ -1025,7 +1029,7 @@ end = struct let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - + (** The size of the ParamDescrs. *) let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) @@ -1092,7 +1096,7 @@ end = struct let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) end -(** General expressions (terms), including Boolean logic *) +(** General expressions (terms) *) and Expr : sig type expr = Expr of AST.ast @@ -1111,6 +1115,7 @@ sig end = struct type expr = Expr of AST.ast + (**/**) let create ( ctx : context ) ( obj : Z3native.ptr ) = if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then (match (Quantifiers.create ctx obj) with Quantifiers.Quantifier(e) -> e) @@ -1148,7 +1153,12 @@ end = struct let gc ( x : expr ) = match x with Expr(a) -> (z3obj_gc a) let gnc ( x : expr ) = match x with Expr(a) -> (z3obj_gnc a) let gno ( x : expr ) = match x with Expr(a) -> (z3obj_gno a) - + + let aton (a : expr array) = + let f (e : expr) = (gno e) in + Array.map f a + (**/**) + (** Returns a simplified version of the expression. @param p A set of parameters to configure the simplifier @@ -1405,10 +1415,6 @@ end = struct *) let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : Sort.sort ) = create ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) - - let aton (a : expr array) = - let f (e : expr) = (gno e) in - Array.map f a end (** Boolean expressions *) @@ -1427,6 +1433,7 @@ end = struct type bool_expr = BoolExpr of Expr.expr type bool_sort = BoolSort of Sort.sort + (**/**) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = let a = (AST.create ctx no) in BoolExpr(Expr.Expr(a)) @@ -1441,6 +1448,7 @@ end = struct let aton ( a : bool_expr array ) = let f (e : bool_expr) = (gno e) in Array.map f a + (**/**) let mk_sort ( ctx : context ) = BoolSort(Sort.create ctx (Z3native.mk_bool_sort (context_gno ctx))) @@ -1542,6 +1550,7 @@ sig end = struct type quantifier = Quantifier of Expr.expr + (**/**) let create ( ctx : context ) ( no : Z3native.ptr ) = let a = (AST.create ctx no) in Quantifier(Expr.Expr(a)) @@ -1549,7 +1558,61 @@ end = struct let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) - + (**/**) + + (** Quantifier patterns + + 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. + *) + module Patterns : + sig + type pattern = Pattern of AST.ast + + val create : context -> Z3native.ptr -> pattern + val aton : pattern array -> Z3native.ptr array + end = struct + type pattern = Pattern of AST.ast + + (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + Pattern(res) + + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) + let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) + let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) + + let aton (a : pattern array) = + let f (e : pattern) = (gno e) in + Array.map f a + (**/**) + + (** + The number of terms in the pattern. + *) + let get_num_terms ( x : pattern ) = + Z3native.get_pattern_num_terms (gnc x) (gno x) + + (** + The terms in the pattern. + *) + let get_terms ( x : pattern ) = + let n = (get_num_terms x) in + let f i = (Expr.create (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in + Array.init n f + + (** + A string representation of the pattern. + *) + let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) + end (** The de-Burijn index of a bound variable. @@ -1575,58 +1638,6 @@ end = struct else Z3native.get_index_value (Expr.gnc x) (Expr.gno x) - (** Quantifier patterns - - 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. - *) - module Patterns : - sig - type pattern = Pattern of AST.ast - - val create : context -> Z3native.ptr -> pattern - val aton : pattern array -> Z3native.ptr array - end = struct - type pattern = Pattern of AST.ast - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - Pattern(res) - - let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) - let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) - let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - - (** - The number of terms in the pattern. - *) - let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms (gnc x) (gno x) - - (** - The terms in the pattern. - *) - let get_terms ( x : pattern ) = - let n = (get_num_terms x) in - let f i = (Expr.create (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in - Array.init n f - - (** - A string representation of the pattern. - *) - let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) - - let aton (a : pattern array) = - let f (e : pattern) = (gno e) in - Array.map f a - end - (** Indicates whether the quantifier is universal. *) @@ -1849,6 +1860,7 @@ end = struct type array_expr = ArrayExpr of Expr.expr type array_sort = ArraySort of Sort.sort + (**/**) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = let e = (Expr.create ctx no) in ArrayExpr(e) @@ -1868,7 +1880,7 @@ end = struct let aton (a : array_expr array) = let f (e : array_expr) = (egno e) in Array.map f a - + (**/**) (** Create a new array sort. @@ -2120,6 +2132,7 @@ sig end = struct type finite_domain_sort = FiniteDomainSort of Sort.sort + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = let s = (Sort.create ctx no) in FiniteDomainSort(s) @@ -2127,7 +2140,8 @@ end = struct let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gc s) let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gnc s) let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s))-> (z3obj_gno s) - + (**/**) + (** Create a new finite domain sort. *) @@ -2168,6 +2182,7 @@ sig end = struct type relation_sort = RelationSort of Sort.sort + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = let s = (Sort.create ctx no) in RelationSort(s) @@ -2175,7 +2190,8 @@ end = struct let gc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gc s) let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gnc s) let gno ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s))-> (z3obj_gno s) - + (**/**) + (** Indicates whether the term is of a relation sort. *) @@ -2306,6 +2322,7 @@ end = struct type datatype_expr = DatatypeExpr of Expr.expr type datatype_sort = DatatypeSort of Sort.sort + (**/**) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = let e = (Expr.create ctx no) in DatatypeExpr(e) @@ -2317,19 +2334,24 @@ end = struct let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gc s) let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gnc s) let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s))-> (z3obj_gno s) - + (**/**) (** Constructors *) - module Constructor = - struct + module Constructor : sig + type constructor + val create : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> constructor + val aton : constructor array -> Z3native.ptr array + end = struct type constructor_extra = { m_n : int; mutable m_tester_decl : FuncDecl.func_decl option; mutable m_constructor_decl : FuncDecl.func_decl option ; mutable m_accessor_decls : FuncDecl.func_decl array option} + type constructor = Constructor of (z3_native_object * constructor_extra) - let create_ssssi ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = + (**/**) + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -2356,6 +2378,10 @@ end = struct let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; Constructor(no, ex) + + let aton ( a : constructor array ) = + let f (e : constructor) = match e with Constructor(no, ex) -> (z3obj_gno no)in + Array.map f a let init_extra ( x : constructor ) = match x with Constructor(no, ex) -> @@ -2367,7 +2393,8 @@ end = struct ex.m_accessor_decls <- Some (let f e = (FuncDecl.create (z3obj_gc no) e) in Array.map f c) ; () | _ -> () - + (**/**) + let get_n ( x : constructor ) = match x with Constructor(no, ex) -> ex.m_n @@ -2389,12 +2416,7 @@ end = struct match ex.m_accessor_decls with | Some(s) -> s | None -> init_extra x ; accessor_decls x - - let aton ( a : constructor array ) = - let f (e : constructor) = match e with Constructor(no, ex) -> (z3obj_gno no)in - Array.map f a - - + (** The number of fields of the constructor. *) let get_num_fields ( x : constructor ) = get_n x @@ -2413,6 +2435,7 @@ end = struct struct type constructor_list = z3_native_object + (**/**) let create ( ctx : context )( c : Constructor.constructor array ) = let res : constructor_list = { m_ctx = ctx ; m_n_obj = null ; @@ -2427,6 +2450,7 @@ end = struct let aton (a : constructor_list array) = let f (e : constructor_list) = (z3obj_gno e) in Array.map f a + (**/**) end (* DATATYPES *) @@ -2441,7 +2465,7 @@ end = struct referring to one of the recursive datatypes that is declared. *) let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array) = - Constructor.create_ssssi ctx name recognizer field_names sorts sort_refs + Constructor.create ctx name recognizer field_names sorts sort_refs (** @@ -2530,6 +2554,7 @@ end = struct mutable _testerdecls : FuncDecl.func_decl array } type enum_sort = EnumSort of (Sort.sort * enum_sort_data) + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = let s = (Sort.create ctx no) in let e = { _constdecls = (let f e = FuncDecl.create ctx e in (Array.map f cdecls)) ; @@ -2539,7 +2564,7 @@ end = struct let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gc s) let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gnc s) let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_)-> (z3obj_gno s) - + (**/**) (** Create a new enumeration sort. @@ -2576,6 +2601,7 @@ end = struct _taildecl : FuncDecl.func_decl } type list_sort = ListSort of (Sort.sort * list_sort_data) + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = let s = (Sort.create ctx no) in let e = {_nildecl = FuncDecl.create ctx nildecl; @@ -2589,7 +2615,7 @@ end = struct let sgc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gc s) let sgnc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gnc s) let sgno ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_)-> (z3obj_gno s) - + (**/**) (** Create a new list sort. *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : Sort.sort ) = @@ -2629,6 +2655,7 @@ sig end = struct type tuple_sort = TupleSort of Sort.sort + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = let s = (Sort.create ctx no) in TupleSort(s) @@ -2636,6 +2663,7 @@ end = struct let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gc s) let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gnc s) let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s))-> (z3obj_gno s) + (**/**) (** Create a new tuple sort. *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : Sort.sort array ) = @@ -2736,6 +2764,7 @@ end = struct type arith_sort = ArithSort of Sort.sort type arith_expr = ArithExpr of Expr.expr + (**/**) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = ArithExpr(Expr.create ctx no) @@ -2749,6 +2778,10 @@ end = struct let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) + let aton (a : arith_expr array) = + let f (e : arith_expr) = (egno e) in + Array.map f a + (**/**) module rec Integers : sig @@ -2764,6 +2797,7 @@ end = struct type int_expr = IntExpr of arith_expr type int_num = IntNum of int_expr + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = IntSort(Arithmetic.create_sort ctx no) @@ -2782,6 +2816,7 @@ end = struct let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) + (**/**) (** Create a new integer sort. *) let mk_sort ( ctx : context ) = @@ -2878,6 +2913,7 @@ end = struct type real_expr = RealExpr of arith_expr type rat_num = RatNum of real_expr + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = RealSort(Arithmetic.create_sort ctx no) @@ -2896,7 +2932,8 @@ end = struct let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - + (**/**) + (** Create a real sort. *) let mk_sort ( ctx : context ) = create_sort ctx (Z3native.mk_real_sort (context_gno ctx)) @@ -2979,12 +3016,14 @@ end = struct end = struct type algebraic_num = AlgebraicNum of arith_expr + (**/**) let create_num ( ctx : context ) ( no : Z3native.ptr ) = AlgebraicNum(Arithmetic.create_expr ctx no) let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) + (**/**) (** Return a upper bound for a given real algebraic number. @@ -3015,10 +3054,6 @@ end = struct let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) end - let aton (a : arith_expr array) = - let f (e : arith_expr) = (egno e) in - Array.map f a - (** Indicates whether the term is of integer sort. *) @@ -3188,7 +3223,6 @@ end = struct Booleans.create_expr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2)) end - (** Functions to manipulate bit-vector expressions *) and BitVectors : sig @@ -3204,6 +3238,7 @@ end = struct type bitvec_expr = BitVecExpr of Expr.expr type bitvec_num = BitVecNum of bitvec_expr + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = BitVecSort(Sort.create ctx no) @@ -3222,6 +3257,7 @@ end = struct let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) + (**/**) (** Create a new bit-vector sort. From 23febf13c40b56d7e7fe3fa4bd071c1b8c57c87d Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 19:49:27 +0000 Subject: [PATCH 055/248] ML API: basic structure and interface Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 81 +- scripts/update_api.py | 30 +- src/api/ml/Makefile | 2 +- src/api/ml/z3.ml | 2714 +++++++++++++++++++---------------------- 4 files changed, 1380 insertions(+), 1447 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index bea2939b6..a187bf9cb 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1340,10 +1340,17 @@ class MLComponent(Component): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) + cmis = '%s/z3enums.cmi %s/z3native.cmi %s/z3.cmi' % (src_dir,src_dir,src_dir) + out.write('%s/z3enums.cmi: %s/z3enums.mli\n' % (src_dir,src_dir)) + out.write('\t%s -I %s -c %s/z3enums.mli\n' % (OCAMLC,src_dir,src_dir)) + out.write('%s/z3native.cmi: %s/z3native.mli\n' % (src_dir,src_dir)) + out.write('\t%s -I %s -c %s/z3native.mli\n' % (OCAMLC,src_dir,src_dir)) + out.write('%s/z3.cmi: %s/z3.mli\n' % (src_dir,src_dir)) + out.write('\t%s -I %s -c %s/z3.mli\n' % (OCAMLC,src_dir,src_dir)) out.write('api/ml/libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, src_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') - out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(src_dir, mlfile)) out.write('\n') @@ -1351,7 +1358,7 @@ class MLComponent(Component): if DEBUG_MODE: out.write('-g ') out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) - out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') @@ -2716,6 +2723,76 @@ def mk_z3consts_ml(api_files): linenum = linenum + 1 if VERBOSE: print "Generated '%s/z3enums.ml'" % ('%s' % gendir) + efile = open('%s.mli' % os.path.join(gendir, "z3enums"), 'w') + efile.write('(* Automatically generated file *)\n\n') + efile.write('(** The enumeration types of Z3. *)\n\n') + for api_file in api_files: + api_file_c = ml.find_file(api_file, ml.name) + api_file = os.path.join(api_file_c.src_dir, api_file) + + api = open(api_file, 'r') + + SEARCHING = 0 + FOUND_ENUM = 1 + IN_ENUM = 2 + + mode = SEARCHING + decls = {} + idx = 0 + + linenum = 1 + for line in api: + m1 = blank_pat.match(line) + m2 = comment_pat.match(line) + if m1 or m2: + # skip blank lines and comments + linenum = linenum + 1 + elif mode == SEARCHING: + m = typedef_pat.match(line) + if m: + mode = FOUND_ENUM + m = typedef2_pat.match(line) + if m: + mode = IN_ENUM + decls = {} + idx = 0 + elif mode == FOUND_ENUM: + m = openbrace_pat.match(line) + if m: + mode = IN_ENUM + decls = {} + idx = 0 + else: + assert False, "Invalid %s, line: %s" % (api_file, linenum) + else: + assert mode == IN_ENUM + words = re.split('[^\-a-zA-Z0-9_]+', line) + m = closebrace_pat.match(line) + if m: + name = words[1] + if name not in DeprecatedEnums: + efile.write('(** %s *)\n' % name[3:]) + efile.write('type %s =\n' % name[3:]) # strip Z3_ + for k, i in decls.iteritems(): + efile.write(' | %s \n' % k[3:]) # strip Z3_ + efile.write('\n') + efile.write('(** Convert %s to int*)\n' % name[3:]) + efile.write('val int_of_%s : %s -> int\n' % (name[3:], name[3:])) # strip Z3_ + efile.write('(** Convert int to %s*)\n' % name[3:]) + efile.write('val %s_of_int : int -> %s\n' % (name[3:],name[3:])) # strip Z3_ + efile.write('\n') + mode = SEARCHING + else: + if words[2] != '': + if len(words[2]) > 1 and words[2][1] == 'x': + idx = int(words[2], 16) + else: + idx = int(words[2]) + decls[words[1]] = idx + idx = idx + 1 + linenum = linenum + 1 + if VERBOSE: + print "Generated '%s/z3enums.mli'" % ('%s' % gendir) def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index c730a325e..6e9c14355 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1147,49 +1147,66 @@ def mk_ml(): return ml_dir = get_component('ml').src_dir ml_nativef = os.path.join(ml_dir, 'z3native.ml') + ml_nativefi = os.path.join(ml_dir, 'z3native.mli') ml_wrapperf = os.path.join(ml_dir, 'z3native.c') ml_native = open(ml_nativef, 'w') + ml_i = open(ml_nativefi, 'w') ml_native.write('(* Automatically generated file *)\n\n') ml_native.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') + ml_i.write('(* Automatically generated file *)\n\n') + ml_i.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') ml_native.write('open Z3enums\n\n') ml_native.write('(**/**)\n') ml_native.write('type ptr\n') + ml_i.write('type ptr\n') ml_native.write('and z3_symbol = ptr\n') + ml_i.write('and z3_symbol = ptr\n') for k, v in Type2Str.iteritems(): if is_obj(k): ml_native.write('and %s = ptr\n' % v.lower()) + ml_i.write('and %s = ptr\n' % v.lower()) ml_native.write('\n') - ml_native.write('external is_null : ptr -> bool\n') - ml_native.write(' = "n_is_null"\n\n') - ml_native.write('external mk_null : unit -> ptr\n') - ml_native.write(' = "n_mk_null"\n\n') + ml_i.write('\n') + ml_native.write('external is_null : ptr -> bool\n = "n_is_null"\n\n') + ml_native.write('external mk_null : unit -> ptr\n = "n_mk_null"\n\n') ml_native.write('exception Exception of string\n\n') + ml_i.write('val is_null : ptr -> bool\n') + ml_i.write('val mk_null : unit -> ptr\n') + ml_i.write('exception Exception of string\n\n') # ML declarations - ml_native.write(' module ML2C = struct\n\n') + ml_native.write('module ML2C = struct\n\n') for name, result, params in _dotnet_decls: ml_native.write(' external n_%s : ' % ml_method_name(name)) + ml_i.write('val %s : ' % ml_method_name(name)) ip = inparams(params) op = outparams(params) if len(ip) == 0: - ml_native.write(' unit -> ') + ml_native.write(' unit -> ') for p in ip: ml_native.write('%s -> ' % param2ml(p)) + ml_i.write('%s -> ' % param2ml(p)) if len(op) > 0: ml_native.write('(') + ml_i.write('(') first = True if result != VOID or len(op) == 0: ml_native.write('%s' % type2ml(result)) + ml_i.write('%s' % type2ml(result)) first = False for p in op: if first: first = False else: ml_native.write(' * ') + ml_i.write(' * ') ml_native.write('%s' % param2ml(p)) + ml_i.write('%s' % param2ml(p)) if len(op) > 0: ml_native.write(')') + ml_i.write(')') ml_native.write('\n') + ml_i.write('\n') ml_native.write(' = "n_%s"\n' % ml_method_name(name)) if len(ip) > 5: ml_native.write(' "n_%s_bytecode"\n' % ml_method_name(name)) @@ -1201,6 +1218,7 @@ def mk_ml(): ip = inparams(params) op = outparams(params) ml_native.write(' let %s ' % ml_method_name(name)) + first = True i = 0; for p in params: diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile index ad5442327..abcefa4af 100644 --- a/src/api/ml/Makefile +++ b/src/api/ml/Makefile @@ -7,4 +7,4 @@ all: doc: *.ml mkdir -p doc - ocamldoc -html -d doc -I ../../../bld_dbg/api/ml -sort *.ml -hide Z3 + ocamldoc -html -d doc -I ../../../bld_dbg/api/ml -sort *.mli -hide Z3 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index aeb9c0d03..ea8c9576e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,8 +7,479 @@ open Z3enums -(** Interaction logging for Z3 +(* Some helpers. *) +let null = Z3native.mk_null() +let is_null o = (Z3native.is_null o) + +(* Internal types *) +type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } +type context = z3_native_context + + + +type z3_native_object = { + m_ctx : context ; + mutable m_n_obj : Z3native.ptr ; + inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; + dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } + + +(* Symbol types *) +type int_symbol = z3_native_object +type string_symbol = z3_native_object + +type symbol = + | S_Int of int_symbol + | S_Str of string_symbol + +(* AST types *) +type ast = z3_native_object +type ast_vector = z3_native_object +type ast_map = z3_native_object + +(* FuncDecl types *) +type func_decl = FuncDecl of ast + +(* Sort types *) +type sort = Sort of ast +type uninterpreted_sort = UninterpretedSort of sort +type bool_sort = BoolSort of sort +type array_sort = ArraySort of sort +type set_sort = SetSort of sort +type datatype_sort = DatatypeSort of sort +type relation_sort = RelationSort of sort +type finite_domain_sort = FiniteDomainSort of sort +type enum_sort = EnumSort of sort +type list_sort = ListSort of sort +type tuple_sort = TupleSort of sort +type arith_sort = ArithSort of sort +type bitvec_sort = BitVecSort of sort + +type int_sort = IntSort of arith_sort +type real_sort = RealSort of arith_sort + +(* FuncDecl parameters *) +type parameter = + | P_Int of int + | P_Dbl of float + | P_Sym of symbol + | P_Srt of sort + | P_Ast of ast + | P_Fdl of func_decl + | P_Rat of string +type params = z3_native_object +type param_descrs = z3_native_object + +(* Expr types *) +type expr = Expr of ast + +type bool_expr = BoolExpr of expr +type arith_expr = ArithExpr of expr +type int_expr = IntExpr of arith_expr +type real_expr = RealExpr of arith_expr +type bitvec_expr = BitVecExpr of expr +type array_expr = ArrayExpr of expr +type datatype_expr = DatatypeExpr of expr + +(* Numerals *) +type int_num = IntNum of int_expr +type rat_num = RatNum of real_expr +type algebraic_num = AlgebraicNum of arith_expr +type bitvec_num = BitVecNum of bitvec_expr + +(* Quantifier stuff *) +type quantifier = Quantifier of expr +type pattern = Pattern of ast + +(* Datatype stuff *) +type constructor_extra = { + m_n : int; + mutable m_tester_decl : func_decl option; + mutable m_constructor_decl : func_decl option ; + mutable m_accessor_decls : func_decl array option} + +type constructor = Constructor of (z3_native_object * constructor_extra) +type constructor_list = z3_native_object + +(* Tactical interface *) +type goal = z3_native_object +type model = z3_native_object +type func_interp = z3_native_object +type func_entry = z3_native_object +type probe = z3_native_object +type tactic = z3_native_object +type apply_result = z3_native_object +type solver = z3_native_object +type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE +type statistics = z3_native_object +type statistics_entry = { + mutable m_key : string; + mutable m_is_int : bool ; + mutable m_is_float : bool ; + mutable m_int : int ; + mutable m_float : float } +type fixedpoint = z3_native_object + + +(** Internal stuff *) +module Internal = +struct + let dispose_context ctx = + if ctx.m_n_obj_cnt == 0 then ( + (* Printf.printf "Disposing context \n" ; *) + (Z3native.del_context ctx.m_n_ctx) + ) else ( + Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; + (* re-queue for finalization? *) + ) + + let create_context settings = + let cfg = Z3native.mk_config in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = Z3native.mk_context_rc cfg in + Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + (* Printf.printf "Installing finalizer on context \n" ; *) + let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in + let f = fun o -> dispose_context o in + Gc.finalise f res; + res + (* CMW: Install error handler here! + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); + *) + + let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) + let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) + let context_gno ctx = ctx.m_n_ctx + + + let z3obj_gc o = o.m_ctx + let z3obj_gnc o = (context_gno o.m_ctx) + + let z3obj_gno o = o.m_n_obj + let z3obj_sno o ctx no = + (context_add1 ctx) ; + o.inc_ref (context_gno ctx) no ; + ( + if not (is_null o.m_n_obj) then + o.dec_ref (context_gno ctx) o.m_n_obj ; + (context_sub1 ctx) + ) ; + o.m_n_obj <- no + + let z3obj_dispose o = + if not (is_null o.m_n_obj) then + ( + o.dec_ref (z3obj_gnc o) o.m_n_obj ; + (context_sub1 (z3obj_gc o)) + ) ; + o.m_n_obj <- null + + let z3obj_create o = + let f = fun o -> (z3obj_dispose o) in + Gc.finalise f o + + let z3obj_nil_ref x y = () + + let array_to_native a = + let f e = (z3obj_gno e) in + Array.map f a + + (* Internal coercions *) + let context_of_ast ( x : ast ) = (z3obj_gc x) + let nc_of_ast ( x : ast ) = (z3obj_gnc x) + let ptr_of_ast ( x : ast ) = (z3obj_gno x) + + let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) + let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) + let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) + + + let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> + let res : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> + let q = (z3_native_object_of_ast_ptr ctx no) in + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then + raise (Z3native.Exception "Invalid coercion") + else + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with + | ARRAY_SORT + | BOOL_SORT + | BV_SORT + | DATATYPE_SORT + | INT_SORT + | REAL_SORT + | UNINTERPRETED_SORT + | FINITE_DOMAIN_SORT + | RELATION_SORT -> Sort(q) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + + let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + FuncDecl(z3_native_object_of_ast_ptr ctx no) + + let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with + | FUNC_DECL_AST + | SORT_AST + | QUANTIFIER_AST + | APP_AST + | NUMERAL_AST + | VAR_AST -> z3_native_object_of_ast_ptr ctx no + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") + + and expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then + Expr(z3_native_object_of_ast_ptr ctx no) + else + let s = Z3native.get_sort (context_gno ctx) no in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) no) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + if (Z3native.is_numeral_ast (context_gno ctx) no) then + if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + raise (Z3native.Exception "Unsupported numeral object") + else + Expr(z3_native_object_of_ast_ptr ctx no) + + let expr_aton ( a : expr array ) = + let f ( e : expr ) = match e with Expr(a) -> (ptr_of_ast a) in + Array.map f a + + let expr_of_func_app : context -> func_decl -> expr array -> expr = fun ctx f args -> + match f with FuncDecl(fa) -> + let o = Z3native.mk_app (context_gno ctx) (ptr_of_ast fa) (Array.length args) (expr_aton args) in + expr_of_ptr ctx o +end + + +open Internal + + + +(* Sort coercions *) +let ast_of_sort s = match s with Sort(x) -> x +let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x +let sort_of_bool_sort s = match s with BoolSort(x) -> x +let sort_of_array_sort s = match s with ArraySort(x) -> x +let sort_of_set_sort s = match s with SetSort(x) -> x +let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x +let sort_of_relation_sort s = match s with RelationSort(x) -> x +let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x +let sort_of_enum_sort s = match s with EnumSort(x) -> x +let sort_of_list_sort s = match s with ListSort(x) -> x +let sort_of_tuple_sort s = match s with TupleSort(x) -> x +let sort_of_arith_sort s = match s with ArithSort(x) -> x +let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x +let arith_sort_of_int_sort s = match s with IntSort(x) -> x +let arith_sort_of_real_sort s = match s with RealSort(x) -> x + +let uninterpreted_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + UninterpretedSort(s) + +let bool_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolSort(s) + +let array_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArraySort(s) + +let datatype_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeSort(s) + +let relation_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RelationSort(s) + +let finite_domain_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + FiniteDomainSort(s) + +let arith_sort_of_sort s = match s with Sort(a) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithSort(s) + +let bitvec_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecSort(s) + +let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntSort(s) + +let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealSort(s) + +(* FuncDecl coercions *) +let ast_of_func_decl f = match f with FuncDecl(x) -> x + +(* Expr coercions *) +let ast_of_expr e = match e with Expr(a) -> a +let expr_of_bool_expr e = match e with BoolExpr(x) -> x +let expr_of_arith_expr e = match e with ArithExpr(x) -> x +let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x +let expr_of_array_expr e = match e with ArrayExpr(x) -> x +let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x + +let arith_expr_of_int_expr e = match e with IntExpr(x) -> x +let arith_expr_of_real_expr e = match e with RealExpr(x) -> x + +let int_expr_of_int_num e = match e with IntNum(x) -> x +let real_expr_of_rat_num e = match e with RatNum(x) -> x +let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x +let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x + +let expr_of_quantifier e = match e with Quantifier(x) -> x +let ast_of_pattern e = match e with Pattern(x) -> x + + +let expr_of_ast a = + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Expr(a) + +let bool_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolExpr(e) + +let arith_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithExpr(e) + +let bitvec_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecExpr(e) + +let array_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArrayExpr(e) + +let datatype_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeExpr(e) + +let int_expr_of_arith_expr e = + match e with ArithExpr(Expr(no)) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntExpr(e) + +let real_expr_of_arith_expr e = + match e with ArithExpr(Expr(no)) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealExpr(e) + +let int_num_of_int_expr e = + match e with IntExpr(ArithExpr(Expr(no))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + raise (Z3native.Exception "Invalid coercion") + else + IntNum(e) + +let rat_num_of_real_expr e = + match e with RealExpr(ArithExpr(Expr(no))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + raise (Z3native.Exception "Invalid coercion") + else + RatNum(e) + +let algebraic_num_of_arith_expr e = + match e with ArithExpr(Expr(no)) -> + if (not (Z3native.is_algebraic_number (z3obj_gnc no) (z3obj_gno no))) then + raise (Z3native.Exception "Invalid coercion") + else + AlgebraicNum(e) + +let bitvec_num_of_bitvec_expr e = + match e with BitVecExpr(Expr(no)) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecNum(e) + +let quantifier_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.QUANTIFIER_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Quantifier(e) + +let pattern_of_ast a = + (* CMW: Unchecked ok? *) + Pattern(a) + + + +(** 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. *) module Log = @@ -28,6 +499,7 @@ struct let append s = Z3native.append_log s end + (** Version information *) module Version = struct @@ -52,11 +524,6 @@ struct string_of_int rev ^ "." end -(**/**) -(* Some helpers. *) - -let null = Z3native.mk_null() -let is_null o = (Z3native.is_null o) let mk_list ( f : int -> 'a ) ( n : int ) = let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = @@ -66,49 +533,8 @@ let mk_list ( f : int -> 'a ) ( n : int ) = (mk_list' f (i+1) n ((f i) :: tail)) in mk_list' f 0 n [] -(**/**) -(**/**) -type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } -(**/**) -type context = z3_native_context - -(**/**) - -let context_dispose ctx = - if ctx.m_n_obj_cnt == 0 then ( - (* Printf.printf "Disposing context \n" ; *) - (Z3native.del_context ctx.m_n_ctx) - ) else ( - Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; - (* re-queue for finalization? *) - ) - -let context_create settings = - let cfg = Z3native.mk_config in - let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in - (List.iter f settings) ; - let v = Z3native.mk_context_rc cfg in - Z3native.del_config(cfg) ; - Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; - (* Printf.printf "Installing finalizer on context \n" ; *) - let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in - let f = fun o -> context_dispose o in - Gc.finalise f res; - res -(* CMW: Install error handler here! - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); -*) - -let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) -let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) -let context_gno ctx = ctx.m_n_ctx - -(**/**) - (** Create a context object. Most interactions with Z3 are interpreted in some context; many users will only @@ -130,113 +556,14 @@ let context_gno ctx = ctx.m_n_ctx *) let mk_context ( cfg : ( string * string ) list ) = - context_create cfg + create_context cfg -(**/**) -class virtual z3object ctx_init obj_init = -object (self) - val mutable m_ctx : context = ctx_init - val mutable m_n_obj : Z3native.ptr option = obj_init - - initializer - (match m_n_obj with - | Some (x) -> self#incref (context_gno m_ctx) x; - (context_add1 m_ctx) - | None -> () - ); - (* Printf.printf "Installing finalizer on z3object %d \n" (Oo.id self) ; *) - let f = fun o -> o#dispose in - let v = self in - Gc.finalise f v - - method virtual incref : Z3native.ptr -> Z3native.ptr -> unit - method virtual decref : Z3native.ptr -> Z3native.ptr -> unit - - method dispose = - (* Printf.printf "Disposing z3object %d \n" (Oo.id self) ; *) - (match m_n_obj with - | Some (x) -> - self#decref (context_gno m_ctx) x; - (context_sub1 m_ctx) ; - m_n_obj <- None; - | None -> () - ); - - method gno = match m_n_obj with - | Some(x) -> x - | None -> raise (Z3native.Exception "Z3 object lost") - - method sno (ctx : context) o = - (context_add1 m_ctx) ; - self#incref (context_gno ctx) o ; - (match m_n_obj with - | Some(x) -> self#decref (context_gno ctx) x ; (context_sub1 m_ctx) - | None -> () - ); - m_n_obj <- Some o - - method gc = m_ctx - method gnc = (context_gno m_ctx) -end - - - -type z3_native_object = { - m_ctx : context ; - mutable m_n_obj : Z3native.ptr ; - inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; - dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - -let z3obj_gc o = o.m_ctx -let z3obj_gnc o = (context_gno o.m_ctx) - -let z3obj_gno o = o.m_n_obj -let z3obj_sno o ctx no = - (context_add1 ctx) ; - o.inc_ref (context_gno ctx) no ; - ( - if not (is_null o.m_n_obj) then - o.dec_ref (context_gno ctx) o.m_n_obj ; - (context_sub1 ctx) - ) ; - o.m_n_obj <- no - -let z3obj_dispose o = - if not (is_null o.m_n_obj) then - ( - o.dec_ref (z3obj_gnc o) o.m_n_obj ; - (context_sub1 (z3obj_gc o)) - ) ; - o.m_n_obj <- null - -let z3obj_create o = - let f = fun o -> (z3obj_dispose o) in - Gc.finalise f o - -let z3obj_nil_ref x y = () - -let array_to_native a = - let f e = (z3obj_gno e) in - Array.map f a -(**/**) (** Symbols are used to name several term and type constructors *) module Symbol = -struct - (** Int symbol objects *) - type int_symbol = z3_native_object - - (** String symbol objects *) - type string_symbol = z3_native_object - - (** Symbol Objects *) - type symbol = - | S_Int of int_symbol - | S_Str of string_symbol - - (**/**) +struct let create_i ( ctx : context ) ( no : Z3native.ptr ) = let res : int_symbol = { m_ctx = ctx ; m_n_obj = null ; @@ -255,6 +582,11 @@ struct (z3obj_create res) ; res + let create ( ctx : context ) ( no : Z3native.ptr ) = + match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with + | INT_SYMBOL -> S_Int (create_i ctx no) + | STRING_SYMBOL -> S_Str (create_s ctx no) + let gc ( x : symbol ) = match x with | S_Int(n) -> (z3obj_gc n) @@ -269,17 +601,7 @@ struct match x with | S_Int(n) -> (z3obj_gno n) | S_Str(n) -> (z3obj_gno n) - - let create ( ctx : context ) ( no : Z3native.ptr ) = - match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> S_Int (create_i ctx no) - | STRING_SYMBOL -> S_Str (create_s ctx no) - - let aton a = - let f e = (gno e) in - Array.map f a - (**/**) - + (** The kind of the symbol (int or string) *) let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) @@ -327,48 +649,11 @@ end (** The abstract syntax tree (AST) module *) -module rec AST : -sig - type ast = z3_native_object - -(**/**) - val create : context -> Z3native.ptr -> ast - val aton : ast array -> Z3native.ptr array -(**/**) - - module ASTVectors : sig - type ast_vector - val create : context -> Z3native.ptr -> ast_vector - val get_size : ast_vector -> int - val get : ast_vector -> int -> ast - end - - val is_expr : ast -> bool - val is_var : ast -> bool -end = struct - type ast = z3_native_object - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let aton (a : ast array) = - let f (e : ast) = (z3obj_gno e) in - Array.map f a - (**/**) - +module AST = +struct (** Vectors of ASTs *) - module ASTVectors = + module ASTVector = struct - type ast_vector = z3_native_object - - (**/**) let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; @@ -377,7 +662,7 @@ end = struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** The size of the vector *) let get_size ( x : ast_vector ) = @@ -411,7 +696,7 @@ end = struct (** Translates all ASTs in the vector to . @param to_ctx A context - @return A new ASTVectors + @return A new ASTVector *) let translate ( x : ast_vector ) ( to_ctx : context ) = create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) @@ -423,10 +708,8 @@ end = struct (** Map from AST to AST *) module ASTMap = - struct - type ast_map = z3_native_object - - (**/**) + struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_map = { m_ctx = ctx ; m_n_obj = null ; @@ -435,7 +718,7 @@ end = struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Checks whether the map contains the key . @param k An AST @@ -476,7 +759,7 @@ end = struct (** The keys stored in the map. *) let get_keys ( x : ast_map ) = - ASTVectors.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) (** Retrieves a string representation of the map.*) let to_string ( x : ast_map ) = @@ -576,7 +859,7 @@ end = struct if (z3obj_gnc x) == (context_gno to_ctx) then x else - create to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Wraps an AST. @@ -590,7 +873,7 @@ end = struct @param nativeObject The native pointer to wrap. *) let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = - create ctx ptr + ast_of_ptr ctx ptr (** Unwraps an AST. @@ -603,66 +886,17 @@ end = struct @param a The AST to unwrap. *) - let unwrap_ast ( x : ast ) = (z3obj_gno x) - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST -> (match (FuncDecl.create ctx no) with FuncDecl.FuncDecl(x) -> x) - | SORT_AST -> (match (Sort.create ctx no) with Sort.Sort(x) -> x) - | QUANTIFIER_AST -> (match (Quantifiers.create ctx no) with Quantifiers.Quantifier(Expr.Expr(x)) -> x) - | APP_AST - | NUMERAL_AST - | VAR_AST -> (match (Expr.create ctx no) with Expr.Expr(x) -> x) - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") -(**/**) + let unwrap_ast ( x : ast ) = (z3obj_gno x) end (** The Sort module implements type information for ASTs *) -and Sort : -sig - type sort = Sort of AST.ast - type uninterpreted_sort = UninterpretedSort of sort - - val create : context -> Z3native.ptr -> sort - val gc : sort -> context - val gnc : sort -> Z3native.ptr - val gno : sort -> Z3native.ptr - val aton : sort array -> Z3native.ptr array -end = struct - type sort = Sort of AST.ast - type uninterpreted_sort = UninterpretedSort of sort - - (**/**) +module Sort = +struct + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) - let aton : sort array -> Z3native.ptr array = fun a -> - let f e = (gno e) in - Array.map f a - - let create : context -> Z3native.ptr -> sort = fun ctx no -> - let q : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno q ctx no) ; - (z3obj_create q) ; - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with - | ARRAY_SORT - | BOOL_SORT - | BV_SORT - | DATATYPE_SORT - | INT_SORT - | REAL_SORT - | UNINTERPRETED_SORT - | FINITE_DOMAIN_SORT - | RELATION_SORT -> Sort(q) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - (**/**) - - (** Comparison operator. @param a A sort @@ -700,7 +934,7 @@ end = struct (** Create a new uninterpreted sort. *) - let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = + let mk_uninterpreted ( ctx : context ) ( s : symbol ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; @@ -718,71 +952,37 @@ end (** Function declarations *) -and FuncDecl : -sig - type func_decl = FuncDecl of AST.ast - - val create : context -> Z3native.ptr -> func_decl - val gc : func_decl -> context - val gno : func_decl -> Z3native.ptr - val gnc : func_decl -> Z3native.ptr - val aton : func_decl array -> Z3native.ptr array - - val get_domain_size : func_decl -> int - val get_decl_kind : func_decl -> Z3enums.decl_kind - val get_arity : func_decl -> int -end = struct - type func_decl = FuncDecl of AST.ast - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - FuncDecl(res) - - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort array ) ( range : Sort.sort ) = +module FuncDecl = +struct + (**/**) + let create_ndr ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Sort.aton domain) (Sort.gno range))) ; + let f x = (ptr_of_ast (ast_of_sort x)) in + (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Array.map f domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) - let create_pdr ( ctx : context) ( prefix : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = + let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort array ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Sort.aton domain) (Sort.gno range))) ; + let f x = (ptr_of_ast (ast_of_sort x)) in + (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Array.map f domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - - let aton (a : func_decl array) = - let f (e : func_decl) = (gno e) in - Array.map f a - (**/**) + (**/**) (** Parameters of Func_Decls *) module Parameter = - struct - type parameter = - | P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - + struct (** The kind of the parameter. *) let get_kind ( x : parameter ) = (match x with @@ -840,13 +1040,13 @@ end = struct (** Creates a new function declaration. *) - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort array ) ( range : Sort.sort ) = + let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort ) = create_ndr ctx name domain range (** Creates a new function declaration. *) - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = mk_func_decl ctx (Symbol.mk_string ctx name) domain range (** @@ -854,19 +1054,19 @@ end = struct *) - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = create_pdr ctx prefix domain range (** Creates a new constant function declaration. *) - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : Sort.sort ) = + let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort ) = create_ndr ctx name [||] range (** Creates a new constant function declaration. *) - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : Sort.sort ) = + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = create_ndr ctx (Symbol.mk_string ctx name) [||] range (** @@ -874,7 +1074,7 @@ end = struct *) - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : Sort.sort ) = + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = create_pdr ctx prefix [||] range @@ -917,14 +1117,14 @@ end = struct *) let get_domain ( x : func_decl ) = let n = (get_domain_size x) in - let f i = Sort.create (gc x) (Z3native.get_domain (gnc x) (gno x) i) in + let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in Array.init n f (** The range of the function declaration *) let get_range ( x : func_decl ) = - Sort.create (gc x) (Z3native.get_range (gnc x) (gno x)) + sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) (** The kind of the function declaration. @@ -947,13 +1147,13 @@ end = struct let get_parameters ( x : func_decl ) = let n = (get_num_parameters x) in let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> Parameter.P_Srt (Sort.create (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> Parameter.P_Ast (AST.create (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (create (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + | PARAMETER_INT -> P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> P_Ast (ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) ) in mk_list f n @@ -961,7 +1161,7 @@ end = struct Create expression that applies function to arguments. @param args The arguments *) - let apply ( x : func_decl ) ( args : Expr.expr array ) = Expr.create_fa (gc x) x args + let apply ( x : func_decl ) ( args : expr array ) = expr_of_func_app (gc x) x args end (** @@ -969,43 +1169,12 @@ end A Params objects represents a configuration in the form of symbol/value pairs. *) -and Params : -sig - type params = z3_native_object - - val create : context -> Z3native.ptr -> params - - module ParamDescrs : sig - type param_descrs = z3_native_object - - val create : context -> Z3native.ptr -> param_descrs - val validate : param_descrs -> params -> unit - end -end = struct - type params = z3_native_object - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : params = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.params_inc_ref ; - dec_ref = Z3native.params_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - (**/**) - +module Params = +struct (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) - module ParamDescrs : - sig - type param_descrs = z3_native_object - - val create : context -> Z3native.ptr -> param_descrs - val validate : param_descrs -> params -> unit - end = struct - type param_descrs = z3_native_object - - (**/**) + module ParamDescrs = + struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : param_descrs = { m_ctx = ctx ; m_n_obj = null ; @@ -1014,14 +1183,14 @@ end = struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Validate a set of parameters. *) let validate ( x : param_descrs ) ( p : params ) = Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = + let get_kind ( x : param_descrs ) ( name : symbol ) = (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) (** Retrieve all names of parameters. *) @@ -1040,25 +1209,25 @@ end = struct (** Adds a parameter setting. *) - let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = + let add_bool ( x : params ) ( name : symbol ) ( value : bool ) = Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = + let add_int ( x : params ) (name : symbol ) ( value : int ) = Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = + let add_double ( x : params ) ( name : symbol ) ( value : float ) = Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = + let add_symbol ( x : params ) ( name : symbol ) ( value : symbol ) = Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) (** @@ -1081,14 +1250,20 @@ end = struct (** Adds a parameter setting. *) - let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = + let add_s_symbol ( x : params ) ( name : string ) ( value : symbol ) = add_symbol x (Symbol.mk_string (z3obj_gc x) name) value (** Creates a new parameter set *) let mk_params ( ctx : context ) = - create ctx (Z3native.mk_params (context_gno ctx)) + let res : params = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.params_inc_ref ; + dec_ref = Z3native.params_dec_ref } in + (z3obj_sno res ctx (Z3native.mk_params (context_gno ctx))) ; + (z3obj_create res) ; + res (** A string representation of the parameter set. @@ -1097,76 +1272,16 @@ end = struct end (** General expressions (terms) *) -and Expr : -sig - type expr = Expr of AST.ast - - val create : context -> Z3native.ptr -> expr - val create_fa : context -> FuncDecl.func_decl -> expr array -> expr - val gc : expr -> context - val gno : expr -> Z3native.ptr - val gnc : expr -> Z3native.ptr - val aton : expr array -> Z3native.ptr array - - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - val get_func_decl : expr -> FuncDecl.func_decl - val is_numeral : expr -> bool - val to_string : expr -> string -end = struct - type expr = Expr of AST.ast - - (**/**) - let create ( ctx : context ) ( obj : Z3native.ptr ) = - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then - (match (Quantifiers.create ctx obj) with Quantifiers.Quantifier(e) -> e) - else - let s = Z3native.get_sort (context_gno ctx) obj in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) obj) then - (match (Arithmetic.AlgebraicNumbers.create_num ctx obj) with Arithmetic.AlgebraicNumbers.AlgebraicNum(Arithmetic.ArithExpr(e)) -> e) - else - if (Z3native.is_numeral_ast (context_gno ctx) obj) && - (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then - match sk with - | INT_SORT -> (match (Arithmetic.Integers.create_num ctx obj) with Arithmetic.Integers.IntNum(Arithmetic.Integers.IntExpr(Arithmetic.ArithExpr(e))) -> e) - | REAL_SORT -> (match (Arithmetic.Reals.create_num ctx obj) with Arithmetic.Reals.RatNum(Arithmetic.Reals.RealExpr(Arithmetic.ArithExpr(e))) -> e) - | BV_SORT -> (match (BitVectors.create_num ctx obj) with BitVectors.BitVecNum(BitVectors.BitVecExpr(e)) -> e) - | _ -> raise (Z3native.Exception "Unsupported numeral object") - else - match sk with - | BOOL_SORT -> (match (Booleans.create_expr ctx obj) with Booleans.BoolExpr(e) -> e) - | INT_SORT -> (match (Arithmetic.Integers.create_expr ctx obj) with Arithmetic.Integers.IntExpr(Arithmetic.ArithExpr(e)) -> e) - | REAL_SORT -> (match (Arithmetic.Reals.create_expr ctx obj) with Arithmetic.Reals.RealExpr(Arithmetic.ArithExpr(e)) -> e) - | BV_SORT -> (match (BitVectors.create_expr ctx obj) with BitVectors.BitVecExpr(e) -> e) - | ARRAY_SORT -> (match (Arrays.create_expr ctx obj) with Arrays.ArrayExpr(e) -> e) - | DATATYPE_SORT -> (match (Datatypes.create_expr ctx obj) with Datatypes.DatatypeExpr(e) -> e) - | _ -> Expr(AST.create ctx obj) - - let aton ( a : expr array ) = - let f ( e : expr ) = match e with Expr(a) -> (z3obj_gno a) in - Array.map f a - - let create_fa ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = - let o = Z3native.mk_app (context_gno ctx) (FuncDecl.gno f) (Array.length args) (aton args) in - Expr.create ctx o - - let gc ( x : expr ) = match x with Expr(a) -> (z3obj_gc a) - let gnc ( x : expr ) = match x with Expr(a) -> (z3obj_gnc a) - let gno ( x : expr ) = match x with Expr(a) -> (z3obj_gno a) - - let aton (a : expr array) = - let f (e : expr) = (gno e) in - Array.map f a - (**/**) - +module Expr = +struct (** Returns a simplified version of the expression. @param p A set of parameters to configure the simplifier *) - let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> Expr.create (gc x) (Z3native.simplify (gnc x) (gno x)) - | Some pp -> Expr.create (gc x) (Z3native.simplify_ex (gnc x) (gno x) (z3obj_gno pp)) + let simplify ( x : expr ) ( p : params option ) = match p with + | None -> expr_of_ptr (c_of_expr x) (Z3native.simplify (nc_of_expr x) (ptr_of_expr x)) + | Some pp -> expr_of_ptr (c_of_expr x) (Z3native.simplify_ex (nc_of_expr x) (ptr_of_expr x) (z3obj_gno pp)) (** a string describing all available parameters to Expr.Simplify. @@ -1183,24 +1298,24 @@ end = struct (** The function declaration of the function that is applied in this expression. *) - let get_func_decl ( x : expr ) = FuncDecl.create (gc x) (Z3native.get_app_decl (gnc x) (gno x)) + let get_func_decl ( x : expr ) = func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) (** Indicates whether the expression is the true or false expression or something else (L_UNDEF). *) - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (nc_of_expr x) (ptr_of_expr x)) (** The number of arguments of the expression. *) - let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) + let get_num_args ( x : expr ) = Z3native.get_app_num_args (nc_of_expr x) (ptr_of_expr x) (** The arguments of the expression. *) let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = create (gc x) (Z3native.get_app_arg (gnc x) (gno x) i) in + let f i = expr_of_ptr (c_of_expr x) (Z3native.get_app_arg (nc_of_expr x) (ptr_of_expr x) i) in Array.init n f (** @@ -1211,7 +1326,7 @@ end = struct if (Array.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - create (gc x) (Z3native.update_term (gnc x) (gno x) (Array.length args) (aton args)) + expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (Array.length args) (expr_aton args)) (** Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. @@ -1224,7 +1339,7 @@ end = struct if (Array.length from) <> (Array.length to_) then raise (Z3native.Exception "Argument sizes do not match") else - create (gc x) (Z3native.substitute (gnc x) (gno x) (Array.length from) (aton from) (aton to_)) + expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (Array.length from) (expr_aton from) (expr_aton to_)) (** Substitute every occurrence of from in the expression with to. @@ -1239,48 +1354,47 @@ end = struct For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) let substitute_vars ( x : expr ) to_ = - create (gc x) (Z3native.substitute_vars (gnc x) (gno x) (Array.length to_) (aton to_)) + expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (Array.length to_) (expr_aton to_)) - (** Translates (copies) the term to the Context . @param ctx A context @return A copy of the term which is associated with *) let translate ( x : expr ) to_ctx = - if (gc x) == to_ctx then + if (c_of_expr x) == to_ctx then x else - create to_ctx (Z3native.translate (gnc x) (gno x) (context_gno to_ctx)) + expr_of_ptr to_ctx (Z3native.translate (nc_of_expr x) (ptr_of_expr x) (context_gno to_ctx)) (** Returns a string representation of the expression. *) - let to_string ( x : expr ) = Z3native.ast_to_string (gnc x) (gno x) + let to_string ( x : expr ) = Z3native.ast_to_string (nc_of_expr x) (ptr_of_expr x) (** Indicates whether the term is a numeral *) - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (gnc x) (gno x)) + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (nc_of_expr x) (ptr_of_expr x)) (** Indicates whether the term is well-sorted. @return True if the term is well-sorted, false otherwise. *) - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (nc_of_expr x) (ptr_of_expr x) (** The Sort of the term. *) - let get_sort ( x : expr ) = Sort.create (gc x) (Z3native.get_sort (gnc x) (gno x)) + let get_sort ( x : expr ) = sort_of_ptr (c_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)) (** Indicates whether the term has Boolean sort. *) let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (gnc x) - (Z3native.mk_bool_sort (gnc x)) - (Z3native.get_sort (gnc x) (gno x))) + (Z3native.is_eq_sort (nc_of_expr x) + (Z3native.mk_bool_sort (nc_of_expr x)) + (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x))) (** Indicates whether the term represents a constant. @@ -1366,14 +1480,14 @@ end = struct (** Creates a new Constant of sort and named . *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : Sort.sort ) = - create ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) + let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = + expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) (** Creates a new Constant of sort and named . *) - let mk_const_s ( ctx : context ) ( name : string ) ( range : Sort.sort ) = + let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) range @@ -1381,21 +1495,21 @@ end = struct Creates a constant from the func_decl . @param f An expression of a 0-arity function *) - let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = - create_fa ctx f [||] + let mk_const_f ( ctx : context ) ( f : func_decl ) = + expr_of_func_app ctx f [||] (** Creates a fresh constant of sort and a name prefixed with . *) - let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : Sort.sort ) = - create ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) + let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = + expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) (** Create a new function application. *) - let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = - create_fa ctx f args + let mk_app ( ctx : context ) ( f : func_decl ) ( args : expr array ) = + expr_of_func_app ctx f args (** Create a numeral of a given sort. @@ -1403,8 +1517,8 @@ end = struct @param ty 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 *) - let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : Sort.sort ) = - create ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) + let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) (** Create a numeral of a given sort. This function can be use to create numerals that fit in a machine integer. @@ -1413,50 +1527,31 @@ end = struct @param ty Sort of the numeral @return A Term with value and type *) - let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : Sort.sort ) = - create ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) + let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) end (** Boolean expressions *) -and Booleans : -sig - type bool_expr = BoolExpr of Expr.expr - type bool_sort = BoolSort of Sort.sort +module Boolean = +struct + let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let a = (ast_of_ptr ctx no) in + BoolExpr(Expr(a)) - val create_expr : context -> Z3native.ptr -> bool_expr - val create_sort : context -> Z3native.ptr -> bool_sort - val gc : bool_expr -> context - val gnc : bool_expr -> Z3native.ptr - val gno : bool_expr -> Z3native.ptr - val aton : bool_expr array -> Z3native.ptr array -end = struct - type bool_expr = BoolExpr of Expr.expr - type bool_sort = BoolSort of Sort.sort - - (**/**) - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - let a = (AST.create ctx no) in - BoolExpr(Expr.Expr(a)) + let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + BoolSort(sort_of_ptr ctx no) - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - BoolSort(Sort.create ctx no) - - let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gc e) - let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gnc e) - let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gno e) - - let aton ( a : bool_expr array ) = - let f (e : bool_expr) = (gno e) in - Array.map f a - (**/**) + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (c_of_expr e) + let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (nc_of_expr e) + let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (ptr_of_expr e) let mk_sort ( ctx : context ) = - BoolSort(Sort.create ctx (Z3native.mk_bool_sort (context_gno ctx))) + BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) (** Create a Boolean constant. *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : symbol ) = let s = (match (mk_sort ctx) with BoolSort(q) -> q) in BoolExpr(Expr.mk_const ctx name s) @@ -1470,13 +1565,13 @@ end = struct The true Term. *) let mk_true ( ctx : context ) = - create_expr ctx (Z3native.mk_true (context_gno ctx)) + bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) (** The false Term. *) let mk_false ( ctx : context ) = - create_expr ctx (Z3native.mk_false (context_gno ctx)) + bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) (** Creates a Boolean value. @@ -1487,20 +1582,20 @@ end = struct (** Creates the equality = . *) - let mk_eq ( ctx : context ) ( x : Expr.expr ) ( y : Expr.expr ) = - create_expr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = + bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (ptr_of_expr x) (ptr_of_expr y)) (** Creates a distinct term. *) - let mk_distinct ( ctx : context ) ( args : Expr.expr array ) = - create_expr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (Expr.aton args)) + let mk_distinct ( ctx : context ) ( args : expr array ) = + bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (expr_aton args)) (** Mk an expression representing not(a). *) let mk_not ( ctx : context ) ( a : bool_expr ) = - create_expr ctx (Z3native.mk_not (context_gno ctx) (gno a)) + bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) (** Create an expression representing an if-then-else: ite(t1, t2, t3). @@ -1509,103 +1604,70 @@ end = struct @param t3 An expression with the same sort as *) let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - create_expr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) (** Create an expression representing t1 iff t2. *) let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create_expr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing t1 -> t2. *) let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create_expr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing t1 xor t2. *) let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create_expr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing the AND of args *) let mk_and ( ctx : context ) ( args : bool_expr array ) = - create_expr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (aton args)) + let f x = (ptr_of_expr (expr_of_bool_expr x)) in + bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (Array.map f args)) (** Create an expression representing the OR of args *) let mk_or ( ctx : context ) ( args : bool_expr array ) = - create_expr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (aton args)) + let f x = (ptr_of_expr (expr_of_bool_expr x)) in + bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (Array.map f args)) end (** Quantifier expressions *) -and Quantifiers : -sig - type quantifier = Quantifier of Expr.expr - - val create : context -> Z3native.ptr -> quantifier -end = struct - type quantifier = Quantifier of Expr.expr - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let a = (AST.create ctx no) in - Quantifier(Expr.Expr(a)) - - let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) - let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) - let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) - (**/**) - +module Quantifier = +struct + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (c_of_expr e) + let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (nc_of_expr e) + let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (ptr_of_expr e) + (** Quantifier patterns 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. *) - module Patterns : - sig - type pattern = Pattern of AST.ast - - val create : context -> Z3native.ptr -> pattern - val aton : pattern array -> Z3native.ptr array - end = struct - type pattern = Pattern of AST.ast - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - Pattern(res) - + module Pattern = struct let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - let aton (a : pattern array) = - let f (e : pattern) = (gno e) in - Array.map f a - (**/**) - (** The number of terms in the pattern. *) let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms (gnc x) (gno x) - + Z3native.get_pattern_num_terms (gnc x) (gno x) + (** The terms in the pattern. *) let get_terms ( x : pattern ) = let n = (get_num_terms x) in - let f i = (Expr.create (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in + let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in Array.init n f (** @@ -1632,11 +1694,11 @@ end = struct on the scope in which it appears. The deeper ( x : expr ) appears, the higher is its index. *) - let get_index ( x : Expr.expr ) = - if not (AST.is_var (match x with Expr.Expr(a) -> a)) then + let get_index ( x : expr ) = + if not (AST.is_var (match x with Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else - Z3native.get_index_value (Expr.gnc x) (Expr.gno x) + Z3native.get_index_value (nc_of_expr x) (ptr_of_expr x) (** Indicates whether the quantifier is universal. @@ -1664,7 +1726,7 @@ end = struct *) let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = (Patterns.create (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in + let f i = Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** @@ -1677,7 +1739,7 @@ end = struct *) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = (Patterns.create (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in + let f i = Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** @@ -1698,31 +1760,31 @@ end = struct *) let get_bound_variable_sorts ( x : quantifier ) = let n = (get_num_bound x) in - let f i = (Sort.create (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in + let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in Array.init n f (** The body of the quantifier. *) let get_body ( x : quantifier ) = - Booleans.create_expr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) + Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) (** Creates a new bound variable. @param index The de-Bruijn index of the variable @param ty The sort of the variable *) - let mk_bound ( ctx : context ) ( index : int ) ( ty : Sort.sort ) = - Expr.create ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) + let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) (** Create a quantifier pattern. *) - let mk_pattern ( ctx : context ) ( terms : Expr.expr array ) = + let mk_pattern ( ctx : context ) ( terms : expr array ) = if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - Patterns.create ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (Expr.aton terms)) + Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) (** Create a universal Quantifier. @@ -1743,96 +1805,96 @@ end = struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - create ctx (Z3native.mk_quantifier (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (Patterns.aton patterns) - (Array.length sorts) (Sort.aton sorts) - (Symbol.aton names) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (let f x = (Symbol.gno x) in (Array.map f names)) + (ptr_of_expr body))) else - create ctx (Z3native.mk_quantifier_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (Patterns.aton patterns) - (Array.length nopatterns) (Expr.aton nopatterns) - (Array.length sorts) (Sort.aton sorts) - (Symbol.aton names) - (Expr.gno body)) - + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length nopatterns) (expr_aton nopatterns) + (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (let f x = (Symbol.gno x) in (Array.map f names)) + (ptr_of_expr body))) + (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - create ctx (Z3native.mk_quantifier_const (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (Expr.aton bound_constants) - (Array.length patterns) (Patterns.aton patterns) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (expr_aton bound_constants) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (ptr_of_expr body))) else - create ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (Expr.aton bound_constants) - (Array.length patterns) (Patterns.aton patterns) - (Array.length nopatterns) (Expr.aton nopatterns) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length bound_constants) (expr_aton bound_constants) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length nopatterns) (expr_aton nopatterns) + (ptr_of_expr body))) (** Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - create ctx (Z3native.mk_quantifier (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (Patterns.aton patterns) - (Array.length sorts) (Sort.aton sorts) - (Symbol.aton names) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (let f x = (Symbol.gno x) in (Array.map f names)) + (ptr_of_expr body))) else - create ctx (Z3native.mk_quantifier_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (Patterns.aton patterns) - (Array.length nopatterns) (Expr.aton nopatterns) - (Array.length sorts) (Sort.aton sorts) - (Symbol.aton names) - (Expr.gno body)) - + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length nopatterns) (expr_aton nopatterns) + (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (let f x = (Symbol.gno x) in (Array.map f names)) + (ptr_of_expr body))) + (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - create ctx (Z3native.mk_quantifier_const (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (Expr.aton bound_constants) - (Array.length patterns) (Patterns.aton patterns) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (expr_aton bound_constants) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (ptr_of_expr body))) else - create ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (Expr.aton bound_constants) - (Array.length patterns) (Patterns.aton patterns) - (Array.length nopatterns) (Expr.aton nopatterns) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length bound_constants) (expr_aton bound_constants) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length nopatterns) (expr_aton nopatterns) + (ptr_of_expr body))) (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -1842,7 +1904,7 @@ end = struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -1850,42 +1912,29 @@ end = struct end (** Functions to manipulate Array expressions *) -and Arrays : -sig - type array_expr = ArrayExpr of Expr.expr - type array_sort = ArraySort of Sort.sort - - val create_expr : context -> Z3native.ptr -> array_expr -end = struct - type array_expr = ArrayExpr of Expr.expr - type array_sort = ArraySort of Sort.sort - - (**/**) +module Array_ = +struct + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (Expr.create ctx no) in + let e = (expr_of_ptr ctx no) in ArrayExpr(e) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in ArraySort(s) - let sgc ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gc s) - let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gnc s) - let sgno ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gno s) + let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gno s) - let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gc e) - let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gnc e) - let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gno e) + let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gc e) + let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) + let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) - let aton (a : array_expr array) = - let f (e : array_expr) = (egno e) in - Array.map f a - (**/**) - (** Create a new array sort. *) - let mk_sort ( ctx : context ) ( domain : Sort.sort ) ( range : Sort.sort ) = + let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = create_sort ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) (** @@ -1893,62 +1942,62 @@ end = struct It satisfies select(store(a,i,v),j) = if i = j then v else select(a,j). Array store takes at least 3 arguments. *) - let is_store ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) (** Indicates whether the term is an array select. *) - let is_select ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_constant_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) + let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) (** Indicates whether the term is a default array. For example default(const(v)) = v. The function is unary. *) - let is_default_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) + let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_array_map ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) + let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_as_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) (** Indicates whether the term is of an array sort. *) - let is_array ( x : Expr.expr ) = - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) + let is_array ( x : expr ) = + (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == ARRAY_SORT) (** The domain of the array sort. *) - let get_domain ( x : array_sort ) = Sort.create (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) + let get_domain ( x : array_sort ) = sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) (** The range of the array sort. *) - let get_range ( x : array_sort ) = Sort.create (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) + let get_range ( x : array_sort ) = sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) (** Create an array constant. *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort ) ( range : Sort.sort ) = + let mk_const ( ctx : context ) ( name : symbol ) ( domain : sort ) ( range : sort ) = ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) (** Create an array constant. *) - let mk_const_s ( ctx : context ) ( name : string ) ( domain : Sort.sort ) ( range : Sort.sort ) = + let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) domain range (** @@ -1963,8 +2012,8 @@ end = struct *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : Expr.expr ) = - create_expr ctx (Z3native.mk_select (context_gno ctx) (egno a) (Expr.gno i)) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = + expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) (** Array update. @@ -1982,8 +2031,8 @@ end = struct *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : Expr.expr ) ( v : Expr.expr ) = - create_expr ctx (Z3native.mk_store (context_gno ctx) (egno a) (Expr.gno i) (Expr.gno v)) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = + expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) (** Create a constant array. @@ -1993,8 +2042,8 @@ end = struct *) - let mk_const_array ( ctx : context ) ( domain : Sort.sort ) ( v : Expr.expr ) = - create_expr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) + let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = + expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) (** Maps f on the argument arrays. @@ -2006,8 +2055,9 @@ end = struct *) - let mk_map ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : array_expr array ) = - create_expr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (aton args)) + let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = + let m x = (ptr_of_expr (expr_of_array_expr x)) in + expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m args)) (** Access the array default value. @@ -2016,137 +2066,122 @@ end = struct finite maps with a default range value. *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = - create_expr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) + expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) end (** Functions to manipulate Set expressions *) -and Sets : -sig - type set_sort = SetSort of Sort.sort - -end = struct - type set_sort = SetSort of Sort.sort - +module Set = +struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in SetSort(s) (** Indicates whether the term is set union *) - let is_union ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) (** Indicates whether the term is set intersection *) - let is_intersect ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) (** Indicates whether the term is set difference *) - let is_difference ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) (** Indicates whether the term is set complement *) - let is_complement ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) (** Indicates whether the term is set subset *) - let is_subset ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) (** Create a set type. *) - let mk_sort ( ctx : context ) ( ty : Sort.sort ) = + let mk_sort ( ctx : context ) ( ty : sort ) = create_sort ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) (** Create an empty set. *) - let mk_empty ( ctx : context ) ( domain : Sort.sort ) = - (Expr.create ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) + let mk_empty ( ctx : context ) ( domain : sort ) = + (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) (** Create the full set. *) - let mk_full ( ctx : context ) ( domain : Sort.sort ) = - Expr.create ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) + let mk_full ( ctx : context ) ( domain : sort ) = + expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) (** Add an element to the set. *) - let mk_set_add ( ctx : context ) ( set : Expr.expr ) ( element : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) + let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = + expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) (** Remove an element from a set. *) - let mk_del ( ctx : context ) ( set : Expr.expr ) ( element : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) + let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = + expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) (** Take the union of a list of sets. *) - let mk_union ( ctx : context ) ( args : Expr.expr array ) = - Expr.create ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (Expr.aton args)) + let mk_union ( ctx : context ) ( args : expr array ) = + expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (expr_aton args)) (** Take the intersection of a list of sets. *) - let mk_intersection ( ctx : context ) ( args : Expr.expr array ) = - Expr.create ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (Expr.aton args)) + let mk_intersection ( ctx : context ) ( args : expr array ) = + expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (expr_aton args)) (** Take the difference between two sets. *) - let mk_difference ( ctx : context ) ( arg1 : Expr.expr ) ( arg2 : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) + let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = + expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) (** Take the complement of a set. *) - let mk_complement ( ctx : context ) ( arg : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) + let mk_complement ( ctx : context ) ( arg : expr ) = + expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (ptr_of_expr arg)) (** Check for set membership. *) - let mk_membership ( ctx : context ) ( elem : Expr.expr ) ( set : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) + let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = + expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (ptr_of_expr elem) (ptr_of_expr set)) (** Check for subsetness of sets. *) - let mk_subset ( ctx : context ) ( arg1 : Expr.expr ) ( arg2 : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) + let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = + expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) end (** Functions to manipulate Finite Domain expressions *) -and FiniteDomains : -sig - type finite_domain_sort = FiniteDomainSort of Sort.sort - -end = struct - type finite_domain_sort = FiniteDomainSort of Sort.sort - - (**/**) - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in - FiniteDomainSort(s) - - let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gc s) - let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gnc s) - let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s))-> (z3obj_gno s) - (**/**) - +module FiniteDomain = +struct + let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) + let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) + let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) + (** Create a new finite domain sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - create_sort ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size) + let mk_sort ( ctx : context ) ( name : symbol ) ( size : int ) = + let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in + FiniteDomainSort(s) (** Create a new finite domain sort. @@ -2158,14 +2193,15 @@ end = struct (** Indicates whether the term is of an array sort. *) - let is_finite_domain ( x : Expr.expr ) = - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) == FINITE_DOMAIN_SORT) + let is_finite_domain ( x : expr ) = + let nc = (nc_of_expr x) in + (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == FINITE_DOMAIN_SORT) (** Indicates whether the term is a less than predicate over a finite domain. *) - let is_lt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) (** The size of the finite domain sort. *) let get_size ( x : finite_domain_sort ) = @@ -2175,29 +2211,25 @@ end = struct end (** Functions to manipulate Relation expressions *) -and Relations : -sig - type relation_sort = RelationSort of Sort.sort - -end = struct - type relation_sort = RelationSort of Sort.sort - - (**/**) +module Relation = +struct + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in RelationSort(s) - let gc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gc s) - let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gnc s) - let gno ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s))-> (z3obj_gno s) - (**/**) + let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) + let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) + let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) + (** Indicates whether the term is of a relation sort. *) - let is_relation ( x : Expr.expr ) = - ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) == RELATION_SORT)) + let is_relation ( x : expr ) = + let nc = (nc_of_expr x) in + ((Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == RELATION_SORT)) (** Indicates whether the term is an relation store @@ -2206,40 +2238,40 @@ end = struct 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. *) - let is_store ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) (** Indicates whether the term is an empty relation *) - let is_empty ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) (** Indicates whether the term is a test for the emptiness of a relation *) - let is_is_empty ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) (** Indicates whether the term is a relational join *) - let is_join ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) (** Indicates whether the term is the union or convex hull of two relations. The function takes two arguments. *) - let is_union ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) (** Indicates whether the term is the widening of two relations The function takes two arguments. *) - let is_widen ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). The function takes one argument. *) - let is_project ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) + let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) (** Indicates whether the term is a relation filter @@ -2250,7 +2282,7 @@ end = struct corresponding to the columns of the relation. So the first column in the relation has index 0. *) - let is_filter ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) + let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) (** Indicates whether the term is an intersection of a relation with the negation of another. @@ -2265,7 +2297,7 @@ end = struct target are elements in ( x : expr ) in pos, such that there is no y in neg that agrees with ( x : expr ) on the columns c1, d1, .., cN, dN. *) - let is_negation_filter ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) + let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) (** Indicates whether the term is the renaming of a column in a relation @@ -2273,12 +2305,12 @@ end = struct The function takes one argument. The parameters contain the renaming as a cycle. *) - let is_rename ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) (** Indicates whether the term is the complement of a relation *) - let is_complement ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) (** Indicates whether the term is a relational select @@ -2287,7 +2319,7 @@ end = struct The function takes n+1 arguments, where the first argument is a relation, and the remaining n arguments correspond to a record. *) - let is_select ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) (** Indicates whether the term is a relational clone (copy) @@ -2298,7 +2330,7 @@ end = struct for terms of kind to perform destructive updates to the first argument. *) - let is_clone ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) (** The arity of the relation sort. *) let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) @@ -2312,46 +2344,22 @@ end = struct end (** Functions to manipulate Datatype expressions *) -and Datatypes : -sig - type datatype_expr = DatatypeExpr of Expr.expr - type datatype_sort = DatatypeSort of Sort.sort - - val create_expr : context -> Z3native.ptr -> datatype_expr -end = struct - type datatype_expr = DatatypeExpr of Expr.expr - type datatype_sort = DatatypeSort of Sort.sort - - (**/**) - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (Expr.create ctx no) in - DatatypeExpr(e) - +module Datatype = +struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in DatatypeSort(s) - let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gc s) - let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gnc s) - let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s))-> (z3obj_gno s) - (**/**) + let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) + (** Constructors *) - module Constructor : sig - type constructor - val create : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> constructor - val aton : constructor array -> Z3native.ptr array - end = struct - type constructor_extra = { - m_n : int; - mutable m_tester_decl : FuncDecl.func_decl option; - mutable m_constructor_decl : FuncDecl.func_decl option ; - mutable m_accessor_decls : FuncDecl.func_decl array option} - - type constructor = Constructor of (z3_native_object * constructor_extra) - - (**/**) - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = + module Constructor = + struct + + let create ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -2362,8 +2370,8 @@ end = struct let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) (Symbol.gno recognizer) n - (Symbol.aton field_names) - (Sort.aton sorts) + (let f x = (Symbol.gno x) in (Array.map f field_names)) + (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) sort_refs) in let no : z3_native_object = { m_ctx = ctx ; m_n_obj = null ; @@ -2379,21 +2387,17 @@ end = struct Gc.finalise f no ; Constructor(no, ex) - let aton ( a : constructor array ) = - let f (e : constructor) = match e with Constructor(no, ex) -> (z3obj_gno no)in - Array.map f a - let init_extra ( x : constructor ) = match x with Constructor(no, ex) -> match ex.m_tester_decl with | None -> let (a, b, c) = (Z3native.query_constructor (z3obj_gnc no) (z3obj_gno no) ex.m_n) in - ex.m_constructor_decl <- Some (FuncDecl.create (z3obj_gc no) a) ; - ex.m_tester_decl <- Some (FuncDecl.create (z3obj_gc no) b) ; - ex.m_accessor_decls <- Some (let f e = (FuncDecl.create (z3obj_gc no) e) in Array.map f c) ; + ex.m_constructor_decl <- Some (func_decl_of_ptr (z3obj_gc no) a) ; + ex.m_tester_decl <- Some (func_decl_of_ptr (z3obj_gc no) b) ; + ex.m_accessor_decls <- Some (let f e = (func_decl_of_ptr (z3obj_gc no) e) in Array.map f c) ; () | _ -> () - (**/**) + let get_n ( x : constructor ) = match x with Constructor(no, ex) -> @@ -2433,24 +2437,18 @@ end = struct (** Constructor list objects *) module ConstructorList = struct - type constructor_list = z3_native_object - - (**/**) - let create ( ctx : context )( c : Constructor.constructor array ) = + + let create ( ctx : context ) ( c : constructor array ) = let res : constructor_list = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref} in - (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Constructor.aton c))) ; + let f x = match x with Constructor(no,_) -> (z3obj_gno no) in + (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Array.map f c))) ; (z3obj_create res) ; let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f res; res - - let aton (a : constructor_list array) = - let f (e : constructor_list) = (z3obj_gno e) in - Array.map f a - (**/**) end (* DATATYPES *) @@ -2464,7 +2462,7 @@ end = struct 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. *) - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array) = + let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = Constructor.create ctx name recognizer field_names sorts sort_refs @@ -2478,21 +2476,22 @@ end = struct 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. *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array) = - let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Constructor.aton constructors)) in + let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = + let f x = match x with Constructor(no,_) -> (z3obj_gno no) in + let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in create_sort ctx x (** Create a new datatype sort. *) - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array ) = mk_sort ctx (Symbol.mk_string ctx name) constructors (** @@ -2500,16 +2499,17 @@ end = struct @param names names of datatype sorts @param c list of constructors, one list per sort. *) - let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = + let mk_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = let n = (Array.length names) in - let f e = (ConstructorList.create ctx e) in + let f e = (ptr_of_ast (ConstructorList.create ctx e)) in let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.aton names) (ConstructorList.aton cla)) in + let f2 x = (Symbol.gno x) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Array.map f2 names) cla) in let g e = (create_sort ctx e) in (Array.map g r) (** Create mutually recursive data-types. *) - let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = + let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = mk_sorts ctx ( let f e = (Symbol.mk_string ctx e) in @@ -2523,54 +2523,50 @@ end = struct (** The range of the array sort. *) let get_constructors ( x : datatype_sort ) = let n = (get_num_constructors x) in - let f i = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in Array.init n f (** The recognizers. *) let get_recognizers ( x : datatype_sort ) = let n = (get_num_constructors x) in - let f i = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in Array.init n f (** The constructor accessors. *) let get_accessors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = ( - let fd = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in - let g j = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in + let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in Array.init ds g ) in Array.init n f end (** Functions to manipulate Enumeration expressions *) -and Enumerations : -sig - type enum_sort_data - type enum_sort = EnumSort of (Sort.sort * enum_sort_data) -end = struct - type enum_sort_data = { mutable _constdecls : FuncDecl.func_decl array ; - mutable _testerdecls : FuncDecl.func_decl array } - type enum_sort = EnumSort of (Sort.sort * enum_sort_data) - - (**/**) +module Enumeration = +struct + let _constdecls = Hashtbl.create 0 + let _testerdecls = Hashtbl.create 0 + let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = - let s = (Sort.create ctx no) in - let e = { _constdecls = (let f e = FuncDecl.create ctx e in (Array.map f cdecls)) ; - _testerdecls = (let f e = FuncDecl.create ctx e in (Array.map f tdecls)) } in - EnumSort(s, e) + let s = (sort_of_ptr ctx no) in + let res = EnumSort(s) in + Hashtbl.add _constdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f cdecls)) ; + Hashtbl.add _testerdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f tdecls)) ; + res - let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gc s) - let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gnc s) - let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_)-> (z3obj_gno s) - (**/**) + let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) (** Create a new enumeration sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = - let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Symbol.aton enum_names)) in + let mk_sort ( ctx : context ) ( name : symbol ) ( enum_names : symbol array ) = + let f x = Symbol.gno x in + let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Array.map f enum_names)) in create_sort ctx a b c (** @@ -2580,45 +2576,40 @@ end = struct mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) (** The function declarations of the constants in the enumeration. *) - let get_const_decls ( x : enum_sort ) = match x with EnumSort(_,ex) -> ex._constdecls + let get_const_decls ( x : enum_sort ) = Hashtbl.find _constdecls x (** The test predicates for the constants in the enumeration. *) - let get_tester_decls ( x : enum_sort ) = match x with EnumSort(_,ex) -> ex._testerdecls + let get_tester_decls ( x : enum_sort ) = Hashtbl.find _testerdecls x end (** Functions to manipulate List expressions *) -and Lists : -sig - type list_sort_data - type list_sort = ListSort of (Sort.sort * list_sort_data) - -end = struct - type list_sort_data = { _nildecl : FuncDecl.func_decl ; - _is_nildecl : FuncDecl.func_decl ; - _consdecl : FuncDecl.func_decl ; - _is_consdecl : FuncDecl.func_decl ; - _headdecl : FuncDecl.func_decl ; - _taildecl : FuncDecl.func_decl } - type list_sort = ListSort of (Sort.sort * list_sort_data) - - (**/**) +module List_ = +struct + let _nildecls = Hashtbl.create 0 + let _is_nildecls = Hashtbl.create 0 + let _consdecls = Hashtbl.create 0 + let _is_consdecls = Hashtbl.create 0 + let _headdecls = Hashtbl.create 0 + let _taildecls = Hashtbl.create 0 + let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = - let s = (Sort.create ctx no) in - let e = {_nildecl = FuncDecl.create ctx nildecl; - _is_nildecl = FuncDecl.create ctx is_nildecl; - _consdecl = FuncDecl.create ctx consdecl; - _is_consdecl = FuncDecl.create ctx is_consdecl; - _headdecl = FuncDecl.create ctx headdecl; - _taildecl = FuncDecl.create ctx taildecl} in - ListSort(s, e) + let s = (sort_of_ptr ctx no) in + let res = ListSort(s) in + Hashtbl.add _nildecls res (func_decl_of_ptr ctx nildecl) ; + Hashtbl.add _is_nildecls res (func_decl_of_ptr ctx is_nildecl) ; + Hashtbl.add _consdecls res (func_decl_of_ptr ctx consdecl) ; + Hashtbl.add _is_consdecls res (func_decl_of_ptr ctx is_consdecl) ; + Hashtbl.add _headdecls res (func_decl_of_ptr ctx headdecl) ; + Hashtbl.add _taildecls res (func_decl_of_ptr ctx taildecl) ; + res - let sgc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gc s) - let sgnc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gnc s) - let sgno ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_)-> (z3obj_gno s) - (**/**) + let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) + (** Create a new list sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : Sort.sort ) = + let mk_sort ( ctx : context ) ( name : symbol ) ( elem_sort : sort ) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in create_sort ctx r a b c d e f @@ -2627,53 +2618,51 @@ end = struct mk_sort ctx (Symbol.mk_string ctx name) elem_sort (** The declaration of the nil function of this list sort. *) - let get_nil_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._nildecl + let get_nil_decl ( x : list_sort ) = (Hashtbl.find _nildecls x) (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._is_nildecl + let get_is_nil_decl ( x : list_sort ) = (Hashtbl.find _is_nildecls x) (** The declaration of the cons function of this list sort. *) - let get_cons_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._consdecl + let get_cons_decl ( x : list_sort ) = (Hashtbl.find _consdecls x) (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._is_consdecl + let get_is_cons_decl ( x : list_sort ) = (Hashtbl.find _is_consdecls x) (** The declaration of the head function of this list sort. *) - let get_head_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._headdecl + let get_head_decl ( x : list_sort ) = (Hashtbl.find _headdecls x) (** The declaration of the tail function of this list sort. *) - let get_tail_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._taildecl + let get_tail_decl ( x : list_sort ) = (Hashtbl.find _taildecls x) (** The empty list. *) - let nil ( x : list_sort ) = Expr.create_fa (sgc x) (get_nil_decl x) [||] + let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [||] end (** Functions to manipulate Tuple expressions *) -and Tuples : -sig - type tuple_sort = TupleSort of Sort.sort -end = struct - type tuple_sort = TupleSort of Sort.sort - - (**/**) +module Tuple = +struct + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in TupleSort(s) - let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gc s) - let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gnc s) - let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s))-> (z3obj_gno s) - (**/**) + let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) + (** Create a new tuple sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : Sort.sort array ) = - let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Symbol.aton field_names) (Sort.aton field_sorts)) in + let mk_sort ( ctx : context ) ( name : symbol ) ( field_names : symbol array ) ( field_sorts : sort array ) = + let f x = Symbol.gno x in + let f2 x = ptr_of_ast (ast_of_sort x) in + let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in (* CMW: leaks a,b? *) create_sort ctx r (** The constructor function of the tuple. *) let get_mk_decl ( x : tuple_sort ) = - FuncDecl.create (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) + func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) (** The number of fields in the tuple. *) let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) @@ -2681,131 +2670,37 @@ end = struct (** The field declarations. *) let get_field_decls ( x : tuple_sort ) = let n = get_num_fields x in - let f i = FuncDecl.create (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in Array.init n f end (** Functions to manipulate arithmetic expressions *) -and Arithmetic : -sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val create_expr : context -> Z3native.ptr -> arith_expr - val create_sort : context -> Z3native.ptr -> arith_sort - val aton : arith_expr array -> Z3native.ptr array - - module Integers : sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val create_sort : context -> Z3native.ptr -> int_sort - val create_expr : context -> Z3native.ptr -> int_expr - val create_num : context -> Z3native.ptr -> int_num - end - - module Reals : sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val create_sort : context -> Z3native.ptr -> real_sort - val create_expr : context -> Z3native.ptr -> real_expr - val create_num : context -> Z3native.ptr -> rat_num - end - - module AlgebraicNumbers : sig - type algebraic_num = AlgebraicNum of arith_expr - - val create_num : context -> Z3native.ptr -> algebraic_num - end - - val is_int : Expr.expr -> bool - val is_arithmetic_numeral : Expr.expr -> bool - val is_le : Expr.expr -> bool - val is_ge : Expr.expr -> bool - val is_lt : Expr.expr -> bool - val is_gt : Expr.expr -> bool - val is_add : Expr.expr -> bool - val is_sub : Expr.expr -> bool - val is_uminus : Expr.expr -> bool - val is_mul : Expr.expr -> bool - val is_div : Expr.expr -> bool - val is_idiv : Expr.expr -> bool - val is_remainder : Expr.expr -> bool - val is_modulus : Expr.expr -> bool - val is_inttoreal : Expr.expr -> bool - val is_real_to_int : Expr.expr -> bool - val is_real_is_int : Expr.expr -> bool - val is_real : Expr.expr -> bool - val is_int_numeral : Expr.expr -> bool - val is_rat_num : Expr.expr -> bool - val is_algebraic_number : Expr.expr -> bool - val mk_add : context -> arith_expr array -> Arithmetic.arith_expr - val mk_mul : context -> arith_expr array -> Arithmetic.arith_expr - val mk_sub : context -> arith_expr array -> Arithmetic.arith_expr - val mk_unary_minus : - context -> arith_expr -> Arithmetic.arith_expr - val mk_div : - context -> arith_expr -> arith_expr -> Arithmetic.arith_expr - val mk_power : - context -> arith_expr -> arith_expr -> Arithmetic.arith_expr - val mk_lt : - context -> arith_expr -> arith_expr -> Booleans.bool_expr - val mk_le : - context -> arith_expr -> arith_expr -> Booleans.bool_expr - val mk_gt : - context -> arith_expr -> arith_expr -> Booleans.bool_expr - val mk_ge : - context -> arith_expr -> arith_expr -> Booleans.bool_expr - -end = struct - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - (**/**) +module Arithmetic = +struct + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - ArithExpr(Expr.create ctx no) + arith_expr_of_expr (expr_of_ptr ctx no) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - ArithSort(Sort.create ctx no) + arith_sort_of_sort (sort_of_ptr ctx no) - let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gc s) - let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gnc s) - let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gno s) - let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gc e) - let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) - let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) + let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gno s) + let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (c_of_expr e) + let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (nc_of_expr e) + let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (ptr_of_expr e) - let aton (a : arith_expr array) = - let f (e : arith_expr) = (egno e) in - Array.map f a - (**/**) - - module rec Integers : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val create_sort : context -> Z3native.ptr -> int_sort - val create_expr : context -> Z3native.ptr -> int_expr - val create_num : context -> Z3native.ptr -> int_num - end = struct - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - (**/**) + module Integer = + struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - IntSort(Arithmetic.create_sort ctx no) + int_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - IntExpr(Arithmetic.create_expr ctx no) + int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) let create_num ( ctx : context ) ( no : Z3native.ptr ) = - IntNum(create_expr ctx no) + int_num_of_int_expr (create_expr ctx no) let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) @@ -2816,7 +2711,7 @@ end = struct let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - (**/**) + (** Create a new integer sort. *) let mk_sort ( ctx : context ) = @@ -2834,7 +2729,7 @@ end = struct (** Creates an integer constant. *) - let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_int_const ( ctx : context ) ( name : symbol ) = IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) (** @@ -2848,14 +2743,14 @@ end = struct The arguments must have int type. *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - create_expr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 rem t2. The arguments must have int type. *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - create_expr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) (** Create an integer numeral. @@ -2883,7 +2778,7 @@ end = struct The argument must be of integer sort. *) let mk_int2real ( ctx : context ) ( t : int_expr ) = - Reals.create_expr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)) + real_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) (** Create an bit bit-vector from the integer argument . @@ -2896,32 +2791,19 @@ end = struct The argument must be of integer sort. *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - BitVectors.create_expr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t)) + bitvec_expr_of_expr (expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) end - and Reals : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val create_sort : context -> Z3native.ptr -> real_sort - val create_expr : context -> Z3native.ptr -> real_expr - val create_num : context -> Z3native.ptr -> rat_num - end = struct - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - (**/**) + module Real = + struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - RealSort(Arithmetic.create_sort ctx no) + real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - RealExpr(Arithmetic.create_expr ctx no) - + real_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + let create_num ( ctx : context ) ( no : Z3native.ptr ) = - RatNum(create_expr ctx no) + rat_num_of_real_expr (create_expr ctx no) let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) @@ -2932,7 +2814,7 @@ end = struct let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - (**/**) + (** Create a real sort. *) let mk_sort ( ctx : context ) = @@ -2940,11 +2822,11 @@ end = struct (** The numerator of a rational numeral. *) let get_numerator ( x : rat_num ) = - Integers.create_num (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + Integer.create_num (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) (** The denominator of a rational numeral. *) let get_denominator ( x : rat_num ) = - Integers.create_num (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + Integer.create_num (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -2955,7 +2837,7 @@ end = struct let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) (** Creates a real constant. *) - let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_real_const ( ctx : context ) ( name : symbol ) = RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) (** Creates a real constant. *) @@ -2995,7 +2877,7 @@ end = struct (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = - Booleans.create_expr ctx (Z3native.mk_is_int (context_gno ctx) (egno t)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) (** Coerce a real to an integer. @@ -3005,25 +2887,18 @@ end = struct The argument must be of real sort. *) let mk_real2int ( ctx : context ) ( t : real_expr ) = - Integers.create_expr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)) + int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) end - and AlgebraicNumbers : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val create_num : context -> Z3native.ptr -> algebraic_num - end = struct - type algebraic_num = AlgebraicNum of arith_expr - - (**/**) + module AlgebraicNumber = + struct let create_num ( ctx : context ) ( no : Z3native.ptr ) = - AlgebraicNum(Arithmetic.create_expr ctx no) + algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - (**/**) + (** Return a upper bound for a given real algebraic number. @@ -3033,7 +2908,7 @@ end = struct @return A numeral Expr of sort Real *) let to_upper ( x : algebraic_num ) ( precision : int ) = - Reals.create_num (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + Real.create_num (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) (** Return a lower bound for the given real algebraic number. @@ -3043,7 +2918,7 @@ end = struct @return A numeral Expr of sort Real *) let to_lower ( x : algebraic_num ) precision = - Reals.create_num (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + Real.create_num (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -3057,207 +2932,197 @@ end = struct (** Indicates whether the term is of integer sort. *) - let is_int ( x : Expr.expr ) = - (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) + let is_int ( x : expr ) = + (Z3native.is_numeral_ast (nc_of_expr x) (nc_of_expr x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == INT_SORT) (** Indicates whether the term is an arithmetic numeral. *) - let is_arithmetic_numeral ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) (** Indicates whether the term is a less-than-or-equal *) - let is_le ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) (** Indicates whether the term is a greater-than-or-equal *) - let is_ge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) (** Indicates whether the term is a less-than *) - let is_lt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) (** Indicates whether the term is a greater-than *) - let is_gt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) (** Indicates whether the term is addition (binary) *) - let is_add ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) (** Indicates whether the term is subtraction (binary) *) - let is_sub ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) (** Indicates whether the term is a unary minus *) - let is_uminus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) (** Indicates whether the term is multiplication (binary) *) - let is_mul ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) (** Indicates whether the term is division (binary) *) - let is_div ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) (** Indicates whether the term is integer division (binary) *) - let is_idiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) (** Indicates whether the term is remainder (binary) *) - let is_remainder ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) (** Indicates whether the term is modulus (binary) *) - let is_modulus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) (** Indicates whether the term is a coercion of integer to real (unary) *) - let is_inttoreal ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) (** Indicates whether the term is a coercion of real to integer (unary) *) - let is_real_to_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) (** Indicates whether the term is a check that tests whether a real is integral (unary) *) - let is_real_is_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) (** Indicates whether the term is of sort real. *) - let is_real ( x : Expr.expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) + let is_real ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == REAL_SORT) (** Indicates whether the term is an integer numeral. *) - let is_int_numeral ( x : Expr.expr ) = (Expr.is_numeral x) && (is_int x) + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) (** Indicates whether the term is a real numeral. *) - let is_rat_num ( x : Expr.expr ) = (Expr.is_numeral x) && (is_real x) + let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) (** Indicates whether the term is an algebraic number *) - let is_algebraic_number ( x : Expr.expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (nc_of_expr x) (nc_of_expr x) (** Create an expression representing t[0] + t[1] + .... *) let mk_add ( ctx : context ) ( t : arith_expr array ) = - Arithmetic.create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Arithmetic.aton t)) + let f x = (ptr_of_expr (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Array.map f t))) (** Create an expression representing t[0] * t[1] * .... *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = - Arithmetic.create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Arithmetic.aton t)) + let f x = (ptr_of_expr (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Array.map f t))) (** Create an expression representing t[0] - t[1] - .... *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = - Arithmetic.create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Arithmetic.aton t)) + let f x = (ptr_of_expr (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Array.map f t))) (** Create an expression representing -t. *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - Arithmetic.create_expr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t)) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) (** Create an expression representing t1 / t2. *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Arithmetic.create_expr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2)) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 ^ t2. *) let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Arithmetic.create_expr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2)) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 < t2 *) let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Booleans.create_expr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 <= t2 *) let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Booleans.create_expr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 > t2 *) let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Booleans.create_expr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 >= t2 *) let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Booleans.create_expr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) end (** Functions to manipulate bit-vector expressions *) -and BitVectors : -sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val create_sort : context -> Z3native.ptr -> bitvec_sort - val create_expr : context -> Z3native.ptr -> bitvec_expr - val create_num : context -> Z3native.ptr -> bitvec_num -end = struct - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - (**/**) +module BitVector = +struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - BitVecSort(Sort.create ctx no) + bitvec_sort_of_sort (sort_of_ptr ctx no) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - BitVecExpr(Expr.create ctx no) + bitvec_expr_of_expr (expr_of_ptr ctx no) let create_num ( ctx : context ) ( no : Z3native.ptr ) = - BitVecNum(create_expr ctx no) + bitvec_num_of_bitvec_expr (create_expr ctx no) let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) - let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gc e) - let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gnc e) - let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gno e) + let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (c_of_expr e) + let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (nc_of_expr e) + let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (ptr_of_expr e) let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - (**/**) + (** Create a new bit-vector sort. @@ -3268,272 +3133,272 @@ end = struct (** Indicates whether the terms is of bit-vector sort. *) - let is_bv ( x : Expr.expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) + let is_bv ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == BV_SORT) (** Indicates whether the term is a bit-vector numeral *) - let is_bv_numeral ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) + let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) (** Indicates whether the term is a one-bit bit-vector with value one *) - let is_bv_bit1 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) + let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) (** Indicates whether the term is a one-bit bit-vector with value zero *) - let is_bv_bit0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) + let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) (** Indicates whether the term is a bit-vector unary minus *) - let is_bv_uminus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) + let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) (** Indicates whether the term is a bit-vector addition (binary) *) - let is_bv_add ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) + let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) (** Indicates whether the term is a bit-vector subtraction (binary) *) - let is_bv_sub ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) + let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) (** Indicates whether the term is a bit-vector multiplication (binary) *) - let is_bv_mul ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) + let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) (** Indicates whether the term is a bit-vector signed division (binary) *) - let is_bv_sdiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) + let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) (** Indicates whether the term is a bit-vector unsigned division (binary) *) - let is_bv_udiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) + let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) (** Indicates whether the term is a bit-vector signed remainder (binary) *) - let is_bv_SRem ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) + let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - let is_bv_urem ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) + let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) (** Indicates whether the term is a bit-vector signed modulus *) - let is_bv_smod ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) + let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) (** Indicates whether the term is a bit-vector signed division by zero *) - let is_bv_sdiv0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) + let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) (** Indicates whether the term is a bit-vector unsigned division by zero *) - let is_bv_udiv0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) + let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) (** Indicates whether the term is a bit-vector signed remainder by zero *) - let is_bv_srem0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) + let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - let is_bv_urem0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) + let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) (** Indicates whether the term is a bit-vector signed modulus by zero *) - let is_bv_smod0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) + let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - let is_bv_ule ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) + let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - let is_bv_sle ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) + let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - let is_bv_uge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) + let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - let is_bv_sge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) + let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) (** Indicates whether the term is an unsigned bit-vector less-than *) - let is_bv_ult ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) + let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) (** Indicates whether the term is a signed bit-vector less-than *) - let is_bv_slt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) + let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) (** Indicates whether the term is an unsigned bit-vector greater-than *) - let is_bv_ugt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) + let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) (** Indicates whether the term is a signed bit-vector greater-than *) - let is_bv_sgt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) + let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) (** Indicates whether the term is a bit-wise AND *) - let is_bv_and ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) + let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) (** Indicates whether the term is a bit-wise OR *) - let is_bv_or ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) + let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) (** Indicates whether the term is a bit-wise NOT *) - let is_bv_not ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) + let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) (** Indicates whether the term is a bit-wise XOR *) - let is_bv_xor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) + let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) (** Indicates whether the term is a bit-wise NAND *) - let is_bv_nand ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) + let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) (** Indicates whether the term is a bit-wise NOR *) - let is_bv_nor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) + let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) (** Indicates whether the term is a bit-wise XNOR *) - let is_bv_xnor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) + let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) (** Indicates whether the term is a bit-vector concatenation (binary) *) - let is_bv_concat ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) + let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) (** Indicates whether the term is a bit-vector sign extension *) - let is_bv_signextension ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) + let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) (** Indicates whether the term is a bit-vector zero extension *) - let is_bv_zeroextension ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) + let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) (** Indicates whether the term is a bit-vector extraction *) - let is_bv_extract ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) + let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) (** Indicates whether the term is a bit-vector repetition *) - let is_bv_repeat ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) + let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) (** Indicates whether the term is a bit-vector reduce OR *) - let is_bv_reduceor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) + let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) (** Indicates whether the term is a bit-vector reduce AND *) - let is_bv_reduceand ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) + let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) (** Indicates whether the term is a bit-vector comparison *) - let is_bv_comp ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) + let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) (** Indicates whether the term is a bit-vector shift left *) - let is_bv_shiftleft ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) + let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) (** Indicates whether the term is a bit-vector logical shift right *) - let is_bv_shiftrightlogical ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) (** Indicates whether the term is a bit-vector arithmetic shift left *) - let is_bv_shiftrightarithmetic ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) + let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) (** Indicates whether the term is a bit-vector rotate left *) - let is_bv_rotateleft ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) (** Indicates whether the term is a bit-vector rotate right *) - let is_bv_rotateright ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_rotateleftextended ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_rotaterightextended ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_int_to_bv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_to_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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))) *) - let is_bv_carry ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) + let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) *) - let is_bv_xor3 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) (** The size of a bit-vector sort. *) let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) @@ -3550,7 +3415,7 @@ end = struct (** Creates a bit-vector constant. *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + let mk_const ( ctx : context ) ( name : symbol ) ( size : int ) = BitVecExpr(Expr.mk_const ctx name (match (mk_sort ctx size) with BitVecSort(s) -> s)) (** @@ -3564,91 +3429,91 @@ end = struct The argument must have a bit-vector sort. *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) + expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = - create_expr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) + expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = - create_expr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) + expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) (** Bitwise conjunction. The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - create_expr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) + expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) (** Unsigned division. @@ -3660,7 +3525,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) (** Signed division. @@ -3675,7 +3540,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) (** Unsigned remainder. @@ -3685,7 +3550,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) (** Signed remainder. @@ -3697,7 +3562,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed remainder (sign follows divisor). @@ -3706,7 +3571,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) (** Unsigned less-than @@ -3714,7 +3579,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed less-than @@ -3722,7 +3587,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) (** Unsigned less-than or equal to. @@ -3730,7 +3595,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed less-than or equal to. @@ -3738,7 +3603,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) (** Unsigned greater than or equal to. @@ -3746,7 +3611,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed greater than or equal to. @@ -3754,7 +3619,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) (** Unsigned greater-than. @@ -3762,7 +3627,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed greater-than. @@ -3770,7 +3635,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) (** Bit-vector concatenation. @@ -3781,7 +3646,7 @@ end = struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) (** Bit-vector extraction. @@ -3792,7 +3657,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) + expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) (** Bit-vector sign extension. @@ -3802,7 +3667,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) (** Bit-vector zero extension. @@ -3813,7 +3678,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) (** Bit-vector repetition. @@ -3821,7 +3686,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) (** Shift left. @@ -3836,7 +3701,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) (** @@ -3851,7 +3716,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) (** Arithmetic shift right @@ -3867,7 +3732,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) (** Rotate Left. @@ -3876,7 +3741,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) (** Rotate Right. @@ -3885,7 +3750,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) (** Rotate Left. @@ -3894,7 +3759,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) (** Rotate Right. @@ -3904,7 +3769,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) (** Create an integer from the bit-vector argument . @@ -3922,7 +3787,7 @@ end = struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = - Arithmetic.Integers.create_expr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) + Arithmetic.Integer.create_expr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3930,7 +3795,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Booleans.create_expr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3938,7 +3803,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise subtraction does not overflow. @@ -3946,7 +3811,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise subtraction does not underflow. @@ -3954,7 +3819,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Booleans.create_expr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3962,7 +3827,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise negation does not overflow. @@ -3970,7 +3835,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3978,7 +3843,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Booleans.create_expr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3986,7 +3851,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) (** Create a bit-vector numeral. @@ -3994,28 +3859,27 @@ end = struct @param v A string representing the value in decimal notation. @param size the size of the bit-vector *) - let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = + let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx size))) end (** Functions to manipulate proof expressions *) -and Proofs : -sig -end = struct +module Proof = +struct (** Indicates whether the term is a Proof for the expression 'true'. *) - let is_true ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) (** Indicates whether the term is a proof for a fact asserted by the user. *) - let is_asserted ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) + let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - let is_goal ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) (** Indicates whether the term is proof via modus ponens @@ -4026,7 +3890,7 @@ end = struct [mp T1 T2]: q The second antecedents may also be a proof for (iff p q). *) - let is_modus_ponens ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) + let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) (** Indicates whether the term is a proof for (R t t), where R is a reflexive relation. @@ -4035,7 +3899,7 @@ end = struct equivalence modulo namings, equality and equivalence. That is, R is either '~', '=' or 'iff'. *) - let is_reflexivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) + let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) (** Indicates whether the term is proof by symmetricity of a relation @@ -4045,7 +3909,7 @@ end = struct [symmetry T1]: (R s t) T1 is the antecedent of this proof object. *) - let is_symmetry ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) + let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) (** Indicates whether the term is a proof by transitivity of a relation @@ -4056,7 +3920,7 @@ end = struct T2: (R s u) [trans T1 T2]: (R t u) *) - let is_transitivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) + let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) (** Indicates whether the term is a proof by condensed transitivity of a relation @@ -4076,7 +3940,7 @@ end = struct if there is a path from s to t, if we view every antecedent (R a b) as an edge between a and b. *) - let is_Transitivity_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) (** @@ -4089,7 +3953,7 @@ end = struct Remark: if t_i == s_i, then the antecedent Ti is suppressed. That is, reflexivity proofs are supressed to save space. *) - let is_monotonicity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) + let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) (** Indicates whether the term is a quant-intro proof @@ -4098,7 +3962,7 @@ end = struct T1: (~ p q) [quant-intro T1]: (~ (forall (x) p) (forall (x) q)) *) - let is_quant_intro ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) + let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) (** Indicates whether the term is a distributivity proof object. @@ -4115,7 +3979,7 @@ end = struct Remark. This rule is used by the CNF conversion pass and instantiated by f = or, and g = and. *) - let is_distributivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) (** Indicates whether the term is a proof by elimination of AND @@ -4124,7 +3988,7 @@ end = struct T1: (and l_1 ... l_n) [and-elim T1]: l_i *) - let is_and_elimination ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) + let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) (** Indicates whether the term is a proof by eliminiation of not-or @@ -4133,7 +3997,7 @@ end = struct T1: (not (or l_1 ... l_n)) [not-or-elim T1]: (not l_i) *) - let is_or_elimination ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) (** Indicates whether the term is a proof by rewriting @@ -4147,11 +4011,11 @@ end = struct Remark: if f is bool, then = is iff. Examples: - (= (+ ( x : Expr.expr ) 0) x) - (= (+ ( x : Expr.expr ) 1 2) (+ 3 x)) - (iff (or ( x : Expr.expr ) false) x) + (= (+ ( x : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) *) - let is_rewrite ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) + let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) (** Indicates whether the term is a proof by rewriting @@ -4166,14 +4030,14 @@ end = struct - When converting bit-vectors to Booleans (BIT2BOOL=true) - When pulling ite expression up (PULL_CHEAP_ITE_TREES=true) *) - let is_rewrite_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) + let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_pull_quant ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) (** Indicates whether the term is a proof for pulling quantifiers out. @@ -4182,7 +4046,7 @@ end = struct This proof object is only used if the parameter PROOF_MODE is 1. This proof object has no antecedents *) - let is_pull_quant_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) (** Indicates whether the term is a proof for pushing quantifiers in. @@ -4195,7 +4059,7 @@ end = struct This proof object has no antecedents *) - let is_push_quant ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) + let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) (** Indicates whether the term is a proof for elimination of unused variables. @@ -4207,34 +4071,34 @@ end = struct This proof object has no antecedents. *) - let is_elim_unused_vars ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : Expr.expr ) t)) P[x])) P[t]) - if ( x : Expr.expr ) does not occur in t. + (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. This proof object has no antecedents. Several variables can be eliminated simultaneously. *) - let is_der ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) + let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) (** Indicates whether the term is a proof for quantifier instantiation A proof of (or (not (forall (x) (P x))) (P a)) *) - let is_quant_inst ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) + let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) (** Indicates whether the term is a hypthesis marker. Mark a hypothesis in a natural deduction style proof. *) - let is_hypothesis ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) + let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) (** Indicates whether the term is a proof by lemma @@ -4246,7 +4110,7 @@ end = struct It converts the proof in a proof for (or (not l_1) ... (not l_n)), when T1 contains the hypotheses: l_1, ..., l_n. *) - let is_lemma ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) + let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) (** Indicates whether the term is a proof by unit resolution @@ -4257,7 +4121,7 @@ end = struct T(n+1): (not l_n) [unit-resolution T1 ... T(n+1)]: (or l_1' ... l_m') *) - let is_unit_resolution ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) (** Indicates whether the term is a proof by iff-true @@ -4265,7 +4129,7 @@ end = struct T1: p [iff-true T1]: (iff p true) *) - let is_iff_true ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) (** Indicates whether the term is a proof by iff-false @@ -4273,7 +4137,7 @@ end = struct T1: (not p) [iff-false T1]: (iff p false) *) - let is_iff_false ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) + let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) (** Indicates whether the term is a proof by commutativity @@ -4285,7 +4149,7 @@ end = struct This proof object has no antecedents. Remark: if f is bool, then = is iff. *) - let is_commutativity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) (** Indicates whether the term is a proof for Tseitin-like axioms @@ -4320,7 +4184,7 @@ end = struct unfolding the Boolean connectives in the axioms a small bounded number of steps (=3). *) - let is_def_axiom ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) (** Indicates whether the term is a proof for introduction of a name @@ -4342,7 +4206,7 @@ end = struct Otherwise: [def-intro]: (= n e) *) - let is_def_intro ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) + let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) (** Indicates whether the term is a proof for application of a definition @@ -4351,7 +4215,7 @@ end = struct F is 'equivalent' to n, given that T1 is a proof that n is a name for F. *) - let is_apply_def ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) + let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) (** Indicates whether the term is a proof iff-oeq @@ -4359,7 +4223,7 @@ end = struct T1: (iff p q) [iff~ T1]: (~ p q) *) - let is_iff_oeq ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) + let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) (** Indicates whether the term is a proof for a positive NNF step @@ -4386,7 +4250,7 @@ end = struct NNF_NEG furthermore handles the case where negation is pushed over Boolean connectives 'and' and 'or'. *) - let is_nnf_pos ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) (** Indicates whether the term is a proof for a negative NNF step @@ -4410,7 +4274,7 @@ end = struct [nnf-neg T1 T2 T3 T4]: (~ (not (iff s_1 s_2)) (and (or r_1 r_2) (or r_1' r_2'))) *) - let is_nnf_neg ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) (** Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form. @@ -4421,7 +4285,7 @@ end = struct This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO. *) - let is_nnf_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) + let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) (** Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form. @@ -4430,19 +4294,19 @@ end = struct 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. *) - let is_cnf_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) + let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) (** Indicates whether the term is a proof for a Skolemization step Proof for: - [sk]: (~ (not (forall ( x : Expr.expr ) (p ( x : Expr.expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : Expr.expr ) (p ( x : Expr.expr ) y)) (p (sk y) y)) + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) This proof object has no antecedents. *) - let is_skolemize ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) + let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) (** Indicates whether the term is a proof by modus ponens for equi-satisfiability. @@ -4452,7 +4316,7 @@ end = struct T2: (~ p q) [mp~ T1 T2]: q *) - let is_modus_ponens_oeq ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) (** Indicates whether the term is a proof for theory lemma @@ -4470,7 +4334,7 @@ end = struct (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. *) - let is_theory_lemma ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) + let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end @@ -4480,10 +4344,8 @@ end of formulas, that can be solved and/or transformed using tactics and solvers. *) module Goal = -struct - type goal = z3_native_object - - (**/**) +struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : goal = { m_ctx = ctx ; m_n_obj = null ; @@ -4492,7 +4354,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** The precision of the goal. @@ -4521,8 +4383,8 @@ struct (** Adds the constraints to the given goal. *) (* CMW: assert seems to be a keyword. *) - let assert_ ( x : goal ) ( constraints : Booleans.bool_expr array ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e) in + let assert_ ( x : goal ) ( constraints : bool_expr array ) = + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in ignore (Array.map f constraints) ; () @@ -4543,7 +4405,7 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = Booleans.create_expr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in + let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) @@ -4562,7 +4424,7 @@ struct create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - let simplify ( x : goal ) ( p : Params.params option ) = + let simplify ( x : goal ) ( p : params option ) = let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in Z3native.tactic_inc_ref (z3obj_gnc x) tn ; let arn = match p with @@ -4602,9 +4464,7 @@ end A Model contains interpretations (assignments) of constants and functions. *) module Model = struct - type model = z3_native_object - - (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : model = { m_ctx = ctx ; m_n_obj = null ; @@ -4613,7 +4473,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Function interpretations @@ -4622,9 +4482,7 @@ struct *) module FuncInterp = struct - type func_interp = z3_native_object - - (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_interp = { m_ctx = ctx ; m_n_obj = null ; @@ -4633,17 +4491,15 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Function interpretations entries An Entry object represents an element in the finite map used to a function interpretation. *) module FuncEntry = - struct - type func_entry = z3_native_object - - (**/**) + struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_entry = { m_ctx = ctx ; m_n_obj = null ; @@ -4652,13 +4508,13 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Return the (symbolic) value of this entry. *) let get_value ( x : func_entry ) = - Expr.create (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) + expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) (** The number of arguments of the entry. @@ -4670,7 +4526,7 @@ struct *) let get_args ( x : func_entry ) = let n = (get_num_args x) in - let f i = (Expr.create (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** @@ -4698,7 +4554,7 @@ struct (** The (symbolic) `else' value of the function interpretation. *) - let get_else ( x : func_interp ) = Expr.create (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) + let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) (** The arity of the function interpretation @@ -4725,7 +4581,7 @@ struct (** Retrieves the interpretation (the assignment) of in the model. A function declaration of zero arity An expression if the function has an interpretation in the model, null otherwise. *) - let get_const_interp ( x : model ) ( f : FuncDecl.func_decl ) = + let get_const_interp ( x : model ) ( f : func_decl ) = if (FuncDecl.get_arity f) != 0 || (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") @@ -4734,19 +4590,19 @@ struct if (Z3native.is_null np) then None else - Some (Expr.create (z3obj_gc x) np) + Some (expr_of_ptr (z3obj_gc x) np) (** Retrieves the interpretation (the assignment) of in the model. A Constant An expression if the constant has an interpretation in the model, null otherwise. *) - let get_const_interp_e ( x : model ) ( a : Expr.expr ) = get_const_interp x (Expr.get_func_decl a) + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) (** Retrieves the interpretation (the assignment) of a non-constant in the model. A function declaration of non-zero arity A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - let rec get_func_interp ( x : model ) ( f : FuncDecl.func_decl ) = + let rec get_func_interp ( x : model ) ( f : func_decl ) = let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in if (FuncDecl.get_arity f) == 0 then let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in @@ -4759,7 +4615,7 @@ struct raise (Z3native.Exception "Argument was not an array constant") else let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x (FuncDecl.create (z3obj_gc x) fd) + get_func_interp x (func_decl_of_ptr (z3obj_gc x) fd) | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); else let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in @@ -4771,7 +4627,7 @@ struct (** The function declarations of the constants in the model. *) let get_const_decls ( x : model ) = let n = (get_num_consts x) in - let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f @@ -4781,15 +4637,15 @@ struct (** The function declarations of the function interpretations in the model. *) let get_func_decls ( x : model ) = let n = (get_num_consts x) in - let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** All symbols that have an interpretation in the model. *) let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in - let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.append (Array.init n_funcs f) (Array.init n_consts g) (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) @@ -4810,15 +4666,15 @@ struct The evaluation of in the model. *) - let eval ( x : model ) ( t : Expr.expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (ptr_of_expr t) completion) in if not r then raise (ModelEvaluationFailedException "evaluation failed") else - Expr.create (z3obj_gc x) v + expr_of_ptr (z3obj_gc x) v (** Alias for eval. *) - let evaluate ( x : model ) ( t : Expr.expr ) ( completion : bool ) = + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = eval x t completion (** The number of uninterpreted sorts that the model has an interpretation for. *) @@ -4834,7 +4690,7 @@ struct *) let get_sorts ( x : model ) = let n = (get_num_sorts x) in - let f i = (Sort.create (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f @@ -4843,10 +4699,10 @@ struct An uninterpreted sort An array of expressions, where each is an element of the universe of *) - let sort_universe ( x : model ) ( s : Sort.sort ) = - let n_univ = AST.ASTVectors.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in - let n = (AST.ASTVectors.get_size n_univ) in - let f i = (AST.ASTVectors.get n_univ i) in + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in Array.init n f (** Conversion of models to strings. @@ -4866,9 +4722,7 @@ end *) module Probe = struct - type probe = z3_native_object - - (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : probe = { m_ctx = ctx ; m_n_obj = null ; @@ -4877,14 +4731,14 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Execute the probe over the goal. A probe always produce a double value. "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - let apply ( x : probe ) (g : Goal.goal) = + let apply ( x : probe ) (g : goal) = Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (** @@ -4988,10 +4842,8 @@ end It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. *) module Tactic = -struct - type tactic = z3_native_object - - (**/**) +struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : tactic = { m_ctx = ctx ; m_n_obj = null ; @@ -5000,7 +4852,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Tactic application results @@ -5008,9 +4860,7 @@ struct tactic to a goal. It contains the subgoals that were produced. *) module ApplyResult = struct - type apply_result = z3_native_object - - (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : apply_result = { m_ctx = ctx ; m_n_obj = null ; @@ -5019,7 +4869,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** The number of Subgoals. *) let get_num_subgoals ( x : apply_result ) = @@ -5039,7 +4889,7 @@ struct goal g, that the ApplyResult was obtained from. #return A model for g *) - let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = + let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) (** A string representation of the ApplyResult. *) @@ -5054,7 +4904,7 @@ struct Params.ParamDescrs.create (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Apply the tactic to the goal. *) - let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = + let apply ( x : tactic ) ( g : goal ) ( p : params option ) = match p with | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) @@ -5122,14 +4972,14 @@ struct If evaluates to false, then the new tactic behaves like the skip tactic. *) (* CMW: when is a keyword *) - let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = + let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) - let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = + let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) (** @@ -5154,7 +5004,7 @@ struct (** Create a tactic that fails if the probe evaluates to false. *) - let fail_if ( ctx : context ) ( p : Probe.probe ) = + let fail_if ( ctx : context ) ( p : probe ) = create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** @@ -5167,14 +5017,14 @@ struct (** Create a tactic that applies using the given set of parameters . *) - let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) (** Create a tactic that applies using the given set of parameters . Alias for UsingParams*) (* CMW: with is a keyword *) - let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + let with_ ( ctx : context ) ( t : tactic ) ( p : params ) = using_params ctx t p (** @@ -5201,10 +5051,8 @@ end (** Solvers *) module Solver = -struct - type solver = z3_native_object - - (**/**) +struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : solver = { m_ctx = ctx ; m_n_obj = null ; @@ -5213,9 +5061,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) - - type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + let string_of_status ( s : status) = match s with | UNSATISFIABLE -> "unsatisfiable" @@ -5224,10 +5070,8 @@ struct (** Objects that track statistical information about solvers. *) module Statistics = - struct - type statistics = z3_native_object - - (**/**) + struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : statistics = { m_ctx = ctx ; m_n_obj = null ; @@ -5236,7 +5080,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Statistical data is organized into pairs of \[Key, Entry\], where every @@ -5245,14 +5089,7 @@ struct *) module Entry = struct - type statistics_entry = { - mutable m_key : string; - mutable m_is_int : bool ; - mutable m_is_float : bool ; - mutable m_int : int ; - mutable m_float : float } - - (**/**) + let create_si k v = let res : statistics_entry = { m_key = k ; @@ -5272,7 +5109,7 @@ struct m_float = v } in res - (**/**) + (** The key of the entry. *) let get_key (x : statistics_entry) = x.m_key @@ -5344,7 +5181,7 @@ struct (** Sets the solver parameters. *) - let set_parameters ( x : solver ) ( p : Params.params )= + let set_parameters ( x : solver ) ( p : params )= Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** @@ -5382,8 +5219,8 @@ struct (** Assert a constraint (or multiple) into the solver. *) - let assert_ ( x : solver ) ( constraints : Booleans.bool_expr array ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e)) in + let assert_ ( x : solver ) ( constraints : bool_expr array ) = + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) (** @@ -5399,11 +5236,11 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( cs : Booleans.bool_expr array ) ( ps : Booleans.bool_expr array ) = + let assert_and_track ( x : solver ) ( cs : bool_expr array ) ( ps : bool_expr array ) = if ((Array.length cs) != (Array.length ps)) then raise (Z3native.Exception "Argument size mismatch") else - let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e) (Booleans.gno (Array.get ps i))) in + let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) (Boolean.gno (Array.get ps i))) in ignore (Array.iteri f cs) (** @@ -5418,24 +5255,24 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( c : Booleans.bool_expr ) ( p : Booleans.bool_expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Booleans.gno c) (Booleans.gno p) + let assert_and_track ( x : solver ) ( c : bool_expr ) ( p : bool_expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) (** The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - (AST.ASTVectors.get_size a) + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + (AST.ASTVector.get_size a) (** The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVectors.get_size a) in - let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get a i)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVector.get_size a) in + let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in Array.init n f (** @@ -5445,12 +5282,13 @@ struct *) - let check ( x : solver ) ( assumptions : Booleans.bool_expr array) = + let check ( x : solver ) ( assumptions : bool_expr array) = let r = if ((Array.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Booleans.aton assumptions)) + let f x = (ptr_of_expr (expr_of_bool_expr x)) in + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Array.map f assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -5481,7 +5319,7 @@ struct if (Z3native.is_null q) then None else - Some (Expr.create (z3obj_gc x) q) + Some (expr_of_ptr (z3obj_gc x) q) (** The unsat core of the last Check. @@ -5491,9 +5329,9 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVectors.get_size cn) in - let f i = (AST.ASTVectors.get cn i) in + let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVector.get_size cn) in + let f i = (AST.ASTVector.get cn i) in Array.init n f (** @@ -5515,7 +5353,7 @@ struct check-sat command, and check-sat commands that take more than a given number of milliseconds to be solved. *) - let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = + let mk_solver ( ctx : context ) ( logic : symbol option ) = match logic with | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) @@ -5539,7 +5377,7 @@ struct The solver supports the commands Push and Pop, but it will always solve each check from scratch. *) - let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = + let mk_solver_t ( ctx : context ) ( t : tactic ) = (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) (** @@ -5551,10 +5389,7 @@ end (** Fixedpoint solving *) module Fixedpoint = -struct - type fixedpoint = z3_native_object - - (**/**) +struct let create ( ctx : context ) = let res : fixedpoint = { m_ctx = ctx ; m_n_obj = null ; @@ -5563,7 +5398,7 @@ struct (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; (z3obj_create res) ; res - (**/**) + (** A string that describes all available fixedpoint solver parameters. @@ -5574,7 +5409,7 @@ struct (** Sets the fixedpoint solver parameters. *) - let set_params ( x : fixedpoint ) ( p : Params.params )= + let set_params ( x : fixedpoint ) ( p : params )= Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** @@ -5586,29 +5421,29 @@ struct (** Assert a constraints into the fixedpoint solver. *) - let assert_ ( x : fixedpoint ) ( constraints : Booleans.bool_expr array ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e)) in + let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) ; () (** Register predicate as recursive relation. *) - let register_relation ( x : fixedpoint ) ( f : FuncDecl.func_decl ) = + let register_relation ( x : fixedpoint ) ( f : func_decl ) = Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (** Add rule into the fixedpoint solver. *) - let add_rule ( x : fixedpoint ) ( rule : Booleans.bool_expr ) ( name : Symbol.symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) (Symbol.gno y) + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) (** Add table fact to the fixedpoint solver. *) - let add_fact ( x : fixedpoint ) ( pred : FuncDecl.func_decl ) ( args : int array ) = + let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (Array.length args) args (** @@ -5617,11 +5452,11 @@ struct 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. *) - let query ( x : fixedpoint ) ( query : Booleans.bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Booleans.gno query))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN + let query ( x : fixedpoint ) ( query : bool_expr ) = + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with + | L_TRUE -> SATISFIABLE + | L_FALSE -> UNSATISFIABLE + | _ -> UNKNOWN (** Query the fixedpoint solver. @@ -5629,11 +5464,12 @@ struct 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. *) - let query_r ( x : fixedpoint ) ( relations : FuncDecl.func_decl array ) = - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (FuncDecl.aton relations))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN + let query_r ( x : fixedpoint ) ( relations : func_decl array ) = + let f x = ptr_of_ast (ast_of_func_decl x) in + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (Array.map f relations))) with + | L_TRUE -> SATISFIABLE + | L_FALSE -> UNSATISFIABLE + | _ -> UNKNOWN (** Creates a backtracking point. @@ -5654,8 +5490,8 @@ struct (** Update named rule into in the fixedpoint solver. *) - let update_rule ( x : fixedpoint ) ( rule : Booleans.bool_expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) (Symbol.gno name) + let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) (** Retrieve satisfying instance or instances of solver, @@ -5666,7 +5502,7 @@ struct if (Z3native.is_null q) then None else - Some (Expr.create (z3obj_gc x) q) + Some (expr_of_ptr (z3obj_gc x) q) (** Retrieve explanation why fixedpoint engine returned status Unknown. @@ -5677,25 +5513,25 @@ struct (** Retrieve the number of levels explored for a given predicate. *) - let get_num_levels ( x : fixedpoint ) ( predicate : FuncDecl.func_decl ) = + let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) (** Retrieve the cover of a predicate. *) - let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : FuncDecl.func_decl ) = + let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in if (Z3native.is_null q) then None else - Some (Expr.create (z3obj_gc x) q) + Some (expr_of_ptr (z3obj_gc x) q) (** Add property about the predicate. The property is added at level. *) - let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : FuncDecl.func_decl ) ( property : Expr.expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) + let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (ptr_of_expr property) (** Retrieve internal string representation of fixedpoint object. @@ -5705,31 +5541,33 @@ struct (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - let set_predicate_representation ( x : fixedpoint ) ( f : FuncDecl.func_decl ) ( kinds : Symbol.symbol array ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Symbol.aton kinds) + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = + let f2 x = (Symbol.gno x) in + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Array.map f2 kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. *) - let to_string_q ( x : fixedpoint ) ( queries : Booleans.bool_expr array ) = - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Booleans.aton queries) + let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = + let f x = ptr_of_expr (expr_of_bool_expr x) in + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Array.map f queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVectors.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVectors.get_size v) in - let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get v i)) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVector.get_size v) in + let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVectors.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVectors.get_size v) in - let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get v i)) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVector.get_size v) in + let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f (** @@ -5813,10 +5651,10 @@ struct @param formula Formula to be checked for consistency in conjunction with assumptions. @return A string representation of the benchmark. *) - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Booleans.bool_expr array ) ( formula : Booleans.bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (Booleans.aton assumptions) - (Booleans.gno formula) + (Array.length assumptions) (let f x = ptr_of_expr (expr_of_bool_expr x) in (Array.map f assumptions)) + (Boolean.gno formula) (** Parse the given string using the SMT-LIB parser. @@ -5827,7 +5665,7 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5837,17 +5675,17 @@ struct else Z3native.parse_smtlib_string (context_gno ctx) str cs - (Symbol.aton sort_names) - (Sort.aton sorts) + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) cd - (Symbol.aton decl_names) - (FuncDecl.aton decls) + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)) (** Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5857,11 +5695,11 @@ struct else Z3native.parse_smtlib_file (context_gno ctx) file_name cs - (Symbol.aton sort_names) - (Sort.aton sorts) + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) cd - (Symbol.aton decl_names) - (FuncDecl.aton decls) + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)) (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. @@ -5873,7 +5711,7 @@ struct *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = Booleans.create_expr ctx (Z3native.get_smtlib_formula (context_gno ctx) i) in + let f i = bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in Array.init n f @@ -5887,7 +5725,7 @@ struct *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = Booleans.create_expr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i) in + let f i = bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in Array.init n f (** @@ -5900,7 +5738,7 @@ struct *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in - let f i = FuncDecl.create ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in + let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f (** @@ -5913,7 +5751,7 @@ struct *) let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in - let f i = (Sort.create ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in + let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in Array.init n f (** @@ -5922,7 +5760,7 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5930,19 +5768,19 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (Symbol.aton sort_names) - (Sort.aton sorts) - cd - (Symbol.aton decl_names) - (FuncDecl.aton decls) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str + cs + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) + cd + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)))) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5950,13 +5788,13 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib2_string (context_gno ctx) file_name + bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name cs - (Symbol.aton sort_names) - (Sort.aton sorts) + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) cd - (Symbol.aton decl_names) - (FuncDecl.aton decls) + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)))) end From a27945f297c20a5af0794d3c8bbff1b1612c7268 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 20:04:11 +0000 Subject: [PATCH 056/248] ML API: got rid of "extra" objects on types. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 73 +++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index ea8c9576e..aa919e7fc 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -93,13 +93,7 @@ type quantifier = Quantifier of expr type pattern = Pattern of ast (* Datatype stuff *) -type constructor_extra = { - m_n : int; - mutable m_tester_decl : func_decl option; - mutable m_constructor_decl : func_decl option ; - mutable m_accessor_decls : func_decl array option} - -type constructor = Constructor of (z3_native_object * constructor_extra) +type constructor = z3_native_object type constructor_list = z3_native_object (* Tactical interface *) @@ -2358,7 +2352,8 @@ struct (** Constructors *) module Constructor = struct - + let _counts = Hashtbl.create 0 + let create ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then @@ -2373,53 +2368,31 @@ struct (let f x = (Symbol.gno x) in (Array.map f field_names)) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) sort_refs) in - let no : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref} in - let ex : constructor_extra = { m_n = n; - m_tester_decl = None; - m_constructor_decl = None; - m_accessor_decls = None} in + let no : constructor = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + Hashtbl.add _counts no n ; (z3obj_sno no ctx ptr) ; (z3obj_create no) ; let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; - Constructor(no, ex) + no - let init_extra ( x : constructor ) = - match x with Constructor(no, ex) -> - match ex.m_tester_decl with - | None -> - let (a, b, c) = (Z3native.query_constructor (z3obj_gnc no) (z3obj_gno no) ex.m_n) in - ex.m_constructor_decl <- Some (func_decl_of_ptr (z3obj_gc no) a) ; - ex.m_tester_decl <- Some (func_decl_of_ptr (z3obj_gc no) b) ; - ex.m_accessor_decls <- Some (let f e = (func_decl_of_ptr (z3obj_gc no) e) in Array.map f c) ; - () - | _ -> () - - - let get_n ( x : constructor ) = - match x with Constructor(no, ex) -> - ex.m_n + let get_n ( x : constructor ) = (Hashtbl.find _counts x) - let rec tester_decl ( x : constructor ) = - match x with Constructor(no, ex) -> - match ex.m_tester_decl with - | Some(s) -> s - | None -> init_extra x ; tester_decl x - let rec constructor_decl ( x : constructor ) = - match x with Constructor(no, ex) -> - match ex.m_constructor_decl with - | Some(s) -> s - | None -> init_extra x ; constructor_decl x + let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + func_decl_of_ptr (z3obj_gc x) a + + let rec tester_decl ( x : constructor ) = + let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + func_decl_of_ptr (z3obj_gc x) b let rec accessor_decls ( x : constructor ) = - match x with Constructor(no, ex) -> - match ex.m_accessor_decls with - | Some(s) -> s - | None -> init_extra x ; accessor_decls x + let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + let f y = func_decl_of_ptr (z3obj_gc x) y in + Array.map f c (** The number of fields of the constructor. *) let get_num_fields ( x : constructor ) = get_n x @@ -2443,7 +2416,7 @@ struct m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref} in - let f x = match x with Constructor(no,_) -> (z3obj_gno no) in + let f x =(z3obj_gno x) in (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Array.map f c))) ; (z3obj_create res) ; let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in @@ -2462,7 +2435,7 @@ struct 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. *) - let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = Constructor.create ctx name recognizer field_names sorts sort_refs @@ -2483,8 +2456,8 @@ struct (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = - let f x = match x with Constructor(no,_) -> (z3obj_gno no) in + let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array ) = + let f x = (z3obj_gno x) in let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in create_sort ctx x From 5f41a40a63eb31a823628b7b77f73b17b1e9bcbf Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 22:49:19 +0000 Subject: [PATCH 057/248] ML API: build system fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index a187bf9cb..e32ca14f9 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1332,40 +1332,49 @@ class MLComponent(Component): def mk_makefile(self, out): if is_ml_enabled(): + CP_CMD = "cp" + if IS_WINDOWS: + CP_CMD = "copy" src_dir = self.to_src_dir sub_dir = os.path.join('api', 'ml') mk_dir(os.path.join(BUILD_DIR, sub_dir)) api_src = get_component(API_COMPONENT).to_src_dir for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): - shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) + out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) + out.write('\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f)) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): - shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) - cmis = '%s/z3enums.cmi %s/z3native.cmi %s/z3.cmi' % (src_dir,src_dir,src_dir) - out.write('%s/z3enums.cmi: %s/z3enums.mli\n' % (src_dir,src_dir)) - out.write('\t%s -I %s -c %s/z3enums.mli\n' % (OCAMLC,src_dir,src_dir)) - out.write('%s/z3native.cmi: %s/z3native.mli\n' % (src_dir,src_dir)) - out.write('\t%s -I %s -c %s/z3native.mli\n' % (OCAMLC,src_dir,src_dir)) - out.write('%s/z3.cmi: %s/z3.mli\n' % (src_dir,src_dir)) - out.write('\t%s -I %s -c %s/z3.mli\n' % (OCAMLC,src_dir,src_dir)) - out.write('api/ml/libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, src_dir)) + out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) + out.write('\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f)) + modules = ["z3enums", "z3native", "z3"] # dependencies in this order! + prev = '' + for m in modules: + out.write('%s/%s.mli: %s/%s.ml %s\n' % (sub_dir,m,sub_dir,m,prev)) + out.write('\t%s -I %s -i -c %s/%s.ml > %s/%s.mli\n' % (OCAMLC,sub_dir,sub_dir,m,sub_dir,m)) + prev = prev + ' ' + sub_dir + '/' + m + '.mli' + cmis = '' + for m in modules: + out.write('%s/%s.cmi: %s/%s.mli\n' % (sub_dir,m,sub_dir,m)) + out.write('\t%s -I %s -c %s/%s.mli\n' % (OCAMLC,sub_dir,sub_dir,m)) + cmis = cmis + ' ' + sub_dir + '/' + m + '.cmi' + out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(src_dir, mlfile)) + out.write(' %s' % os.path.join(sub_dir, mlfile)) out.write('\n') out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) + out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) + out.write(' %s' % os.path.join(sub_dir, mlfile)) out.write('\n') out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) + out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') out.write('\n') From fd2ae5f60e28c8523be6dac66b41a7e1d9e67421 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 23:42:50 +0000 Subject: [PATCH 058/248] ML API: bugfixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 54 +++++++++++++++++++++-------------- src/api/ml/z3.ml | 60 ++++++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 47 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 3b13a2462..49db6fb50 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -7,6 +7,7 @@ open Z3 open Z3.Symbol open Z3.Sort open Z3.Expr +open Z3.Boolean open Z3.FuncDecl open Z3.Goal open Z3.Tactic @@ -22,12 +23,20 @@ exception TestFailedException of string *) let model_converter_test ( ctx : context ) = Printf.printf "ModelConverterTest\n"; - let xr = ((mk_const ctx (Symbol.mk_string ctx "x") (mk_real_sort ctx )) :> arith_expr) in - let yr = ((mk_const ctx (Symbol.mk_string ctx "y") (mk_real_sort ctx )) :> arith_expr) in + let xr = (arith_expr_of_expr + (Expr.mk_const ctx (Symbol.mk_string ctx "x") + (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in + let yr = (arith_expr_of_expr + (Expr.mk_const ctx (Symbol.mk_string ctx "y") + (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in let g4 = (mk_goal ctx true false false ) in - (Goal.assert_ g4 [| (mk_gt ctx xr (mk_real_numeral_nd ctx 10 1)) |]) ; - (Goal.assert_ g4 [| (mk_eq ctx yr (mk_add ctx [| xr; (mk_real_numeral_nd ctx 1 1) |] )) |] ) ; - (Goal.assert_ g4 [| (mk_gt ctx yr (mk_real_numeral_nd ctx 1 1)) |]) ; + (Goal.assert_ g4 [| (mk_gt ctx xr + (arith_expr_of_real_expr (real_expr_of_rat_num + (Real.mk_numeral_nd ctx 10 1)))) |]) ; + (Goal.assert_ g4 [| (mk_eq ctx + (expr_of_arith_expr yr) + (expr_of_arith_expr (mk_add ctx [| xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) |] ))) |] ) ; + (Goal.assert_ g4 [| (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) |]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in if ((get_num_subgoals ar) == 1 && @@ -67,15 +76,15 @@ let model_converter_test ( ctx : context ) = *) let basic_tests ( ctx : context ) = Printf.printf "BasicTests\n" ; - let qi = (mk_int ctx 1) in +(* let qi = (mk_int ctx 1) in *) let fname = (mk_string ctx "f") in let x = (mk_string ctx "x") in let y = (mk_string ctx "y") in - let bs = (Sort.mk_bool ctx) in + let bs = (sort_of_bool_sort (Boolean.mk_sort ctx)) in let domain = [| bs; bs |] in let f = (FuncDecl.mk_func_decl ctx fname domain bs) in let fapp = (mk_app ctx f - [| (mk_const ctx x bs); (mk_const ctx y bs) |]) in + [| (Expr.mk_const ctx x bs); (Expr.mk_const ctx y bs) |]) in let fargs2 = [| (mk_fresh_const ctx "cp" bs) |] in let domain2 = [| bs |] in let fapp2 = (mk_app ctx (mk_fresh_func_decl ctx "fp" domain2 bs) fargs2) in @@ -110,8 +119,11 @@ let basic_tests ( ctx : context ) = else Printf.printf "Test passed.\n" ); - (Goal.assert_ g [| (mk_eq ctx (mk_numeral_int ctx 1 (BitVectors.mk_sort ctx 32)) - (mk_numeral_int ctx 2 (BitVectors.mk_sort ctx 32))) |] ) + (Goal.assert_ g [| (mk_eq ctx + (mk_numeral_int ctx 1 + (sort_of_bitvec_sort (BitVector.mk_sort ctx 32))) + (mk_numeral_int ctx 2 + (sort_of_bitvec_sort (BitVector.mk_sort ctx 32)))) |] ) ; ( let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in @@ -132,7 +144,7 @@ let basic_tests ( ctx : context ) = ); ( let g2 = (mk_goal ctx true true false) in - (Goal.assert_ g2 [| (mk_false ctx) |]) ; + (Goal.assert_ g2 [| (Boolean.mk_false ctx) |]) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then @@ -142,10 +154,10 @@ let basic_tests ( ctx : context ) = ); ( let g3 = (mk_goal ctx true true false) in - let xc = (mk_const ctx (Symbol.mk_string ctx "x") (mk_int_sort ctx)) in - let yc = (mk_const ctx (Symbol.mk_string ctx "y") (mk_int_sort ctx)) in - (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (mk_int_sort ctx))) |]) ; - (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (mk_int_sort ctx))) |]) ; + let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in + let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in + (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) |]) ; + (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) |]) ; let constr = (mk_eq ctx xc yc) in (Goal.assert_ g3 [| constr |] ) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in @@ -208,14 +220,14 @@ let _ = let ctx = (mk_context cfg) in let is = (Symbol.mk_int ctx 42) in let ss = (Symbol.mk_string ctx "mySymbol") in - let bs = (Sort.mk_bool ctx) in - let ints = (mk_int_sort ctx) in - let rs = (mk_real_sort ctx) in + let bs = (Boolean.mk_sort ctx) in + let ints = (Integer.mk_sort ctx) in + let rs = (Real.mk_sort ctx) in Printf.printf "int symbol: %s\n" (Symbol.to_string is); Printf.printf "string symbol: %s\n" (Symbol.to_string ss); - Printf.printf "bool sort: %s\n" (Sort.to_string bs); - Printf.printf "int sort: %s\n" (Sort.to_string ints); - Printf.printf "real sort: %s\n" (Sort.to_string rs); + Printf.printf "bool sort: %s\n" (Sort.to_string (sort_of_bool_sort bs)); + Printf.printf "int sort: %s\n" (Sort.to_string (sort_of_arith_sort (arith_sort_of_int_sort ints))); + Printf.printf "real sort: %s\n" (Sort.to_string (sort_of_arith_sort (arith_sort_of_real_sort rs))); basic_tests ctx ; Printf.printf "Disposing...\n"; Gc.full_major () diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index aa919e7fc..651102bc8 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -240,7 +240,7 @@ struct Expr(z3_native_object_of_ast_ptr ctx no) else let s = Z3native.get_sort (context_gno ctx) no in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in if (Z3native.is_algebraic_number (context_gno ctx) no) then Expr(z3_native_object_of_ast_ptr ctx no) else @@ -376,92 +376,99 @@ let expr_of_ast a = Expr(a) let bool_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.BOOL_SORT) then raise (Z3native.Exception "Invalid coercion") else BoolExpr(e) let arith_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then raise (Z3native.Exception "Invalid coercion") else ArithExpr(e) let bitvec_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.BV_SORT) then raise (Z3native.Exception "Invalid coercion") else BitVecExpr(e) let array_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.ARRAY_SORT) then raise (Z3native.Exception "Invalid coercion") else ArrayExpr(e) let datatype_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.DATATYPE_SORT) then raise (Z3native.Exception "Invalid coercion") else DatatypeExpr(e) let int_expr_of_arith_expr e = - match e with ArithExpr(Expr(no)) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.INT_SORT) then raise (Z3native.Exception "Invalid coercion") else IntExpr(e) let real_expr_of_arith_expr e = - match e with ArithExpr(Expr(no)) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.REAL_SORT) then raise (Z3native.Exception "Invalid coercion") else RealExpr(e) let int_num_of_int_expr e = - match e with IntExpr(ArithExpr(Expr(no))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + match e with IntExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then raise (Z3native.Exception "Invalid coercion") else IntNum(e) let rat_num_of_real_expr e = - match e with RealExpr(ArithExpr(Expr(no))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + match e with RealExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then raise (Z3native.Exception "Invalid coercion") else RatNum(e) let algebraic_num_of_arith_expr e = - match e with ArithExpr(Expr(no)) -> - if (not (Z3native.is_algebraic_number (z3obj_gnc no) (z3obj_gno no))) then + match e with ArithExpr(Expr(a)) -> + if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then raise (Z3native.Exception "Invalid coercion") else AlgebraicNum(e) let bitvec_num_of_bitvec_expr e = - match e with BitVecExpr(Expr(no)) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + match e with BitVecExpr(Expr(a)) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then raise (Z3native.Exception "Invalid coercion") else BitVecNum(e) let quantifier_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in if (q != Z3enums.QUANTIFIER_AST) then raise (Z3native.Exception "Invalid coercion") else @@ -4378,7 +4385,8 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (bool_expr_of_expr (expr_of_ptr (z3obj_gc x) + (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) From 09aa02759f3501492f0f710ae50848687f4eb22a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 20 Feb 2013 11:49:00 +0000 Subject: [PATCH 059/248] ML API: Build system and error handling fixes. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 8 ++++++-- scripts/update_api.py | 12 ++++++++++++ src/api/ml/z3.ml | 6 +----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index e32ca14f9..a30e074b0 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1341,10 +1341,14 @@ class MLComponent(Component): api_src = get_component(API_COMPONENT).to_src_dir for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) - out.write('\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f)) + str = '\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f) + if IS_WINDOWS: str = str.replace('/','\\') + out.write(str) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) - out.write('\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f)) + str = '\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f) + if IS_WINDOWS: str = str.replace('/','\\') + out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! prev = '' for m in modules: diff --git a/scripts/update_api.py b/scripts/update_api.py index 6e9c14355..e5c66dd39 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1169,9 +1169,11 @@ def mk_ml(): ml_i.write('\n') ml_native.write('external is_null : ptr -> bool\n = "n_is_null"\n\n') ml_native.write('external mk_null : unit -> ptr\n = "n_mk_null"\n\n') + ml_native.write('external set_internal_error_handler : ptr -> unit\n = "n_set_internal_error_handler"\n\n') ml_native.write('exception Exception of string\n\n') ml_i.write('val is_null : ptr -> bool\n') ml_i.write('val mk_null : unit -> ptr\n') + ml_i.write('val set_internal_error_handler : ptr -> unit\n\n') ml_i.write('exception Exception of string\n\n') # ML declarations @@ -1329,6 +1331,16 @@ def mk_ml(): ml_wrapper.write(' memcpy( Data_custom_val(result), &z3_result, sizeof(void*));\n') ml_wrapper.write(' CAMLreturn (result);\n') ml_wrapper.write('}\n\n') + ml_wrapper.write('void MLErrorHandler(Z3_context c, Z3_error_code e)\n') + ml_wrapper.write('{\n') + ml_wrapper.write(' // Internal do-nothing error handler. This is required to avoid that Z3 calls exit()\n') + ml_wrapper.write(' // upon errors, but the actual error handling is done by throwing exceptions in the\n') + ml_wrapper.write(' // wrappers below.\n') + ml_wrapper.write('}\n\n') + ml_wrapper.write('void n_set_internal_error_handler(Z3_context c)\n') + ml_wrapper.write('{\n') + ml_wrapper.write(' Z3_set_error_handler(c, MLErrorHandler);\n') + ml_wrapper.write('}\n\n') for name, result, params in _dotnet_decls: ip = inparams(params) op = outparams(params) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 651102bc8..45faae468 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -135,16 +135,12 @@ struct let v = Z3native.mk_context_rc cfg in Z3native.del_config(cfg) ; Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + Z3native.set_internal_error_handler v ; (* Printf.printf "Installing finalizer on context \n" ; *) let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in let f = fun o -> dispose_context o in Gc.finalise f res; res - (* CMW: Install error handler here! - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); - *) let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) From 2af1f81ae17a42801384c5e543edcdbc16b4dcfd Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 20 Feb 2013 18:37:52 +0000 Subject: [PATCH 060/248] ML API: Cleanup Signed-off-by: Christoph M. Wintersteiger --- examples/ml/Makefile | 4 +- examples/ml/ml_example.ml | 5 +- scripts/update_api.py | 2 + src/api/ml/z3.ml | 2247 +++++++++++++++++++------------------ 4 files changed, 1159 insertions(+), 1099 deletions(-) diff --git a/examples/ml/Makefile b/examples/ml/Makefile index 4b3e7c4d2..a7f8e6ee0 100644 --- a/examples/ml/Makefile +++ b/examples/ml/Makefile @@ -3,5 +3,5 @@ # in the top-level build directory. all: - OCAML_COMPAT=c ocamlc -g -annot -o ml_example.byte -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cma ml_example.ml - ocamlopt -g -annot -o ml_example -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cmxa ml_example.ml + OCAML_COMPAT=c C:/ocamlw32/bin/ocamlc -g -annot -o ml_example.byte -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cma ml_example.ml + C:/ocamlw32/bin/ocamlopt -g -annot -o ml_example -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cmxa ml_example.ml diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 49db6fb50..6dfe11623 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -15,6 +15,9 @@ open Z3.Tactic.ApplyResult open Z3.Probe open Z3.Solver open Z3.Arithmetic +open Z3.Arithmetic.Integer +open Z3.Arithmetic.Real +open Z3.BitVector exception TestFailedException of string @@ -35,7 +38,7 @@ let model_converter_test ( ctx : context ) = (Real.mk_numeral_nd ctx 10 1)))) |]) ; (Goal.assert_ g4 [| (mk_eq ctx (expr_of_arith_expr yr) - (expr_of_arith_expr (mk_add ctx [| xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) |] ))) |] ) ; + (expr_of_arith_expr (Arithmetic.mk_add ctx [| xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) |]) ) ) |] ) ; (Goal.assert_ g4 [| (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) |]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in diff --git a/scripts/update_api.py b/scripts/update_api.py index e5c66dd39..a0b7e6250 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1155,6 +1155,7 @@ def mk_ml(): ml_native.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') ml_i.write('(* Automatically generated file *)\n\n') ml_i.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') + ml_i.write('(**/**)\n\n'); ml_native.write('open Z3enums\n\n') ml_native.write('(**/**)\n') ml_native.write('type ptr\n') @@ -1214,6 +1215,7 @@ def mk_ml(): ml_native.write(' "n_%s_bytecode"\n' % ml_method_name(name)) ml_native.write('\n') ml_native.write(' end\n\n') + ml_i.write('\n(**/**)\n'); # Exception wrappers for name, result, params in _dotnet_decls: diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 45faae468..c261fce05 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -16,104 +16,11 @@ let is_null o = (Z3native.is_null o) type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } type context = z3_native_context - - type z3_native_object = { m_ctx : context ; mutable m_n_obj : Z3native.ptr ; inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - - -(* Symbol types *) -type int_symbol = z3_native_object -type string_symbol = z3_native_object - -type symbol = - | S_Int of int_symbol - | S_Str of string_symbol - -(* AST types *) -type ast = z3_native_object -type ast_vector = z3_native_object -type ast_map = z3_native_object - -(* FuncDecl types *) -type func_decl = FuncDecl of ast - -(* Sort types *) -type sort = Sort of ast -type uninterpreted_sort = UninterpretedSort of sort -type bool_sort = BoolSort of sort -type array_sort = ArraySort of sort -type set_sort = SetSort of sort -type datatype_sort = DatatypeSort of sort -type relation_sort = RelationSort of sort -type finite_domain_sort = FiniteDomainSort of sort -type enum_sort = EnumSort of sort -type list_sort = ListSort of sort -type tuple_sort = TupleSort of sort -type arith_sort = ArithSort of sort -type bitvec_sort = BitVecSort of sort - -type int_sort = IntSort of arith_sort -type real_sort = RealSort of arith_sort - -(* FuncDecl parameters *) -type parameter = - | P_Int of int - | P_Dbl of float - | P_Sym of symbol - | P_Srt of sort - | P_Ast of ast - | P_Fdl of func_decl - | P_Rat of string -type params = z3_native_object -type param_descrs = z3_native_object - -(* Expr types *) -type expr = Expr of ast - -type bool_expr = BoolExpr of expr -type arith_expr = ArithExpr of expr -type int_expr = IntExpr of arith_expr -type real_expr = RealExpr of arith_expr -type bitvec_expr = BitVecExpr of expr -type array_expr = ArrayExpr of expr -type datatype_expr = DatatypeExpr of expr - -(* Numerals *) -type int_num = IntNum of int_expr -type rat_num = RatNum of real_expr -type algebraic_num = AlgebraicNum of arith_expr -type bitvec_num = BitVecNum of bitvec_expr - -(* Quantifier stuff *) -type quantifier = Quantifier of expr -type pattern = Pattern of ast - -(* Datatype stuff *) -type constructor = z3_native_object -type constructor_list = z3_native_object - -(* Tactical interface *) -type goal = z3_native_object -type model = z3_native_object -type func_interp = z3_native_object -type func_entry = z3_native_object -type probe = z3_native_object -type tactic = z3_native_object -type apply_result = z3_native_object -type solver = z3_native_object -type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE -type statistics = z3_native_object -type statistics_entry = { - mutable m_key : string; - mutable m_is_int : bool ; - mutable m_is_float : bool ; - mutable m_int : int ; - mutable m_float : float } -type fixedpoint = z3_native_object (** Internal stuff *) @@ -121,11 +28,9 @@ module Internal = struct let dispose_context ctx = if ctx.m_n_obj_cnt == 0 then ( - (* Printf.printf "Disposing context \n" ; *) (Z3native.del_context ctx.m_n_ctx) ) else ( - Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; - (* re-queue for finalization? *) + Printf.printf "ERROR: NOT DISPOSING CONTEXT (because it still has %d objects alive)\n" ctx.m_n_obj_cnt; ) let create_context settings = @@ -136,7 +41,6 @@ struct Z3native.del_config(cfg) ; Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; Z3native.set_internal_error_handler v ; - (* Printf.printf "Installing finalizer on context \n" ; *) let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in let f = fun o -> dispose_context o in Gc.finalise f res; @@ -178,16 +82,6 @@ struct let array_to_native a = let f e = (z3obj_gno e) in Array.map f a - - (* Internal coercions *) - let context_of_ast ( x : ast ) = (z3obj_gc x) - let nc_of_ast ( x : ast ) = (z3obj_gnc x) - let ptr_of_ast ( x : ast ) = (z3obj_gno x) - - let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) - let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) - let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) - let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> let res : z3_native_object = { m_ctx = ctx ; @@ -196,323 +90,25 @@ struct dec_ref = Z3native.dec_ref } in (z3obj_sno res ctx no) ; (z3obj_create res) ; - res - - let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> - let q = (z3_native_object_of_ast_ptr ctx no) in - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then - raise (Z3native.Exception "Invalid coercion") - else - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with - | ARRAY_SORT - | BOOL_SORT - | BV_SORT - | DATATYPE_SORT - | INT_SORT - | REAL_SORT - | UNINTERPRETED_SORT - | FINITE_DOMAIN_SORT - | RELATION_SORT -> Sort(q) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - - let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - FuncDecl(z3_native_object_of_ast_ptr ctx no) - - let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST - | SORT_AST - | QUANTIFIER_AST - | APP_AST - | NUMERAL_AST - | VAR_AST -> z3_native_object_of_ast_ptr ctx no - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") - - and expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then - Expr(z3_native_object_of_ast_ptr ctx no) - else - let s = Z3native.get_sort (context_gno ctx) no in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) no) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - if (Z3native.is_numeral_ast (context_gno ctx) no) then - if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - raise (Z3native.Exception "Unsupported numeral object") - else - Expr(z3_native_object_of_ast_ptr ctx no) - - let expr_aton ( a : expr array ) = - let f ( e : expr ) = match e with Expr(a) -> (ptr_of_ast a) in - Array.map f a - - let expr_of_func_app : context -> func_decl -> expr array -> expr = fun ctx f args -> - match f with FuncDecl(fa) -> - let o = Z3native.mk_app (context_gno ctx) (ptr_of_ast fa) (Array.length args) (expr_aton args) in - expr_of_ptr ctx o + res end - open Internal - - -(* Sort coercions *) -let ast_of_sort s = match s with Sort(x) -> x -let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x -let sort_of_bool_sort s = match s with BoolSort(x) -> x -let sort_of_array_sort s = match s with ArraySort(x) -> x -let sort_of_set_sort s = match s with SetSort(x) -> x -let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x -let sort_of_relation_sort s = match s with RelationSort(x) -> x -let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x -let sort_of_enum_sort s = match s with EnumSort(x) -> x -let sort_of_list_sort s = match s with ListSort(x) -> x -let sort_of_tuple_sort s = match s with TupleSort(x) -> x -let sort_of_arith_sort s = match s with ArithSort(x) -> x -let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x -let arith_sort_of_int_sort s = match s with IntSort(x) -> x -let arith_sort_of_real_sort s = match s with RealSort(x) -> x - -let uninterpreted_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - UninterpretedSort(s) - -let bool_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolSort(s) - -let array_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArraySort(s) - -let datatype_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeSort(s) - -let relation_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RelationSort(s) - -let finite_domain_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - FiniteDomainSort(s) - -let arith_sort_of_sort s = match s with Sort(a) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithSort(s) - -let bitvec_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecSort(s) - -let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntSort(s) - -let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealSort(s) - -(* FuncDecl coercions *) -let ast_of_func_decl f = match f with FuncDecl(x) -> x - -(* Expr coercions *) -let ast_of_expr e = match e with Expr(a) -> a -let expr_of_bool_expr e = match e with BoolExpr(x) -> x -let expr_of_arith_expr e = match e with ArithExpr(x) -> x -let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x -let expr_of_array_expr e = match e with ArrayExpr(x) -> x -let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x - -let arith_expr_of_int_expr e = match e with IntExpr(x) -> x -let arith_expr_of_real_expr e = match e with RealExpr(x) -> x - -let int_expr_of_int_num e = match e with IntNum(x) -> x -let real_expr_of_rat_num e = match e with RatNum(x) -> x -let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x -let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x - -let expr_of_quantifier e = match e with Quantifier(x) -> x -let ast_of_pattern e = match e with Pattern(x) -> x - - -let expr_of_ast a = - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Expr(a) - -let bool_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolExpr(e) - -let arith_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithExpr(e) - -let bitvec_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecExpr(e) - -let array_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArrayExpr(e) - -let datatype_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeExpr(e) - -let int_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntExpr(e) - -let real_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealExpr(e) - -let int_num_of_int_expr e = - match e with IntExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - IntNum(e) - -let rat_num_of_real_expr e = - match e with RealExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - RatNum(e) - -let algebraic_num_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - AlgebraicNum(e) - -let bitvec_num_of_bitvec_expr e = - match e with BitVecExpr(Expr(a)) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecNum(e) - -let quantifier_of_expr e = - match e with Expr(a) -> - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.QUANTIFIER_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Quantifier(e) - -let pattern_of_ast a = - (* CMW: Unchecked ok? *) - Pattern(a) - - - -(** 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. *) module Log = struct - (** Open an interaction log file. - @param filename the name of the file to open. - @return True if opening the log file succeeds, false otherwise. - *) - (* CMW: "open" seems to be a reserved keyword? *) let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) - - (** Closes the interaction log. *) let close = Z3native.close_log - - (** Appends a user-provided string to the interaction log. - @param s the string to append*) let append s = Z3native.append_log s end -(** Version information *) module Version = struct - (** The major version. *) let major = let (x, _, _, _) = Z3native.get_version in x - - (** The minor version. *) let minor = let (_, x, _, _) = Z3native.get_version in x - - (** The build version. *) let build = let (_, _, x, _) = Z3native.get_version in x - - (** The revision. *) let revision = let (_, _, _, x) = Z3native.get_version in x - - (** A string representation of the version information. *) let to_string = let (mj, mn, bld, rev) = Z3native.get_version in string_of_int mj ^ "." ^ @@ -532,35 +128,21 @@ let mk_list ( f : int -> 'a ) ( n : int ) = mk_list' f 0 n [] -(** Create a context object. - - Most interactions with Z3 are interpreted in some context; many users will only - require one such object, but power users may require more than one. To start using - Z3, do - - - let ctx = (mk_context []) in - (...) - - - where a list of pairs of strings may be passed to set options on - the context, e.g., like so: - - - let cfg = [("model", "true"); ("...", "...")] in - let ctx = (mk_context cfg) in - (...) - -*) let mk_context ( cfg : ( string * string ) list ) = create_context cfg - - -(** Symbols are used to name several term and type constructors *) module Symbol = -struct +struct + (* Symbol types *) + type int_symbol = z3_native_object + type string_symbol = z3_native_object + + type symbol = + | S_Int of int_symbol + | S_Str of string_symbol + + let create_i ( ctx : context ) ( no : Z3native.ptr ) = let res : int_symbol = { m_ctx = ctx ; m_n_obj = null ; @@ -588,7 +170,7 @@ struct match x with | S_Int(n) -> (z3obj_gc n) | S_Str(n) -> (z3obj_gc n) - + let gnc ( x : symbol ) = match x with | S_Int(n) -> (z3obj_gnc n) @@ -599,59 +181,55 @@ struct | S_Int(n) -> (z3obj_gno n) | S_Str(n) -> (z3obj_gno n) - (** The kind of the symbol (int or string) *) - let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) - - (** Indicates whether the symbol is of Int kind *) + let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL - - (** Indicates whether the symbol is of string kind. *) let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL - - (** The int value of the symbol. *) let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) - - (** The string value of the symbol. *) let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) - - (** A string representation of the symbol. *) let to_string ( o : symbol ) = match (kind o) with | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) - (** - 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. - *) let mk_int ( ctx : context ) ( i : int ) = S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) - (** Creates a new symbol using a string. *) let mk_string ( ctx : context ) ( s : string ) = S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) - (** Create an array of symbols. *) let mk_ints ( ctx : context ) ( names : int array ) = let f elem = mk_int ( ctx : context ) elem in (Array.map f names) - (** Create an array of symbols. *) let mk_strings ( ctx : context ) ( names : string array ) = let f elem = mk_string ( ctx : context ) elem in (Array.map f names) end -(** The abstract syntax tree (AST) module *) module AST = -struct - (** Vectors of ASTs *) +struct + type ast = z3_native_object + + let context_of_ast ( x : ast ) = (z3obj_gc x) + let nc_of_ast ( x : ast ) = (z3obj_gnc x) + let ptr_of_ast ( x : ast ) = (z3obj_gno x) + + let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with + | FUNC_DECL_AST + | SORT_AST + | QUANTIFIER_AST + | APP_AST + | NUMERAL_AST + | VAR_AST -> z3_native_object_of_ast_ptr ctx no + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") + module ASTVector = struct - let create ( ctx : context ) ( no : Z3native.ptr ) = + type ast_vector = z3_native_object + + let ast_vector_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_vector_inc_ref ; @@ -659,55 +237,34 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - - - (** The size of the vector *) + let get_size ( x : ast_vector ) = Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) - (** - Retrieves the i-th object in the vector. - @param i Index - @return An AST - *) let get ( x : ast_vector ) ( i : int ) = - create (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) + ast_of_ptr (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) - (** Sets the i-th object in the vector. *) let set ( x : ast_vector ) ( i : int ) ( value : ast ) = Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) - (** Resize the vector to . - @param newSize The new size of the vector. *) let resize ( x : ast_vector ) ( new_size : int ) = Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size - (** - Add the AST to the back of the vector. The size - is increased by 1. - @param a An AST - *) let push ( x : ast_vector ) ( a : ast ) = Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) - (** - Translates all ASTs in the vector to . - @param to_ctx A context - @return A new ASTVector - *) let translate ( x : ast_vector ) ( to_ctx : context ) = - create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + ast_vector_of_ptr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - (** Retrieves a string representation of the vector. *) let to_string ( x : ast_vector ) = Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) end - (** Map from AST to AST *) module ASTMap = struct + type ast_map = z3_native_object - let create ( ctx : context ) ( no : Z3native.ptr ) = + let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_map = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_map_inc_ref ; @@ -715,73 +272,36 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - - - (** Checks whether the map contains the key . - @param k An AST - @return True if is a key in the map, false otherwise. *) + let contains ( x : ast_map ) ( key : ast ) = Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - (** Finds the value associated with the key . - - This function signs an error when is not a key in the map. - @param k An AST - *) let find ( x : ast_map ) ( key : ast ) = - create (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) + ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) - (** - Stores or replaces a new key/value pair in the map. - @param k The key AST - @param v The value AST - *) let insert ( x : ast_map ) ( key : ast ) ( value : ast) = Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) - (** - Erases the key from the map. - @param k An AST - *) let erase ( x : ast_map ) ( key : ast ) = Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - (** Removes all keys from the map. *) let reset ( x : ast_map ) = Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) - (** The size of the map *) let get_size ( x : ast_map ) = Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) - (** The keys stored in the map. *) let get_keys ( x : ast_map ) = - ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) - (** Retrieves a string representation of the map.*) let to_string ( x : ast_map ) = Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) end - (** - The AST's hash code. - @return A hash code - *) let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) - - (** - A unique identifier for the AST (unique among all ASTs). - *) let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) - - (** - The kind of the AST. - *) let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) - (** - Indicates whether the AST is an Expr - *) let is_expr ( x : ast ) = match get_ast_kind ( x : ast ) with | APP_AST @@ -790,117 +310,77 @@ struct | VAR_AST -> true | _ -> false - (** - Indicates whether the AST is a bound variable - *) let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST - - (** - Indicates whether the AST is a Quantifier - *) let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST - - - (** - Indicates whether the AST is a Sort - *) let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST - - (** - Indicates whether the AST is a FunctionDeclaration - *) let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST - (** - A string representation of the AST. - *) let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - - (** - A string representation of the AST in s-expression notation. - *) let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - (** - Comparison operator. - @param a An AST - @param b An AST - @return True if and are from the same context - and represent the same sort; false otherwise. - *) + let ( = ) ( a : ast ) ( b : ast ) = (a == b) || if (z3obj_gnc a) != (z3obj_gnc b) then false else Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) - (** - Object Comparison. - @param other Another ast - @return Negative if the object should be sorted before , positive if after else zero. - *) let compare a b = if (get_id a) < (get_id b) then -1 else if (get_id a) > (get_id b) then 1 else 0 - (** Operator < *) let ( < ) (a : ast) (b : ast) = (compare a b) - (** - Translates (copies) the AST to the Context . - @param ctx A context - @return A copy of the AST which is associated with - *) let translate ( x : ast ) ( to_ctx : context ) = if (z3obj_gnc x) == (context_gno to_ctx) then x else ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - (** - 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., - . - - @param nativeObject The native pointer to wrap. - *) - let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = - ast_of_ptr ctx ptr - - (** - 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., - ). - - @param a The AST to unwrap. - *) + let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr let unwrap_ast ( x : ast ) = (z3obj_gno x) end -(** The Sort module implements type information for ASTs *) +open AST + + module Sort = struct - + type sort = Sort of AST.ast + type uninterpreted_sort = UninterpretedSort of sort + + let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> + let q = (z3_native_object_of_ast_ptr ctx no) in + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then + raise (Z3native.Exception "Invalid coercion") + else + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with + | ARRAY_SORT + | BOOL_SORT + | BV_SORT + | DATATYPE_SORT + | INT_SORT + | REAL_SORT + | UNINTERPRETED_SORT + | FINITE_DOMAIN_SORT + | RELATION_SORT -> Sort(q) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + + let ast_of_sort s = match s with Sort(x) -> x + let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x + + let uninterpreted_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + UninterpretedSort(s) + + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) - - (** - Comparison operator. - @param a A sort - @param b A sort - @return True if and are from the same context - and represent the same sort; false otherwise. - *) + let ( = ) : sort -> sort -> bool = fun a b -> (a == b) || if (gnc a) != (gnc b) then @@ -908,30 +388,13 @@ struct else (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) - (** - Returns a unique identifier for the sort. - *) + let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) - - (** - The kind of the sort. - *) let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) - - (** - The name of the sort - *) let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) - - (** - A string representation of the sort. - *) let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted ( ctx : context ) ( s : symbol ) = + + let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; @@ -940,24 +403,76 @@ struct (z3obj_create res) ; UninterpretedSort(Sort(res)) - (** - Create a new uninterpreted sort. - *) let mk_uninterpreted_s ( ctx : context ) ( s : string ) = mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) end +open Sort -(** Function declarations *) -module FuncDecl = -struct - (**/**) - let create_ndr ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort ) = + +module rec FuncDecl : +sig + type func_decl = FuncDecl of AST.ast + val ast_of_func_decl : FuncDecl.func_decl -> AST.ast + val func_decl_of_ptr : context -> Z3native.ptr -> func_decl + val gc : func_decl -> context + val gnc : func_decl -> Z3native.ptr + val gno : func_decl -> Z3native.ptr + module Parameter : + sig + type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + val get_kind : parameter -> Z3enums.parameter_kind + val get_int : parameter -> int + val get_float : parameter -> float + val get_symbol : parameter -> Symbol.symbol + val get_sort : parameter -> Sort.sort + val get_ast : parameter -> AST.ast + val get_func_decl : parameter -> func_decl + val get_rational : parameter -> string + end + val mk_func_decl : context -> Symbol.symbol -> Sort.sort array -> Sort.sort -> func_decl + val mk_func_decl_s : context -> string -> Sort.sort array -> Sort.sort -> func_decl + val mk_fresh_func_decl : context -> string -> Sort.sort array -> Sort.sort -> func_decl + val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl + val mk_const_decl_s : context -> string -> Sort.sort -> func_decl + val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl + val ( = ) : func_decl -> func_decl -> bool + val to_string : func_decl -> string + val get_id : func_decl -> int + val get_arity : func_decl -> int + val get_domain_size : func_decl -> int + val get_domain : func_decl -> Sort.sort array + val get_range : func_decl -> Sort.sort + val get_decl_kind : func_decl -> Z3enums.decl_kind + val get_name : func_decl -> Symbol.symbol + val get_num_parameters : func_decl -> int + val get_parameters : func_decl -> Parameter.parameter list + val apply : func_decl -> Expr.expr array -> Expr.expr +end = struct + type func_decl = FuncDecl of AST.ast + + let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + FuncDecl(z3_native_object_of_ast_ptr ctx no) + + let ast_of_func_decl f = match f with FuncDecl(x) -> x + + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - let f x = (ptr_of_ast (ast_of_sort x)) in + let f x = (AST.ptr_of_ast (ast_of_sort x)) in (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Array.map f domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) @@ -967,20 +482,26 @@ struct m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - let f x = (ptr_of_ast (ast_of_sort x)) in + let f x = (AST.ptr_of_ast (ast_of_sort x)) in (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Array.map f domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) - let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - (**/**) + let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - (** Parameters of Func_Decls *) module Parameter = - struct - (** The kind of the parameter. *) + struct + type parameter = + | P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + let get_kind ( x : parameter ) = (match x with | P_Int(_) -> PARAMETER_INT @@ -991,188 +512,137 @@ struct | P_Fdl(_) -> PARAMETER_FUNC_DECL | P_Rat(_) -> PARAMETER_RATIONAL) - (**The int value of the parameter.*) let get_int ( x : parameter ) = match x with | P_Int(x) -> x | _ -> raise (Z3native.Exception "parameter is not an int") - - (**The double value of the parameter.*) + let get_float ( x : parameter ) = match x with | P_Dbl(x) -> x | _ -> raise (Z3native.Exception "parameter is not a double") - - (**The Symbol value of the parameter.*) + let get_symbol ( x : parameter ) = match x with | P_Sym(x) -> x | _ -> raise (Z3native.Exception "parameter is not a symbol") - (**The Sort value of the parameter.*) let get_sort ( x : parameter ) = match x with | P_Srt(x) -> x | _ -> raise (Z3native.Exception "parameter is not a sort") - (**The AST value of the parameter.*) let get_ast ( x : parameter ) = match x with | P_Ast(x) -> x | _ -> raise (Z3native.Exception "parameter is not an ast") - (**The FunctionDeclaration value of the parameter.*) let get_func_decl ( x : parameter ) = match x with | P_Fdl(x) -> x | _ -> raise (Z3native.Exception "parameter is not a func_decl") - (**The rational string value of the parameter.*) - let get_func_decl ( x : parameter ) = + let get_rational ( x : parameter ) = match x with | P_Rat(x) -> x | _ -> raise (Z3native.Exception "parameter is not a rational string") end - (** - Creates a new function declaration. - *) - let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = create_ndr ctx name domain range - (** - Creates a new function declaration. - *) let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = mk_func_decl ctx (Symbol.mk_string ctx name) domain range - (** - Creates a fresh function declaration with a name prefixed with . - - - *) let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = create_pdr ctx prefix domain range - (** - Creates a new constant function declaration. - *) - let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort ) = + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = create_ndr ctx name [||] range - (** - Creates a new constant function declaration. - *) let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = create_ndr ctx (Symbol.mk_string ctx name) [||] range - (** - Creates a fresh constant function declaration with a name prefixed with . - - - *) let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = create_pdr ctx prefix [||] range - (** - Comparison operator. - @param a A func_decl - @param b A func_decl - @return True if and are from the same context - and represent the same func_decl; false otherwise. - *) let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || if (gnc a) != (gnc b) then false else (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) - (** - A string representations of the function declaration. - *) let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) - (** - Returns a unique identifier for the function declaration. - *) let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) - (** - The arity of the function declaration - *) let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) - (** - The size of the domain of the function declaration - - *) let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) - (** - The domain of the function declaration - *) let get_domain ( x : func_decl ) = let n = (get_domain_size x) in let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in Array.init n f - (** - The range of the function declaration - *) let get_range ( x : func_decl ) = sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) - (** - The kind of the function declaration. - *) let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) - (** - The name of the function declaration - *) let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) - (** - The number of parameters of the function declaration - *) let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) - (** - The parameters of the function declaration - *) let get_parameters ( x : func_decl ) = let n = (get_num_parameters x) in let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> P_Ast (ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> Parameter.P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> Parameter.P_Ast (AST.ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) ) in mk_list f n - (** - Create expression that applies function to arguments. - @param args The arguments - *) - let apply ( x : func_decl ) ( args : expr array ) = expr_of_func_app (gc x) x args + let apply ( x : func_decl ) ( args : Expr.expr array ) = Expr.expr_of_func_app (gc x) x args end -(** - Parameter sets (of Solvers, Tactics, ...) - A Params objects represents a configuration in the form of symbol/value pairs. -*) -module Params = -struct - (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) +and Params : +sig + type params = z3_native_object + module ParamDescrs : + sig + type param_descrs + val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs + val validate : param_descrs -> params -> unit + val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind + val get_names : param_descrs -> Symbol.symbol array + val get_size : param_descrs -> int + val to_string : param_descrs -> string + end + val add_bool : params -> Symbol.symbol -> bool -> unit + val add_int : params -> Symbol.symbol -> int -> unit + val add_double : params -> Symbol.symbol -> float -> unit + val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit + val add_s_bool : params -> string -> bool -> unit + val add_s_int : params -> string -> int -> unit + val add_s_double : params -> string -> float -> unit + val add_s_symbol : params -> string -> Symbol.symbol -> unit + val mk_params : context -> params + val to_string : params -> string +end = struct + type params = z3_native_object + module ParamDescrs = - struct - - let create ( ctx : context ) ( no : Z3native.ptr ) = + struct + type param_descrs = z3_native_object + + let param_descrs_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let res : param_descrs = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.param_descrs_inc_ref ; @@ -1180,79 +650,46 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - - - (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params ) = Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) - (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = + let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) - (** Retrieve all names of parameters. *) let get_names ( x : param_descrs ) = let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** The size of the ParamDescrs. *) - let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) - - (** Retrieves a string representation of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) end - (** - Adds a parameter setting. - *) - let add_bool ( x : params ) ( name : symbol ) ( value : bool ) = + let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - (** - Adds a parameter setting. - *) - let add_int ( x : params ) (name : symbol ) ( value : int ) = + let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - (** - Adds a parameter setting. - *) - let add_double ( x : params ) ( name : symbol ) ( value : float ) = + let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - (** - Adds a parameter setting. - *) - let add_symbol ( x : params ) ( name : symbol ) ( value : symbol ) = + let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) - (** - Adds a parameter setting. - *) let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = add_bool x (Symbol.mk_string (z3obj_gc x) name) value - (** - Adds a parameter setting. - *) let add_s_int ( x : params) ( name : string ) ( value : int ) = add_int x (Symbol.mk_string (z3obj_gc x) name) value - (** - Adds a parameter setting. - *) let add_s_double ( x : params ) ( name : string ) ( value : float ) = add_double x (Symbol.mk_string (z3obj_gc x) name) value - (** - Adds a parameter setting. - *) - let add_s_symbol ( x : params ) ( name : string ) ( value : symbol ) = + + let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = add_symbol x (Symbol.mk_string (z3obj_gc x) name) value - (** - Creates a new parameter set - *) let mk_params ( ctx : context ) = let res : params = { m_ctx = ctx ; m_n_obj = null ; @@ -1262,21 +699,107 @@ struct (z3obj_create res) ; res - (** - A string representation of the parameter set. - *) let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) end (** General expressions (terms) *) -module Expr = -struct +and Expr : +sig + type expr = Expr of AST.ast + val expr_of_ptr : context -> Z3native.ptr -> expr + val c_of_expr : expr -> context + val nc_of_expr : expr -> Z3native.ptr + val ptr_of_expr : expr -> Z3native.ptr + val expr_aton : expr array -> Z3native.ptr array + val ast_of_expr : expr -> AST.ast + val expr_of_ast : AST.ast -> expr + val expr_of_func_app : context -> FuncDecl.func_decl -> expr array -> expr + val simplify : expr -> Params.params option -> expr + val get_simplify_help : context -> string + val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs + val get_func_decl : expr -> FuncDecl.func_decl + val get_bool_value : expr -> Z3enums.lbool + val get_num_args : expr -> int + val get_args : expr -> expr array + val update : expr -> expr array -> expr + val substitute : expr -> expr array -> expr array -> expr + val substitute_one : expr -> expr -> expr -> expr + val substitute_vars : expr -> expr array -> expr + val translate : expr -> context -> expr + val to_string : expr -> string + val is_numeral : expr -> bool + val is_well_sorted : expr -> bool + val get_sort : expr -> Sort.sort + val is_bool : expr -> bool + val is_const : expr -> bool + val is_true : expr -> bool + val is_false : expr -> bool + val is_eq : expr -> bool + val is_distinct : expr -> bool + val is_ite : expr -> bool + val is_and : expr -> bool + val is_or : expr -> bool + val is_iff : expr -> bool + val is_xor : expr -> bool + val is_not : expr -> bool + val is_implies : expr -> bool + val is_label : expr -> bool + val is_oeq : expr -> bool + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + val mk_const_s : context -> string -> Sort.sort -> expr + val mk_const_f : context -> FuncDecl.func_decl -> expr + val mk_fresh_const : context -> string -> Sort.sort -> expr + val mk_app : context -> FuncDecl.func_decl -> expr array -> expr + val mk_numeral_string : context -> string -> Sort.sort -> expr + val mk_numeral_int : context -> int -> Sort.sort -> expr +end = struct + type expr = Expr of AST.ast + + let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) + let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) + let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) + + let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then + Expr(z3_native_object_of_ast_ptr ctx no) + else + let s = Z3native.get_sort (context_gno ctx) no in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) no) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + if (Z3native.is_numeral_ast (context_gno ctx) no) then + if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + raise (Z3native.Exception "Unsupported numeral object") + else + Expr(z3_native_object_of_ast_ptr ctx no) + + let expr_of_ast a = + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Expr(a) + + let ast_of_expr e = match e with Expr(a) -> a + + let expr_aton ( a : expr array ) = + let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in + Array.map f a + + let expr_of_func_app : context -> FuncDecl.func_decl -> expr array -> expr = fun ctx f args -> + match f with FuncDecl.FuncDecl(fa) -> + let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (Array.length args) (expr_aton args) in + expr_of_ptr ctx o + (** Returns a simplified version of the expression. @param p A set of parameters to configure the simplifier *) - let simplify ( x : expr ) ( p : params option ) = match p with + let simplify ( x : expr ) ( p : Params.params option ) = match p with | None -> expr_of_ptr (c_of_expr x) (Z3native.simplify (nc_of_expr x) (ptr_of_expr x)) | Some pp -> expr_of_ptr (c_of_expr x) (Z3native.simplify_ex (nc_of_expr x) (ptr_of_expr x) (z3obj_gno pp)) @@ -1290,12 +813,12 @@ struct Retrieves parameter descriptions for simplifier. *) let get_simplify_parameter_descrs ( ctx : context ) = - Params.ParamDescrs.create ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) + Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. *) - let get_func_decl ( x : expr ) = func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) + let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) (** Indicates whether the expression is the true or false expression @@ -1477,7 +1000,7 @@ struct (** Creates a new Constant of sort and named . *) - let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) @@ -1492,8 +1015,7 @@ struct Creates a constant from the func_decl . @param f An expression of a 0-arity function *) - let mk_const_f ( ctx : context ) ( f : func_decl ) = - expr_of_func_app ctx f [||] + let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [||] (** Creates a fresh constant of sort and a @@ -1505,8 +1027,7 @@ struct (** Create a new function application. *) - let mk_app ( ctx : context ) ( f : func_decl ) ( args : expr array ) = - expr_of_func_app ctx f args + let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = expr_of_func_app ctx f args (** Create a numeral of a given sort. @@ -1528,19 +1049,44 @@ struct expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) end +open FuncDecl +open Expr + (** Boolean expressions *) module Boolean = -struct +struct + type bool_sort = BoolSort of Sort.sort + type bool_expr = BoolExpr of Expr.expr + let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let a = (ast_of_ptr ctx no) in - BoolExpr(Expr(a)) + let a = (AST.ast_of_ptr ctx no) in + BoolExpr(Expr.Expr(a)) + + let bool_expr_of_expr e = + match e with Expr.Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolExpr(e) let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = BoolSort(sort_of_ptr ctx no) - let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (c_of_expr e) - let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (nc_of_expr e) - let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (ptr_of_expr e) + let sort_of_bool_sort s = match s with BoolSort(x) -> x + + let bool_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolSort(s) + + let expr_of_bool_expr e = match e with BoolExpr(x) -> x + + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.c_of_expr e) + let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.nc_of_expr e) + let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.ptr_of_expr e) let mk_sort ( ctx : context ) = BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) @@ -1548,7 +1094,7 @@ struct (** Create a Boolean constant. *) - let mk_const ( ctx : context ) ( name : symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = let s = (match (mk_sort ctx) with BoolSort(q) -> q) in BoolExpr(Expr.mk_const ctx name s) @@ -1638,17 +1184,38 @@ end (** Quantifier expressions *) module Quantifier = struct + type quantifier = Quantifier of expr + + let expr_of_quantifier e = match e with Quantifier(x) -> x + + let quantifier_of_expr e = + match e with Expr.Expr(a) -> + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.QUANTIFIER_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Quantifier(e) + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (c_of_expr e) let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (nc_of_expr e) let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (ptr_of_expr e) - + (** Quantifier patterns 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. *) - module Pattern = struct + module Pattern = + struct + type pattern = Pattern of ast + + let ast_of_pattern e = match e with Pattern(x) -> x + + let pattern_of_ast a = + (* CMW: Unchecked ok? *) + Pattern(a) + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) @@ -1692,7 +1259,7 @@ struct index. *) let get_index ( x : expr ) = - if not (AST.is_var (match x with Expr(a) -> a)) then + if not (AST.is_var (match x with Expr.Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else Z3native.get_index_value (nc_of_expr x) (ptr_of_expr x) @@ -1723,7 +1290,7 @@ struct *) let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in + let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** @@ -1736,7 +1303,7 @@ struct *) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in + let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** @@ -1781,7 +1348,7 @@ struct if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) + Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) (** Create a universal Quantifier. @@ -1802,14 +1369,14 @@ struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) - (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) + (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) else @@ -1817,21 +1384,21 @@ struct (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (Array.length nopatterns) (expr_aton nopatterns) - (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true @@ -1839,7 +1406,7 @@ struct (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (Array.length nopatterns) (expr_aton nopatterns) (ptr_of_expr body))) @@ -1847,14 +1414,14 @@ struct Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) - (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) + (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) else @@ -1862,21 +1429,21 @@ struct (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (Array.length nopatterns) (expr_aton nopatterns) - (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) - + (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false @@ -1884,14 +1451,14 @@ struct (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (Array.length nopatterns) (expr_aton nopatterns) (ptr_of_expr body))) (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -1901,7 +1468,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -1911,14 +1478,35 @@ end (** Functions to manipulate Array expressions *) module Array_ = struct + type array_sort = ArraySort of sort + type array_expr = ArrayExpr of expr - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let array_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let e = (expr_of_ptr ctx no) in ArrayExpr(e) - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let array_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in - ArraySort(s) + ArraySort(s) + + let sort_of_array_sort s = match s with ArraySort(x) -> x + + let array_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArraySort(s) + + let array_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArrayExpr(e) + + let expr_of_array_expr e = match e with ArrayExpr(x) -> x let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) @@ -1932,7 +1520,7 @@ struct Create a new array sort. *) let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = - create_sort ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) + array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) (** Indicates whether the term is an array store. @@ -1979,16 +1567,15 @@ struct ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == ARRAY_SORT) (** The domain of the array sort. *) - let get_domain ( x : array_sort ) = sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) + let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) (** The range of the array sort. *) - let get_range ( x : array_sort ) = sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) - + let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) (** Create an array constant. *) - let mk_const ( ctx : context ) ( name : symbol ) ( domain : sort ) ( range : sort ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) (** @@ -2010,7 +1597,7 @@ struct *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) + array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) (** Array update. @@ -2029,7 +1616,7 @@ struct *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = - expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) + array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) (** Create a constant array. @@ -2040,7 +1627,7 @@ struct *) let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) + array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) (** Maps f on the argument arrays. @@ -2054,7 +1641,7 @@ struct *) let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = let m x = (ptr_of_expr (expr_of_array_expr x)) in - expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m args)) + array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m args)) (** Access the array default value. @@ -2063,16 +1650,20 @@ struct finite maps with a default range value. *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = - expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) + array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) end (** Functions to manipulate Set expressions *) module Set = struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + type set_sort = SetSort of sort + + let set_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in SetSort(s) + let sort_of_set_sort s = match s with SetSort(x) -> x + (** Indicates whether the term is set union *) @@ -2102,7 +1693,7 @@ struct Create a set type. *) let mk_sort ( ctx : context ) ( ty : sort ) = - create_sort ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) + set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) (** Create an empty set. @@ -2169,14 +1760,24 @@ end (** Functions to manipulate Finite Domain expressions *) module FiniteDomain = struct + type finite_domain_sort = FiniteDomainSort of sort + + let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x + + let finite_domain_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + FiniteDomainSort(s) + let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) - + (** Create a new finite domain sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( size : int ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in FiniteDomainSort(s) @@ -2210,15 +1811,24 @@ end (** Functions to manipulate Relation expressions *) module Relation = struct - - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + type relation_sort = RelationSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in RelationSort(s) + let sort_of_relation_sort s = match s with RelationSort(x) -> x + + let relation_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RelationSort(s) + let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) - + (** Indicates whether the term is of a relation sort. @@ -2335,29 +1945,53 @@ struct (** The sorts of the columns of the relation sort. *) let get_column_sorts ( x : relation_sort ) = let n = get_arity x in - let f i = (create_sort (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in + let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in Array.init n f end (** Functions to manipulate Datatype expressions *) module Datatype = -struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = +struct + type datatype_sort = DatatypeSort of sort + type datatype_expr = DatatypeExpr of expr + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in DatatypeSort(s) + let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x + + let datatype_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeSort(s) + + let datatype_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeExpr(e) + + let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x + let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) - + (** Constructors *) module Constructor = struct + type constructor = z3_native_object + let _counts = Hashtbl.create 0 - let create ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -2366,11 +2000,11 @@ struct raise (Z3native.Exception "Number of field names does not match number of sort refs") else let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) - (Symbol.gno recognizer) - n - (let f x = (Symbol.gno x) in (Array.map f field_names)) - (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - sort_refs) in + (Symbol.gno recognizer) + n + (let f x = (Symbol.gno x) in (Array.map f field_names)) + (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + sort_refs) in let no : constructor = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; @@ -2383,7 +2017,7 @@ struct no let get_n ( x : constructor ) = (Hashtbl.find _counts x) - + let rec constructor_decl ( x : constructor ) = let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in func_decl_of_ptr (z3obj_gc x) a @@ -2391,12 +2025,12 @@ struct let rec tester_decl ( x : constructor ) = let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in func_decl_of_ptr (z3obj_gc x) b - + let rec accessor_decls ( x : constructor ) = let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in let f y = func_decl_of_ptr (z3obj_gc x) y in Array.map f c - + (** The number of fields of the constructor. *) let get_num_fields ( x : constructor ) = get_n x @@ -2413,8 +2047,9 @@ struct (** Constructor list objects *) module ConstructorList = struct - - let create ( ctx : context ) ( c : constructor array ) = + type constructor_list = z3_native_object + + let create ( ctx : context ) ( c : Constructor.constructor array ) = let res : constructor_list = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; @@ -2438,7 +2073,7 @@ struct 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. *) - let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = Constructor.create ctx name recognizer field_names sorts sort_refs @@ -2452,22 +2087,22 @@ struct 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. *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array ) = let f x = (z3obj_gno x) in let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in - create_sort ctx x + sort_of_ptr ctx x (** Create a new datatype sort. *) - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array ) = + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = mk_sort ctx (Symbol.mk_string ctx name) constructors (** @@ -2475,17 +2110,17 @@ struct @param names names of datatype sorts @param c list of constructors, one list per sort. *) - let mk_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = + let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = let n = (Array.length names) in - let f e = (ptr_of_ast (ConstructorList.create ctx e)) in + let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in let cla = (Array.map f c) in let f2 x = (Symbol.gno x) in let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Array.map f2 names) cla) in - let g e = (create_sort ctx e) in + let g e = (sort_of_ptr ctx e) in (Array.map g r) (** Create mutually recursive data-types. *) - let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = + let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = mk_sorts ctx ( let f e = (Symbol.mk_string ctx e) in @@ -2522,17 +2157,21 @@ end (** Functions to manipulate Enumeration expressions *) module Enumeration = -struct +struct + type enum_sort = EnumSort of sort + let _constdecls = Hashtbl.create 0 let _testerdecls = Hashtbl.create 0 - - let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = let s = (sort_of_ptr ctx no) in let res = EnumSort(s) in Hashtbl.add _constdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f cdecls)) ; Hashtbl.add _testerdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f tdecls)) ; res + let sort_of_enum_sort s = match s with EnumSort(x) -> x + let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) @@ -2540,10 +2179,10 @@ struct (** Create a new enumeration sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( enum_names : symbol array ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = let f x = Symbol.gno x in let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Array.map f enum_names)) in - create_sort ctx a b c + sort_of_ptr ctx a b c (** Create a new enumeration sort. @@ -2561,14 +2200,16 @@ end (** Functions to manipulate List expressions *) module List_ = struct + type list_sort = ListSort of sort + let _nildecls = Hashtbl.create 0 let _is_nildecls = Hashtbl.create 0 let _consdecls = Hashtbl.create 0 let _is_consdecls = Hashtbl.create 0 let _headdecls = Hashtbl.create 0 let _taildecls = Hashtbl.create 0 - - let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in let res = ListSort(s) in Hashtbl.add _nildecls res (func_decl_of_ptr ctx nildecl) ; @@ -2578,16 +2219,18 @@ struct Hashtbl.add _headdecls res (func_decl_of_ptr ctx headdecl) ; Hashtbl.add _taildecls res (func_decl_of_ptr ctx taildecl) ; res + + let sort_of_list_sort s = match s with ListSort(x) -> x let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) - - + + (** Create a new list sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( elem_sort : sort ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in - create_sort ctx r a b c d e f + sort_of_ptr ctx r a b c d e f (** Create a new list sort. *) let mk_list_s ( ctx : context ) (name : string) elem_sort = @@ -2618,23 +2261,26 @@ end (** Functions to manipulate Tuple expressions *) module Tuple = struct - - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + type tuple_sort = TupleSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in TupleSort(s) + let sort_of_tuple_sort s = match s with TupleSort(x) -> x + let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - + (** Create a new tuple sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( field_names : symbol array ) ( field_sorts : sort array ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : sort array ) = let f x = Symbol.gno x in let f2 x = ptr_of_ast (ast_of_sort x) in let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in (* CMW: leaks a,b? *) - create_sort ctx r + sort_of_ptr ctx r (** The constructor function of the tuple. *) let get_mk_decl ( x : tuple_sort ) = @@ -2651,13 +2297,144 @@ struct end (** Functions to manipulate arithmetic expressions *) -module Arithmetic = -struct - - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - arith_expr_of_expr (expr_of_ptr ctx no) +module rec Arithmetic : +sig + type arith_sort = ArithSort of Sort.sort + type arith_expr = ArithExpr of Expr.expr + + val sort_of_arith_sort : arith_sort -> Sort.sort + val arith_sort_of_sort : Sort.sort -> arith_sort + val expr_of_arith_expr : arith_expr -> Expr.expr + val arith_expr_of_expr : Expr.expr -> arith_expr - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val int_expr_of_ptr : context -> Z3native.ptr -> int_expr + val int_num_of_ptr : context -> Z3native.ptr -> int_num + + val arith_sort_of_int_sort : Integer.int_sort -> arith_sort + val int_sort_of_arith_sort : arith_sort -> int_sort + val arith_expr_of_int_expr : int_expr -> arith_expr + val int_expr_of_int_num : int_num -> int_expr + val int_expr_of_arith_expr : arith_expr -> int_expr + val int_num_of_int_expr : int_expr -> int_num + + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val real_expr_of_ptr : context -> Z3native.ptr -> real_expr + val rat_num_of_ptr : context -> Z3native.ptr -> rat_num + + val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort + val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort + val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr + val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr + val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr + val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num + + val mk_sort : context -> real_sort + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr + end + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : algebraic_num -> arith_expr + val algebraic_num_of_arith_expr : arith_expr -> algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end + + val is_int : Expr.expr -> bool + val is_arithmetic_numeral : Expr.expr -> bool + val is_le : Expr.expr -> bool + val is_ge : Expr.expr -> bool + val is_lt : Expr.expr -> bool + val is_gt : Expr.expr -> bool + val is_add : Expr.expr -> bool + val is_sub : Expr.expr -> bool + val is_uminus : Expr.expr -> bool + val is_mul : Expr.expr -> bool + val is_div : Expr.expr -> bool + val is_idiv : Expr.expr -> bool + val is_remainder : Expr.expr -> bool + val is_modulus : Expr.expr -> bool + val is_inttoreal : Expr.expr -> bool + val is_real_to_int : Expr.expr -> bool + val is_real_is_int : Expr.expr -> bool + val is_real : Expr.expr -> bool + val is_int_numeral : Expr.expr -> bool + val is_rat_num : Expr.expr -> bool + val is_algebraic_number : Expr.expr -> bool + val mk_add : context -> arith_expr array -> arith_expr + val mk_mul : context -> arith_expr array -> arith_expr + val mk_sub : context -> arith_expr array -> arith_expr + val mk_unary_minus : context -> arith_expr -> arith_expr + val mk_div : context -> arith_expr -> arith_expr -> arith_expr + val mk_power : context -> arith_expr -> arith_expr -> arith_expr + val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr +end = struct + type arith_sort = ArithSort of sort + type arith_expr = ArithExpr of expr + + let arith_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithExpr(e) + + let arith_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + arith_expr_of_expr (expr_of_ptr ctx no) + + let sort_of_arith_sort s = match s with ArithSort(x) -> x + let expr_of_arith_expr e = match e with ArithExpr(x) -> x + + let arith_sort_of_sort s = match s with Sort(a) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithSort(s) + + let arith_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = arith_sort_of_sort (sort_of_ptr ctx no) let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) @@ -2667,16 +2444,72 @@ struct let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (nc_of_expr e) let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (ptr_of_expr e) - module Integer = - struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - int_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) - - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr - let create_num ( ctx : context ) ( no : Z3native.ptr ) = - int_num_of_int_expr (create_expr ctx no) + val int_expr_of_ptr : context -> Z3native.ptr -> int_expr + val int_num_of_ptr : context -> Z3native.ptr -> int_num + + val arith_sort_of_int_sort : Integer.int_sort -> arith_sort + val int_sort_of_arith_sort : arith_sort -> int_sort + val arith_expr_of_int_expr : int_expr -> arith_expr + val int_expr_of_int_num : int_num -> int_expr + val int_expr_of_arith_expr : arith_expr -> int_expr + val int_num_of_int_expr : int_expr -> int_num + + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end = struct + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + let int_expr_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntExpr(e) + + let int_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) + + let int_num_of_int_expr e = + match e with IntExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + IntNum(e) + + let int_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_num_of_int_expr (int_expr_of_ptr ctx no) + + let arith_sort_of_int_sort s = match s with IntSort(x) -> x + let arith_expr_of_int_expr e = match e with IntExpr(x) -> x + let int_expr_of_int_num e = match e with IntNum(x) -> x + + let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntSort(s) + + let int_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_sort_of_arith_sort (arith_sort_of_sort (Sort.sort_of_ptr ctx no)) let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) @@ -2687,11 +2520,11 @@ struct let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - + (** Create a new integer sort. *) let mk_sort ( ctx : context ) = - create_sort ctx (Z3native.mk_int_sort (context_gno ctx)) + int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) (** Retrieve the int value. *) let get_int ( x : int_num ) = @@ -2705,7 +2538,7 @@ struct (** Creates an integer constant. *) - let mk_int_const ( ctx : context ) ( name : symbol ) = + let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) (** @@ -2719,21 +2552,21 @@ struct The arguments must have int type. *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 rem t2. The arguments must have int type. *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) (** Create an integer numeral. @param v A string representing the Term value in decimal notation. *) let mk_int_numeral_s ( ctx : context ) ( v : string ) = - create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) (** Create an integer numeral. @@ -2741,7 +2574,7 @@ struct @return A Term with value and sort Integer *) let mk_int_numeral_i ( ctx : context ) ( v : int ) = - create_num ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) (** Coerce an integer to a real. @@ -2754,7 +2587,7 @@ struct The argument must be of integer sort. *) let mk_int2real ( ctx : context ) ( t : int_expr ) = - real_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) + Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) (** Create an bit bit-vector from the integer argument . @@ -2767,19 +2600,76 @@ struct The argument must be of integer sort. *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - bitvec_expr_of_expr (expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) + BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) end - module Real = - struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) - - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - real_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr - let create_num ( ctx : context ) ( no : Z3native.ptr ) = - rat_num_of_real_expr (create_expr ctx no) + val real_expr_of_ptr : context -> Z3native.ptr -> real_expr + val rat_num_of_ptr : context -> Z3native.ptr -> rat_num + + val arith_sort_of_real_sort : real_sort -> arith_sort + val real_sort_of_arith_sort : arith_sort -> real_sort + val arith_expr_of_real_expr : real_expr -> arith_expr + val real_expr_of_rat_num : rat_num -> real_expr + val real_expr_of_arith_expr : arith_expr -> real_expr + val rat_num_of_real_expr : real_expr -> rat_num + + val mk_sort : context -> real_sort + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr + end = struct + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + let arith_sort_of_real_sort s = match s with RealSort(x) -> x + let arith_expr_of_real_expr e = match e with RealExpr(x) -> x + let real_expr_of_rat_num e = match e with RatNum(x) -> x + + let real_expr_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealExpr(e) + + let real_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) + + let rat_num_of_real_expr e = + match e with RealExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + RatNum(e) + + let rat_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + rat_num_of_real_expr (real_expr_of_ptr ctx no) + + let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealSort(s) + + let real_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) @@ -2790,19 +2680,19 @@ struct let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - + (** Create a real sort. *) let mk_sort ( ctx : context ) = - create_sort ctx (Z3native.mk_real_sort (context_gno ctx)) + real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) (** The numerator of a rational numeral. *) let get_numerator ( x : rat_num ) = - Integer.create_num (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) (** The denominator of a rational numeral. *) let get_denominator ( x : rat_num ) = - Integer.create_num (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -2813,7 +2703,7 @@ struct let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) (** Creates a real constant. *) - let mk_real_const ( ctx : context ) ( name : symbol ) = + let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) (** Creates a real constant. *) @@ -2832,7 +2722,7 @@ struct if (den == 0) then raise (Z3native.Exception "Denominator is zero") else - create_num ctx (Z3native.mk_real (context_gno ctx) num den) + rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) (** Create a real numeral. @@ -2840,7 +2730,7 @@ struct @return A Term with value and sort Real *) let mk_numeral_s ( ctx : context ) ( v : string ) = - create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) (** Create a real numeral. @@ -2849,11 +2739,11 @@ struct @return A Term with value and sort Real *) let mk_numeral_i ( ctx : context ) ( v : int ) = - create_num ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) (** Coerce a real to an integer. @@ -2863,18 +2753,39 @@ struct The argument must be of real sort. *) let mk_real2int ( ctx : context ) ( t : real_expr ) = - int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) + Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) end - module AlgebraicNumber = - struct - let create_num ( ctx : context ) ( no : Z3native.ptr ) = - algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + val arith_expr_of_algebraic_num : algebraic_num -> arith_expr + val algebraic_num_of_arith_expr : arith_expr -> algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end = struct + type algebraic_num = AlgebraicNum of arith_expr + + let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x + + let algebraic_num_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + AlgebraicNum(e) + + let algebraic_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - + (** Return a upper bound for a given real algebraic number. @@ -2884,7 +2795,7 @@ struct @return A numeral Expr of sort Real *) let to_upper ( x : algebraic_num ) ( precision : int ) = - Real.create_num (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) (** Return a lower bound for the given real algebraic number. @@ -2894,7 +2805,7 @@ struct @return A numeral Expr of sort Real *) let to_lower ( x : algebraic_num ) precision = - Real.create_num (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -3056,38 +2967,186 @@ struct Create an expression representing t1 < t2 *) let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 <= t2 *) let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 > t2 *) let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 >= t2 *) let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) end (** Functions to manipulate bit-vector expressions *) -module BitVector = -struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = +and BitVector : +sig + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort + val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort + val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr + val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr + val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr + val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num + + val mk_sort : context -> int -> bitvec_sort + val is_bv : Expr.expr -> bool + val is_bv_numeral : Expr.expr -> bool + val is_bv_bit1 : Expr.expr -> bool + val is_bv_bit0 : Expr.expr -> bool + val is_bv_uminus : Expr.expr -> bool + val is_bv_add : Expr.expr -> bool + val is_bv_sub : Expr.expr -> bool + val is_bv_mul : Expr.expr -> bool + val is_bv_sdiv : Expr.expr -> bool + val is_bv_udiv : Expr.expr -> bool + val is_bv_SRem : Expr.expr -> bool + val is_bv_urem : Expr.expr -> bool + val is_bv_smod : Expr.expr -> bool + val is_bv_sdiv0 : Expr.expr -> bool + val is_bv_udiv0 : Expr.expr -> bool + val is_bv_srem0 : Expr.expr -> bool + val is_bv_urem0 : Expr.expr -> bool + val is_bv_smod0 : Expr.expr -> bool + val is_bv_ule : Expr.expr -> bool + val is_bv_sle : Expr.expr -> bool + val is_bv_uge : Expr.expr -> bool + val is_bv_sge : Expr.expr -> bool + val is_bv_ult : Expr.expr -> bool + val is_bv_slt : Expr.expr -> bool + val is_bv_ugt : Expr.expr -> bool + val is_bv_sgt : Expr.expr -> bool + val is_bv_and : Expr.expr -> bool + val is_bv_or : Expr.expr -> bool + val is_bv_not : Expr.expr -> bool + val is_bv_xor : Expr.expr -> bool + val is_bv_nand : Expr.expr -> bool + val is_bv_nor : Expr.expr -> bool + val is_bv_xnor : Expr.expr -> bool + val is_bv_concat : Expr.expr -> bool + val is_bv_signextension : Expr.expr -> bool + val is_bv_zeroextension : Expr.expr -> bool + val is_bv_extract : Expr.expr -> bool + val is_bv_repeat : Expr.expr -> bool + val is_bv_reduceor : Expr.expr -> bool + val is_bv_reduceand : Expr.expr -> bool + val is_bv_comp : Expr.expr -> bool + val is_bv_shiftleft : Expr.expr -> bool + val is_bv_shiftrightlogical : Expr.expr -> bool + val is_bv_shiftrightarithmetic : Expr.expr -> bool + val is_bv_rotateleft : Expr.expr -> bool + val is_bv_rotateright : Expr.expr -> bool + val is_bv_rotateleftextended : Expr.expr -> bool + val is_bv_rotaterightextended : Expr.expr -> bool + val is_int_to_bv : Expr.expr -> bool + val is_bv_to_int : Expr.expr -> bool + val is_bv_carry : Expr.expr -> bool + val is_bv_xor3 : Expr.expr -> bool + val get_size : bitvec_sort -> int + val get_int : bitvec_num -> int + val to_string : bitvec_num -> string + val mk_const : context -> Symbol.symbol -> int -> bitvec_expr + val mk_const_s : context -> string -> int -> bitvec_expr + val mk_not : context -> bitvec_expr -> Expr.expr + val mk_redand : context -> bitvec_expr -> Expr.expr + val mk_redor : context -> bitvec_expr -> Expr.expr + val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_neg : context -> bitvec_expr -> bitvec_expr + val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_numeral : context -> string -> int -> bitvec_num +end = struct + type bitvec_sort = BitVecSort of sort + type bitvec_expr = BitVecExpr of expr + type bitvec_num = BitVecNum of bitvec_expr + + let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x + + let bitvec_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecSort(s) + + let bitvec_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = bitvec_sort_of_sort (sort_of_ptr ctx no) - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let bitvec_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecExpr(e) + + let bitvec_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = bitvec_expr_of_expr (expr_of_ptr ctx no) - let create_num ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_num_of_bitvec_expr (create_expr ctx no) + let bitvec_num_of_bitvec_expr e = + match e with BitVecExpr(Expr(a)) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecNum(e) + + let bitvec_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + bitvec_num_of_bitvec_expr (bitvec_expr_of_expr (expr_of_ptr ctx no)) + + let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x + let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x + let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) @@ -3098,13 +3157,13 @@ struct let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - + (** Create a new bit-vector sort. *) let mk_sort ( ctx : context ) size = - create_sort ctx (Z3native.mk_bv_sort (context_gno ctx) size) + bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) (** Indicates whether the terms is of bit-vector sort. @@ -3391,8 +3450,8 @@ struct (** Creates a bit-vector constant. *) - let mk_const ( ctx : context ) ( name : symbol ) ( size : int ) = - BitVecExpr(Expr.mk_const ctx name (match (mk_sort ctx size) with BitVecSort(s) -> s)) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) (** Creates a bit-vector constant. @@ -3426,70 +3485,70 @@ struct The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) (** Unsigned division. @@ -3501,7 +3560,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) (** Signed division. @@ -3516,7 +3575,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) (** Unsigned remainder. @@ -3526,7 +3585,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) (** Signed remainder. @@ -3538,7 +3597,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed remainder (sign follows divisor). @@ -3547,7 +3606,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) (** Unsigned less-than @@ -3555,7 +3614,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed less-than @@ -3563,7 +3622,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) (** Unsigned less-than or equal to. @@ -3571,7 +3630,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed less-than or equal to. @@ -3579,7 +3638,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) (** Unsigned greater than or equal to. @@ -3587,7 +3646,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed greater than or equal to. @@ -3595,7 +3654,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) (** Unsigned greater-than. @@ -3603,7 +3662,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed greater-than. @@ -3611,7 +3670,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) (** Bit-vector concatenation. @@ -3622,7 +3681,7 @@ struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) (** Bit-vector extraction. @@ -3633,7 +3692,7 @@ struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) (** Bit-vector sign extension. @@ -3643,7 +3702,7 @@ struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) (** Bit-vector zero extension. @@ -3654,7 +3713,7 @@ struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) (** Bit-vector repetition. @@ -3662,7 +3721,7 @@ struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) (** Shift left. @@ -3677,8 +3736,8 @@ struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) - + bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) + (** Logical shift right @@ -3692,7 +3751,7 @@ struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) (** Arithmetic shift right @@ -3708,7 +3767,7 @@ struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) (** Rotate Left. @@ -3717,7 +3776,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) (** Rotate Right. @@ -3726,7 +3785,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) (** Rotate Left. @@ -3735,7 +3794,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) (** Rotate Right. @@ -3745,7 +3804,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) (** Create an integer from the bit-vector argument . @@ -3763,7 +3822,7 @@ struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = - Arithmetic.Integer.create_expr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) + Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3771,7 +3830,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3779,7 +3838,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise subtraction does not overflow. @@ -3787,7 +3846,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise subtraction does not underflow. @@ -3795,7 +3854,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3803,7 +3862,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise negation does not overflow. @@ -3811,7 +3870,7 @@ struct The arguments must be of bit-vector sort. *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3819,7 +3878,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3827,7 +3886,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) (** Create a bit-vector numeral. @@ -3836,7 +3895,7 @@ struct @param size the size of the bit-vector *) let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = - create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx size))) + bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) end (** Functions to manipulate proof expressions *) @@ -4321,7 +4380,8 @@ end tactics and solvers. *) module Goal = struct - + type goal = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : goal = { m_ctx = ctx ; m_n_obj = null ; @@ -4330,7 +4390,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** The precision of the goal. @@ -4359,7 +4419,7 @@ struct (** Adds the constraints to the given goal. *) (* CMW: assert seems to be a keyword. *) - let assert_ ( x : goal ) ( constraints : bool_expr array ) = + let assert_ ( x : goal ) ( constraints : Boolean.bool_expr array ) = let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in ignore (Array.map f constraints) ; () @@ -4381,7 +4441,7 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = (bool_expr_of_expr (expr_of_ptr (z3obj_gc x) + let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in Array.init n f @@ -4401,7 +4461,7 @@ struct create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - let simplify ( x : goal ) ( p : params option ) = + let simplify ( x : goal ) ( p : Params.params option ) = let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in Z3native.tactic_inc_ref (z3obj_gnc x) tn ; let arn = match p with @@ -4441,7 +4501,8 @@ end A Model contains interpretations (assignments) of constants and functions. *) module Model = struct - + type model = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : model = { m_ctx = ctx ; m_n_obj = null ; @@ -4450,7 +4511,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Function interpretations @@ -4459,7 +4520,8 @@ struct *) module FuncInterp = struct - + type func_interp = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_interp = { m_ctx = ctx ; m_n_obj = null ; @@ -4468,7 +4530,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Function interpretations entries @@ -4476,7 +4538,8 @@ struct *) module FuncEntry = struct - + type func_entry = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_entry = { m_ctx = ctx ; m_n_obj = null ; @@ -4485,7 +4548,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Return the (symbolic) value of this entry. @@ -4677,7 +4740,7 @@ struct An array of expressions, where each is an element of the universe of *) let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in Array.init n f @@ -4699,7 +4762,8 @@ end *) module Probe = struct - + type probe = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : probe = { m_ctx = ctx ; m_n_obj = null ; @@ -4708,14 +4772,14 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Execute the probe over the goal. A probe always produce a double value. "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - let apply ( x : probe ) (g : goal) = + let apply ( x : probe ) ( g : Goal.goal ) = Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (** @@ -4820,7 +4884,8 @@ end *) module Tactic = struct - + type tactic = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : tactic = { m_ctx = ctx ; m_n_obj = null ; @@ -4829,7 +4894,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Tactic application results @@ -4837,7 +4902,8 @@ struct tactic to a goal. It contains the subgoals that were produced. *) module ApplyResult = struct - + type apply_result = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : apply_result = { m_ctx = ctx ; m_n_obj = null ; @@ -4846,7 +4912,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** The number of Subgoals. *) let get_num_subgoals ( x : apply_result ) = @@ -4866,7 +4932,7 @@ struct goal g, that the ApplyResult was obtained from. #return A model for g *) - let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = + let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) (** A string representation of the ApplyResult. *) @@ -4878,10 +4944,10 @@ struct (** Retrieves parameter descriptions for Tactics. *) let get_param_descrs ( x : tactic ) = - Params.ParamDescrs.create (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Apply the tactic to the goal. *) - let apply ( x : tactic ) ( g : goal ) ( p : params option ) = + let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = match p with | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) @@ -4949,14 +5015,14 @@ struct If evaluates to false, then the new tactic behaves like the skip tactic. *) (* CMW: when is a keyword *) - let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = + let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) - let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = + let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) (** @@ -4981,7 +5047,7 @@ struct (** Create a tactic that fails if the probe evaluates to false. *) - let fail_if ( ctx : context ) ( p : probe ) = + let fail_if ( ctx : context ) ( p : Probe.probe ) = create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** @@ -4994,14 +5060,14 @@ struct (** Create a tactic that applies using the given set of parameters . *) - let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = + let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) (** Create a tactic that applies using the given set of parameters . Alias for UsingParams*) (* CMW: with is a keyword *) - let with_ ( ctx : context ) ( t : tactic ) ( p : params ) = + let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = using_params ctx t p (** @@ -5029,7 +5095,9 @@ end (** Solvers *) module Solver = struct - + type solver = z3_native_object + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : solver = { m_ctx = ctx ; m_n_obj = null ; @@ -5038,7 +5106,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + let string_of_status ( s : status) = match s with | UNSATISFIABLE -> "unsatisfiable" @@ -5048,7 +5116,8 @@ struct (** Objects that track statistical information about solvers. *) module Statistics = struct - + type statistics = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : statistics = { m_ctx = ctx ; m_n_obj = null ; @@ -5066,7 +5135,13 @@ struct *) module Entry = struct - + type statistics_entry = { + mutable m_key : string; + mutable m_is_int : bool ; + mutable m_is_float : bool ; + mutable m_int : int ; + mutable m_float : float } + let create_si k v = let res : statistics_entry = { m_key = k ; @@ -5086,7 +5161,7 @@ struct m_float = v } in res - + (** The key of the entry. *) let get_key (x : statistics_entry) = x.m_key @@ -5142,11 +5217,9 @@ struct let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** - The value of a particular statistical counter. - *) + (** The value of a particular statistical counter. *) let get ( x : statistics ) ( key : string ) = - let f p c = (if (Entry.get_key c) = key then (Some c) else p) in + let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in Array.fold_left f None (get_entries x) end @@ -5158,14 +5231,14 @@ struct (** Sets the solver parameters. *) - let set_parameters ( x : solver ) ( p : params )= + let set_parameters ( x : solver ) ( p : Params.params )= Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** Retrieves parameter descriptions for solver. *) let get_param_descrs ( x : solver ) = - Params.ParamDescrs.create (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** The current number of backtracking points (scopes). @@ -5196,7 +5269,7 @@ struct (** Assert a constraint (or multiple) into the solver. *) - let assert_ ( x : solver ) ( constraints : bool_expr array ) = + let assert_ ( x : solver ) ( constraints : Boolean.bool_expr array ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) @@ -5213,7 +5286,7 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( cs : bool_expr array ) ( ps : bool_expr array ) = + let assert_and_track ( x : solver ) ( cs : Boolean.bool_expr array ) ( ps : Boolean.bool_expr array ) = if ((Array.length cs) != (Array.length ps)) then raise (Z3native.Exception "Argument size mismatch") else @@ -5232,14 +5305,14 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( c : bool_expr ) ( p : bool_expr ) = + let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) (** The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) @@ -5247,9 +5320,9 @@ struct The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in - let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in Array.init n f (** @@ -5259,12 +5332,12 @@ struct *) - let check ( x : solver ) ( assumptions : bool_expr array) = + let check ( x : solver ) ( assumptions : Boolean.bool_expr array) = let r = if ((Array.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - let f x = (ptr_of_expr (expr_of_bool_expr x)) in + let f x = (ptr_of_expr (Boolean.expr_of_bool_expr x)) in lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Array.map f assumptions)) in match r with @@ -5306,7 +5379,7 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f @@ -5330,7 +5403,7 @@ struct check-sat command, and check-sat commands that take more than a given number of milliseconds to be solved. *) - let mk_solver ( ctx : context ) ( logic : symbol option ) = + let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = match logic with | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) @@ -5354,7 +5427,7 @@ struct The solver supports the commands Push and Pop, but it will always solve each check from scratch. *) - let mk_solver_t ( ctx : context ) ( t : tactic ) = + let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) (** @@ -5366,7 +5439,9 @@ end (** Fixedpoint solving *) module Fixedpoint = -struct +struct + type fixedpoint = z3_native_object + let create ( ctx : context ) = let res : fixedpoint = { m_ctx = ctx ; m_n_obj = null ; @@ -5375,7 +5450,7 @@ struct (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; (z3obj_create res) ; res - + (** A string that describes all available fixedpoint solver parameters. @@ -5386,19 +5461,19 @@ struct (** Sets the fixedpoint solver parameters. *) - let set_params ( x : fixedpoint ) ( p : params )= + let set_params ( x : fixedpoint ) ( p : Params.params )= Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** Retrieves parameter descriptions for Fixedpoint solver. *) let get_param_descrs ( x : fixedpoint ) = - Params.ParamDescrs.create (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Assert a constraints into the fixedpoint solver. *) - let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = + let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr array ) = let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) ; () @@ -5412,7 +5487,7 @@ struct (** Add rule into the fixedpoint solver. *) - let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = match name with | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) @@ -5429,11 +5504,11 @@ struct 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. *) - let query ( x : fixedpoint ) ( query : bool_expr ) = + let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with - | L_TRUE -> SATISFIABLE - | L_FALSE -> UNSATISFIABLE - | _ -> UNKNOWN + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN (** Query the fixedpoint solver. @@ -5444,9 +5519,9 @@ struct let query_r ( x : fixedpoint ) ( relations : func_decl array ) = let f x = ptr_of_ast (ast_of_func_decl x) in match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (Array.map f relations))) with - | L_TRUE -> SATISFIABLE - | L_FALSE -> UNSATISFIABLE - | _ -> UNKNOWN + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN (** Creates a backtracking point. @@ -5467,7 +5542,7 @@ struct (** Update named rule into in the fixedpoint solver. *) - let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = + let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) (** @@ -5518,33 +5593,33 @@ struct (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = let f2 x = (Symbol.gno x) in Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Array.map f2 kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. *) - let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = - let f x = ptr_of_expr (expr_of_bool_expr x) in + let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr array ) = + let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Array.map f queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f (** @@ -5628,9 +5703,9 @@ struct @param formula Formula to be checked for consistency in conjunction with assumptions. @return A string representation of the benchmark. *) - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr array ) ( formula : Boolean.bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (let f x = ptr_of_expr (expr_of_bool_expr x) in (Array.map f assumptions)) + (Array.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.map f assumptions)) (Boolean.gno formula) (** @@ -5642,7 +5717,7 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5662,7 +5737,7 @@ struct Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5688,7 +5763,7 @@ struct *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in Array.init n f @@ -5702,7 +5777,7 @@ struct *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in Array.init n f (** @@ -5737,7 +5812,7 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5745,19 +5820,19 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) - cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str + cs + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) + cd + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)))) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5765,13 +5840,13 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name - cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) - cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name + cs + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) + cd + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)))) end @@ -5818,23 +5893,3 @@ let get_global_param ( id : string ) = *) let global_param_reset_all = Z3native.global_param_reset_all - - - -(* - -(** - 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, error_code errorCode, string errorString); - - internal Z3native.error_handler m_n_err_handler = null; - - internal void NativeErrorHandler(IntPtr ctx, error_code errorCode) - - Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. - -*) From 9d15c958562df323be46cd0465036fde21d1765e Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 20 Feb 2013 19:49:09 +0000 Subject: [PATCH 061/248] ML API: proper use of datatype API for list/enum/constructor. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/Makefile | 2 +- src/api/ml/z3.ml | 47 ++++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile index abcefa4af..96fd0a55d 100644 --- a/src/api/ml/Makefile +++ b/src/api/ml/Makefile @@ -7,4 +7,4 @@ all: doc: *.ml mkdir -p doc - ocamldoc -html -d doc -I ../../../bld_dbg/api/ml -sort *.mli -hide Z3 + ocamldoc -html -d doc -I _build -sort *.mli -hide Z3 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c261fce05..344e542f7 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -2159,15 +2159,10 @@ end module Enumeration = struct type enum_sort = EnumSort of sort - - let _constdecls = Hashtbl.create 0 - let _testerdecls = Hashtbl.create 0 let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = let s = (sort_of_ptr ctx no) in let res = EnumSort(s) in - Hashtbl.add _constdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f cdecls)) ; - Hashtbl.add _testerdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f tdecls)) ; res let sort_of_enum_sort s = match s with EnumSort(x) -> x @@ -2191,33 +2186,27 @@ struct mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) (** The function declarations of the constants in the enumeration. *) - let get_const_decls ( x : enum_sort ) = Hashtbl.find _constdecls x + let get_const_decls ( x : enum_sort ) = + let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in + let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in + Array.init n f (** The test predicates for the constants in the enumeration. *) - let get_tester_decls ( x : enum_sort ) = Hashtbl.find _testerdecls x + let get_tester_decls ( x : enum_sort ) = + let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in + let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in + Array.init n f + end (** Functions to manipulate List expressions *) module List_ = struct type list_sort = ListSort of sort - - let _nildecls = Hashtbl.create 0 - let _is_nildecls = Hashtbl.create 0 - let _consdecls = Hashtbl.create 0 - let _is_consdecls = Hashtbl.create 0 - let _headdecls = Hashtbl.create 0 - let _taildecls = Hashtbl.create 0 let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in let res = ListSort(s) in - Hashtbl.add _nildecls res (func_decl_of_ptr ctx nildecl) ; - Hashtbl.add _is_nildecls res (func_decl_of_ptr ctx is_nildecl) ; - Hashtbl.add _consdecls res (func_decl_of_ptr ctx consdecl) ; - Hashtbl.add _is_consdecls res (func_decl_of_ptr ctx is_consdecl) ; - Hashtbl.add _headdecls res (func_decl_of_ptr ctx headdecl) ; - Hashtbl.add _taildecls res (func_decl_of_ptr ctx taildecl) ; res let sort_of_list_sort s = match s with ListSort(x) -> x @@ -2237,22 +2226,28 @@ struct mk_sort ctx (Symbol.mk_string ctx name) elem_sort (** The declaration of the nil function of this list sort. *) - let get_nil_decl ( x : list_sort ) = (Hashtbl.find _nildecls x) + let get_nil_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl ( x : list_sort ) = (Hashtbl.find _is_nildecls x) + let get_is_nil_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) (** The declaration of the cons function of this list sort. *) - let get_cons_decl ( x : list_sort ) = (Hashtbl.find _consdecls x) + let get_cons_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl ( x : list_sort ) = (Hashtbl.find _is_consdecls x) + let get_is_cons_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) (** The declaration of the head function of this list sort. *) - let get_head_decl ( x : list_sort ) = (Hashtbl.find _headdecls x) + let get_head_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) (** The declaration of the tail function of this list sort. *) - let get_tail_decl ( x : list_sort ) = (Hashtbl.find _taildecls x) + let get_tail_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) (** The empty list. *) let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [||] From 576591086df79e48c7316a23ca2b30eeae69c8ca Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 20 Feb 2013 22:07:18 +0000 Subject: [PATCH 062/248] ML API savepoint Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2595 +--------------------------------------------- 1 file changed, 50 insertions(+), 2545 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 344e542f7..b1e40fcac 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -338,7 +338,7 @@ struct else ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr + let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr let unwrap_ast ( x : ast ) = (z3obj_gno x) end @@ -744,6 +744,7 @@ sig val is_not : expr -> bool val is_implies : expr -> bool val is_label : expr -> bool + val is_label_lit : expr -> bool val is_oeq : expr -> bool val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val mk_const_s : context -> string -> Sort.sort -> expr @@ -794,257 +795,97 @@ end = struct let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (Array.length args) (expr_aton args) in expr_of_ptr ctx o - (** - Returns a simplified version of the expression. - @param p A set of parameters to configure the simplifier - - *) let simplify ( x : expr ) ( p : Params.params option ) = match p with | None -> expr_of_ptr (c_of_expr x) (Z3native.simplify (nc_of_expr x) (ptr_of_expr x)) | Some pp -> expr_of_ptr (c_of_expr x) (Z3native.simplify_ex (nc_of_expr x) (ptr_of_expr x) (z3obj_gno pp)) - (** - a string describing all available parameters to Expr.Simplify. - *) let get_simplify_help ( ctx : context ) = Z3native.simplify_get_help (context_gno ctx) - (** - Retrieves parameter descriptions for simplifier. - *) let get_simplify_parameter_descrs ( ctx : context ) = Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - - (** - The function declaration of the function that is applied in this expression. - *) let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) - (** - Indicates whether the expression is the true or false expression - or something else (L_UNDEF). - *) let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (nc_of_expr x) (ptr_of_expr x)) - (** - The number of arguments of the expression. - *) let get_num_args ( x : expr ) = Z3native.get_app_num_args (nc_of_expr x) (ptr_of_expr x) - (** - The arguments of the expression. - *) let get_args ( x : expr ) = let n = (get_num_args x) in let f i = expr_of_ptr (c_of_expr x) (Z3native.get_app_arg (nc_of_expr x) (ptr_of_expr x) i) in Array.init n f - (** - Update the arguments of the expression using the arguments - The number of new arguments should coincide with the current number of arguments. - *) let update ( x : expr ) args = if (Array.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (Array.length args) (expr_aton 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]. - *) let substitute ( x : expr ) from to_ = if (Array.length from) <> (Array.length to_) then raise (Z3native.Exception "Argument sizes do not match") else expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (Array.length from) (expr_aton from) (expr_aton to_)) - (** - Substitute every occurrence of from in the expression with to. - - *) let substitute_one ( x : expr ) from to_ = substitute ( x : expr ) [| from |] [| 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]. - *) let substitute_vars ( x : expr ) to_ = expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (Array.length to_) (expr_aton to_)) - (** - Translates (copies) the term to the Context . - @param ctx A context - @return A copy of the term which is associated with - *) let translate ( x : expr ) to_ctx = if (c_of_expr x) == to_ctx then x else expr_of_ptr to_ctx (Z3native.translate (nc_of_expr x) (ptr_of_expr x) (context_gno to_ctx)) - (** - Returns a string representation of the expression. - *) let to_string ( x : expr ) = Z3native.ast_to_string (nc_of_expr x) (ptr_of_expr x) - (** - Indicates whether the term is a numeral - *) let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (nc_of_expr x) (ptr_of_expr x)) - (** - Indicates whether the term is well-sorted. - @return True if the term is well-sorted, false otherwise. - *) let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (nc_of_expr x) (ptr_of_expr x) - (** - The Sort of the term. - *) let get_sort ( x : expr ) = sort_of_ptr (c_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)) - (** - Indicates whether the term has Boolean sort. - *) let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && (Z3native.is_eq_sort (nc_of_expr x) (Z3native.mk_bool_sort (nc_of_expr x)) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x))) - (** - Indicates whether the term represents a constant. - *) let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && (get_num_args x) == 0 && (FuncDecl.get_domain_size (get_func_decl x)) == 0 - - (** - Indicates whether the term is the constant true. - *) + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - - (** - Indicates whether the term is the constant false. - *) let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - - (** - Indicates whether the term is an equality predicate. - *) let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - - (** - Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). - *) let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - - (** - Indicates whether the term is a ternary if-then-else term - *) let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - - (** - Indicates whether the term is an n-ary conjunction - *) let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - - (** - Indicates whether the term is an n-ary disjunction - *) let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - - (** - Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) - *) let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - - (** - Indicates whether the term is an exclusive or - *) let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - - (** - Indicates whether the term is a negation - *) let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - - (** - Indicates whether the term is an implication - *) let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - - (** - 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. - *) let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - *) + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) - (** - Creates a new Constant of sort and named . - *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) - - (** - Creates a new Constant of sort and named . - *) let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) range - - (** - Creates a constant from the func_decl . - @param f An expression of a 0-arity function - *) let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [||] - (** - Creates a fresh constant of sort and a - name prefixed with . - *) let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) - (** - Create a new function application. - *) let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = expr_of_func_app ctx f args - (** - Create a numeral of a given sort. - @param v 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]*. - @param ty 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 - *) let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) - (** - Create a numeral 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. - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - *) let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) end @@ -1052,7 +893,6 @@ end open FuncDecl open Expr -(** Boolean expressions *) module Boolean = struct type bool_sort = BoolSort of Sort.sort @@ -1091,97 +931,53 @@ struct let mk_sort ( ctx : context ) = BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) - (** - Create a Boolean constant. - *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) = let s = (match (mk_sort ctx) with BoolSort(q) -> q) in BoolExpr(Expr.mk_const ctx name s) - (** - Create a Boolean constant. - *) let mk_const_s ( ctx : context ) ( name : string ) = mk_const ctx (Symbol.mk_string ctx name) - (** - The true Term. - *) let mk_true ( ctx : context ) = bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) - (** - The false Term. - *) let mk_false ( ctx : context ) = bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) - (** - Creates a Boolean value. - *) let mk_val ( ctx : context ) ( value : bool ) = if value then mk_true ctx else mk_false ctx - (** - Creates the equality = . - *) let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (ptr_of_expr x) (ptr_of_expr y)) - (** - Creates a distinct term. - *) let mk_distinct ( ctx : context ) ( args : expr array ) = bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (expr_aton args)) - (** - Mk an expression representing not(a). - *) let mk_not ( ctx : context ) ( a : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) - (** - Create an expression representing an if-then-else: ite(t1, t2, t3). - @param t1 An expression with Boolean sort - @param t2 An expression - @param t3 An expression with the same sort as - *) let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) - (** - Create an expression representing t1 iff t2. - *) let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) - (** - Create an expression representing t1 -> t2. - *) let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) - (** - Create an expression representing t1 xor t2. - *) + let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - (** - Create an expression representing the AND of args - *) let mk_and ( ctx : context ) ( args : bool_expr array ) = let f x = (ptr_of_expr (expr_of_bool_expr x)) in bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (Array.map f args)) - (** - Create an expression representing the OR of args - *) let mk_or ( ctx : context ) ( args : bool_expr array ) = let f x = (ptr_of_expr (expr_of_bool_expr x)) in bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (Array.map f args)) end -(** Quantifier expressions *) + module Quantifier = struct type quantifier = Quantifier of expr @@ -1200,12 +996,6 @@ struct let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (nc_of_expr e) let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (ptr_of_expr e) - (** Quantifier patterns - - 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. - *) module Pattern = struct type pattern = Pattern of ast @@ -1220,155 +1010,68 @@ struct let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - (** - The number of terms in the pattern. - *) let get_num_terms ( x : pattern ) = Z3native.get_pattern_num_terms (gnc x) (gno x) - (** - The terms in the pattern. - *) let get_terms ( x : pattern ) = let n = (get_num_terms x) in let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in Array.init n f - (** - A string representation of the pattern. - *) let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) end - (** - 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 : expr ) appears, the higher is its - index. - *) let get_index ( x : expr ) = if not (AST.is_var (match x with Expr.Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else Z3native.get_index_value (nc_of_expr x) (ptr_of_expr x) - (** - Indicates whether the quantifier is universal. - *) let is_universal ( x : quantifier ) = Z3native.is_quantifier_forall (gnc x) (gno x) - (** - Indicates whether the quantifier is existential. - *) let is_existential ( x : quantifier ) = not (is_universal x) - (** - The weight of the quantifier. - *) let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) - (** - The number of patterns. - *) let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) - (** - The patterns. - *) let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in Array.init n f - (** - The number of no-patterns. - *) let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) - (** - The no-patterns. - *) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in Array.init n f - (** - The number of bound variables. - *) let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) - (** - The symbols for the bound variables. - *) let get_bound_variable_names ( x : quantifier ) = let n = (get_num_bound x) in let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in Array.init n f - (** - The sorts of the bound variables. - *) let get_bound_variable_sorts ( x : quantifier ) = let n = (get_num_bound x) in let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in Array.init n f - (** - The body of the quantifier. - *) let get_body ( x : quantifier ) = Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) - (** - Creates a new bound variable. - @param index The de-Bruijn index of the variable - @param ty The sort of the variable - *) let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) - (** - Create a quantifier pattern. - *) let mk_pattern ( ctx : context ) ( terms : expr array ) = if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) - (** - 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. - - @param sorts the sorts of the bound variables. - @param names names of the bound variables - @param body the body of the quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param patterns array containing the patterns created using MkPattern. - @param noPatterns array containing the anti-patterns created using MkPattern. - @param quantifierID optional symbol to track quantifier. - @param skolemID optional symbol to track skolem constants. - *) let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") @@ -1390,9 +1093,6 @@ struct (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) - (** - Create a universal Quantifier. - *) let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true @@ -1410,10 +1110,6 @@ struct (Array.length nopatterns) (expr_aton nopatterns) (ptr_of_expr body))) - (** - Create an existential Quantifier. - - *) let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") @@ -1435,9 +1131,6 @@ struct (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) - (** - Create an existential Quantifier. - *) let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false @@ -1455,19 +1148,12 @@ struct (Array.length nopatterns) (expr_aton nopatterns) (ptr_of_expr body))) - (** - Create a Quantifier. - *) let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - - (** - Create a Quantifier. - *) let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id @@ -1475,7 +1161,7 @@ struct mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id end -(** Functions to manipulate Array expressions *) + module Array_ = struct type array_sort = ArraySort of sort @@ -1516,144 +1202,46 @@ struct let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) - (** - Create a new array sort. - *) let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) - (** - 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. - *) let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) - - (** - Indicates whether the term is an array select. - *) let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) - - (** - Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. - *) let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) - - (** - Indicates whether the term is of an array sort. - *) let is_array ( x : expr ) = (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == ARRAY_SORT) - (** The domain of the array sort. *) let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) - - (** The range of the array sort. *) let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) - (** - Create an array constant. - *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) - (** - Create an array constant. - *) let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) 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. - - - *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) - - (** - 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). - - - *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = + array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) + + let mk_store ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) - (** - Create a constant array. - - The resulting term is an array, such that a selecton an arbitrary index - produces the value v. - - - *) let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) - (** - 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]. - - - - *) let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = let m x = (ptr_of_expr (expr_of_array_expr x)) in array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m 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. - *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) end -(** Functions to manipulate Set expressions *) + module Set = struct type set_sort = SetSort of sort @@ -1664,100 +1252,49 @@ struct let sort_of_set_sort s = match s with SetSort(x) -> x - (** - Indicates whether the term is set union - *) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) - - (** - Indicates whether the term is set intersection - *) - let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) - - (** - Indicates whether the term is set difference - *) - let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) - - (** - Indicates whether the term is set complement - *) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) - - (** - Indicates whether the term is set subset - *) - let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) - - (** - Create a set type. - *) let mk_sort ( ctx : context ) ( ty : sort ) = set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) - (** - Create an empty set. - *) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + + let mk_empty ( ctx : context ) ( domain : sort ) = (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) - (** - Create the full set. - *) let mk_full ( ctx : context ) ( domain : sort ) = expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) - (** - Add an element to the set. - *) let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) - (** - Remove an element from a set. - *) let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) - (** - Take the union of a list of sets. - *) let mk_union ( ctx : context ) ( args : expr array ) = expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (expr_aton args)) - (** - Take the intersection of a list of sets. - *) let mk_intersection ( ctx : context ) ( args : expr array ) = expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (expr_aton args)) - (** - Take the difference between two sets. - *) let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) - (** - Take the complement of a set. - *) let mk_complement ( ctx : context ) ( arg : expr ) = expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (ptr_of_expr arg)) - (** - Check for set membership. - *) let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (ptr_of_expr elem) (ptr_of_expr set)) - (** - Check for subsetness of sets. - *) let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) end -(** Functions to manipulate Finite Domain expressions *) + module FiniteDomain = struct type finite_domain_sort = FiniteDomainSort of sort @@ -1774,41 +1311,28 @@ struct let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) - (** - Create a new finite domain sort. - *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in FiniteDomainSort(s) - (** - Create a new finite domain sort. - *) let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = mk_sort ctx (Symbol.mk_string ctx name) size - (** - Indicates whether the term is of an array sort. - *) let is_finite_domain ( x : expr ) = let nc = (nc_of_expr x) in (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == FINITE_DOMAIN_SORT) - (** - Indicates whether the term is a less than predicate over a finite domain. - *) let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) - (** The size of the finite domain sort. *) let get_size ( x : finite_domain_sort ) = let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in if r then v else raise (Z3native.Exception "Conversion failed.") end -(** Functions to manipulate Relation expressions *) + module Relation = struct type relation_sort = RelationSort of sort @@ -1830,119 +1354,27 @@ struct let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) - (** - Indicates whether the term is of a relation sort. - *) let is_relation ( x : expr ) = let nc = (nc_of_expr x) in ((Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == 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. - *) let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) - - (** - Indicates whether the term is an empty relation - *) let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) - - (** - Indicates whether the term is a test for the emptiness of a relation - *) let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) - - (** - Indicates whether the term is a relational join - *) let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) - - (** - Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. - *) let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) - - (** - Indicates whether the term is the widening of two relations - The function takes two arguments. - *) let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) - - (** - Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. - *) let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. - *) let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) - - (** - Indicates whether the term is the complement of a relation - *) let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) - (** The arity of the relation sort. *) let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) - (** The sorts of the columns of the relation sort. *) let get_column_sorts ( x : relation_sort ) = let n = get_arity x in let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in @@ -1950,7 +1382,7 @@ struct end -(** Functions to manipulate Datatype expressions *) + module Datatype = struct type datatype_sort = DatatypeSort of sort @@ -1983,14 +1415,10 @@ struct let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) - - (** Constructors *) module Constructor = struct type constructor = z3_native_object - let _counts = Hashtbl.create 0 - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then @@ -2009,42 +1437,29 @@ struct m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref} in - Hashtbl.add _counts no n ; (z3obj_sno no ctx ptr) ; (z3obj_create no) ; let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; no + + let get_num_fields ( x : constructor ) = Z3native.get_arity (z3obj_gnc x) (z3obj_gno x) - let get_n ( x : constructor ) = (Hashtbl.find _counts x) - - let rec constructor_decl ( x : constructor ) = - let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + let get_constructor_decl ( x : constructor ) = + let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in func_decl_of_ptr (z3obj_gc x) a - let rec tester_decl ( x : constructor ) = - let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + let get_tester_decl ( x : constructor ) = + let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in func_decl_of_ptr (z3obj_gc x) b - - let rec accessor_decls ( x : constructor ) = - let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + + let get_accessor_decls ( x : constructor ) = + let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in let f y = func_decl_of_ptr (z3obj_gc x) y in Array.map f c - (** The number of fields of the constructor. *) - let get_num_fields ( x : constructor ) = get_n x - - (** The function declaration of the constructor. *) - let get_constructor_decl ( x : constructor ) = constructor_decl x - - (** The function declaration of the tester. *) - let get_tester_decl ( x : constructor ) = tester_decl x - - (** The function declarations of the accessors *) - let get_accessor_decls ( x : constructor ) = accessor_decls x end - (** Constructor list objects *) module ConstructorList = struct type constructor_list = z3_native_object @@ -2062,54 +1477,21 @@ struct res end - (* DATATYPES *) - (** - Create a datatype constructor. - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - *) let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = Constructor.create ctx name recognizer field_names sorts sort_refs - (** - Create a datatype constructor. - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - *) let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs - - (** - Create a new datatype sort. - *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array ) = let f x = (z3obj_gno x) in let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in sort_of_ptr ctx x - (** - Create a new datatype sort. - *) let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = mk_sort ctx (Symbol.mk_string ctx name) constructors - (** - Create mutually recursive datatypes. - @param names names of datatype sorts - @param c list of constructors, one list per sort. - *) let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = let n = (Array.length names) in let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in @@ -2119,7 +1501,6 @@ struct let g e = (sort_of_ptr ctx e) in (Array.map g r) - (** Create mutually recursive data-types. *) let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = mk_sorts ctx ( @@ -2128,22 +1509,18 @@ struct ) c - (** The number of constructors of the datatype sort. *) let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) - (** The range of the array sort. *) let get_constructors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in Array.init n f - (** The recognizers. *) let get_recognizers ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in Array.init n f - (** The constructor accessors. *) let get_accessors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = ( @@ -2155,7 +1532,7 @@ struct Array.init n f end -(** Functions to manipulate Enumeration expressions *) + module Enumeration = struct type enum_sort = EnumSort of sort @@ -2171,27 +1548,19 @@ struct let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) - (** - Create a new enumeration sort. - *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = let f x = Symbol.gno x in let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Array.map f enum_names)) in sort_of_ptr ctx a b c - (** - Create a new enumeration sort. - *) let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string array ) = mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) - (** The function declarations of the constants in the enumeration. *) let get_const_decls ( x : enum_sort ) = let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in Array.init n f - (** The test predicates for the constants in the enumeration. *) let get_tester_decls ( x : enum_sort ) = let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in @@ -2199,7 +1568,7 @@ struct end -(** Functions to manipulate List expressions *) + module List_ = struct type list_sort = ListSort of sort @@ -2214,46 +1583,36 @@ struct let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) - - - (** Create a new list sort. *) + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in sort_of_ptr ctx r a b c d e f - (** Create a new list sort. *) let mk_list_s ( ctx : context ) (name : string) elem_sort = mk_sort ctx (Symbol.mk_string ctx name) elem_sort - (** The declaration of the nil function of this list sort. *) let get_nil_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) - (** The declaration of the isNil function of this list sort. *) let get_is_nil_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) - (** The declaration of the cons function of this list sort. *) let get_cons_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) - (** The declaration of the isCons function of this list sort. *) let get_is_cons_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) - (** The declaration of the head function of this list sort. *) let get_head_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) - (** The declaration of the tail function of this list sort. *) let get_tail_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) - (** The empty list. *) let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [||] end -(** Functions to manipulate Tuple expressions *) + module Tuple = struct type tuple_sort = TupleSort of sort @@ -2268,30 +1627,24 @@ struct let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - - (** Create a new tuple sort. *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : sort array ) = let f x = Symbol.gno x in let f2 x = ptr_of_ast (ast_of_sort x) in - let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in - (* CMW: leaks a,b? *) + let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in sort_of_ptr ctx r - (** The constructor function of the tuple. *) let get_mk_decl ( x : tuple_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) - (** The number of fields in the tuple. *) let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) - (** The field declarations. *) let get_field_decls ( x : tuple_sort ) = let n = get_num_fields x in let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in Array.init n f end -(** Functions to manipulate arithmetic expressions *) + module rec Arithmetic : sig type arith_sort = ArithSort of Sort.sort @@ -2516,84 +1869,37 @@ end = struct let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - - (** Create a new integer sort. *) let mk_sort ( ctx : context ) = int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) - (** Retrieve the int value. *) let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - (** Returns a string representation of the numeral. *) let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - (** - Creates an integer constant. - *) let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) - (** - Creates an integer constant. - *) let mk_int_const_s ( ctx : context ) ( name : string ) = mk_int_const ctx (Symbol.mk_string ctx name) - (** - Create an expression representing t1 mod t2. - The arguments must have int type. - *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) - (** - Create an expression representing t1 rem t2. - The arguments must have int type. - *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) - (** - Create an integer numeral. - @param v A string representing the Term value in decimal notation. - *) let mk_int_numeral_s ( ctx : context ) ( v : string ) = int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - (** - Create an integer numeral. - @param v value of the numeral. - @return A Term with value and sort Integer - *) let mk_int_numeral_i ( ctx : context ) ( v : int ) = int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) - (** - 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. - *) let mk_int2real ( ctx : context ) ( t : int_expr ) = Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) - (** - 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. - *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) end @@ -2677,76 +1983,41 @@ end = struct let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - (** Create a real sort. *) let mk_sort ( ctx : context ) = real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) - (** The numerator of a rational numeral. *) let get_numerator ( x : rat_num ) = Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) - (** The denominator of a rational numeral. *) let get_denominator ( x : rat_num ) = Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) let to_decimal_string ( x : rat_num ) ( precision : int ) = Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision - (** Returns a string representation of the numeral. *) let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - (** Creates a real constant. *) let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) - (** Creates a real constant. *) let mk_real_const_s ( ctx : context ) ( name : string ) = mk_real_const ctx (Symbol.mk_string ctx name) - (** - Create a real from a fraction. - - @param num numerator of rational. - @param den denominator of rational. - @return A Term with value / and sort Real - - *) let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = if (den == 0) then raise (Z3native.Exception "Denominator is zero") else rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) - (** - Create a real numeral. - @param v A string representing the Term value in decimal notation. - @return A Term with value and sort Real - *) let mk_numeral_s ( ctx : context ) ( v : string ) = rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - (** - Create a real numeral. - - @param v value of the numeral. - @return A Term with value and sort Real - *) let mk_numeral_i ( ctx : context ) ( v : int ) = rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) - (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) - (** - 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. - *) let mk_real2int ( ctx : context ) ( t : real_expr ) = Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) end @@ -2782,208 +2053,97 @@ end = struct let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - (** - Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) let to_upper ( x : algebraic_num ) ( precision : int ) = Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) - (** - Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) let to_lower ( x : algebraic_num ) precision = Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) let to_decimal_string ( x : algebraic_num ) ( precision : int ) = Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision - (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) end - (** - Indicates whether the term is of integer sort. - *) let is_int ( x : expr ) = (Z3native.is_numeral_ast (nc_of_expr x) (nc_of_expr x)) && ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == INT_SORT) - (** - Indicates whether the term is an arithmetic numeral. - *) let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - (** - Indicates whether the term is a less-than-or-equal - *) let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - (** - Indicates whether the term is a greater-than-or-equal - *) let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - (** - Indicates whether the term is a less-than - *) let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - (** - Indicates whether the term is a greater-than - *) let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - (** - Indicates whether the term is addition (binary) - *) let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - (** - Indicates whether the term is subtraction (binary) - *) let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - (** - Indicates whether the term is a unary minus - *) let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - (** - Indicates whether the term is multiplication (binary) - *) let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - (** - Indicates whether the term is division (binary) - *) let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - (** - Indicates whether the term is integer division (binary) - *) let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - (** - Indicates whether the term is remainder (binary) - *) let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - (** - Indicates whether the term is modulus (binary) - *) let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - (** - Indicates whether the term is a coercion of integer to real (unary) - *) let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - (** - Indicates whether the term is a coercion of real to integer (unary) - *) let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - (** - Indicates whether the term is a check that tests whether a real is integral (unary) - *) let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) - (** - Indicates whether the term is of sort real. - *) let is_real ( x : expr ) = ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == REAL_SORT) - - (** - Indicates whether the term is an integer numeral. - *) let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) - (** - Indicates whether the term is a real numeral. - *) let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) - (** - Indicates whether the term is an algebraic number - *) let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (nc_of_expr x) (nc_of_expr x) - (** - Create an expression representing t[0] + t[1] + .... - *) let mk_add ( ctx : context ) ( t : arith_expr array ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Array.map f t))) - (** - Create an expression representing t[0] * t[1] * .... - *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Array.map f t))) - (** - Create an expression representing t[0] - t[1] - .... - *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Array.map f t))) - (** - Create an expression representing -t. - *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) - (** - Create an expression representing t1 / t2. - *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 ^ t2. - *) let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 < t2 - *) let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 <= t2 - *) let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 > t2 - *) let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 >= t2 - *) let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) end -(** Functions to manipulate bit-vector expressions *) + and BitVector : sig type bitvec_sort = BitVecSort of Sort.sort @@ -3089,8 +2249,10 @@ sig val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr + val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr @@ -3154,1225 +2316,213 @@ end = struct let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - (** - Create a new bit-vector sort. - *) let mk_sort ( ctx : context ) size = bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) - - (** - Indicates whether the terms is of bit-vector sort. - *) let is_bv ( x : expr ) = ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == BV_SORT) - - (** - Indicates whether the term is a bit-vector numeral - *) let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) - - (** - Indicates whether the term is a one-bit bit-vector with value one - *) let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) - - (** - Indicates whether the term is a one-bit bit-vector with value zero - *) let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) - - (** - Indicates whether the term is a bit-vector unary minus - *) let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) - - (** - Indicates whether the term is a bit-vector addition (binary) - *) let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) - - (** - Indicates whether the term is a bit-vector subtraction (binary) - *) let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) - - (** - Indicates whether the term is a bit-vector multiplication (binary) - *) let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) - - (** - Indicates whether the term is a bit-vector signed division (binary) - *) let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) - - (** - Indicates whether the term is a bit-vector unsigned division (binary) - *) let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) - - (** - Indicates whether the term is a bit-vector signed remainder (binary) - *) let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) - - (** - Indicates whether the term is a bit-vector unsigned remainder (binary) - *) let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) - - (** - Indicates whether the term is a bit-vector signed modulus - *) let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) - - (** - Indicates whether the term is a bit-vector signed division by zero - *) let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) - - (** - Indicates whether the term is a bit-vector unsigned division by zero - *) let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) - - (** - Indicates whether the term is a bit-vector signed remainder by zero - *) let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) - - (** - Indicates whether the term is a bit-vector unsigned remainder by zero - *) let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) - - (** - Indicates whether the term is a bit-vector signed modulus by zero - *) let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) - - (** - Indicates whether the term is an unsigned bit-vector less-than-or-equal - *) let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) - - (** - Indicates whether the term is a signed bit-vector less-than-or-equal - *) let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) - - (** - Indicates whether the term is an unsigned bit-vector greater-than-or-equal - *) let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) - - (** - Indicates whether the term is a signed bit-vector greater-than-or-equal - *) let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) - - (** - Indicates whether the term is an unsigned bit-vector less-than - *) let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) - - (** - Indicates whether the term is a signed bit-vector less-than - *) let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) - - (** - Indicates whether the term is an unsigned bit-vector greater-than - *) let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) - - (** - Indicates whether the term is a signed bit-vector greater-than - *) let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) - - (** - Indicates whether the term is a bit-wise AND - *) let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) - - (** - Indicates whether the term is a bit-wise OR - *) let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) - - (** - Indicates whether the term is a bit-wise NOT - *) let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) - - (** - Indicates whether the term is a bit-wise XOR - *) let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) - - (** - Indicates whether the term is a bit-wise NAND - *) let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) - - (** - Indicates whether the term is a bit-wise NOR - *) let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) - - (** - Indicates whether the term is a bit-wise XNOR - *) let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) - - (** - Indicates whether the term is a bit-vector concatenation (binary) - *) let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) - - (** - Indicates whether the term is a bit-vector sign extension - *) let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) - - (** - Indicates whether the term is a bit-vector zero extension - *) let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) - - (** - Indicates whether the term is a bit-vector extraction - *) let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) - - (** - Indicates whether the term is a bit-vector repetition - *) let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) - - (** - Indicates whether the term is a bit-vector reduce OR - *) let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) - - (** - Indicates whether the term is a bit-vector reduce AND - *) let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) - - (** - Indicates whether the term is a bit-vector comparison - *) let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) - - (** - Indicates whether the term is a bit-vector shift left - *) let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) - - (** - Indicates whether the term is a bit-vector logical shift right - *) let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) - - (** - Indicates whether the term is a bit-vector arithmetic shift left - *) let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) - - (** - Indicates whether the term is a bit-vector rotate left - *) let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) - - (** - Indicates whether the term is a bit-vector rotate right - *) let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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))) - *) let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) - - (** The size of a bit-vector sort. *) let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) - - (** Retrieve the int value. *) let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - - (** Returns a string representation of the numeral. *) let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - - (** - Creates a bit-vector constant. - *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) - - (** - Creates a bit-vector constant. - *) let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = mk_const ctx (Symbol.mk_string ctx name) size - - (** - Bitwise negation. - The argument must have a bit-vector sort. - *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) - - (** - Take conjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. - *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) - - (** - Take disjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. - *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) - - (** - Bitwise conjunction. - The arguments must have a bit-vector sort. - *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise disjunction. - The arguments must have a bit-vector sort. - *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise XOR. - The arguments must have a bit-vector sort. - *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise NAND. - The arguments must have a bit-vector sort. - *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise NOR. - The arguments must have a bit-vector sort. - *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise XNOR. - The arguments must have a bit-vector sort. - *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) - - (** - Standard two's complement unary minus. - The arguments must have a bit-vector sort. - *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) - - (** - Two's complement addition. - The arguments must have the same bit-vector sort. - *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) - - (** - Two's complement subtraction. - The arguments must have the same bit-vector sort. - *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) - - (** - Two's complement multiplication. - The arguments must have the same bit-vector sort. - *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) - - (** - Unsigned less-than - - The arguments must have the same bit-vector sort. - *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) - - (** - Two's complement signed less-than - - The arguments must have the same bit-vector sort. - *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) - - (** - Unsigned less-than or equal to. - - The arguments must have the same bit-vector sort. - *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) - - (** - Two's complement signed less-than or equal to. - - The arguments must have the same bit-vector sort. - *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) - - (** - Unsigned greater than or equal to. - - The arguments must have the same bit-vector sort. - *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) - - (** - Two's complement signed greater than or equal to. - - The arguments must have the same bit-vector sort. - *) let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) - - (** - Unsigned greater-than. - - The arguments must have the same bit-vector sort. - *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) - - (** - Two's complement signed greater-than. - - The arguments must have the same bit-vector sort. - *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) - - (** - 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). - *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) - - (** - 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. - *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) - - (** - 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. - *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) - - (** - Bit-vector repetition. - - The argument must have a bit-vector sort. - *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) - - (** - 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. - *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) - - - (** - 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. - *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) - - (** - Rotate Left. - - Rotate bits of \c t to the left \c i times. - The argument must have a bit-vector sort. - *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) - - (** - Rotate Right. - - Rotate bits of \c t to the right \c i times. - The argument must have a bit-vector sort. - *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) - - (** - Rotate Left. - - Rotate bits of to the left times. - The arguments must have the same bit-vector sort. - *) - let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + let mk_ext_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) - - (** - Rotate Right. - - - Rotate bits of to the right times. - The arguments must have the same bit-vector sort. - *) - let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + let mk_ext_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) - - (** - Create a predicate that checks that the bit-wise addition does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - - (** - Create a predicate that checks that the bit-wise addition does not underflow. - - The arguments must be of bit-vector sort. - *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) - - (** - Create a predicate that checks that the bit-wise subtraction does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) - - (** - Create a predicate that checks that the bit-wise subtraction does not underflow. - - The arguments must be of bit-vector sort. - *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) - - (** - Create a predicate that checks that the bit-wise signed division does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) - - (** - Create a predicate that checks that the bit-wise negation does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) - - (** - Create a predicate that checks that the bit-wise multiplication does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - - (** - Create a predicate that checks that the bit-wise multiplication does not underflow. - - The arguments must be of bit-vector sort. - *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) - - (** - Create a bit-vector numeral. - - @param v A string representing the value in decimal notation. - @param size the size of the bit-vector - *) let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) end -(** Functions to manipulate proof expressions *) + module Proof = struct - (** - Indicates whether the term is a Proof for the expression 'true'. - *) let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) - - (** - Indicates whether the term is a proof for a fact asserted by the user. - *) let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) - - (** - Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. - *) let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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). - *) let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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'. - *) let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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)) - *) let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 - *) let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) - *) let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 - *) let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 - *) - let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) - let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. - - This proof object has no antecedents. - - Several variables can be eliminated simultaneously. - *) - let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) - - (** - Indicates whether the term is a proof for quantifier instantiation - - A proof of (or (not (forall (x) (P x))) (P a)) - *) let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) - - (** - Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. - *) let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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') - *) let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) - - (** - Indicates whether the term is a proof by iff-true - - T1: p - [iff-true T1]: (iff p true) - *) let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) - - (** - Indicates whether the term is a proof by iff-false - - T1: (not p) - [iff-false T1]: (iff p false) - *) let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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). - *) let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) - - (** - Indicates whether the term is a proof iff-oeq - - T1: (iff p q) - [iff~ T1]: (~ p q) - *) let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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'. - *) let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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'))) - *) let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) - - (** - Indicates whether the term is a proof for a Skolemization step - - Proof for: - - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) - - This proof object has no antecedents. - *) let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 - *) let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end -(** Goals - - A goal (aka problem). A goal is essentially a - of formulas, that can be solved and/or transformed using - tactics and solvers. *) module Goal = struct type goal = z3_native_object @@ -4386,76 +2536,52 @@ struct (z3obj_create res) ; res - - (** 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. - *) let get_precision ( x : goal ) = goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) - (** Indicates whether the goal is precise. *) let is_precise ( x : goal ) = (get_precision x) == GOAL_PRECISE - (** Indicates whether the goal is an under-approximation. *) let is_underapproximation ( x : goal ) = (get_precision x) == GOAL_UNDER - (** Indicates whether the goal is an over-approximation. *) let is_overapproximation ( x : goal ) = (get_precision x) == GOAL_OVER - (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) let is_garbage ( x : goal ) = (get_precision x) == GOAL_UNDER_OVER - (** Adds the constraints to the given goal. *) - (* CMW: assert seems to be a keyword. *) let assert_ ( x : goal ) ( constraints : Boolean.bool_expr array ) = let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in ignore (Array.map f constraints) ; () - (** Indicates whether the goal contains `false'. *) let is_inconsistent ( x : goal ) = Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) - (** The depth of the goal. - This tracks how many transformations were applied to it. *) let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) - (** Erases all formulas from the given goal. *) let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) - (** The number of formulas in the goal. *) let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) - (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in Array.init n f - (** The number of formulas, subformulas and terms in the goal. *) let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) - (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) let is_decided_sat ( x : goal ) = Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) - (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) let is_decided_unsat ( x : goal ) = Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) - (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) let simplify ( x : goal ) ( p : Params.params option ) = let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in Z3native.tactic_inc_ref (z3obj_gnc x) tn ; @@ -4473,27 +2599,13 @@ struct Z3native.tactic_dec_ref (z3obj_gnc x) tn ; create (z3obj_gc x) res - - (** - Creates a new Goal. - - Note that the Context must have been created with proof generation support if - is set to true here. - @param models Indicates whether model generation should be enabled. - @param unsat_cores Indicates whether unsat core generation should be enabled. - @param proofs Indicates whether proof generation should be enabled. - *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) - (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) end -(** Models - - A Model contains interpretations (assignments) of constants and functions. *) module Model = struct type model = z3_native_object @@ -4507,12 +2619,6 @@ struct (z3obj_create res) ; res - - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. - *) module FuncInterp = struct type func_interp = z3_native_object @@ -4526,11 +2632,6 @@ struct (z3obj_create res) ; res - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. - *) module FuncEntry = struct type func_entry = z3_native_object @@ -4544,61 +2645,33 @@ struct (z3obj_create res) ; res - - (** - Return the (symbolic) value of this entry. - *) let get_value ( x : func_entry ) = expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) - (** - The number of arguments of the entry. - *) let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) - (** - The arguments of the function entry. - *) let get_args ( x : func_entry ) = let n = (get_num_args x) in let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f - (** - A string representation of the function entry. - *) let to_string ( x : func_entry ) = let a = (get_args x) in let f c p = (p ^ (Expr.to_string c) ^ ", ") in "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") end - (** - The number of entries in the function interpretation. - *) let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) - (** - The entries in the function interpretation - *) let get_entries ( x : func_interp ) = let n = (get_num_entries x) in let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f - (** - The (symbolic) `else' value of the function interpretation. - *) let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) - (** - The arity of the function interpretation - *) let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) - (** - A string representation of the function interpretation. - *) let to_string ( x : func_interp ) = let f c p = ( let n = (FuncEntry.get_num_args c) in @@ -4613,9 +2686,6 @@ struct Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") end - (** Retrieves the interpretation (the assignment) of in the model. - A function declaration of zero arity - An expression if the function has an interpretation in the model, null otherwise. *) let get_const_interp ( x : model ) ( f : func_decl ) = if (FuncDecl.get_arity f) != 0 || (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then @@ -4627,16 +2697,9 @@ struct else Some (expr_of_ptr (z3obj_gc x) np) - (** Retrieves the interpretation (the assignment) of in the model. - A Constant - An expression if the constant has an interpretation in the model, null otherwise. - *) let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - (** Retrieves the interpretation (the assignment) of a non-constant in the model. - A function declaration of non-zero arity - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) let rec get_func_interp ( x : model ) ( f : func_decl ) = let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in if (FuncDecl.get_arity f) == 0 then @@ -4659,23 +2722,18 @@ struct (** The number of constants that have an interpretation in the model. *) let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) - (** The function declarations of the constants in the model. *) let get_const_decls ( x : model ) = let n = (get_num_consts x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - - (** The number of function interpretations in the model. *) let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) - (** The function declarations of the function interpretations in the model. *) let get_func_decls ( x : model ) = let n = (get_num_consts x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** All symbols that have an interpretation in the model. *) let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in @@ -4683,24 +2741,8 @@ struct let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.append (Array.init n_funcs f) (Array.init n_consts g) - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) exception ModelEvaluationFailedException of string - (** - 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. - - The evaluation of in the model. - *) let eval ( x : model ) ( t : expr ) ( completion : bool ) = let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (ptr_of_expr t) completion) in if not r then @@ -4708,53 +2750,26 @@ struct else expr_of_ptr (z3obj_gc x) v - (** Alias for eval. *) let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = eval x t completion - (** The number of uninterpreted sorts that the model has an interpretation for. *) let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) - (** 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. - - - *) let get_sorts ( x : model ) = let n = (get_num_sorts x) in let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f - - (** The finite set of distinct values that represent the interpretation for sort . - - An uninterpreted sort - An array of expressions, where each is an element of the universe of - *) let sort_universe ( x : model ) ( s : sort ) = let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in Array.init n f - - (** Conversion of models to strings. - A string representation of the model. - *) + let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) end -(** Probes - - 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. -*) module Probe = struct type probe = z3_native_object @@ -4769,114 +2784,52 @@ struct res - (** - Execute the probe over the goal. - A probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. - *) let apply ( x : probe ) ( g : Goal.goal ) = Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) - (** - The number of supported Probes. - *) let get_num_probes ( ctx : context ) = Z3native.get_num_probes (context_gno ctx) - (** - The names of all supported Probes. - *) let get_probe_names ( ctx : context ) = let n = (get_num_probes ctx) in let f i = (Z3native.get_probe_name (context_gno ctx) i) in Array.init n f - (** - Returns a string containing a description of the probe with the given name. - *) let get_probe_description ( ctx : context ) ( name : string ) = Z3native.probe_get_descr (context_gno ctx) name - (** - Creates a new Probe. - *) let mk_probe ( ctx : context ) ( name : string ) = (create ctx (Z3native.mk_probe (context_gno ctx) name)) - (** - Create a probe that always evaluates to . - *) let const ( ctx : context ) ( v : float ) = (create ctx (Z3native.probe_const (context_gno ctx) v)) - (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by - *) let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by - *) let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by - *) let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by - *) let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by - *) let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". - *) - (* CMW: and is a keyword *) let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". - *) - (* CMW: or is a keyword *) let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". - *) - (* CMW: is not a keyword? *) let not_ ( ctx : context ) ( p : probe ) = (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) end -(** Tactics - - Tactics are the basic building block for creating custom solvers for specific problem domains. - The complete list of tactics may be obtained using Context.get_num_tactics - and Context.get_tactic_names. - It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. -*) module Tactic = struct type tactic = z3_native_object @@ -4890,11 +2843,6 @@ struct (z3obj_create res) ; res - - (** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) module ApplyResult = struct type apply_result = z3_native_object @@ -4908,75 +2856,46 @@ struct (z3obj_create res) ; res - - (** The number of Subgoals. *) let get_num_subgoals ( x : apply_result ) = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) - (** Retrieves the subgoals from the apply_result. *) let get_subgoals ( x : apply_result ) = let n = (get_num_subgoals x) in let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** Retrieves the subgoals from the apply_result. *) let get_subgoal ( x : apply_result ) ( i : int ) = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) - (** 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 - *) let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) - (** A string representation of the ApplyResult. *) let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) end - (** A string containing a description of parameters accepted by the tactic. *) let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) - (** Retrieves parameter descriptions for Tactics. *) let get_param_descrs ( x : tactic ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - (** Apply the tactic to the goal. *) let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = match p with | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) - (** - The number of supported tactics. - *) let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) - (** - The names of all supported tactics. - *) let get_tactic_names ( ctx : context ) = let n = (get_num_tactics ctx ) in let f i = (Z3native.get_tactic_name (context_gno ctx) i) in Array.init n f - - (** - Returns a string containing a description of the tactic with the given name. - *) let get_tactic_description ( ctx : context ) ( name : string ) = Z3native.tactic_get_descr (context_gno ctx) name - (** - Creates a new Tactic. - *) let mk_tactic ( ctx : context ) ( name : string ) = create ctx (Z3native.mk_tactic (context_gno ctx) name) - (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . - *) let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array ) = let f p c = (match p with | None -> (Some (z3obj_gno c)) @@ -4988,106 +2907,50 @@ struct let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) - (** - Create a tactic that first applies to a Goal and - if it fails then returns the result of applied to the Goal. - *) let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - (** - Create a tactic that applies to a goal for milliseconds. - - If does not terminate within milliseconds, then it fails. - *) let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) 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. - *) - (* CMW: when is a keyword *) let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) - (** - Create a tactic that applies to a given goal if the probe - evaluates to true and otherwise. - *) let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) - (** - Create a tactic that keeps applying until the goal is not - modified anymore or the maximum number of iterations is reached. - *) let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) - (** - Create a tactic that just returns the given goal. - *) let skip ( ctx : context ) = create ctx (Z3native.tactic_skip (context_gno ctx)) - (** - Create a tactic always fails. - *) let fail ( ctx : context ) = create ctx (Z3native.tactic_fail (context_gno ctx)) - (** - Create a tactic that fails if the probe evaluates to false. - *) let fail_if ( ctx : context ) ( p : Probe.probe ) = create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) - (** - Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). - *) let fail_if_not_decided ( ctx : context ) = create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) - (** - Create a tactic that applies using the given set of parameters . - *) let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) - (** - Create a tactic that applies using the given set of parameters . - Alias for UsingParams*) - (* CMW: with is a keyword *) let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = using_params ctx t p - (** - Create a tactic that applies the given tactics in parallel. - *) let par_or ( ctx : context ) ( t : tactic array ) = create ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) - (** - Create a tactic that applies to a given goal and then - to every subgoal produced by . The subgoals are processed in parallel. - *) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - (** - Interrupt the execution of a Z3 procedure. - This procedure can be used to interrupt: solvers, simplifiers and tactics. - *) let interrupt ( ctx : context ) = Z3native.interrupt (context_gno ctx) end -(** Solvers *) module Solver = struct type solver = z3_native_object @@ -5102,13 +2965,11 @@ struct (z3obj_create res) ; res - let string_of_status ( s : status) = match s with | UNSATISFIABLE -> "unsatisfiable" | SATISFIABLE -> "satisfiable" | _ -> "unknown" - (** Objects that track statistical information about solvers. *) module Statistics = struct type statistics = z3_native_object @@ -5123,11 +2984,6 @@ struct res - (** - Statistical data is organized into pairs of \[Key, Entry\], where every - Entry is either a floating point or integer value. - - *) module Entry = struct type statistics_entry = { @@ -5158,22 +3014,11 @@ struct res - (** The key of the entry. *) let get_key (x : statistics_entry) = x.m_key - - (** The int-value of the entry. *) - let get_int (x : statistics_entry) = x.m_int - - (** The float-value of the entry. *) + let get_int (x : statistics_entry) = x.m_int let get_float (x : statistics_entry) = x.m_float - - (** True if the entry is uint-valued. *) let is_int (x : statistics_entry) = x.m_is_int - - (** True if the entry is double-valued. *) let is_float (x : statistics_entry) = x.m_is_float - - (** The string representation of the the entry's value. *) let to_string_value (x : statistics_entry) = if (is_int x) then string_of_int (get_int x) @@ -5181,18 +3026,13 @@ struct string_of_float (get_float x) else raise (Z3native.Exception "Unknown statistical entry type") - - (** The string representation of the entry (key and value) *) let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) end - (** A string representation of the statistical data. *) let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) - (** The number of statistical data. *) let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) - (** The data entries. *) let get_entries ( x : statistics ) = let n = (get_size x ) in let f i = ( @@ -5204,129 +3044,56 @@ struct ) in Array.init n f - (** - The statistical counters. - *) let get_keys ( x : statistics ) = let n = (get_size x) in let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** The value of a particular statistical counter. *) let get ( x : statistics ) ( key : string ) = let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in Array.fold_left f None (get_entries x) end - (** - A string that describes all available solver parameters. - *) let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) - (** - Sets the solver parameters. - *) let set_parameters ( x : solver ) ( p : Params.params )= Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - (** - Retrieves parameter descriptions for solver. - *) let get_param_descrs ( x : solver ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - (** - The current number of backtracking points (scopes). - - - *) let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) - (** - Creates a backtracking point. - - *) let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) - (** - Backtracks backtracking points. - Note that an exception is thrown if is not smaller than NumScopes - - *) let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n - (** - Resets the Solver. - This removes all assertions from the solver. - *) let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - (** - Assert a constraint (or multiple) into the solver. - *) let assert_ ( x : solver ) ( constraints : Boolean.bool_expr array ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) - (** - * Assert multiple constraints (cs) into the solver, and track them (in the - * unsat) core - * using the Boolean constants in ps. - * - * This API is an alternative to with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using - * and the Boolean literals - * provided using with assumptions. - *) - let assert_and_track ( x : solver ) ( cs : Boolean.bool_expr array ) ( ps : Boolean.bool_expr array ) = + let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr array ) ( ps : Boolean.bool_expr array ) = if ((Array.length cs) != (Array.length ps)) then raise (Z3native.Exception "Argument size mismatch") else let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) (Boolean.gno (Array.get ps i))) in ignore (Array.iteri f cs) - (** - * Assert a constraint (c) into the solver, and track it (in the unsat) core - * using the Boolean constant p. - * - * This API is an alternative to with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using - * and the Boolean literals - * provided using with assumptions. - *) let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) - (** - The number of assertions in the solver. - *) let get_num_assertions ( x : solver ) = let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) - - (** - The set of asserted formulas. - *) let get_assertions ( x : solver ) = let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in Array.init n f - (** - Checks whether the assertions in the solver are consistent or not. - - - - - *) let check ( x : solver ) ( assumptions : Boolean.bool_expr array) = let r = if ((Array.length assumptions) == 0) then @@ -5340,12 +3107,6 @@ struct | L_FALSE -> UNSATISFIABLE | _ -> UNKNOWN - (** - The model of the last Check. - - The result is None if Check was not invoked before, - if its results was not SATISFIABLE, or if model production is not enabled. - *) let get_model ( x : solver ) = let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in if (Z3native.is_null q) then @@ -5353,12 +3114,6 @@ struct else Some (Model.create (z3obj_gc x) q) - (** - 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. - *) let get_proof ( x : solver ) = let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in if (Z3native.is_null q) then @@ -5366,73 +3121,35 @@ struct else Some (expr_of_ptr (z3obj_gc x) q) - (** - 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. - *) let get_unsat_core ( x : solver ) = let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f - (** - A brief justification of why the last call to Check returned UNKNOWN. - *) let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - - (** - Solver statistics. - *) let get_statistics ( x : solver ) = (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) - (** - 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. - *) let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = match logic with | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) - (** - Creates a new (incremental) solver. - - *) let mk_solver_s ( ctx : context ) ( logic : string ) = mk_solver ctx (Some (Symbol.mk_string ctx logic)) - (** - Creates a new (incremental) solver. - *) let mk_simple_solver ( ctx : context ) = (create ctx (Z3native.mk_simple_solver (context_gno ctx))) - (** - 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. - *) let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) - (** - A string representation of the solver. - *) let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) end -(** Fixedpoint solving *) module Fixedpoint = struct type fixedpoint = z3_native_object @@ -5447,70 +3164,37 @@ struct res - (** - A string that describes all available fixedpoint solver parameters. - *) let get_help ( x : fixedpoint ) = Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) - (** - Sets the fixedpoint solver parameters. - *) let set_params ( x : fixedpoint ) ( p : Params.params )= Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - (** - Retrieves parameter descriptions for Fixedpoint solver. - *) let get_param_descrs ( x : fixedpoint ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - (** - Assert a constraints into the fixedpoint solver. - *) let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr array ) = let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) ; () - (** - Register predicate as recursive relation. - *) let register_relation ( x : fixedpoint ) ( f : func_decl ) = Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) - (** - Add rule into the fixedpoint solver. - *) let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = match name with | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) - (** - Add table fact to the fixedpoint solver. - *) let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (Array.length args) 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. - *) let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.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. - *) let query_r ( x : fixedpoint ) ( relations : func_decl array ) = let f x = ptr_of_ast (ast_of_func_decl x) in match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (Array.map f relations))) with @@ -5518,32 +3202,15 @@ struct | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN - (** - Creates a backtracking point. - - *) let push ( x : fixedpoint ) = Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) - (** - Backtrack one backtracking point. - - Note that an exception is thrown if Pop is called without a corresponding Push - - *) let pop ( x : fixedpoint ) = Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) - (** - Update named rule into in the fixedpoint solver. - *) let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) - (** - Retrieve satisfying instance or instances of solver, - or definitions for the recursive predicates that show unsatisfiability. - *) let get_answer ( x : fixedpoint ) = let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in if (Z3native.is_null q) then @@ -5551,21 +3218,12 @@ struct else Some (expr_of_ptr (z3obj_gc x) q) - (** - Retrieve explanation why fixedpoint engine returned status Unknown. - *) let get_reason_unknown ( x : fixedpoint ) = Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - (** - Retrieve the number of levels explored for a given predicate. - *) let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) - (** - Retrieve the cover of a predicate. - *) let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in if (Z3native.is_null q) then @@ -5573,82 +3231,40 @@ struct else Some (expr_of_ptr (z3obj_gc x) q) - (** - Add property about the predicate. - The property is added at level. - *) let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (ptr_of_expr property) - (** - Retrieve internal string representation of fixedpoint object. - *) let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - (** - Instrument the Datalog engine on which table representation to use for recursive predicate. - *) let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = let f2 x = (Symbol.gno x) in Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Array.map f2 kinds) - (** - Convert benchmark given as set of axioms, rules and queries to a string. - *) let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr array ) = let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Array.map f queries) - (** - Retrieve set of rules added to fixedpoint context. - *) let get_rules ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f - (** - Retrieve set of assertions added to fixedpoint context. - *) let get_assertions ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f - (** - Create a Fixedpoint context. - *) let mk_fixedpoint ( ctx : context ) = create ctx end -(** Global and context options - - Note: This module contains functions that set parameters/options for context - objects as well as functions that set options that are used globally, across - contexts.*) module Options = struct - (** - 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. - - *) let update_param_value ( ctx : context ) ( id : string) ( value : string )= Z3native.update_param_value (context_gno ctx) id value - (** - Get a configuration parameter. - - Returns None if the parameter value does not exist. - - *) let get_param_value ( ctx : context ) ( id : string ) = let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in if not r then @@ -5656,62 +3272,21 @@ struct else Some v - (** - 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 PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - - - - - *) let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) - (** - Enable/disable printing of warning messages to the console. - - Note that this function is static and effects the behaviour of - all contexts globally. - *) let toggle_warning_messages ( enabled: bool ) = Z3native.toggle_warning_messages enabled end -(** Functions for handling SMT and SMT2 expressions and files *) + module SMT = struct - (** - Convert a benchmark into an SMT-LIB formatted string. - - @param name Name of the benchmark. The argument is optional. - @param logic The benchmark logic. - @param status The status string (sat, unsat, or unknown) - @param attributes Other attributes, such as source, difficulty or category. - @param assumptions Auxiliary assumptions. - @param formula Formula to be checked for consistency in conjunction with assumptions. - @return A string representation of the benchmark. - *) let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr array ) ( formula : Boolean.bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes (Array.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.map f assumptions)) (Boolean.gno formula) - (** - 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. - *) let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in @@ -5728,10 +3303,6 @@ struct (let f x = Symbol.gno x in (Array.map f decl_names)) (let f x = FuncDecl.gno x in (Array.map f decls)) - (** - Parse the given file using the SMT-LIB parser. - - *) let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in @@ -5748,65 +3319,34 @@ struct (let f x = Symbol.gno x in (Array.map f decl_names)) (let f x = FuncDecl.gno x in (Array.map f decls)) - (** - The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) - (** - The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in Array.init n f - - (** - The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) - (** - The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in Array.init n f - (** - The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) - (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f - (** - The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) - - (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) + let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in Array.init n f - (** - 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. - *) let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in @@ -5823,10 +3363,6 @@ struct (let f x = Symbol.gno x in (Array.map f decl_names)) (let f x = FuncDecl.gno x in (Array.map f decls)))) - (** - Parse the given file using the SMT-LIB2 parser. - - *) let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in @@ -5845,34 +3381,9 @@ struct end -(* Global functions *) - -(** - * Set a global (or module) parameter, which is shared by all Z3 contexts. - * - * When a Z3 module is initialized it will use the value of these parameters - * when Z3_params objects are not provided. - * The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. - * The character '.' is a delimiter (more later). - * The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. - * Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". - * This function can be used to set parameters for a specific Z3 module. - * This can be done by using .. - * For example: - * (set_global_param "pp.decimal" "true") - * will set the parameter "decimal" in the module "pp" to true. -*) let set_global_param ( id : string ) ( value : string ) = (Z3native.global_param_set id value) -(** - * Get a global (or module) parameter. - * - * Returns None if the parameter does not exist. - * The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. - * This function cannot be invoked simultaneously from different threads without synchronization. - * The result string stored in param_value is stored in a shared location. -*) let get_global_param ( id : string ) = let (r, v) = (Z3native.global_param_get id) in if not r then @@ -5880,11 +3391,5 @@ let get_global_param ( id : string ) = else Some v -(** - * Restore the value of all global (and module) parameters. - * - * This command will not affect already created objects (such as tactics and solvers) - * -*) let global_param_reset_all = Z3native.global_param_reset_all From a0f6d1d3dfcab9f5c8b79a1aaa2fba8d9ee67f42 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 21 Feb 2013 00:29:51 +0000 Subject: [PATCH 063/248] ML API: replaced arrays with lists. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 46 ++-- src/api/ml/z3.ml | 507 +++++++++++++++++++------------------- 2 files changed, 279 insertions(+), 274 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 6dfe11623..31f31d566 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -33,13 +33,13 @@ let model_converter_test ( ctx : context ) = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in let g4 = (mk_goal ctx true false false ) in - (Goal.assert_ g4 [| (mk_gt ctx xr + (Goal.assert_ g4 [ (mk_gt ctx xr (arith_expr_of_real_expr (real_expr_of_rat_num - (Real.mk_numeral_nd ctx 10 1)))) |]) ; - (Goal.assert_ g4 [| (mk_eq ctx + (Real.mk_numeral_nd ctx 10 1)))) ]) ; + (Goal.assert_ g4 [ (mk_eq ctx (expr_of_arith_expr yr) - (expr_of_arith_expr (Arithmetic.mk_add ctx [| xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) |]) ) ) |] ) ; - (Goal.assert_ g4 [| (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) |]) ; + (expr_of_arith_expr (Arithmetic.mk_add ctx [ xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) ]) ) ) ] ) ; + (Goal.assert_ g4 [ (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) ]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in if ((get_num_subgoals ar) == 1 && @@ -50,7 +50,7 @@ let model_converter_test ( ctx : context ) = Printf.printf "Test passed.\n" ); ( - let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") [||]) g4 None) in + let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") []) g4 None) in if ((get_num_subgoals ar) == 1 && ((is_decided_sat (get_subgoal ar 0)) || (is_decided_unsat (get_subgoal ar 0)))) then @@ -59,9 +59,9 @@ let model_converter_test ( ctx : context ) = Printf.printf "Test passed.\n" ; let solver = (mk_solver ctx None) in - let f e = (Solver.assert_ solver [| e |]) in - ignore (Array.map f (get_formulas (get_subgoal ar 0))) ; - let q = (check solver [||]) in + let f e = (Solver.assert_ solver [ e ]) in + ignore (List.map f (get_formulas (get_subgoal ar 0))) ; + let q = (check solver []) in if q != SATISFIABLE then raise (TestFailedException "") else @@ -84,23 +84,23 @@ let basic_tests ( ctx : context ) = let x = (mk_string ctx "x") in let y = (mk_string ctx "y") in let bs = (sort_of_bool_sort (Boolean.mk_sort ctx)) in - let domain = [| bs; bs |] in + let domain = [ bs; bs ] in let f = (FuncDecl.mk_func_decl ctx fname domain bs) in let fapp = (mk_app ctx f - [| (Expr.mk_const ctx x bs); (Expr.mk_const ctx y bs) |]) in - let fargs2 = [| (mk_fresh_const ctx "cp" bs) |] in - let domain2 = [| bs |] in + [ (Expr.mk_const ctx x bs); (Expr.mk_const ctx y bs) ]) in + let fargs2 = [ (mk_fresh_const ctx "cp" bs) ] in + let domain2 = [ bs ] in let fapp2 = (mk_app ctx (mk_fresh_func_decl ctx "fp" domain2 bs) fargs2) in let trivial_eq = (mk_eq ctx fapp fapp) in let nontrivial_eq = (mk_eq ctx fapp fapp2) in let g = (mk_goal ctx true false false) in - (Goal.assert_ g [| trivial_eq |]) ; - (Goal.assert_ g [| nontrivial_eq |]) ; + (Goal.assert_ g [ trivial_eq ]) ; + (Goal.assert_ g [ nontrivial_eq ]) ; Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; ( let solver = (mk_solver ctx None) in - (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; - if (check solver [||]) != SATISFIABLE then + (List.iter (fun a -> (Solver.assert_ solver [ a ])) (get_formulas g)) ; + if (check solver []) != SATISFIABLE then raise (TestFailedException "") else Printf.printf "Test passed.\n" @@ -122,11 +122,11 @@ let basic_tests ( ctx : context ) = else Printf.printf "Test passed.\n" ); - (Goal.assert_ g [| (mk_eq ctx + (Goal.assert_ g [ (mk_eq ctx (mk_numeral_int ctx 1 (sort_of_bitvec_sort (BitVector.mk_sort ctx 32))) (mk_numeral_int ctx 2 - (sort_of_bitvec_sort (BitVector.mk_sort ctx 32)))) |] ) + (sort_of_bitvec_sort (BitVector.mk_sort ctx 32)))) ] ) ; ( let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in @@ -147,7 +147,7 @@ let basic_tests ( ctx : context ) = ); ( let g2 = (mk_goal ctx true true false) in - (Goal.assert_ g2 [| (Boolean.mk_false ctx) |]) ; + (Goal.assert_ g2 [ (Boolean.mk_false ctx) ]) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then @@ -159,10 +159,10 @@ let basic_tests ( ctx : context ) = let g3 = (mk_goal ctx true true false) in let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in - (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) |]) ; - (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) |]) ; + (Goal.assert_ g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) ]) ; + (Goal.assert_ g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) ]) ; let constr = (mk_eq ctx xc yc) in - (Goal.assert_ g3 [| constr |] ) ; + (Goal.assert_ g3 [ constr ] ) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index b1e40fcac..56d319c1a 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -79,10 +79,6 @@ struct let z3obj_nil_ref x y = () - let array_to_native a = - let f e = (z3obj_gno e) in - Array.map f a - let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> let res : z3_native_object = { m_ctx = ctx ; m_n_obj = null ; @@ -127,6 +123,9 @@ let mk_list ( f : int -> 'a ) ( n : int ) = in mk_list' f 0 n [] +let list_of_array ( x : _ array ) = + let f i = (Array.get x i) in + mk_list f (Array.length x) let mk_context ( cfg : ( string * string ) list ) = create_context cfg @@ -180,6 +179,10 @@ struct match x with | S_Int(n) -> (z3obj_gno n) | S_Str(n) -> (z3obj_gno n) + + let symbol_lton ( a : symbol list ) = + let f ( e : symbol ) = (gno e) in + Array.of_list (List.map f a) let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL @@ -197,13 +200,13 @@ struct let mk_string ( ctx : context ) ( s : string ) = S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) - let mk_ints ( ctx : context ) ( names : int array ) = + let mk_ints ( ctx : context ) ( names : int list ) = let f elem = mk_int ( ctx : context ) elem in - (Array.map f names) + (List.map f names) - let mk_strings ( ctx : context ) ( names : string array ) = + let mk_strings ( ctx : context ) ( names : string list ) = let f elem = mk_string ( ctx : context ) elem in - (Array.map f names) + (List.map f names) end @@ -292,7 +295,9 @@ struct Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) let get_keys ( x : ast_map ) = - ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + let av = ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in + let f i = (ASTVector.get av i) in + mk_list f (ASTVector.get_size av) let to_string ( x : ast_map ) = Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) @@ -376,10 +381,13 @@ struct else UninterpretedSort(s) - let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) + + let sort_lton ( a : sort list ) = + let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in + Array.of_list (List.map f a) let ( = ) : sort -> sort -> bool = fun a b -> (a == b) || @@ -438,9 +446,9 @@ sig val get_func_decl : parameter -> func_decl val get_rational : parameter -> string end - val mk_func_decl : context -> Symbol.symbol -> Sort.sort array -> Sort.sort -> func_decl - val mk_func_decl_s : context -> string -> Sort.sort array -> Sort.sort -> func_decl - val mk_fresh_func_decl : context -> string -> Sort.sort array -> Sort.sort -> func_decl + val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl + val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl + val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl val mk_const_decl_s : context -> string -> Sort.sort -> func_decl val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl @@ -449,13 +457,13 @@ sig val get_id : func_decl -> int val get_arity : func_decl -> int val get_domain_size : func_decl -> int - val get_domain : func_decl -> Sort.sort array + val get_domain : func_decl -> Sort.sort list val get_range : func_decl -> Sort.sort val get_decl_kind : func_decl -> Z3enums.decl_kind val get_name : func_decl -> Symbol.symbol val get_num_parameters : func_decl -> int val get_parameters : func_decl -> Parameter.parameter list - val apply : func_decl -> Expr.expr array -> Expr.expr + val apply : func_decl -> Expr.expr list -> Expr.expr end = struct type func_decl = FuncDecl of AST.ast @@ -467,23 +475,21 @@ end = struct let ast_of_func_decl f = match f with FuncDecl(x) -> x - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - let f x = (AST.ptr_of_ast (ast_of_sort x)) in - (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Array.map f domain) (Sort.gno range))) ; + (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (List.length domain) (sort_lton domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) - let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort list ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - let f x = (AST.ptr_of_ast (ast_of_sort x)) in - (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Array.map f domain) (Sort.gno range))) ; + (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (List.length domain) (sort_lton domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) @@ -548,23 +554,23 @@ end = struct | _ -> raise (Z3native.Exception "parameter is not a rational string") end - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = create_ndr ctx name domain range - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort list ) ( range : sort ) = mk_func_decl ctx (Symbol.mk_string ctx name) domain range - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort list ) ( range : sort ) = create_pdr ctx prefix domain range let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - create_ndr ctx name [||] range + create_ndr ctx name [] range let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = - create_ndr ctx (Symbol.mk_string ctx name) [||] range + create_ndr ctx (Symbol.mk_string ctx name) [] range let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = - create_pdr ctx prefix [||] range + create_pdr ctx prefix [] range let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || @@ -584,7 +590,7 @@ end = struct let get_domain ( x : func_decl ) = let n = (get_domain_size x) in let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in - Array.init n f + mk_list f n let get_range ( x : func_decl ) = sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) @@ -608,7 +614,7 @@ end = struct ) in mk_list f n - let apply ( x : func_decl ) ( args : Expr.expr array ) = Expr.expr_of_func_app (gc x) x args + let apply ( x : func_decl ) ( args : Expr.expr list ) = Expr.expr_of_func_app (gc x) x args end @@ -621,7 +627,7 @@ sig val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs val validate : param_descrs -> params -> unit val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind - val get_names : param_descrs -> Symbol.symbol array + val get_names : param_descrs -> Symbol.symbol list val get_size : param_descrs -> int val to_string : param_descrs -> string end @@ -660,7 +666,7 @@ end = struct let get_names ( x : param_descrs ) = let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) @@ -710,21 +716,21 @@ sig val c_of_expr : expr -> context val nc_of_expr : expr -> Z3native.ptr val ptr_of_expr : expr -> Z3native.ptr - val expr_aton : expr array -> Z3native.ptr array + val expr_lton : expr list -> Z3native.ptr array val ast_of_expr : expr -> AST.ast val expr_of_ast : AST.ast -> expr - val expr_of_func_app : context -> FuncDecl.func_decl -> expr array -> expr + val expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr val simplify : expr -> Params.params option -> expr val get_simplify_help : context -> string val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs val get_func_decl : expr -> FuncDecl.func_decl val get_bool_value : expr -> Z3enums.lbool val get_num_args : expr -> int - val get_args : expr -> expr array - val update : expr -> expr array -> expr - val substitute : expr -> expr array -> expr array -> expr + val get_args : expr -> expr list + val update : expr -> expr list -> expr + val substitute : expr -> expr list -> expr list -> expr val substitute_one : expr -> expr -> expr -> expr - val substitute_vars : expr -> expr array -> expr + val substitute_vars : expr -> expr list -> expr val translate : expr -> context -> expr val to_string : expr -> string val is_numeral : expr -> bool @@ -750,7 +756,7 @@ sig val mk_const_s : context -> string -> Sort.sort -> expr val mk_const_f : context -> FuncDecl.func_decl -> expr val mk_fresh_const : context -> string -> Sort.sort -> expr - val mk_app : context -> FuncDecl.func_decl -> expr array -> expr + val mk_app : context -> FuncDecl.func_decl -> expr list -> expr val mk_numeral_string : context -> string -> Sort.sort -> expr val mk_numeral_int : context -> int -> Sort.sort -> expr end = struct @@ -786,13 +792,13 @@ end = struct let ast_of_expr e = match e with Expr(a) -> a - let expr_aton ( a : expr array ) = + let expr_lton ( a : expr list ) = let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in - Array.map f a + Array.of_list (List.map f a) - let expr_of_func_app : context -> FuncDecl.func_decl -> expr array -> expr = fun ctx f args -> + let expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr = fun ctx f args -> match f with FuncDecl.FuncDecl(fa) -> - let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (Array.length args) (expr_aton args) in + let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (List.length args) (expr_lton args) in expr_of_ptr ctx o let simplify ( x : expr ) ( p : Params.params option ) = match p with @@ -812,25 +818,25 @@ end = struct let get_args ( x : expr ) = let n = (get_num_args x) in let f i = expr_of_ptr (c_of_expr x) (Z3native.get_app_arg (nc_of_expr x) (ptr_of_expr x) i) in - Array.init n f + mk_list f n - let update ( x : expr ) args = - if (Array.length args <> (get_num_args x)) then + let update ( x : expr ) ( args : expr list ) = + if (List.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (Array.length args) (expr_aton args)) + expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (List.length args) (expr_lton args)) let substitute ( x : expr ) from to_ = - if (Array.length from) <> (Array.length to_) then + if (List.length from) <> (List.length to_) then raise (Z3native.Exception "Argument sizes do not match") else - expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (Array.length from) (expr_aton from) (expr_aton to_)) + expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (List.length from) (expr_lton from) (expr_lton to_)) let substitute_one ( x : expr ) from to_ = - substitute ( x : expr ) [| from |] [| to_ |] + substitute ( x : expr ) [ from ] [ to_ ] let substitute_vars ( x : expr ) to_ = - expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (Array.length to_) (expr_aton to_)) + expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (List.length to_) (expr_lton to_)) let translate ( x : expr ) to_ctx = if (c_of_expr x) == to_ctx then @@ -876,12 +882,12 @@ end = struct let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) range - let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [||] + let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [] let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) - let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = expr_of_func_app ctx f args + let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr list ) = expr_of_func_app ctx f args let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) @@ -950,8 +956,8 @@ struct let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (ptr_of_expr x) (ptr_of_expr y)) - let mk_distinct ( ctx : context ) ( args : expr array ) = - bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (expr_aton args)) + let mk_distinct ( ctx : context ) ( args : expr list ) = + bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) let mk_not ( ctx : context ) ( a : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) @@ -968,13 +974,13 @@ struct let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - let mk_and ( ctx : context ) ( args : bool_expr array ) = + let mk_and ( ctx : context ) ( args : bool_expr list ) = let f x = (ptr_of_expr (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (Array.map f args)) + bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) - let mk_or ( ctx : context ) ( args : bool_expr array ) = + let mk_or ( ctx : context ) ( args : bool_expr list ) = let f x = (ptr_of_expr (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (Array.map f args)) + bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) end @@ -1016,7 +1022,7 @@ struct let get_terms ( x : pattern ) = let n = (get_num_terms x) in let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) end @@ -1039,26 +1045,26 @@ struct let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) let get_bound_variable_names ( x : quantifier ) = let n = (get_num_bound x) in let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let get_bound_variable_sorts ( x : quantifier ) = let n = (get_num_bound x) in let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let get_body ( x : quantifier ) = Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) @@ -1066,95 +1072,95 @@ struct let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) - let mk_pattern ( ctx : context ) ( terms : expr array ) = - if (Array.length terms) == 0 then + let mk_pattern ( ctx : context ) ( terms : expr list ) = + if (List.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) + Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (List.length terms) (expr_lton terms))) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (Array.length sorts) != (Array.length names) then + let mk_forall ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (List.length sorts) != (List.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - (let f x = (Symbol.gno x) in (Array.map f names)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length nopatterns) (expr_aton nopatterns) - (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - (let f x = (Symbol.gno x) in (Array.map f names)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) (ptr_of_expr body))) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length nopatterns) (expr_aton nopatterns) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) (ptr_of_expr body))) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (Array.length sorts) != (Array.length names) then + let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (List.length sorts) != (List.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - (let f x = (Symbol.gno x) in (Array.map f names)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length nopatterns) (expr_aton nopatterns) - (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - (let f x = (Symbol.gno x) in (Array.map f names)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) (ptr_of_expr body))) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length nopatterns) (expr_aton nopatterns) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) (ptr_of_expr body))) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -1233,9 +1239,9 @@ struct let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) - let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = + let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr list ) = let m x = (ptr_of_expr (expr_of_array_expr x)) in - array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m args)) + array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) let mk_term_array ( ctx : context ) ( arg : array_expr ) = array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) @@ -1274,11 +1280,11 @@ struct let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) - let mk_union ( ctx : context ) ( args : expr array ) = - expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (expr_aton args)) + let mk_union ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) - let mk_intersection ( ctx : context ) ( args : expr array ) = - expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (expr_aton args)) + let mk_intersection ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) @@ -1378,7 +1384,7 @@ struct let get_column_sorts ( x : relation_sort ) = let n = get_arity x in let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in - Array.init n f + mk_list f n end @@ -1418,21 +1424,23 @@ struct module Constructor = struct type constructor = z3_native_object + + let _sizes = Hashtbl.create 0 - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = - let n = (Array.length field_names) in - if n != (Array.length sorts) then + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let n = (List.length field_names) in + if n != (List.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") else - if n != (Array.length sort_refs) then + if n != (List.length sort_refs) then raise (Z3native.Exception "Number of field names does not match number of sort refs") else let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) (Symbol.gno recognizer) n - (let f x = (Symbol.gno x) in (Array.map f field_names)) - (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - sort_refs) in + (Symbol.symbol_lton field_names) + (sort_lton sorts) + (Array.of_list sort_refs)) in let no : constructor = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; @@ -1441,9 +1449,10 @@ struct (z3obj_create no) ; let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; + Hashtbl.add _sizes no n ; no - let get_num_fields ( x : constructor ) = Z3native.get_arity (z3obj_gnc x) (z3obj_gno x) + let get_num_fields ( x : constructor ) = Hashtbl.find _sizes x let get_constructor_decl ( x : constructor ) = let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in @@ -1455,8 +1464,8 @@ struct let get_accessor_decls ( x : constructor ) = let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - let f y = func_decl_of_ptr (z3obj_gc x) y in - Array.map f c + let f i = func_decl_of_ptr (z3obj_gc x) (Array.get c i) in + mk_list f (Array.length c) end @@ -1464,48 +1473,47 @@ struct struct type constructor_list = z3_native_object - let create ( ctx : context ) ( c : Constructor.constructor array ) = + let create ( ctx : context ) ( c : Constructor.constructor list ) = let res : constructor_list = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref} in let f x =(z3obj_gno x) in - (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Array.map f c))) ; + (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (List.length c) (Array.of_list (List.map f c)))) ; (z3obj_create res) ; let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f res; res end - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = Constructor.create ctx name recognizer field_names sorts sort_refs - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = let f x = (z3obj_gno x) in - let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in + let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (List.length constructors) (Array.of_list (List.map f constructors))) in sort_of_ptr ctx x - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor list ) = mk_sort ctx (Symbol.mk_string ctx name) constructors - let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = - let n = (Array.length names) in + let mk_sorts ( ctx : context ) ( names : Symbol.symbol list ) ( c : Constructor.constructor list list ) = + let n = (List.length names) in let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in - let cla = (Array.map f c) in - let f2 x = (Symbol.gno x) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Array.map f2 names) cla) in - let g e = (sort_of_ptr ctx e) in - (Array.map g r) + let cla = (Array.of_list (List.map f c)) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.symbol_lton names) cla) in + let g i = (sort_of_ptr ctx (Array.get r i)) in + mk_list g (Array.length r) - let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = + let mk_sorts_s ( ctx : context ) ( names : string list ) ( c : Constructor.constructor list list ) = mk_sorts ctx ( let f e = (Symbol.mk_string ctx e) in - Array.map f names + List.map f names ) c @@ -1514,12 +1522,12 @@ struct let get_constructors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in - Array.init n f + mk_list f n let get_recognizers ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in - Array.init n f + mk_list f n let get_accessors ( x : datatype_sort ) = let n = (get_num_constructors x) in @@ -1527,9 +1535,9 @@ struct let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in - Array.init ds g + mk_list g ds ) in - Array.init n f + mk_list f n end @@ -1537,7 +1545,7 @@ module Enumeration = struct type enum_sort = EnumSort of sort - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl list ) ( tdecls : Z3native.z3_func_decl list ) = let s = (sort_of_ptr ctx no) in let res = EnumSort(s) in res @@ -1548,23 +1556,22 @@ struct let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = - let f x = Symbol.gno x in - let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Array.map f enum_names)) in - sort_of_ptr ctx a b c + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = + let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in + sort_of_ptr ctx a (list_of_array b) (list_of_array c) - let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string array ) = + let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) let get_const_decls ( x : enum_sort ) = let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in - Array.init n f + mk_list f n let get_tester_decls ( x : enum_sort ) = let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in - Array.init n f + mk_list f n end @@ -1609,7 +1616,7 @@ struct let get_tail_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) - let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [||] + let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [] end @@ -1627,10 +1634,8 @@ struct let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : sort array ) = - let f x = Symbol.gno x in - let f2 x = ptr_of_ast (ast_of_sort x) in - let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = + let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in sort_of_ptr ctx r let get_mk_decl ( x : tuple_sort ) = @@ -1641,7 +1646,7 @@ struct let get_field_decls ( x : tuple_sort ) = let n = get_num_fields x in let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in - Array.init n f + mk_list f n end @@ -1746,9 +1751,9 @@ sig val is_int_numeral : Expr.expr -> bool val is_rat_num : Expr.expr -> bool val is_algebraic_number : Expr.expr -> bool - val mk_add : context -> arith_expr array -> arith_expr - val mk_mul : context -> arith_expr array -> arith_expr - val mk_sub : context -> arith_expr array -> arith_expr + val mk_add : context -> arith_expr list -> arith_expr + val mk_mul : context -> arith_expr list -> arith_expr + val mk_sub : context -> arith_expr list -> arith_expr val mk_unary_minus : context -> arith_expr -> arith_expr val mk_div : context -> arith_expr -> arith_expr -> arith_expr val mk_power : context -> arith_expr -> arith_expr -> arith_expr @@ -2109,17 +2114,17 @@ end = struct let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (nc_of_expr x) (nc_of_expr x) - let mk_add ( ctx : context ) ( t : arith_expr array ) = + let mk_add ( ctx : context ) ( t : arith_expr list ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Array.map f t))) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_mul ( ctx : context ) ( t : arith_expr array ) = + let mk_mul ( ctx : context ) ( t : arith_expr list ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Array.map f t))) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_sub ( ctx : context ) ( t : arith_expr array ) = + let mk_sub ( ctx : context ) ( t : arith_expr list ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Array.map f t))) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) @@ -2551,9 +2556,9 @@ struct let is_garbage ( x : goal ) = (get_precision x) == GOAL_UNDER_OVER - let assert_ ( x : goal ) ( constraints : Boolean.bool_expr array ) = + let assert_ ( x : goal ) ( constraints : Boolean.bool_expr list ) = let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in - ignore (Array.map f constraints) ; + ignore (List.map f constraints) ; () let is_inconsistent ( x : goal ) = @@ -2569,7 +2574,7 @@ struct let n = get_size x in let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in - Array.init n f + mk_list f n let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) @@ -2653,12 +2658,12 @@ struct let get_args ( x : func_entry ) = let n = (get_num_args x) in let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in - Array.init n f + mk_list f n let to_string ( x : func_entry ) = let a = (get_args x) in let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") + "[" ^ List.fold_right f a ((Expr.to_string (get_value x)) ^ "]") end let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) @@ -2666,7 +2671,7 @@ struct let get_entries ( x : func_interp ) = let n = (get_num_entries x) in let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in - Array.init n f + mk_list f n let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) @@ -2678,12 +2683,12 @@ struct p ^ let g c p = (p ^ (Expr.to_string c) ^ ", ") in (if n > 1 then "[" else "") ^ - (Array.fold_right + (List.fold_right g (FuncEntry.get_args c) ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) ) in - Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + List.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") end let get_const_interp ( x : model ) ( f : func_decl ) = @@ -2725,21 +2730,21 @@ struct let get_const_decls ( x : model ) = let n = (get_num_consts x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) let get_func_decls ( x : model ) = let n = (get_num_consts x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - Array.append (Array.init n_funcs f) (Array.init n_consts g) + (mk_list f n_funcs) @ (mk_list g n_consts) exception ModelEvaluationFailedException of string @@ -2758,13 +2763,13 @@ struct let get_sorts ( x : model ) = let n = (get_num_sorts x) in let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in - Array.init n f + mk_list f n let sort_universe ( x : model ) ( s : sort ) = let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in - Array.init n f + mk_list f n let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) end @@ -2793,7 +2798,7 @@ struct let get_probe_names ( ctx : context ) = let n = (get_num_probes ctx) in let f i = (Z3native.get_probe_name (context_gno ctx) i) in - Array.init n f + mk_list f n let get_probe_description ( ctx : context ) ( name : string ) = Z3native.probe_get_descr (context_gno ctx) name @@ -2862,7 +2867,7 @@ struct let get_subgoals ( x : apply_result ) = let n = (get_num_subgoals x) in let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get_subgoal ( x : apply_result ) ( i : int ) = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) @@ -2888,7 +2893,7 @@ struct let get_tactic_names ( ctx : context ) = let n = (get_num_tactics ctx ) in let f i = (Z3native.get_tactic_name (context_gno ctx) i) in - Array.init n f + mk_list f n let get_tactic_description ( ctx : context ) ( name : string ) = Z3native.tactic_get_descr (context_gno ctx) name @@ -2896,11 +2901,11 @@ struct let mk_tactic ( ctx : context ) ( name : string ) = create ctx (Z3native.mk_tactic (context_gno ctx) name) - let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array ) = + let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic list ) = let f p c = (match p with | None -> (Some (z3obj_gno c)) | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in - match (Array.fold_left f None ts) with + match (List.fold_left f None ts) with | None -> create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) | Some(x) -> @@ -2940,8 +2945,9 @@ struct let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = using_params ctx t p - let par_or ( ctx : context ) ( t : tactic array ) = - create ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) + let par_or ( ctx : context ) ( t : tactic list ) = + let f e = (z3obj_gno e) in + create ctx (Z3native.tactic_par_or (context_gno ctx) (List.length t) (Array.of_list (List.map f t))) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) @@ -3042,16 +3048,16 @@ struct else (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in - Array.init n f + mk_list f n let get_keys ( x : statistics ) = let n = (get_size x) in let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get ( x : statistics ) ( key : string ) = let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in - Array.fold_left f None (get_entries x) + List.fold_left f None (get_entries x) end let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) @@ -3070,16 +3076,16 @@ struct let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - let assert_ ( x : solver ) ( constraints : Boolean.bool_expr array ) = + let assert_ ( x : solver ) ( constraints : Boolean.bool_expr list ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in - ignore (Array.map f constraints) + ignore (List.map f constraints) - let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr array ) ( ps : Boolean.bool_expr array ) = - if ((Array.length cs) != (Array.length ps)) then + let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr list ) ( ps : Boolean.bool_expr list ) = + if ((List.length cs) != (List.length ps)) then raise (Z3native.Exception "Argument size mismatch") else - let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) (Boolean.gno (Array.get ps i))) in - ignore (Array.iteri f cs) + let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno a) (Boolean.gno b)) in + ignore (List.iter2 f cs ps) let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) @@ -3092,15 +3098,15 @@ struct let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in - Array.init n f + mk_list f n - let check ( x : solver ) ( assumptions : Boolean.bool_expr array) = + let check ( x : solver ) ( assumptions : Boolean.bool_expr list ) = let r = - if ((Array.length assumptions) == 0) then + if ((List.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else let f x = (ptr_of_expr (Boolean.expr_of_bool_expr x)) in - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Array.map f assumptions)) + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) in match r with | L_TRUE -> SATISFIABLE @@ -3125,7 +3131,7 @@ struct let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in - Array.init n f + mk_list f n let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) @@ -3173,9 +3179,9 @@ struct let get_param_descrs ( x : fixedpoint ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr array ) = + let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr list ) = let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in - ignore (Array.map f constraints) ; + ignore (List.map f constraints) ; () let register_relation ( x : fixedpoint ) ( f : func_decl ) = @@ -3186,8 +3192,8 @@ struct | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) - let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = - Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (Array.length args) args + let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = + Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with @@ -3195,9 +3201,9 @@ struct | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN - let query_r ( x : fixedpoint ) ( relations : func_decl array ) = + let query_r ( x : fixedpoint ) ( relations : func_decl list ) = let f x = ptr_of_ast (ast_of_func_decl x) in - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (Array.map f relations))) with + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (List.length relations) (Array.of_list (List.map f relations)))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -3236,25 +3242,24 @@ struct let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = - let f2 x = (Symbol.gno x) in - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Array.map f2 kinds) + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) - let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr array ) = + let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr list ) = let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Array.map f queries) + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) let get_rules ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - Array.init n f + mk_list f n let get_assertions ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - Array.init n f + mk_list f n let mk_fixedpoint ( ctx : context ) = create ctx end @@ -3282,102 +3287,102 @@ end module SMT = struct - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr array ) ( formula : Boolean.bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr list ) ( formula : Boolean.bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.map f assumptions)) + (List.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.of_list (List.map f assumptions))) (Boolean.gno formula) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = - let csn = (Array.length sort_names) in - let cs = (Array.length sorts) in - let cdn = (Array.length decl_names) in - let cd = (Array.length decls) in + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else Z3native.parse_smtlib_string (context_gno ctx) str cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) + (Symbol.symbol_lton sort_names) + (sort_lton sorts) cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)) + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = - let csn = (Array.length sort_names) in - let cs = (Array.length sorts) in - let cdn = (Array.length decl_names) in - let cd = (Array.length decls) in + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else Z3native.parse_smtlib_file (context_gno ctx) file_name cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) + (Symbol.symbol_lton sort_names) + (sort_lton sorts) cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)) + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in - Array.init n f + mk_list f n let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in - Array.init n f + mk_list f n let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in - Array.init n f + mk_list f n let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in - Array.init n f + mk_list f n - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = - let csn = (Array.length sort_names) in - let cs = (Array.length sorts) in - let cdn = (Array.length decl_names) in - let cd = (Array.length decls) in + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) + (Symbol.symbol_lton sort_names) + (sort_lton sorts) cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)))) + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = - let csn = (Array.length sort_names) in - let cs = (Array.length sorts) in - let cdn = (Array.length decl_names) in - let cd = (Array.length decls) in + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) + (Symbol.symbol_lton sort_names) + (sort_lton sorts) cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)))) + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) end From 6417f9e64815f98a59693146f1bc8d6b5c57a2d8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 21 Feb 2013 13:25:31 +0000 Subject: [PATCH 064/248] ML API: flat & rich layer in place. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 40 +- src/api/ml/z3.ml | 1458 ++++------------ src/api/ml/z3_rich.ml | 3400 +++++++++++++++++++++++++++++++++++++ src/api/ml/z3_rich.mli | 3072 +++++++++++++++++++++++++++++++++ 4 files changed, 6865 insertions(+), 1105 deletions(-) create mode 100644 src/api/ml/z3_rich.ml create mode 100644 src/api/ml/z3_rich.mli diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 31f31d566..823a08fe2 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -26,20 +26,14 @@ exception TestFailedException of string *) let model_converter_test ( ctx : context ) = Printf.printf "ModelConverterTest\n"; - let xr = (arith_expr_of_expr - (Expr.mk_const ctx (Symbol.mk_string ctx "x") - (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in - let yr = (arith_expr_of_expr - (Expr.mk_const ctx (Symbol.mk_string ctx "y") - (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in + let xr = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Real.mk_sort ctx)) in + let yr = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Real.mk_sort ctx)) in let g4 = (mk_goal ctx true false false ) in - (Goal.assert_ g4 [ (mk_gt ctx xr - (arith_expr_of_real_expr (real_expr_of_rat_num - (Real.mk_numeral_nd ctx 10 1)))) ]) ; + (Goal.assert_ g4 [ (mk_gt ctx xr (Real.mk_numeral_nd ctx 10 1)) ]) ; (Goal.assert_ g4 [ (mk_eq ctx - (expr_of_arith_expr yr) - (expr_of_arith_expr (Arithmetic.mk_add ctx [ xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) ]) ) ) ] ) ; - (Goal.assert_ g4 [ (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) ]) ; + yr + (Arithmetic.mk_add ctx [ xr; (Real.mk_numeral_nd ctx 1 1) ])) ]) ; + (Goal.assert_ g4 [ (mk_gt ctx yr (Real.mk_numeral_nd ctx 1 1)) ]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in if ((get_num_subgoals ar) == 1 && @@ -83,7 +77,7 @@ let basic_tests ( ctx : context ) = let fname = (mk_string ctx "f") in let x = (mk_string ctx "x") in let y = (mk_string ctx "y") in - let bs = (sort_of_bool_sort (Boolean.mk_sort ctx)) in + let bs = (Boolean.mk_sort ctx) in let domain = [ bs; bs ] in let f = (FuncDecl.mk_func_decl ctx fname domain bs) in let fapp = (mk_app ctx f @@ -123,10 +117,8 @@ let basic_tests ( ctx : context ) = Printf.printf "Test passed.\n" ); (Goal.assert_ g [ (mk_eq ctx - (mk_numeral_int ctx 1 - (sort_of_bitvec_sort (BitVector.mk_sort ctx 32))) - (mk_numeral_int ctx 2 - (sort_of_bitvec_sort (BitVector.mk_sort ctx 32)))) ] ) + (mk_numeral_int ctx 1 (BitVector.mk_sort ctx 32)) + (mk_numeral_int ctx 2 (BitVector.mk_sort ctx 32))) ] ) ; ( let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in @@ -157,10 +149,10 @@ let basic_tests ( ctx : context ) = ); ( let g3 = (mk_goal ctx true true false) in - let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in - let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in - (Goal.assert_ g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) ]) ; - (Goal.assert_ g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) ]) ; + let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Integer.mk_sort ctx)) in + let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Integer.mk_sort ctx)) in + (Goal.assert_ g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (Integer.mk_sort ctx))) ]) ; + (Goal.assert_ g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (Integer.mk_sort ctx))) ]) ; let constr = (mk_eq ctx xc yc) in (Goal.assert_ g3 [ constr ] ) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in @@ -228,9 +220,9 @@ let _ = let rs = (Real.mk_sort ctx) in Printf.printf "int symbol: %s\n" (Symbol.to_string is); Printf.printf "string symbol: %s\n" (Symbol.to_string ss); - Printf.printf "bool sort: %s\n" (Sort.to_string (sort_of_bool_sort bs)); - Printf.printf "int sort: %s\n" (Sort.to_string (sort_of_arith_sort (arith_sort_of_int_sort ints))); - Printf.printf "real sort: %s\n" (Sort.to_string (sort_of_arith_sort (arith_sort_of_real_sort rs))); + Printf.printf "bool sort: %s\n" (Sort.to_string bs); + Printf.printf "int sort: %s\n" (Sort.to_string ints); + Printf.printf "real sort: %s\n" (Sort.to_string rs); basic_tests ctx ; Printf.printf "Disposing...\n"; Gc.full_major () diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 56d319c1a..0676f1a39 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -133,52 +133,34 @@ let mk_context ( cfg : ( string * string ) list ) = module Symbol = struct - (* Symbol types *) - type int_symbol = z3_native_object - type string_symbol = z3_native_object - - type symbol = - | S_Int of int_symbol - | S_Str of string_symbol - + type symbol = z3_native_object let create_i ( ctx : context ) ( no : Z3native.ptr ) = - let res : int_symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in + let res : symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + let create_s ( ctx : context ) ( no : Z3native.ptr ) = - let res : string_symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in + let res : symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in (z3obj_sno res ctx no) ; (z3obj_create res) ; res let create ( ctx : context ) ( no : Z3native.ptr ) = match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> S_Int (create_i ctx no) - | STRING_SYMBOL -> S_Str (create_s ctx no) + | INT_SYMBOL -> (create_i ctx no) + | STRING_SYMBOL -> (create_s ctx no) - let gc ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gc n) - | S_Str(n) -> (z3obj_gc n) - - let gnc ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gnc n) - | S_Str(n) -> (z3obj_gnc n) - - let gno ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gno n) - | S_Str(n) -> (z3obj_gno n) + let gc ( x : symbol ) = (z3obj_gc x) + let gnc ( x : symbol ) = (z3obj_gnc x) + let gno ( x : symbol ) = (z3obj_gno x) let symbol_lton ( a : symbol list ) = let f ( e : symbol ) = (gno e) in @@ -187,18 +169,18 @@ struct let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL - let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) - let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) + let get_int (o : symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) + let get_string (o : symbol ) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) let to_string ( o : symbol ) = match (kind o) with | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) let mk_int ( ctx : context ) ( i : int ) = - S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) + (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) let mk_string ( ctx : context ) ( s : string ) = - S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) + (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) let mk_ints ( ctx : context ) ( names : int list ) = let f elem = mk_int ( ctx : context ) elem in @@ -353,7 +335,6 @@ open AST module Sort = struct type sort = Sort of AST.ast - type uninterpreted_sort = UninterpretedSort of sort let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> let q = (z3_native_object_of_ast_ptr ctx no) in @@ -373,14 +354,7 @@ struct | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") let ast_of_sort s = match s with Sort(x) -> x - let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x - - let uninterpreted_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - UninterpretedSort(s) - + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) @@ -409,7 +383,7 @@ struct dec_ref = Z3native.dec_ref } in (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; (z3obj_create res) ; - UninterpretedSort(Sort(res)) + Sort(res) let mk_uninterpreted_s ( ctx : context ) ( s : string ) = mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) @@ -713,9 +687,9 @@ and Expr : sig type expr = Expr of AST.ast val expr_of_ptr : context -> Z3native.ptr -> expr - val c_of_expr : expr -> context - val nc_of_expr : expr -> Z3native.ptr - val ptr_of_expr : expr -> Z3native.ptr + val gc : expr -> context + val gnc : expr -> Z3native.ptr + val gno : expr -> Z3native.ptr val expr_lton : expr list -> Z3native.ptr array val ast_of_expr : expr -> AST.ast val expr_of_ast : AST.ast -> expr @@ -762,9 +736,9 @@ sig end = struct type expr = Expr of AST.ast - let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) - let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) - let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) + let gc e = match e with Expr(a) -> (z3obj_gc a) + let gnc e = match e with Expr(a) -> (z3obj_gnc a) + let gno e = match e with Expr(a) -> (z3obj_gno a) let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then @@ -802,60 +776,60 @@ end = struct expr_of_ptr ctx o let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> expr_of_ptr (c_of_expr x) (Z3native.simplify (nc_of_expr x) (ptr_of_expr x)) - | Some pp -> expr_of_ptr (c_of_expr x) (Z3native.simplify_ex (nc_of_expr x) (ptr_of_expr x) (z3obj_gno pp)) + | None -> expr_of_ptr (Expr.gc x) (Z3native.simplify (gnc x) (gno x)) + | Some pp -> expr_of_ptr (Expr.gc x) (Z3native.simplify_ex (gnc x) (gno x) (z3obj_gno pp)) let get_simplify_help ( ctx : context ) = Z3native.simplify_get_help (context_gno ctx) let get_simplify_parameter_descrs ( ctx : context ) = Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) + let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (gnc x) (gno x)) - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (nc_of_expr x) (ptr_of_expr x)) + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) - let get_num_args ( x : expr ) = Z3native.get_app_num_args (nc_of_expr x) (ptr_of_expr x) + let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = expr_of_ptr (c_of_expr x) (Z3native.get_app_arg (nc_of_expr x) (ptr_of_expr x) i) in + let f i = expr_of_ptr (Expr.gc x) (Z3native.get_app_arg (gnc x) (gno x) i) in mk_list f n let update ( x : expr ) ( args : expr list ) = if (List.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (List.length args) (expr_lton args)) + expr_of_ptr (Expr.gc x) (Z3native.update_term (gnc x) (gno x) (List.length args) (expr_lton args)) let substitute ( x : expr ) from to_ = if (List.length from) <> (List.length to_) then raise (Z3native.Exception "Argument sizes do not match") else - expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (List.length from) (expr_lton from) (expr_lton to_)) + expr_of_ptr (Expr.gc x) (Z3native.substitute (gnc x) (gno x) (List.length from) (expr_lton from) (expr_lton to_)) let substitute_one ( x : expr ) from to_ = substitute ( x : expr ) [ from ] [ to_ ] let substitute_vars ( x : expr ) to_ = - expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (List.length to_) (expr_lton to_)) + expr_of_ptr (Expr.gc x) (Z3native.substitute_vars (gnc x) (gno x) (List.length to_) (expr_lton to_)) let translate ( x : expr ) to_ctx = - if (c_of_expr x) == to_ctx then + if (Expr.gc x) == to_ctx then x else - expr_of_ptr to_ctx (Z3native.translate (nc_of_expr x) (ptr_of_expr x) (context_gno to_ctx)) + expr_of_ptr to_ctx (Z3native.translate (gnc x) (gno x) (context_gno to_ctx)) - let to_string ( x : expr ) = Z3native.ast_to_string (nc_of_expr x) (ptr_of_expr x) + let to_string ( x : expr ) = Z3native.ast_to_string (gnc x) (gno x) - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (nc_of_expr x) (ptr_of_expr x)) + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (gnc x) (gno x)) - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (nc_of_expr x) (ptr_of_expr x) + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) - let get_sort ( x : expr ) = sort_of_ptr (c_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)) + let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (gnc x) (gno x)) let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (nc_of_expr x) - (Z3native.mk_bool_sort (nc_of_expr x)) - (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x))) + (Z3native.is_eq_sort (gnc x) + (Z3native.mk_bool_sort (gnc x)) + (Z3native.get_sort (gnc x) (gno x))) let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && (get_num_args x) == 0 && @@ -901,86 +875,52 @@ open Expr module Boolean = struct - type bool_sort = BoolSort of Sort.sort - type bool_expr = BoolExpr of Expr.expr - - let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let a = (AST.ast_of_ptr ctx no) in - BoolExpr(Expr.Expr(a)) - - let bool_expr_of_expr e = - match e with Expr.Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolExpr(e) - - let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - BoolSort(sort_of_ptr ctx no) - - let sort_of_bool_sort s = match s with BoolSort(x) -> x - - let bool_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolSort(s) - - let expr_of_bool_expr e = match e with BoolExpr(x) -> x - - let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.c_of_expr e) - let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.nc_of_expr e) - let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.ptr_of_expr e) - let mk_sort ( ctx : context ) = - BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) + (sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - let s = (match (mk_sort ctx) with BoolSort(q) -> q) in - BoolExpr(Expr.mk_const ctx name s) + (Expr.mk_const ctx name (mk_sort ctx)) let mk_const_s ( ctx : context ) ( name : string ) = mk_const ctx (Symbol.mk_string ctx name) let mk_true ( ctx : context ) = - bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) + expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) let mk_false ( ctx : context ) = - bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) + expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) let mk_val ( ctx : context ) ( value : bool ) = if value then mk_true ctx else mk_false ctx let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (ptr_of_expr x) (ptr_of_expr y)) + expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) let mk_distinct ( ctx : context ) ( args : expr list ) = - bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) + expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) - let mk_not ( ctx : context ) ( a : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) + let mk_not ( ctx : context ) ( a : expr ) = + expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) - let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + let mk_ite ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( t3 : expr ) = + expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) - let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + let mk_iff ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) - let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + let mk_implies ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) - let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + let mk_xor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - let mk_and ( ctx : context ) ( args : bool_expr list ) = - let f x = (ptr_of_expr (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) + let mk_and ( ctx : context ) ( args : expr list ) = + let f x = (Expr.gno (x)) in + expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) - let mk_or ( ctx : context ) ( args : bool_expr list ) = - let f x = (ptr_of_expr (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) + let mk_or ( ctx : context ) ( args : expr list ) = + let f x = (Expr.gno (x)) in + expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) end @@ -998,9 +938,9 @@ struct else Quantifier(e) - let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (c_of_expr e) - let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (nc_of_expr e) - let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (ptr_of_expr e) + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) + let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) + let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) module Pattern = struct @@ -1031,7 +971,7 @@ struct if not (AST.is_var (match x with Expr.Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else - Z3native.get_index_value (nc_of_expr x) (ptr_of_expr x) + Z3native.get_index_value (Expr.gnc x) (Expr.gno x) let is_universal ( x : quantifier ) = Z3native.is_quantifier_forall (gnc x) (gno x) @@ -1067,7 +1007,7 @@ struct mk_list f n let get_body ( x : quantifier ) = - Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) + expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) @@ -1087,7 +1027,7 @@ struct (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (List.length sorts) (sort_lton sorts) (Symbol.symbol_lton names) - (ptr_of_expr body))) + (Expr.gno body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) @@ -1097,7 +1037,7 @@ struct (List.length nopatterns) (expr_lton nopatterns) (List.length sorts) (sort_lton sorts) (Symbol.symbol_lton names) - (ptr_of_expr body))) + (Expr.gno body))) let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then @@ -1105,7 +1045,7 @@ struct (match weight with | None -> 1 | Some(x) -> x) (List.length bound_constants) (expr_lton bound_constants) (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (ptr_of_expr body))) + (Expr.gno body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) @@ -1114,7 +1054,7 @@ struct (List.length bound_constants) (expr_lton bound_constants) (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (List.length nopatterns) (expr_lton nopatterns) - (ptr_of_expr body))) + (Expr.gno body))) let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (List.length sorts) != (List.length names) then @@ -1125,7 +1065,7 @@ struct (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (List.length sorts) (sort_lton sorts) (Symbol.symbol_lton names) - (ptr_of_expr body))) + (Expr.gno body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) @@ -1135,7 +1075,7 @@ struct (List.length nopatterns) (expr_lton nopatterns) (List.length sorts) (sort_lton sorts) (Symbol.symbol_lton names) - (ptr_of_expr body))) + (Expr.gno body))) let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then @@ -1143,7 +1083,7 @@ struct (match weight with | None -> 1 | Some(x) -> x) (List.length bound_constants) (expr_lton bound_constants) (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (ptr_of_expr body))) + (Expr.gno body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) @@ -1152,7 +1092,7 @@ struct (List.length bound_constants) (expr_lton bound_constants) (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (List.length nopatterns) (expr_lton nopatterns) - (ptr_of_expr body))) + (Expr.gno body))) let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then @@ -1170,46 +1110,8 @@ end module Array_ = struct - type array_sort = ArraySort of sort - type array_expr = ArrayExpr of expr - - let array_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (expr_of_ptr ctx no) in - ArrayExpr(e) - - let array_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - ArraySort(s) - - let sort_of_array_sort s = match s with ArraySort(x) -> x - - let array_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArraySort(s) - - let array_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArrayExpr(e) - - let expr_of_array_expr e = match e with ArrayExpr(x) -> x - - let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gno s) - - let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gc e) - let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) - let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) - let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = - array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) + sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) @@ -1218,48 +1120,40 @@ struct let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) let is_array ( x : expr ) = - (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == ARRAY_SORT) + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) - let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) - let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) + let get_domain ( x : sort ) = Sort.sort_of_ptr (Sort.gc x) (Z3native.get_array_sort_domain (Sort.gnc x) (Sort.gno x)) + let get_range ( x : sort ) = Sort.sort_of_ptr (Sort.gc x) (Z3native.get_array_sort_range (Sort.gnc x) (Sort.gno x)) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = - ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) + (Expr.mk_const ctx name (mk_sort ctx domain range)) let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) domain range - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) + let mk_select ( ctx : context ) ( a : expr ) ( i : expr ) = + expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (Expr.gno a) (Expr.gno i)) - let mk_store ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = - array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) + let mk_store ( ctx : context ) ( a : expr ) ( i : expr ) ( v : expr ) = + expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (Expr.gno a) (Expr.gno i) (Expr.gno v)) let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) + expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) - let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr list ) = - let m x = (ptr_of_expr (expr_of_array_expr x)) in - array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) + let mk_map ( ctx : context ) ( f : func_decl ) ( args : expr list ) = + let m x = (Expr.gno x) in + expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) - let mk_term_array ( ctx : context ) ( arg : array_expr ) = - array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) + let mk_term_array ( ctx : context ) ( arg : expr ) = + expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (Expr.gno arg)) end module Set = struct - type set_sort = SetSort of sort - - let set_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - SetSort(s) - - let sort_of_set_sort s = match s with SetSort(x) -> x - let mk_sort ( ctx : context ) ( ty : sort ) = - set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) + sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) @@ -1275,10 +1169,10 @@ struct expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) + expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) + expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) let mk_union ( ctx : context ) ( args : expr list ) = expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) @@ -1287,53 +1181,37 @@ struct expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) + expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) let mk_complement ( ctx : context ) ( arg : expr ) = - expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (ptr_of_expr arg)) + expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (ptr_of_expr elem) (ptr_of_expr set)) + expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) + expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) end module FiniteDomain = struct - type finite_domain_sort = FiniteDomainSort of sort - - let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x - - let finite_domain_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - FiniteDomainSort(s) - - let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) - let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) - let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in - FiniteDomainSort(s) + (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = mk_sort ctx (Symbol.mk_string ctx name) size - let is_finite_domain ( x : expr ) = - let nc = (nc_of_expr x) in - (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == FINITE_DOMAIN_SORT) + let nc = (Expr.gnc x) in + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) - let get_size ( x : finite_domain_sort ) = - let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in + let get_size ( x : sort ) = + let (r, v) = (Z3native.get_finite_domain_sort_size (Sort.gnc x) (Sort.gno x)) in if r then v else raise (Z3native.Exception "Conversion failed.") end @@ -1341,29 +1219,10 @@ end module Relation = struct - type relation_sort = RelationSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - RelationSort(s) - - let sort_of_relation_sort s = match s with RelationSort(x) -> x - - let relation_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RelationSort(s) - - let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) - let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) - let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) - - let is_relation ( x : expr ) = - let nc = (nc_of_expr x) in - ((Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == RELATION_SORT)) + let nc = (Expr.gnc x) in + ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) @@ -1379,48 +1238,17 @@ struct let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) - let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) + let get_arity ( x : sort ) = Z3native.get_relation_arity (Sort.gnc x) (Sort.gno x) - let get_column_sorts ( x : relation_sort ) = + let get_column_sorts ( x : sort ) = let n = get_arity x in - let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in + let f i = (sort_of_ptr (Sort.gc x) (Z3native.get_relation_column (Sort.gnc x) (Sort.gno x) i)) in mk_list f n - end module Datatype = struct - type datatype_sort = DatatypeSort of sort - type datatype_expr = DatatypeExpr of expr - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - DatatypeSort(s) - - let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x - - let datatype_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeSort(s) - - let datatype_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeExpr(e) - - let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x - - let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) - module Constructor = struct type constructor = z3_native_object @@ -1517,24 +1345,24 @@ struct ) c - let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) + let get_num_constructors ( x : sort ) = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) - let get_constructors ( x : datatype_sort ) = + let get_constructors ( x : sort ) = let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i) in mk_list f n - let get_recognizers ( x : datatype_sort ) = + let get_recognizers ( x : sort ) = let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) i) in mk_list f n - let get_accessors ( x : datatype_sort ) = + let get_accessors ( x : sort ) = let n = (get_num_constructors x) in let f i = ( - let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let fd = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i) in let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in - let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in + let g j = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) i j) in mk_list g ds ) in mk_list f n @@ -1543,467 +1371,133 @@ end module Enumeration = struct - type enum_sort = EnumSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl list ) ( tdecls : Z3native.z3_func_decl list ) = - let s = (sort_of_ptr ctx no) in - let res = EnumSort(s) in - res - - let sort_of_enum_sort s = match s with EnumSort(x) -> x - - let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = - let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in - sort_of_ptr ctx a (list_of_array b) (list_of_array c) + let (a, _, _) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in + sort_of_ptr ctx a let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) - let get_const_decls ( x : enum_sort ) = - let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in - let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in + let get_const_decls ( x : sort ) = + let n = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) in + let f i = (func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i)) in mk_list f n - let get_tester_decls ( x : enum_sort ) = - let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in - let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in + let get_tester_decls ( x : sort ) = + let n = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) in + let f i = (func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) i)) in mk_list f n end module List_ = -struct - type list_sort = ListSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - let res = ListSort(s) in - res - - let sort_of_list_sort s = match s with ListSort(x) -> x - - let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) - +struct let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in - sort_of_ptr ctx r a b c d e f + let (r, _, _, _, _, _, _) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in + sort_of_ptr ctx r let mk_list_s ( ctx : context ) (name : string) elem_sort = mk_sort ctx (Symbol.mk_string ctx name) elem_sort - let get_nil_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) + let get_nil_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) 0) - let get_is_nil_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) + let get_is_nil_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) 0) - let get_cons_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) + let get_cons_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) 1) - let get_is_cons_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) + let get_is_cons_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) 1) - let get_head_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) + let get_head_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) 1 0) - let get_tail_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) + let get_tail_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) 1 1) - let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [] + let nil ( x : sort ) = expr_of_func_app (Sort.gc x) (get_nil_decl x) [] end module Tuple = struct - type tuple_sort = TupleSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - TupleSort(s) - - let sort_of_tuple_sort s = match s with TupleSort(x) -> x - - let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in sort_of_ptr ctx r - let get_mk_decl ( x : tuple_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) + let get_mk_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_tuple_sort_mk_decl (Sort.gnc x) (Sort.gno x)) - let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) + let get_num_fields ( x : sort ) = Z3native.get_tuple_sort_num_fields (Sort.gnc x) (Sort.gno x) - let get_field_decls ( x : tuple_sort ) = + let get_field_decls ( x : sort ) = let n = get_num_fields x in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_tuple_sort_field_decl (Sort.gnc x) (Sort.gno x) i) in mk_list f n end -module rec Arithmetic : -sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val sort_of_arith_sort : arith_sort -> Sort.sort - val arith_sort_of_sort : Sort.sort -> arith_sort - val expr_of_arith_expr : arith_expr -> Expr.expr - val arith_expr_of_expr : Expr.expr -> arith_expr +module Arithmetic = +struct - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val int_expr_of_ptr : context -> Z3native.ptr -> int_expr - val int_num_of_ptr : context -> Z3native.ptr -> int_num - - val arith_sort_of_int_sort : Integer.int_sort -> arith_sort - val int_sort_of_arith_sort : arith_sort -> int_sort - val arith_expr_of_int_expr : int_expr -> arith_expr - val int_expr_of_int_num : int_num -> int_expr - val int_expr_of_arith_expr : arith_expr -> int_expr - val int_num_of_int_expr : int_expr -> int_num - - val mk_sort : context -> int_sort - val get_int : int_num -> int - val to_string : int_num -> string - val mk_int_const : context -> Symbol.symbol -> int_expr - val mk_int_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> int_expr - val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_int_numeral_s : context -> string -> int_num - val mk_int_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> Real.real_expr - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val real_expr_of_ptr : context -> Z3native.ptr -> real_expr - val rat_num_of_ptr : context -> Z3native.ptr -> rat_num - - val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort - val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort - val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr - val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr - val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr - val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num - - val mk_sort : context -> real_sort - val get_numerator : rat_num -> Integer.int_num - val get_denominator : rat_num -> Integer.int_num - val to_decimal_string : rat_num -> int -> string - val to_string : rat_num -> string - val mk_real_const : context -> Symbol.symbol -> real_expr - val mk_real_const_s : context -> string -> real_expr - val mk_numeral_nd : context -> int -> int -> rat_num - val mk_numeral_s : context -> string -> rat_num - val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - val mk_real2int : context -> real_expr -> Integer.int_expr - end - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : algebraic_num -> arith_expr - val algebraic_num_of_arith_expr : arith_expr -> algebraic_num - - val to_upper : algebraic_num -> int -> Real.rat_num - val to_lower : algebraic_num -> int -> Real.rat_num - val to_decimal_string : algebraic_num -> int -> string - val to_string : algebraic_num -> string - end - - val is_int : Expr.expr -> bool - val is_arithmetic_numeral : Expr.expr -> bool - val is_le : Expr.expr -> bool - val is_ge : Expr.expr -> bool - val is_lt : Expr.expr -> bool - val is_gt : Expr.expr -> bool - val is_add : Expr.expr -> bool - val is_sub : Expr.expr -> bool - val is_uminus : Expr.expr -> bool - val is_mul : Expr.expr -> bool - val is_div : Expr.expr -> bool - val is_idiv : Expr.expr -> bool - val is_remainder : Expr.expr -> bool - val is_modulus : Expr.expr -> bool - val is_inttoreal : Expr.expr -> bool - val is_real_to_int : Expr.expr -> bool - val is_real_is_int : Expr.expr -> bool - val is_real : Expr.expr -> bool - val is_int_numeral : Expr.expr -> bool - val is_rat_num : Expr.expr -> bool - val is_algebraic_number : Expr.expr -> bool - val mk_add : context -> arith_expr list -> arith_expr - val mk_mul : context -> arith_expr list -> arith_expr - val mk_sub : context -> arith_expr list -> arith_expr - val mk_unary_minus : context -> arith_expr -> arith_expr - val mk_div : context -> arith_expr -> arith_expr -> arith_expr - val mk_power : context -> arith_expr -> arith_expr -> arith_expr - val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr -end = struct - type arith_sort = ArithSort of sort - type arith_expr = ArithExpr of expr - - let arith_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithExpr(e) - - let arith_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - arith_expr_of_expr (expr_of_ptr ctx no) - - let sort_of_arith_sort s = match s with ArithSort(x) -> x - let expr_of_arith_expr e = match e with ArithExpr(x) -> x - - let arith_sort_of_sort s = match s with Sort(a) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithSort(s) - - let arith_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - arith_sort_of_sort (sort_of_ptr ctx no) - - let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gno s) - let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (c_of_expr e) - let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (nc_of_expr e) - let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (ptr_of_expr e) - - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val int_expr_of_ptr : context -> Z3native.ptr -> int_expr - val int_num_of_ptr : context -> Z3native.ptr -> int_num - - val arith_sort_of_int_sort : Integer.int_sort -> arith_sort - val int_sort_of_arith_sort : arith_sort -> int_sort - val arith_expr_of_int_expr : int_expr -> arith_expr - val int_expr_of_int_num : int_num -> int_expr - val int_expr_of_arith_expr : arith_expr -> int_expr - val int_num_of_int_expr : int_expr -> int_num - - val mk_sort : context -> int_sort - val get_int : int_num -> int - val to_string : int_num -> string - val mk_int_const : context -> Symbol.symbol -> int_expr - val mk_int_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> int_expr - val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_int_numeral_s : context -> string -> int_num - val mk_int_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> Real.real_expr - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end = struct - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - let int_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntExpr(e) - - let int_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) - - let int_num_of_int_expr e = - match e with IntExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - IntNum(e) - - let int_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_num_of_int_expr (int_expr_of_ptr ctx no) - - let arith_sort_of_int_sort s = match s with IntSort(x) -> x - let arith_expr_of_int_expr e = match e with IntExpr(x) -> x - let int_expr_of_int_num e = match e with IntNum(x) -> x - - let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntSort(s) - - let int_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_sort_of_arith_sort (arith_sort_of_sort (Sort.sort_of_ptr ctx no)) - - let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) - let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) - let sgno ( x : int_sort ) = match (x) with IntSort(s) -> (sgno s) - let egc ( x : int_expr ) = match (x) with IntExpr(e) -> (egc e) - let egnc ( x : int_expr ) = match (x) with IntExpr(e) -> (egnc e) - let egno ( x : int_expr ) = match (x) with IntExpr(e) -> (egno e) - let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) - let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) - let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - + module Integer = + struct let mk_sort ( ctx : context ) = - int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) + sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) - let get_int ( x : int_num ) = - let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + let get_int ( x : expr ) = + let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = - IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) + Expr.mk_const ctx name (mk_sort ctx) let mk_int_const_s ( ctx : context ) ( name : string ) = mk_int_const ctx (Symbol.mk_string ctx name) - let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + let mk_mod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + let mk_rem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) let mk_int_numeral_s ( ctx : context ) ( v : string ) = - int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) let mk_int_numeral_i ( ctx : context ) ( v : int ) = - int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) - let mk_int2real ( ctx : context ) ( t : int_expr ) = - Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) + let mk_int2real ( ctx : context ) ( t : expr ) = + (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (Expr.gno t))) - let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) + let mk_int2bv ( ctx : context ) ( n : int ) ( t : expr ) = + (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (Expr.gno t))) end - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val real_expr_of_ptr : context -> Z3native.ptr -> real_expr - val rat_num_of_ptr : context -> Z3native.ptr -> rat_num - - val arith_sort_of_real_sort : real_sort -> arith_sort - val real_sort_of_arith_sort : arith_sort -> real_sort - val arith_expr_of_real_expr : real_expr -> arith_expr - val real_expr_of_rat_num : rat_num -> real_expr - val real_expr_of_arith_expr : arith_expr -> real_expr - val rat_num_of_real_expr : real_expr -> rat_num - - val mk_sort : context -> real_sort - val get_numerator : rat_num -> Integer.int_num - val get_denominator : rat_num -> Integer.int_num - val to_decimal_string : rat_num -> int -> string - val to_string : rat_num -> string - val mk_real_const : context -> Symbol.symbol -> real_expr - val mk_real_const_s : context -> string -> real_expr - val mk_numeral_nd : context -> int -> int -> rat_num - val mk_numeral_s : context -> string -> rat_num - val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - val mk_real2int : context -> real_expr -> Integer.int_expr - end = struct - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - let arith_sort_of_real_sort s = match s with RealSort(x) -> x - let arith_expr_of_real_expr e = match e with RealExpr(x) -> x - let real_expr_of_rat_num e = match e with RatNum(x) -> x - - let real_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealExpr(e) - - let real_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) - - let rat_num_of_real_expr e = - match e with RealExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - RatNum(e) - - let rat_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - rat_num_of_real_expr (real_expr_of_ptr ctx no) - - let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealSort(s) - - let real_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) - - let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) - let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) - let sgno ( x : real_sort ) = match (x) with RealSort(s) -> (sgno s) - let egc ( x : real_expr ) = match (x) with RealExpr(e) -> (egc e) - let egnc ( x : real_expr ) = match (x) with RealExpr(e) -> (egnc e) - let egno ( x : real_expr ) = match (x) with RealExpr(e) -> (egno e) - let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) - let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) - let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - - + module Real = + struct let mk_sort ( ctx : context ) = - real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) + sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) - let get_numerator ( x : rat_num ) = - Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + let get_numerator ( x : expr ) = + expr_of_ptr (Expr.gc x) (Z3native.get_numerator (Expr.gnc x) (Expr.gno x)) - let get_denominator ( x : rat_num ) = - Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + let get_denominator ( x : expr ) = + expr_of_ptr (Expr.gc x) (Z3native.get_denominator (Expr.gnc x) (Expr.gno x)) - let to_decimal_string ( x : rat_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + let to_decimal_string ( x : expr ) ( precision : int ) = + Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = - RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) + Expr.mk_const ctx name (mk_sort ctx) let mk_real_const_s ( ctx : context ) ( name : string ) = mk_real_const ctx (Symbol.mk_string ctx name) @@ -2012,67 +1506,38 @@ end = struct if (den == 0) then raise (Z3native.Exception "Denominator is zero") else - rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) + expr_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) let mk_numeral_s ( ctx : context ) ( v : string ) = - rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) let mk_numeral_i ( ctx : context ) ( v : int ) = - rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) - let mk_is_integer ( ctx : context ) ( t : real_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) + let mk_is_integer ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (Expr.gno t))) - let mk_real2int ( ctx : context ) ( t : real_expr ) = - Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) + let mk_real2int ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (Expr.gno t))) end - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : algebraic_num -> arith_expr - val algebraic_num_of_arith_expr : arith_expr -> algebraic_num - - val to_upper : algebraic_num -> int -> Real.rat_num - val to_lower : algebraic_num -> int -> Real.rat_num - val to_decimal_string : algebraic_num -> int -> string - val to_string : algebraic_num -> string - end = struct - type algebraic_num = AlgebraicNum of arith_expr - - let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x - - let algebraic_num_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - AlgebraicNum(e) - - let algebraic_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) - - let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) - let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) - let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - - - let to_upper ( x : algebraic_num ) ( precision : int ) = - Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + module AlgebraicNumber = + struct + let to_upper ( x : expr ) ( precision : int ) = + expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_upper (Expr.gnc x) (Expr.gno x) precision) - let to_lower ( x : algebraic_num ) precision = - Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + let to_lower ( x : expr ) precision = + expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_lower (Expr.gnc x) (Expr.gno x) precision) - let to_decimal_string ( x : algebraic_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + let to_decimal_string ( x : expr ) ( precision : int ) = + Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) end let is_int ( x : expr ) = - (Z3native.is_numeral_ast (nc_of_expr x) (nc_of_expr x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == INT_SORT) + (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) @@ -2107,224 +1572,55 @@ end = struct let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == REAL_SORT) + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (nc_of_expr x) (nc_of_expr x) + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) - let mk_add ( ctx : context ) ( t : arith_expr list ) = - let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + let mk_add ( ctx : context ) ( t : expr list ) = + let f x = (Expr.gno x) in + (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_mul ( ctx : context ) ( t : arith_expr list ) = - let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + let mk_mul ( ctx : context ) ( t : expr list ) = + let f x = (Expr.gno x) in + (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_sub ( ctx : context ) ( t : arith_expr list ) = - let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + let mk_sub ( ctx : context ) ( t : expr list ) = + let f x = (Expr.gno x) in + (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) + let mk_unary_minus ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (Expr.gno t))) - let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) + let mk_div ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) + let mk_power ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) + let mk_lt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) + let mk_le ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) + let mk_gt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) + let mk_ge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) end -and BitVector : -sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort - val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort - val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr - val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr - val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr - val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num - - val mk_sort : context -> int -> bitvec_sort - val is_bv : Expr.expr -> bool - val is_bv_numeral : Expr.expr -> bool - val is_bv_bit1 : Expr.expr -> bool - val is_bv_bit0 : Expr.expr -> bool - val is_bv_uminus : Expr.expr -> bool - val is_bv_add : Expr.expr -> bool - val is_bv_sub : Expr.expr -> bool - val is_bv_mul : Expr.expr -> bool - val is_bv_sdiv : Expr.expr -> bool - val is_bv_udiv : Expr.expr -> bool - val is_bv_SRem : Expr.expr -> bool - val is_bv_urem : Expr.expr -> bool - val is_bv_smod : Expr.expr -> bool - val is_bv_sdiv0 : Expr.expr -> bool - val is_bv_udiv0 : Expr.expr -> bool - val is_bv_srem0 : Expr.expr -> bool - val is_bv_urem0 : Expr.expr -> bool - val is_bv_smod0 : Expr.expr -> bool - val is_bv_ule : Expr.expr -> bool - val is_bv_sle : Expr.expr -> bool - val is_bv_uge : Expr.expr -> bool - val is_bv_sge : Expr.expr -> bool - val is_bv_ult : Expr.expr -> bool - val is_bv_slt : Expr.expr -> bool - val is_bv_ugt : Expr.expr -> bool - val is_bv_sgt : Expr.expr -> bool - val is_bv_and : Expr.expr -> bool - val is_bv_or : Expr.expr -> bool - val is_bv_not : Expr.expr -> bool - val is_bv_xor : Expr.expr -> bool - val is_bv_nand : Expr.expr -> bool - val is_bv_nor : Expr.expr -> bool - val is_bv_xnor : Expr.expr -> bool - val is_bv_concat : Expr.expr -> bool - val is_bv_signextension : Expr.expr -> bool - val is_bv_zeroextension : Expr.expr -> bool - val is_bv_extract : Expr.expr -> bool - val is_bv_repeat : Expr.expr -> bool - val is_bv_reduceor : Expr.expr -> bool - val is_bv_reduceand : Expr.expr -> bool - val is_bv_comp : Expr.expr -> bool - val is_bv_shiftleft : Expr.expr -> bool - val is_bv_shiftrightlogical : Expr.expr -> bool - val is_bv_shiftrightarithmetic : Expr.expr -> bool - val is_bv_rotateleft : Expr.expr -> bool - val is_bv_rotateright : Expr.expr -> bool - val is_bv_rotateleftextended : Expr.expr -> bool - val is_bv_rotaterightextended : Expr.expr -> bool - val is_int_to_bv : Expr.expr -> bool - val is_bv_to_int : Expr.expr -> bool - val is_bv_carry : Expr.expr -> bool - val is_bv_xor3 : Expr.expr -> bool - val get_size : bitvec_sort -> int - val get_int : bitvec_num -> int - val to_string : bitvec_num -> string - val mk_const : context -> Symbol.symbol -> int -> bitvec_expr - val mk_const_s : context -> string -> int -> bitvec_expr - val mk_not : context -> bitvec_expr -> Expr.expr - val mk_redand : context -> bitvec_expr -> Expr.expr - val mk_redor : context -> bitvec_expr -> Expr.expr - val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_neg : context -> bitvec_expr -> bitvec_expr - val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr - val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr - val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr - val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr - val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr - val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr - val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr - val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr - val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_numeral : context -> string -> int -> bitvec_num -end = struct - type bitvec_sort = BitVecSort of sort - type bitvec_expr = BitVecExpr of expr - type bitvec_num = BitVecNum of bitvec_expr - - let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x - - let bitvec_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecSort(s) - - let bitvec_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_sort_of_sort (sort_of_ptr ctx no) - - let bitvec_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecExpr(e) - - let bitvec_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_expr_of_expr (expr_of_ptr ctx no) - - let bitvec_num_of_bitvec_expr e = - match e with BitVecExpr(Expr(a)) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecNum(e) - - let bitvec_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_num_of_bitvec_expr (bitvec_expr_of_expr (expr_of_ptr ctx no)) - - let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x - let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x - - - let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) - let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) - let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) - let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (c_of_expr e) - let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (nc_of_expr e) - let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (ptr_of_expr e) - let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) - let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) - let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - - +module BitVector = +struct let mk_sort ( ctx : context ) size = - bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) + sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) let is_bv ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == BV_SORT) + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) @@ -2376,112 +1672,112 @@ end = struct let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) - let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) - let get_int ( x : bitvec_num ) = - let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + let get_size (x : sort ) = Z3native.get_bv_sort_size (Sort.gnc x) (Sort.gno x) + let get_int ( x : expr ) = + let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) + Expr.mk_const ctx name (mk_sort ctx size) let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = mk_const ctx (Symbol.mk_string ctx name) size - let mk_not ( ctx : context ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) - let mk_redand ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) - let mk_redor ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) - let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) - let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) - let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) - let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) - let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) - let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) - let mk_neg ( ctx : context ) ( t : bitvec_expr) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) - let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) - let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) - let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) - let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) - let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) - let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) - let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) - let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) - let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) - let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) - let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) - let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) - let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) - let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) - let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) - let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) - let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) - let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) - let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) - let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) - let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) - let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) - let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) - let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) - let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) - let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) - let mk_ext_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) - let mk_ext_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) - let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = - Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) - let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) - let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) - let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) - let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) - let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) + let mk_not ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (Expr.gno t)) + let mk_redand ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (Expr.gno t)) + let mk_redor ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (Expr.gno t)) + let mk_and ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_or ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_xor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_nand ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_nor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_xnor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_neg ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (Expr.gno t)) + let mk_add ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_sub ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_mul ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_udiv ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_sdiv ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_urem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_srem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_smod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_ult ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_slt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_ule ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sle ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_uge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_ugt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sgt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_concat ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (Expr.gno t)) + let mk_sign_ext ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (Expr.gno t)) + let mk_zero_ext ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (Expr.gno t)) + let mk_repeat ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (Expr.gno t)) + let mk_shl ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_lshr ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_ashr ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_rotate_left ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (Expr.gno t)) + let mk_rotate_right ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (Expr.gno t)) + let mk_ext_rotate_left ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_ext_rotate_right ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_bv2int ( ctx : context ) ( t : expr ) ( signed : bool ) = + expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (Expr.gno t) signed) + let mk_add_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = + (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) + let mk_add_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sub_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sub_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = + (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) + let mk_sdiv_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_neg_no_overflow ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (Expr.gno t))) + let mk_mul_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = + (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) + let mk_mul_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = - bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx size))) end @@ -2556,8 +1852,8 @@ struct let is_garbage ( x : goal ) = (get_precision x) == GOAL_UNDER_OVER - let assert_ ( x : goal ) ( constraints : Boolean.bool_expr list ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in + let assert_ ( x : goal ) ( constraints : expr list ) = + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e) in ignore (List.map f constraints) ; () @@ -2572,7 +1868,7 @@ struct let get_formulas ( x : goal ) = let n = get_size x in - let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) + let f i = ((expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in mk_list f n @@ -2749,7 +2045,7 @@ struct exception ModelEvaluationFailedException of string let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (ptr_of_expr t) completion) in + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in if not r then raise (ModelEvaluationFailedException "evaluation failed") else @@ -3076,19 +2372,19 @@ struct let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - let assert_ ( x : solver ) ( constraints : Boolean.bool_expr list ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in + let assert_ ( x : solver ) ( constraints : expr list ) = + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in ignore (List.map f constraints) - let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr list ) ( ps : Boolean.bool_expr list ) = + let assert_and_track_a ( x : solver ) ( cs : expr list ) ( ps : expr list ) = if ((List.length cs) != (List.length ps)) then raise (Z3native.Exception "Argument size mismatch") else - let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno a) (Boolean.gno b)) in + let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Expr.gno a) (Expr.gno b)) in ignore (List.iter2 f cs ps) - let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) + let assert_and_track ( x : solver ) ( c : expr ) ( p : expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Expr.gno c) (Expr.gno p) let get_num_assertions ( x : solver ) = let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in @@ -3097,15 +2393,15 @@ struct let get_assertions ( x : solver ) = let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in + let f i = (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in mk_list f n - let check ( x : solver ) ( assumptions : Boolean.bool_expr list ) = + let check ( x : solver ) ( assumptions : expr list ) = let r = if ((List.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - let f x = (ptr_of_expr (Boolean.expr_of_bool_expr x)) in + let f x = (Expr.gno x) in lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) in match r with @@ -3179,24 +2475,24 @@ struct let get_param_descrs ( x : fixedpoint ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr list ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in + let assert_ ( x : fixedpoint ) ( constraints : expr list ) = + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in ignore (List.map f constraints) ; () let register_relation ( x : fixedpoint ) ( f : func_decl ) = Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) - let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : expr ) ( name : Symbol.symbol option ) = match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) (Symbol.gno y) let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) - let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with + let query ( x : fixedpoint ) ( query : expr ) = + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Expr.gno query))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -3214,8 +2510,8 @@ struct let pop ( x : fixedpoint ) = Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) - let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) + let update_rule ( x : fixedpoint ) ( rule : expr ) ( name : Symbol.symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) (Symbol.gno name) let get_answer ( x : fixedpoint ) = let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in @@ -3238,27 +2534,27 @@ struct Some (expr_of_ptr (z3obj_gc x) q) let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (ptr_of_expr property) + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) - let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr list ) = - let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in + let to_string_q ( x : fixedpoint ) ( queries : expr list ) = + let f x = Expr.gno x in Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) let get_rules ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in mk_list f n let get_assertions ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in mk_list f n let mk_fixedpoint ( ctx : context ) = create ctx @@ -3287,10 +2583,10 @@ end module SMT = struct - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr list ) ( formula : Boolean.bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : expr list ) ( formula : expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (List.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.of_list (List.map f assumptions))) - (Boolean.gno formula) + (List.length assumptions) (let f x = Expr.gno (x) in (Array.of_list (List.map f assumptions))) + (Expr.gno formula) let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = let csn = (List.length sort_names) in @@ -3328,14 +2624,14 @@ struct let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in + let f i =(expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in mk_list f n let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in + let f i = (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in mk_list f n let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) @@ -3360,14 +2656,14 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) - + (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = let csn = (List.length sort_names) in let cs = (List.length sorts) in @@ -3376,13 +2672,13 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) + (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) end diff --git a/src/api/ml/z3_rich.ml b/src/api/ml/z3_rich.ml new file mode 100644 index 000000000..052ca5e22 --- /dev/null +++ b/src/api/ml/z3_rich.ml @@ -0,0 +1,3400 @@ +(** + The Z3 ML/Ocaml Interface. + + Copyright (C) 2012 Microsoft Corporation + @author CM Wintersteiger (cwinter) 2012-12-17 +*) + +open Z3enums + +(* Some helpers. *) +let null = Z3native.mk_null() +let is_null o = (Z3native.is_null o) + + +(* Internal types *) +type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } +type context = z3_native_context + +type z3_native_object = { + m_ctx : context ; + mutable m_n_obj : Z3native.ptr ; + inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; + dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } + + +(** Internal stuff *) +module Internal = +struct + let dispose_context ctx = + if ctx.m_n_obj_cnt == 0 then ( + (Z3native.del_context ctx.m_n_ctx) + ) else ( + Printf.printf "ERROR: NOT DISPOSING CONTEXT (because it still has %d objects alive)\n" ctx.m_n_obj_cnt; + ) + + let create_context settings = + let cfg = Z3native.mk_config in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = Z3native.mk_context_rc cfg in + Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + Z3native.set_internal_error_handler v ; + let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in + let f = fun o -> dispose_context o in + Gc.finalise f res; + res + + let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) + let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) + let context_gno ctx = ctx.m_n_ctx + + + let z3obj_gc o = o.m_ctx + let z3obj_gnc o = (context_gno o.m_ctx) + + let z3obj_gno o = o.m_n_obj + let z3obj_sno o ctx no = + (context_add1 ctx) ; + o.inc_ref (context_gno ctx) no ; + ( + if not (is_null o.m_n_obj) then + o.dec_ref (context_gno ctx) o.m_n_obj ; + (context_sub1 ctx) + ) ; + o.m_n_obj <- no + + let z3obj_dispose o = + if not (is_null o.m_n_obj) then + ( + o.dec_ref (z3obj_gnc o) o.m_n_obj ; + (context_sub1 (z3obj_gc o)) + ) ; + o.m_n_obj <- null + + let z3obj_create o = + let f = fun o -> (z3obj_dispose o) in + Gc.finalise f o + + let z3obj_nil_ref x y = () + + let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> + let res : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res +end + +open Internal + +module Log = +struct + let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) + let close = Z3native.close_log + let append s = Z3native.append_log s +end + + +module Version = +struct + let major = let (x, _, _, _) = Z3native.get_version in x + let minor = let (_, x, _, _) = Z3native.get_version in x + let build = let (_, _, x, _) = Z3native.get_version in x + let revision = let (_, _, _, x) = Z3native.get_version in x + let to_string = + let (mj, mn, bld, rev) = Z3native.get_version in + string_of_int mj ^ "." ^ + string_of_int mn ^ "." ^ + string_of_int bld ^ "." ^ + string_of_int rev ^ "." +end + + +let mk_list ( f : int -> 'a ) ( n : int ) = + let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = + if (i >= n) then + tail + else + (mk_list' f (i+1) n ((f i) :: tail)) + in + mk_list' f 0 n [] + +let list_of_array ( x : _ array ) = + let f i = (Array.get x i) in + mk_list f (Array.length x) + +let mk_context ( cfg : ( string * string ) list ) = + create_context cfg + + +module Symbol = +struct + (* Symbol types *) + type int_symbol = z3_native_object + type string_symbol = z3_native_object + + type symbol = + | S_Int of int_symbol + | S_Str of string_symbol + + + let create_i ( ctx : context ) ( no : Z3native.ptr ) = + let res : int_symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let create_s ( ctx : context ) ( no : Z3native.ptr ) = + let res : string_symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let create ( ctx : context ) ( no : Z3native.ptr ) = + match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with + | INT_SYMBOL -> S_Int (create_i ctx no) + | STRING_SYMBOL -> S_Str (create_s ctx no) + + let gc ( x : symbol ) = + match x with + | S_Int(n) -> (z3obj_gc n) + | S_Str(n) -> (z3obj_gc n) + + let gnc ( x : symbol ) = + match x with + | S_Int(n) -> (z3obj_gnc n) + | S_Str(n) -> (z3obj_gnc n) + + let gno ( x : symbol ) = + match x with + | S_Int(n) -> (z3obj_gno n) + | S_Str(n) -> (z3obj_gno n) + + let symbol_lton ( a : symbol list ) = + let f ( e : symbol ) = (gno e) in + Array.of_list (List.map f a) + + let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) + let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL + let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL + let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) + let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) + let to_string ( o : symbol ) = + match (kind o) with + | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) + | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) + + let mk_int ( ctx : context ) ( i : int ) = + S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) + + let mk_string ( ctx : context ) ( s : string ) = + S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) + + let mk_ints ( ctx : context ) ( names : int list ) = + let f elem = mk_int ( ctx : context ) elem in + (List.map f names) + + let mk_strings ( ctx : context ) ( names : string list ) = + let f elem = mk_string ( ctx : context ) elem in + (List.map f names) +end + + +module AST = +struct + type ast = z3_native_object + + let context_of_ast ( x : ast ) = (z3obj_gc x) + let nc_of_ast ( x : ast ) = (z3obj_gnc x) + let ptr_of_ast ( x : ast ) = (z3obj_gno x) + + let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with + | FUNC_DECL_AST + | SORT_AST + | QUANTIFIER_AST + | APP_AST + | NUMERAL_AST + | VAR_AST -> z3_native_object_of_ast_ptr ctx no + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") + + module ASTVector = + struct + type ast_vector = z3_native_object + + let ast_vector_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_vector = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_vector_inc_ref ; + dec_ref = Z3native.ast_vector_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let get_size ( x : ast_vector ) = + Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) + + let get ( x : ast_vector ) ( i : int ) = + ast_of_ptr (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) + + let set ( x : ast_vector ) ( i : int ) ( value : ast ) = + Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) + + let resize ( x : ast_vector ) ( new_size : int ) = + Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size + + let push ( x : ast_vector ) ( a : ast ) = + Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) + + let translate ( x : ast_vector ) ( to_ctx : context ) = + ast_vector_of_ptr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + + let to_string ( x : ast_vector ) = + Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) + end + + module ASTMap = + struct + type ast_map = z3_native_object + + let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_map = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_map_inc_ref ; + dec_ref = Z3native.ast_map_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let contains ( x : ast_map ) ( key : ast ) = + Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) + + let find ( x : ast_map ) ( key : ast ) = + ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) + + let insert ( x : ast_map ) ( key : ast ) ( value : ast) = + Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) + + let erase ( x : ast_map ) ( key : ast ) = + Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) + + let reset ( x : ast_map ) = + Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) + + let get_size ( x : ast_map ) = + Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) + + let get_keys ( x : ast_map ) = + let av = ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in + let f i = (ASTVector.get av i) in + mk_list f (ASTVector.get_size av) + + let to_string ( x : ast_map ) = + Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) + end + + let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) + let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) + let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) + + let is_expr ( x : ast ) = + match get_ast_kind ( x : ast ) with + | APP_AST + | NUMERAL_AST + | QUANTIFIER_AST + | VAR_AST -> true + | _ -> false + + let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST + let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST + let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST + let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST + + let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) + let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) + + + let ( = ) ( a : ast ) ( b : ast ) = (a == b) || + if (z3obj_gnc a) != (z3obj_gnc b) then + false + else + Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) + + let compare a b = + if (get_id a) < (get_id b) then -1 else + if (get_id a) > (get_id b) then 1 else + 0 + + let ( < ) (a : ast) (b : ast) = (compare a b) + + let translate ( x : ast ) ( to_ctx : context ) = + if (z3obj_gnc x) == (context_gno to_ctx) then + x + else + ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + + let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr + let unwrap_ast ( x : ast ) = (z3obj_gno x) +end + +open AST + + +module Sort = +struct + type sort = Sort of AST.ast + type uninterpreted_sort = UninterpretedSort of sort + + let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> + let q = (z3_native_object_of_ast_ptr ctx no) in + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then + raise (Z3native.Exception "Invalid coercion") + else + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with + | ARRAY_SORT + | BOOL_SORT + | BV_SORT + | DATATYPE_SORT + | INT_SORT + | REAL_SORT + | UNINTERPRETED_SORT + | FINITE_DOMAIN_SORT + | RELATION_SORT -> Sort(q) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + + let ast_of_sort s = match s with Sort(x) -> x + let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x + + let uninterpreted_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + UninterpretedSort(s) + + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) + let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) + let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) + + let sort_lton ( a : sort list ) = + let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in + Array.of_list (List.map f a) + + let ( = ) : sort -> sort -> bool = fun a b -> + (a == b) || + if (gnc a) != (gnc b) then + false + else + (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) + + + let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) + let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) + let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) + let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) + + let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; + (z3obj_create res) ; + UninterpretedSort(Sort(res)) + + let mk_uninterpreted_s ( ctx : context ) ( s : string ) = + mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) +end + +open Sort + + +module rec FuncDecl : +sig + type func_decl = FuncDecl of AST.ast + val ast_of_func_decl : FuncDecl.func_decl -> AST.ast + val func_decl_of_ptr : context -> Z3native.ptr -> func_decl + val gc : func_decl -> context + val gnc : func_decl -> Z3native.ptr + val gno : func_decl -> Z3native.ptr + module Parameter : + sig + type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + val get_kind : parameter -> Z3enums.parameter_kind + val get_int : parameter -> int + val get_float : parameter -> float + val get_symbol : parameter -> Symbol.symbol + val get_sort : parameter -> Sort.sort + val get_ast : parameter -> AST.ast + val get_func_decl : parameter -> func_decl + val get_rational : parameter -> string + end + val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl + val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl + val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl + val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl + val mk_const_decl_s : context -> string -> Sort.sort -> func_decl + val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl + val ( = ) : func_decl -> func_decl -> bool + val to_string : func_decl -> string + val get_id : func_decl -> int + val get_arity : func_decl -> int + val get_domain_size : func_decl -> int + val get_domain : func_decl -> Sort.sort list + val get_range : func_decl -> Sort.sort + val get_decl_kind : func_decl -> Z3enums.decl_kind + val get_name : func_decl -> Symbol.symbol + val get_num_parameters : func_decl -> int + val get_parameters : func_decl -> Parameter.parameter list + val apply : func_decl -> Expr.expr list -> Expr.expr +end = struct + type func_decl = FuncDecl of AST.ast + + let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + FuncDecl(z3_native_object_of_ast_ptr ctx no) + + let ast_of_func_decl f = match f with FuncDecl(x) -> x + + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (List.length domain) (sort_lton domain) (Sort.gno range))) ; + (z3obj_create res) ; + FuncDecl(res) + + let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort list ) ( range : sort ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (List.length domain) (sort_lton domain) (Sort.gno range))) ; + (z3obj_create res) ; + FuncDecl(res) + + let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) + let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) + let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) + + module Parameter = + struct + type parameter = + | P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + let get_kind ( x : parameter ) = + (match x with + | P_Int(_) -> PARAMETER_INT + | P_Dbl(_) -> PARAMETER_DOUBLE + | P_Sym(_) -> PARAMETER_SYMBOL + | P_Srt(_) -> PARAMETER_SORT + | P_Ast(_) -> PARAMETER_AST + | P_Fdl(_) -> PARAMETER_FUNC_DECL + | P_Rat(_) -> PARAMETER_RATIONAL) + + let get_int ( x : parameter ) = + match x with + | P_Int(x) -> x + | _ -> raise (Z3native.Exception "parameter is not an int") + + let get_float ( x : parameter ) = + match x with + | P_Dbl(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a double") + + let get_symbol ( x : parameter ) = + match x with + | P_Sym(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a symbol") + + let get_sort ( x : parameter ) = + match x with + | P_Srt(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a sort") + + let get_ast ( x : parameter ) = + match x with + | P_Ast(x) -> x + | _ -> raise (Z3native.Exception "parameter is not an ast") + + let get_func_decl ( x : parameter ) = + match x with + | P_Fdl(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a func_decl") + + let get_rational ( x : parameter ) = + match x with + | P_Rat(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a rational string") + end + + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = + create_ndr ctx name domain range + + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort list ) ( range : sort ) = + mk_func_decl ctx (Symbol.mk_string ctx name) domain range + + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort list ) ( range : sort ) = + create_pdr ctx prefix domain range + + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + create_ndr ctx name [] range + + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = + create_ndr ctx (Symbol.mk_string ctx name) [] range + + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = + create_pdr ctx prefix [] range + + + let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || + if (gnc a) != (gnc b) then + false + else + (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) + + let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) + + let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) + + let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) + + let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) + + let get_domain ( x : func_decl ) = + let n = (get_domain_size x) in + let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in + mk_list f n + + let get_range ( x : func_decl ) = + sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) + + let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) + + let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) + + let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) + + let get_parameters ( x : func_decl ) = + let n = (get_num_parameters x) in + let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with + | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> Parameter.P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> Parameter.P_Ast (AST.ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + ) in + mk_list f n + + let apply ( x : func_decl ) ( args : Expr.expr list ) = Expr.expr_of_func_app (gc x) x args +end + + +and Params : +sig + type params = z3_native_object + module ParamDescrs : + sig + type param_descrs + val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs + val validate : param_descrs -> params -> unit + val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind + val get_names : param_descrs -> Symbol.symbol list + val get_size : param_descrs -> int + val to_string : param_descrs -> string + end + val add_bool : params -> Symbol.symbol -> bool -> unit + val add_int : params -> Symbol.symbol -> int -> unit + val add_double : params -> Symbol.symbol -> float -> unit + val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit + val add_s_bool : params -> string -> bool -> unit + val add_s_int : params -> string -> int -> unit + val add_s_double : params -> string -> float -> unit + val add_s_symbol : params -> string -> Symbol.symbol -> unit + val mk_params : context -> params + val to_string : params -> string +end = struct + type params = z3_native_object + + module ParamDescrs = + struct + type param_descrs = z3_native_object + + let param_descrs_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let res : param_descrs = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.param_descrs_inc_ref ; + dec_ref = Z3native.param_descrs_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let validate ( x : param_descrs ) ( p : params ) = + Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) + + let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) + + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in + let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) + end + + let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = + Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value + + let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = + Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value + + let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = + Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value + + let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = + Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) + + let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = + add_bool x (Symbol.mk_string (z3obj_gc x) name) value + + let add_s_int ( x : params) ( name : string ) ( value : int ) = + add_int x (Symbol.mk_string (z3obj_gc x) name) value + + let add_s_double ( x : params ) ( name : string ) ( value : float ) = + add_double x (Symbol.mk_string (z3obj_gc x) name) value + + let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = + add_symbol x (Symbol.mk_string (z3obj_gc x) name) value + + let mk_params ( ctx : context ) = + let res : params = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.params_inc_ref ; + dec_ref = Z3native.params_dec_ref } in + (z3obj_sno res ctx (Z3native.mk_params (context_gno ctx))) ; + (z3obj_create res) ; + res + + let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) +end + +(** General expressions (terms) *) +and Expr : +sig + type expr = Expr of AST.ast + val expr_of_ptr : context -> Z3native.ptr -> expr + val gc : expr -> context + val gnc : expr -> Z3native.ptr + val gno : expr -> Z3native.ptr + val expr_lton : expr list -> Z3native.ptr array + val ast_of_expr : expr -> AST.ast + val expr_of_ast : AST.ast -> expr + val expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr + val simplify : expr -> Params.params option -> expr + val get_simplify_help : context -> string + val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs + val get_func_decl : expr -> FuncDecl.func_decl + val get_bool_value : expr -> Z3enums.lbool + val get_num_args : expr -> int + val get_args : expr -> expr list + val update : expr -> expr list -> expr + val substitute : expr -> expr list -> expr list -> expr + val substitute_one : expr -> expr -> expr -> expr + val substitute_vars : expr -> expr list -> expr + val translate : expr -> context -> expr + val to_string : expr -> string + val is_numeral : expr -> bool + val is_well_sorted : expr -> bool + val get_sort : expr -> Sort.sort + val is_bool : expr -> bool + val is_const : expr -> bool + val is_true : expr -> bool + val is_false : expr -> bool + val is_eq : expr -> bool + val is_distinct : expr -> bool + val is_ite : expr -> bool + val is_and : expr -> bool + val is_or : expr -> bool + val is_iff : expr -> bool + val is_xor : expr -> bool + val is_not : expr -> bool + val is_implies : expr -> bool + val is_label : expr -> bool + val is_label_lit : expr -> bool + val is_oeq : expr -> bool + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + val mk_const_s : context -> string -> Sort.sort -> expr + val mk_const_f : context -> FuncDecl.func_decl -> expr + val mk_fresh_const : context -> string -> Sort.sort -> expr + val mk_app : context -> FuncDecl.func_decl -> expr list -> expr + val mk_numeral_string : context -> string -> Sort.sort -> expr + val mk_numeral_int : context -> int -> Sort.sort -> expr +end = struct + type expr = Expr of AST.ast + + let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) + let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) + let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) + + let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then + Expr(z3_native_object_of_ast_ptr ctx no) + else + let s = Z3native.get_sort (context_gno ctx) no in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) no) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + if (Z3native.is_numeral_ast (context_gno ctx) no) then + if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + raise (Z3native.Exception "Unsupported numeral object") + else + Expr(z3_native_object_of_ast_ptr ctx no) + + let expr_of_ast a = + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Expr(a) + + let ast_of_expr e = match e with Expr(a) -> a + + let expr_lton ( a : expr list ) = + let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in + Array.of_list (List.map f a) + + let expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr = fun ctx f args -> + match f with FuncDecl.FuncDecl(fa) -> + let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (List.length args) (expr_lton args) in + expr_of_ptr ctx o + + let simplify ( x : expr ) ( p : Params.params option ) = match p with + | None -> expr_of_ptr (Expr.gc x) (Z3native.simplify (Expr.gnc x) (Expr.gno x)) + | Some pp -> expr_of_ptr (Expr.gc x) (Z3native.simplify_ex (Expr.gnc x) (Expr.gno x) (z3obj_gno pp)) + + let get_simplify_help ( ctx : context ) = + Z3native.simplify_get_help (context_gno ctx) + + let get_simplify_parameter_descrs ( ctx : context ) = + Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) + let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (Expr.gnc x) (Expr.gno x)) + + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (Expr.gnc x) (Expr.gno x)) + + let get_num_args ( x : expr ) = Z3native.get_app_num_args (Expr.gnc x) (Expr.gno x) + + let get_args ( x : expr ) = let n = (get_num_args x) in + let f i = expr_of_ptr (Expr.gc x) (Z3native.get_app_arg (Expr.gnc x) (Expr.gno x) i) in + mk_list f n + + let update ( x : expr ) ( args : expr list ) = + if (List.length args <> (get_num_args x)) then + raise (Z3native.Exception "Number of arguments does not match") + else + expr_of_ptr (Expr.gc x) (Z3native.update_term (Expr.gnc x) (Expr.gno x) (List.length args) (expr_lton args)) + + let substitute ( x : expr ) from to_ = + if (List.length from) <> (List.length to_) then + raise (Z3native.Exception "Argument sizes do not match") + else + expr_of_ptr (Expr.gc x) (Z3native.substitute (Expr.gnc x) (Expr.gno x) (List.length from) (expr_lton from) (expr_lton to_)) + + let substitute_one ( x : expr ) from to_ = + substitute ( x : expr ) [ from ] [ to_ ] + + let substitute_vars ( x : expr ) to_ = + expr_of_ptr (Expr.gc x) (Z3native.substitute_vars (Expr.gnc x) (Expr.gno x) (List.length to_) (expr_lton to_)) + + let translate ( x : expr ) to_ctx = + if (Expr.gc x) == to_ctx then + x + else + expr_of_ptr to_ctx (Z3native.translate (Expr.gnc x) (Expr.gno x) (context_gno to_ctx)) + + let to_string ( x : expr ) = Z3native.ast_to_string (Expr.gnc x) (Expr.gno x) + + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) + + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (Expr.gnc x) (Expr.gno x) + + let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)) + + let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + (Z3native.is_eq_sort (Expr.gnc x) + (Z3native.mk_bool_sort (Expr.gnc x)) + (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) + + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + (get_num_args x) == 0 && + (FuncDecl.get_domain_size (get_func_decl x)) == 0 + + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) + let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) + let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) + let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) + let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) + let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) + let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) + let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) + let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) + let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) + let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) + let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) + let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) + + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) + + let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = + mk_const ctx (Symbol.mk_string ctx name) range + + let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [] + + let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = + expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) + + let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr list ) = expr_of_func_app ctx f args + + let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) + + let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) +end + +open FuncDecl +open Expr + +module Boolean = +struct + type bool_sort = BoolSort of Sort.sort + type bool_expr = BoolExpr of Expr.expr + + let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let a = (AST.ast_of_ptr ctx no) in + BoolExpr(Expr.Expr(a)) + + let bool_expr_of_expr e = + match e with Expr.Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolExpr(e) + + let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + BoolSort(sort_of_ptr ctx no) + + let sort_of_bool_sort s = match s with BoolSort(x) -> x + + let bool_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolSort(s) + + let expr_of_bool_expr e = match e with BoolExpr(x) -> x + + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.c_of_expr e) + let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.nc_of_expr e) + let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.ptr_of_expr e) + + let mk_sort ( ctx : context ) = + BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) + + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = + let s = (match (mk_sort ctx) with BoolSort(q) -> q) in + BoolExpr(Expr.mk_const ctx name s) + + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) + + let mk_true ( ctx : context ) = + bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) + + let mk_false ( ctx : context ) = + bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) + + let mk_val ( ctx : context ) ( value : bool ) = + if value then mk_true ctx else mk_false ctx + + let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = + bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + + let mk_distinct ( ctx : context ) ( args : expr list ) = + bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) + + let mk_not ( ctx : context ) ( a : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) + + let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + + let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + + let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + + let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + + let mk_and ( ctx : context ) ( args : bool_expr list ) = + let f x = (Expr.gno (expr_of_bool_expr x)) in + bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) + + let mk_or ( ctx : context ) ( args : bool_expr list ) = + let f x = (Expr.gno (expr_of_bool_expr x)) in + bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) +end + + +module Quantifier = +struct + type quantifier = Quantifier of expr + + let expr_of_quantifier e = match e with Quantifier(x) -> x + + let quantifier_of_expr e = + match e with Expr.Expr(a) -> + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.QUANTIFIER_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Quantifier(e) + + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) + let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) + let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) + + module Pattern = + struct + type pattern = Pattern of ast + + let ast_of_pattern e = match e with Pattern(x) -> x + + let pattern_of_ast a = + (* CMW: Unchecked ok? *) + Pattern(a) + + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) + let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) + let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) + + let get_num_terms ( x : pattern ) = + Z3native.get_pattern_num_terms (gnc x) (gno x) + + let get_terms ( x : pattern ) = + let n = (get_num_terms x) in + let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in + mk_list f n + + let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) + end + + let get_index ( x : expr ) = + if not (AST.is_var (match x with Expr.Expr(a) -> a)) then + raise (Z3native.Exception "Term is not a bound variable.") + else + Z3native.get_index_value (Expr.gnc x) (Expr.gno x) + + let is_universal ( x : quantifier ) = + Z3native.is_quantifier_forall (gnc x) (gno x) + + let is_existential ( x : quantifier ) = not (is_universal x) + + let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) + + let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) + + let get_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in + mk_list f n + + let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) + + let get_no_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in + mk_list f n + + let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) + + let get_bound_variable_names ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in + mk_list f n + + let get_bound_variable_sorts ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in + mk_list f n + + let get_body ( x : quantifier ) = + Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) + + let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) + + let mk_pattern ( ctx : context ) ( terms : expr list ) = + if (List.length terms) == 0 then + raise (Z3native.Exception "Cannot create a pattern from zero terms") + else + Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (List.length terms) (expr_lton terms))) + + let mk_forall ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (List.length sorts) != (List.length names) then + raise (Z3native.Exception "Number of sorts does not match number of names") + else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) + (Expr.gno body))) + else + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) + (Expr.gno body))) + + let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (Expr.gno body))) + else + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (Expr.gno body))) + + let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (List.length sorts) != (List.length names) then + raise (Z3native.Exception "Number of sorts does not match number of names") + else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) + (Expr.gno body))) + else + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) + (Expr.gno body))) + + let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (Expr.gno body))) + else + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (Expr.gno body))) + + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (universal) then + (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) + else + (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) + + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (universal) then + mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id + else + mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id +end + + +module Array_ = +struct + type array_sort = ArraySort of sort + type array_expr = ArrayExpr of expr + + let array_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let e = (expr_of_ptr ctx no) in + ArrayExpr(e) + + let array_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + ArraySort(s) + + let sort_of_array_sort s = match s with ArraySort(x) -> x + + let array_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArraySort(s) + + let array_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArrayExpr(e) + + let expr_of_array_expr e = match e with ArrayExpr(x) -> x + + let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gno s) + + let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gc e) + let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) + let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) + + let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = + array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) + + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) + let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) + let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) + let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) + let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + let is_array ( x : expr ) = + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) + + let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) + let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) + + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = + ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) + + let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = + mk_const ctx (Symbol.mk_string ctx name) domain range + + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = + array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (Expr.gno i)) + + let mk_store ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = + array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (Expr.gno i) (Expr.gno v)) + + let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = + array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) + + let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr list ) = + let m x = (Expr.gno (expr_of_array_expr x)) in + array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) + + let mk_term_array ( ctx : context ) ( arg : array_expr ) = + array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) +end + + +module Set = +struct + type set_sort = SetSort of sort + + let set_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + SetSort(s) + + let sort_of_set_sort s = match s with SetSort(x) -> x + + let mk_sort ( ctx : context ) ( ty : sort ) = + set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) + + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + + + let mk_empty ( ctx : context ) ( domain : sort ) = + (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) + + let mk_full ( ctx : context ) ( domain : sort ) = + expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) + + let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = + expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) + + let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = + expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) + + let mk_union ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) + + let mk_intersection ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) + + let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = + expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) + + let mk_complement ( ctx : context ) ( arg : expr ) = + expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) + + let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = + expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) + + let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = + expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) + +end + + +module FiniteDomain = +struct + type finite_domain_sort = FiniteDomainSort of sort + + let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x + + let finite_domain_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + FiniteDomainSort(s) + + let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) + let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) + let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in + FiniteDomainSort(s) + + let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = + mk_sort ctx (Symbol.mk_string ctx name) size + + + let is_finite_domain ( x : expr ) = + let nc = (Expr.gnc x) in + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) + + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + + let get_size ( x : finite_domain_sort ) = + let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in + if r then v + else raise (Z3native.Exception "Conversion failed.") +end + + +module Relation = +struct + type relation_sort = RelationSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + RelationSort(s) + + let sort_of_relation_sort s = match s with RelationSort(x) -> x + + let relation_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RelationSort(s) + + let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) + let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) + let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) + + + let is_relation ( x : expr ) = + let nc = (Expr.gnc x) in + ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) + + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) + let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) + let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) + let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) + let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + + let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) + + let get_column_sorts ( x : relation_sort ) = + let n = get_arity x in + let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in + mk_list f n + +end + + +module Datatype = +struct + type datatype_sort = DatatypeSort of sort + type datatype_expr = DatatypeExpr of expr + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + DatatypeSort(s) + + let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x + + let datatype_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeSort(s) + + let datatype_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeExpr(e) + + let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x + + let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) + + module Constructor = + struct + type constructor = z3_native_object + + let _sizes = Hashtbl.create 0 + + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let n = (List.length field_names) in + if n != (List.length sorts) then + raise (Z3native.Exception "Number of field names does not match number of sorts") + else + if n != (List.length sort_refs) then + raise (Z3native.Exception "Number of field names does not match number of sort refs") + else + let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) + (Symbol.gno recognizer) + n + (Symbol.symbol_lton field_names) + (sort_lton sorts) + (Array.of_list sort_refs)) in + let no : constructor = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + (z3obj_sno no ctx ptr) ; + (z3obj_create no) ; + let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in + Gc.finalise f no ; + Hashtbl.add _sizes no n ; + no + + let get_num_fields ( x : constructor ) = Hashtbl.find _sizes x + + let get_constructor_decl ( x : constructor ) = + let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in + func_decl_of_ptr (z3obj_gc x) a + + let get_tester_decl ( x : constructor ) = + let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in + func_decl_of_ptr (z3obj_gc x) b + + let get_accessor_decls ( x : constructor ) = + let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in + let f i = func_decl_of_ptr (z3obj_gc x) (Array.get c i) in + mk_list f (Array.length c) + + end + + module ConstructorList = + struct + type constructor_list = z3_native_object + + let create ( ctx : context ) ( c : Constructor.constructor list ) = + let res : constructor_list = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + let f x =(z3obj_gno x) in + (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (List.length c) (Array.of_list (List.map f c)))) ; + (z3obj_create res) ; + let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in + Gc.finalise f res; + res + end + + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + Constructor.create ctx name recognizer field_names sorts sort_refs + + + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = + let f x = (z3obj_gno x) in + let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (List.length constructors) (Array.of_list (List.map f constructors))) in + sort_of_ptr ctx x + + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor list ) = + mk_sort ctx (Symbol.mk_string ctx name) constructors + + let mk_sorts ( ctx : context ) ( names : Symbol.symbol list ) ( c : Constructor.constructor list list ) = + let n = (List.length names) in + let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in + let cla = (Array.of_list (List.map f c)) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.symbol_lton names) cla) in + let g i = (sort_of_ptr ctx (Array.get r i)) in + mk_list g (Array.length r) + + let mk_sorts_s ( ctx : context ) ( names : string list ) ( c : Constructor.constructor list list ) = + mk_sorts ctx + ( + let f e = (Symbol.mk_string ctx e) in + List.map f names + ) + c + + let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) + + let get_constructors ( x : datatype_sort ) = + let n = (get_num_constructors x) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + mk_list f n + + let get_recognizers ( x : datatype_sort ) = + let n = (get_num_constructors x) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in + mk_list f n + + let get_accessors ( x : datatype_sort ) = + let n = (get_num_constructors x) in + let f i = ( + let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in + let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in + mk_list g ds + ) in + mk_list f n +end + + +module Enumeration = +struct + type enum_sort = EnumSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl list ) ( tdecls : Z3native.z3_func_decl list ) = + let s = (sort_of_ptr ctx no) in + let res = EnumSort(s) in + res + + let sort_of_enum_sort s = match s with EnumSort(x) -> x + + let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = + let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in + sort_of_ptr ctx a (list_of_array b) (list_of_array c) + + let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = + mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) + + let get_const_decls ( x : enum_sort ) = + let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in + let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in + mk_list f n + + let get_tester_decls ( x : enum_sort ) = + let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in + let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in + mk_list f n + +end + + +module List_ = +struct + type list_sort = ListSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + let res = ListSort(s) in + res + + let sort_of_list_sort s = match s with ListSort(x) -> x + + let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in + sort_of_ptr ctx r a b c d e f + + let mk_list_s ( ctx : context ) (name : string) elem_sort = + mk_sort ctx (Symbol.mk_string ctx name) elem_sort + + let get_nil_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) + + let get_is_nil_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) + + let get_cons_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) + + let get_is_cons_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) + + let get_head_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) + + let get_tail_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) + + let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [] +end + + +module Tuple = +struct + type tuple_sort = TupleSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + TupleSort(s) + + let sort_of_tuple_sort s = match s with TupleSort(x) -> x + + let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = + let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in + sort_of_ptr ctx r + + let get_mk_decl ( x : tuple_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) + + let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) + + let get_field_decls ( x : tuple_sort ) = + let n = get_num_fields x in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in + mk_list f n +end + + +module rec Arithmetic : +sig + type arith_sort = ArithSort of Sort.sort + type arith_expr = ArithExpr of Expr.expr + + val sort_of_arith_sort : arith_sort -> Sort.sort + val arith_sort_of_sort : Sort.sort -> arith_sort + val expr_of_arith_expr : arith_expr -> Expr.expr + val arith_expr_of_expr : Expr.expr -> arith_expr + + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val int_expr_of_ptr : context -> Z3native.ptr -> int_expr + val int_num_of_ptr : context -> Z3native.ptr -> int_num + + val arith_sort_of_int_sort : Integer.int_sort -> arith_sort + val int_sort_of_arith_sort : arith_sort -> int_sort + val arith_expr_of_int_expr : int_expr -> arith_expr + val int_expr_of_int_num : int_num -> int_expr + val int_expr_of_arith_expr : arith_expr -> int_expr + val int_num_of_int_expr : int_expr -> int_num + + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val real_expr_of_ptr : context -> Z3native.ptr -> real_expr + val rat_num_of_ptr : context -> Z3native.ptr -> rat_num + + val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort + val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort + val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr + val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr + val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr + val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num + + val mk_sort : context -> real_sort + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr + end + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : algebraic_num -> arith_expr + val algebraic_num_of_arith_expr : arith_expr -> algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end + + val is_int : Expr.expr -> bool + val is_arithmetic_numeral : Expr.expr -> bool + val is_le : Expr.expr -> bool + val is_ge : Expr.expr -> bool + val is_lt : Expr.expr -> bool + val is_gt : Expr.expr -> bool + val is_add : Expr.expr -> bool + val is_sub : Expr.expr -> bool + val is_uminus : Expr.expr -> bool + val is_mul : Expr.expr -> bool + val is_div : Expr.expr -> bool + val is_idiv : Expr.expr -> bool + val is_remainder : Expr.expr -> bool + val is_modulus : Expr.expr -> bool + val is_inttoreal : Expr.expr -> bool + val is_real_to_int : Expr.expr -> bool + val is_real_is_int : Expr.expr -> bool + val is_real : Expr.expr -> bool + val is_int_numeral : Expr.expr -> bool + val is_rat_num : Expr.expr -> bool + val is_algebraic_number : Expr.expr -> bool + val mk_add : context -> arith_expr list -> arith_expr + val mk_mul : context -> arith_expr list -> arith_expr + val mk_sub : context -> arith_expr list -> arith_expr + val mk_unary_minus : context -> arith_expr -> arith_expr + val mk_div : context -> arith_expr -> arith_expr -> arith_expr + val mk_power : context -> arith_expr -> arith_expr -> arith_expr + val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr +end = struct + type arith_sort = ArithSort of sort + type arith_expr = ArithExpr of expr + + let arith_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithExpr(e) + + let arith_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + arith_expr_of_expr (expr_of_ptr ctx no) + + let sort_of_arith_sort s = match s with ArithSort(x) -> x + let expr_of_arith_expr e = match e with ArithExpr(x) -> x + + let arith_sort_of_sort s = match s with Sort(a) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithSort(s) + + let arith_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + arith_sort_of_sort (sort_of_ptr ctx no) + + let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gno s) + let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gc e) + let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) + let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) + + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val int_expr_of_ptr : context -> Z3native.ptr -> int_expr + val int_num_of_ptr : context -> Z3native.ptr -> int_num + + val arith_sort_of_int_sort : Integer.int_sort -> arith_sort + val int_sort_of_arith_sort : arith_sort -> int_sort + val arith_expr_of_int_expr : int_expr -> arith_expr + val int_expr_of_int_num : int_num -> int_expr + val int_expr_of_arith_expr : arith_expr -> int_expr + val int_num_of_int_expr : int_expr -> int_num + + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end = struct + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + let int_expr_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntExpr(e) + + let int_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) + + let int_num_of_int_expr e = + match e with IntExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + IntNum(e) + + let int_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_num_of_int_expr (int_expr_of_ptr ctx no) + + let arith_sort_of_int_sort s = match s with IntSort(x) -> x + let arith_expr_of_int_expr e = match e with IntExpr(x) -> x + let int_expr_of_int_num e = match e with IntNum(x) -> x + + let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntSort(s) + + let int_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_sort_of_arith_sort (arith_sort_of_sort (Sort.sort_of_ptr ctx no)) + + let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) + let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) + let sgno ( x : int_sort ) = match (x) with IntSort(s) -> (sgno s) + let egc ( x : int_expr ) = match (x) with IntExpr(e) -> (egc e) + let egnc ( x : int_expr ) = match (x) with IntExpr(e) -> (egnc e) + let egno ( x : int_expr ) = match (x) with IntExpr(e) -> (egno e) + let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) + let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) + let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) + + let mk_sort ( ctx : context ) = + int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) + + let get_int ( x : int_num ) = + let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + if r then v + else raise (Z3native.Exception "Conversion failed.") + + let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + + let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) + + let mk_int_const_s ( ctx : context ) ( name : string ) = + mk_int_const ctx (Symbol.mk_string ctx name) + + let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + + let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + + let mk_int_numeral_s ( ctx : context ) ( v : string ) = + int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + + let mk_int_numeral_i ( ctx : context ) ( v : int ) = + int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + + let mk_int2real ( ctx : context ) ( t : int_expr ) = + Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) + + let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = + BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) + end + + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val real_expr_of_ptr : context -> Z3native.ptr -> real_expr + val rat_num_of_ptr : context -> Z3native.ptr -> rat_num + + val arith_sort_of_real_sort : real_sort -> arith_sort + val real_sort_of_arith_sort : arith_sort -> real_sort + val arith_expr_of_real_expr : real_expr -> arith_expr + val real_expr_of_rat_num : rat_num -> real_expr + val real_expr_of_arith_expr : arith_expr -> real_expr + val rat_num_of_real_expr : real_expr -> rat_num + + val mk_sort : context -> real_sort + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr + end = struct + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + let arith_sort_of_real_sort s = match s with RealSort(x) -> x + let arith_expr_of_real_expr e = match e with RealExpr(x) -> x + let real_expr_of_rat_num e = match e with RatNum(x) -> x + + let real_expr_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealExpr(e) + + let real_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) + + let rat_num_of_real_expr e = + match e with RealExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + RatNum(e) + + let rat_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + rat_num_of_real_expr (real_expr_of_ptr ctx no) + + let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealSort(s) + + let real_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) + + let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) + let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) + let sgno ( x : real_sort ) = match (x) with RealSort(s) -> (sgno s) + let egc ( x : real_expr ) = match (x) with RealExpr(e) -> (egc e) + let egnc ( x : real_expr ) = match (x) with RealExpr(e) -> (egnc e) + let egno ( x : real_expr ) = match (x) with RealExpr(e) -> (egno e) + let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) + let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) + let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) + + + let mk_sort ( ctx : context ) = + real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) + + let get_numerator ( x : rat_num ) = + Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + + let get_denominator ( x : rat_num ) = + Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + + let to_decimal_string ( x : rat_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + + let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + + let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) + + let mk_real_const_s ( ctx : context ) ( name : string ) = + mk_real_const ctx (Symbol.mk_string ctx name) + + let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = + if (den == 0) then + raise (Z3native.Exception "Denominator is zero") + else + rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) + + let mk_numeral_s ( ctx : context ) ( v : string ) = + rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + + let mk_numeral_i ( ctx : context ) ( v : int ) = + rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + + let mk_is_integer ( ctx : context ) ( t : real_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) + + let mk_real2int ( ctx : context ) ( t : real_expr ) = + Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) + end + + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : algebraic_num -> arith_expr + val algebraic_num_of_arith_expr : arith_expr -> algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end = struct + type algebraic_num = AlgebraicNum of arith_expr + + let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x + + let algebraic_num_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + AlgebraicNum(e) + + let algebraic_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + + let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) + let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) + let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) + + + let to_upper ( x : algebraic_num ) ( precision : int ) = + Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + + let to_lower ( x : algebraic_num ) precision = + Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + + let to_decimal_string ( x : algebraic_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + + let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + end + + let is_int ( x : expr ) = + (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) + + let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + + let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + + let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + + let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + + let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + + let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + + let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + + let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + + let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + + let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + + let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + + let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + + let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + + let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + + let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + + let is_real ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) + + let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) + + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) + + let mk_add ( ctx : context ) ( t : arith_expr list ) = + let f x = (Expr.gno (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + + let mk_mul ( ctx : context ) ( t : arith_expr list ) = + let f x = (Expr.gno (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + + let mk_sub ( ctx : context ) ( t : arith_expr list ) = + let f x = (Expr.gno (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + + let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) + + let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) + + let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) + + let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) + + let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) + + let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) + + let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) +end + + +and BitVector : +sig + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort + val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort + val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr + val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr + val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr + val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num + + val mk_sort : context -> int -> bitvec_sort + val is_bv : Expr.expr -> bool + val is_bv_numeral : Expr.expr -> bool + val is_bv_bit1 : Expr.expr -> bool + val is_bv_bit0 : Expr.expr -> bool + val is_bv_uminus : Expr.expr -> bool + val is_bv_add : Expr.expr -> bool + val is_bv_sub : Expr.expr -> bool + val is_bv_mul : Expr.expr -> bool + val is_bv_sdiv : Expr.expr -> bool + val is_bv_udiv : Expr.expr -> bool + val is_bv_SRem : Expr.expr -> bool + val is_bv_urem : Expr.expr -> bool + val is_bv_smod : Expr.expr -> bool + val is_bv_sdiv0 : Expr.expr -> bool + val is_bv_udiv0 : Expr.expr -> bool + val is_bv_srem0 : Expr.expr -> bool + val is_bv_urem0 : Expr.expr -> bool + val is_bv_smod0 : Expr.expr -> bool + val is_bv_ule : Expr.expr -> bool + val is_bv_sle : Expr.expr -> bool + val is_bv_uge : Expr.expr -> bool + val is_bv_sge : Expr.expr -> bool + val is_bv_ult : Expr.expr -> bool + val is_bv_slt : Expr.expr -> bool + val is_bv_ugt : Expr.expr -> bool + val is_bv_sgt : Expr.expr -> bool + val is_bv_and : Expr.expr -> bool + val is_bv_or : Expr.expr -> bool + val is_bv_not : Expr.expr -> bool + val is_bv_xor : Expr.expr -> bool + val is_bv_nand : Expr.expr -> bool + val is_bv_nor : Expr.expr -> bool + val is_bv_xnor : Expr.expr -> bool + val is_bv_concat : Expr.expr -> bool + val is_bv_signextension : Expr.expr -> bool + val is_bv_zeroextension : Expr.expr -> bool + val is_bv_extract : Expr.expr -> bool + val is_bv_repeat : Expr.expr -> bool + val is_bv_reduceor : Expr.expr -> bool + val is_bv_reduceand : Expr.expr -> bool + val is_bv_comp : Expr.expr -> bool + val is_bv_shiftleft : Expr.expr -> bool + val is_bv_shiftrightlogical : Expr.expr -> bool + val is_bv_shiftrightarithmetic : Expr.expr -> bool + val is_bv_rotateleft : Expr.expr -> bool + val is_bv_rotateright : Expr.expr -> bool + val is_bv_rotateleftextended : Expr.expr -> bool + val is_bv_rotaterightextended : Expr.expr -> bool + val is_int_to_bv : Expr.expr -> bool + val is_bv_to_int : Expr.expr -> bool + val is_bv_carry : Expr.expr -> bool + val is_bv_xor3 : Expr.expr -> bool + val get_size : bitvec_sort -> int + val get_int : bitvec_num -> int + val to_string : bitvec_num -> string + val mk_const : context -> Symbol.symbol -> int -> bitvec_expr + val mk_const_s : context -> string -> int -> bitvec_expr + val mk_not : context -> bitvec_expr -> Expr.expr + val mk_redand : context -> bitvec_expr -> Expr.expr + val mk_redor : context -> bitvec_expr -> Expr.expr + val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_neg : context -> bitvec_expr -> bitvec_expr + val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr + val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_numeral : context -> string -> int -> bitvec_num +end = struct + type bitvec_sort = BitVecSort of sort + type bitvec_expr = BitVecExpr of expr + type bitvec_num = BitVecNum of bitvec_expr + + let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x + + let bitvec_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecSort(s) + + let bitvec_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + bitvec_sort_of_sort (sort_of_ptr ctx no) + + let bitvec_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecExpr(e) + + let bitvec_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + bitvec_expr_of_expr (expr_of_ptr ctx no) + + let bitvec_num_of_bitvec_expr e = + match e with BitVecExpr(Expr(a)) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecNum(e) + + let bitvec_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + bitvec_num_of_bitvec_expr (bitvec_expr_of_expr (expr_of_ptr ctx no)) + + let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x + let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x + + + let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) + let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) + let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) + let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gc e) + let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gnc e) + let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gno e) + let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) + let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) + let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) + + + let mk_sort ( ctx : context ) size = + bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) + let is_bv ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) + let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) + let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) + let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) + let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) + let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) + let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) + let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) + let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) + let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) + let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) + let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) + let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) + let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) + let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) + let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) + let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) + let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) + let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) + let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) + let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) + let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) + let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) + let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) + let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) + let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) + let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) + let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) + let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) + let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) + let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) + let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) + let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) + let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) + let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) + let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) + let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) + let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) + let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) + let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) + let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) + let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) + let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) + let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) + let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) + let get_int ( x : bitvec_num ) = + let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + if r then v + else raise (Z3native.Exception "Conversion failed.") + let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) + let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = + mk_const ctx (Symbol.mk_string ctx name) size + let mk_not ( ctx : context ) ( t : bitvec_expr ) = + expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) + let mk_redand ( ctx : context ) ( t : bitvec_expr) = + expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) + let mk_redor ( ctx : context ) ( t : bitvec_expr) = + expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) + let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) + let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) + let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) + let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) + let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) + let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) + let mk_neg ( ctx : context ) ( t : bitvec_expr) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) + let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) + let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) + let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) + let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) + let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) + let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) + let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) + let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) + let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) + let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) + let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) + let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) + let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) + let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) + let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) + let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) + let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) + let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) + let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) + let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) + let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) + let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) + let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) + let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) + let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) + let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) + let mk_ext_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) + let mk_ext_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) + let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = + Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) + let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) + let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) + let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) + let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) + let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) + let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) + let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) + let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) + let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = + bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) +end + + +module Proof = +struct + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) + let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) + let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) + let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) + let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) + let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) + let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) + let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) + let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) + let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) + let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) + let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) + let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) + let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) + let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) + let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) + let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) + let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) + let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) + let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) + let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) + let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) + let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) + let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) +end + + +module Goal = +struct + type goal = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : goal = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.goal_inc_ref ; + dec_ref = Z3native.goal_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let get_precision ( x : goal ) = + goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) + + let is_precise ( x : goal ) = + (get_precision x) == GOAL_PRECISE + + let is_underapproximation ( x : goal ) = + (get_precision x) == GOAL_UNDER + + let is_overapproximation ( x : goal ) = + (get_precision x) == GOAL_OVER + + let is_garbage ( x : goal ) = + (get_precision x) == GOAL_UNDER_OVER + + let assert_ ( x : goal ) ( constraints : Boolean.bool_expr list ) = + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in + ignore (List.map f constraints) ; + () + + let is_inconsistent ( x : goal ) = + Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) + + let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) + + let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) + + let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) + + let get_formulas ( x : goal ) = + let n = get_size x in + let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) + (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in + mk_list f n + + let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) + + let is_decided_sat ( x : goal ) = + Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) + + let is_decided_unsat ( x : goal ) = + Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) + + let translate ( x : goal ) ( to_ctx : context ) = + create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + + let simplify ( x : goal ) ( p : Params.params option ) = + let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in + Z3native.tactic_inc_ref (z3obj_gnc x) tn ; + let arn = match p with + | None -> Z3native.tactic_apply (z3obj_gnc x) tn (z3obj_gno x) + | Some(pn) -> Z3native.tactic_apply_ex (z3obj_gnc x) tn (z3obj_gno x) (z3obj_gno pn) + in + Z3native.apply_result_inc_ref (z3obj_gnc x) arn ; + let sg = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) arn in + let res = if sg == 0 then + raise (Z3native.Exception "No subgoals") + else + Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in + Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; + Z3native.tactic_dec_ref (z3obj_gnc x) tn ; + create (z3obj_gc x) res + + let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = + create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) + + let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) +end + + +module Model = +struct + type model = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : model = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.model_inc_ref ; + dec_ref = Z3native.model_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + module FuncInterp = + struct + type func_interp = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : func_interp = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.func_interp_inc_ref ; + dec_ref = Z3native.func_interp_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + module FuncEntry = + struct + type func_entry = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : func_entry = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.func_entry_inc_ref ; + dec_ref = Z3native.func_entry_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let get_value ( x : func_entry ) = + expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) + + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) + + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in + mk_list f n + + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ List.fold_right f a ((Expr.to_string (get_value x)) ^ "]") + end + + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) + + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in + mk_list f n + + let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) + + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) + + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (List.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + List.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + end + + let get_const_interp ( x : model ) ( f : func_decl ) = + if (FuncDecl.get_arity f) != 0 || + (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then + raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") + else + let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in + if (Z3native.is_null np) then + None + else + Some (expr_of_ptr (z3obj_gc x) np) + + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + + + let rec get_func_interp ( x : model ) ( f : func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in + if (FuncDecl.get_arity f) == 0 then + let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in + if (Z3native.is_null n) then + None + else + match sk with + | ARRAY_SORT -> + if not (Z3native.is_as_array (z3obj_gnc x) n) then + raise (Z3native.Exception "Argument was not an array constant") + else + let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in + get_func_interp x (func_decl_of_ptr (z3obj_gc x) fd) + | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); + else + let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in + if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) + + (** The number of constants that have an interpretation in the model. *) + let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) + + let get_const_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) + + let get_func_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get_decls ( x : model ) = + let n_funcs = (get_num_funcs x) in + let n_consts = (get_num_consts x ) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + (mk_list f n_funcs) @ (mk_list g n_consts) + + exception ModelEvaluationFailedException of string + + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in + if not r then + raise (ModelEvaluationFailedException "evaluation failed") + else + expr_of_ptr (z3obj_gc x) v + + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + eval x t completion + + let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) + + let get_sorts ( x : model ) = + let n = (get_num_sorts x) in + let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in + mk_list f n + + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in + mk_list f n + + let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) +end + + +module Probe = +struct + type probe = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : probe = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.probe_inc_ref ; + dec_ref = Z3native.probe_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + + let apply ( x : probe ) ( g : Goal.goal ) = + Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) + + let get_num_probes ( ctx : context ) = + Z3native.get_num_probes (context_gno ctx) + + let get_probe_names ( ctx : context ) = + let n = (get_num_probes ctx) in + let f i = (Z3native.get_probe_name (context_gno ctx) i) in + mk_list f n + + let get_probe_description ( ctx : context ) ( name : string ) = + Z3native.probe_get_descr (context_gno ctx) name + + let mk_probe ( ctx : context ) ( name : string ) = + (create ctx (Z3native.mk_probe (context_gno ctx) name)) + + let const ( ctx : context ) ( v : float ) = + (create ctx (Z3native.probe_const (context_gno ctx) v)) + + let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let not_ ( ctx : context ) ( p : probe ) = + (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) +end + + +module Tactic = +struct + type tactic = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : tactic = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.tactic_inc_ref ; + dec_ref = Z3native.tactic_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + module ApplyResult = + struct + type apply_result = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : apply_result = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.apply_result_inc_ref ; + dec_ref = Z3native.apply_result_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let get_num_subgoals ( x : apply_result ) = + Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) + + let get_subgoals ( x : apply_result ) = + let n = (get_num_subgoals x) in + let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get_subgoal ( x : apply_result ) ( i : int ) = + Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) + + let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = + Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) + + let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) + end + + let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) + + let get_param_descrs ( x : tactic ) = + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + + let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = + match p with + | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) + | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) + + let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) + + let get_tactic_names ( ctx : context ) = + let n = (get_num_tactics ctx ) in + let f i = (Z3native.get_tactic_name (context_gno ctx) i) in + mk_list f n + + let get_tactic_description ( ctx : context ) ( name : string ) = + Z3native.tactic_get_descr (context_gno ctx) name + + let mk_tactic ( ctx : context ) ( name : string ) = + create ctx (Z3native.mk_tactic (context_gno ctx) name) + + let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic list ) = + let f p c = (match p with + | None -> (Some (z3obj_gno c)) + | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in + match (List.fold_left f None ts) with + | None -> + create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + | Some(x) -> + let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in + create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) + + let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = + create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + + let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = + create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) + + let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = + create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) + + let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = + create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) + + let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = + create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) + + let skip ( ctx : context ) = + create ctx (Z3native.tactic_skip (context_gno ctx)) + + let fail ( ctx : context ) = + create ctx (Z3native.tactic_fail (context_gno ctx)) + + let fail_if ( ctx : context ) ( p : Probe.probe ) = + create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) + + let fail_if_not_decided ( ctx : context ) = + create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) + + let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) + + let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + using_params ctx t p + + let par_or ( ctx : context ) ( t : tactic list ) = + let f e = (z3obj_gno e) in + create ctx (Z3native.tactic_par_or (context_gno ctx) (List.length t) (Array.of_list (List.map f t))) + + let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = + create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + + let interrupt ( ctx : context ) = + Z3native.interrupt (context_gno ctx) +end + + +module Solver = +struct + type solver = z3_native_object + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : solver = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.solver_inc_ref ; + dec_ref = Z3native.solver_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let string_of_status ( s : status) = match s with + | UNSATISFIABLE -> "unsatisfiable" + | SATISFIABLE -> "satisfiable" + | _ -> "unknown" + + module Statistics = + struct + type statistics = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : statistics = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.stats_inc_ref ; + dec_ref = Z3native.stats_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + + module Entry = + struct + type statistics_entry = { + mutable m_key : string; + mutable m_is_int : bool ; + mutable m_is_float : bool ; + mutable m_int : int ; + mutable m_float : float } + + let create_si k v = + let res : statistics_entry = { + m_key = k ; + m_is_int = true ; + m_is_float = false ; + m_int = v ; + m_float = 0.0 + } in + res + + let create_sd k v = + let res : statistics_entry = { + m_key = k ; + m_is_int = false ; + m_is_float = true ; + m_int = 0 ; + m_float = v + } in + res + + + let get_key (x : statistics_entry) = x.m_key + let get_int (x : statistics_entry) = x.m_int + let get_float (x : statistics_entry) = x.m_float + let is_int (x : statistics_entry) = x.m_is_int + let is_float (x : statistics_entry) = x.m_is_float + let to_string_value (x : statistics_entry) = + if (is_int x) then + string_of_int (get_int x) + else if (is_float x) then + string_of_float (get_float x) + else + raise (Z3native.Exception "Unknown statistical entry type") + let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) + end + + let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) + + let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) + + let get_entries ( x : statistics ) = + let n = (get_size x ) in + let f i = ( + let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in + if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then + (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) + else + (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) + ) in + mk_list f n + + let get_keys ( x : statistics ) = + let n = (get_size x) in + let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get ( x : statistics ) ( key : string ) = + let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in + List.fold_left f None (get_entries x) + end + + let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) + + let set_parameters ( x : solver ) ( p : Params.params )= + Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) + + let get_param_descrs ( x : solver ) = + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + + let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) + + let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) + + let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n + + let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) + + let assert_ ( x : solver ) ( constraints : Boolean.bool_expr list ) = + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in + ignore (List.map f constraints) + + let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr list ) ( ps : Boolean.bool_expr list ) = + if ((List.length cs) != (List.length ps)) then + raise (Z3native.Exception "Argument size mismatch") + else + let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno a) (Boolean.gno b)) in + ignore (List.iter2 f cs ps) + + let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) + + let get_num_assertions ( x : solver ) = + let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + (AST.ASTVector.get_size a) + + let get_assertions ( x : solver ) = + let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVector.get_size a) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in + mk_list f n + + let check ( x : solver ) ( assumptions : Boolean.bool_expr list ) = + let r = + if ((List.length assumptions) == 0) then + lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) + else + let f x = (Expr.gno (Boolean.expr_of_bool_expr x)) in + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) + in + match r with + | L_TRUE -> SATISFIABLE + | L_FALSE -> UNSATISFIABLE + | _ -> UNKNOWN + + let get_model ( x : solver ) = + let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in + if (Z3native.is_null q) then + None + else + Some (Model.create (z3obj_gc x) q) + + let get_proof ( x : solver ) = + let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in + if (Z3native.is_null q) then + None + else + Some (expr_of_ptr (z3obj_gc x) q) + + let get_unsat_core ( x : solver ) = + let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVector.get_size cn) in + let f i = (AST.ASTVector.get cn i) in + mk_list f n + + let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) + + let get_statistics ( x : solver ) = + (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) + + let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = + match logic with + | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) + | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) + + let mk_solver_s ( ctx : context ) ( logic : string ) = + mk_solver ctx (Some (Symbol.mk_string ctx logic)) + + let mk_simple_solver ( ctx : context ) = + (create ctx (Z3native.mk_simple_solver (context_gno ctx))) + + let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = + (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) + + let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) +end + + +module Fixedpoint = +struct + type fixedpoint = z3_native_object + + let create ( ctx : context ) = + let res : fixedpoint = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.fixedpoint_inc_ref ; + dec_ref = Z3native.fixedpoint_dec_ref } in + (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; + (z3obj_create res) ; + res + + + let get_help ( x : fixedpoint ) = + Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) + + let set_params ( x : fixedpoint ) ( p : Params.params )= + Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) + + let get_param_descrs ( x : fixedpoint ) = + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + + let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr list ) = + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in + ignore (List.map f constraints) ; + () + + let register_relation ( x : fixedpoint ) ( f : func_decl ) = + Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) + + let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = + match name with + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) + + let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = + Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) + + let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN + + let query_r ( x : fixedpoint ) ( relations : func_decl list ) = + let f x = ptr_of_ast (ast_of_func_decl x) in + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (List.length relations) (Array.of_list (List.map f relations)))) with + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN + + let push ( x : fixedpoint ) = + Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) + + let pop ( x : fixedpoint ) = + Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) + + let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) + + let get_answer ( x : fixedpoint ) = + let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in + if (Z3native.is_null q) then + None + else + Some (expr_of_ptr (z3obj_gc x) q) + + let get_reason_unknown ( x : fixedpoint ) = + Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) + + let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = + Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) + + let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = + let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in + if (Z3native.is_null q) then + None + else + Some (expr_of_ptr (z3obj_gc x) q) + + let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) + + let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] + + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) + + let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr list ) = + let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) + + let get_rules ( x : fixedpoint ) = + let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVector.get_size v) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + mk_list f n + + let get_assertions ( x : fixedpoint ) = + let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVector.get_size v) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + mk_list f n + + let mk_fixedpoint ( ctx : context ) = create ctx +end + +module Options = +struct + + let update_param_value ( ctx : context ) ( id : string) ( value : string )= + Z3native.update_param_value (context_gno ctx) id value + + let get_param_value ( ctx : context ) ( id : string ) = + let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in + if not r then + None + else + Some v + + let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = + Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) + + let toggle_warning_messages ( enabled: bool ) = + Z3native.toggle_warning_messages enabled +end + + +module SMT = +struct + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr list ) ( formula : Boolean.bool_expr ) = + Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes + (List.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.of_list (List.map f assumptions))) + (Boolean.gno formula) + + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Z3native.parse_smtlib_string (context_gno ctx) str + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) + + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Z3native.parse_smtlib_file (context_gno ctx) file_name + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) + + let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) + + let get_smtlib_formulas ( ctx : context ) = + let n = (get_num_smtlib_formulas ctx ) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in + mk_list f n + + let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) + + let get_smtlib_assumptions ( ctx : context ) = + let n = (get_num_smtlib_assumptions ctx ) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in + mk_list f n + + let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) + + let get_smtlib_decls ( ctx : context ) = + let n = (get_num_smtlib_decls ctx) in + let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in + mk_list f n + + let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) + + let get_smtlib_sorts ( ctx : context ) = + let n = (get_num_smtlib_sorts ctx) in + let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in + mk_list f n + + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) + + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) +end + + +let set_global_param ( id : string ) ( value : string ) = + (Z3native.global_param_set id value) + +let get_global_param ( id : string ) = + let (r, v) = (Z3native.global_param_get id) in + if not r then + None + else + Some v + +let global_param_reset_all = + Z3native.global_param_reset_all diff --git a/src/api/ml/z3_rich.mli b/src/api/ml/z3_rich.mli new file mode 100644 index 000000000..8b6681e11 --- /dev/null +++ b/src/api/ml/z3_rich.mli @@ -0,0 +1,3072 @@ +(** + The Z3 ML/Ocaml Interface. + + Copyright (C) 2012 Microsoft Corporation + @author CM Wintersteiger (cwinter) 2012-12-17 + + NOTE: This is the *rich* version of the interface, using more + type information directly in the type system. Coercion functions + are provided to tran coerce on type into another where applicable. +*) + +(** Context objects. + + Most interactions with Z3 are interpreted in some context; many users will only + require one such object, but power users may require more than one. To start using + Z3, do + + + let ctx = (mk_context []) in + (...) + + + where a list of pairs of strings may be passed to set options on + the context, e.g., like so: + + + let cfg = [("model", "true"); ("...", "...")] in + let ctx = (mk_context cfg) in + (...) + +*) +type context + +(** Create a context object *) +val mk_context : (string * string) list -> context + + +(** 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. *) +module Log : +sig + (** Open an interaction log file. + @return True if opening the log file succeeds, false otherwise. *) + (* CMW: "open" seems to be a reserved keyword? *) + val open_ : string -> bool + + (** Closes the interaction log. *) + val close : unit + + (** Appends a user-provided string to the interaction log. *) + val append : string -> unit +end + +(** Version information *) +module Version : +sig + (** The major version. *) + val major : int + + (** The minor version. *) + val minor : int + + (** The build version. *) + val build : int + + (** The revision. *) + val revision : int + + (** A string representation of the version information. *) + val to_string : string +end + +(** Symbols are used to name several term and type constructors *) +module Symbol : +sig + (** Numbered Symbols *) + type int_symbol + + (** Named Symbols *) + type string_symbol + + (** Symbols *) + type symbol = S_Int of int_symbol | S_Str of string_symbol + + (** The kind of the symbol (int or string) *) + val kind : symbol -> Z3enums.symbol_kind + + (** Indicates whether the symbol is of Int kind *) + val is_int_symbol : symbol -> bool + + (** Indicates whether the symbol is of string kind. *) + val is_string_symbol : symbol -> bool + + (** The int value of the symbol. *) + val get_int : int_symbol -> int + + (** The string value of the symbol. *) + val get_string : string_symbol -> string + + (** A string representation of the symbol. *) + val to_string : symbol -> string + + (** 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. *) + val mk_int : context -> int -> symbol + + (** Creates a new symbol using a string. *) + val mk_string : context -> string -> symbol + + (** Create a list of symbols. *) + val mk_ints : context -> int list -> symbol list + + (** Create a list of symbols. *) + val mk_strings : context -> string list -> symbol list +end + +(** The abstract syntax tree (AST) module *) +module AST : +sig + type ast + + (** Vectors of ASTs *) + module ASTVector : + sig + type ast_vector + + (** The size of the vector *) + val get_size : ast_vector -> int + + (** + Retrieves the i-th object in the vector. + @return An AST *) + val get : ast_vector -> int -> ast + + (** Sets the i-th object in the vector. *) + val set : ast_vector -> int -> ast -> unit + + (** Resize the vector to a new size. *) + val resize : ast_vector -> int -> unit + + (** Add an ast to the back of the vector. The size + is increased by 1. *) + val push : ast_vector -> ast -> unit + + (** Translates all ASTs in the vector to another context. + @return A new ASTVector *) + val translate : ast_vector -> context -> ast_vector + + (** Retrieves a string representation of the vector. *) + val to_string : ast_vector -> string + end + + (** Map from AST to AST *) + module ASTMap : + sig + type ast_map + + (** Checks whether the map contains a key. + @return True if the key in the map, false otherwise. *) + val contains : ast_map -> ast -> bool + + (** Finds the value associated with the key. + This function signs an error when the key is not a key in the map. *) + val find : ast_map -> ast -> ast + + (** Stores or replaces a new key/value pair in the map. *) + val insert : ast_map -> ast -> ast -> unit + + (** Erases the key from the map.*) + val erase : ast_map -> ast -> unit + + (** Removes all keys from the map. *) + val reset : ast_map -> unit + + (** The size of the map *) + val get_size : ast_map -> int + + (** The keys stored in the map. *) + val get_keys : ast_map -> ast list + + (** Retrieves a string representation of the map.*) + val to_string : ast_map -> string + end + + (** The AST's hash code. + @return A hash code *) + val get_hash_code : ast -> int + + (** A unique identifier for the AST (unique among all ASTs). *) + val get_id : ast -> int + + (** The kind of the AST. *) + val get_ast_kind : ast -> Z3enums.ast_kind + + (** Indicates whether the AST is an Expr *) + val is_expr : ast -> bool + + (** Indicates whether the AST is a bound variable*) + val is_var : ast -> bool + + (** Indicates whether the AST is a Quantifier *) + val is_quantifier : ast -> bool + + (** Indicates whether the AST is a Sort *) + val is_sort : ast -> bool + + (** Indicates whether the AST is a func_decl *) + val is_func_decl : ast -> bool + + (** A string representation of the AST. *) + val to_string : ast -> string + + (** A string representation of the AST in s-expression notation. *) + val to_sexpr : ast -> string + + (** Comparison operator. + @return True if the two ast's are from the same context + and represent the same sort; false otherwise. *) + val ( = ) : ast -> ast -> bool + + (** Object Comparison. + @return Negative if the first ast should be sorted before the second, positive if after else zero. *) + val compare : ast -> ast -> int + + (** Operator < *) + val ( < ) : ast -> ast -> int + + (** Translates (copies) the AST to another context. + @return A copy of the AST which is associated with the other context. *) + val translate : ast -> context -> ast + + (** Wraps an AST. + + This function is used for transitions between native and + managed objects. Note that the native ast that is passed must be a + native object obtained from Z3 (e.g., through {!unwrap_ast}) + and that it must have a correct reference count (see e.g., + Z3native.inc_ref). *) + val wrap_ast : context -> Z3native.z3_ast -> ast + + (** 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., + Z3native.inc_ref). + {!wrap_ast} *) + val unwrap_ast : ast -> Z3native.ptr +end + +(** The Sort module implements type information for ASTs *) +module Sort : +sig + (** Sorts *) + type sort = Sort of AST.ast + + (** Uninterpreted Sorts *) + type uninterpreted_sort = UninterpretedSort of sort + + val ast_of_sort : sort -> AST.ast + val sort_of_uninterpreted_sort : uninterpreted_sort -> sort + val uninterpreted_sort_of_sort : sort -> uninterpreted_sort + + (** Comparison operator. + @return True if the two sorts are from the same context + and represent the same sort; false otherwise. *) + val ( = ) : sort -> sort -> bool + + (** Returns a unique identifier for the sort. *) + val get_id : sort -> int + + (** The kind of the sort. *) + val get_sort_kind : sort -> Z3enums.sort_kind + + (** The name of the sort *) + val get_name : sort -> Symbol.symbol + + (** A string representation of the sort. *) + val to_string : sort -> string + + (** Create a new uninterpreted sort. *) + val mk_uninterpreted : context -> Symbol.symbol -> uninterpreted_sort + + (** Create a new uninterpreted sort. *) + val mk_uninterpreted_s : context -> string -> uninterpreted_sort +end + +(** Function declarations *) +module rec FuncDecl : +sig + type func_decl = FuncDecl of AST.ast + + val ast_of_func_decl : FuncDecl.func_decl -> AST.ast + + (** Parameters of Func_Decls *) + module Parameter : + sig + (** Parameters of func_decls *) + type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + (** The kind of the parameter. *) + val get_kind : parameter -> Z3enums.parameter_kind + + (** The int value of the parameter.*) + val get_int : parameter -> int + + (** The double value of the parameter.*) + val get_float : parameter -> float + + (** The Symbol.Symbol value of the parameter.*) + val get_symbol : parameter -> Symbol.symbol + + (** The Sort value of the parameter.*) + val get_sort : parameter -> Sort.sort + + (** The AST value of the parameter.*) + val get_ast : parameter -> AST.ast + + (** The FunctionDeclaration value of the parameter.*) + val get_func_decl : parameter -> func_decl + + (** The rational string value of the parameter.*) + val get_rational : parameter -> string + end + + (** Creates a new function declaration. *) + val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl + + (** Creates a new function declaration. *) + val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl + (** Creates a fresh function declaration with a name prefixed with a prefix string. *) + + val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl + + (** Creates a new constant function declaration. *) + val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl + + (** Creates a new constant function declaration. *) + val mk_const_decl_s : context -> string -> Sort.sort -> func_decl + + (** Creates a fresh constant function declaration with a name prefixed with a prefix string. + {!mk_func_decl} + {!mk_func_decl} *) + val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl + + (** Comparison operator. + @return True if a and b are from the same context and represent the same func_decl; false otherwise. *) + val ( = ) : func_decl -> func_decl -> bool + + (** A string representations of the function declaration. *) + val to_string : func_decl -> string + + (** Returns a unique identifier for the function declaration. *) + val get_id : func_decl -> int + + (** The arity of the function declaration *) + val get_arity : func_decl -> int + + (** The size of the domain of the function declaration + {!get_arity} *) + val get_domain_size : func_decl -> int + + (** The domain of the function declaration *) + val get_domain : func_decl -> Sort.sort list + + (** The range of the function declaration *) + val get_range : func_decl -> Sort.sort + + (** The kind of the function declaration. *) + val get_decl_kind : func_decl -> Z3enums.decl_kind + + (** The name of the function declaration*) + val get_name : func_decl -> Symbol.symbol + + (** The number of parameters of the function declaration *) + val get_num_parameters : func_decl -> int + + (** The parameters of the function declaration *) + val get_parameters : func_decl -> Parameter.parameter list + + (** Create expression that applies function to arguments. *) + val apply : func_decl -> Expr.expr list -> Expr.expr +end + +(** Parameter sets (of Solvers, Tactics, ...) + + A Params objects represents a configuration in the form of Symbol.symbol/value pairs. *) +and Params : +sig + type params + + (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) + module ParamDescrs : + sig + type param_descrs + + (** Validate a set of parameters. *) + val validate : param_descrs -> params -> unit + + (** Retrieve kind of parameter. *) + val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind + + (** Retrieve all names of parameters. *) + val get_names : param_descrs -> Symbol.symbol list + + (** The size of the ParamDescrs. *) + val get_size : param_descrs -> int + + (** Retrieves a string representation of the ParamDescrs. *) + val to_string : param_descrs -> string + end + + (** Adds a parameter setting. *) + val add_bool : params -> Symbol.symbol -> bool -> unit + + (** Adds a parameter setting. *) + val add_int : params -> Symbol.symbol -> int -> unit + + (** Adds a parameter setting. *) + val add_double : params -> Symbol.symbol -> float -> unit + + (** Adds a parameter setting. *) + val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit + + (** Adds a parameter setting. *) + val add_s_bool : params -> string -> bool -> unit + + (** Adds a parameter setting. *) + val add_s_int : params -> string -> int -> unit + + (** Adds a parameter setting. *) + val add_s_double : params -> string -> float -> unit + + (** Adds a parameter setting. *) + val add_s_symbol : params -> string -> Symbol.symbol -> unit + + (** Creates a new parameter set *) + val mk_params : context -> params + + (** A string representation of the parameter set. *) + val to_string : params -> string +end + +(** General Expressions (terms) *) +and Expr : +sig + type expr = Expr of AST.ast + + val ast_of_expr : Expr.expr -> AST.ast + val expr_of_ast : AST.ast -> Expr.expr + + (** Returns a simplified version of the expression. + {!get_simplify_help} *) + val simplify : Expr.expr -> Params.params option -> expr + + (** A string describing all available parameters to Expr.Simplify. *) + val get_simplify_help : context -> string + + (** Retrieves parameter descriptions for simplifier. *) + val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs + + (** The function declaration of the function that is applied in this expression. *) + val get_func_decl : Expr.expr -> FuncDecl.func_decl + + (** Indicates whether the expression is the true or false expression + or something else (L_UNDEF). *) + val get_bool_value : Expr.expr -> Z3enums.lbool + + (** The number of arguments of the expression. *) + val get_num_args : Expr.expr -> int + + (** The arguments of the expression. *) + val get_args : Expr.expr -> Expr.expr list + + (** Update the arguments of the expression using an array of expressions. + The number of new arguments should coincide with the current number of arguments. *) + val update : Expr.expr -> Expr.expr list -> expr + + (** 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]. *) + val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr + + (** Substitute every occurrence of from in the expression with to. + {!substitute} *) + val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr + + (** Substitute the free variables in the expression with the expressions in the expr array + + For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) + val substitute_vars : Expr.expr -> Expr.expr list -> expr + + (** Translates (copies) the term to another context. + @return A copy of the term which is associated with the other context *) + val translate : Expr.expr -> context -> expr + + (** Returns a string representation of the expression. *) + val to_string : Expr.expr -> string + + (** Indicates whether the term is a numeral *) + val is_numeral : Expr.expr -> bool + + (** Indicates whether the term is well-sorted. + @return True if the term is well-sorted, false otherwise. *) + val is_well_sorted : Expr.expr -> bool + + (** The Sort of the term. *) + val get_sort : Expr.expr -> Sort.sort + + (** Indicates whether the term has Boolean sort. *) + val is_bool : Expr.expr -> bool + + (** Indicates whether the term represents a constant. *) + val is_const : Expr.expr -> bool + + (** Indicates whether the term is the constant true. *) + val is_true : Expr.expr -> bool + + (** Indicates whether the term is the constant false. *) + val is_false : Expr.expr -> bool + + (** Indicates whether the term is an equality predicate. *) + val is_eq : Expr.expr -> bool + + (** Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). *) + val is_distinct : Expr.expr -> bool + + (** Indicates whether the term is a ternary if-then-else term *) + val is_ite : Expr.expr -> bool + + (** Indicates whether the term is an n-ary conjunction *) + val is_and : Expr.expr -> bool + + (** Indicates whether the term is an n-ary disjunction *) + val is_or : Expr.expr -> bool + + (** Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) *) + val is_iff : Expr.expr -> bool + + (** Indicates whether the term is an exclusive or *) + val is_xor : Expr.expr -> bool + + (** Indicates whether the term is a negation *) + val is_not : Expr.expr -> bool + + (** Indicates whether the term is an implication *) + val is_implies : Expr.expr -> bool + + (** 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. *) + val is_label : Expr.expr -> bool + + (** 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. + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) *) + val is_label_lit : Expr.expr -> bool + + (** 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. *) + val is_oeq : Expr.expr -> bool + + (** Creates a new constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + + (** Creates a new constant. *) + val mk_const_s : context -> string -> Sort.sort -> expr + + (** Creates a constant from the func_decl. *) + val mk_const_f : context -> FuncDecl.func_decl -> expr + + (** Creates a fresh constant with a name prefixed with a string. *) + val mk_fresh_const : context -> string -> Sort.sort -> expr + + (** Create a new function application. *) + val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr + + (** Create a numeral of a given sort. + @return A Term with the goven value and sort *) + val mk_numeral_string : context -> string -> Sort.sort -> expr + + (** Create a numeral 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. + @return A Term with the given value and sort *) + val mk_numeral_int : context -> int -> Sort.sort -> expr +end + +(** Boolean expressions *) +module Boolean : +sig + type bool_sort = BoolSort of Sort.sort + type bool_expr = BoolExpr of Expr.expr + + val expr_of_bool_expr : bool_expr -> Expr.expr + val sort_of_bool_sort : bool_sort -> Sort.sort + val bool_sort_of_sort : Sort.sort -> bool_sort + val bool_expr_of_expr : Expr.expr -> bool_expr + + (** Create a Boolean sort *) + val mk_sort : context -> bool_sort + + (** Create a Boolean constant. *) + val mk_const : context -> Symbol.symbol -> bool_expr + + (** Create a Boolean constant. *) + val mk_const_s : context -> string -> bool_expr + + (** The true Term. *) + val mk_true : context -> bool_expr + + (** The false Term. *) + val mk_false : context -> bool_expr + + (** Creates a Boolean value. *) + val mk_val : context -> bool -> bool_expr + + (** Creates the equality between two expr's. *) + val mk_eq : context -> Expr.expr -> Expr.expr -> bool_expr + + (** Creates a distinct term. *) + val mk_distinct : context -> Expr.expr list -> bool_expr + + (** Mk an expression representing not(a). *) + val mk_not : context -> bool_expr -> bool_expr + + (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) + val mk_ite : context -> bool_expr -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 iff t2. *) + val mk_iff : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 -> t2. *) + val mk_implies : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 xor t2. *) + val mk_xor : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing the AND of args *) + val mk_and : context -> bool_expr list -> bool_expr + + (** Create an expression representing the OR of args *) + val mk_or : context -> bool_expr list -> bool_expr +end + +(** Quantifier expressions *) +module Quantifier : +sig + type quantifier = Quantifier of Expr.expr + + val expr_of_quantifier : quantifier -> Expr.expr + val quantifier_of_expr : Expr.expr -> quantifier + + (** Quantifier patterns + + 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. *) + module Pattern : + sig + type pattern = Pattern of AST.ast + + val ast_of_pattern : pattern -> AST.ast + val pattern_of_ast : AST.ast -> pattern + + (** The number of terms in the pattern. *) + val get_num_terms : pattern -> int + + (** The terms in the pattern. *) + val get_terms : pattern -> Expr.expr list + + (** A string representation of the pattern. *) + val to_string : pattern -> string + end + + + (** 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 : expr ) appears, the higher is its + index. *) + val get_index : Expr.expr -> int + + (** Indicates whether the quantifier is universal. *) + val is_universal : quantifier -> bool + + (** Indicates whether the quantifier is existential. *) + val is_existential : quantifier -> bool + + (** The weight of the quantifier. *) + val get_weight : quantifier -> int + + (** The number of patterns. *) + val get_num_patterns : quantifier -> int + + (** The patterns. *) + val get_patterns : quantifier -> Pattern.pattern list + + (** The number of no-patterns. *) + val get_num_no_patterns : quantifier -> int + + (** The no-patterns. *) + val get_no_patterns : quantifier -> Pattern.pattern list + + (** The number of bound variables. *) + val get_num_bound : quantifier -> int + + (** The symbols for the bound variables. *) + val get_bound_variable_names : quantifier -> Symbol.symbol list + + (** The sorts of the bound variables. *) + val get_bound_variable_sorts : quantifier -> Sort.sort list + + (** The body of the quantifier. *) + val get_body : quantifier -> Boolean.bool_expr + + (** Creates a new bound variable. *) + val mk_bound : context -> int -> Sort.sort -> Expr.expr + + (** Create a quantifier pattern. *) + val mk_pattern : context -> Expr.expr list -> Pattern.pattern + + (** Create a universal Quantifier. *) + val mk_forall : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a universal Quantifier. *) + val mk_forall_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create an existential Quantifier. *) + val mk_exists : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create an existential Quantifier. *) + val mk_exists_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a Quantifier. *) + val mk_quantifier : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a Quantifier. *) + val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier +end + +(** Functions to manipulate Array expressions *) +module Array_ : +sig + type array_sort = ArraySort of Sort.sort + type array_expr = ArrayExpr of Expr.expr + + val sort_of_array_sort : array_sort -> Sort.sort + val array_sort_of_sort : Sort.sort -> array_sort + val expr_of_array_expr : array_expr -> Expr.expr + + val array_expr_of_expr : Expr.expr -> array_expr + + (** Create a new array sort. *) + val mk_sort : context -> Sort.sort -> Sort.sort -> 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. *) + val is_store : Expr.expr -> bool + + (** Indicates whether the term is an array select. *) + val is_select : Expr.expr -> bool + + (** 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. *) + val is_constant_array : Expr.expr -> bool + + (** Indicates whether the term is a default array. + For example default(const(v)) = v. The function is unary. *) + val is_default_array : Expr.expr -> bool + + (** 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. *) + val is_array_map : Expr.expr -> bool + + (** 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. *) + val is_as_array : Expr.expr -> bool + + (** Indicates whether the term is of an array sort. *) + val is_array : Expr.expr -> bool + + (** The domain of the array sort. *) + val get_domain : array_sort -> Sort.sort + + (** The range of the array sort. *) + val get_range : array_sort -> Sort.sort + + (** Create an array constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> array_expr + + (** Create an array constant. *) + val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> array_expr + + (** 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. + {!Array_.mk_sort} + {!mk_store} *) + val mk_select : context -> array_expr -> Expr.expr -> array_expr + + (** 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). + {!Array_.mk_sort} + {!mk_select} *) + val mk_store : context -> array_expr -> Expr.expr -> Expr.expr -> array_expr + + (** Create a constant array. + + The resulting term is an array, such that a selecton an arbitrary index + produces the value v. + {!Array_.mk_sort} + {!mk_select} *) + val mk_const_array : context -> Sort.sort -> Expr.expr -> array_expr + + (** 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]. + {!Array_.mk_sort} + {!mk_select} + {!mk_store} *) + val mk_map : context -> FuncDecl.func_decl -> array_expr list -> array_expr + + (** Access the array default value. + + Produces the default range value, for arrays that can be represented as + finite maps with a default range value. *) + val mk_term_array : context -> array_expr -> array_expr +end + +(** Functions to manipulate Set expressions *) +module Set : +sig + type set_sort = SetSort of Sort.sort + + val sort_of_set_sort : set_sort -> Sort.sort + + (** Create a set type. *) + val mk_sort : context -> Sort.sort -> set_sort + + (** Indicates whether the term is set union *) + val is_union : Expr.expr -> bool + + (** Indicates whether the term is set intersection *) + val is_intersect : Expr.expr -> bool + + (** Indicates whether the term is set difference *) + val is_difference : Expr.expr -> bool + + (** Indicates whether the term is set complement *) + val is_complement : Expr.expr -> bool + + (** Indicates whether the term is set subset *) + val is_subset : Expr.expr -> bool + + (** Create an empty set. *) + val mk_empty : context -> Sort.sort -> Expr.expr + + (** Create the full set. *) + val mk_full : context -> Sort.sort -> Expr.expr + + (** Add an element to the set. *) + val mk_set_add : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Remove an element from a set. *) + val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Take the union of a list of sets. *) + val mk_union : context -> Expr.expr list -> Expr.expr + + (** Take the intersection of a list of sets. *) + val mk_intersection : context -> Expr.expr list -> Expr.expr + + (** Take the difference between two sets. *) + val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Take the complement of a set. *) + val mk_complement : context -> Expr.expr -> Expr.expr + + (** Check for set membership. *) + val mk_membership : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Check for subsetness of sets. *) + val mk_subset : context -> Expr.expr -> Expr.expr -> Expr.expr +end + +(** Functions to manipulate Finite Domain expressions *) +module FiniteDomain : +sig + type finite_domain_sort = FiniteDomainSort of Sort.sort + + val sort_of_finite_domain_sort : finite_domain_sort -> Sort.sort + val finite_domain_sort_of_sort : Sort.sort -> finite_domain_sort + + (** Create a new finite domain sort. *) + val mk_sort : context -> Symbol.symbol -> int -> finite_domain_sort + + (** Create a new finite domain sort. *) + val mk_sort_s : context -> string -> int -> finite_domain_sort + + (** Indicates whether the term is of an array sort. *) + val is_finite_domain : Expr.expr -> bool + + (** Indicates whether the term is a less than predicate over a finite domain. *) + val is_lt : Expr.expr -> bool + + (** The size of the finite domain sort. *) + val get_size : finite_domain_sort -> int +end + + +(** Functions to manipulate Relation expressions *) +module Relation : +sig + type relation_sort = RelationSort of Sort.sort + + val sort_of_relation_sort : relation_sort -> Sort.sort + val relation_sort_of_sort : Sort.sort -> relation_sort + + (** Indicates whether the term is of a relation sort. *) + val is_relation : Expr.expr -> bool + + (** 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. *) + val is_store : Expr.expr -> bool + + (** Indicates whether the term is an empty relation *) + val is_empty : Expr.expr -> bool + + (** Indicates whether the term is a test for the emptiness of a relation *) + val is_is_empty : Expr.expr -> bool + + (** Indicates whether the term is a relational join *) + val is_join : Expr.expr -> bool + + (** Indicates whether the term is the union or convex hull of two relations. + The function takes two arguments. *) + val is_union : Expr.expr -> bool + + (** Indicates whether the term is the widening of two relations + The function takes two arguments. *) + val is_widen : Expr.expr -> bool + + (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). + The function takes one argument. *) + val is_project : Expr.expr -> bool + + (** 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. *) + val is_filter : Expr.expr -> bool + + (** 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. *) + val is_negation_filter : Expr.expr -> bool + + (** 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. *) + val is_rename : Expr.expr -> bool + + (** Indicates whether the term is the complement of a relation *) + val is_complement : Expr.expr -> bool + + (** 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. *) + val is_select : Expr.expr -> bool + + (** 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 {!is_union} + to perform destructive updates to the first argument. *) + val is_clone : Expr.expr -> bool + + (** The arity of the relation sort. *) + val get_arity : relation_sort -> int + + (** The sorts of the columns of the relation sort. *) + val get_column_sorts : relation_sort -> relation_sort list +end + +(** Functions to manipulate Datatype expressions *) +module Datatype : +sig + type datatype_sort = DatatypeSort of Sort.sort + type datatype_expr = DatatypeExpr of Expr.expr + + val sort_of_datatype_sort : datatype_sort -> Sort.sort + val datatype_sort_of_sort : Sort.sort -> datatype_sort + val expr_of_datatype_expr : datatype_expr -> Expr.expr + val datatype_expr_of_expr : Expr.expr -> datatype_expr + + (** Datatype Constructors *) + module Constructor : + sig + type constructor + + (** The number of fields of the constructor. *) + val get_num_fields : constructor -> int + + (** The function declaration of the constructor. *) + val get_constructor_decl : constructor -> FuncDecl.func_decl + + (** The function declaration of the tester. *) + val get_tester_decl : constructor -> FuncDecl.func_decl + + (** The function declarations of the accessors *) + val get_accessor_decls : constructor -> FuncDecl.func_decl list + end + + (** Create a datatype 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. *) + val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + + (** Create a datatype 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. *) + val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + + (** Create a new datatype sort. *) + val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> datatype_sort + + (** Create a new datatype sort. *) + val mk_sort_s : context -> string -> Constructor.constructor list -> datatype_sort + + (** Create mutually recursive datatypes. *) + val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> datatype_sort list + + (** Create mutually recursive data-types. *) + val mk_sorts_s : context -> string list -> Constructor.constructor list list -> datatype_sort list + + + (** The number of constructors of the datatype sort. *) + val get_num_constructors : datatype_sort -> int + + (** The constructors. *) + val get_constructors : datatype_sort -> FuncDecl.func_decl list + + (** The recognizers. *) + val get_recognizers : datatype_sort -> FuncDecl.func_decl list + + (** The constructor accessors. *) + val get_accessors : datatype_sort -> FuncDecl.func_decl list list +end + +(** Functions to manipulate Enumeration expressions *) +module Enumeration : +sig + type enum_sort = EnumSort of Sort.sort + + val sort_of_enum_sort : enum_sort -> Sort.sort + + (** Create a new enumeration sort. *) + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> enum_sort + + (** Create a new enumeration sort. *) + val mk_sort_s : context -> string -> string list -> enum_sort + + (** The function declarations of the constants in the enumeration. *) + val get_const_decls : enum_sort -> FuncDecl.func_decl list + + (** The test predicates for the constants in the enumeration. *) + val get_tester_decls : enum_sort -> FuncDecl.func_decl list +end + +(** Functions to manipulate List expressions *) +module List_ : +sig + type list_sort = ListSort of Sort.sort + + val sort_of_list_sort : list_sort -> Sort.sort + + (** Create a new list sort. *) + val mk_sort : context -> Symbol.symbol -> Sort.sort -> list_sort + + (** Create a new list sort. *) + val mk_list_s : context -> string -> Sort.sort -> list_sort + + (** The declaration of the nil function of this list sort. *) + val get_nil_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the isNil function of this list sort. *) + val get_is_nil_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the cons function of this list sort. *) + val get_cons_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the isCons function of this list sort. *) + val get_is_cons_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the head function of this list sort. *) + val get_head_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the tail function of this list sort. *) + val get_tail_decl : list_sort -> FuncDecl.func_decl + + (** The empty list. *) + val nil : list_sort -> Expr.expr +end + +(** Functions to manipulate Tuple expressions *) +module Tuple : +sig + type tuple_sort = TupleSort of Sort.sort + + val sort_of_tuple_sort : tuple_sort -> Sort.sort + + (** Create a new tuple sort. *) + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> tuple_sort + + (** The constructor function of the tuple. *) + val get_mk_decl : tuple_sort -> FuncDecl.func_decl + + (** The number of fields in the tuple. *) + val get_num_fields : tuple_sort -> int + + (** The field declarations. *) + val get_field_decls : tuple_sort -> FuncDecl.func_decl list +end + +(** Functions to manipulate arithmetic expressions *) +module rec Arithmetic : +sig + type arith_sort = ArithSort of Sort.sort + type arith_expr = ArithExpr of Expr.expr + + val sort_of_arith_sort : Arithmetic.arith_sort -> Sort.sort + val arith_sort_of_sort : Sort.sort -> Arithmetic.arith_sort + val expr_of_arith_expr : Arithmetic.arith_expr -> Expr.expr + val arith_expr_of_expr : Expr.expr -> Arithmetic.arith_expr + + (** Integer Arithmetic *) + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val arith_sort_of_int_sort : Arithmetic.Integer.int_sort -> Arithmetic.arith_sort + val int_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Integer.int_sort + val arith_expr_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.arith_expr + val int_expr_of_int_num : Arithmetic.Integer.int_num -> Arithmetic.Integer.int_expr + val int_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Integer.int_expr + val int_num_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.Integer.int_num + + (** Create a new integer sort. *) + val mk_sort : context -> int_sort + + (** Retrieve the int value. *) + val get_int : int_num -> int + + (** Returns a string representation of the numeral. *) + val to_string : int_num -> string + + (** Creates an integer constant. *) + val mk_int_const : context -> Symbol.symbol -> int_expr + + (** Creates an integer constant. *) + val mk_int_const_s : context -> string -> int_expr + + (** Create an expression representing t1 mod t2. + The arguments must have int type. *) + val mk_mod : context -> int_expr -> int_expr -> int_expr + + (** Create an expression representing t1 rem t2. + The arguments must have int type. *) + val mk_rem : context -> int_expr -> int_expr -> int_expr + + (** Create an integer numeral. *) + val mk_int_numeral_s : context -> string -> int_num + + (** Create an integer numeral. + @return A Term with the given value and sort Integer *) + val mk_int_numeral_i : context -> int -> int_num + + (** 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. *) + val mk_int2real : context -> int_expr -> Real.real_expr + + (** Create an n-bit bit-vector from an 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. *) + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end + + (** Real Arithmetic *) + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort + val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort + val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr + val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr + val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr + val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num + + (** Create a real sort. *) + val mk_sort : context -> real_sort + + (** The numerator of a rational numeral. *) + val get_numerator : rat_num -> Integer.int_num + + (** The denominator of a rational numeral. *) + val get_denominator : rat_num -> Integer.int_num + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as indicated by the int argument.*) + val to_decimal_string : rat_num -> int -> string + + (** Returns a string representation of the numeral. *) + val to_string : rat_num -> string + + (** Creates a real constant. *) + val mk_real_const : context -> Symbol.symbol -> real_expr + + (** Creates a real constant. *) + val mk_real_const_s : context -> string -> real_expr + + (** Create a real numeral from a fraction. + @return A Term with rational value and sort Real + {!mk_numeral_s} *) + val mk_numeral_nd : context -> int -> int -> rat_num + + (** Create a real numeral. + @return A Term with the given value and sort Real *) + val mk_numeral_s : context -> string -> rat_num + + (** Create a real numeral. + @return A Term with the given value and sort Real *) + val mk_numeral_i : context -> int -> rat_num + + (** Creates an expression that checks whether a real number is an integer. *) + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + + (** 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. *) + val mk_real2int : context -> real_expr -> Integer.int_expr + end + + (** Algebraic Numbers *) + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : Arithmetic.AlgebraicNumber.algebraic_num -> Arithmetic.arith_expr + val algebraic_num_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.AlgebraicNumber.algebraic_num + + (** Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) + val to_upper : algebraic_num -> int -> Real.rat_num + + (** Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) + val to_lower : algebraic_num -> int -> Real.rat_num + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as the int argument provided.*) + val to_decimal_string : algebraic_num -> int -> string + + (** Returns a string representation of the numeral. *) + val to_string : algebraic_num -> string + end + + (** Indicates whether the term is of integer sort. *) + val is_int : Expr.expr -> bool + + (** Indicates whether the term is an arithmetic numeral. *) + val is_arithmetic_numeral : Expr.expr -> bool + + (** Indicates whether the term is a less-than-or-equal *) + val is_le : Expr.expr -> bool + + (** Indicates whether the term is a greater-than-or-equal *) + val is_ge : Expr.expr -> bool + + (** Indicates whether the term is a less-than *) + val is_lt : Expr.expr -> bool + + (** Indicates whether the term is a greater-than *) + val is_gt : Expr.expr -> bool + + (** Indicates whether the term is addition (binary) *) + val is_add : Expr.expr -> bool + + (** Indicates whether the term is subtraction (binary) *) + val is_sub : Expr.expr -> bool + + (** Indicates whether the term is a unary minus *) + val is_uminus : Expr.expr -> bool + + (** Indicates whether the term is multiplication (binary) *) + val is_mul : Expr.expr -> bool + + (** Indicates whether the term is division (binary) *) + val is_div : Expr.expr -> bool + + (** Indicates whether the term is integer division (binary) *) + val is_idiv : Expr.expr -> bool + + (** Indicates whether the term is remainder (binary) *) + val is_remainder : Expr.expr -> bool + + (** Indicates whether the term is modulus (binary) *) + val is_modulus : Expr.expr -> bool + + (** Indicates whether the term is a coercion of integer to real (unary) *) + val is_inttoreal : Expr.expr -> bool + + (** Indicates whether the term is a coercion of real to integer (unary) *) + val is_real_to_int : Expr.expr -> bool + + (** Indicates whether the term is a check that tests whether a real is integral (unary) *) + val is_real_is_int : Expr.expr -> bool + + (** Indicates whether the term is of sort real. *) + val is_real : Expr.expr -> bool + + (** Indicates whether the term is an integer numeral. *) + val is_int_numeral : Expr.expr -> bool + + (** Indicates whether the term is a real numeral. *) + val is_rat_num : Expr.expr -> bool + + (** Indicates whether the term is an algebraic number *) + val is_algebraic_number : Expr.expr -> bool + + (** Create an expression representing t[0] + t[1] + .... *) + val mk_add : context -> arith_expr list -> arith_expr + + (** Create an expression representing t[0] * t[1] * .... *) + val mk_mul : context -> arith_expr list -> arith_expr + + (** Create an expression representing t[0] - t[1] - .... *) + val mk_sub : context -> arith_expr list -> arith_expr + + (** Create an expression representing -t. *) + val mk_unary_minus : context -> arith_expr -> arith_expr + + (** Create an expression representing t1 / t2. *) + val mk_div : context -> arith_expr -> arith_expr -> arith_expr + + (** Create an expression representing t1 ^ t2. *) + val mk_power : context -> arith_expr -> arith_expr -> arith_expr + + (** Create an expression representing t1 < t2 *) + val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 <= t2 *) + val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 > t2 *) + val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 >= t2 *) + val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr +end + +(** Functions to manipulate bit-vector expressions *) +and BitVector : +sig + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort + val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort + val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr + val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr + val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr + val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num + + (** Create a new bit-vector sort. *) + val mk_sort : context -> int -> bitvec_sort + + (** Indicates whether the terms is of bit-vector sort. *) + val is_bv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector numeral *) + val is_bv_numeral : Expr.expr -> bool + + (** Indicates whether the term is a one-bit bit-vector with value one *) + val is_bv_bit1 : Expr.expr -> bool + + (** Indicates whether the term is a one-bit bit-vector with value zero *) + val is_bv_bit0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unary minus *) + val is_bv_uminus : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector addition (binary) *) + val is_bv_add : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector subtraction (binary) *) + val is_bv_sub : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector multiplication (binary) *) + val is_bv_mul : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed division (binary) *) + val is_bv_sdiv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned division (binary) *) + val is_bv_udiv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed remainder (binary) *) + val is_bv_SRem : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) + val is_bv_urem : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed modulus *) + val is_bv_smod : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed division by zero *) + val is_bv_sdiv0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned division by zero *) + val is_bv_udiv0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed remainder by zero *) + val is_bv_srem0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned remainder by zero *) + val is_bv_urem0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed modulus by zero *) + val is_bv_smod0 : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) + val is_bv_ule : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector less-than-or-equal *) + val is_bv_sle : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) + val is_bv_uge : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) + val is_bv_sge : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector less-than *) + val is_bv_ult : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector less-than *) + val is_bv_slt : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector greater-than *) + val is_bv_ugt : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector greater-than *) + val is_bv_sgt : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise AND *) + val is_bv_and : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise OR *) + val is_bv_or : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NOT *) + val is_bv_not : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise XOR *) + val is_bv_xor : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NAND *) + val is_bv_nand : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NOR *) + val is_bv_nor : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise XNOR *) + val is_bv_xnor : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector concatenation (binary) *) + val is_bv_concat : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector sign extension *) + val is_bv_signextension : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector zero extension *) + val is_bv_zeroextension : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector extraction *) + val is_bv_extract : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector repetition *) + val is_bv_repeat : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector reduce OR *) + val is_bv_reduceor : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector reduce AND *) + val is_bv_reduceand : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector comparison *) + val is_bv_comp : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector shift left *) + val is_bv_shiftleft : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector logical shift right *) + val is_bv_shiftrightlogical : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector arithmetic shift left *) + val is_bv_shiftrightarithmetic : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector rotate left *) + val is_bv_rotateleft : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector rotate right *) + val is_bv_rotateright : Expr.expr -> bool + + (** 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. *) + val is_bv_rotateleftextended : Expr.expr -> bool + + (** 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. *) + val is_bv_rotaterightextended : Expr.expr -> bool + + (** 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. *) + + (** 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. *) + val is_int_to_bv : Expr.expr -> bool + + (** 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. *) + val is_bv_to_int : Expr.expr -> bool + + (** 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))) *) + val is_bv_carry : Expr.expr -> bool + + (** 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) *) + val is_bv_xor3 : Expr.expr -> bool + + (** The size of a bit-vector sort. *) + val get_size : bitvec_sort -> int + + (** Retrieve the int value. *) + val get_int : bitvec_num -> int + + (** Returns a string representation of the numeral. *) + val to_string : bitvec_num -> string + + (** Creates a bit-vector constant. *) + val mk_const : context -> Symbol.symbol -> int -> bitvec_expr + + (** Creates a bit-vector constant. *) + val mk_const_s : context -> string -> int -> bitvec_expr + + (** Bitwise negation. + The argument must have a bit-vector sort. *) + val mk_not : context -> bitvec_expr -> Expr.expr + + (** Take conjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. *) + val mk_redand : context -> bitvec_expr -> Expr.expr + + (** Take disjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. *) + val mk_redor : context -> bitvec_expr -> Expr.expr + + (** Bitwise conjunction. + The arguments must have a bit-vector sort. *) + val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise disjunction. + The arguments must have a bit-vector sort. *) + val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise XOR. + The arguments must have a bit-vector sort. *) + val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise NAND. + The arguments must have a bit-vector sort. *) + val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise NOR. + The arguments must have a bit-vector sort. *) + val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise XNOR. + The arguments must have a bit-vector sort. *) + val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Standard two's complement unary minus. + The arguments must have a bit-vector sort. *) + val mk_neg : context -> bitvec_expr -> bitvec_expr + + (** Two's complement addition. + The arguments must have the same bit-vector sort. *) + val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Two's complement subtraction. + The arguments must have the same bit-vector sort. *) + val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Two's complement multiplication. + The arguments must have the same bit-vector sort. *) + val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Unsigned less-than + + The arguments must have the same bit-vector sort. *) + val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed less-than + + The arguments must have the same bit-vector sort. *) + val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned less-than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed less-than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned greater than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed greater than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned greater-than. + + The arguments must have the same bit-vector sort. *) + val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed greater-than. + + The arguments must have the same bit-vector sort. *) + val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** 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). *) + val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bit-vector extraction. + + Extract the bits between two limits from a bitvector of + size m to yield a new bitvector of size n, where + n = high - low + 1. *) + val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + + (** Bit-vector repetition. *) + val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + + (** Shift left. + + It is equivalent to multiplication by 2^x where \c x is the value of third 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.*) + val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Logical shift right + + It is equivalent to unsigned division by 2^x where \c x is the value of the third 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. *) + val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Rotate Left. + Rotate bits of \c t to the left \c i times. *) + val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr + + (** Rotate Right. + Rotate bits of \c t to the right \c i times.*) + val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr + + (** Rotate Left. + Rotate bits of the second argument to the left.*) + val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Rotate Right. + Rotate bits of the second argument to the right. *) + val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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 the argument. + 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.*) + val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + + (** Create a predicate that checks that the bit-wise addition does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise addition does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise subtraction does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise subtraction does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise signed division does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise negation does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise multiplication does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise multiplication does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a bit-vector numeral. *) + val mk_numeral : context -> string -> int -> bitvec_num +end + +(** Functions to manipulate proof expressions *) +module Proof : +sig + (** Indicates whether the term is a Proof for the expression 'true'. *) + val is_true : Expr.expr -> bool + + (** Indicates whether the term is a proof for a fact asserted by the user. *) + val is_asserted : Expr.expr -> bool + + (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) + val is_goal : Expr.expr -> bool + + (** 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). *) + val is_modus_ponens : Expr.expr -> bool + + (** 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'. *) + val is_reflexivity : Expr.expr -> bool + + (** 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. *) + val is_symmetry : Expr.expr -> bool + + (** 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) *) + val is_transitivity : Expr.expr -> bool + + (** 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. *) + val is_Transitivity_star : Expr.expr -> bool + + (** 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. *) + val is_monotonicity : Expr.expr -> bool + + (** 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)) *) + val is_quant_intro : Expr.expr -> bool + + (** 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. *) + val is_distributivity : Expr.expr -> bool + + (** 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 *) + val is_and_elimination : Expr.expr -> bool + + (** 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) *) + val is_or_elimination : Expr.expr -> bool + + (** 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 : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) *) + val is_rewrite : Expr.expr -> bool + + (** 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) *) + val is_rewrite_star : Expr.expr -> bool + + (** 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. *) + val is_pull_quant : Expr.expr -> bool + + (** 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 *) + val is_pull_quant_star : Expr.expr -> bool + + (** 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 *) + val is_push_quant : Expr.expr -> bool + + (** 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. *) + val is_elim_unused_vars : Expr.expr -> bool + + (** Indicates whether the term is a proof for destructive equality resolution + + A proof for destructive equality resolution: + (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. + + This proof object has no antecedents. + + Several variables can be eliminated simultaneously. *) + val is_der : Expr.expr -> bool + + (** Indicates whether the term is a proof for quantifier instantiation + + A proof of (or (not (forall (x) (P x))) (P a)) *) + val is_quant_inst : Expr.expr -> bool + + (** Indicates whether the term is a hypthesis marker. + Mark a hypothesis in a natural deduction style proof. *) + val is_hypothesis : Expr.expr -> bool + + (** 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. *) + val is_lemma : Expr.expr -> bool + + (** 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') *) + val is_unit_resolution : Expr.expr -> bool + + (** Indicates whether the term is a proof by iff-true + + T1: p + [iff-true T1]: (iff p true) *) + val is_iff_true : Expr.expr -> bool + + (** Indicates whether the term is a proof by iff-false + + T1: (not p) + [iff-false T1]: (iff p false) *) + val is_iff_false : Expr.expr -> bool + + (** 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. *) + val is_commutativity : Expr.expr -> bool + + (** 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). *) + val is_def_axiom : Expr.expr -> bool + + (** 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) *) + val is_def_intro : Expr.expr -> bool + + (** 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. *) + val is_apply_def : Expr.expr -> bool + + (** Indicates whether the term is a proof iff-oeq + + T1: (iff p q) + [iff~ T1]: (~ p q) *) + val is_iff_oeq : Expr.expr -> bool + + (** 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'. *) + val is_nnf_pos : Expr.expr -> bool + + (** 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'))) *) + val is_nnf_neg : Expr.expr -> bool + + (** 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. *) + val is_nnf_star : Expr.expr -> bool + + (** 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. *) + val is_cnf_star : Expr.expr -> bool + + (** Indicates whether the term is a proof for a Skolemization step + + Proof for: + + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + + This proof object has no antecedents. *) + val is_skolemize : Expr.expr -> bool + + (** 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 *) + val is_modus_ponens_oeq : Expr.expr -> bool + + (** 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. *) + val is_theory_lemma : Expr.expr -> bool +end + +(** Goals + + A goal (aka problem). A goal is essentially a + of formulas, that can be solved and/or transformed using + tactics and solvers. *) +module Goal : +sig + type goal + + (** 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. *) + val get_precision : goal -> Z3enums.goal_prec + + (** Indicates whether the goal is precise. *) + val is_precise : goal -> bool + + (** Indicates whether the goal is an under-approximation. *) + val is_underapproximation : goal -> bool + + (** Indicates whether the goal is an over-approximation. *) + val is_overapproximation : goal -> bool + + (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) + val is_garbage : goal -> bool + + (** Adds the constraints to the given goal. *) + val assert_ : goal -> Boolean.bool_expr list -> unit + + (** Indicates whether the goal contains `false'. *) + val is_inconsistent : goal -> bool + + (** The depth of the goal. + This tracks how many transformations were applied to it. *) + val get_depth : goal -> int + + (** Erases all formulas from the given goal. *) + val reset : goal -> unit + + (** The number of formulas in the goal. *) + val get_size : goal -> int + + (** The formulas in the goal. *) + val get_formulas : goal -> Boolean.bool_expr list + + (** The number of formulas, subformulas and terms in the goal. *) + val get_num_exprs : goal -> int + + (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) + val is_decided_sat : goal -> bool + + (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) + val is_decided_unsat : goal -> bool + + (** Translates (copies) the Goal to another context.. *) + val translate : goal -> context -> goal + + (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) + val simplify : goal -> Params.params option -> goal + + (** Creates a new Goal. + + Note that the Context must have been created with proof generation support if + the fourth argument is set to true here. *) + val mk_goal : context -> bool -> bool -> bool -> goal + + (** A string representation of the Goal. *) + val to_string : goal -> string +end + +(** Models + + A Model contains interpretations (assignments) of constants and functions. *) +module Model : +sig + type model + + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. *) + module FuncInterp : + sig + type func_interp + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. *) + module FuncEntry : + sig + type func_entry + + (** Return the (symbolic) value of this entry. + *) + val get_value : func_entry -> Expr.expr + + (** The number of arguments of the entry. + *) + val get_num_args : func_entry -> int + + (** The arguments of the function entry. + *) + val get_args : func_entry -> Expr.expr list + + (** A string representation of the function entry. + *) + val to_string : func_entry -> string + end + + (** The number of entries in the function interpretation. *) + val get_num_entries : func_interp -> int + + (** The entries in the function interpretation *) + val get_entries : func_interp -> FuncEntry.func_entry list + + (** The (symbolic) `else' value of the function interpretation. *) + val get_else : func_interp -> Expr.expr + + (** The arity of the function interpretation *) + val get_arity : func_interp -> int + + (** A string representation of the function interpretation. *) + val to_string : func_interp -> string + end + + (** Retrieves the interpretation (the assignment) of a func_decl in the model. + An expression if the function has an interpretation in the model, null otherwise. *) + val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option + + (** Retrieves the interpretation (the assignment) of an expression in the model. + An expression if the constant has an interpretation in the model, null otherwise. *) + val get_const_interp_e : model -> Expr.expr -> Expr.expr option + + (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option + + (** The number of constant interpretations in the model. *) + val get_num_consts : model -> int + + (** The function declarations of the constants in the model. *) + val get_const_decls : model -> FuncDecl.func_decl list + + (** The number of function interpretations in the model. *) + val get_num_funcs : model -> int + + (** The function declarations of the function interpretations in the model. *) + val get_func_decls : model -> FuncDecl.func_decl list + + (** All symbols that have an interpretation in the model. *) + val get_decls : model -> FuncDecl.func_decl list + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) + exception ModelEvaluationFailedException of string + + (** Evaluates an expression in the current model. + + This function may fail if the argument contains quantifiers, + is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. + In this case a ModelEvaluationFailedException is thrown. + *) + val eval : model -> Expr.expr -> bool -> Expr.expr + + (** Alias for eval. *) + val evaluate : model -> Expr.expr -> bool -> Expr.expr + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + val get_num_sorts : model -> int + + (** 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. + {!get_num_sorts} + {!sort_universe} *) + val get_sorts : model -> Sort.sort list + + (** The finite set of distinct values that represent the interpretation of a sort. + {!get_sorts} + @returns A list of expressions, where each is an element of the universe of the sort *) + val sort_universe : model -> Sort.sort -> AST.ast list + + (** Conversion of models to strings. + A string representation of the model. *) + val to_string : model -> string +end + +(** Probes + + 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. +*) +module Probe : +sig + type probe + + (** Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) + val apply : probe -> Goal.goal -> float + + (** The number of supported Probes. *) + val get_num_probes : context -> int + + (** The names of all supported Probes. *) + val get_probe_names : context -> string list + + (** Returns a string containing a description of the probe with the given name. *) + val get_probe_description : context -> string -> string + + (** Creates a new Probe. *) + val mk_probe : context -> string -> probe + + (** Create a probe that always evaluates to a float value. *) + val const : context -> float -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is less than the value returned by second argument *) + val lt : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is greater than the value returned by second argument *) + val gt : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is less than or equal the value returned by second argument *) + val le : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is greater than or equal the value returned by second argument *) + val ge : context -> probe -> probe -> probe + + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is equal the value returned by second argument *) + val eq : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when both of two probes evaluate to "true". *) + val and_ : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when either of two probes evaluates to "true". *) + val or_ : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when another probe does not evaluate to "true". *) + val not_ : context -> probe -> probe +end + +(** Tactics + + Tactics are the basic building block for creating custom solvers for specific problem domains. + The complete list of tactics may be obtained using Context.get_num_tactics + and Context.get_tactic_names. + It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. +*) +module Tactic : +sig + type tactic + + (** Tactic application results + + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) + module ApplyResult : + sig + type apply_result + + (** The number of Subgoals. *) + val get_num_subgoals : apply_result -> int + + (** Retrieves the subgoals from the apply_result. *) + val get_subgoals : apply_result -> Goal.goal list + + (** Retrieves a subgoal from the apply_result. *) + val get_subgoal : apply_result -> int -> Goal.goal + + (** Convert a model for a subgoal into a model for the original + goal g, that the ApplyResult was obtained from. + #return A model for g *) + val convert_model : apply_result -> int -> Model.model -> Model.model + + (** A string representation of the ApplyResult. *) + val to_string : apply_result -> string + end + + (** A string containing a description of parameters accepted by the tactic. *) + val get_help : tactic -> string + + (** Retrieves parameter descriptions for Tactics. *) + val get_param_descrs : tactic -> Params.ParamDescrs.param_descrs + + (** Apply the tactic to the goal. *) + val apply : tactic -> Goal.goal -> Params.params option -> ApplyResult.apply_result + + (** The number of supported tactics. *) + val get_num_tactics : context -> int + + (** The names of all supported tactics. *) + val get_tactic_names : context -> string list + + (** Returns a string containing a description of the tactic with the given name. *) + val get_tactic_description : context -> string -> string + + (** Creates a new Tactic. *) + val mk_tactic : context -> string -> tactic + + (** Create a tactic that applies one tactic to a Goal and + then another one to every subgoal produced by the first one. *) + val and_then : context -> tactic -> tactic -> tactic list -> tactic + + (** Create a tactic that first applies one tactic to a Goal and + if it fails then returns the result of another tactic applied to the Goal. *) + val or_else : context -> tactic -> tactic -> tactic + + (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). + + If the tactic does not terminate within the timeout, then it fails. *) + val try_for : context -> tactic -> int -> tactic + + (** Create a tactic that applies one tactic to a given goal if the probe + evaluates to true. + + If the probe evaluates to false, then the new tactic behaves like the skip tactic. *) + val when_ : context -> Probe.probe -> tactic -> tactic + + (** Create a tactic that applies a tactic to a given goal if the probe + evaluates to true and another tactic otherwise. *) + val cond : context -> Probe.probe -> tactic -> tactic -> tactic + + (** Create a tactic that keeps applying one tactic until the goal is not + modified anymore or the maximum number of iterations is reached. *) + val repeat : context -> tactic -> int -> tactic + + (** Create a tactic that just returns the given goal. *) + val skip : context -> tactic + + (** Create a tactic always fails. *) + val fail : context -> tactic + + (** Create a tactic that fails if the probe evaluates to false. *) + val fail_if : context -> Probe.probe -> tactic + + (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) + or trivially unsatisfiable (i.e., contains `false'). *) + val fail_if_not_decided : context -> tactic + + (** Create a tactic that applies a tactic using the given set of parameters. *) + val using_params : context -> tactic -> Params.params -> tactic + + (** Create a tactic that applies a tactic using the given set of parameters. + Alias for UsingParams*) + val with_ : context -> tactic -> Params.params -> tactic + + (** Create a tactic that applies the given tactics in parallel. *) + val par_or : context -> tactic list -> tactic + + (** Create a tactic that applies a tactic to a given goal and then another tactic + to every subgoal produced by the first one. The subgoals are processed in parallel. *) + val par_and_then : context -> tactic -> tactic -> tactic + + (** Interrupt the execution of a Z3 procedure. + This procedure can be used to interrupt: solvers, simplifiers and tactics. *) + val interrupt : context -> unit +end + +(** Solvers *) +module Solver : +sig + type solver + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + + val string_of_status : status -> string + + (** Objects that track statistical information about solvers. *) + module Statistics : + sig + type statistics + + (** Statistical data is organized into pairs of \[Key, Entry\], where every + Entry is either a floating point or integer value. + *) + module Entry : + sig + type statistics_entry + + (** The key of the entry. *) + val get_key : statistics_entry -> string + + (** The int-value of the entry. *) + val get_int : statistics_entry -> int + + (** The float-value of the entry. *) + val get_float : statistics_entry -> float + + (** True if the entry is uint-valued. *) + val is_int : statistics_entry -> bool + + (** True if the entry is double-valued. *) + val is_float : statistics_entry -> bool + + (** The string representation of the the entry's value. *) + val to_string_value : statistics_entry -> string + + (** The string representation of the entry (key and value) *) + val to_string : statistics_entry -> string + end + + (** A string representation of the statistical data. *) + val to_string : statistics -> string + + (** The number of statistical data. *) + val get_size : statistics -> int + + (** The data entries. *) + val get_entries : statistics -> Entry.statistics_entry list + + (** The statistical counters. *) + val get_keys : statistics -> string list + + (** The value of a particular statistical counter. *) + val get : statistics -> string -> Entry.statistics_entry option + end + + (** A string that describes all available solver parameters. *) + val get_help : solver -> string + + (** Sets the solver parameters. *) + val set_parameters : solver -> Params.params -> unit + + (** Retrieves parameter descriptions for solver. *) + val get_param_descrs : solver -> Params.ParamDescrs.param_descrs + + (** The current number of backtracking points (scopes). + {!pop} + {!push} *) + val get_num_scopes : solver -> int + + (** Creates a backtracking point. + {!pop} *) + val push : solver -> unit + + (** Backtracks a number of backtracking points. + Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} + {!push} *) + val pop : solver -> int -> unit + + (** Resets the Solver. + This removes all assertions from the solver. *) + val reset : solver -> unit + + (** Assert a constraint (or multiple) into the solver. *) + val assert_ : solver -> Boolean.bool_expr list -> unit + + (** * Assert multiple constraints (cs) into the solver, and track them (in the + * unsat) core + * using the Boolean constants in ps. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) + val assert_and_track_a : solver -> Boolean.bool_expr list -> Boolean.bool_expr list -> unit + + (** * Assert a constraint (c) into the solver, and track it (in the unsat) core + * using the Boolean constant p. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) + val assert_and_track : solver -> Boolean.bool_expr -> Boolean.bool_expr -> unit + + (** The number of assertions in the solver. *) + val get_num_assertions : solver -> int + + (** The set of asserted formulas. *) + val get_assertions : solver -> Boolean.bool_expr list + + (** Checks whether the assertions in the solver are consistent or not. + + {!Model} + {!get_unsat_core} + {!Proof} *) + val check : solver -> Boolean.bool_expr list -> status + + (** The model of the last Check. + + The result is None if Check was not invoked before, + if its results was not SATISFIABLE, or if model production is not enabled. *) + val get_model : solver -> Model.model option + + (** 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. *) + val get_proof : solver -> Expr.expr option + + (** 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. *) + val get_unsat_core : solver -> AST.ast list + + (** A brief justification of why the last call to Check returned UNKNOWN. *) + val get_reason_unknown : solver -> string + + (** Solver statistics. *) + val get_statistics : solver -> Statistics.statistics + + (** 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. *) + val mk_solver : context -> Symbol.symbol option -> solver + + (** Creates a new (incremental) solver. + {!mk_solver} *) + val mk_solver_s : context -> string -> solver + + (** Creates a new (incremental) solver. *) + val mk_simple_solver : context -> solver + + (** 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. *) + val mk_solver_t : context -> Tactic.tactic -> solver + + (** A string representation of the solver. *) + val to_string : solver -> string +end + +(** Fixedpoint solving *) +module Fixedpoint : +sig + type fixedpoint + + (** A string that describes all available fixedpoint solver parameters. *) + val get_help : fixedpoint -> string + + (** Sets the fixedpoint solver parameters. *) + val set_params : fixedpoint -> Params.params -> unit + + (** Retrieves parameter descriptions for Fixedpoint solver. *) + val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs + + (** Assert a constraints into the fixedpoint solver. *) + val assert_ : fixedpoint -> Boolean.bool_expr list -> unit + + (** Register predicate as recursive relation. *) + val register_relation : fixedpoint -> FuncDecl.func_decl -> unit + + (** Add rule into the fixedpoint solver. *) + val add_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol option -> unit + + (** Add table fact to the fixedpoint solver. *) + val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit + + (** 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. *) + val query : fixedpoint -> Boolean.bool_expr -> Solver.status + + (** 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. *) + val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status + + (** Creates a backtracking point. + {!pop} *) + val push : fixedpoint -> unit + + (** Backtrack one backtracking point. + + Note that an exception is thrown if Pop is called without a corresponding Push + {!push} *) + val pop : fixedpoint -> unit + + (** Update named rule into in the fixedpoint solver. *) + val update_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol -> unit + + (** Retrieve satisfying instance or instances of solver, + or definitions for the recursive predicates that show unsatisfiability. *) + val get_answer : fixedpoint -> Expr.expr option + + (** Retrieve explanation why fixedpoint engine returned status Unknown. *) + val get_reason_unknown : fixedpoint -> string + + (** Retrieve the number of levels explored for a given predicate. *) + val get_num_levels : fixedpoint -> FuncDecl.func_decl -> int + + (** Retrieve the cover of a predicate. *) + val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option + + (** Add property about the predicate. + The property is added at level. *) + val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit + + (** Retrieve internal string representation of fixedpoint object. *) + val to_string : fixedpoint -> string + + (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) + val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol list -> unit + + (** Convert benchmark given as set of axioms, rules and queries to a string. *) + val to_string_q : fixedpoint -> Boolean.bool_expr list -> string + + (** Retrieve set of rules added to fixedpoint context. *) + val get_rules : fixedpoint -> Boolean.bool_expr list + + (** Retrieve set of assertions added to fixedpoint context. *) + val get_assertions : fixedpoint -> Boolean.bool_expr list + + (** Create a Fixedpoint context. *) + val mk_fixedpoint : context -> fixedpoint +end + +(** Global and context options + + Note: This module contains functions that set parameters/options for context + objects as well as functions that set options that are used globally, across + contexts.*) +module Options : +sig + (** 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. + {!get_param_value} *) + val update_param_value : context -> string -> string -> unit + + (** Get a configuration parameter. + + Returns None if the parameter value does not exist. + {!update_param_value} *) + val get_param_value : context -> string -> string option + + (** 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + {!AST.to_string} + {!Quantifier.Pattern.to_string} + {!FuncDecl.to_string} + {!Sort.to_string} *) + val set_print_mode : context -> Z3enums.ast_print_mode -> unit + + (** Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) + val toggle_warning_messages : bool -> unit +end + +(** Functions for handling SMT and SMT2 expressions and files *) +module SMT : +sig + (** Convert a benchmark into an SMT-LIB formatted string. + + @return A string representation of the benchmark. *) + val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr list -> Boolean.bool_expr -> string + + (** 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 in the third and fifth argument + don't need to match the names of the sorts and declarations in the arrays in the fourth + and sixth argument. This is a useful feature since we can use arbitrary names to + reference sorts and declarations. *) + val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit + + (** Parse the given file using the SMT-LIB parser. + {!parse_smtlib_string} *) + val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit + + (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_formulas : context -> int + + (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_formulas : context -> Boolean.bool_expr list + + (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_assumptions : context -> int + + (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_assumptions : context -> Boolean.bool_expr list + + (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_decls : context -> int + + (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_decls : context -> FuncDecl.func_decl list + + (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_sorts : context -> int + + (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_sorts : context -> Sort.sort list + + (** Parse the given string using the SMT-LIB2 parser. + + {!parse_smtlib_string} + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) + val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr + + (** Parse the given file using the SMT-LIB2 parser. + {!parse_smtlib2_string} *) + val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr +end + +(** Set a global (or module) parameter, which is shared by all Z3 contexts. + + When a Z3 module is initialized it will use the value of these parameters + when Z3_params objects are not provided. + The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. + The character '.' is a delimiter (more later). + The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. + Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". + This function can be used to set parameters for a specific Z3 module. + This can be done by using .. + For example: + (set_global_param "pp.decimal" "true") + will set the parameter "decimal" in the module "pp" to true. +*) +val set_global_param : string -> string -> unit + +(** Get a global (or module) parameter. + + Returns None if the parameter does not exist. + The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. + This function cannot be invoked simultaneously from different threads without synchronization. + The result string stored in param_value is stored in a shared location. +*) +val get_global_param : string -> string option + +(** Restore the value of all global (and module) parameters. + + This command will not affect already created objects (such as tactics and solvers) + {!set_global_param} +*) +val global_param_reset_all : unit From 13416de27e3e6f824f54f0cc1f09ee57da5da58a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 21 Feb 2013 14:17:35 +0000 Subject: [PATCH 065/248] ML API savegame Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 124 +++++++++++++++++++------------------- src/api/ml/z3.ml | 18 +++--- src/api/ml/z3_rich.ml | 43 +++++++------ src/api/ml/z3_rich.mli | 13 ++-- 4 files changed, 96 insertions(+), 102 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 823a08fe2..f7a4cbc00 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -162,70 +162,68 @@ let basic_tests ( ctx : context ) = else Printf.printf "Test passed.\n" ) ; - model_converter_test ctx -(* - // Real num/den test. - RatNum rn = ctx.MkReal(42, 43); - Expr inum = rn.Numerator; - Expr iden = rn.Denominator; - Console.WriteLine("Numerator: " + inum + " Denominator: " + iden); - if (inum.ToString() != "42" || iden.ToString() != "43") - throw new TestFailedException(); - - if (rn.ToDecimalString(3) != "0.976?") - throw new TestFailedException(); - - BigIntCheck(ctx, ctx.MkReal("-1231231232/234234333")); - BigIntCheck(ctx, ctx.MkReal("-123123234234234234231232/234234333")); - BigIntCheck(ctx, ctx.MkReal("-234234333")); - BigIntCheck(ctx, ctx.MkReal("234234333/2")); - - - string bn = "1234567890987654321"; - - if (ctx.MkInt(bn).BigInteger.ToString() != bn) - throw new TestFailedException(); - - if (ctx.MkBV(bn, 128).BigInteger.ToString() != bn) - throw new TestFailedException(); - - if (ctx.MkBV(bn, 32).BigInteger.ToString() == bn) - throw new TestFailedException(); - - // Error handling test. - try - { - IntExpr i = ctx.MkInt("1/2"); - throw new TestFailedException(); // unreachable - } - catch (Z3Exception) - { - } - } -*) + model_converter_test ctx ; + (* Real num/den test. *) + let rn = Real.mk_numeral_nd ctx 42 43 in + let inum = (get_numerator rn) in + let iden = get_denominator rn in + Printf.printf "Numerator: %s Denominator: %s\n" (Real.to_string inum) (Real.to_string iden) ; + if ((Real.to_string inum) <> "42" or (Real.to_string iden) <> "43") then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ; + if ((to_decimal_string rn 3) <> "0.976?") then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ; + if (to_decimal_string (Real.mk_numeral_s ctx "-1231231232/234234333") 5 <> "-5.25640?") then + raise (TestFailedException "") + else if (to_decimal_string (Real.mk_numeral_s ctx "-123123234234234234231232/234234333") 5 <> "-525641278361333.28170?") then + raise (TestFailedException "") + else if (to_decimal_string (Real.mk_numeral_s ctx "-234234333") 5 <> "-234234333") then + raise (TestFailedException "") + else if (to_decimal_string (Real.mk_numeral_s ctx "234234333/2") 5 <> "117117166.5") then + raise (TestFailedException "") + ; + (* Error handling test. *) + try ( + let i = Integer.mk_numeral_s ctx "1/2" in + raise (TestFailedException "") (* unreachable *) + ) + with Z3native.Exception(_) -> ( + Printf.printf "Exception caught, OK.\n" + ) let _ = - if not (Log.open_ "z3.log") then - raise (TestFailedException "Log couldn't be opened.") - else - ( - Printf.printf "Running Z3 version %s\n" Version.to_string ; - let cfg = [("model", "true"); ("proof", "false")] in - let ctx = (mk_context cfg) in - let is = (Symbol.mk_int ctx 42) in - let ss = (Symbol.mk_string ctx "mySymbol") in - let bs = (Boolean.mk_sort ctx) in - let ints = (Integer.mk_sort ctx) in - let rs = (Real.mk_sort ctx) in - Printf.printf "int symbol: %s\n" (Symbol.to_string is); - Printf.printf "string symbol: %s\n" (Symbol.to_string ss); - Printf.printf "bool sort: %s\n" (Sort.to_string bs); - Printf.printf "int sort: %s\n" (Sort.to_string ints); - Printf.printf "real sort: %s\n" (Sort.to_string rs); - basic_tests ctx ; - Printf.printf "Disposing...\n"; - Gc.full_major () - ); - Printf.printf "Exiting.\n"; + try ( + if not (Log.open_ "z3.log") then + raise (TestFailedException "Log couldn't be opened.") + else + ( + Printf.printf "Running Z3 version %s\n" Version.to_string ; + let cfg = [("model", "true"); ("proof", "false")] in + let ctx = (mk_context cfg) in + let is = (Symbol.mk_int ctx 42) in + let ss = (Symbol.mk_string ctx "mySymbol") in + let bs = (Boolean.mk_sort ctx) in + let ints = (Integer.mk_sort ctx) in + let rs = (Real.mk_sort ctx) in + Printf.printf "int symbol: %s\n" (Symbol.to_string is); + Printf.printf "string symbol: %s\n" (Symbol.to_string ss); + Printf.printf "bool sort: %s\n" (Sort.to_string bs); + Printf.printf "int sort: %s\n" (Sort.to_string ints); + Printf.printf "real sort: %s\n" (Sort.to_string rs); + basic_tests ctx ; + Printf.printf "Disposing...\n"; + Gc.full_major () + ); + Printf.printf "Exiting.\n" ; + exit 0 + ) with Z3native.Exception(msg) -> ( + Printf.printf "Z3 EXCEPTION: %s\n" msg ; + exit 1 + ) ;; diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 0676f1a39..e62732924 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -11,7 +11,6 @@ open Z3enums let null = Z3native.mk_null() let is_null o = (Z3native.is_null o) - (* Internal types *) type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } type context = z3_native_context @@ -21,7 +20,6 @@ type z3_native_object = { mutable m_n_obj : Z3native.ptr ; inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - (** Internal stuff *) module Internal = @@ -1455,11 +1453,11 @@ struct let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) - let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = Expr.mk_const ctx name (mk_sort ctx) - let mk_int_const_s ( ctx : context ) ( name : string ) = - mk_int_const ctx (Symbol.mk_string ctx name) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) let mk_mod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) @@ -1467,10 +1465,10 @@ struct let mk_rem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_int_numeral_s ( ctx : context ) ( v : string ) = + let mk_numeral_s ( ctx : context ) ( v : string ) = expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) - let mk_int_numeral_i ( ctx : context ) ( v : int ) = + let mk_numeral_i ( ctx : context ) ( v : int ) = expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) let mk_int2real ( ctx : context ) ( t : expr ) = @@ -1496,11 +1494,11 @@ struct let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) - let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = Expr.mk_const ctx name (mk_sort ctx) - let mk_real_const_s ( ctx : context ) ( name : string ) = - mk_real_const ctx (Symbol.mk_string ctx name) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = if (den == 0) then diff --git a/src/api/ml/z3_rich.ml b/src/api/ml/z3_rich.ml index 052ca5e22..0c2f95b6b 100644 --- a/src/api/ml/z3_rich.ml +++ b/src/api/ml/z3_rich.ml @@ -1,4 +1,4 @@ -(** +\(** The Z3 ML/Ocaml Interface. Copyright (C) 2012 Microsoft Corporation @@ -11,7 +11,6 @@ open Z3enums let null = Z3native.mk_null() let is_null o = (Z3native.is_null o) - (* Internal types *) type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } type context = z3_native_context @@ -1679,12 +1678,12 @@ sig val mk_sort : context -> int_sort val get_int : int_num -> int val to_string : int_num -> string - val mk_int_const : context -> Symbol.symbol -> int_expr - val mk_int_const_s : context -> string -> int_expr + val mk_const : context -> Symbol.symbol -> int_expr + val mk_const_s : context -> string -> int_expr val mk_mod : context -> int_expr -> int_expr -> int_expr val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_int_numeral_s : context -> string -> int_num - val mk_int_numeral_i : context -> int -> int_num + val mk_numeral_s : context -> string -> int_num + val mk_numeral_i : context -> int -> int_num val mk_int2real : context -> int_expr -> Real.real_expr val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr end @@ -1709,8 +1708,8 @@ sig val get_denominator : rat_num -> Integer.int_num val to_decimal_string : rat_num -> int -> string val to_string : rat_num -> string - val mk_real_const : context -> Symbol.symbol -> real_expr - val mk_real_const_s : context -> string -> real_expr + val mk_const : context -> Symbol.symbol -> real_expr + val mk_const_s : context -> string -> real_expr val mk_numeral_nd : context -> int -> int -> rat_num val mk_numeral_s : context -> string -> rat_num val mk_numeral_i : context -> int -> rat_num @@ -1816,12 +1815,12 @@ end = struct val mk_sort : context -> int_sort val get_int : int_num -> int val to_string : int_num -> string - val mk_int_const : context -> Symbol.symbol -> int_expr - val mk_int_const_s : context -> string -> int_expr + val mk_const : context -> Symbol.symbol -> int_expr + val mk_const_s : context -> string -> int_expr val mk_mod : context -> int_expr -> int_expr -> int_expr val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_int_numeral_s : context -> string -> int_num - val mk_int_numeral_i : context -> int -> int_num + val mk_numeral_s : context -> string -> int_num + val mk_numeral_i : context -> int -> int_num val mk_int2real : context -> int_expr -> Real.real_expr val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr end = struct @@ -1884,11 +1883,11 @@ end = struct let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) - let mk_int_const_s ( ctx : context ) ( name : string ) = - mk_int_const ctx (Symbol.mk_string ctx name) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) @@ -1896,10 +1895,10 @@ end = struct let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) - let mk_int_numeral_s ( ctx : context ) ( v : string ) = + let mk_numeral_s ( ctx : context ) ( v : string ) = int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - let mk_int_numeral_i ( ctx : context ) ( v : int ) = + let mk_numeral_i ( ctx : context ) ( v : int ) = int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) let mk_int2real ( ctx : context ) ( t : int_expr ) = @@ -1930,8 +1929,8 @@ end = struct val get_denominator : rat_num -> Integer.int_num val to_decimal_string : rat_num -> int -> string val to_string : rat_num -> string - val mk_real_const : context -> Symbol.symbol -> real_expr - val mk_real_const_s : context -> string -> real_expr + val mk_const : context -> Symbol.symbol -> real_expr + val mk_const_s : context -> string -> real_expr val mk_numeral_nd : context -> int -> int -> rat_num val mk_numeral_s : context -> string -> rat_num val mk_numeral_i : context -> int -> rat_num @@ -2002,11 +2001,11 @@ end = struct let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) - let mk_real_const_s ( ctx : context ) ( name : string ) = - mk_real_const ctx (Symbol.mk_string ctx name) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = if (den == 0) then diff --git a/src/api/ml/z3_rich.mli b/src/api/ml/z3_rich.mli index 8b6681e11..f2ecd326d 100644 --- a/src/api/ml/z3_rich.mli +++ b/src/api/ml/z3_rich.mli @@ -34,7 +34,6 @@ type context (** Create a context object *) val mk_context : (string * string) list -> context - (** 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. *) @@ -1219,10 +1218,10 @@ sig val to_string : int_num -> string (** Creates an integer constant. *) - val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_const : context -> Symbol.symbol -> int_expr (** Creates an integer constant. *) - val mk_int_const_s : context -> string -> int_expr + val mk_const_s : context -> string -> int_expr (** Create an expression representing t1 mod t2. The arguments must have int type. *) @@ -1233,11 +1232,11 @@ sig val mk_rem : context -> int_expr -> int_expr -> int_expr (** Create an integer numeral. *) - val mk_int_numeral_s : context -> string -> int_num + val mk_numeral_s : context -> string -> int_num (** Create an integer numeral. @return A Term with the given value and sort Integer *) - val mk_int_numeral_i : context -> int -> int_num + val mk_numeral_i : context -> int -> int_num (** Coerce an integer to a real. @@ -1291,10 +1290,10 @@ sig val to_string : rat_num -> string (** Creates a real constant. *) - val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_const : context -> Symbol.symbol -> real_expr (** Creates a real constant. *) - val mk_real_const_s : context -> string -> real_expr + val mk_const_s : context -> string -> real_expr (** Create a real numeral from a fraction. @return A Term with rational value and sort Real From 74ab6dbd2262509881d7d72e5dcbe6fc0b02d949 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 21 Feb 2013 18:53:29 +0000 Subject: [PATCH 066/248] ML API: bugfix Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index a0b7e6250..44d871348 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1339,9 +1339,10 @@ def mk_ml(): ml_wrapper.write(' // upon errors, but the actual error handling is done by throwing exceptions in the\n') ml_wrapper.write(' // wrappers below.\n') ml_wrapper.write('}\n\n') - ml_wrapper.write('void n_set_internal_error_handler(Z3_context c)\n') + ml_wrapper.write('void n_set_internal_error_handler(value a0)\n') ml_wrapper.write('{\n') - ml_wrapper.write(' Z3_set_error_handler(c, MLErrorHandler);\n') + ml_wrapper.write(' Z3_context _a0 = * (Z3_context*) Data_custom_val(a0);\n') + ml_wrapper.write(' Z3_set_error_handler(_a0, MLErrorHandler);\n') ml_wrapper.write('}\n\n') for name, result, params in _dotnet_decls: ip = inparams(params) From c37eb794c2d14b710cf8f281c0008781251eac13 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 26 Feb 2013 19:45:45 +0000 Subject: [PATCH 067/248] ML API: renamed assert_ to add Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 24 ++++++++++++------------ src/api/ml/z3.ml | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index f7a4cbc00..c9ed1d948 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -29,11 +29,11 @@ let model_converter_test ( ctx : context ) = let xr = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Real.mk_sort ctx)) in let yr = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Real.mk_sort ctx)) in let g4 = (mk_goal ctx true false false ) in - (Goal.assert_ g4 [ (mk_gt ctx xr (Real.mk_numeral_nd ctx 10 1)) ]) ; - (Goal.assert_ g4 [ (mk_eq ctx + (Goal.add g4 [ (mk_gt ctx xr (Real.mk_numeral_nd ctx 10 1)) ]) ; + (Goal.add g4 [ (mk_eq ctx yr (Arithmetic.mk_add ctx [ xr; (Real.mk_numeral_nd ctx 1 1) ])) ]) ; - (Goal.assert_ g4 [ (mk_gt ctx yr (Real.mk_numeral_nd ctx 1 1)) ]) ; + (Goal.add g4 [ (mk_gt ctx yr (Real.mk_numeral_nd ctx 1 1)) ]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in if ((get_num_subgoals ar) == 1 && @@ -53,7 +53,7 @@ let model_converter_test ( ctx : context ) = Printf.printf "Test passed.\n" ; let solver = (mk_solver ctx None) in - let f e = (Solver.assert_ solver [ e ]) in + let f e = (Solver.add solver [ e ]) in ignore (List.map f (get_formulas (get_subgoal ar 0))) ; let q = (check solver []) in if q != SATISFIABLE then @@ -88,12 +88,12 @@ let basic_tests ( ctx : context ) = let trivial_eq = (mk_eq ctx fapp fapp) in let nontrivial_eq = (mk_eq ctx fapp fapp2) in let g = (mk_goal ctx true false false) in - (Goal.assert_ g [ trivial_eq ]) ; - (Goal.assert_ g [ nontrivial_eq ]) ; + (Goal.add g [ trivial_eq ]) ; + (Goal.add g [ nontrivial_eq ]) ; Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; ( let solver = (mk_solver ctx None) in - (List.iter (fun a -> (Solver.assert_ solver [ a ])) (get_formulas g)) ; + (List.iter (fun a -> (Solver.add solver [ a ])) (get_formulas g)) ; if (check solver []) != SATISFIABLE then raise (TestFailedException "") else @@ -116,7 +116,7 @@ let basic_tests ( ctx : context ) = else Printf.printf "Test passed.\n" ); - (Goal.assert_ g [ (mk_eq ctx + (Goal.add g [ (mk_eq ctx (mk_numeral_int ctx 1 (BitVector.mk_sort ctx 32)) (mk_numeral_int ctx 2 (BitVector.mk_sort ctx 32))) ] ) ; @@ -139,7 +139,7 @@ let basic_tests ( ctx : context ) = ); ( let g2 = (mk_goal ctx true true false) in - (Goal.assert_ g2 [ (Boolean.mk_false ctx) ]) ; + (Goal.add g2 [ (Boolean.mk_false ctx) ]) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then @@ -151,10 +151,10 @@ let basic_tests ( ctx : context ) = let g3 = (mk_goal ctx true true false) in let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Integer.mk_sort ctx)) in let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Integer.mk_sort ctx)) in - (Goal.assert_ g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (Integer.mk_sort ctx))) ]) ; - (Goal.assert_ g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (Integer.mk_sort ctx))) ]) ; + (Goal.add g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (Integer.mk_sort ctx))) ]) ; + (Goal.add g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (Integer.mk_sort ctx))) ]) ; let constr = (mk_eq ctx xc yc) in - (Goal.assert_ g3 [ constr ] ) ; + (Goal.add g3 [ constr ] ) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index e62732924..8eb5427bb 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1850,7 +1850,7 @@ struct let is_garbage ( x : goal ) = (get_precision x) == GOAL_UNDER_OVER - let assert_ ( x : goal ) ( constraints : expr list ) = + let add ( x : goal ) ( constraints : expr list ) = let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e) in ignore (List.map f constraints) ; () @@ -2370,11 +2370,11 @@ struct let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - let assert_ ( x : solver ) ( constraints : expr list ) = + let add ( x : solver ) ( constraints : expr list ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in ignore (List.map f constraints) - let assert_and_track_a ( x : solver ) ( cs : expr list ) ( ps : expr list ) = + let assert_and_track_l ( x : solver ) ( cs : expr list ) ( ps : expr list ) = if ((List.length cs) != (List.length ps)) then raise (Z3native.Exception "Argument size mismatch") else @@ -2473,7 +2473,7 @@ struct let get_param_descrs ( x : fixedpoint ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - let assert_ ( x : fixedpoint ) ( constraints : expr list ) = + let add ( x : fixedpoint ) ( constraints : expr list ) = let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in ignore (List.map f constraints) ; () From 17005a413b346ec04d9baaa68ceee87858721346 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 3 Jun 2013 18:26:07 +0100 Subject: [PATCH 068/248] Removed unnecessary file Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/README-win | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/api/ml/README-win diff --git a/src/api/ml/README-win b/src/api/ml/README-win deleted file mode 100644 index 82ddc2652..000000000 --- a/src/api/ml/README-win +++ /dev/null @@ -1,23 +0,0 @@ -The OCaml API for Z3 was tested using OCaml 3.12.1. -You also need CamlIDL to be able to generate the OCaml API. - -- To download OCaml: - http://caml.inria.fr/ocaml/ - -- To download CamlIDL: - http://forge.ocamlcore.org/projects/camlidl/ - -- To build the OCaml API for Z3: - .\build-lib.cmd - -Remark: The OCaml and C compiler tool chains must be configured in your environment. -Running from the Visual Studio Command Prompt configures the Microsoft C compiler. - -Remark: Building the OCaml API copies some pathnames into files, -so the OCaml API must be recompiled if the Z3 library files are moved. - -See ..\examples\ocaml\build-test.cmd for an example of how to compile and link with Z3. - -Acknowledgements: -The OCaml interface for Z3 was written by Josh Berdine and Jakob Lichtenberg. -Many thanks to them! From c0df7640396a16c4ea12619997d7917f9cf53ef6 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 3 Jun 2013 18:51:40 +0100 Subject: [PATCH 069/248] Updates to ML API. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 43 ++++----- src/api/ml/z3.mli | 233 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 253 insertions(+), 23 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 8eb5427bb..4a8fbaa0a 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -323,8 +323,8 @@ struct else ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + let unwrap_ast ( x : ast ) = (z3obj_gno x) let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr - let unwrap_ast ( x : ast ) = (z3obj_gno x) end open AST @@ -678,6 +678,19 @@ end = struct res let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) + + let update_param_value ( ctx : context ) ( id : string) ( value : string )= + Z3native.update_param_value (context_gno ctx) id value + + let get_param_value ( ctx : context ) ( id : string ) = + let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in + if not r then + None + else + Some v + + let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = + Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) end (** General expressions (terms) *) @@ -1106,7 +1119,7 @@ struct end -module Array_ = +module Array = struct let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) @@ -1389,7 +1402,7 @@ struct end -module List_ = +module List = struct let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = let (r, _, _, _, _, _, _) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in @@ -2558,26 +2571,6 @@ struct let mk_fixedpoint ( ctx : context ) = create ctx end -module Options = -struct - - let update_param_value ( ctx : context ) ( id : string) ( value : string )= - Z3native.update_param_value (context_gno ctx) id value - - let get_param_value ( ctx : context ) ( id : string ) = - let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in - if not r then - None - else - Some v - - let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = - Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) - - let toggle_warning_messages ( enabled: bool ) = - Z3native.toggle_warning_messages enabled -end - module SMT = struct @@ -2692,3 +2685,7 @@ let get_global_param ( id : string ) = let global_param_reset_all = Z3native.global_param_reset_all + +let toggle_warning_messages ( enabled: bool ) = + Z3native.toggle_warning_messages enabled + diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 2eb9eecb7..1eae4f013 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -756,9 +756,27 @@ and goal_prec = the first conjunct in the body of an implication is position 1 the second conjunct in the body of an implication is position 2 +<<<<<<< HEAD For general implications where the head is a disjunction, the first n positions correspond to the n disjuncts in the head. The next m positions correspond to the m conjuncts in the body. +======= +(** Create a context object + The following parameters can be set: + + - proof (Boolean) Enable proof generation + - debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting + - trace (Boolean) Tracing support for VCC + - trace_file_name (String) Trace out file for VCC traces + - timeout (unsigned) default timeout (in milliseconds) used for solvers + - well_sorted_check type checker + - auto_config use heuristics to automatically select solver and configure it + - model model generation for solvers, this parameter can be overwritten when creating a solver + - model_validate validate models produced by solvers + - unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver +*) +val mk_context : (string * string) list -> context +>>>>>>> Updates to ML API. The premises can be universally quantified so that the most general non-ground form is: @@ -1084,6 +1102,7 @@ val mk_symbol: context -> symbol_refined -> symbol external mk_int_symbol : context -> int -> symbol = "camlidl_z3_Z3_mk_int_symbol" +<<<<<<< HEAD (** Summary: Create a Z3 symbol using a C string. Symbols are used to name several term and type constructors. @@ -1137,6 +1156,27 @@ type sort_refined = | Sort_datatype of datatype_constructor array | Sort_relation of sort array | Sort_unknown +======= + (** 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., + Z3native.inc_ref). + {!wrap_ast} *) + val unwrap_ast : ast -> Z3native.ptr + + (** Wraps an AST. + + This function is used for transitions between native and + managed objects. Note that the native ast that is passed must be a + native object obtained from Z3 (e.g., through {!unwrap_ast}) + and that it must have a correct reference count (see e.g., + Z3native.inc_ref). *) + val wrap_ast : context -> Z3native.z3_ast -> ast +end +>>>>>>> Updates to ML API. (** @@ -1693,6 +1733,7 @@ external mk_bvnot : context -> ast -> ast external mk_bvredand : context -> ast -> ast = "camlidl_z3_Z3_mk_bvredand" +<<<<<<< HEAD (** Summary: \[ [ mk_bvredor c t1 ] \] Take disjunction of bits in vector, return vector of length 1. @@ -1701,6 +1742,41 @@ external mk_bvredand : context -> ast -> ast *) external mk_bvredor : context -> ast -> ast = "camlidl_z3_Z3_mk_bvredor" +======= + (** A string representation of the parameter set. *) + val to_string : params -> string + + (** Update a mutable configuration parameter. + + The list of all configuration parameters can be obtained using the Z3 executable: + z3.exe -p + Only a few configuration parameters are mutable once the context is created. + An exception is thrown when trying to modify an immutable parameter. + {!get_param_value} *) + val update_param_value : context -> string -> string -> unit + + (** Get a configuration parameter. + + Returns None if the parameter value does not exist. + {!update_param_value} *) + val get_param_value : context -> string -> string option + + (** 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + {!AST.to_string} + {!Quantifier.Pattern.to_string} + {!FuncDecl.to_string} + {!Sort.to_string} *) + val set_print_mode : context -> Z3enums.ast_print_mode -> unit +end +>>>>>>> Updates to ML API. (** Summary: \[ [ mk_bvand c t1 t2 ] \] @@ -1931,6 +2007,7 @@ external mk_bvugt : context -> ast -> ast -> ast external mk_bvsgt : context -> ast -> ast -> ast = "camlidl_z3_Z3_mk_bvsgt" +<<<<<<< HEAD (** Summary: \[ [ mk_concat c t1 t2 ] \] Concatenate the given bit-vectors. @@ -1941,6 +2018,106 @@ external mk_bvsgt : context -> ast -> ast -> ast *) external mk_concat : context -> ast -> ast -> ast = "camlidl_z3_Z3_mk_concat" +======= +(** Functions to manipulate Array expressions *) +module Array : +sig + (** Create a new array sort. *) + val mk_sort : context -> Sort.sort -> Sort.sort -> Sort.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. *) + val is_store : Expr.expr -> bool + + (** Indicates whether the term is an array select. *) + val is_select : Expr.expr -> bool + + (** 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. *) + val is_constant_array : Expr.expr -> bool + + (** Indicates whether the term is a default array. + For example default(const(v)) = v. The function is unary. *) + val is_default_array : Expr.expr -> bool + + (** 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. *) + val is_array_map : Expr.expr -> bool + + (** 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. *) + val is_as_array : Expr.expr -> bool + + (** Indicates whether the term is of an array sort. *) + val is_array : Expr.expr -> bool + + (** The domain of the array sort. *) + val get_domain : Sort.sort -> Sort.sort + + (** The range of the array sort. *) + val get_range : Sort.sort -> Sort.sort + + (** Create an array constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> Expr.expr + + (** Create an array constant. *) + val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> Expr.expr + + (** 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. + {!Array.mk_sort} + {!mk_store} *) + val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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). + {!Array.mk_sort} + {!mk_select} *) + val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create a constant array. + + The resulting term is an array, such that a selecton an arbitrary index + produces the value v. + {!Array.mk_sort} + {!mk_select} *) + val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr + + (** 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]. + {!Array.mk_sort} + {!mk_select} + {!mk_store} *) + val mk_map : context -> FuncDecl.func_decl -> Expr.expr list -> Expr.expr + + (** Access the array default value. + + Produces the default range value, for arrays that can be represented as + finite maps with a default range value. *) + val mk_term_array : context -> Expr.expr -> Expr.expr +end +>>>>>>> Updates to ML API. (** Summary: \[ [ mk_extract c high low t1 ] \] @@ -2259,12 +2436,20 @@ external mk_set_sort : context -> sort -> sort external mk_empty_set : context -> sort -> ast = "camlidl_z3_Z3_mk_empty_set" +<<<<<<< HEAD (** Summary: Create the full set. def_API('mk_full_set', AST, (_in(CONTEXT), _in(SORT))) *) external mk_full_set : context -> sort -> ast = "camlidl_z3_Z3_mk_full_set" +======= +(** Functions to manipulate List expressions *) +module List : +sig + (** Create a new list sort. *) + val mk_sort : context -> Symbol.symbol -> Sort.sort -> Sort.sort +>>>>>>> Updates to ML API. (** Summary: Add an element to a set. @@ -8806,6 +8991,7 @@ external theory_get_num_apps : theory -> int external theory_get_app : theory -> int -> ast = "camlidl_z3V3_Z3_theory_get_app" +<<<<<<< HEAD (** {2 {L Deprecated Injective functions API}} *) @@ -9135,6 +9321,12 @@ external get_model_func_decl : context -> model -> int -> func_decl *) external eval_func_decl : context -> model -> func_decl -> bool * ast = "camlidl_z3V3_Z3_eval_func_decl" +======= +(** Functions for handling SMT and SMT2 expressions and files *) +module SMT : +sig + (** Convert a benchmark into an SMT-LIB formatted string. +>>>>>>> Updates to ML API. (** Summary: \[ [ is_array_value c v ] \] @@ -9586,3 +9778,44 @@ val set_new_relevant_callback : theory -> (ast -> unit) -> unit end +<<<<<<< HEAD +======= +(** Set a global (or module) parameter, which is shared by all Z3 contexts. + + When a Z3 module is initialized it will use the value of these parameters + when Z3_params objects are not provided. + The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. + The character '.' is a delimiter (more later). + The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. + Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". + This function can be used to set parameters for a specific Z3 module. + This can be done by using .. + For example: + (set_global_param "pp.decimal" "true") + will set the parameter "decimal" in the module "pp" to true. +*) +val set_global_param : string -> string -> unit + +(** Get a global (or module) parameter. + + Returns None if the parameter does not exist. + The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. + This function cannot be invoked simultaneously from different threads without synchronization. + The result string stored in param_value is stored in a shared location. +*) +val get_global_param : string -> string option + +(** Restore the value of all global (and module) parameters. + + This command will not affect already created objects (such as tactics and solvers) + {!set_global_param} +*) + +val global_param_reset_all : unit + + (** Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) + val toggle_warning_messages : bool -> unit +>>>>>>> Updates to ML API. From 9726ee4c5faa875c991dca1a4c9d75aa80923355 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 3 Jun 2013 19:12:00 +0100 Subject: [PATCH 070/248] ML API: refactoring Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 74 +- src/api/ml/z3.mli | 11735 +++++++++----------------------------------- 2 files changed, 2454 insertions(+), 9355 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 4a8fbaa0a..081433f1f 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,6 +7,8 @@ open Z3enums +exception Error = Z3native.Exception + (* Some helpers. *) let null = Z3native.mk_null() let is_null o = (Z3native.is_null o) @@ -283,7 +285,7 @@ struct Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) end - let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) + let hash ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) @@ -304,7 +306,7 @@ struct let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - let ( = ) ( a : ast ) ( b : ast ) = (a == b) || + let equal ( a : ast ) ( b : ast ) = (a == b) || if (z3obj_gnc a) != (z3obj_gnc b) then false else @@ -314,8 +316,6 @@ struct if (get_id a) < (get_id b) then -1 else if (get_id a) > (get_id b) then 1 else 0 - - let ( < ) (a : ast) (b : ast) = (compare a b) let translate ( x : ast ) ( to_ctx : context ) = if (z3obj_gnc x) == (context_gno to_ctx) then @@ -361,7 +361,7 @@ struct let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in Array.of_list (List.map f a) - let ( = ) : sort -> sort -> bool = fun a b -> + let equal : sort -> sort -> bool = fun a b -> (a == b) || if (gnc a) != (gnc b) then false @@ -424,7 +424,7 @@ sig val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl val mk_const_decl_s : context -> string -> Sort.sort -> func_decl val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl - val ( = ) : func_decl -> func_decl -> bool + val equal : func_decl -> func_decl -> bool val to_string : func_decl -> string val get_id : func_decl -> int val get_arity : func_decl -> int @@ -498,7 +498,7 @@ end = struct let get_float ( x : parameter ) = match x with | P_Dbl(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a double") + | _ -> raise (Z3native.Exception "parameter is not a float") let get_symbol ( x : parameter ) = match x with @@ -545,7 +545,7 @@ end = struct create_pdr ctx prefix [] range - let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || + let equal ( a : func_decl ) ( b : func_decl ) = (a == b) || if (gnc a) != (gnc b) then false else @@ -605,12 +605,8 @@ sig end val add_bool : params -> Symbol.symbol -> bool -> unit val add_int : params -> Symbol.symbol -> int -> unit - val add_double : params -> Symbol.symbol -> float -> unit + val add_float : params -> Symbol.symbol -> float -> unit val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - val add_s_bool : params -> string -> bool -> unit - val add_s_int : params -> string -> int -> unit - val add_s_double : params -> string -> float -> unit - val add_s_symbol : params -> string -> Symbol.symbol -> unit val mk_params : context -> params val to_string : params -> string end = struct @@ -650,24 +646,12 @@ end = struct let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = + let add_float ( x : params ) ( name : Symbol.symbol ) ( value : float ) = Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) - let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = - add_bool x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_int ( x : params) ( name : string ) ( value : int ) = - add_int x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_double ( x : params ) ( name : string ) ( value : float ) = - add_double x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = - add_symbol x (Symbol.mk_string (z3obj_gc x) name) value - let mk_params ( ctx : context ) = let res : params = { m_ctx = ctx ; m_n_obj = null ; @@ -734,8 +718,6 @@ sig val is_xor : expr -> bool val is_not : expr -> bool val is_implies : expr -> bool - val is_label : expr -> bool - val is_label_lit : expr -> bool val is_oeq : expr -> bool val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val mk_const_s : context -> string -> Sort.sort -> expr @@ -857,8 +839,6 @@ end = struct let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = @@ -1530,20 +1510,20 @@ struct let mk_real2int ( ctx : context ) ( t : expr ) = (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (Expr.gno t))) - end - module AlgebraicNumber = - struct - let to_upper ( x : expr ) ( precision : int ) = - expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_upper (Expr.gnc x) (Expr.gno x) precision) - - let to_lower ( x : expr ) precision = - expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_lower (Expr.gnc x) (Expr.gno x) precision) - - let to_decimal_string ( x : expr ) ( precision : int ) = - Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + module AlgebraicNumber = + struct + let to_upper ( x : expr ) ( precision : int ) = + expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_upper (Expr.gnc x) (Expr.gno x) precision) + + let to_lower ( x : expr ) precision = + expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_lower (Expr.gnc x) (Expr.gno x) precision) + + let to_decimal_string ( x : expr ) ( precision : int ) = + Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision + + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + end end let is_int ( x : expr ) = @@ -2052,13 +2032,11 @@ struct let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in (mk_list f n_funcs) @ (mk_list g n_consts) - - exception ModelEvaluationFailedException of string - + let eval ( x : model ) ( t : expr ) ( completion : bool ) = let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in if not r then - raise (ModelEvaluationFailedException "evaluation failed") + None else expr_of_ptr (z3obj_gc x) v @@ -2353,7 +2331,7 @@ struct if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.create_sd k (Z3native.stats_get_float_value (z3obj_gnc x) (z3obj_gno x) i)) ) in mk_list f n diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 1eae4f013..570ff8717 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1,766 +1,37 @@ -(* File generated from z3.idl *) +(** + The Z3 ML/Ocaml Interface. + Copyright (C) 2012 Microsoft Corporation + @author CM Wintersteiger (cwinter) 2012-12-17 +*) + +(** General Z3 exceptions + + Many functions in this API may throw an exception; if they do, it is this one.*) +exception Error + +(** Context objects. + + Most interactions with Z3 are interpreted in some context; many users will only + require one such object, but power users may require more than one. To start using + Z3, do + + + let ctx = (mk_context []) in + (...) + + + where a list of pairs of strings may be passed to set options on + the context, e.g., like so: + + + let cfg = [("model", "true"); ("...", "...")] in + let ctx = (mk_context cfg) in + (...) + +*) type context -and symbol -and ast -and sort = private ast -and func_decl = private ast -and app = private ast -and pattern = private ast -and params -and param_descrs -and model -and func_interp -and func_entry -and fixedpoint -and ast_vector -and ast_map -and goal -and tactic -and probe -and apply_result -and solver -and stats - - -and constructor -and constructor_list - -and lbool = - | L_FALSE - | L_UNDEF - | L_TRUE - -and symbol_kind = - | INT_SYMBOL - | STRING_SYMBOL - -and parameter_kind = - | PARAMETER_INT - | PARAMETER_DOUBLE - | PARAMETER_RATIONAL - | PARAMETER_SYMBOL - | PARAMETER_SORT - | PARAMETER_AST - | PARAMETER_FUNC_DECL - -and sort_kind = - | UNINTERPRETED_SORT - | BOOL_SORT - | INT_SORT - | REAL_SORT - | BV_SORT - | ARRAY_SORT - | DATATYPE_SORT - | RELATION_SORT - | FINITE_DOMAIN_SORT - | UNKNOWN_SORT - -and ast_kind = - | NUMERAL_AST - | APP_AST - | VAR_AST - | QUANTIFIER_AST - | SORT_AST - | FUNC_DECL_AST - | UNKNOWN_AST - -and decl_kind = - | OP_TRUE - | OP_FALSE - | OP_EQ - | OP_DISTINCT - | OP_ITE - | OP_AND - | OP_OR - | OP_IFF - | OP_XOR - | OP_NOT - | OP_IMPLIES - | OP_OEQ - | OP_ANUM - | OP_AGNUM - | OP_LE - | OP_GE - | OP_LT - | OP_GT - | OP_ADD - | OP_SUB - | OP_UMINUS - | OP_MUL - | OP_DIV - | OP_IDIV - | OP_REM - | OP_MOD - | OP_TO_REAL - | OP_TO_INT - | OP_IS_INT - | OP_POWER - | OP_STORE - | OP_SELECT - | OP_CONST_ARRAY - | OP_ARRAY_MAP - | OP_ARRAY_DEFAULT - | OP_SET_UNION - | OP_SET_INTERSECT - | OP_SET_DIFFERENCE - | OP_SET_COMPLEMENT - | OP_SET_SUBSET - | OP_AS_ARRAY - | OP_BNUM - | OP_BIT1 - | OP_BIT0 - | OP_BNEG - | OP_BADD - | OP_BSUB - | OP_BMUL - | OP_BSDIV - | OP_BUDIV - | OP_BSREM - | OP_BUREM - | OP_BSMOD - | OP_BSDIV0 - | OP_BUDIV0 - | OP_BSREM0 - | OP_BUREM0 - | OP_BSMOD0 - | OP_ULEQ - | OP_SLEQ - | OP_UGEQ - | OP_SGEQ - | OP_ULT - | OP_SLT - | OP_UGT - | OP_SGT - | OP_BAND - | OP_BOR - | OP_BNOT - | OP_BXOR - | OP_BNAND - | OP_BNOR - | OP_BXNOR - | OP_CONCAT - | OP_SIGN_EXT - | OP_ZERO_EXT - | OP_EXTRACT - | OP_REPEAT - | OP_BREDOR - | OP_BREDAND - | OP_BCOMP - | OP_BSHL - | OP_BLSHR - | OP_BASHR - | OP_ROTATE_LEFT - | OP_ROTATE_RIGHT - | OP_EXT_ROTATE_LEFT - | OP_EXT_ROTATE_RIGHT - | OP_INT2BV - | OP_BV2INT - | OP_CARRY - | OP_XOR3 - | OP_PR_UNDEF - | OP_PR_TRUE - | OP_PR_ASSERTED - | OP_PR_GOAL - | OP_PR_MODUS_PONENS - | OP_PR_REFLEXIVITY - | OP_PR_SYMMETRY - | OP_PR_TRANSITIVITY - | OP_PR_TRANSITIVITY_STAR - | OP_PR_MONOTONICITY - | OP_PR_QUANT_INTRO - | OP_PR_DISTRIBUTIVITY - | OP_PR_AND_ELIM - | OP_PR_NOT_OR_ELIM - | OP_PR_REWRITE - | OP_PR_REWRITE_STAR - | OP_PR_PULL_QUANT - | OP_PR_PULL_QUANT_STAR - | OP_PR_PUSH_QUANT - | OP_PR_ELIM_UNUSED_VARS - | OP_PR_DER - | OP_PR_QUANT_INST - | OP_PR_HYPOTHESIS - | OP_PR_LEMMA - | OP_PR_UNIT_RESOLUTION - | OP_PR_IFF_TRUE - | OP_PR_IFF_FALSE - | OP_PR_COMMUTATIVITY - | OP_PR_DEF_AXIOM - | OP_PR_DEF_INTRO - | OP_PR_APPLY_DEF - | OP_PR_IFF_OEQ - | OP_PR_NNF_POS - | OP_PR_NNF_NEG - | OP_PR_NNF_STAR - | OP_PR_CNF_STAR - | OP_PR_SKOLEMIZE - | OP_PR_MODUS_PONENS_OEQ - | OP_PR_TH_LEMMA - | OP_PR_HYPER_RESOLVE - | OP_RA_STORE - | OP_RA_EMPTY - | OP_RA_IS_EMPTY - | OP_RA_JOIN - | OP_RA_UNION - | OP_RA_WIDEN - | OP_RA_PROJECT - | OP_RA_FILTER - | OP_RA_NEGATION_FILTER - | OP_RA_RENAME - | OP_RA_COMPLEMENT - | OP_RA_SELECT - | OP_RA_CLONE - | OP_FD_LT - | OP_LABEL - | OP_LABEL_LIT - | OP_DT_CONSTRUCTOR - | OP_DT_RECOGNISER - | OP_DT_ACCESSOR - | OP_UNINTERPRETED - -and param_kind = - | PK_UINT - | PK_BOOL - | PK_DOUBLE - | PK_SYMBOL - | PK_STRING - | PK_OTHER - | PK_INVALID - -and ast_print_mode = - | PRINT_SMTLIB_FULL - | PRINT_LOW_LEVEL - | PRINT_SMTLIB_COMPLIANT - | PRINT_SMTLIB2_COMPLIANT - -and error_code = - | OK - | SORT_ERROR - | IOB - | INVALID_ARG - | PARSER_ERROR - | NO_PARSER - | INVALID_PATTERN - | MEMOUT_FAIL - | FILE_ACCESS_ERROR - | INTERNAL_FATAL - | INVALID_USAGE - | DEC_REF_ERROR - | EXCEPTION - -and goal_prec = - | GOAL_PRECISE - | GOAL_UNDER - | GOAL_OVER - | GOAL_UNDER_OVER - - -(** -*) -(** - {2 {L Types}} - Most of the types in the API are abstract. - - [context]: manager of all other Z3 objects, global configuration options, etc. - - [symbol]: Lisp-like symbol used to name types, constants, and functions. A symbol can be created using string or integers. - - [ast]: abstract syntax tree node. That is, the data-structure used in Z3 to represent terms, formulas and types. - - [sort]: kind of AST used to represent types. - - [func_decl]: kind of AST used to represent function symbols. - - [app]: kind of AST used to represent function applications. - - [pattern]: kind of AST used to represent pattern and multi-patterns used to guide quantifier instantiation. - - [params]: parameter set used to configure many components such as: simplifiers, tactics, solvers, etc. - - [model]: model for the constraints asserted into the logical context. - - [func_interp]: interpretation of a function in a model. - - [func_entry]: representation of the value of a [func_interp] at a particular point. - - [fixedpoint]: context for the recursive predicate solver. - - [ast_vector]: vector of [ast] objects. - - [ast_map]: mapping from [ast] to [ast] objects. - - [goal]: set of formulas that can be solved and/or transformed using tactics and solvers. - - [tactic]: basic building block for creating custom solvers for specific problem domains. - - [probe]: function/predicate used to inspect a goal and collect information that may be used to decide which solver and/or preprocessing step will be used. - - [apply_result]: collection of subgoals resulting from applying of a tactic to a goal. - - [solver]: (incremental) solver, possibly specialized by a particular tactic or logic. - - [stats]: statistical data for a solver. -*) -(** - {!lbool} - Lifted Boolean type: [false], [undefined], [true]. -*) -(** - {!symbol_kind} - The different kinds of symbol. - In Z3, a symbol can be represented using integers and strings (See {!get_symbol_kind}). - - {b See also}: {!mk_int_symbol} - - {b See also}: {!mk_string_symbol} -*) -(** - {!parameter_kind} - The different kinds of parameters that can be associated with function symbols. - - {b See also}: {!get_decl_num_parameters} - - {b See also}: {!get_decl_parameter_kind} - - PARAMETER_INT is used for integer parameters. - - PARAMETER_DOUBLE is used for double parameters. - - PARAMETER_RATIONAL is used for parameters that are rational numbers. - - PARAMETER_SYMBOL is used for parameters that are symbols. - - PARAMETER_SORT is used for sort parameters. - - PARAMETER_AST is used for expression parameters. - - PARAMETER_FUNC_DECL is used for function declaration parameters. -*) -(** - {!sort_kind} - The different kinds of Z3 types (See {!get_sort_kind}). -*) -(** - {!ast_kind} - The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types. - - APP_AST: constant and applications - - NUMERAL_AST: numeral constants - - VAR_AST: bound variables - - QUANTIFIER_AST: quantifiers - - SORT_AST: sort - - FUNC_DECL_AST: function declaration - - UNKNOWN_AST: internal -*) -(** - {!decl_kind} - The different kinds of interpreted function kinds. - - OP_TRUE The constant true. - - OP_FALSE The constant false. - - OP_EQ The equality predicate. - - OP_DISTINCT The n-ary distinct predicate (every argument is mutually distinct). - - OP_ITE The ternary if-then-else term. - - OP_AND n-ary conjunction. - - OP_OR n-ary disjunction. - - OP_IFF equivalence (binary). - - OP_XOR Exclusive or. - - OP_NOT Negation. - - OP_IMPLIES Implication. - - OP_OEQ Binary equivalence modulo namings. This binary predicate is used in proof terms. - It captures equisatisfiability and equivalence modulo renamings. - - OP_ANUM Arithmetic numeral. - - OP_AGNUM Arithmetic algebraic numeral. Algebraic numbers are used to represent irrational numbers in Z3. - - OP_LE <=. - - OP_GE >=. - - OP_LT <. - - OP_GT >. - - OP_ADD Addition - Binary. - - OP_SUB Binary subtraction. - - OP_UMINUS Unary minus. - - OP_MUL Multiplication - Binary. - - OP_DIV Division - Binary. - - OP_IDIV Integer division - Binary. - - OP_REM Remainder - Binary. - - OP_MOD Modulus - Binary. - - OP_TO_REAL Coercion of integer to real - Unary. - - OP_TO_INT Coercion of real to integer - Unary. - - OP_IS_INT Check if real is also an integer - Unary. - - OP_POWER Power operator x^y. - - OP_STORE 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. - - OP_SELECT Array select. - - OP_CONST_ARRAY The constant array. For example, select(const(v),i) = v holds for every v and i. The function is unary. - - OP_ARRAY_DEFAULT Default value of arrays. For example default(const(v)) = v. The function is unary. - - OP_ARRAY_MAP Array map operator. - It satisfies map[f](a1,..,a_n)[i] = f(a1[i],...,a_n[i]) for every i. - - OP_SET_UNION Set union between two Booelan arrays (two arrays whose range type is Boolean). The function is binary. - - OP_SET_INTERSECT Set intersection between two Boolean arrays. The function is binary. - - OP_SET_DIFFERENCE Set difference between two Boolean arrays. The function is binary. - - OP_SET_COMPLEMENT Set complement of a Boolean array. The function is unary. - - OP_SET_SUBSET Subset predicate between two Boolean arrays. The relation is binary. - - OP_AS_ARRAY An array value that behaves as the function graph of the - function passed as parameter. - - OP_BNUM Bit-vector numeral. - - OP_BIT1 One bit bit-vector. - - OP_BIT0 Zero bit bit-vector. - - OP_BNEG Unary minus. - - OP_BADD Binary addition. - - OP_BSUB Binary subtraction. - - OP_BMUL Binary multiplication. - - OP_BSDIV Binary signed division. - - OP_BUDIV Binary unsigned int division. - - OP_BSREM Binary signed remainder. - - OP_BUREM Binary unsigned int remainder. - - OP_BSMOD Binary signed modulus. - - OP_BSDIV0 Unary function. bsdiv(x,0) is congruent to bsdiv0(x). - - OP_BUDIV0 Unary function. budiv(x,0) is congruent to budiv0(x). - - OP_BSREM0 Unary function. bsrem(x,0) is congruent to bsrem0(x). - - OP_BUREM0 Unary function. burem(x,0) is congruent to burem0(x). - - OP_BSMOD0 Unary function. bsmod(x,0) is congruent to bsmod0(x). - - OP_ULEQ Unsigned bit-vector <= - Binary relation. - - OP_SLEQ Signed bit-vector <= - Binary relation. - - OP_UGEQ Unsigned bit-vector >= - Binary relation. - - OP_SGEQ Signed bit-vector >= - Binary relation. - - OP_ULT Unsigned bit-vector < - Binary relation. - - OP_SLT Signed bit-vector < - Binary relation. - - OP_UGT Unsigned bit-vector > - Binary relation. - - OP_SGT Signed bit-vector > - Binary relation. - - OP_BAND Bit-wise and - Binary. - - OP_BOR Bit-wise or - Binary. - - OP_BNOT Bit-wise not - Unary. - - OP_BXOR Bit-wise xor - Binary. - - OP_BNAND Bit-wise nand - Binary. - - OP_BNOR Bit-wise nor - Binary. - - OP_BXNOR Bit-wise xnor - Binary. - - OP_CONCAT Bit-vector concatenation - Binary. - - OP_SIGN_EXT Bit-vector sign extension. - - OP_ZERO_EXT Bit-vector zero extension. - - OP_EXTRACT Bit-vector extraction. - - OP_REPEAT Repeat bit-vector n times. - - OP_BREDOR Bit-vector reduce or - Unary. - - OP_BREDAND Bit-vector reduce and - Unary. - - OP_BCOMP . - - OP_BSHL Shift left. - - OP_BLSHR Logical shift right. - - OP_BASHR Arithmetical shift right. - - OP_ROTATE_LEFT Left rotation. - - OP_ROTATE_RIGHT Right rotation. - - OP_EXT_ROTATE_LEFT (extended) Left rotation. Similar to OP_ROTATE_LEFT, but it is a binary operator instead of a parametric one. - - OP_EXT_ROTATE_RIGHT (extended) Right rotation. Similar to OP_ROTATE_RIGHT, but it is a binary operator instead of a parametric one. - - OP_INT2BV Coerce integer to bit-vector. NB. This function - is not supported by the decision procedures. Only the most - rudimentary simplification rules are applied to this function. - - OP_BV2INT Coerce bit-vector to integer. NB. This function - is not supported by the decision procedures. Only the most - rudimentary simplification rules are applied to this function. - - OP_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))) - - OP_XOR3 Compute ternary XOR. - The meaning is given by the equivalence - (xor3 l1 l2 l3) <=> (xor (xor l1 l2) l3) - - OP_PR_UNDEF: Undef/Null proof object. - - OP_PR_TRUE: Proof for the expression 'true'. - - OP_PR_ASSERTED: Proof for a fact asserted by the user. - - OP_PR_GOAL: Proof for a fact (tagged as goal) asserted by the user. - - OP_PR_MODUS_PONENS: Given a proof for p and a proof for (implies p q), produces a proof for q. - {e - T1: p - T2: (implies p q) - [mp T1 T2]: q - } - The second antecedents may also be a proof for (iff p q). - - OP_PR_REFLEXIVITY: 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'. - - OP_PR_SYMMETRY: Given an symmetric relation R and a proof for (R t s), produces a proof for (R s t). - {e - T1: (R t s) - [symmetry T1]: (R s t) - } - T1 is the antecedent of this proof object. - - OP_PR_TRANSITIVITY: Given a transitive relation R, and proofs for (R t s) and (R s u), produces a proof - for (R t u). - {e - T1: (R t s) - T2: (R s u) - [trans T1 T2]: (R t u) - } - - OP_PR_TRANSITIVITY_STAR: Condensed transitivity proof. This proof object is only used if the parameter PROOF_MODE is 1. - It combines several symmetry and transitivity proofs. - Example: - {e - 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. - - OP_PR_MONOTONICITY: Monotonicity proof object. - {e - 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. - - OP_PR_QUANT_INTRO: 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)) - - OP_PR_DISTRIBUTIVITY: 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. - - OP_PR_AND_ELIM: Given a proof for (and l_1 ... l_n), produces a proof for l_i - {e - T1: (and l_1 ... l_n) - [and-elim T1]: l_i - } - - OP_PR_NOT_OR_ELIM: Given a proof for (not (or l_1 ... l_n)), produces a proof for (not l_i). - {e - T1: (not (or l_1 ... l_n)) - [not-or-elim T1]: (not l_i) - } - - OP_PR_REWRITE: 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: - {e - (= (+ x 0) x) - (= (+ x 1 2) (+ 3 x)) - (iff (or x false) x) - } - - OP_PR_REWRITE_STAR: 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) - - OP_PR_PULL_QUANT: A proof for (iff (f (forall (x) q(x)) r) (forall (x) (f (q x) r))). This proof object has no antecedents. - - OP_PR_PULL_QUANT_STAR: 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. - - OP_PR_PUSH_QUANT: A proof for: - {e - (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. - - OP_PR_ELIM_UNUSED_VARS: - 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. - - OP_PR_DER: 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. - - OP_PR_QUANT_INST: A proof of (or (not (forall (x) (P x))) (P a)) - - OP_PR_HYPOTHESIS: Mark a hypothesis in a natural deduction style proof. - - OP_PR_LEMMA: - {e - 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. - - OP_PR_UNIT_RESOLUTION: - {e - 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') - } - - OP_PR_IFF_TRUE: - {e - T1: p - [iff-true T1]: (iff p true) - } - - OP_PR_IFF_FALSE: - {e - T1: (not p) - [iff-false T1]: (iff p false) - } - - - OP_PR_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. - - - OP_PR_DEF_AXIOM: Proof object used to justify Tseitin's like axioms: - - {e - (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). - - - OP_PR_DEF_INTRO: 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) - - - OP_PR_APPLY_DEF: - [apply-def T1]: F ~ n - F is 'equivalent' to n, given that T1 is a proof that - n is a name for F. - - - OP_PR_IFF_OEQ: - T1: (iff p q) - [iff~ T1]: (~ p q) - - - OP_PR_NNF_POS: Proof for a (positive) NNF step. Example: - {e - 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 - {e - 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'. - - - - OP_PR_NFF_NEG: Proof for a (negative) NNF step. Examples: - {e - 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'))) - } - - OP_PR_NNF_STAR: 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. - - - OP_PR_CNF_STAR: 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. - - - OP_PR_SKOLEMIZE: Proof for: - - {e - [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. - - - OP_PR_MODUS_PONENS_OEQ: Modus ponens style rule for equi-satisfiability. - {e - T1: p - T2: (~ p q) - [mp~ T1 T2]: q - } - - - OP_PR_TH_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: - {e - (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - } - - - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. - - - - OP_PR_HYPER_RESOLVE: Hyper-resolution rule. - - The premises of the rules is a sequence of clauses. - The first clause argument is the main clause of the rule. - One literal from the second, third, .. clause is resolved - with a literal from the first (main) clause. - - Premises of the rules are of the form - {e - (or l0 l1 l2 .. ln) - } - or - {e - (=> (and ln+1 ln+2 .. ln+m) l0) - } - or in the most general (ground) form: - {e - (=> (and ln+1 ln+2 .. ln+m) (or l0 l1 .. ln-1)) - } - In other words we use the following (Prolog style) convention for Horn - implications: - The head of a Horn implication is position 0, - the first conjunct in the body of an implication is position 1 - the second conjunct in the body of an implication is position 2 - -<<<<<<< HEAD - For general implications where the head is a disjunction, the - first n positions correspond to the n disjuncts in the head. - The next m positions correspond to the m conjuncts in the body. -======= (** Create a context object The following parameters can be set: @@ -776,387 +47,194 @@ and goal_prec = - unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver *) val mk_context : (string * string) list -> context ->>>>>>> Updates to ML API. - The premises can be universally quantified so that the most - general non-ground form is: +(** 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. *) +module Log : +sig + (** Open an interaction log file. + @return True if opening the log file succeeds, false otherwise. *) + (* CMW: "open" seems to be a reserved keyword? *) + val open_ : string -> bool - {e - (forall (vars) (=> (and ln+1 ln+2 .. ln+m) (or l0 l1 .. ln-1))) - } + (** Closes the interaction log. *) + val close : unit - The hyper-resolution rule takes a sequence of parameters. - The parameters are substitutions of bound variables separated by pairs - of literal positions from the main clause and side clause. + (** Appends a user-provided string to the interaction log. *) + val append : string -> unit +end +(** Version information *) +module Version : +sig + (** The major version. *) + val major : int - - OP_RA_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. + (** The minor version. *) + val minor : int - - OP_RA_EMPTY: Creates the empty relation. + (** The build version. *) + val build : int - - OP_RA_IS_EMPTY: Tests if the relation is empty. + (** The revision. *) + val revision : int - - OP_RA_JOIN: Create the relational join. + (** A string representation of the version information. *) + val to_string : string +end - - OP_RA_UNION: Create the union or convex hull of two relations. - The function takes two arguments. +(** Symbols are used to name several term and type constructors *) +module Symbol : +sig + type symbol - - OP_RA_WIDEN: Widen two relations. - The function takes two arguments. + (** The kind of the symbol (int or string) *) + val kind : symbol -> Z3enums.symbol_kind - - OP_RA_PROJECT: Project the columns (provided as numbers in the parameters). - The function takes one argument. + (** Indicates whether the symbol is of Int kind *) + val is_int_symbol : symbol -> bool - - OP_RA_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. + (** Indicates whether the symbol is of string kind. *) + val is_string_symbol : symbol -> bool - - OP_RA_NEGATION_FILTER: 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 + (** The int value of the symbol. *) + val get_int : symbol -> int - target = filter_by_negation(pos, neg, columns) + (** The string value of the symbol. *) + val get_string : symbol -> string - 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. + (** A string representation of the symbol. *) + val to_string : symbol -> string + (** 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. *) + val mk_int : context -> int -> symbol - - OP_RA_RENAME: rename columns in the relation. - The function takes one argument. - The parameters contain the renaming as a cycle. + (** Creates a new symbol using a string. *) + val mk_string : context -> string -> symbol - - OP_RA_COMPLEMENT: Complement the relation. + (** Create a list of symbols. *) + val mk_ints : context -> int list -> symbol list - - OP_RA_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. + (** Create a list of symbols. *) + val mk_strings : context -> string list -> symbol list +end - - OP_RA_CLONE: Create a fresh copy (clone) of a relation. - The function is logically the identity, but - in the context of a register machine allows - for [OP_RA_UNION] - to perform destructive updates to the first argument. +(** The abstract syntax tree (AST) module *) +module AST : +sig + type ast + (** Vectors of ASTs *) + module ASTVector : + sig + type ast_vector + + (** The size of the vector *) + val get_size : ast_vector -> int - - OP_FD_LT: A less than predicate over the finite domain FINITE_DOMAIN_SORT. + (** + Retrieves the i-th object in the vector. + @return An AST *) + val get : ast_vector -> int -> ast - - OP_LABEL: 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. + (** Sets the i-th object in the vector. *) + val set : ast_vector -> int -> ast -> unit - - OP_LABEL_LIT: A label literal (used by the Boogie Verification condition generator). - A label literal has a set of string parameters. It takes no arguments. + (** Resize the vector to a new size. *) + val resize : ast_vector -> int -> unit - - OP_DT_CONSTRUCTOR: datatype constructor. + (** Add an ast to the back of the vector. The size + is increased by 1. *) + val push : ast_vector -> ast -> unit - - OP_DT_RECOGNISER: datatype recognizer. + (** Translates all ASTs in the vector to another context. + @return A new ASTVector *) + val translate : ast_vector -> context -> ast_vector - - OP_DT_ACCESSOR: datatype accessor. + (** Retrieves a string representation of the vector. *) + val to_string : ast_vector -> string + end - - OP_UNINTERPRETED: kind used for uninterpreted symbols. -*) -(** - {!param_kind} + (** Map from AST to AST *) + module ASTMap : + sig + type ast_map + + (** Checks whether the map contains a key. + @return True if the key in the map, false otherwise. *) + val contains : ast_map -> ast -> bool - The different kinds of parameters that can be associated with parameter sets. - (see {!mk_params}). + (** Finds the value associated with the key. + This function signs an error when the key is not a key in the map. *) + val find : ast_map -> ast -> ast - - PK_UINT integer parameters. - - PK_BOOL boolean parameters. - - PK_DOUBLE double parameters. - - PK_SYMBOL symbol parameters. - - PK_STRING string parameters. - - PK_OTHER all internal parameter kinds which are not exposed in the API. - - PK_INVALID invalid parameter. -*) -(** - {!ast_print_mode} - Z3 pretty printing modes (See {!set_ast_print_mode}). - - PRINT_SMTLIB_FULL: Print AST nodes in SMTLIB verbose format. - - PRINT_LOW_LEVEL: Print AST nodes using a low-level format. - - PRINT_SMTLIB_COMPLIANT: Print AST nodes in SMTLIB 1.x compliant format. - - PRINT_SMTLIB2_COMPLIANT: Print AST nodes in SMTLIB 2.x compliant format. -*) -(** - {!error_code} - Z3 error codes - - OK: No error. - - SORT_ERROR: User tried to build an invalid (type incorrect) AST. - - IOB: Index out of bounds. - - INVALID_ARG: Invalid argument was provided. - - PARSER_ERROR: An error occurred when parsing a string or file. - - NO_PARSER: Parser output is not available, that is, user didn't invoke {!parse_smtlib_string} or {!parse_smtlib_file}. - - INVALID_PATTERN: Invalid pattern was used to build a quantifier. - - MEMOUT_FAIL: A memory allocation failure was encountered. - - FILE_ACCESS_ERRROR: A file could not be accessed. - - INVALID_USAGE: API call is invalid in the current state. - - INTERNAL_FATAL: An error internal to Z3 occurred. - - DEC_REF_ERROR: Trying to decrement the reference counter of an AST that was deleted or the reference counter was not initialized. - - EXCEPTION: Internal Z3 exception. Additional details can be retrieved using {!get_error_msg}. -*) -(** - Definitions for update_api.py - def_Type('CONFIG', 'config', 'Config') - def_Type('CONTEXT', 'context', 'ContextObj') - def_Type('AST', 'ast', 'Ast') - def_Type('APP', 'app', 'Ast') - def_Type('SORT', 'sort', 'Sort') - def_Type('FUNC_DECL', 'func_decl', 'FuncDecl') - def_Type('PATTERN', 'pattern', 'Pattern') - def_Type('MODEL', 'model', 'Model') - def_Type('LITERALS', 'literals', 'Literals') - def_Type('CONSTRUCTOR', 'constructor', 'Constructor') - def_Type('CONSTRUCTOR_LIST', 'constructor_list', 'ConstructorList') - def_Type('THEORY', 'theory', 'ctypes.c_void_p') - def_Type('THEORY_DATA', 'theory_data', 'ctypes.c_void_p') - def_Type('SOLVER', 'solver', 'SolverObj') - def_Type('GOAL', 'goal', 'GoalObj') - def_Type('TACTIC', 'tactic', 'TacticObj') - def_Type('PARAMS', 'params', 'Params') - def_Type('PROBE', 'probe', 'ProbeObj') - def_Type('STATS', 'stats', 'StatsObj') - def_Type('AST_VECTOR', 'ast_vector', 'AstVectorObj') - def_Type('AST_MAP', 'ast_map', 'AstMapObj') - def_Type('APPLY_RESULT', 'apply_result', 'ApplyResultObj') - def_Type('FUNC_INTERP', 'func_interp', 'FuncInterpObj') - def_Type('FUNC_ENTRY', 'func_entry', 'FuncEntryObj') - def_Type('FIXEDPOINT', 'fixedpoint', 'FixedpointObj') - def_Type('PARAM_DESCRS', 'param_descrs', 'ParamDescrs') -*) + (** Stores or replaces a new key/value pair in the map. *) + val insert : ast_map -> ast -> ast -> unit -(** Exceptions raised by Z3. It is safe to continue interacting with Z3 after - catching [Error] exceptions. - - {b See also}: {!get_error_msg} -*) -exception Error of context * error_code + (** Erases the key from the map.*) + val erase : ast_map -> ast -> unit -(** - {!goal_prec} - A Goal is essentially a set of formulas. Z3 provide APIs for building strategies/tactics for solving and transforming Goals. Some of these transformations apply under/over approximations. - - GOAL_PRECISE: Approximations/Relaxations were not applied on the goal (sat and unsat answers were preserved). - - GOAL_UNDER: Goal is the product of a under-approximation (sat answers are preserved). - - GOAL_OVER: Goal is the product of an over-approximation (unsat answers are preserved). - - GOAL_UNDER_OVER: Goal is garbage (it is the product of over- and under-approximations, sat and unsat answers are not preserved). -*) -(** - {2 {L Create context}} -*) -(** - Summary: Create a context using the given configuration. - After a context is created, the configuration cannot be changed, - although some parameters can be changed using {!update_param_value}. - All main interaction with Z3 happens in the context of a [context]. - def_API('mk_context', CONTEXT, (_in(CONFIG),)) -*) -external mk_context: (string * string) list -> context = "caml_z3_mk_context" + (** Removes all keys from the map. *) + val reset : ast_map -> unit -(** - Summary: Set a value of a context parameter. - - {b See also}: {!global_param_set} - def_API('update_param_value', VOID, (_in(CONTEXT), _in(STRING), _in(STRING))) -*) -external update_param_value : context -> string -> string -> unit - = "camlidl_z3_Z3_update_param_value" + (** The size of the map *) + val get_size : ast_map -> int -(** - Summary: Return the value of a context parameter. - - {b See also}: {!global_param_get} - def_API('get_param_value', BOOL, (_in(CONTEXT), _in(STRING), _out(STRING))) -*) -external get_param_value : context -> string -> string option - = "camlidl_z3_Z3_get_param_value" + (** The keys stored in the map. *) + val get_keys : ast_map -> ast list -(** - Summary: Interrupt the execution of a Z3 procedure. - This procedure can be used to interrupt: solvers, simplifiers and tactics. - def_API('interrupt', VOID, (_in(CONTEXT),)) -*) -external interrupt : context -> unit - = "camlidl_z3_Z3_interrupt" + (** Retrieves a string representation of the map.*) + val to_string : ast_map -> string + end -(** - {2 {L Parameters}} -*) -(** - Summary: Create a Z3 (empty) parameter set. - Starting at Z3 4.0, parameter sets are used to configure many components such as: - simplifiers, tactics, solvers, etc. - def_API('mk_params', PARAMS, (_in(CONTEXT),)) -*) -external mk_params : context -> params - = "camlidl_z3_Z3_mk_params" + (** The AST's hash code. + @return A hash code *) + val hash : ast -> int -(** - Summary: Add a Boolean parameter [k] with value [v] to the parameter set [p]. - def_API('params_set_bool', VOID, (_in(CONTEXT), _in(PARAMS), _in(SYMBOL), _in(BOOL))) -*) -external params_set_bool : context -> params -> symbol -> bool -> unit - = "camlidl_z3_Z3_params_set_bool" + (** A unique identifier for the AST (unique among all ASTs). *) + val get_id : ast -> int -(** - Summary: Add a unsigned int parameter [k] with value [v] to the parameter set [p]. - def_API('params_set_uint', VOID, (_in(CONTEXT), _in(PARAMS), _in(SYMBOL), _in(UINT))) -*) -external params_set_uint : context -> params -> symbol -> int -> unit - = "camlidl_z3_Z3_params_set_uint" + (** The kind of the AST. *) + val get_ast_kind : ast -> Z3enums.ast_kind -(** - Summary: Add a double parameter [k] with value [v] to the parameter set [p]. - def_API('params_set_double', VOID, (_in(CONTEXT), _in(PARAMS), _in(SYMBOL), _in(DOUBLE))) -*) -external params_set_double : context -> params -> symbol -> float -> unit - = "camlidl_z3_Z3_params_set_double" + (** Indicates whether the AST is an Expr *) + val is_expr : ast -> bool -(** - Summary: Add a symbol parameter [k] with value [v] to the parameter set [p]. - def_API('params_set_symbol', VOID, (_in(CONTEXT), _in(PARAMS), _in(SYMBOL), _in(SYMBOL))) -*) -external params_set_symbol : context -> params -> symbol -> symbol -> unit - = "camlidl_z3_Z3_params_set_symbol" + (** Indicates whether the AST is a bound variable*) + val is_var : ast -> bool -(** - Summary: Convert a parameter set into a string. This function is mainly used for printing the - contents of a parameter set. - def_API('params_to_string', STRING, (_in(CONTEXT), _in(PARAMS))) -*) -external params_to_string : context -> params -> string - = "camlidl_z3_Z3_params_to_string" + (** Indicates whether the AST is a Quantifier *) + val is_quantifier : ast -> bool -(** - Summary: Validate the parameter set [p] against the parameter description set [d]. - The procedure invokes the error handler if [p] is invalid. - def_API('params_validate', VOID, (_in(CONTEXT), _in(PARAMS), _in(PARAM_DESCRS))) -*) -external params_validate : context -> params -> param_descrs -> unit - = "camlidl_z3_Z3_params_validate" + (** Indicates whether the AST is a Sort *) + val is_sort : ast -> bool -(** - {2 {L Parameter Descriptions}} -*) -(** - Summary: Return the kind associated with the given parameter name [n]. - def_API('param_descrs_get_kind', UINT, (_in(CONTEXT), _in(PARAM_DESCRS), _in(SYMBOL))) -*) -external param_descrs_get_kind : context -> param_descrs -> symbol -> param_kind - = "camlidl_z3_Z3_param_descrs_get_kind" + (** Indicates whether the AST is a func_decl *) + val is_func_decl : ast -> bool -(** - Summary: Return the number of parameters in the given parameter description set. - def_API('param_descrs_size', UINT, (_in(CONTEXT), _in(PARAM_DESCRS))) -*) -external param_descrs_size : context -> param_descrs -> int - = "camlidl_z3_Z3_param_descrs_size" + (** A string representation of the AST. *) + val to_string : ast -> string -(** - Summary: Return the number of parameters in the given parameter description set. - - {b Precondition}: i < param_descrs_size c p - def_API('param_descrs_get_name', SYMBOL, (_in(CONTEXT), _in(PARAM_DESCRS), _in(UINT))) -*) -external param_descrs_get_name : context -> param_descrs -> int -> symbol - = "camlidl_z3_Z3_param_descrs_get_name" + (** A string representation of the AST in s-expression notation. *) + val to_sexpr : ast -> string -(** - Summary: Convert a parameter description set into a string. This function is mainly used for printing the - contents of a parameter description set. - def_API('param_descrs_to_string', STRING, (_in(CONTEXT), _in(PARAM_DESCRS))) -*) -external param_descrs_to_string : context -> param_descrs -> string - = "camlidl_z3_Z3_param_descrs_to_string" + (** Comparison operator. + @return True if the two ast's are from the same context + and represent the same sort; false otherwise. *) + val equal : ast -> ast -> bool -(** - {2 {L Symbols}} -*) + (** Object Comparison. + @return Negative if the first ast should be sorted before the second, positive if after else zero. *) + val compare : ast -> ast -> int -(** - Refined view of a {!symbol}. - - {b See also}: {!mk_symbol} - - {b See also}: {!symbol_refine} -*) -type symbol_refined = - | Symbol_int of int - | Symbol_string of string + (** Translates (copies) the AST to another context. + @return A copy of the AST which is associated with the other context. *) + val translate : ast -> context -> ast - -(** - Summary: \[ [ mk_symbol c sr ] \] constructs the symbol described by [sr]. - - {b See also}: {!symbol_refine} -*) -val mk_symbol: context -> symbol_refined -> symbol - -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Create a Z3 symbol using an integer. - Symbols are used to name several term and type constructors. - NB. Not all integers can be passed to this function. - The legal range of unsigned int integers is 0 to 2^30-1. - - {b See also}: {!mk_string_symbol} - def_API('mk_int_symbol', SYMBOL, (_in(CONTEXT), _in(INT))) -*) -external mk_int_symbol : context -> int -> symbol - = "camlidl_z3_Z3_mk_int_symbol" - -<<<<<<< HEAD -(** - Summary: Create a Z3 symbol using a C string. - Symbols are used to name several term and type constructors. - - {b See also}: {!mk_int_symbol} - def_API('mk_string_symbol', SYMBOL, (_in(CONTEXT), _in(STRING))) -*) -external mk_string_symbol : context -> string -> symbol - = "camlidl_z3_Z3_mk_string_symbol" - -(** - {2 {L Sorts}} -*) - -(** - A datatype constructor descriptor. -*) -type datatype_constructor_desc = { - constructor_desc : symbol; (** name of the constructor function *) - recognizer_desc : symbol; (** name of the recognizer function *) - accessor_descs : (symbol * sort) array; (** names and sorts of the fields *) -} -(** - A datatype is described by a name and constructor descriptors. -*) -type datatype_desc = symbol * datatype_constructor_desc array -(** - A datatype constructor representation. -*) -type datatype_constructor = { - constructor : func_decl; (** constructor function *) - recognizer : func_decl; (** recognizer function *) - accessors : func_decl array; (** field accessor functions *) -} -(** - A datatype is represented by a sort and constructors. -*) -type datatype = sort * datatype_constructor array -(** - Refined view of a {!sort}. - - {b See also}: {!mk_sort} - - {b See also}: {!sort_refine} -*) -type sort_refined = - | Sort_uninterpreted of symbol - | Sort_bool - | Sort_int - | Sort_bv of int - | Sort_finite_domain of symbol * int64 - | Sort_real - | Sort_array of sort * sort - | Sort_datatype of datatype_constructor array - | Sort_relation of sort array - | Sort_unknown -======= (** Unwraps an AST. This function is used for transitions between native and managed objects. It returns the native pointer to the AST. Note that @@ -1176,573 +254,185 @@ type sort_refined = Z3native.inc_ref). *) val wrap_ast : context -> Z3native.z3_ast -> ast end ->>>>>>> Updates to ML API. +(** The Sort module implements type information for ASTs *) +module Sort : +sig + type sort = Sort of AST.ast -(** - Summary: \[ [ mk_sort c sr ] \] constructs the sort described by [sr]. - - {b Precondition}: [sr] is not of form [Sort_relation] or [Sort_unknown], which cannot be directly constructed - - {b See also}: {!mk_datatypes} - - {b See also}: {!sort_refine} -*) -val mk_sort: context -> sort_refined -> sort -(** - \[ [mk_datatypes ctx sorts_to_descriptors] \] creates mutually recursive datatypes described by - [sorts_to_descriptors], which is a function from the sorts of the datatypes to be created to - descriptors of the datatypes' constructors. - - {b See also}: {!Test_mlapi.forest_example} -*) -val mk_datatypes: context -> (sort array -> (datatype_desc array) option) -> datatype array + val ast_of_sort : sort -> AST.ast -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Create a free (uninterpreted) type using the given name (symbol). - Two free types are considered the same iff the have the same name. - def_API('mk_uninterpreted_sort', SORT, (_in(CONTEXT), _in(SYMBOL))) -*) -external mk_uninterpreted_sort : context -> symbol -> sort - = "camlidl_z3_Z3_mk_uninterpreted_sort" + (** Comparison operator. + @return True if the two sorts are from the same context + and represent the same sort; false otherwise. *) + val equal : sort -> sort -> bool -(** - Summary: Create the Boolean type. - This type is used to create propositional variables and predicates. - def_API('mk_bool_sort', SORT, (_in(CONTEXT), )) -*) -external mk_bool_sort : context -> sort - = "camlidl_z3_Z3_mk_bool_sort" + (** Returns a unique identifier for the sort. *) + val get_id : sort -> int -(** - Summary: Create the integer type. - This type is not the int type found in programming languages. - A machine integer can be represented using bit-vectors. The function - {!mk_bv_sort} creates a bit-vector type. - - {b See also}: {!mk_bv_sort} - def_API('mk_int_sort', SORT, (_in(CONTEXT), )) -*) -external mk_int_sort : context -> sort - = "camlidl_z3_Z3_mk_int_sort" + (** The kind of the sort. *) + val get_sort_kind : sort -> Z3enums.sort_kind -(** - Summary: Create the real type. - This type is not a floating point number. - Z3 does not have support for floating point numbers yet. - def_API('mk_real_sort', SORT, (_in(CONTEXT), )) -*) -external mk_real_sort : context -> sort - = "camlidl_z3_Z3_mk_real_sort" + (** The name of the sort *) + val get_name : sort -> Symbol.symbol -(** - Summary: Create a bit-vector type of the given size. - This type can also be seen as a machine integer. - - {b Remarks}: The size of the bitvector type must be greater than zero. - def_API('mk_bv_sort', SORT, (_in(CONTEXT), _in(UINT))) -*) -external mk_bv_sort : context -> int -> sort - = "camlidl_z3_Z3_mk_bv_sort" + (** A string representation of the sort. *) + val to_string : sort -> string -(** - Summary: Create a named finite domain sort. - To create constants that belong to the finite domain, - use the APIs for creating numerals and pass a numeric - constant together with the sort returned by this call. - - {b See also}: {!get_finite_domain_sort_size} - def_API('mk_finite_domain_sort', SORT, (_in(CONTEXT), _in(SYMBOL), _in(UINT64))) -*) -external mk_finite_domain_sort : context -> symbol -> int64 -> sort - = "camlidl_z3_Z3_mk_finite_domain_sort" + (** Create a new uninterpreted sort. *) + val mk_uninterpreted : context -> Symbol.symbol -> sort -(** - Summary: Create an array type. - We usually represent the array type as: {e [domain -> range] }. - Arrays are usually used to model the heap/memory in software verification. - - {b See also}: {!mk_select} - - {b See also}: {!mk_store} - def_API('mk_array_sort', SORT, (_in(CONTEXT), _in(SORT), _in(SORT))) -*) -external mk_array_sort : context -> sort -> sort -> sort - = "camlidl_z3_Z3_mk_array_sort" + (** Create a new uninterpreted sort. *) + val mk_uninterpreted_s : context -> string -> sort +end -(** - Summary: Create a tuple type. - [mk_tuple_sort c name field_names field_sorts] creates a tuple with a constructor named [name], - a [n] fields, where [n] is the size of the arrays [field_names] and [field_sorts]. - @param c logical context - @param mk_tuple_name name of the constructor function associated with the tuple type. - @param num_fields number of fields in the tuple type. - @param field_names name of the projection functions. - @param field_sorts type of the tuple fields. - @param mk_tuple_decl output parameter that will contain the constructor declaration. - @param proj_decl output parameter that will contain the projection function declarations. This field must be a buffer of size [num_fields] allocated by the user. - def_API('mk_tuple_sort', SORT, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _out(FUNC_DECL), _out_array(2, FUNC_DECL))) -*) -external mk_tuple_sort : context -> symbol -> symbol array -> sort array -> sort * func_decl * func_decl array - = "camlidl_z3_Z3_mk_tuple_sort" +(** Function declarations *) +module rec FuncDecl : +sig + type func_decl = FuncDecl of AST.ast -(** - Summary: Create a enumeration sort. - [mk_enumeration_sort c enums] creates an enumeration sort with enumeration names [enums], - it also returns [n] predicates, where [n] is the number of [enums] corresponding - to testing whether an element is one of the enumerants. - @param c logical context - @param name name of the enumeration sort. - @param n number of elemenets in enumeration sort. - @param enum_names names of the enumerated elements. - @param enum_consts constants corresponding to the enumerated elements. - @param enum_testers predicates testing if terms of the enumeration sort correspond to an enumeration. - For example, if this function is called with three symbols A, B, C and the name S, then - [s] is a sort whose name is S, and the function returns three terms corresponding to A, B, C in - [enum_consts]. The array [enum_testers] has three predicates of type {e (s -> Bool) }. - The first predicate (corresponding to A) is true when applied to A, and false otherwise. - Similarly for the other predicates. - def_API('mk_enumeration_sort', SORT, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _in_array(2, SYMBOL), _out_array(2, FUNC_DECL), _out_array(2, FUNC_DECL))) -*) -external mk_enumeration_sort : context -> symbol -> symbol array -> sort * func_decl array * func_decl array - = "camlidl_z3_Z3_mk_enumeration_sort" + val ast_of_func_decl : FuncDecl.func_decl -> AST.ast -(** - Summary: Create a list sort - [mk_list_sort c name elem_sort] creates a list sort of [name], over elements of sort [elem_sort]. - @param c logical context - @param name name of the list sort. - @param elem_sort sort of list elements. - @param nil_decl declaration for the empty list. - @param is_nil_decl test for the empty list. - @param cons_decl declaration for a cons cell. - @param is_cons_decl cons cell test. - @param head_decl list head. - @param tail_decl list tail. - def_API('mk_list_sort', SORT, (_in(CONTEXT), _in(SYMBOL), _in(SORT), _out(FUNC_DECL), _out(FUNC_DECL), _out(FUNC_DECL), _out(FUNC_DECL), _out(FUNC_DECL), _out(FUNC_DECL))) -*) -external mk_list_sort : context -> symbol -> sort -> sort * func_decl * func_decl * func_decl * func_decl * func_decl * func_decl - = "camlidl_z3_Z3_mk_list_sort" + (** Parameters of Func_Decls *) + module Parameter : + sig + (** Parameters of func_decls *) + type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + (** The kind of the parameter. *) + val get_kind : parameter -> Z3enums.parameter_kind -(* -(** - Summary: Create a constructor. - @param c logical context. - @param name constructor name. - @param recognizer name of recognizer function. - @param num_fields number of fields in constructor. - @param field_names names of the constructor fields. - @param sorts field sorts, [None] - if the field sort refers to a recursive sort. - @param sort_refs reference to datatype sort that is an argument to the constructor; if the corresponding - sort reference is [None], - then the value in sort_refs should be an index referring to - one of the recursive datatypes that is declared. - def_API('mk_constructor', CONSTRUCTOR, (_in(CONTEXT), _in(SYMBOL), _in(SYMBOL), _in(UINT), _in_array(3, SYMBOL), _in_array(3, SORT), _in_array(3, UINT))) -*) -external mk_constructor : context -> symbol -> symbol -> symbol array -> sort option array -> int array -> constructor - = "camlidl_z3_Z3_mk_constructor_bytecode" "camlidl_z3_Z3_mk_constructor" + (** The int value of the parameter.*) + val get_int : parameter -> int -(** - Summary: Reclaim memory allocated to constructor. - @param c logical context. - @param constr constructor. - def_API('del_constructor', VOID, (_in(CONTEXT), _in(CONSTRUCTOR))) -*) -external del_constructor : context -> constructor -> unit - = "camlidl_z3_Z3_del_constructor" + (** The float value of the parameter.*) + val get_float : parameter -> float -(** - Summary: Create datatype, such as lists, trees, records, enumerations or unions of records. - The datatype may be recursive. Return the datatype sort. - @param c logical context. - @param name name of datatype. - @param num_constructors number of constructors passed in. - @param constructors array of constructor containers. - def_API('mk_datatype', SORT, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _inout_array(2, CONSTRUCTOR))) -*) -external mk_datatype : context -> symbol -> constructor array -> sort * constructor array - = "camlidl_z3_Z3_mk_datatype" + (** The Symbol.Symbol value of the parameter.*) + val get_symbol : parameter -> Symbol.symbol -(** - Summary: Create list of constructors. - @param c logical context. - @param num_constructors number of constructors in list. - @param constructors list of constructors. - def_API('mk_constructor_list', CONSTRUCTOR_LIST, (_in(CONTEXT), _in(UINT), _in_array(1, CONSTRUCTOR))) -*) -external mk_constructor_list : context -> constructor array -> constructor_list - = "camlidl_z3_Z3_mk_constructor_list" + (** The Sort value of the parameter.*) + val get_sort : parameter -> Sort.sort -(** - Summary: Reclaim memory allocated for constructor list. - Each constructor inside the constructor list must be independently reclaimed using {!del_constructor}. - @param c logical context. - @param clist constructor list container. - def_API('del_constructor_list', VOID, (_in(CONTEXT), _in(CONSTRUCTOR_LIST))) -*) -external del_constructor_list : context -> constructor_list -> unit - = "camlidl_z3_Z3_del_constructor_list" + (** The AST value of the parameter.*) + val get_ast : parameter -> AST.ast -(** - Summary: Create mutually recursive datatypes. - @param c logical context. - @param num_sorts number of datatype sorts. - @param sort_names names of datatype sorts. - @param sorts array of datatype sorts. - @param constructor_lists list of constructors, one list per sort. - def_API('mk_datatypes', VOID, (_in(CONTEXT), _in(UINT), _in_array(1, SYMBOL), _out_array(1, SORT), _inout_array(1, CONSTRUCTOR_LIST))) -*) -external mk_datatypes : context -> symbol array -> constructor_list array -> sort array * constructor_list array - = "camlidl_z3_Z3_mk_datatypes" + (** The FunctionDeclaration value of the parameter.*) + val get_func_decl : parameter -> func_decl -(** - Summary: Query constructor for declared functions. - @param c logical context. - @param constr constructor container. The container must have been passed in to a {!mk_datatype} call. - @param num_fields number of accessor fields in the constructor. - @param constructor constructor function declaration. - @param tester constructor test function declaration. - @param accessors array of accessor function declarations. - def_API('query_constructor', VOID, (_in(CONTEXT), _in(CONSTRUCTOR), _in(UINT), _out(FUNC_DECL), _out(FUNC_DECL), _out_array(2, FUNC_DECL))) -*) -external query_constructor : context -> constructor -> int -> func_decl * func_decl * func_decl array - = "camlidl_z3_Z3_query_constructor" + (** The rational string value of the parameter.*) + val get_rational : parameter -> string + end -*) -(** - {2 {L Constants and Applications}} -*) -(** - Summary: Declare a constant or function. - [mk_func_decl c n d r] creates a function with name [n], domain [d], and range [r]. - The arity of the function is the size of the array [d]. - @param c logical context. - @param s name of the constant or function. - @param domain_size number of arguments. It is 0 when declaring a constant. - @param domain array containing the sort of each argument. The array must contain domain_size elements. It is 0 when declaring a constant. - @param range sort of the constant or the return sort of the function. - After declaring a constant or function, the function - {!mk_app} can be used to create a constant or function - application. - - {b See also}: {!mk_app} - def_API('mk_func_decl', FUNC_DECL, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _in_array(2, SORT), _in(SORT))) -*) -external mk_func_decl : context -> symbol -> sort array -> sort -> func_decl - = "camlidl_z3_Z3_mk_func_decl" + (** Creates a new function declaration. *) + val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl -(** - Summary: Create a constant or function application. - - {b See also}: {!mk_func_decl} - def_API('mk_app', AST, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT), _in_array(2, AST))) -*) -external mk_app : context -> func_decl -> ast array -> ast - = "camlidl_z3_Z3_mk_app" + (** Creates a new function declaration. *) + val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl + (** Creates a fresh function declaration with a name prefixed with a prefix string. *) -(** - Summary: Declare and create a constant. - [mk_const c s t] is a shorthand for [mk_app c (mk_func_decl c s [||] t) [||]] - - {b See also}: {!mk_func_decl} - - {b See also}: {!mk_app} - def_API('mk_const', AST, (_in(CONTEXT), _in(SYMBOL), _in(SORT))) -*) -external mk_const : context -> symbol -> sort -> ast - = "camlidl_z3_Z3_mk_const" + val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl -(** - Summary: Declare a fresh constant or function. - Z3 will generate an unique name for this function declaration. - - {b See also}: {!mk_func_decl} - def_API('mk_fresh_func_decl', FUNC_DECL, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SORT), _in(SORT))) -*) -external mk_fresh_func_decl : context -> string -> sort array -> sort -> func_decl - = "camlidl_z3_Z3_mk_fresh_func_decl" + (** Creates a new constant function declaration. *) + val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl -(** - Summary: Declare and create a fresh constant. - [mk_fresh_const c p t] is a shorthand for [mk_app c (mk_fresh_func_decl c p [||] t) [||]]. - - {b See also}: {!mk_func_decl} - - {b See also}: {!mk_app} - def_API('mk_fresh_const', AST, (_in(CONTEXT), _in(STRING), _in(SORT))) -*) -external mk_fresh_const : context -> string -> sort -> ast - = "camlidl_z3_Z3_mk_fresh_const" + (** Creates a new constant function declaration. *) + val mk_const_decl_s : context -> string -> Sort.sort -> func_decl -(** - {2 {L Propositional Logic and Equality}} -*) -(** - Summary: Create an AST node representing [true]. - def_API('mk_true', AST, (_in(CONTEXT), )) -*) -external mk_true : context -> ast - = "camlidl_z3_Z3_mk_true" + (** Creates a fresh constant function declaration with a name prefixed with a prefix string. + {!mk_func_decl} + {!mk_func_decl} *) + val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl -(** - Summary: Create an AST node representing [false]. - def_API('mk_false', AST, (_in(CONTEXT), )) -*) -external mk_false : context -> ast - = "camlidl_z3_Z3_mk_false" + (** Comparison operator. + @return True if a and b are from the same context and represent the same func_decl; false otherwise. *) + val equal : func_decl -> func_decl -> bool -(** - Summary: \[ [ mk_eq c l r ] \] - Create an AST node representing {e l = r }. - The nodes [l] and [r] must have the same type. - def_API('mk_eq', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_eq : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_eq" + (** A string representations of the function declaration. *) + val to_string : func_decl -> string -(** - Summary: \[ [mk_distinct c [| t_1; ...; t_n |]] \] Create an AST - node represeting a distinct construct. It is used for declaring - the arguments t_i pairwise distinct. - The [distinct] construct is used for declaring the arguments pairwise distinct. - That is, {e Forall 0 <= i < j < num_args. not args[i] = args[j] }. - All arguments must have the same sort. - - {b Remarks}: The number of arguments of a distinct construct must be greater than one. - def_API('mk_distinct', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_distinct : context -> ast array -> ast - = "camlidl_z3_Z3_mk_distinct" + (** Returns a unique identifier for the function declaration. *) + val get_id : func_decl -> int -(** - Summary: \[ [ mk_not c a ] \] - Create an AST node representing {e not(a) }. - The node [a] must have Boolean sort. - def_API('mk_not', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_not : context -> ast -> ast - = "camlidl_z3_Z3_mk_not" + (** The arity of the function declaration *) + val get_arity : func_decl -> int -(** - Summary: \[ [ mk_ite c t1 t2 t2 ] \] - Create an AST node representing an if-then-else: {e ite(t1, t2, - t3) }. - The node [t1] must have Boolean sort, [t2] and [t3] must have the same sort. - The sort of the new node is equal to the sort of [t2] and [t3]. - def_API('mk_ite', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(AST))) -*) -external mk_ite : context -> ast -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_ite" + (** The size of the domain of the function declaration + {!get_arity} *) + val get_domain_size : func_decl -> int + + (** The domain of the function declaration *) + val get_domain : func_decl -> Sort.sort list + + (** The range of the function declaration *) + val get_range : func_decl -> Sort.sort -(** - Summary: \[ [ mk_iff c t1 t2 ] \] - Create an AST node representing {e t1 iff t2 }. - The nodes [t1] and [t2] must have Boolean sort. - def_API('mk_iff', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_iff : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_iff" + (** The kind of the function declaration. *) + val get_decl_kind : func_decl -> Z3enums.decl_kind -(** - Summary: \[ [ mk_implies c t1 t2 ] \] - Create an AST node representing {e t1 implies t2 }. - The nodes [t1] and [t2] must have Boolean sort. - def_API('mk_implies', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_implies : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_implies" + (** The name of the function declaration*) + val get_name : func_decl -> Symbol.symbol -(** - Summary: \[ [ mk_xor c t1 t2 ] \] - Create an AST node representing {e t1 xor t2 }. - The nodes [t1] and [t2] must have Boolean sort. - def_API('mk_xor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_xor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_xor" + (** The number of parameters of the function declaration *) + val get_num_parameters : func_decl -> int -(** - Summary: \[ [mk_and c [| t_1; ...; t_n |]] \] Create the conjunction: {e t_1 and ... and t_n}. - All arguments must have Boolean sort. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_and', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_and : context -> ast array -> ast - = "camlidl_z3_Z3_mk_and" + (** The parameters of the function declaration *) + val get_parameters : func_decl -> Parameter.parameter list -(** - Summary: \[ [mk_or c [| t_1; ...; t_n |]] \] Create the disjunction: {e t_1 or ... or t_n}. - All arguments must have Boolean sort. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_or', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_or : context -> ast array -> ast - = "camlidl_z3_Z3_mk_or" + (** Create expression that applies function to arguments. *) + val apply : func_decl -> Expr.expr list -> Expr.expr +end -(** - {2 {L Arithmetic: Integers and Reals}} -*) -(** - Summary: \[ [mk_add c [| t_1; ...; t_n |]] \] Create the term: {e t_1 + ... + t_n}. - All arguments must have int or real sort. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_add', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_add : context -> ast array -> ast - = "camlidl_z3_Z3_mk_add" +(** Parameter sets (of Solvers, Tactics, ...) -(** - Summary: \[ [mk_mul c [| t_1; ...; t_n |]] \] Create the term: {e t_1 * ... * t_n}. - All arguments must have int or real sort. - - {b Remarks}: Z3 has limited support for non-linear arithmetic. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_mul', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_mul : context -> ast array -> ast - = "camlidl_z3_Z3_mk_mul" + A Params objects represents a configuration in the form of Symbol.symbol/value pairs. *) +and Params : +sig + type params -(** - Summary: \[ [mk_sub c [| t_1; ...; t_n |]] \] Create the term: {e t_1 - ... - t_n}. - All arguments must have int or real sort. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_sub', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_sub : context -> ast array -> ast - = "camlidl_z3_Z3_mk_sub" + (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) + module ParamDescrs : + sig + type param_descrs -(** - Summary: \[ [mk_unary_minus c arg] \] Create the term: {e - arg}. - The arguments must have int or real type. - def_API('mk_unary_minus', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_unary_minus : context -> ast -> ast - = "camlidl_z3_Z3_mk_unary_minus" + (** Validate a set of parameters. *) + val validate : param_descrs -> params -> unit -(** - Summary: \[ [mk_div c t_1 t_2] \] Create the term: {e t_1 div t_2}. - The arguments must either both have int type or both have real type. - If the arguments have int type, then the result type is an int type, otherwise the - the result type is real. - def_API('mk_div', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_div : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_div" + (** Retrieve kind of parameter. *) + val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind -(** - Summary: \[ [mk_mod c t_1 t_2] \] Create the term: {e t_1 mod t_2}. - The arguments must have int type. - def_API('mk_mod', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_mod : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_mod" + (** Retrieve all names of parameters. *) + val get_names : param_descrs -> Symbol.symbol list -(** - Summary: \[ [mk_rem c t_1 t_2] \] Create the term: {e t_1 rem t_2}. - The arguments must have int type. - def_API('mk_rem', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_rem : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_rem" + (** The size of the ParamDescrs. *) + val get_size : param_descrs -> int -(** - The arguments must have int or real type. - def_API('mk_power', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_power : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_power" + (** Retrieves a string representation of the ParamDescrs. *) + val to_string : param_descrs -> string + end -(** - Summary: \[ [ mk_lt c t1 t2 ] \] - Create less than. - The nodes [t1] and [t2] must have the same sort, and must be int or real. - def_API('mk_lt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_lt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_lt" + (** Adds a parameter setting. *) + val add_bool : params -> Symbol.symbol -> bool -> unit -(** - Summary: \[ [ mk_le c t1 t2 ] \] - Create less than or equal to. - The nodes [t1] and [t2] must have the same sort, and must be int or real. - def_API('mk_le', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_le : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_le" + (** Adds a parameter setting. *) + val add_int : params -> Symbol.symbol -> int -> unit -(** - Summary: \[ [ mk_gt c t1 t2 ] \] - Create greater than. - The nodes [t1] and [t2] must have the same sort, and must be int or real. - def_API('mk_gt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_gt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_gt" + (** Adds a parameter setting. *) + val add_float : params -> Symbol.symbol -> float -> unit -(** - Summary: \[ [ mk_ge c t1 t2 ] \] - Create greater than or equal to. - The nodes [t1] and [t2] must have the same sort, and must be int or real. - def_API('mk_ge', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_ge : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_ge" + (** Adds a parameter setting. *) + val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit -(** - Summary: \[ [ mk_int2real c t1 ] \] - 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 constant [k] and - and asserting {e mk_int2real(k) <= t1 < mk_int2real(k)+1 }. - The node [t1] must have sort integer. - - {b See also}: {!mk_real2int} - - {b See also}: {!mk_is_int} - def_API('mk_int2real', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_int2real : context -> ast -> ast - = "camlidl_z3_Z3_mk_int2real" + (** Creates a new parameter set *) + val mk_params : context -> params -(** - Summary: \[ [ mk_real2int c t1 ] \] - Coerce a real to an integer. - The semantics of this function follows the SMT-LIB standard - for the function to_int - - {b See also}: {!mk_int2real} - - {b See also}: {!mk_is_int} - def_API('mk_real2int', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_real2int : context -> ast -> ast - = "camlidl_z3_Z3_mk_real2int" - -(** - Summary: \[ [ mk_is_int c t1 ] \] - Check if a real number is an integer. - - {b See also}: {!mk_int2real} - - {b See also}: {!mk_real2int} - def_API('mk_is_int', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_is_int : context -> ast -> ast - = "camlidl_z3_Z3_mk_is_int" - -(** - {2 {L Bit-vectors}} -*) -(** - Summary: \[ [ mk_bvnot c t1 ] \] - Bitwise negation. - The node [t1] must have a bit-vector sort. - def_API('mk_bvnot', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvnot : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvnot" - -(** - Summary: \[ [ mk_bvredand c t1 ] \] - Take conjunction of bits in vector, return vector of length 1. - The node [t1] must have a bit-vector sort. - def_API('mk_bvredand', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvredand : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvredand" - -<<<<<<< HEAD -(** - Summary: \[ [ mk_bvredor c t1 ] \] - Take disjunction of bits in vector, return vector of length 1. - The node [t1] must have a bit-vector sort. - def_API('mk_bvredor', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvredor : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvredor" -======= (** A string representation of the parameter set. *) val to_string : params -> string @@ -1776,249 +466,300 @@ external mk_bvredor : context -> ast -> ast {!Sort.to_string} *) val set_print_mode : context -> Z3enums.ast_print_mode -> unit end ->>>>>>> Updates to ML API. -(** - Summary: \[ [ mk_bvand c t1 t2 ] \] - Bitwise and. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvand', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvand : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvand" +(** General Expressions (terms) *) +and Expr : +sig + type expr = Expr of AST.ast -(** - Summary: \[ [ mk_bvor c t1 t2 ] \] - Bitwise or. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvor" + val ast_of_expr : Expr.expr -> AST.ast + val expr_of_ast : AST.ast -> Expr.expr -(** - Summary: \[ [ mk_bvxor c t1 t2 ] \] - Bitwise exclusive-or. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvxor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvxor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvxor" + (** Returns a simplified version of the expression. + {!get_simplify_help} *) + val simplify : Expr.expr -> Params.params option -> expr -(** - Summary: \[ [ mk_bvnand c t1 t2 ] \] - Bitwise nand. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvnand', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvnand : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvnand" + (** A string describing all available parameters to Expr.Simplify. *) + val get_simplify_help : context -> string -(** - Summary: \[ [ mk_bvnor c t1 t2 ] \] - Bitwise nor. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvnor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvnor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvnor" + (** Retrieves parameter descriptions for simplifier. *) + val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs -(** - Summary: \[ [ mk_bvxnor c t1 t2 ] \] - Bitwise xnor. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvxnor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvxnor : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvxnor" + (** The function declaration of the function that is applied in this expression. *) + val get_func_decl : Expr.expr -> FuncDecl.func_decl -(** - Summary: \[ [ mk_bvneg c t1 ] \] - Standard two's complement unary minus. - The node [t1] must have bit-vector sort. - def_API('mk_bvneg', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvneg : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvneg" + (** Indicates whether the expression is the true or false expression + or something else (L_UNDEF). *) + val get_bool_value : Expr.expr -> Z3enums.lbool -(** - Summary: \[ [ mk_bvadd c t1 t2 ] \] - Standard two's complement addition. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvadd', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvadd : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvadd" + (** The number of arguments of the expression. *) + val get_num_args : Expr.expr -> int -(** - Summary: \[ [ mk_bvsub c t1 t2 ] \] - Standard two's complement subtraction. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsub', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsub : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsub" + (** The arguments of the expression. *) + val get_args : Expr.expr -> Expr.expr list -(** - Summary: \[ [ mk_bvmul c t1 t2 ] \] - Standard two's complement multiplication. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvmul', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvmul : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvmul" + (** Update the arguments of the expression using an array of expressions. + The number of new arguments should coincide with the current number of arguments. *) + val update : Expr.expr -> Expr.expr list -> expr -(** - Summary: \[ [ mk_bvudiv c t1 t2 ] \] - Unsigned division. - It is defined as the [floor] of {e t1/t2 } if [t2] is - different from zero. If {e t2 } is zero, then the result - is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvudiv', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvudiv : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvudiv" + (** 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]. *) + val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr -(** - Summary: \[ [ mk_bvsdiv c t1 t2 ] \] - Two's complement signed division. - It is defined in the following way: - - The [floor] of {e t1/t2 } if [t2] is different from zero, and {e t1*t2 >= 0 }. - - The [ceiling] of {e t1/t2 } if [t2] is different from zero, and {e t1*t2 < 0 }. - If {e t2 } is zero, then the result is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsdiv', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsdiv : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsdiv" + (** Substitute every occurrence of from in the expression with to. + {!substitute} *) + val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr -(** - Summary: \[ [ mk_bvurem c t1 t2 ] \] - Unsigned remainder. - It is defined as {e t1 - (t1 /u t2) * t2 }, where {e /u } represents unsigned int division. - If {e t2 } is zero, then the result is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvurem', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvurem : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvurem" + (** Substitute the free variables in the expression with the expressions in the expr array -(** - Summary: \[ [ mk_bvsrem c t1 t2 ] \] - Two's complement signed remainder (sign follows dividend). - It is defined as {e t1 - (t1 /s t2) * t2 }, where {e /s } represents signed division. - The most significant bit (sign) of the result is equal to the most significant bit of [t1]. - If {e t2 } is zero, then the result is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - - {b See also}: {!mk_bvsmod} - def_API('mk_bvsrem', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsrem : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsrem" + For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) + val substitute_vars : Expr.expr -> Expr.expr list -> expr -(** - Summary: \[ [ mk_bvsmod c t1 t2 ] \] - Two's complement signed remainder (sign follows divisor). - If {e t2 } is zero, then the result is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - - {b See also}: {!mk_bvsrem} - def_API('mk_bvsmod', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsmod : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsmod" + (** Translates (copies) the term to another context. + @return A copy of the term which is associated with the other context *) + val translate : Expr.expr -> context -> expr -(** - Summary: \[ [ mk_bvult c t1 t2 ] \] - Unsigned less than. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvult', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvult : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvult" + (** Returns a string representation of the expression. *) + val to_string : Expr.expr -> string -(** - Summary: \[ [ mk_bvslt c t1 t2 ] \] - Two's complement signed less than. - It abbreviates: - {v - (or (and (= (extract[|m-1|:|m-1|] t1) bit1) - (= (extract[|m-1|:|m-1|] t2) bit0)) - (and (= (extract[|m-1|:|m-1|] t1) (extract[|m-1|:|m-1|] t2)) - (bvult t1 t2))) - v} - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvslt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvslt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvslt" + (** Indicates whether the term is a numeral *) + val is_numeral : Expr.expr -> bool -(** - Summary: \[ [ mk_bvule c t1 t2 ] \] - Unsigned less than or equal to. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvule', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvule : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvule" + (** Indicates whether the term is well-sorted. + @return True if the term is well-sorted, false otherwise. *) + val is_well_sorted : Expr.expr -> bool -(** - Summary: \[ [ mk_bvsle c t1 t2 ] \] - Two's complement signed less than or equal to. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsle', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsle : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsle" + (** The Sort of the term. *) + val get_sort : Expr.expr -> Sort.sort -(** - Summary: \[ [ mk_bvuge c t1 t2 ] \] - Unsigned greater than or equal to. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvuge', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvuge : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvuge" + (** Indicates whether the term has Boolean sort. *) + val is_bool : Expr.expr -> bool -(** - Summary: \[ [ mk_bvsge c t1 t2 ] \] - Two's complement signed greater than or equal to. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsge', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsge : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsge" + (** Indicates whether the term represents a constant. *) + val is_const : Expr.expr -> bool -(** - Summary: \[ [ mk_bvugt c t1 t2 ] \] - Unsigned greater than. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvugt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvugt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvugt" + (** Indicates whether the term is the constant true. *) + val is_true : Expr.expr -> bool -(** - Summary: \[ [ mk_bvsgt c t1 t2 ] \] - Two's complement signed greater than. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsgt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsgt : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsgt" + (** Indicates whether the term is the constant false. *) + val is_false : Expr.expr -> bool + + (** Indicates whether the term is an equality predicate. *) + val is_eq : Expr.expr -> bool + + (** Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). *) + val is_distinct : Expr.expr -> bool + + (** Indicates whether the term is a ternary if-then-else term *) + val is_ite : Expr.expr -> bool + + (** Indicates whether the term is an n-ary conjunction *) + val is_and : Expr.expr -> bool + + (** Indicates whether the term is an n-ary disjunction *) + val is_or : Expr.expr -> bool + + (** Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) *) + val is_iff : Expr.expr -> bool + + (** Indicates whether the term is an exclusive or *) + val is_xor : Expr.expr -> bool + + (** Indicates whether the term is a negation *) + val is_not : Expr.expr -> bool + + (** Indicates whether the term is an implication *) + val is_implies : Expr.expr -> bool + + (** 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. *) + val is_oeq : Expr.expr -> bool + + (** Creates a new constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + + (** Creates a new constant. *) + val mk_const_s : context -> string -> Sort.sort -> expr + + (** Creates a constant from the func_decl. *) + val mk_const_f : context -> FuncDecl.func_decl -> expr + + (** Creates a fresh constant with a name prefixed with a string. *) + val mk_fresh_const : context -> string -> Sort.sort -> expr + + (** Create a new function application. *) + val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr + + (** Create a numeral of a given sort. + @return A Term with the goven value and sort *) + val mk_numeral_string : context -> string -> Sort.sort -> expr + + (** Create a numeral 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. + @return A Term with the given value and sort *) + val mk_numeral_int : context -> int -> Sort.sort -> expr +end + +(** Boolean expressions *) +module Boolean : +sig + (** Create a Boolean sort *) + val mk_sort : context -> Sort.sort + + (** Create a Boolean constant. *) + val mk_const : context -> Symbol.symbol -> Expr.expr + + (** Create a Boolean constant. *) + val mk_const_s : context -> string -> Expr.expr + + (** The true Term. *) + val mk_true : context -> Expr.expr + + (** The false Term. *) + val mk_false : context -> Expr.expr + + (** Creates a Boolean value. *) + val mk_val : context -> bool -> Expr.expr + + (** Creates the equality between two expr's. *) + val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Creates a distinct term. *) + val mk_distinct : context -> Expr.expr list -> Expr.expr + + (** Mk an expression representing not(a). *) + val mk_not : context -> Expr.expr -> Expr.expr + + (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) + val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 iff t2. *) + val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 -> t2. *) + val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 xor t2. *) + val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing the AND of args *) + val mk_and : context -> Expr.expr list -> Expr.expr + + (** Create an expression representing the OR of args *) + val mk_or : context -> Expr.expr list -> Expr.expr +end + +(** Quantifier expressions *) +module Quantifier : +sig + type quantifier = Quantifier of Expr.expr + + val expr_of_quantifier : quantifier -> Expr.expr + val quantifier_of_expr : Expr.expr -> quantifier + + (** Quantifier patterns + + 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. *) + module Pattern : + sig + type pattern = Pattern of AST.ast + + val ast_of_pattern : pattern -> AST.ast + val pattern_of_ast : AST.ast -> pattern + + (** The number of terms in the pattern. *) + val get_num_terms : pattern -> int + + (** The terms in the pattern. *) + val get_terms : pattern -> Expr.expr list + + (** A string representation of the pattern. *) + val to_string : pattern -> string + end + + + (** 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 : expr ) appears, the higher is its + index. *) + val get_index : Expr.expr -> int + + (** Indicates whether the quantifier is universal. *) + val is_universal : quantifier -> bool + + (** Indicates whether the quantifier is existential. *) + val is_existential : quantifier -> bool + + (** The weight of the quantifier. *) + val get_weight : quantifier -> int + + (** The number of patterns. *) + val get_num_patterns : quantifier -> int + + (** The patterns. *) + val get_patterns : quantifier -> Pattern.pattern list + + (** The number of no-patterns. *) + val get_num_no_patterns : quantifier -> int + + (** The no-patterns. *) + val get_no_patterns : quantifier -> Pattern.pattern list + + (** The number of bound variables. *) + val get_num_bound : quantifier -> int + + (** The symbols for the bound variables. *) + val get_bound_variable_names : quantifier -> Symbol.symbol list + + (** The sorts of the bound variables. *) + val get_bound_variable_sorts : quantifier -> Sort.sort list + + (** The body of the quantifier. *) + val get_body : quantifier -> Expr.expr + + (** Creates a new bound variable. *) + val mk_bound : context -> int -> Sort.sort -> Expr.expr + + (** Create a quantifier pattern. *) + val mk_pattern : context -> Expr.expr list -> Pattern.pattern + + (** Create a universal Quantifier. *) + val mk_forall : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a universal Quantifier. *) + val mk_forall_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create an existential Quantifier. *) + val mk_exists : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create an existential Quantifier. *) + val mk_exists_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a Quantifier. *) + val mk_quantifier : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a Quantifier. *) + val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier +end -<<<<<<< HEAD -(** - Summary: \[ [ mk_concat c t1 t2 ] \] - Concatenate the given bit-vectors. - The nodes [t1] and [t2] must have (possibly different) bit-vector sorts - The result is a bit-vector of size {e n1+n2 }, where [n1] ([n2)] is the size - of [t1] ([t2)]. - def_API('mk_concat', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_concat : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_concat" -======= (** Functions to manipulate Array expressions *) module Array : sig @@ -2117,7669 +858,2049 @@ sig finite maps with a default range value. *) val mk_term_array : context -> Expr.expr -> Expr.expr end ->>>>>>> Updates to ML API. -(** - Summary: \[ [ mk_extract c high low t1 ] \] - Extract the bits [high] down to [low] from a bitvector of - size [m] to yield a new bitvector of size [n], where {e n = - high - low + 1 }. - The node [t1] must have a bit-vector sort. - def_API('mk_extract', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in(AST))) -*) -external mk_extract : context -> int -> int -> ast -> ast - = "camlidl_z3_Z3_mk_extract" +(** Functions to manipulate Set expressions *) +module Set : +sig + (** Create a set type. *) + val mk_sort : context -> Sort.sort -> Sort.sort -(** - Summary: \[ [ mk_sign_ext c i t1 ] \] - Sign-extend of the given bit-vector to the (signed) equivalent bitvector of - size {e m+i }, where [m] is the size of the given - bit-vector. - The node [t1] must have a bit-vector sort. - def_API('mk_sign_ext', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_sign_ext : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_sign_ext" + (** Indicates whether the term is set union *) + val is_union : Expr.expr -> bool -(** - Summary: \[ [ mk_zero_ext c i t1 ] \] - Extend the given bit-vector with zeros to the (unsigned) equivalent - bitvector of size {e m+i }, where [m] is the size of the - given bit-vector. - The node [t1] must have a bit-vector sort. - def_API('mk_zero_ext', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_zero_ext : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_zero_ext" + (** Indicates whether the term is set intersection *) + val is_intersect : Expr.expr -> bool -(** - Summary: \[ [ mk_repeat c i t1 ] \] - Repeat the given bit-vector up length {e i }. - The node [t1] must have a bit-vector sort. - def_API('mk_repeat', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_repeat : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_repeat" + (** Indicates whether the term is set difference *) + val is_difference : Expr.expr -> bool -(** - Summary: \[ [ mk_bvshl c t1 t2 ] \] - Shift left. - It is equivalent to multiplication by {e 2^x } where [x] is the value of the - third 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 nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvshl', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvshl : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvshl" + (** Indicates whether the term is set complement *) + val is_complement : Expr.expr -> bool -(** - Summary: \[ [ mk_bvlshr c t1 t2 ] \] - Logical shift right. - It is equivalent to unsigned int division by {e 2^x } where [x] is the - value of the third 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 nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvlshr', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvlshr : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvlshr" + (** Indicates whether the term is set subset *) + val is_subset : Expr.expr -> bool -(** - Summary: \[ [ mk_bvashr c t1 t2 ] \] - 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. - 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 nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvashr', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvashr : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvashr" + (** Create an empty set. *) + val mk_empty : context -> Sort.sort -> Expr.expr -(** - Summary: \[ [ mk_rotate_left c i t1 ] \] - Rotate bits of [t1] to the left [i] times. - The node [t1] must have a bit-vector sort. - def_API('mk_rotate_left', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_rotate_left : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_rotate_left" + (** Create the full set. *) + val mk_full : context -> Sort.sort -> Expr.expr -(** - Summary: \[ [ mk_rotate_right c i t1 ] \] - Rotate bits of [t1] to the right [i] times. - The node [t1] must have a bit-vector sort. - def_API('mk_rotate_right', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_rotate_right : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_rotate_right" + (** Add an element to the set. *) + val mk_set_add : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: \[ [ mk_ext_rotate_left c t1 t2 ] \] - Rotate bits of [t1] to the left [t2] times. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_ext_rotate_left', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_ext_rotate_left : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_ext_rotate_left" + (** Remove an element from a set. *) + val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: \[ [ mk_ext_rotate_right c t1 t2 ] \] - Rotate bits of [t1] to the right [t2] times. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_ext_rotate_right', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_ext_rotate_right : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_ext_rotate_right" + (** Take the union of a list of sets. *) + val mk_union : context -> Expr.expr list -> Expr.expr -(** - Summary: \[ [ mk_int2bv c n t1 ] \] - Create an [n] bit bit-vector from the integer argument [t1]. - 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 node [t1] must have integer sort. - def_API('mk_int2bv', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_int2bv : context -> int -> ast -> ast - = "camlidl_z3_Z3_mk_int2bv" + (** Take the intersection of a list of sets. *) + val mk_intersection : context -> Expr.expr list -> Expr.expr -(** - Summary: \[ [ mk_bv2int c t1 is_signed ] \] - Create an integer from the bit-vector argument [t1]. - If [is_signed] is false, then the bit-vector [t1] is treated as unsigned int. - So the result is non-negative - and in the range {e [0..2^N-1] }, where N are the number of bits in [t1]. - If [is_signed] is true, [t1] is treated as a signed bit-vector. - 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 node [t1] must have a bit-vector sort. - def_API('mk_bv2int', AST, (_in(CONTEXT), _in(AST), _in(BOOL))) -*) -external mk_bv2int : context -> ast -> bool -> ast - = "camlidl_z3_Z3_mk_bv2int" + (** Take the difference between two sets. *) + val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: \[ [ mk_bvadd_no_overflow c t1 t2 is_signed ] \] - Create a predicate that checks that the bit-wise addition - of [t1] and [t2] does not overflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvadd_no_overflow', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(BOOL))) -*) -external mk_bvadd_no_overflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3_Z3_mk_bvadd_no_overflow" + (** Take the complement of a set. *) + val mk_complement : context -> Expr.expr -> Expr.expr -(** - Summary: \[ [ mk_bvadd_no_underflow c t1 t2 ] \] - Create a predicate that checks that the bit-wise signed addition - of [t1] and [t2] does not underflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvadd_no_underflow', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvadd_no_underflow : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvadd_no_underflow" + (** Check for set membership. *) + val mk_membership : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: \[ [ mk_bvsub_no_overflow c t1 t2 ] \] - Create a predicate that checks that the bit-wise signed subtraction - of [t1] and [t2] does not overflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsub_no_overflow', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsub_no_overflow : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsub_no_overflow" + (** Check for subsetness of sets. *) + val mk_subset : context -> Expr.expr -> Expr.expr -> Expr.expr +end -(** - Summary: \[ [ mk_bvsub_no_underflow c t1 t2 is_signed ] \] - Create a predicate that checks that the bit-wise subtraction - of [t1] and [t2] does not underflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsub_no_underflow', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(BOOL))) -*) -external mk_bvsub_no_underflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3_Z3_mk_bvsub_no_underflow" +(** Functions to manipulate Finite Domain expressions *) +module FiniteDomain : +sig + (** Create a new finite domain sort. *) + val mk_sort : context -> Symbol.symbol -> int -> Sort.sort -(** - Summary: \[ [ mk_bvsdiv_no_overflow c t1 t2 ] \] - Create a predicate that checks that the bit-wise signed division - of [t1] and [t2] does not overflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsdiv_no_overflow', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsdiv_no_overflow : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvsdiv_no_overflow" + (** Create a new finite domain sort. *) + val mk_sort_s : context -> string -> int -> Sort.sort -(** - Summary: \[ [ mk_bvneg_no_overflow c t1 ] \] - Check that bit-wise negation does not overflow when - [t1] is interpreted as a signed bit-vector. - The node [t1] must have bit-vector sort. - def_API('mk_bvneg_no_overflow', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvneg_no_overflow : context -> ast -> ast - = "camlidl_z3_Z3_mk_bvneg_no_overflow" + (** Indicates whether the term is of an array sort. *) + val is_finite_domain : Expr.expr -> bool -(** - Summary: \[ [ mk_bvmul_no_overflow c t1 t2 is_signed ] \] - Create a predicate that checks that the bit-wise multiplication - of [t1] and [t2] does not overflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvmul_no_overflow', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(BOOL))) -*) -external mk_bvmul_no_overflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3_Z3_mk_bvmul_no_overflow" + (** Indicates whether the term is a less than predicate over a finite domain. *) + val is_lt : Expr.expr -> bool -(** - Summary: \[ [ mk_bvmul_no_underflow c t1 t2 ] \] - Create a predicate that checks that the bit-wise signed multiplication - of [t1] and [t2] does not underflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvmul_no_underflow', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvmul_no_underflow : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_bvmul_no_underflow" + (** The size of the finite domain sort. *) + val get_size : Sort.sort -> int +end -(** - {2 {L Arrays}} -*) -(** - Summary: \[ [ mk_select c a i ] \] - 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 {e [domain -> range] }, - and [i] must have the sort [domain]. - The sort of the result is [range]. - - {b See also}: {!mk_array_sort} - - {b See also}: {!mk_store} - def_API('mk_select', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_select : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_select" -(** - Summary: \[ [ mk_store c a i v ] \] - Array update. - The node [a] must have an array sort {e [domain -> range] }, [i] must have sort [domain], - [v] must have sort range. The sort of the result is {e [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). - - {b See also}: {!mk_array_sort} - - {b See also}: {!mk_select} - def_API('mk_store', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(AST))) -*) -external mk_store : context -> ast -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_store" +(** Functions to manipulate Relation expressions *) +module Relation : +sig + (** Indicates whether the term is of a relation sort. *) + val is_relation : Expr.expr -> bool -(** - Summary: Create the constant array. - The resulting term is an array, such that a [select] on an arbitrary index - produces the value [v]. - @param c logical context. - @param domain domain sort for the array. - @param v value that the array maps to. - def_API('mk_const_array', AST, (_in(CONTEXT), _in(SORT), _in(AST))) -*) -external mk_const_array : context -> sort -> ast -> ast - = "camlidl_z3_Z3_mk_const_array" + (** 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. *) + val is_store : Expr.expr -> bool -(** - Summary: \[ [ mk_map f n args ] \] - map f on the the argument arrays. - The [n] nodes [args] must be of array sorts {e [domain_i -> range_i] }. - The function declaration [f] must have type {e range_1 .. range_n -> range }. - [v] must have sort range. The sort of the result is {e [domain_i -> range] }. - - {b See also}: {!mk_array_sort} - - {b See also}: {!mk_store} - - {b See also}: {!mk_select} - def_API('mk_map', AST, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT), _in_array(2, AST))) -*) -external mk_map : context -> func_decl -> int -> ast -> ast - = "camlidl_z3_Z3_mk_map" + (** Indicates whether the term is an empty relation *) + val is_empty : Expr.expr -> bool -(** - Summary: Access the array default value. - Produces the default range value, for arrays that can be represented as - finite maps with a default range value. - @param c logical context. - @param array array value whose default range value is accessed. - def_API('mk_array_default', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_array_default : context -> ast -> ast - = "camlidl_z3_Z3_mk_array_default" + (** Indicates whether the term is a test for the emptiness of a relation *) + val is_is_empty : Expr.expr -> bool -(** - {2 {L Sets}} -*) -(** - Summary: Create Set type. - def_API('mk_set_sort', SORT, (_in(CONTEXT), _in(SORT))) -*) -external mk_set_sort : context -> sort -> sort - = "camlidl_z3_Z3_mk_set_sort" + (** Indicates whether the term is a relational join *) + val is_join : Expr.expr -> bool -(** - Summary: Create the empty set. - def_API('mk_empty_set', AST, (_in(CONTEXT), _in(SORT))) -*) -external mk_empty_set : context -> sort -> ast - = "camlidl_z3_Z3_mk_empty_set" + (** Indicates whether the term is the union or convex hull of two relations. + The function takes two arguments. *) + val is_union : Expr.expr -> bool + + (** Indicates whether the term is the widening of two relations + The function takes two arguments. *) + val is_widen : Expr.expr -> bool + + (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). + The function takes one argument. *) + val is_project : Expr.expr -> bool + + (** 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. *) + val is_filter : Expr.expr -> bool + + (** 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. *) + val is_negation_filter : Expr.expr -> bool + + (** 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. *) + val is_rename : Expr.expr -> bool + + (** Indicates whether the term is the complement of a relation *) + val is_complement : Expr.expr -> bool + + (** 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. *) + val is_select : Expr.expr -> bool + + (** 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 {!is_union} + to perform destructive updates to the first argument. *) + val is_clone : Expr.expr -> bool + + (** The arity of the relation sort. *) + val get_arity : Sort.sort -> int + + (** The sorts of the columns of the relation sort. *) + val get_column_sorts : Sort.sort -> Sort.sort list +end + +(** Functions to manipulate Datatype expressions *) +module Datatype : +sig + (** Datatype Constructors *) + module Constructor : + sig + type constructor + + (** The number of fields of the constructor. *) + val get_num_fields : constructor -> int + + (** The function declaration of the constructor. *) + val get_constructor_decl : constructor -> FuncDecl.func_decl + + (** The function declaration of the tester. *) + val get_tester_decl : constructor -> FuncDecl.func_decl + + (** The function declarations of the accessors *) + val get_accessor_decls : constructor -> FuncDecl.func_decl list + end + + (** Create a datatype 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. *) + val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + + (** Create a datatype 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. *) + val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + + (** Create a new datatype sort. *) + val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> Sort.sort + + (** Create a new datatype sort. *) + val mk_sort_s : context -> string -> Constructor.constructor list -> Sort.sort + + (** Create mutually recursive datatypes. *) + val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> Sort.sort list + + (** Create mutually recursive data-types. *) + val mk_sorts_s : context -> string list -> Constructor.constructor list list -> Sort.sort list + + + (** The number of constructors of the datatype sort. *) + val get_num_constructors : Sort.sort -> int + + (** The constructors. *) + val get_constructors : Sort.sort -> FuncDecl.func_decl list + + (** The recognizers. *) + val get_recognizers : Sort.sort -> FuncDecl.func_decl list + + (** The constructor accessors. *) + val get_accessors : Sort.sort -> FuncDecl.func_decl list list +end + +(** Functions to manipulate Enumeration expressions *) +module Enumeration : +sig + (** Create a new enumeration sort. *) + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort + + (** Create a new enumeration sort. *) + val mk_sort_s : context -> string -> string list -> Sort.sort + + (** The function declarations of the constants in the enumeration. *) + val get_const_decls : Sort.sort -> FuncDecl.func_decl list + + (** The test predicates for the constants in the enumeration. *) + val get_tester_decls : Sort.sort -> FuncDecl.func_decl list +end -<<<<<<< HEAD -(** - Summary: Create the full set. - def_API('mk_full_set', AST, (_in(CONTEXT), _in(SORT))) -*) -external mk_full_set : context -> sort -> ast - = "camlidl_z3_Z3_mk_full_set" -======= (** Functions to manipulate List expressions *) module List : sig (** Create a new list sort. *) val mk_sort : context -> Symbol.symbol -> Sort.sort -> Sort.sort ->>>>>>> Updates to ML API. -(** - Summary: Add an element to a set. - The first argument must be a set, the second an element. - def_API('mk_set_add', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_add : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_add" + (** Create a new list sort. *) + val mk_list_s : context -> string -> Sort.sort -> Sort.sort -(** - Summary: Remove an element to a set. - The first argument must be a set, the second an element. - def_API('mk_set_del', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_del : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_del" + (** The declaration of the nil function of this list sort. *) + val get_nil_decl : Sort.sort -> FuncDecl.func_decl -(** - Summary: Take the union of a list of sets. - def_API('mk_set_union', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_set_union : context -> ast array -> ast - = "camlidl_z3_Z3_mk_set_union" + (** The declaration of the isNil function of this list sort. *) + val get_is_nil_decl : Sort.sort -> FuncDecl.func_decl -(** - Summary: Take the intersection of a list of sets. - def_API('mk_set_intersect', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_set_intersect : context -> ast array -> ast - = "camlidl_z3_Z3_mk_set_intersect" + (** The declaration of the cons function of this list sort. *) + val get_cons_decl : Sort.sort -> FuncDecl.func_decl -(** - Summary: Take the set difference between two sets. - def_API('mk_set_difference', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_difference : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_difference" + (** The declaration of the isCons function of this list sort. *) + val get_is_cons_decl : Sort.sort -> FuncDecl.func_decl -(** - Summary: Take the complement of a set. - def_API('mk_set_complement', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_set_complement : context -> ast -> ast - = "camlidl_z3_Z3_mk_set_complement" + (** The declaration of the head function of this list sort. *) + val get_head_decl : Sort.sort -> FuncDecl.func_decl -(** - Summary: Check for set membership. - The first argument should be an element type of the set. - def_API('mk_set_member', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_member : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_member" + (** The declaration of the tail function of this list sort. *) + val get_tail_decl : Sort.sort -> FuncDecl.func_decl -(** - Summary: Check for subsetness of sets. - def_API('mk_set_subset', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_subset : context -> ast -> ast -> ast - = "camlidl_z3_Z3_mk_set_subset" + (** The empty list. *) + val nil : Sort.sort -> Expr.expr +end -(** - {2 {L Numerals}} -*) +(** Functions to manipulate Tuple expressions *) +module Tuple : +sig + (** Create a new tuple sort. *) + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> Sort.sort -(** - Summary: \[ [ numeral_refined ] \] is the refined view of a numeral . -*) -type numeral_refined = - | Numeral_int of int * sort - | Numeral_int64 of int64 * sort - | Numeral_large of string * sort - | Numeral_rational of numeral_refined * numeral_refined + (** The constructor function of the tuple. *) + val get_mk_decl : Sort.sort -> FuncDecl.func_decl + (** The number of fields in the tuple. *) + val get_num_fields : Sort.sort -> int -(** - Summary: \[ [ embed_numeral c nr ] \] constructs the numeral described by [nr]. - - {b See also}: {!numeral_refine} -*) -val embed_numeral: context -> numeral_refined -> ast + (** The field declarations. *) + val get_field_decls : Sort.sort -> FuncDecl.func_decl list +end -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Create a numeral of a given sort. - @param c logical context. - @param numeral A string representing the numeral value in decimal notation. If the given sort is a real, then the numeral can be a rational, that is, a string of the form {e [num]* / [num]* }. - @param ty The sort of the numeral. In the current implementation, the given sort can be an int, real, finite-domain, or bit-vectors of arbitrary size. - - {b See also}: {!mk_int} - def_API('mk_numeral', AST, (_in(CONTEXT), _in(STRING), _in(SORT))) -*) -external mk_numeral : context -> string -> sort -> ast - = "camlidl_z3_Z3_mk_numeral" +(** Functions to manipulate arithmetic expressions *) +module Arithmetic : +sig + (** Integer Arithmetic *) + module Integer : + sig + (** Create a new integer sort. *) + val mk_sort : context -> Sort.sort -(** - Summary: Create a real from a fraction. - @param c logical context. - @param num numerator of rational. - @param den denomerator of rational. - - {b Precondition}: den != 0 - - {b See also}: {!mk_numeral} - - {b See also}: {!mk_int} - def_API('mk_real', AST, (_in(CONTEXT), _in(INT), _in(INT))) -*) -external mk_real : context -> int -> int -> ast - = "camlidl_z3_Z3_mk_real" + (** Retrieve the int value. *) + val get_int : Expr.expr -> int -(** - Summary: Create a numeral of an int, bit-vector, or finite-domain sort. - This function can be use to create numerals that fit in a machine integer. - It is slightly faster than {!mk_numeral} since it is not necessary to parse a string. - - {b See also}: {!mk_numeral} - def_API('mk_int', AST, (_in(CONTEXT), _in(INT), _in(SORT))) -*) -external mk_int : context -> int -> sort -> ast - = "camlidl_z3_Z3_mk_int" + (** Returns a string representation of the numeral. *) + val to_string : Expr.expr -> string -(** - Summary: Create a numeral of a int, bit-vector, or finite-domain sort. - This function can be use to create numerals that fit in a machine long long integer. - It is slightly faster than {!mk_numeral} since it is not necessary to parse a string. - - {b See also}: {!mk_numeral} - def_API('mk_int64', AST, (_in(CONTEXT), _in(INT64), _in(SORT))) -*) -external mk_int64 : context -> int64 -> sort -> ast - = "camlidl_z3_Z3_mk_int64" + (** Creates an integer constant. *) + val mk_const : context -> Symbol.symbol -> Expr.expr -(** - {2 {L Quantifiers}} -*) -(** - Summary: Create a pattern for quantifier instantiation. - Z3 uses pattern matching to instantiate quantifiers. If a - pattern is not provided for a quantifier, then Z3 will - automatically compute a set of patterns for it. However, for - optimal performance, the user should provide the patterns. - Patterns comprise a list of terms. The list should be - non-empty. If the list comprises of more than one term, it is - a called a multi-pattern. - In general, one can pass in a list of (multi-)patterns in the - quantifier constructor. - - {b See also}: {!mk_forall} - - {b See also}: {!mk_exists} - def_API('mk_pattern', PATTERN, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_pattern : context -> ast array -> pattern - = "camlidl_z3_Z3_mk_pattern" + (** Creates an integer constant. *) + val mk_const_s : context -> string -> Expr.expr -(** - Summary: Create 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. - {v - 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)) - v} - 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. - @param c logical context - @param index de-Bruijn index - @param ty sort of the bound variable - - {b See also}: {!mk_forall} - - {b See also}: {!mk_exists} - def_API('mk_bound', AST, (_in(CONTEXT), _in(UINT), _in(SORT))) -*) -external mk_bound : context -> int -> sort -> ast - = "camlidl_z3_Z3_mk_bound" + (** Create an expression representing t1 mod t2. + The arguments must have int type. *) + val mk_mod : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: Create a forall formula. It takes an expression [body] that contains bound variables - of the same sorts as the sorts listed in the array [sorts]. The bound variables are de-Bruijn indices created - using {!mk_bound}. The array [decl_names] contains the names that the quantified formula uses for the - bound variables. Z3 applies the convention that the last element in the [decl_names] and [sorts] array - refers to the variable with index 0, the second to last element of [decl_names] and [sorts] refers - to the variable with index 1, etc. - [mk_forall c w p t n b] creates a forall formula, where - [w] is the weight, [p] is an array of patterns, [t] is an array - with the sorts of the bound variables, [n] is an array with the - 'names' of the bound variables, and [b] is the body of the - quantifier. Quantifiers are associated with weights indicating - the importance of using the quantifier during - instantiation. - @param c logical context. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param num_decls number of variables to be bound. - @param sorts the sorts of the bound variables. - @param decl_names names of the bound variables - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_bound} - - {b See also}: {!mk_exists} - def_API('mk_forall', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in_array(2, PATTERN), _in(UINT), _in_array(4, SORT), _in_array(4, SYMBOL), _in(AST))) -*) -external mk_forall : context -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3_Z3_mk_forall_bytecode" "camlidl_z3_Z3_mk_forall" + (** Create an expression representing t1 rem t2. + The arguments must have int type. *) + val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: Create an exists formula. Similar to {!mk_forall}. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_bound} - - {b See also}: {!mk_forall} - - {b See also}: {!mk_quantifier} - def_API('mk_exists', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in_array(2, PATTERN), _in(UINT), _in_array(4, SORT), _in_array(4, SYMBOL), _in(AST))) -*) -external mk_exists : context -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3_Z3_mk_exists_bytecode" "camlidl_z3_Z3_mk_exists" + (** Create an integer numeral. *) + val mk_numeral_s : context -> string -> Expr.expr -(** - Summary: Create a quantifier - universal or existential, with pattern hints. - See the documentation for {!mk_forall} for an explanation of the parameters. - @param c logical context. - @param is_forall flag to indicate if this is a universal or existential quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param num_decls number of variables to be bound. - @param sorts array of sorts of the bound variables. - @param decl_names names of the bound variables. - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_bound} - - {b See also}: {!mk_forall} - - {b See also}: {!mk_exists} - def_API('mk_quantifier', AST, (_in(CONTEXT), _in(BOOL), _in(UINT), _in(UINT), _in_array(3, PATTERN), _in(UINT), _in_array(5, SORT), _in_array(5, SYMBOL), _in(AST))) -*) -external mk_quantifier : context -> bool -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3_Z3_mk_quantifier_bytecode" "camlidl_z3_Z3_mk_quantifier" + (** Create an integer numeral. + @return A Term with the given value and sort Integer *) + val mk_numeral_i : context -> int -> Expr.expr -(** - Summary: Create a quantifier - universal or existential, with pattern hints, no patterns, and attributes - @param c logical context. - @param is_forall flag to indicate if this is a universal or existential quantifier. - @param quantifier_id identifier to identify quantifier - @param skolem_id identifier to identify skolem constants introduced by quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param num_no_patterns number of no_patterns. - @param no_patterns array containing subexpressions to be excluded from inferred patterns. - @param num_decls number of variables to be bound. - @param sorts array of sorts of the bound variables. - @param decl_names names of the bound variables. - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_bound} - - {b See also}: {!mk_forall} - - {b See also}: {!mk_exists} - def_API('mk_quantifier_ex', AST, (_in(CONTEXT), _in(BOOL), _in(UINT), _in(SYMBOL), _in(SYMBOL), _in(UINT), _in_array(5, PATTERN), _in(UINT), _in_array(7, AST), _in(UINT), _in_array(9, SORT), _in_array(9, SYMBOL), _in(AST))) -*) -external mk_quantifier_ex : context -> bool -> int -> symbol -> symbol -> pattern array -> ast array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3_Z3_mk_quantifier_ex_bytecode" "camlidl_z3_Z3_mk_quantifier_ex" + (** 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. *) + val mk_int2real : context -> Expr.expr -> Expr.expr -(** - Summary: Create a universal quantifier using a list of constants that - will form the set of bound variables. - @param c logical context. - @param weight quantifiers are associated with weights indicating the importance of using - the quantifier during instantiation. By default, pass the weight 0. - @param num_bound number of constants to be abstracted into bound variables. - @param bound array of constants to be abstracted into bound variables. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_exists_const} - def_API('mk_forall_const', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in_array(2, APP), _in(UINT), _in_array(4, PATTERN), _in(AST))) -*) -external mk_forall_const : context -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3_Z3_mk_forall_const" - -(** - Summary: Similar to {!mk_forall_const}. - Summary: Create an existential quantifier using a list of constants that - will form the set of bound variables. - @param c logical context. - @param weight quantifiers are associated with weights indicating the importance of using - the quantifier during instantiation. By default, pass the weight 0. - @param num_bound number of constants to be abstracted into bound variables. - @param bound array of constants to be abstracted into bound variables. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_forall_const} - def_API('mk_exists_const', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in_array(2, APP), _in(UINT), _in_array(4, PATTERN), _in(AST))) -*) -external mk_exists_const : context -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3_Z3_mk_exists_const" - -(** - Summary: Create a universal or existential - quantifier using a list of constants that - will form the set of bound variables. - def_API('mk_quantifier_const', AST, (_in(CONTEXT), _in(BOOL), _in(UINT), _in(UINT), _in_array(3, APP), _in(UINT), _in_array(5, PATTERN), _in(AST))) -*) -external mk_quantifier_const : context -> bool -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3_Z3_mk_quantifier_const_bytecode" "camlidl_z3_Z3_mk_quantifier_const" - -(** - Summary: Create a universal or existential - quantifier using a list of constants that - will form the set of bound variables. - def_API('mk_quantifier_const_ex', AST, (_in(CONTEXT), _in(BOOL), _in(UINT), _in(SYMBOL), _in(SYMBOL), _in(UINT), _in_array(5, APP), _in(UINT), _in_array(7, PATTERN), _in(UINT), _in_array(9, AST), _in(AST))) -*) -external mk_quantifier_const_ex : context -> bool -> int -> symbol -> symbol -> app array -> pattern array -> ast array -> ast -> ast - = "camlidl_z3_Z3_mk_quantifier_const_ex_bytecode" "camlidl_z3_Z3_mk_quantifier_const_ex" - -(** - {2 {L Accessors}} -*) -(** - {3 {L Symbols}} -*) - -(** - Summary: \[ [ symbol_refine c s ] \] is the refined view of [s]. -*) -val symbol_refine: context -> symbol -> symbol_refined - -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Return [INT_SYMBOL] if the symbol was constructed - using {!mk_int_symbol}, and [STRING_SYMBOL] if the symbol - was constructed using {!mk_string_symbol}. - def_API('get_symbol_kind', UINT, (_in(CONTEXT), _in(SYMBOL))) -*) -external get_symbol_kind : context -> symbol -> symbol_kind - = "camlidl_z3_Z3_get_symbol_kind" - -(** - Summary: \[ [ get_symbol_int c s ] \] - Return the symbol int value. - - {b Precondition}: get_symbol_kind s == INT_SYMBOL - - {b See also}: {!mk_int_symbol} - def_API('get_symbol_int', INT, (_in(CONTEXT), _in(SYMBOL))) -*) -external get_symbol_int : context -> symbol -> int - = "camlidl_z3_Z3_get_symbol_int" - -(** - Summary: \[ [ get_symbol_string c s ] \] - Return the symbol name. - - {b Precondition}: get_symbol_string s == STRING_SYMBOL - - {b See also}: {!mk_string_symbol} - def_API('get_symbol_string', STRING, (_in(CONTEXT), _in(SYMBOL))) -*) -external get_symbol_string : context -> symbol -> string - = "camlidl_z3_Z3_get_symbol_string" - -(** - {3 {L Sorts}} -*) - -(** - Summary: \[ [ sort_refine c s ] \] is the refined view of [s]. -*) -val sort_refine: context -> sort -> sort_refined - -(** - Summary: Return the sort name as a symbol. - def_API('get_sort_name', SYMBOL, (_in(CONTEXT), _in(SORT))) -*) -external get_sort_name : context -> sort -> symbol - = "camlidl_z3_Z3_get_sort_name" - -(** - Summary: Return a unique identifier for [s]. - - {b Remarks}: Implicitly used by [Pervasives.( = )] and [Pervasives.compare]. - def_API('get_sort_id', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_sort_id : context -> sort -> int - = "camlidl_z3_Z3_get_sort_id" - -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Convert a [sort] into [ast]. - - {b Remarks}: [sort_to_ast c s] can be replaced by [(s :> ast)]. - def_API('sort_to_ast', AST, (_in(CONTEXT), _in(SORT))) -*) -external sort_to_ast : context -> sort -> ast - = "camlidl_z3_Z3_sort_to_ast" - -(** - Summary: compare sorts. - - {b Remarks}: [Pervasives.( = )] or [Pervasives.compare] can also be used. - def_API('is_eq_sort', BOOL, (_in(CONTEXT), _in(SORT), _in(SORT))) -*) -external is_eq_sort : context -> sort -> sort -> bool - = "camlidl_z3_Z3_is_eq_sort" - -(** - Summary: Return the sort kind (e.g., array, tuple, int, bool, etc). - - {b See also}: {!sort_kind} - def_API('get_sort_kind', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_sort_kind : context -> sort -> sort_kind - = "camlidl_z3_Z3_get_sort_kind" - -(** - Summary: \[ [ get_bv_sort_size c t ] \] - Return the size of the given bit-vector sort. - - {b Precondition}: get_sort_kind c t == BV_SORT - - {b See also}: {!mk_bv_sort} - - {b See also}: {!get_sort_kind} - def_API('get_bv_sort_size', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_bv_sort_size : context -> sort -> int - = "camlidl_z3_Z3_get_bv_sort_size" - -(** - Summary: Return the size of the sort in [r]. Return [None] if the call failed. - That is, get_sort_kind(s) == FINITE_DOMAIN_SORT - def_API('get_finite_domain_sort_size', BOOL, (_in(CONTEXT), _in(SORT), _out(UINT64))) -*) -external get_finite_domain_sort_size : context -> sort -> int64 option - = "camlidl_z3_Z3_get_finite_domain_sort_size" - -(** - Summary: \[ [ get_array_sort_domain c t ] \] - Return the domain of the given array sort. - - {b Precondition}: get_sort_kind c t == ARRAY_SORT - - {b See also}: {!mk_array_sort} - - {b See also}: {!get_sort_kind} - def_API('get_array_sort_domain', SORT, (_in(CONTEXT), _in(SORT))) -*) -external get_array_sort_domain : context -> sort -> sort - = "camlidl_z3_Z3_get_array_sort_domain" - -(** - Summary: \[ [ get_array_sort_range c t ] \] - Return the range of the given array sort. - - {b Precondition}: get_sort_kind c t == ARRAY_SORT - - {b See also}: {!mk_array_sort} - - {b See also}: {!get_sort_kind} - def_API('get_array_sort_range', SORT, (_in(CONTEXT), _in(SORT))) -*) -external get_array_sort_range : context -> sort -> sort - = "camlidl_z3_Z3_get_array_sort_range" - -(** - Summary: \[ [ get_tuple_sort_mk_decl c t ] \] - Return the constructor declaration of the given tuple - sort. - - {b Precondition}: get_sort_kind c t == DATATYPE_SORT - - {b See also}: {!mk_tuple_sort} - - {b See also}: {!get_sort_kind} - def_API('get_tuple_sort_mk_decl', FUNC_DECL, (_in(CONTEXT), _in(SORT))) -*) -external get_tuple_sort_mk_decl : context -> sort -> func_decl - = "camlidl_z3_Z3_get_tuple_sort_mk_decl" - -(** - Summary: \[ [ get_tuple_sort_num_fields c t ] \] - Return the number of fields of the given tuple sort. - - {b Precondition}: get_sort_kind c t == DATATYPE_SORT - - {b See also}: {!mk_tuple_sort} - - {b See also}: {!get_sort_kind} - def_API('get_tuple_sort_num_fields', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_tuple_sort_num_fields : context -> sort -> int - = "camlidl_z3_Z3_get_tuple_sort_num_fields" - -(** - Summary: \[ [ get_tuple_sort_field_decl c t i ] \] - Return the i-th field declaration (i.e., projection function declaration) - of the given tuple sort. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b Precondition}: i < get_tuple_sort_num_fields c t - - {b See also}: {!mk_tuple_sort} - - {b See also}: {!get_sort_kind} - def_API('get_tuple_sort_field_decl', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT))) -*) -external get_tuple_sort_field_decl : context -> sort -> int -> func_decl - = "camlidl_z3_Z3_get_tuple_sort_field_decl" - -(** - Summary: Return number of constructors for datatype. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b See also}: {!get_datatype_sort_constructor} - - {b See also}: {!get_datatype_sort_recognizer} - - {b See also}: {!get_datatype_sort_constructor_accessor} - def_API('get_datatype_sort_num_constructors', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_datatype_sort_num_constructors : context -> sort -> int - = "camlidl_z3_Z3_get_datatype_sort_num_constructors" - -(** - Summary: Return idx'th constructor. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b Precondition}: idx < get_datatype_sort_num_constructors c t - - {b See also}: {!get_datatype_sort_num_constructors} - - {b See also}: {!get_datatype_sort_recognizer} - - {b See also}: {!get_datatype_sort_constructor_accessor} - def_API('get_datatype_sort_constructor', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT))) -*) -external get_datatype_sort_constructor : context -> sort -> int -> func_decl - = "camlidl_z3_Z3_get_datatype_sort_constructor" - -(** - Summary: Return idx'th recognizer. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b Precondition}: idx < get_datatype_sort_num_constructors c t - - {b See also}: {!get_datatype_sort_num_constructors} - - {b See also}: {!get_datatype_sort_constructor} - - {b See also}: {!get_datatype_sort_constructor_accessor} - def_API('get_datatype_sort_recognizer', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT))) -*) -external get_datatype_sort_recognizer : context -> sort -> int -> func_decl - = "camlidl_z3_Z3_get_datatype_sort_recognizer" - -(** - Summary: Return idx_a'th accessor for the idx_c'th constructor. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b Precondition}: idx_c < get_datatype_sort_num_constructors c t - - {b Precondition}: idx_a < get_domain_size c get_datatype_sort_constructor c idx_c - - {b See also}: {!get_datatype_sort_num_constructors} - - {b See also}: {!get_datatype_sort_constructor} - - {b See also}: {!get_datatype_sort_recognizer} - def_API('get_datatype_sort_constructor_accessor', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT), _in(UINT))) -*) -external get_datatype_sort_constructor_accessor : context -> sort -> int -> int -> func_decl - = "camlidl_z3_Z3_get_datatype_sort_constructor_accessor" - -(** - Summary: Return arity of relation. - - {b Precondition}: get_sort_kind s == RELATION_SORT - - {b See also}: {!get_relation_column} - def_API('get_relation_arity', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_relation_arity : context -> sort -> int - = "camlidl_z3_Z3_get_relation_arity" - -(** - Summary: Return sort at i'th column of relation sort. - - {b Precondition}: get_sort_kind c s == RELATION_SORT - - {b Precondition}: col < get_relation_arity c s - - {b See also}: {!get_relation_arity} - def_API('get_relation_column', SORT, (_in(CONTEXT), _in(SORT), _in(UINT))) -*) -external get_relation_column : context -> sort -> int -> sort - = "camlidl_z3_Z3_get_relation_column" - -(** - {3 {L Function Declarations}} -*) -(** - Summary: Convert a [func_decl] into [ast]. - - {b Remarks}: [func_decl_to_ast c f] can be replaced by [(f :> ast)]. - def_API('func_decl_to_ast', AST, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external func_decl_to_ast : context -> func_decl -> ast - = "camlidl_z3_Z3_func_decl_to_ast" - -(** - Summary: compare terms. - - {b Remarks}: [Pervasives.( = )] or [Pervasives.compare] can also be used. - def_API('is_eq_func_decl', BOOL, (_in(CONTEXT), _in(FUNC_DECL), _in(FUNC_DECL))) -*) -external is_eq_func_decl : context -> func_decl -> func_decl -> bool - = "camlidl_z3_Z3_is_eq_func_decl" - -(** - Summary: Return a unique identifier for [f]. - - {b Remarks}: Implicitly used by [Pervasives.( = )] and [Pervasives.compare]. - def_API('get_func_decl_id', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_func_decl_id : context -> func_decl -> int - = "camlidl_z3_Z3_get_func_decl_id" - -(** - Summary: Return the constant declaration name as a symbol. - def_API('get_decl_name', SYMBOL, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_decl_name : context -> func_decl -> symbol - = "camlidl_z3_Z3_get_decl_name" - -(** - Summary: Return declaration kind corresponding to declaration. - def_API('get_decl_kind', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_decl_kind : context -> func_decl -> decl_kind - = "camlidl_z3_Z3_get_decl_kind" - -(** - Summary: Return the number of parameters of the given declaration. - - {b See also}: {!get_arity} - def_API('get_domain_size', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_domain_size : context -> func_decl -> int - = "camlidl_z3_Z3_get_domain_size" - -(** - Summary: Alias for [get_domain_size]. - - {b See also}: {!get_domain_size} - def_API('get_arity', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_arity : context -> func_decl -> int - = "camlidl_z3_Z3_get_arity" - -(** - Summary: \[ [ get_domain c d i ] \] - Return the sort of the i-th parameter of the given function declaration. - - {b Precondition}: i < get_domain_size d - - {b See also}: {!get_domain_size} - def_API('get_domain', SORT, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_domain : context -> func_decl -> int -> sort - = "camlidl_z3_Z3_get_domain" - - -(** - Summary: \[ [ get_domains c d ] \] is the array of parameters of [d]. - - {b See also}: {!get_domain_size} - - {b See also}: {!get_domain} -*) -val get_domains: context -> func_decl -> sort array - -(** - Summary: \[ [ get_range c d ] \] - Return the range of the given declaration. - If [d] is a constant (i.e., has zero arguments), then this - function returns the sort of the constant. - def_API('get_range', SORT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_range : context -> func_decl -> sort - = "camlidl_z3_Z3_get_range" - -(** - Summary: Return the number of parameters associated with a declaration. - def_API('get_decl_num_parameters', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_decl_num_parameters : context -> func_decl -> int - = "camlidl_z3_Z3_get_decl_num_parameters" - -(** - Summary: Return the parameter type associated with a declaration. - @param c the context - @param d the function declaration - @param idx is the index of the named parameter it should be between 0 and the number of parameters. - def_API('get_decl_parameter_kind', UINT, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_parameter_kind : context -> func_decl -> int -> parameter_kind - = "camlidl_z3_Z3_get_decl_parameter_kind" - -(** - Summary: Return the integer value associated with an integer parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_INT - def_API('get_decl_int_parameter', INT, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_int_parameter : context -> func_decl -> int -> int - = "camlidl_z3_Z3_get_decl_int_parameter" - -(** - Summary: Return the double value associated with an double parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_DOUBLE - def_API('get_decl_double_parameter', DOUBLE, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_double_parameter : context -> func_decl -> int -> float - = "camlidl_z3_Z3_get_decl_double_parameter" - -(** - Summary: Return the double value associated with an double parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_SYMBOL - def_API('get_decl_symbol_parameter', SYMBOL, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_symbol_parameter : context -> func_decl -> int -> symbol - = "camlidl_z3_Z3_get_decl_symbol_parameter" - -(** - Summary: Return the sort value associated with a sort parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_SORT - def_API('get_decl_sort_parameter', SORT, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_sort_parameter : context -> func_decl -> int -> sort - = "camlidl_z3_Z3_get_decl_sort_parameter" - -(** - Summary: Return the expresson value associated with an expression parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_AST - def_API('get_decl_ast_parameter', AST, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_ast_parameter : context -> func_decl -> int -> ast - = "camlidl_z3_Z3_get_decl_ast_parameter" - -(** - Summary: Return the expresson value associated with an expression parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_FUNC_DECL - def_API('get_decl_func_decl_parameter', FUNC_DECL, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_func_decl_parameter : context -> func_decl -> int -> func_decl - = "camlidl_z3_Z3_get_decl_func_decl_parameter" - -(** - Summary: Return the rational value, as a string, associated with a rational parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_RATIONAL - def_API('get_decl_rational_parameter', STRING, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_rational_parameter : context -> func_decl -> int -> string - = "camlidl_z3_Z3_get_decl_rational_parameter" - -(** - {3 {L Applications}} -*) -(** - Summary: Convert a [app] into [ast]. - - {b Remarks}: [app_to_ast c a] can be replaced by [(a :> ast)]. - def_API('app_to_ast', AST, (_in(CONTEXT), _in(APP))) -*) -external app_to_ast : context -> app -> ast - = "camlidl_z3_Z3_app_to_ast" - -(** - Summary: Return the declaration of a constant or function application. - def_API('get_app_decl', FUNC_DECL, (_in(CONTEXT), _in(APP))) -*) -external get_app_decl : context -> app -> func_decl - = "camlidl_z3_Z3_get_app_decl" - -(** - Summary: \[ [ get_app_num_args c a ] \] - Return the number of argument of an application. If [t] - is an constant, then the number of arguments is 0. - def_API('get_app_num_args', UINT, (_in(CONTEXT), _in(APP))) -*) -external get_app_num_args : context -> app -> int - = "camlidl_z3_Z3_get_app_num_args" - -(** - Summary: \[ [ get_app_arg c a i ] \] - Return the i-th argument of the given application. - - {b Precondition}: i < get_num_args c a - def_API('get_app_arg', AST, (_in(CONTEXT), _in(APP), _in(UINT))) -*) -external get_app_arg : context -> app -> int -> ast - = "camlidl_z3_Z3_get_app_arg" - - -(** - Summary: \[ [ get_app_args c a ] \] is the array of arguments of an application. If [t] is a constant, then the array is empty. - - {b See also}: {!get_app_num_args} - - {b See also}: {!get_app_arg} -*) -val get_app_args: context -> app -> ast array - -(** - {3 {L Terms}} -*) - -(** - Summary: \[ [ binder_type ] \] is a universal or existential quantifier. - - {b See also}: {!term_refined} -*) -type binder_type = Forall | Exists -(** - Summary: \[ [ term_refined ] \] is the refinement of a {!ast} . - - {b See also}: {!term_refine} -*) -type term_refined = - | Term_numeral of numeral_refined - | Term_app of decl_kind * func_decl * ast array - | Term_quantifier of binder_type * int * ast array array * (symbol * sort) array * ast - | Term_var of int * sort - - -(** - Summary: \[ [ mk_term c tr ] \] constructs the term described by [tr]. - - {b Precondition}: [tr] is not of form - - {b See also}: {!term_refine} -*) -(* val mk_term: context -> term_refined -> ast *) -(** - Summary: \[ [ term_refine c a ] \] is the refined view of [a]. -*) -val term_refine : context -> ast -> term_refined - -(** - Summary: compare terms. - - {b Remarks}: [Pervasives.( = )] or [Pervasives.compare] can also be used. - def_API('is_eq_ast', BOOL, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external is_eq_ast : context -> ast -> ast -> bool - = "camlidl_z3_Z3_is_eq_ast" - -(** - Summary: Return a unique identifier for [t]. - - {b Remarks}: Implicitly used by [Pervasives.compare] for values of type [ast], [app], [sort], [func_decl], and [pattern]. - def_API('get_ast_id', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_ast_id : context -> ast -> int - = "camlidl_z3_Z3_get_ast_id" - -(** - Summary: Return a hash code for the given AST. - - {b Remarks}: Implicitly used by [Hashtbl.hash] for values of type [ast], [app], [sort], [func_decl], and [pattern]. - def_API('get_ast_hash', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_ast_hash : context -> ast -> int - = "camlidl_z3_Z3_get_ast_hash" - -(** - Summary: Return the sort of an AST node. - The AST node must be a constant, application, numeral, bound variable, or quantifier. - def_API('get_sort', SORT, (_in(CONTEXT), _in(AST))) -*) -external get_sort : context -> ast -> sort - = "camlidl_z3_Z3_get_sort" - -(** - Summary: Return true if the given expression [t] is well sorted. - def_API('is_well_sorted', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_well_sorted : context -> ast -> bool - = "camlidl_z3_Z3_is_well_sorted" - -(** - Summary: Return L_TRUE if [a] is true, L_FALSE if it is false, and L_UNDEF otherwise. - def_API('get_bool_value', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_bool_value : context -> ast -> lbool - = "camlidl_z3_Z3_get_bool_value" - -(** - Summary: Return the kind of the given AST. - def_API('get_ast_kind', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_ast_kind : context -> ast -> ast_kind - = "camlidl_z3_Z3_get_ast_kind" - -(** - def_API('is_app', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_app : context -> ast -> bool - = "camlidl_z3_Z3_is_app" - -(** - def_API('is_numeral_ast', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_numeral_ast : context -> ast -> bool - = "camlidl_z3_Z3_is_numeral_ast" - -(** - Summary: Return true if the give AST is a real algebraic number. - def_API('is_algebraic_number', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_algebraic_number : context -> ast -> bool - = "camlidl_z3_Z3_is_algebraic_number" - -(** - Summary: Convert an [ast] into an [APP_AST]. - - {b Precondition}: {v get_ast_kind c a == [APP_AST] v} - def_API('to_app', APP, (_in(CONTEXT), _in(AST))) -*) -external to_app : context -> ast -> app - = "camlidl_z3_Z3_to_app" - -(** - Summary: Convert an AST into a FUNC_DECL_AST. This is just type casting. - - {b Precondition}: {v get_ast_kind c a == FUNC_DECL_AST v} - def_API('to_func_decl', FUNC_DECL, (_in(CONTEXT), _in(AST))) -*) -external to_func_decl : context -> ast -> func_decl - = "camlidl_z3_Z3_to_func_decl" - -(** - {4 {L Numerals}} -*) - -(** - Summary: \[ [ numeral_refine c a ] \] is the refined view of [a]. - - {b Precondition}: [get_ast_kind c a = NUMERAL_AST] -*) -val numeral_refine : context -> ast -> numeral_refined - -(** - {5 {L Low-level API}} -*) -(** - Summary: Return numeral value, as a string of a numeric constant term - - {b Precondition}: get_ast_kind c a == NUMERAL_AST - def_API('get_numeral_string', STRING, (_in(CONTEXT), _in(AST))) -*) -external get_numeral_string : context -> ast -> string - = "camlidl_z3_Z3_get_numeral_string" - -(** - Summary: Return numeral as a string in decimal notation. - The result has at most [precision] decimal places. - - {b Precondition}: get_ast_kind c a == NUMERAL_AST || is_algebraic_number c a - def_API('get_numeral_decimal_string', STRING, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_numeral_decimal_string : context -> ast -> int -> string - = "camlidl_z3_Z3_get_numeral_decimal_string" - -(** - Summary: Return the numerator (as a numeral AST) of a numeral AST of sort Real. - - {b Precondition}: get_ast_kind c a == NUMERAL_AST - def_API('get_numerator', AST, (_in(CONTEXT), _in(AST))) -*) -external get_numerator : context -> ast -> ast - = "camlidl_z3_Z3_get_numerator" - -(** - Summary: Return the denominator (as a numeral AST) of a numeral AST of sort Real. - - {b Precondition}: get_ast_kind c a == NUMERAL_AST - def_API('get_denominator', AST, (_in(CONTEXT), _in(AST))) -*) -external get_denominator : context -> ast -> ast - = "camlidl_z3_Z3_get_denominator" - -(** - Summary: Return numeral value, as a pair of 64 bit numbers if the representation fits. - @param c logical context. - @param a term. - @param num numerator. - @param den denominator. - Return [TRUE] if the numeral value fits in 64 bit numerals, [FALSE] otherwise. - - {b Precondition}: get_ast_kind a == NUMERAL_AST - def_API('get_numeral_small', BOOL, (_in(CONTEXT), _in(AST), _out(INT64), _out(INT64))) -*) -external get_numeral_small : context -> ast -> bool * int64 * int64 - = "camlidl_z3_Z3_get_numeral_small" - -(** - Summary: \[ [ get_numeral_int c v ] \] - Similar to {!get_numeral_string}, but only succeeds if - the value can fit in a machine int. Return TRUE if the call succeeded. - - {b Precondition}: get_ast_kind c v == NUMERAL_AST - - {b See also}: {!get_numeral_string} - def_API('get_numeral_int', BOOL, (_in(CONTEXT), _in(AST), _out(INT))) -*) -external get_numeral_int : context -> ast -> bool * int - = "camlidl_z3_Z3_get_numeral_int" - -(** - Summary: \[ [ get_numeral_int64 c v ] \] - Similar to {!get_numeral_string}, but only succeeds if - the value can fit in a machine long long int. Return TRUE if the call succeeded. - - {b Precondition}: get_ast_kind c v == NUMERAL_AST - - {b See also}: {!get_numeral_string} - def_API('get_numeral_int64', BOOL, (_in(CONTEXT), _in(AST), _out(INT64))) -*) -external get_numeral_int64 : context -> ast -> bool * int64 - = "camlidl_z3_Z3_get_numeral_int64" - -(** - Summary: \[ [ get_numeral_rational_int64 c x y] \] - Similar to {!get_numeral_string}, but only succeeds if - the value can fit as a rational number as machine long long int. Return TRUE if the call succeeded. - - {b Precondition}: get_ast_kind c v == NUMERAL_AST - - {b See also}: {!get_numeral_string} - def_API('get_numeral_rational_int64', BOOL, (_in(CONTEXT), _in(AST), _out(INT64), _out(INT64))) -*) -external get_numeral_rational_int64 : context -> ast -> bool * int64 * int64 - = "camlidl_z3_Z3_get_numeral_rational_int64" - -(** - Summary: Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - The result is a numeral AST of sort Real. - - {b Precondition}: is_algebraic_number c a - def_API('get_algebraic_number_lower', AST, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_algebraic_number_lower : context -> ast -> int -> ast - = "camlidl_z3_Z3_get_algebraic_number_lower" - -(** - Summary: Return a upper bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - The result is a numeral AST of sort Real. - - {b Precondition}: is_algebraic_number c a - def_API('get_algebraic_number_upper', AST, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_algebraic_number_upper : context -> ast -> int -> ast - = "camlidl_z3_Z3_get_algebraic_number_upper" - -(** - {4 {L Patterns}} -*) -(** - Summary: Convert a pattern into ast. - - {b Remarks}: [pattern_to_ast c p] can be replaced by [(p :> ast)]. - def_API('pattern_to_ast', AST, (_in(CONTEXT), _in(PATTERN))) -*) -external pattern_to_ast : context -> pattern -> ast - = "camlidl_z3_Z3_pattern_to_ast" - - -(** - Summary: \[ [ get_pattern_terms c p ] \] is the ast's in pattern. - - {b See also}: {!get_pattern_num_terms} - - {b See also}: {!get_pattern} -*) -val get_pattern_terms: context -> pattern -> ast array;; - -(** - Summary: Return number of terms in pattern. - def_API('get_pattern_num_terms', UINT, (_in(CONTEXT), _in(PATTERN))) -*) -external get_pattern_num_terms : context -> pattern -> int - = "camlidl_z3_Z3_get_pattern_num_terms" - -(** - Summary: Return i'th ast in pattern. - def_API('get_pattern', AST, (_in(CONTEXT), _in(PATTERN), _in(UINT))) -*) -external get_pattern : context -> pattern -> int -> ast - = "camlidl_z3_Z3_get_pattern" - -(** - {4 {L Quantifiers}} -*) -(** - Summary: Return index of de-Brujin bound variable. - - {b Precondition}: get_ast_kind a == VAR_AST - def_API('get_index_value', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_index_value : context -> ast -> int - = "camlidl_z3_Z3_get_index_value" - -(** - Summary: Determine if quantifier is universal. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('is_quantifier_forall', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_quantifier_forall : context -> ast -> bool - = "camlidl_z3_Z3_is_quantifier_forall" - -(** - Summary: Obtain weight of quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_weight', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_weight : context -> ast -> int - = "camlidl_z3_Z3_get_quantifier_weight" - -(** - Summary: Return number of patterns used in quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_num_patterns', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_num_patterns : context -> ast -> int - = "camlidl_z3_Z3_get_quantifier_num_patterns" - -(** - Summary: Return i'th pattern. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_pattern_ast', PATTERN, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_quantifier_pattern_ast : context -> ast -> int -> pattern - = "camlidl_z3_Z3_get_quantifier_pattern_ast" - -(** - Summary: Return number of no_patterns used in quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_num_no_patterns', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_num_no_patterns : context -> ast -> int - = "camlidl_z3_Z3_get_quantifier_num_no_patterns" - -(** - Summary: Return i'th no_pattern. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_no_pattern_ast', AST, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_quantifier_no_pattern_ast : context -> ast -> int -> ast - = "camlidl_z3_Z3_get_quantifier_no_pattern_ast" - -(** - Summary: Return number of bound variables of quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_num_bound', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_num_bound : context -> ast -> int - = "camlidl_z3_Z3_get_quantifier_num_bound" - -(** - Summary: Return symbol of the i'th bound variable. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_bound_name', SYMBOL, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_quantifier_bound_name : context -> ast -> int -> symbol - = "camlidl_z3_Z3_get_quantifier_bound_name" - -(** - Summary: Return sort of the i'th bound variable. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_bound_sort', SORT, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_quantifier_bound_sort : context -> ast -> int -> sort - = "camlidl_z3_Z3_get_quantifier_bound_sort" - -(** - Summary: Return body of quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_body', AST, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_body : context -> ast -> ast - = "camlidl_z3_Z3_get_quantifier_body" - -(** - {3 {L Simplification}} -*) -(** - Summary: Interface to simplifier. - Provides an interface to the AST simplifier used by Z3. - def_API('simplify', AST, (_in(CONTEXT), _in(AST))) -*) -external simplify : context -> ast -> ast - = "camlidl_z3_Z3_simplify" - -(** - Summary: Interface to simplifier. - Provides an interface to the AST simplifier used by Z3. - This procedure is similar to {!simplify}, but the behavior of the simplifier - can be configured using the given parameter set. - def_API('simplify_ex', AST, (_in(CONTEXT), _in(AST), _in(PARAMS))) -*) -external simplify_ex : context -> ast -> params -> ast - = "camlidl_z3_Z3_simplify_ex" - -(** - Summary: Return a string describing all available parameters. - def_API('simplify_get_help', STRING, (_in(CONTEXT),)) -*) -external simplify_get_help : context -> string - = "camlidl_z3_Z3_simplify_get_help" - -(** - Summary: Return the parameter description set for the simplify procedure. - def_API('simplify_get_param_descrs', PARAM_DESCRS, (_in(CONTEXT),)) -*) -external simplify_get_param_descrs : context -> param_descrs - = "camlidl_z3_Z3_simplify_get_param_descrs" - -(** - {2 {L Modifiers}} -*) -(** - Summary: Update the arguments of term [a] using the arguments [args]. - The number of arguments [num_args] should coincide - with the number of arguments to [a]. - If [a] is a quantifier, then num_args has to be 1. - def_API('update_term', AST, (_in(CONTEXT), _in(AST), _in(UINT), _in_array(2, AST))) -*) -external update_term : context -> ast -> ast array -> ast - = "camlidl_z3_Z3_update_term" - -(** - Summary: Substitute every occurrence of {e from[i] } in [a] with {e to[i] }, for [i] smaller than [num_exprs]. - The result is the new AST. The arrays [from] and [to] must have size [num_exprs]. - For every [i] smaller than [num_exprs], we must have that sort of {e from[i] } must be equal to sort of {e to[i] }. - def_API('substitute', AST, (_in(CONTEXT), _in(AST), _in(UINT), _in_array(2, AST), _in_array(2, AST))) -*) -external substitute : context -> ast -> ast array -> ast array -> ast - = "camlidl_z3_Z3_substitute" - -(** - Summary: Substitute the free variables in [a] with the expressions in [to]. - For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term {e to[i] }. - def_API('substitute_vars', AST, (_in(CONTEXT), _in(AST), _in(UINT), _in_array(2, AST))) -*) -external substitute_vars : context -> ast -> ast array -> ast - = "camlidl_z3_Z3_substitute_vars" - -(** - Summary: Translate/Copy the AST [a] from context [source] to context [target]. - AST [a] must have been created using context [source]. - - {b Precondition}: source != target - def_API('translate', AST, (_in(CONTEXT), _in(AST), _in(CONTEXT))) -*) -external translate : context -> ast -> context -> ast - = "camlidl_z3_Z3_translate" - -(** - {2 {L Models}} -*) - -(** - A model assigns uninterpreted sorts to finite universes of distinct values, constants to values, - and arrays and functions to finite maps from argument values to result values plus a default - value for all other arguments. -*) -type model_refined = { - sorts : (sort, ast_vector) Hashtbl.t; - consts : (func_decl, ast) Hashtbl.t; - arrays : (func_decl, (ast, ast) Hashtbl.t * ast) Hashtbl.t; - funcs : (func_decl, (ast array, ast) Hashtbl.t * ast) Hashtbl.t; -} - - -(** - Summary: [model_refine c m] is the refined model of [m]. -*) -val model_refine : context -> model -> model_refined - -(** - Summary: \[ [ model_eval c m t ] \] - Evaluate the AST node [t] in the given model. - Return [None] if the term was not successfully evaluated. - If [model_completion] is TRUE, then Z3 will assign an interpretation for any constant or function that does - not have an interpretation in [m]. These constants and functions were essentially don't cares. - The evaluation may fail for the following reasons: - - [t] contains a quantifier. - - the model [m] is partial, that is, it doesn't have a complete interpretation for uninterpreted functions. - That is, the option {e MODEL_PARTIAL=true } was used. - - [t] is type incorrect. - def_API('model_eval', BOOL, (_in(CONTEXT), _in(MODEL), _in(AST), _in(BOOL), _out(AST))) -*) -external model_eval : context -> model -> ast -> bool -> ast option - = "camlidl_z3_Z3_model_eval" - -(** - {4 {L Low-level API}} -*) -(** - Summary: Return the interpretation (i.e., assignment) of constant [a] in the model [m]. - Return [None], - if the model does not assign an interpretation for [a]. - That should be interpreted as: the value of [a] does not matter. - - {b Precondition}: get_arity c a == 0 - def_API('model_get_const_interp', AST, (_in(CONTEXT), _in(MODEL), _in(FUNC_DECL))) -*) -external model_get_const_interp : context -> model -> func_decl -> ast option - = "camlidl_z3_Z3_model_get_const_interp" - -(** - Summary: Return the interpretation of the function [f] in the model [m]. - Return [None], - if the model does not assign an interpretation for [f]. - That should be interpreted as: the [f] does not matter. - - {b Precondition}: get_arity c f > 0 - def_API('model_get_func_interp', FUNC_INTERP, (_in(CONTEXT), _in(MODEL), _in(FUNC_DECL))) -*) -external model_get_func_interp : context -> model -> func_decl -> func_interp option - = "camlidl_z3_Z3_model_get_func_interp" - -(** - Summary: Return the number of constants assigned by the given model. - - {b See also}: {!model_get_const_decl} - def_API('model_get_num_consts', UINT, (_in(CONTEXT), _in(MODEL))) -*) -external model_get_num_consts : context -> model -> int - = "camlidl_z3_Z3_model_get_num_consts" - -(** - Summary: \[ [ model_get_const_decl c m i ] \] - Return the i-th constant in the given model. - - {b Precondition}: i < model_get_num_consts c m - - {b See also}: {!model_eval} - def_API('model_get_const_decl', FUNC_DECL, (_in(CONTEXT), _in(MODEL), _in(UINT))) -*) -external model_get_const_decl : context -> model -> int -> func_decl - = "camlidl_z3_Z3_model_get_const_decl" - -(** - Summary: Return the number of function interpretations in the given model. - 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. - def_API('model_get_num_funcs', UINT, (_in(CONTEXT), _in(MODEL))) -*) -external model_get_num_funcs : context -> model -> int - = "camlidl_z3_Z3_model_get_num_funcs" - -(** - Summary: \[ [ model_get_func_decl c m i ] \] - Return the declaration of the i-th function in the given model. - - {b Precondition}: i < model_get_num_funcs c m - - {b See also}: {!model_get_num_funcs} - def_API('model_get_func_decl', FUNC_DECL, (_in(CONTEXT), _in(MODEL), _in(UINT))) -*) -external model_get_func_decl : context -> model -> int -> func_decl - = "camlidl_z3_Z3_model_get_func_decl" - -(** - Summary: Return the number of uninterpreted sorts that [m] assigs an interpretation to. - Z3 also provides an intepretation for uninterpreted sorts used in a formua. - The interpretation for a sort [s] is a finite set of distinct values. We say this finite set is - the "universe" of [s]. - - {b See also}: {!model_get_sort} - - {b See also}: {!model_get_sort_universe} - def_API('model_get_num_sorts', UINT, (_in(CONTEXT), _in(MODEL))) -*) -external model_get_num_sorts : context -> model -> int - = "camlidl_z3_Z3_model_get_num_sorts" - -(** - Summary: Return a uninterpreted sort that [m] assigns an interpretation. - - {b Precondition}: i < model_get_num_sorts c m - - {b See also}: {!model_get_num_sorts} - - {b See also}: {!model_get_sort_universe} - def_API('model_get_sort', SORT, (_in(CONTEXT), _in(MODEL), _in(UINT))) -*) -external model_get_sort : context -> model -> int -> sort - = "camlidl_z3_Z3_model_get_sort" - -(** - Summary: Return the finite set of distinct values that represent the interpretation for sort [s]. - - {b See also}: {!model_get_num_sorts} - - {b See also}: {!model_get_sort} - def_API('model_get_sort_universe', AST_VECTOR, (_in(CONTEXT), _in(MODEL), _in(SORT))) -*) -external model_get_sort_universe : context -> model -> sort -> ast_vector - = "camlidl_z3_Z3_model_get_sort_universe" - -(** - Summary: The {e (_ as-array f) } AST node is a construct for assigning interpretations for arrays in Z3. - It is the array such that forall indices [i] we have that {e (select (_ as-array f) i) } is equal to {e (f i) }. - This procedure returns TRUE if the [a] is an [as-array] AST node. - Z3 current solvers have minimal support for [as_array] nodes. - - {b See also}: {!get_as_array_func_decl} - def_API('is_as_array', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_as_array : context -> ast -> bool - = "camlidl_z3_Z3_is_as_array" - -(** - Summary: Return the function declaration [f] associated with a {e (_ as_array f) } node. - - {b See also}: {!is_as_array} - def_API('get_as_array_func_decl', FUNC_DECL, (_in(CONTEXT), _in(AST))) -*) -external get_as_array_func_decl : context -> ast -> func_decl - = "camlidl_z3_Z3_get_as_array_func_decl" - -(** - Summary: Return the number of entries in the given function interpretation. - 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. - This procedure return the number of element in the finite map of [f]. - def_API('func_interp_get_num_entries', UINT, (_in(CONTEXT), _in(FUNC_INTERP))) -*) -external func_interp_get_num_entries : context -> func_interp -> int - = "camlidl_z3_Z3_func_interp_get_num_entries" - -(** - Summary: Return a "point" of the given function intepretation. It represents the - value of [f] in a particular point. - - {b Precondition}: i < func_interp_get_num_entries c f - - {b See also}: {!func_interp_get_num_entries} - def_API('func_interp_get_entry', FUNC_ENTRY, (_in(CONTEXT), _in(FUNC_INTERP), _in(UINT))) -*) -external func_interp_get_entry : context -> func_interp -> int -> func_entry - = "camlidl_z3_Z3_func_interp_get_entry" - -(** - Summary: Return the 'else' value of the given function interpretation. - A function interpretation is represented as a finite map and an 'else' value. - This procedure returns the 'else' value. - def_API('func_interp_get_else', AST, (_in(CONTEXT), _in(FUNC_INTERP))) -*) -external func_interp_get_else : context -> func_interp -> ast - = "camlidl_z3_Z3_func_interp_get_else" - -(** - Summary: Return the arity (number of arguments) of the given function interpretation. - def_API('func_interp_get_arity', UINT, (_in(CONTEXT), _in(FUNC_INTERP))) -*) -external func_interp_get_arity : context -> func_interp -> int - = "camlidl_z3_Z3_func_interp_get_arity" - -(** - Summary: Return the value of this point. - A func_entry object represents an element in the finite map used to encode - a function interpretation. - - {b See also}: {!func_interp_get_entry} - def_API('func_entry_get_value', AST, (_in(CONTEXT), _in(FUNC_ENTRY))) -*) -external func_entry_get_value : context -> func_entry -> ast - = "camlidl_z3_Z3_func_entry_get_value" - -(** - Summary: Return the number of arguments in a func_entry object. - - {b See also}: {!func_interp_get_entry} - def_API('func_entry_get_num_args', UINT, (_in(CONTEXT), _in(FUNC_ENTRY))) -*) -external func_entry_get_num_args : context -> func_entry -> int - = "camlidl_z3_Z3_func_entry_get_num_args" - -(** - Summary: Return an argument of a func_entry object. - - {b Precondition}: i < func_entry_get_num_args c e - - {b See also}: {!func_interp_get_entry} - def_API('func_entry_get_arg', AST, (_in(CONTEXT), _in(FUNC_ENTRY), _in(UINT))) -*) -external func_entry_get_arg : context -> func_entry -> int -> ast - = "camlidl_z3_Z3_func_entry_get_arg" - -(** - {2 {L Interaction logging.}} -*) -(** - Summary: Log interaction to a file. - extra_API('open_log', INT, (_in(STRING),)) -*) -external open_log : string -> bool - = "camlidl_z3_Z3_open_log" - -(** - Summary: Append user-defined string to interaction log. - The interaction log is opened using open_log. - It contains the formulas that are checked using Z3. - You can use this command to append comments, for instance. - extra_API('append_log', VOID, (_in(STRING),)) -*) -external append_log : string -> unit - = "camlidl_z3_Z3_append_log" - -(** - Summary: Close interaction log. - extra_API('close_log', VOID, ()) -*) -external close_log : unit -> unit - = "camlidl_z3_Z3_close_log" - -(** - Summary: Enable/disable printing warning messages to the console. - Warnings are printed after passing [true], warning messages are - suppressed after calling this method with [false]. - def_API('toggle_warning_messages', VOID, (_in(BOOL),)) -*) -external toggle_warning_messages : bool -> unit - = "camlidl_z3_Z3_toggle_warning_messages" - -(** - {2 {L String conversion}} -*) -(** - Summary: Select mode for the format used for pretty-printing AST nodes. - The default mode for pretty printing AST nodes is to produce - SMT-LIB style output where common subexpressions are printed - at each occurrence. The mode is called PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - - {b See also}: {!ast_to_string} - - {b See also}: {!pattern_to_string} - - {b See also}: {!func_decl_to_string} - def_API('set_ast_print_mode', VOID, (_in(CONTEXT), _in(PRINT_MODE))) -*) -external set_ast_print_mode : context -> ast_print_mode -> unit - = "camlidl_z3_Z3_set_ast_print_mode" - -(** - Summary: Convert the given AST node into a string. - - {b See also}: {!pattern_to_string} - - {b See also}: {!sort_to_string} - def_API('ast_to_string', STRING, (_in(CONTEXT), _in(AST))) -*) -external ast_to_string : context -> ast -> string - = "camlidl_z3_Z3_ast_to_string" - -(** - def_API('pattern_to_string', STRING, (_in(CONTEXT), _in(PATTERN))) -*) -external pattern_to_string : context -> pattern -> string - = "camlidl_z3_Z3_pattern_to_string" - -(** - def_API('sort_to_string', STRING, (_in(CONTEXT), _in(SORT))) -*) -external sort_to_string : context -> sort -> string - = "camlidl_z3_Z3_sort_to_string" - -(** - def_API('func_decl_to_string', STRING, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external func_decl_to_string : context -> func_decl -> string - = "camlidl_z3_Z3_func_decl_to_string" - -(** - Summary: Convert the given model into a string. - def_API('model_to_string', STRING, (_in(CONTEXT), _in(MODEL))) -*) -external model_to_string : context -> model -> string - = "camlidl_z3_Z3_model_to_string" - -(** - Summary: Convert the given benchmark into SMT-LIB formatted string. - @param c - context. - @param name - name of benchmark. The argument is optional. - @param logic - the benchmark logic. - @param status - the status string (sat, unsat, or unknown) - @param attributes - other attributes, such as source, difficulty or category. - @param num_assumptions - number of assumptions. - @param assumptions - auxiliary assumptions. - @param formula - formula to be checked for consistency in conjunction with assumptions. - def_API('benchmark_to_smtlib_string', STRING, (_in(CONTEXT), _in(STRING), _in(STRING), _in(STRING), _in(STRING), _in(UINT), _in_array(5, AST), _in(AST))) -*) -external benchmark_to_smtlib_string : context -> string -> string -> string -> string -> ast array -> ast -> string - = "camlidl_z3_Z3_benchmark_to_smtlib_string_bytecode" "camlidl_z3_Z3_benchmark_to_smtlib_string" - -(** - {2 {L Parser interface}} -*) -(** - Summary: \[ [ parse_smtlib2_string c str ] \] - Parse the given string using the SMT-LIB2 parser. - It returns a formula comprising of the conjunction of assertions in the scope - (up to push/pop) at the end of the string. - def_API('parse_smtlib2_string', AST, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _in(UINT), _in_array(5, SYMBOL), _in_array(5, FUNC_DECL))) -*) -external parse_smtlib2_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - = "camlidl_z3_Z3_parse_smtlib2_string_bytecode" "camlidl_z3_Z3_parse_smtlib2_string" - -(** - Summary: Similar to {!parse_smtlib2_string}, but reads the benchmark from a file. - def_API('parse_smtlib2_file', AST, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _in(UINT), _in_array(5, SYMBOL), _in_array(5, FUNC_DECL))) -*) -external parse_smtlib2_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - = "camlidl_z3_Z3_parse_smtlib2_file_bytecode" "camlidl_z3_Z3_parse_smtlib2_file" - - -(** - Summary: \[ [ parse_smtlib_string_x c str sort_names sorts decl_names decls ] \] - 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 [sort_names] and [decl_names] don't need to match the names - of the sorts and declarations in the arrays [sorts] and [decls]. This is an useful feature - since we can use arbitrary names to reference sorts and declarations defined using the API. - - {b See also}: {!parse_smtlib_file_x} -*) -val parse_smtlib_string_x: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> (ast array * ast array * func_decl array) -(** - Summary: Similar to {!parse_smtlib_string_x}, but reads the benchmark from a file. - - {b See also}: {!parse_smtlib_string_x} -*) -val parse_smtlib_file_x: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> (ast array * ast array * func_decl array) -(** - Summary: \[ [ parse_smtlib_string_formula c ... ] \] calls [(parse_smtlib_string c ...)] and returns the single formula produced. - - {b See also}: {!parse_smtlib_file_formula} - - {b See also}: {!parse_smtlib_string_x} -*) -val parse_smtlib_string_formula: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast -(** - Summary: \[ [ parse_smtlib_file_formula c ... ] \] calls [(parse_smtlib_file c ...)] and returns the single formula produced. - - {b See also}: {!parse_smtlib_string_formula} - - {b See also}: {!parse_smtlib_file_x} -*) -val parse_smtlib_file_formula: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - -(** - {4 {L Low-level API}} -*) -(** - Summary: \[ [ parse_smtlib_string c str sort_names sorts decl_names decls ] \] - 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 [sort_names] and [decl_names] don't need to match the names - of the sorts and declarations in the arrays [sorts] and [decls]. This is an useful feature - since we can use arbitrary names to reference sorts and declarations defined using the C API. - The formulas, assumptions and declarations defined in [str] can be extracted using the functions: - {!get_smtlib_num_formulas}, {!get_smtlib_formula}, {!get_smtlib_num_assumptions}, {!get_smtlib_assumption}, - {!get_smtlib_num_decls}, and {!get_smtlib_decl}. - def_API('parse_smtlib_string', VOID, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _in(UINT), _in_array(5, SYMBOL), _in_array(5, FUNC_DECL))) -*) -external parse_smtlib_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - = "camlidl_z3_Z3_parse_smtlib_string_bytecode" "camlidl_z3_Z3_parse_smtlib_string" - -(** - Summary: Similar to {!parse_smtlib_string}, but reads the benchmark from a file. - def_API('parse_smtlib_file', VOID, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _in(UINT), _in_array(5, SYMBOL), _in_array(5, FUNC_DECL))) -*) -external parse_smtlib_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - = "camlidl_z3_Z3_parse_smtlib_file_bytecode" "camlidl_z3_Z3_parse_smtlib_file" - -(** - Summary: Return the number of SMTLIB formulas parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - def_API('get_smtlib_num_formulas', UINT, (_in(CONTEXT), )) -*) -external get_smtlib_num_formulas : context -> int - = "camlidl_z3_Z3_get_smtlib_num_formulas" - -(** - Summary: \[ [ get_smtlib_formula c i ] \] - Return the i-th formula parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - - {b Precondition}: i < get_smtlib_num_formulas c - def_API('get_smtlib_formula', AST, (_in(CONTEXT), _in(UINT))) -*) -external get_smtlib_formula : context -> int -> ast - = "camlidl_z3_Z3_get_smtlib_formula" - -(** - Summary: Return the number of SMTLIB assumptions parsed by {!parse_smtlib_string} or {!parse_smtlib_file}. - def_API('get_smtlib_num_assumptions', UINT, (_in(CONTEXT), )) -*) -external get_smtlib_num_assumptions : context -> int - = "camlidl_z3_Z3_get_smtlib_num_assumptions" - -(** - Summary: \[ [ get_smtlib_assumption c i ] \] - Return the i-th assumption parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - - {b Precondition}: i < get_smtlib_num_assumptions c - def_API('get_smtlib_assumption', AST, (_in(CONTEXT), _in(UINT))) -*) -external get_smtlib_assumption : context -> int -> ast - = "camlidl_z3_Z3_get_smtlib_assumption" - -(** - Summary: Return the number of declarations parsed by {!parse_smtlib_string} or {!parse_smtlib_file}. - def_API('get_smtlib_num_decls', UINT, (_in(CONTEXT), )) -*) -external get_smtlib_num_decls : context -> int - = "camlidl_z3_Z3_get_smtlib_num_decls" - -(** - Summary: \[ [ get_smtlib_decl c i ] \] - Return the i-th declaration parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - - {b Precondition}: i < get_smtlib_num_decls c - def_API('get_smtlib_decl', FUNC_DECL, (_in(CONTEXT), _in(UINT))) -*) -external get_smtlib_decl : context -> int -> func_decl - = "camlidl_z3_Z3_get_smtlib_decl" - -(** - Summary: Return the number of sorts parsed by {!parse_smtlib_string} or {!parse_smtlib_file}. - def_API('get_smtlib_num_sorts', UINT, (_in(CONTEXT), )) -*) -external get_smtlib_num_sorts : context -> int - = "camlidl_z3_Z3_get_smtlib_num_sorts" - -(** - Summary: \[ [ get_smtlib_sort c i ] \] - Return the i-th sort parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - - {b Precondition}: i < get_smtlib_num_sorts c - def_API('get_smtlib_sort', SORT, (_in(CONTEXT), _in(UINT))) -*) -external get_smtlib_sort : context -> int -> sort - = "camlidl_z3_Z3_get_smtlib_sort" - -(* -(** - Summary: \[ [ get_smtlib_error c ] \] - Retrieve that last error message information generated from parsing. - def_API('get_smtlib_error', STRING, (_in(CONTEXT), )) -*) -external get_smtlib_error : context -> string - = "camlidl_z3_Z3_get_smtlib_error" - -*) -(** - {2 {L Error Handling}} -*) -(** - Summary: Set an error. - def_API('set_error', VOID, (_in(CONTEXT), _in(ERROR_CODE))) -*) -external set_error : context -> error_code -> unit - = "camlidl_z3_Z3_set_error" - -(* -(** - Summary: Return a string describing the given error code. - def_API('get_error_msg_ex', STRING, (_in(CONTEXT), _in(ERROR_CODE))) -*) -external get_error_msg_ex : context -> error_code -> string - = "camlidl_z3_Z3_get_error_msg_ex" - -*) - -(** - Summary: Return a string describing the given error code. -*) -val get_error_msg: context -> error_code -> string - -(** - {2 {L Miscellaneous}} -*) -(** - Summary: Return Z3 version number information. - def_API('get_version', VOID, (_out(UINT), _out(UINT), _out(UINT), _out(UINT))) -*) -external get_version : unit -> int * int * int * int - = "camlidl_z3_Z3_get_version" - -(** - Summary: Enable tracing messages tagged as [tag] when Z3 is compiled in debug mode. - It is a NOOP otherwise - def_API('enable_trace', VOID, (_in(STRING),)) -*) -external enable_trace : string -> unit - = "camlidl_z3_Z3_enable_trace" - -(** - Summary: Disable tracing messages tagged as [tag] when Z3 is compiled in debug mode. - It is a NOOP otherwise - def_API('disable_trace', VOID, (_in(STRING),)) -*) -external disable_trace : string -> unit - = "camlidl_z3_Z3_disable_trace" - -(** - {2 {L Fixedpoint facilities}} -*) -(** - Summary: Create a new fixedpoint context. - def_API('mk_fixedpoint', FIXEDPOINT, (_in(CONTEXT), )) -*) -external mk_fixedpoint : context -> fixedpoint - = "camlidl_z3_Z3_mk_fixedpoint" - -(** - Summary: Add a universal Horn clause as a named rule. - The [horn_rule] should be of the form: - {v - horn_rule ::= (forall (bound-vars) horn_rule) - | (=> atoms horn_rule) - | atom - v} - def_API('fixedpoint_add_rule', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(AST), _in(SYMBOL))) -*) -external fixedpoint_add_rule : context -> fixedpoint -> ast -> symbol -> unit - = "camlidl_z3_Z3_fixedpoint_add_rule" - -(** - Summary: Add a Database fact. - @param c - context - @param d - fixed point context - @param r - relation signature for the row. - @param num_args - number of columns for the given row. - @param args - array of the row elements. - The number of arguments [num_args] should be equal to the number - of sorts in the domain of [r]. Each sort in the domain should be an integral - (bit-vector, Boolean or or finite domain sort). - The call has the same effect as adding a rule where [r] is applied to the arguments. - def_API('fixedpoint_add_fact', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(FUNC_DECL), _in(UINT), _in_array(3, UINT))) -*) -external fixedpoint_add_fact : context -> fixedpoint -> func_decl -> int array -> unit - = "camlidl_z3_Z3_fixedpoint_add_fact" - -(** - Summary: Assert a constraint to the fixedpoint context. - The constraints are used as background axioms when the fixedpoint engine uses the PDR mode. - They are ignored for standard Datalog mode. - def_API('fixedpoint_assert', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(AST))) -*) -external fixedpoint_assert : context -> fixedpoint -> ast -> unit - = "camlidl_z3_Z3_fixedpoint_assert" - -(** - Summary: Pose a query against the asserted rules. - {v - query ::= (exists (bound-vars) query) - | literals - v} - query returns - - L_FALSE if the query is unsatisfiable. - - L_TRUE if the query is satisfiable. Obtain the answer by calling {!fixedpoint_get_answer}. - - L_UNDEF if the query was interrupted, timed out or otherwise failed. - def_API('fixedpoint_query', INT, (_in(CONTEXT), _in(FIXEDPOINT), _in(AST))) -*) -external fixedpoint_query : context -> fixedpoint -> ast -> lbool - = "camlidl_z3_Z3_fixedpoint_query" - -(** - Summary: Pose multiple queries against the asserted rules. - The queries are encoded as relations (function declarations). - query returns - - L_FALSE if the query is unsatisfiable. - - L_TRUE if the query is satisfiable. Obtain the answer by calling {!fixedpoint_get_answer}. - - L_UNDEF if the query was interrupted, timed out or otherwise failed. - def_API('fixedpoint_query_relations', INT, (_in(CONTEXT), _in(FIXEDPOINT), _in(UINT), _in_array(2, FUNC_DECL))) -*) -external fixedpoint_query_relations : context -> fixedpoint -> func_decl array -> lbool - = "camlidl_z3_Z3_fixedpoint_query_relations" - -(** - Summary: Retrieve a formula that encodes satisfying answers to the query. - When used in Datalog mode, the returned answer is a disjunction of conjuncts. - Each conjunct encodes values of the bound variables of the query that are satisfied. - In PDR mode, the returned answer is a single conjunction. - The previous call to fixedpoint_query must have returned L_TRUE. - def_API('fixedpoint_get_answer', AST, (_in(CONTEXT), _in(FIXEDPOINT))) -*) -external fixedpoint_get_answer : context -> fixedpoint -> ast - = "camlidl_z3_Z3_fixedpoint_get_answer" - -(** - Summary: Retrieve a string that describes the last status returned by {!fixedpoint_query}. - Use this method when {!fixedpoint_query} returns L_UNDEF. - def_API('fixedpoint_get_reason_unknown', STRING, (_in(CONTEXT), _in(FIXEDPOINT) )) -*) -external fixedpoint_get_reason_unknown : context -> fixedpoint -> string - = "camlidl_z3_Z3_fixedpoint_get_reason_unknown" - -(** - Summary: Update a named rule. - A rule with the same name must have been previously created. - def_API('fixedpoint_update_rule', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(AST), _in(SYMBOL))) -*) -external fixedpoint_update_rule : context -> fixedpoint -> ast -> symbol -> unit - = "camlidl_z3_Z3_fixedpoint_update_rule" - -(** - Summary: Query the PDR engine for the maximal levels properties are known about predicate. - This call retrieves the maximal number of relevant unfoldings - of [pred] with respect to the current exploration state. - Note: this functionality is PDR specific. - def_API('fixedpoint_get_num_levels', UINT, (_in(CONTEXT), _in(FIXEDPOINT), _in(FUNC_DECL))) -*) -external fixedpoint_get_num_levels : context -> fixedpoint -> func_decl -> int - = "camlidl_z3_Z3_fixedpoint_get_num_levels" - -(** - Retrieve the current cover of [pred] up to [level] unfoldings. - Return just the delta that is known at [level]. To - obtain the full set of properties of [pred] one should query - at [level+1] , [level+2] etc, and include [level=-1]. - Note: this functionality is PDR specific. - def_API('fixedpoint_get_cover_delta', AST, (_in(CONTEXT), _in(FIXEDPOINT), _in(INT), _in(FUNC_DECL))) -*) -external fixedpoint_get_cover_delta : context -> fixedpoint -> int -> func_decl -> ast - = "camlidl_z3_Z3_fixedpoint_get_cover_delta" - -(** - Summary: Add property about the predicate [pred]. - Add a property of predicate [pred] at [level]. - It gets pushed forward when possible. - Note: level = -1 is treated as the fixedpoint. So passing -1 for the [level] - means that the property is true of the fixed-point unfolding with respect to [pred]. - Note: this functionality is PDR specific. - def_API('fixedpoint_add_cover', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(INT), _in(FUNC_DECL), _in(AST))) -*) -external fixedpoint_add_cover : context -> fixedpoint -> int -> func_decl -> ast -> unit - = "camlidl_z3_Z3_fixedpoint_add_cover" - -(** - Summary: Retrieve statistics information from the last call to {!fixedpoint_query}. - def_API('fixedpoint_get_statistics', STATS, (_in(CONTEXT), _in(FIXEDPOINT))) -*) -external fixedpoint_get_statistics : context -> fixedpoint -> stats - = "camlidl_z3_Z3_fixedpoint_get_statistics" - -(** - Summary: Register relation as Fixedpoint defined. - Fixedpoint defined relations have least-fixedpoint semantics. - For example, the relation is empty if it does not occur - in a head or a fact. - def_API('fixedpoint_register_relation', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(FUNC_DECL))) -*) -external fixedpoint_register_relation : context -> fixedpoint -> func_decl -> unit - = "camlidl_z3_Z3_fixedpoint_register_relation" - -(** - Summary: Configure the predicate representation. - It sets the predicate to use a set of domains given by the list of symbols. - The domains given by the list of symbols must belong to a set - of built-in domains. - def_API('fixedpoint_set_predicate_representation', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(FUNC_DECL), _in(UINT), _in_array(3, SYMBOL))) -*) -external fixedpoint_set_predicate_representation : context -> fixedpoint -> func_decl -> symbol array -> unit - = "camlidl_z3_Z3_fixedpoint_set_predicate_representation" - -(** - Summary: Retrieve set of rules from fixedpoint context. - def_API('fixedpoint_get_rules', AST_VECTOR, (_in(CONTEXT),_in(FIXEDPOINT))) -*) -external fixedpoint_get_rules : context -> fixedpoint -> ast_vector - = "camlidl_z3_Z3_fixedpoint_get_rules" - -(** - Summary: Retrieve set of background assertions from fixedpoint context. - def_API('fixedpoint_get_assertions', AST_VECTOR, (_in(CONTEXT),_in(FIXEDPOINT))) -*) -external fixedpoint_get_assertions : context -> fixedpoint -> ast_vector - = "camlidl_z3_Z3_fixedpoint_get_assertions" - -(** - Summary: Set parameters on fixedpoint context. - def_API('fixedpoint_set_params', VOID, (_in(CONTEXT), _in(FIXEDPOINT), _in(PARAMS))) -*) -external fixedpoint_set_params : context -> fixedpoint -> params -> unit - = "camlidl_z3_Z3_fixedpoint_set_params" - -(** - Summary: Return a string describing all fixedpoint available parameters. - def_API('fixedpoint_get_help', STRING, (_in(CONTEXT), _in(FIXEDPOINT))) -*) -external fixedpoint_get_help : context -> fixedpoint -> string - = "camlidl_z3_Z3_fixedpoint_get_help" - -(** - Summary: Return the parameter description set for the given fixedpoint object. - def_API('fixedpoint_get_param_descrs', PARAM_DESCRS, (_in(CONTEXT), _in(FIXEDPOINT))) -*) -external fixedpoint_get_param_descrs : context -> fixedpoint -> param_descrs - = "camlidl_z3_Z3_fixedpoint_get_param_descrs" - -(** - Summary: Print the current rules and background axioms as a string. - @param c - context. - @param f - fixedpoint context. - @param num_queries - number of additional queries to print. - @param queries - additional queries. - def_API('fixedpoint_to_string', STRING, (_in(CONTEXT), _in(FIXEDPOINT), _in(UINT), _in_array(2, AST))) -*) -external fixedpoint_to_string : context -> fixedpoint -> ast array -> string - = "camlidl_z3_Z3_fixedpoint_to_string" - -(** - Summary: Parse an SMT-LIB2 string with fixedpoint rules. - Add the rules to the current fixedpoint context. - Return the set of queries in the file. - @param c - context. - @param f - fixedpoint context. - @param s - string containing SMT2 specification. - def_API('fixedpoint_from_string', AST_VECTOR, (_in(CONTEXT), _in(FIXEDPOINT), _in(STRING))) -*) -external fixedpoint_from_string : context -> fixedpoint -> string -> ast_vector - = "camlidl_z3_Z3_fixedpoint_from_string" - -(** - Summary: Parse an SMT-LIB2 file with fixedpoint rules. - Add the rules to the current fixedpoint context. - Return the set of queries in the file. - @param c - context. - @param f - fixedpoint context. - @param s - string containing SMT2 specification. - def_API('fixedpoint_from_file', AST_VECTOR, (_in(CONTEXT), _in(FIXEDPOINT), _in(STRING))) -*) -external fixedpoint_from_file : context -> fixedpoint -> string -> ast_vector - = "camlidl_z3_Z3_fixedpoint_from_file" - -(** - Summary: Create a backtracking point. - The fixedpoint solver contains a set of rules, added facts and assertions. - The set of rules, facts and assertions are restored upon calling {!fixedpoint_pop}. - - {b See also}: {!fixedpoint_pop} - def_API('fixedpoint_push', VOID, (_in(CONTEXT), _in(FIXEDPOINT))) -*) -external fixedpoint_push : context -> fixedpoint -> unit - = "camlidl_z3_Z3_fixedpoint_push" - -(** - Summary: Backtrack one backtracking point. - - {b See also}: {!fixedpoint_push} - - {b Precondition}: The number of calls to pop cannot exceed calls to push. - def_API('fixedpoint_pop', VOID, (_in(CONTEXT), _in(FIXEDPOINT))) -*) -external fixedpoint_pop : context -> fixedpoint -> unit - = "camlidl_z3_Z3_fixedpoint_pop" - -(** - {2 {L AST vectors}} -*) -(** - Summary: Return an empty AST vector. - def_API('mk_ast_vector', AST_VECTOR, (_in(CONTEXT),)) -*) -external mk_ast_vector : context -> ast_vector - = "camlidl_z3_Z3_mk_ast_vector" - -(** - Summary: Return the size of the given AST vector. - def_API('ast_vector_size', UINT, (_in(CONTEXT), _in(AST_VECTOR))) -*) -external ast_vector_size : context -> ast_vector -> int - = "camlidl_z3_Z3_ast_vector_size" - -(** - Summary: Return the AST at position [i] in the AST vector [v]. - - {b Precondition}: i < ast_vector_size c v - def_API('ast_vector_get', AST, (_in(CONTEXT), _in(AST_VECTOR), _in(UINT))) -*) -external ast_vector_get : context -> ast_vector -> int -> ast - = "camlidl_z3_Z3_ast_vector_get" - -(** - Summary: Update position [i] of the AST vector [v] with the AST [a]. - - {b Precondition}: i < ast_vector_size c v - def_API('ast_vector_set', VOID, (_in(CONTEXT), _in(AST_VECTOR), _in(UINT), _in(AST))) -*) -external ast_vector_set : context -> ast_vector -> int -> ast -> unit - = "camlidl_z3_Z3_ast_vector_set" - -(** - Summary: Resize the AST vector [v]. - def_API('ast_vector_resize', VOID, (_in(CONTEXT), _in(AST_VECTOR), _in(UINT))) -*) -external ast_vector_resize : context -> ast_vector -> int -> unit - = "camlidl_z3_Z3_ast_vector_resize" - -(** - Summary: Add the AST [a] in the end of the AST vector [v]. The size of [v] is increased by one. - def_API('ast_vector_push', VOID, (_in(CONTEXT), _in(AST_VECTOR), _in(AST))) -*) -external ast_vector_push : context -> ast_vector -> ast -> unit - = "camlidl_z3_Z3_ast_vector_push" - -(** - Summary: Translate the AST vector [v] from context [s] into an AST vector in context [t]. - def_API('ast_vector_translate', AST_VECTOR, (_in(CONTEXT), _in(AST_VECTOR), _in(CONTEXT))) -*) -external ast_vector_translate : context -> ast_vector -> context -> ast_vector - = "camlidl_z3_Z3_ast_vector_translate" - -(** - Summary: Convert AST vector into a string. - def_API('ast_vector_to_string', STRING, (_in(CONTEXT), _in(AST_VECTOR))) -*) -external ast_vector_to_string : context -> ast_vector -> string - = "camlidl_z3_Z3_ast_vector_to_string" - -(** - {2 {L AST maps}} -*) -(** - Summary: Return an empty mapping from AST to AST - def_API('mk_ast_map', AST_MAP, (_in(CONTEXT),) ) -*) -external mk_ast_map : context -> ast_map - = "camlidl_z3_Z3_mk_ast_map" - -(** - Summary: Return true if the map [m] contains the AST key [k]. - def_API('ast_map_contains', BOOL, (_in(CONTEXT), _in(AST_MAP), _in(AST))) -*) -external ast_map_contains : context -> ast_map -> ast -> bool - = "camlidl_z3_Z3_ast_map_contains" - -(** - Summary: Return the value associated with the key [k]. - The procedure invokes the error handler if [k] is not in the map. - def_API('ast_map_find', AST, (_in(CONTEXT), _in(AST_MAP), _in(AST))) -*) -external ast_map_find : context -> ast_map -> ast -> ast - = "camlidl_z3_Z3_ast_map_find" - -(** - Summary: Store/Replace a new key, value pair in the given map. - def_API('ast_map_insert', VOID, (_in(CONTEXT), _in(AST_MAP), _in(AST), _in(AST))) -*) -external ast_map_insert : context -> ast_map -> ast -> ast -> unit - = "camlidl_z3_Z3_ast_map_insert" - -(** - Summary: Erase a key from the map. - def_API('ast_map_erase', VOID, (_in(CONTEXT), _in(AST_MAP), _in(AST))) -*) -external ast_map_erase : context -> ast_map -> ast -> unit - = "camlidl_z3_Z3_ast_map_erase" - -(** - Summary: Remove all keys from the given map. - def_API('ast_map_reset', VOID, (_in(CONTEXT), _in(AST_MAP))) -*) -external ast_map_reset : context -> ast_map -> unit - = "camlidl_z3_Z3_ast_map_reset" - -(** - Summary: Return the size of the given map. - def_API('ast_map_size', UINT, (_in(CONTEXT), _in(AST_MAP))) -*) -external ast_map_size : context -> ast_map -> int - = "camlidl_z3_Z3_ast_map_size" - -(** - Summary: Return the keys stored in the given map. - def_API('ast_map_keys', AST_VECTOR, (_in(CONTEXT), _in(AST_MAP))) -*) -external ast_map_keys : context -> ast_map -> ast_vector - = "camlidl_z3_Z3_ast_map_keys" - -(** - Summary: Convert the given map into a string. - def_API('ast_map_to_string', STRING, (_in(CONTEXT), _in(AST_MAP))) -*) -external ast_map_to_string : context -> ast_map -> string - = "camlidl_z3_Z3_ast_map_to_string" - -(** - {2 {L Goals}} -*) -(** - Summary: Create a goal (aka problem). A goal is essentially a set - of formulas, that can be solved and/or transformed using - tactics and solvers. - If models == true, then model generation is enabled for the new goal. - If unsat_cores == true, then unsat core generation is enabled for the new goal. - If proofs == true, then proof generation is enabled for the new goal. Remark, the - Z3 context c must have been created with proof generation support. - def_API('mk_goal', GOAL, (_in(CONTEXT), _in(BOOL), _in(BOOL), _in(BOOL))) -*) -external mk_goal : context -> bool -> bool -> bool -> goal - = "camlidl_z3_Z3_mk_goal" - -(** - Summary: Return the "precision" of the given goal. Goals can be transformed using over and under approximations. - A 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. - def_API('goal_precision', UINT, (_in(CONTEXT), _in(GOAL))) -*) -external goal_precision : context -> goal -> goal_prec - = "camlidl_z3_Z3_goal_precision" - -(** - Summary: Add a new formula [a] to the given goal. - def_API('goal_assert', VOID, (_in(CONTEXT), _in(GOAL), _in(AST))) -*) -external goal_assert : context -> goal -> ast -> unit - = "camlidl_z3_Z3_goal_assert" - -(** - Summary: Return true if the given goal contains the formula [false]. - def_API('goal_inconsistent', BOOL, (_in(CONTEXT), _in(GOAL))) -*) -external goal_inconsistent : context -> goal -> bool - = "camlidl_z3_Z3_goal_inconsistent" - -(** - Summary: Return the depth of the given goal. It tracks how many transformations were applied to it. - def_API('goal_depth', UINT, (_in(CONTEXT), _in(GOAL))) -*) -external goal_depth : context -> goal -> int - = "camlidl_z3_Z3_goal_depth" - -(** - Summary: Erase all formulas from the given goal. - def_API('goal_reset', VOID, (_in(CONTEXT), _in(GOAL))) -*) -external goal_reset : context -> goal -> unit - = "camlidl_z3_Z3_goal_reset" - -(** - Summary: Return the number of formulas in the given goal. - def_API('goal_size', UINT, (_in(CONTEXT), _in(GOAL))) -*) -external goal_size : context -> goal -> int - = "camlidl_z3_Z3_goal_size" - -(** - Summary: Return a formula from the given goal. - - {b Precondition}: idx < goal_size c g - def_API('goal_formula', AST, (_in(CONTEXT), _in(GOAL), _in(UINT))) -*) -external goal_formula : context -> goal -> int -> ast - = "camlidl_z3_Z3_goal_formula" - -(** - Summary: Return the number of formulas, subformulas and terms in the given goal. - def_API('goal_num_exprs', UINT, (_in(CONTEXT), _in(GOAL))) -*) -external goal_num_exprs : context -> goal -> int - = "camlidl_z3_Z3_goal_num_exprs" - -(** - Summary: Return true if the goal is empty, and it is precise or the product of a under approximation. - def_API('goal_is_decided_sat', BOOL, (_in(CONTEXT), _in(GOAL))) -*) -external goal_is_decided_sat : context -> goal -> bool - = "camlidl_z3_Z3_goal_is_decided_sat" - -(** - Summary: Return true if the goal contains false, and it is precise or the product of an over approximation. - def_API('goal_is_decided_unsat', BOOL, (_in(CONTEXT), _in(GOAL))) -*) -external goal_is_decided_unsat : context -> goal -> bool - = "camlidl_z3_Z3_goal_is_decided_unsat" - -(** - Summary: Copy a goal [g] from the context [source] to a the context [target]. - def_API('goal_translate', GOAL, (_in(CONTEXT), _in(GOAL), _in(CONTEXT))) -*) -external goal_translate : context -> goal -> context -> goal - = "camlidl_z3_Z3_goal_translate" - -(** - Summary: Convert a goal into a string. - def_API('goal_to_string', STRING, (_in(CONTEXT), _in(GOAL))) -*) -external goal_to_string : context -> goal -> string - = "camlidl_z3_Z3_goal_to_string" - -(** - {2 {L Tactics and Probes}} -*) -(** - Summary: Return a tactic associated with the given name. - The complete list of tactics may be obtained using the procedures {!get_num_tactics} and {!get_tactic_name}. - It may also be obtained using the command {e (help-tactics) } in the SMT 2.0 front-end. - Tactics are the basic building block for creating custom solvers for specific problem domains. - def_API('mk_tactic', TACTIC, (_in(CONTEXT), _in(STRING))) -*) -external mk_tactic : context -> string -> tactic - = "camlidl_z3_Z3_mk_tactic" - -(** - Summary: Return a probe associated with the given name. - The complete list of probes may be obtained using the procedures {!get_num_probes} and {!get_probe_name}. - It may also be obtained using the command {e (help-tactics) } in the SMT 2.0 front-end. - 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. - def_API('mk_probe', PROBE, (_in(CONTEXT), _in(STRING))) -*) -external mk_probe : context -> string -> probe - = "camlidl_z3_Z3_mk_probe" - -(** - Summary: Return a tactic that applies [t1] to a given goal and [t2] - to every subgoal produced by t1. - def_API('tactic_and_then', TACTIC, (_in(CONTEXT), _in(TACTIC), _in(TACTIC))) -*) -external tactic_and_then : context -> tactic -> tactic -> tactic - = "camlidl_z3_Z3_tactic_and_then" - -(** - Summary: Return a tactic that first applies [t1] to a given goal, - if it fails then returns the result of [t2] applied to the given goal. - def_API('tactic_or_else', TACTIC, (_in(CONTEXT), _in(TACTIC), _in(TACTIC))) -*) -external tactic_or_else : context -> tactic -> tactic -> tactic - = "camlidl_z3_Z3_tactic_or_else" - -(** - Summary: Return a tactic that applies the given tactics in parallel. - def_API('tactic_par_or', TACTIC, (_in(CONTEXT), _in(UINT), _in_array(1, TACTIC))) -*) -external tactic_par_or : context -> tactic array -> tactic - = "camlidl_z3_Z3_tactic_par_or" - -(** - Summary: Return a tactic that applies [t1] to a given goal and then [t2] - to every subgoal produced by t1. The subgoals are processed in parallel. - def_API('tactic_par_and_then', TACTIC, (_in(CONTEXT), _in(TACTIC), _in(TACTIC))) -*) -external tactic_par_and_then : context -> tactic -> tactic -> tactic - = "camlidl_z3_Z3_tactic_par_and_then" - -(** - Summary: Return a tactic that applies [t] to a given goal for [ms] milliseconds. - If [t] does not terminate in [ms] milliseconds, then it fails. - def_API('tactic_try_for', TACTIC, (_in(CONTEXT), _in(TACTIC), _in(UINT))) -*) -external tactic_try_for : context -> tactic -> int -> tactic - = "camlidl_z3_Z3_tactic_try_for" - -(** - Summary: Return a tactic that applies [t] to a given goal is the probe [p] evaluates to true. - If [p] evaluates to false, then the new tactic behaves like the skip tactic. - def_API('tactic_when', TACTIC, (_in(CONTEXT), _in(PROBE), _in(TACTIC))) -*) -external tactic_when : context -> probe -> tactic -> tactic - = "camlidl_z3_Z3_tactic_when" - -(** - Summary: Return a tactic that applies [t1] to a given goal if the probe [p] evaluates to true, - and [t2] if [p] evaluates to false. - def_API('tactic_cond', TACTIC, (_in(CONTEXT), _in(PROBE), _in(TACTIC), _in(TACTIC))) -*) -external tactic_cond : context -> probe -> tactic -> tactic -> tactic - = "camlidl_z3_Z3_tactic_cond" - -(** - Summary: Return a tactic that keeps applying [t] until the goal is not modified anymore or the maximum - number of iterations [max] is reached. - def_API('tactic_repeat', TACTIC, (_in(CONTEXT), _in(TACTIC), _in(UINT))) -*) -external tactic_repeat : context -> tactic -> int -> tactic - = "camlidl_z3_Z3_tactic_repeat" - -(** - Summary: Return a tactic that just return the given goal. - def_API('tactic_skip', TACTIC, (_in(CONTEXT),)) -*) -external tactic_skip : context -> tactic - = "camlidl_z3_Z3_tactic_skip" - -(** - Summary: Return a tactic that always fails. - def_API('tactic_fail', TACTIC, (_in(CONTEXT),)) -*) -external tactic_fail : context -> tactic - = "camlidl_z3_Z3_tactic_fail" - -(** - Summary: Return a tactic that fails if the probe [p] evaluates to false. - def_API('tactic_fail_if', TACTIC, (_in(CONTEXT), _in(PROBE))) -*) -external tactic_fail_if : context -> probe -> tactic - = "camlidl_z3_Z3_tactic_fail_if" - -(** - Summary: Return a tactic that fails if the goal is not trivially satisfiable (i.e., empty) or - trivially unsatisfiable (i.e., contains false). - def_API('tactic_fail_if_not_decided', TACTIC, (_in(CONTEXT),)) -*) -external tactic_fail_if_not_decided : context -> tactic - = "camlidl_z3_Z3_tactic_fail_if_not_decided" - -(** - Summary: Return a tactic that applies [t] using the given set of parameters. - def_API('tactic_using_params', TACTIC, (_in(CONTEXT), _in(TACTIC), _in(PARAMS))) -*) -external tactic_using_params : context -> tactic -> params -> tactic - = "camlidl_z3_Z3_tactic_using_params" - -(** - Summary: Return a probe that always evaluates to val. - def_API('probe_const', PROBE, (_in(CONTEXT), _in(DOUBLE))) -*) -external probe_const : context -> float -> probe - = "camlidl_z3_Z3_probe_const" - -(** - Summary: Return a probe that evaluates to "true" when the value returned by [p1] is less than the value returned by [p2]. - - {b Remarks}: For probes, "true" is any value different from 0.0. - def_API('probe_lt', PROBE, (_in(CONTEXT), _in(PROBE), _in(PROBE))) -*) -external probe_lt : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_lt" - -(** - Summary: Return a probe that evaluates to "true" when the value returned by [p1] is greater than the value returned by [p2]. - - {b Remarks}: For probes, "true" is any value different from 0.0. - def_API('probe_gt', PROBE, (_in(CONTEXT), _in(PROBE), _in(PROBE))) -*) -external probe_gt : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_gt" - -(** - Summary: Return a probe that evaluates to "true" when the value returned by [p1] is less than or equal to the value returned by [p2]. - - {b Remarks}: For probes, "true" is any value different from 0.0. - def_API('probe_le', PROBE, (_in(CONTEXT), _in(PROBE), _in(PROBE))) -*) -external probe_le : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_le" - -(** - Summary: Return a probe that evaluates to "true" when the value returned by [p1] is greater than or equal to the value returned by [p2]. - - {b Remarks}: For probes, "true" is any value different from 0.0. - def_API('probe_ge', PROBE, (_in(CONTEXT), _in(PROBE), _in(PROBE))) -*) -external probe_ge : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_ge" - -(** - Summary: Return a probe that evaluates to "true" when the value returned by [p1] is equal to the value returned by [p2]. - - {b Remarks}: For probes, "true" is any value different from 0.0. - def_API('probe_eq', PROBE, (_in(CONTEXT), _in(PROBE), _in(PROBE))) -*) -external probe_eq : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_eq" - -(** - Summary: Return a probe that evaluates to "true" when [p1] and [p2] evaluates to true. - - {b Remarks}: For probes, "true" is any value different from 0.0. - def_API('probe_and', PROBE, (_in(CONTEXT), _in(PROBE), _in(PROBE))) -*) -external probe_and : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_and" - -(** - Summary: Return a probe that evaluates to "true" when [p1] or [p2] evaluates to true. - - {b Remarks}: For probes, "true" is any value different from 0.0. - def_API('probe_or', PROBE, (_in(CONTEXT), _in(PROBE), _in(PROBE))) -*) -external probe_or : context -> probe -> probe -> probe - = "camlidl_z3_Z3_probe_or" - -(** - Summary: Return a probe that evaluates to "true" when [p] does not evaluate to true. - - {b Remarks}: For probes, "true" is any value different from 0.0. - def_API('probe_not', PROBE, (_in(CONTEXT), _in(PROBE))) -*) -external probe_not : context -> probe -> probe - = "camlidl_z3_Z3_probe_not" - -(** - Summary: Return the number of builtin tactics available in Z3. - def_API('get_num_tactics', UINT, (_in(CONTEXT),)) -*) -external get_num_tactics : context -> int - = "camlidl_z3_Z3_get_num_tactics" - -(** - Summary: Return the name of the idx tactic. - - {b Precondition}: i < get_num_tactics c - def_API('get_tactic_name', STRING, (_in(CONTEXT), _in(UINT))) -*) -external get_tactic_name : context -> int -> string - = "camlidl_z3_Z3_get_tactic_name" - -(** - Summary: Return the number of builtin probes available in Z3. - def_API('get_num_probes', UINT, (_in(CONTEXT),)) -*) -external get_num_probes : context -> int - = "camlidl_z3_Z3_get_num_probes" - -(** - Summary: Return the name of the i probe. - - {b Precondition}: i < get_num_probes c - def_API('get_probe_name', STRING, (_in(CONTEXT), _in(UINT))) -*) -external get_probe_name : context -> int -> string - = "camlidl_z3_Z3_get_probe_name" - -(** - Summary: Return a string containing a description of parameters accepted by the given tactic. - def_API('tactic_get_help', STRING, (_in(CONTEXT), _in(TACTIC))) -*) -external tactic_get_help : context -> tactic -> string - = "camlidl_z3_Z3_tactic_get_help" - -(** - Summary: Return the parameter description set for the given tactic object. - def_API('tactic_get_param_descrs', PARAM_DESCRS, (_in(CONTEXT), _in(TACTIC))) -*) -external tactic_get_param_descrs : context -> tactic -> param_descrs - = "camlidl_z3_Z3_tactic_get_param_descrs" - -(** - Summary: Return a string containing a description of the tactic with the given name. - def_API('tactic_get_descr', STRING, (_in(CONTEXT), _in(STRING))) -*) -external tactic_get_descr : context -> string -> string - = "camlidl_z3_Z3_tactic_get_descr" - -(** - Summary: Return a string containing a description of the probe with the given name. - def_API('probe_get_descr', STRING, (_in(CONTEXT), _in(STRING))) -*) -external probe_get_descr : context -> string -> string - = "camlidl_z3_Z3_probe_get_descr" - -(** - Summary: Execute the probe over the goal. The probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. - def_API('probe_apply', DOUBLE, (_in(CONTEXT), _in(PROBE), _in(GOAL))) -*) -external probe_apply : context -> probe -> goal -> float - = "camlidl_z3_Z3_probe_apply" - -(** - Summary: Apply tactic [t] to the goal [g]. - def_API('tactic_apply', APPLY_RESULT, (_in(CONTEXT), _in(TACTIC), _in(GOAL))) -*) -external tactic_apply : context -> tactic -> goal -> apply_result - = "camlidl_z3_Z3_tactic_apply" - -(** - Summary: Apply tactic [t] to the goal [g] using the parameter set [p]. - def_API('tactic_apply_ex', APPLY_RESULT, (_in(CONTEXT), _in(TACTIC), _in(GOAL), _in(PARAMS))) -*) -external tactic_apply_ex : context -> tactic -> goal -> params -> apply_result - = "camlidl_z3_Z3_tactic_apply_ex" - -(** - Summary: Convert the [apply_result] object returned by {!tactic_apply} into a string. - def_API('apply_result_to_string', STRING, (_in(CONTEXT), _in(APPLY_RESULT))) -*) -external apply_result_to_string : context -> apply_result -> string - = "camlidl_z3_Z3_apply_result_to_string" - -(** - Summary: Return the number of subgoals in the [apply_result] object returned by {!tactic_apply}. - def_API('apply_result_get_num_subgoals', UINT, (_in(CONTEXT), _in(APPLY_RESULT))) -*) -external apply_result_get_num_subgoals : context -> apply_result -> int - = "camlidl_z3_Z3_apply_result_get_num_subgoals" - -(** - Summary: Return one of the subgoals in the [apply_result] object returned by {!tactic_apply}. - - {b Precondition}: i < apply_result_get_num_subgoals c r - def_API('apply_result_get_subgoal', GOAL, (_in(CONTEXT), _in(APPLY_RESULT), _in(UINT))) -*) -external apply_result_get_subgoal : context -> apply_result -> int -> goal - = "camlidl_z3_Z3_apply_result_get_subgoal" - -(** - Summary: Convert a model for the subgoal [apply_result_get_subgoal(c], r, i) into a model for the original goal [g]. - Where [g] is the goal used to create [r] using [tactic_apply(c], t, g). - def_API('apply_result_convert_model', MODEL, (_in(CONTEXT), _in(APPLY_RESULT), _in(UINT), _in(MODEL))) -*) -external apply_result_convert_model : context -> apply_result -> int -> model -> model - = "camlidl_z3_Z3_apply_result_convert_model" - -(** - {2 {L Solvers}} -*) -(** - Summary: Create 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. - def_API('mk_solver', SOLVER, (_in(CONTEXT),)) -*) -external mk_solver : context -> solver - = "camlidl_z3_Z3_mk_solver" - -(** - Summary: Create a new (incremental) solver. - def_API('mk_simple_solver', SOLVER, (_in(CONTEXT),)) -*) -external mk_simple_solver : context -> solver - = "camlidl_z3_Z3_mk_simple_solver" - -(** - Summary: Create a new solver customized for the given logic. - It behaves like {!mk_solver} if the logic is unknown or unsupported. - def_API('mk_solver_for_logic', SOLVER, (_in(CONTEXT), _in(SYMBOL))) -*) -external mk_solver_for_logic : context -> symbol -> solver - = "camlidl_z3_Z3_mk_solver_for_logic" - -(** - Summary: Create a new solver that is implemented using the given tactic. - The solver supports the commands {!solver_push} and {!solver_pop}, but it - will always solve each {!solver_check} from scratch. - def_API('mk_solver_from_tactic', SOLVER, (_in(CONTEXT), _in(TACTIC))) -*) -external mk_solver_from_tactic : context -> tactic -> solver - = "camlidl_z3_Z3_mk_solver_from_tactic" - -(** - Summary: Return a string describing all solver available parameters. - def_API('solver_get_help', STRING, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_help : context -> solver -> string - = "camlidl_z3_Z3_solver_get_help" - -(** - Summary: Return the parameter description set for the given solver object. - def_API('solver_get_param_descrs', PARAM_DESCRS, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_param_descrs : context -> solver -> param_descrs - = "camlidl_z3_Z3_solver_get_param_descrs" - -(** - Summary: Set the given solver using the given parameters. - def_API('solver_set_params', VOID, (_in(CONTEXT), _in(SOLVER), _in(PARAMS))) -*) -external solver_set_params : context -> solver -> params -> unit - = "camlidl_z3_Z3_solver_set_params" - -(** - Summary: Create a backtracking point. - The solver contains a stack of assertions. - - {b See also}: {!solver_pop} - def_API('solver_push', VOID, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_push : context -> solver -> unit - = "camlidl_z3_Z3_solver_push" - -(** - Summary: Backtrack [n] backtracking points. - - {b See also}: {!solver_push} - - {b Precondition}: n <= solver_get_num_scopes c s - def_API('solver_pop', VOID, (_in(CONTEXT), _in(SOLVER), _in(UINT))) -*) -external solver_pop : context -> solver -> int -> unit - = "camlidl_z3_Z3_solver_pop" - -(** - Summary: Remove all assertions from the solver. - def_API('solver_reset', VOID, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_reset : context -> solver -> unit - = "camlidl_z3_Z3_solver_reset" - -(** - Summary: Return the number of backtracking points. - - {b See also}: {!solver_push} - - {b See also}: {!solver_pop} - def_API('solver_get_num_scopes', UINT, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_num_scopes : context -> solver -> int - = "camlidl_z3_Z3_solver_get_num_scopes" - -(** - Summary: Assert a constraint into the solver. - The functions {!solver_check} and {!solver_check_assumptions} should be - used to check whether the logical context is consistent or not. - def_API('solver_assert', VOID, (_in(CONTEXT), _in(SOLVER), _in(AST))) -*) -external solver_assert : context -> solver -> ast -> unit - = "camlidl_z3_Z3_solver_assert" - -(** - Summary: Assert a constraint [a] into the solver, and track it (in the unsat) core using - the Boolean constant [p]. - This API is an alternative to {!solver_check_assumptions} for extracting unsat cores. - Both APIs can be used in the same solver. The unsat core will contain a combination - of the Boolean variables provided using solver_assert_and_track and the Boolean literals - provided using {!solver_check_assumptions}. - - {b Precondition}: [a] must be a Boolean expression - - {b Precondition}: [p] must be a Boolean constant aka variable. - def_API('solver_assert_and_track', VOID, (_in(CONTEXT), _in(SOLVER), _in(AST), _in(AST))) -*) -external solver_assert_and_track : context -> solver -> ast -> ast -> unit - = "camlidl_z3_Z3_solver_assert_and_track" - -(** - Summary: Return the set of asserted formulas as a goal object. - def_API('solver_get_assertions', AST_VECTOR, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_assertions : context -> solver -> ast_vector - = "camlidl_z3_Z3_solver_get_assertions" - -(** - Summary: Check whether the assertions in a given solver are consistent or not. - The function {!solver_get_model} retrieves a model if the - assertions are not unsatisfiable (i.e., the result is not \c - L_FALSE) and model construction is enabled. - The function {!solver_get_proof} retrieves a proof if proof - generation was enabled when the context was created, and the - assertions are unsatisfiable (i.e., the result is [L_FALSE)]. - def_API('solver_check', INT, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_check : context -> solver -> lbool - = "camlidl_z3_Z3_solver_check" - -(** - Summary: Check whether the assertions in the given solver and - optional assumptions are consistent or not. - The function {!solver_get_unsat_core} retrieves the subset of the - assumptions used in the unsatisfiability proof produced by Z3. - - {b See also}: {!solver_check} - def_API('solver_check_assumptions', INT, (_in(CONTEXT), _in(SOLVER), _in(UINT), _in_array(2, AST))) -*) -external solver_check_assumptions : context -> solver -> ast array -> lbool - = "camlidl_z3_Z3_solver_check_assumptions" - -(** - Summary: Retrieve the model for the last {!solver_check} or {!solver_check_assumptions} - The error handler is invoked if a model is not available because - the commands above were not invoked for the given solver, or if the result was [L_FALSE]. - def_API('solver_get_model', MODEL, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_model : context -> solver -> model - = "camlidl_z3_Z3_solver_get_model" - -(** - Summary: Retrieve the proof for the last {!solver_check} or {!solver_check_assumptions} - The error handler is invoked if proof generation is not enabled, - or if the commands above were not invoked for the given solver, - or if the result was different from [L_FALSE]. - def_API('solver_get_proof', AST, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_proof : context -> solver -> ast - = "camlidl_z3_Z3_solver_get_proof" - -(** - Summary: Retrieve the unsat core for the last {!solver_check_assumptions} - The unsat core is a subset of the assumptions [a]. - def_API('solver_get_unsat_core', AST_VECTOR, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_unsat_core : context -> solver -> ast_vector - = "camlidl_z3_Z3_solver_get_unsat_core" - -(** - Summary: Return a brief justification for an "unknown" result (i.e., L_UNDEF) for - the commands {!solver_check} and {!solver_check_assumptions} - def_API('solver_get_reason_unknown', STRING, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_reason_unknown : context -> solver -> string - = "camlidl_z3_Z3_solver_get_reason_unknown" - -(** - Summary: Return statistics for the given solver. - def_API('solver_get_statistics', STATS, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_get_statistics : context -> solver -> stats - = "camlidl_z3_Z3_solver_get_statistics" - -(** - Summary: Convert a solver into a string. - def_API('solver_to_string', STRING, (_in(CONTEXT), _in(SOLVER))) -*) -external solver_to_string : context -> solver -> string - = "camlidl_z3_Z3_solver_to_string" - -(** - {2 {L Statistics}} -*) - -type stat_datum = Stat_int of int | Stat_float of float -type stats_refined = (string, stat_datum) Hashtbl.t - - -(** - Summary: [stats_refine c s] is the refined stats of [s]. -*) -val stats_refine : context -> stats -> stats_refined - -(** - Summary: Convert a statistics into a string. - def_API('stats_to_string', STRING, (_in(CONTEXT), _in(STATS))) -*) -external stats_to_string : context -> stats -> string - = "camlidl_z3_Z3_stats_to_string" - -(** - {4 {L Low-level API}} -*) -(** - Summary: Return the number of statistical data in [s]. - def_API('stats_size', UINT, (_in(CONTEXT), _in(STATS))) -*) -external stats_size : context -> stats -> int - = "camlidl_z3_Z3_stats_size" - -(** - Summary: Return the key (a string) for a particular statistical data. - - {b Precondition}: idx < stats_size c s - def_API('stats_get_key', STRING, (_in(CONTEXT), _in(STATS), _in(UINT))) -*) -external stats_get_key : context -> stats -> int -> string - = "camlidl_z3_Z3_stats_get_key" - -(** - Summary: Return TRUE if the given statistical data is a unsigned int integer. - - {b Precondition}: idx < stats_size c s - def_API('stats_is_uint', BOOL, (_in(CONTEXT), _in(STATS), _in(UINT))) -*) -external stats_is_uint : context -> stats -> int -> bool - = "camlidl_z3_Z3_stats_is_uint" - -(** - Summary: Return TRUE if the given statistical data is a double. - - {b Precondition}: idx < stats_size c s - def_API('stats_is_double', BOOL, (_in(CONTEXT), _in(STATS), _in(UINT))) -*) -external stats_is_double : context -> stats -> int -> bool - = "camlidl_z3_Z3_stats_is_double" - -(** - Summary: Return the unsigned int value of the given statistical data. - - {b Precondition}: idx < stats_size c s && stats_is_uint c s - def_API('stats_get_uint_value', UINT, (_in(CONTEXT), _in(STATS), _in(UINT))) -*) -external stats_get_uint_value : context -> stats -> int -> int - = "camlidl_z3_Z3_stats_get_uint_value" - -(** - Summary: Return the double value of the given statistical data. - - {b Precondition}: idx < stats_size c s && stats_is_double c s - def_API('stats_get_double_value', DOUBLE, (_in(CONTEXT), _in(STATS), _in(UINT))) -*) -external stats_get_double_value : context -> stats -> int -> float - = "camlidl_z3_Z3_stats_get_double_value" - -(** - {2 {L Deprecated Constraints API}} -*) -(** - Summary: Retrieve congruence class representatives for terms. - The function can be used for relying on Z3 to identify equal terms under the current - set of assumptions. The array of terms and array of class identifiers should have - the same length. The class identifiers are numerals that are assigned to the same - value for their corresponding terms if the current context forces the terms to be - equal. You cannot deduce that terms corresponding to different numerals must be all different, - (especially when using non-convex theories). - All implied equalities are returned by this call. - This means that two terms map to the same class identifier if and only if - the current context implies that they are equal. - A side-effect of the function is a satisfiability check on the assertions on the solver that is passed in. - The function return L_FALSE if the current assertions are not satisfiable. - - {b See also}: {!check_and_get_model} - - {b See also}: {!check} - @deprecated To be moved outside of API. - def_API('get_implied_equalities', UINT, (_in(CONTEXT), _in(SOLVER), _in(UINT), _in_array(2, AST), _out_array(2, UINT))) -*) -external get_implied_equalities : context -> solver -> ast array -> lbool * int array - = "camlidl_z3_Z3_get_implied_equalities" - - -(** - {2 {L Legacy V3 API}} -*) -module V3 : sig -(** - {2 {L Legacy V3 API}} -*) - -(* File generated from z3V3.idl *) - -type symbol -and literals -and theory -and config -and context -and sort -and func_decl -and ast -and app -and pattern -and model -and constructor -and constructor_list - -and lbool = - | L_FALSE - | L_UNDEF - | L_TRUE - -and symbol_kind = - | INT_SYMBOL - | STRING_SYMBOL - -and parameter_kind = - | PARAMETER_INT - | PARAMETER_DOUBLE - | PARAMETER_RATIONAL - | PARAMETER_SYMBOL - | PARAMETER_SORT - | PARAMETER_AST - | PARAMETER_FUNC_DECL - -and sort_kind = - | UNINTERPRETED_SORT - | BOOL_SORT - | INT_SORT - | REAL_SORT - | BV_SORT - | ARRAY_SORT - | DATATYPE_SORT - | RELATION_SORT - | FINITE_DOMAIN_SORT - | UNKNOWN_SORT - -and ast_kind = - | NUMERAL_AST - | APP_AST - | VAR_AST - | QUANTIFIER_AST - | SORT_AST - | FUNC_DECL_AST - | UNKNOWN_AST - -and decl_kind = - | OP_TRUE - | OP_FALSE - | OP_EQ - | OP_DISTINCT - | OP_ITE - | OP_AND - | OP_OR - | OP_IFF - | OP_XOR - | OP_NOT - | OP_IMPLIES - | OP_OEQ - | OP_ANUM - | OP_AGNUM - | OP_LE - | OP_GE - | OP_LT - | OP_GT - | OP_ADD - | OP_SUB - | OP_UMINUS - | OP_MUL - | OP_DIV - | OP_IDIV - | OP_REM - | OP_MOD - | OP_TO_REAL - | OP_TO_INT - | OP_IS_INT - | OP_POWER - | OP_STORE - | OP_SELECT - | OP_CONST_ARRAY - | OP_ARRAY_MAP - | OP_ARRAY_DEFAULT - | OP_SET_UNION - | OP_SET_INTERSECT - | OP_SET_DIFFERENCE - | OP_SET_COMPLEMENT - | OP_SET_SUBSET - | OP_AS_ARRAY - | OP_BNUM - | OP_BIT1 - | OP_BIT0 - | OP_BNEG - | OP_BADD - | OP_BSUB - | OP_BMUL - | OP_BSDIV - | OP_BUDIV - | OP_BSREM - | OP_BUREM - | OP_BSMOD - | OP_BSDIV0 - | OP_BUDIV0 - | OP_BSREM0 - | OP_BUREM0 - | OP_BSMOD0 - | OP_ULEQ - | OP_SLEQ - | OP_UGEQ - | OP_SGEQ - | OP_ULT - | OP_SLT - | OP_UGT - | OP_SGT - | OP_BAND - | OP_BOR - | OP_BNOT - | OP_BXOR - | OP_BNAND - | OP_BNOR - | OP_BXNOR - | OP_CONCAT - | OP_SIGN_EXT - | OP_ZERO_EXT - | OP_EXTRACT - | OP_REPEAT - | OP_BREDOR - | OP_BREDAND - | OP_BCOMP - | OP_BSHL - | OP_BLSHR - | OP_BASHR - | OP_ROTATE_LEFT - | OP_ROTATE_RIGHT - | OP_EXT_ROTATE_LEFT - | OP_EXT_ROTATE_RIGHT - | OP_INT2BV - | OP_BV2INT - | OP_CARRY - | OP_XOR3 - | OP_PR_UNDEF - | OP_PR_TRUE - | OP_PR_ASSERTED - | OP_PR_GOAL - | OP_PR_MODUS_PONENS - | OP_PR_REFLEXIVITY - | OP_PR_SYMMETRY - | OP_PR_TRANSITIVITY - | OP_PR_TRANSITIVITY_STAR - | OP_PR_MONOTONICITY - | OP_PR_QUANT_INTRO - | OP_PR_DISTRIBUTIVITY - | OP_PR_AND_ELIM - | OP_PR_NOT_OR_ELIM - | OP_PR_REWRITE - | OP_PR_REWRITE_STAR - | OP_PR_PULL_QUANT - | OP_PR_PULL_QUANT_STAR - | OP_PR_PUSH_QUANT - | OP_PR_ELIM_UNUSED_VARS - | OP_PR_DER - | OP_PR_QUANT_INST - | OP_PR_HYPOTHESIS - | OP_PR_LEMMA - | OP_PR_UNIT_RESOLUTION - | OP_PR_IFF_TRUE - | OP_PR_IFF_FALSE - | OP_PR_COMMUTATIVITY - | OP_PR_DEF_AXIOM - | OP_PR_DEF_INTRO - | OP_PR_APPLY_DEF - | OP_PR_IFF_OEQ - | OP_PR_NNF_POS - | OP_PR_NNF_NEG - | OP_PR_NNF_STAR - | OP_PR_CNF_STAR - | OP_PR_SKOLEMIZE - | OP_PR_MODUS_PONENS_OEQ - | OP_PR_TH_LEMMA - | OP_PR_HYPER_RESOLVE - | OP_RA_STORE - | OP_RA_EMPTY - | OP_RA_IS_EMPTY - | OP_RA_JOIN - | OP_RA_UNION - | OP_RA_WIDEN - | OP_RA_PROJECT - | OP_RA_FILTER - | OP_RA_NEGATION_FILTER - | OP_RA_RENAME - | OP_RA_COMPLEMENT - | OP_RA_SELECT - | OP_RA_CLONE - | OP_FD_LT - | OP_LABEL - | OP_LABEL_LIT - | OP_DT_CONSTRUCTOR - | OP_DT_RECOGNISER - | OP_DT_ACCESSOR - | OP_UNINTERPRETED - -and param_kind = - | PK_UINT - | PK_BOOL - | PK_DOUBLE - | PK_SYMBOL - | PK_STRING - | PK_OTHER - | PK_INVALID - -and search_failure = - | NO_FAILURE - | UNKNOWN - | TIMEOUT - | MEMOUT_WATERMARK - | CANCELED - | NUM_CONFLICTS - | THEORY - | QUANTIFIERS - -and ast_print_mode = - | PRINT_SMTLIB_FULL - | PRINT_LOW_LEVEL - | PRINT_SMTLIB_COMPLIANT - | PRINT_SMTLIB2_COMPLIANT - - -(** -*) -(** - {2 {L Types}} - Most of the types in the API are abstract. - - [context]: manager of all other Z3 objects, global configuration options, etc. - - [symbol]: Lisp-like symbol used to name types, constants, and functions. A symbol can be created using string or integers. - - [ast]: abstract syntax tree node. That is, the data-structure used in Z3 to represent terms, formulas and types. - - [sort]: kind of AST used to represent types. - - [func_decl]: kind of AST used to represent function symbols. - - [app]: kind of AST used to represent function applications. - - [pattern]: kind of AST used to represent pattern and multi-patterns used to guide quantifier instantiation. - - [params]: parameter set used to configure many components such as: simplifiers, tactics, solvers, etc. - - [model]: model for the constraints asserted into the logical context. - - [func_interp]: interpretation of a function in a model. - - [func_entry]: representation of the value of a [func_interp] at a particular point. - - [fixedpoint]: context for the recursive predicate solver. - - [ast_vector]: vector of [ast] objects. - - [ast_map]: mapping from [ast] to [ast] objects. - - [goal]: set of formulas that can be solved and/or transformed using tactics and solvers. - - [tactic]: basic building block for creating custom solvers for specific problem domains. - - [probe]: function/predicate used to inspect a goal and collect information that may be used to decide which solver and/or preprocessing step will be used. - - [apply_result]: collection of subgoals resulting from applying of a tactic to a goal. - - [solver]: (incremental) solver, possibly specialized by a particular tactic or logic. - - [stats]: statistical data for a solver. -*) -(** - {!lbool} - Lifted Boolean type: [false], [undefined], [true]. -*) -(** - {!symbol_kind} - The different kinds of symbol. - In Z3, a symbol can be represented using integers and strings (See {!get_symbol_kind}). - - {b See also}: {!mk_int_symbol} - - {b See also}: {!mk_string_symbol} -*) -(** - {!parameter_kind} - The different kinds of parameters that can be associated with function symbols. - - {b See also}: {!get_decl_num_parameters} - - {b See also}: {!get_decl_parameter_kind} - - PARAMETER_INT is used for integer parameters. - - PARAMETER_DOUBLE is used for double parameters. - - PARAMETER_RATIONAL is used for parameters that are rational numbers. - - PARAMETER_SYMBOL is used for parameters that are symbols. - - PARAMETER_SORT is used for sort parameters. - - PARAMETER_AST is used for expression parameters. - - PARAMETER_FUNC_DECL is used for function declaration parameters. -*) -(** - {!sort_kind} - The different kinds of Z3 types (See {!get_sort_kind}). -*) -(** - {!ast_kind} - The different kinds of Z3 AST (abstract syntax trees). That is, terms, formulas and types. - - - APP_AST: constant and applications - - NUMERAL_AST: numeral constants - - VAR_AST: bound variables - - QUANTIFIER_AST: quantifiers - - SORT_AST: sort - - FUNC_DECL_AST: function declaration - - UNKNOWN_AST: internal -*) -(** - {!decl_kind} - The different kinds of interpreted function kinds. - - - OP_TRUE The constant true. - - - OP_FALSE The constant false. - - - OP_EQ The equality predicate. - - - OP_DISTINCT The n-ary distinct predicate (every argument is mutually distinct). - - - OP_ITE The ternary if-then-else term. - - - OP_AND n-ary conjunction. - - - OP_OR n-ary disjunction. - - - OP_IFF equivalence (binary). - - - OP_XOR Exclusive or. - - - OP_NOT Negation. - - - OP_IMPLIES Implication. - - - OP_OEQ Binary equivalence modulo namings. This binary predicate is used in proof terms. - It captures equisatisfiability and equivalence modulo renamings. - - - OP_ANUM Arithmetic numeral. - - - OP_AGNUM Arithmetic algebraic numeral. Algebraic numbers are used to represent irrational numbers in Z3. - - - OP_LE <=. - - - OP_GE >=. - - - OP_LT <. - - - OP_GT >. - - - OP_ADD Addition - Binary. - - - OP_SUB Binary subtraction. - - - OP_UMINUS Unary minus. - - - OP_MUL Multiplication - Binary. - - - OP_DIV Division - Binary. - - - OP_IDIV Integer division - Binary. - - - OP_REM Remainder - Binary. - - - OP_MOD Modulus - Binary. - - - OP_TO_REAL Coercion of integer to real - Unary. - - - OP_TO_INT Coercion of real to integer - Unary. - - - OP_IS_INT Check if real is also an integer - Unary. - - - OP_POWER Power operator x^y. - - - OP_STORE 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. - - - OP_SELECT Array select. - - - OP_CONST_ARRAY The constant array. For example, select(const(v),i) = v holds for every v and i. The function is unary. - - - OP_ARRAY_DEFAULT Default value of arrays. For example default(const(v)) = v. The function is unary. - - - OP_ARRAY_MAP Array map operator. - It satisfies map[f](a1,..,a_n)[i] = f(a1[i],...,a_n[i]) for every i. - - - OP_SET_UNION Set union between two Booelan arrays (two arrays whose range type is Boolean). The function is binary. - - - OP_SET_INTERSECT Set intersection between two Boolean arrays. The function is binary. - - - OP_SET_DIFFERENCE Set difference between two Boolean arrays. The function is binary. - - - OP_SET_COMPLEMENT Set complement of a Boolean array. The function is unary. - - - OP_SET_SUBSET Subset predicate between two Boolean arrays. The relation is binary. - - - OP_AS_ARRAY An array value that behaves as the function graph of the - function passed as parameter. - - - OP_BNUM Bit-vector numeral. - - - OP_BIT1 One bit bit-vector. - - - OP_BIT0 Zero bit bit-vector. - - - OP_BNEG Unary minus. - - - OP_BADD Binary addition. - - - OP_BSUB Binary subtraction. - - - OP_BMUL Binary multiplication. - - - OP_BSDIV Binary signed division. - - - OP_BUDIV Binary unsigned int division. - - - OP_BSREM Binary signed remainder. - - - OP_BUREM Binary unsigned int remainder. - - - OP_BSMOD Binary signed modulus. - - - OP_BSDIV0 Unary function. bsdiv(x,0) is congruent to bsdiv0(x). - - - OP_BUDIV0 Unary function. budiv(x,0) is congruent to budiv0(x). - - - OP_BSREM0 Unary function. bsrem(x,0) is congruent to bsrem0(x). - - - OP_BUREM0 Unary function. burem(x,0) is congruent to burem0(x). - - - OP_BSMOD0 Unary function. bsmod(x,0) is congruent to bsmod0(x). - - - OP_ULEQ Unsigned bit-vector <= - Binary relation. - - - OP_SLEQ Signed bit-vector <= - Binary relation. - - - OP_UGEQ Unsigned bit-vector >= - Binary relation. - - - OP_SGEQ Signed bit-vector >= - Binary relation. - - - OP_ULT Unsigned bit-vector < - Binary relation. - - - OP_SLT Signed bit-vector < - Binary relation. - - - OP_UGT Unsigned bit-vector > - Binary relation. - - - OP_SGT Signed bit-vector > - Binary relation. - - - OP_BAND Bit-wise and - Binary. - - - OP_BOR Bit-wise or - Binary. - - - OP_BNOT Bit-wise not - Unary. - - - OP_BXOR Bit-wise xor - Binary. - - - OP_BNAND Bit-wise nand - Binary. - - - OP_BNOR Bit-wise nor - Binary. - - - OP_BXNOR Bit-wise xnor - Binary. - - - OP_CONCAT Bit-vector concatenation - Binary. - - - OP_SIGN_EXT Bit-vector sign extension. - - - OP_ZERO_EXT Bit-vector zero extension. - - - OP_EXTRACT Bit-vector extraction. - - - OP_REPEAT Repeat bit-vector n times. - - - OP_BREDOR Bit-vector reduce or - Unary. - - - OP_BREDAND Bit-vector reduce and - Unary. - - - OP_BCOMP . - - - OP_BSHL Shift left. - - - OP_BLSHR Logical shift right. - - - OP_BASHR Arithmetical shift right. - - - OP_ROTATE_LEFT Left rotation. - - - OP_ROTATE_RIGHT Right rotation. - - - OP_EXT_ROTATE_LEFT (extended) Left rotation. Similar to OP_ROTATE_LEFT, but it is a binary operator instead of a parametric one. - - - OP_EXT_ROTATE_RIGHT (extended) Right rotation. Similar to OP_ROTATE_RIGHT, but it is a binary operator instead of a parametric one. - - - OP_INT2BV Coerce integer to bit-vector. NB. This function - is not supported by the decision procedures. Only the most - rudimentary simplification rules are applied to this function. - - - OP_BV2INT Coerce bit-vector to integer. NB. This function - is not supported by the decision procedures. Only the most - rudimentary simplification rules are applied to this function. - - - OP_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))) - - - OP_XOR3 Compute ternary XOR. - The meaning is given by the equivalence - (xor3 l1 l2 l3) <=> (xor (xor l1 l2) l3) - - - OP_PR_UNDEF: Undef/Null proof object. - - - OP_PR_TRUE: Proof for the expression 'true'. - - - OP_PR_ASSERTED: Proof for a fact asserted by the user. - - - OP_PR_GOAL: Proof for a fact (tagged as goal) asserted by the user. - - - OP_PR_MODUS_PONENS: Given a proof for p and a proof for (implies p q), produces a proof for q. - {e - T1: p - T2: (implies p q) - [mp T1 T2]: q - } - The second antecedents may also be a proof for (iff p q). - - - OP_PR_REFLEXIVITY: 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'. - - - OP_PR_SYMMETRY: Given an symmetric relation R and a proof for (R t s), produces a proof for (R s t). - {e - T1: (R t s) - [symmetry T1]: (R s t) - } - T1 is the antecedent of this proof object. - - - OP_PR_TRANSITIVITY: Given a transitive relation R, and proofs for (R t s) and (R s u), produces a proof - for (R t u). - {e - T1: (R t s) - T2: (R s u) - [trans T1 T2]: (R t u) - } - - - OP_PR_TRANSITIVITY_STAR: Condensed transitivity proof. This proof object is only used if the parameter PROOF_MODE is 1. - It combines several symmetry and transitivity proofs. - - Example: - {e - 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. - - - OP_PR_MONOTONICITY: Monotonicity proof object. - {e - 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. - - - OP_PR_QUANT_INTRO: 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)) - - - OP_PR_DISTRIBUTIVITY: 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. - - - OP_PR_AND_ELIM: Given a proof for (and l_1 ... l_n), produces a proof for l_i - - {e - T1: (and l_1 ... l_n) - [and-elim T1]: l_i - } - - OP_PR_NOT_OR_ELIM: Given a proof for (not (or l_1 ... l_n)), produces a proof for (not l_i). - - {e - T1: (not (or l_1 ... l_n)) - [not-or-elim T1]: (not l_i) - } - - - OP_PR_REWRITE: 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: - {e - (= (+ x 0) x) - (= (+ x 1 2) (+ 3 x)) - (iff (or x false) x) - } - - - OP_PR_REWRITE_STAR: 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) - - - OP_PR_PULL_QUANT: A proof for (iff (f (forall (x) q(x)) r) (forall (x) (f (q x) r))). This proof object has no antecedents. - - - OP_PR_PULL_QUANT_STAR: 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. - - - OP_PR_PUSH_QUANT: A proof for: - - {e - (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. - - - OP_PR_ELIM_UNUSED_VARS: - 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. - - - OP_PR_DER: 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. - - - OP_PR_QUANT_INST: A proof of (or (not (forall (x) (P x))) (P a)) - - - OP_PR_HYPOTHESIS: Mark a hypothesis in a natural deduction style proof. - - - OP_PR_LEMMA: - - {e - 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. - - - OP_PR_UNIT_RESOLUTION: - {e - 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') - } - - - OP_PR_IFF_TRUE: - {e - T1: p - [iff-true T1]: (iff p true) - } - - - OP_PR_IFF_FALSE: - {e - T1: (not p) - [iff-false T1]: (iff p false) - } - - - OP_PR_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. - - - OP_PR_DEF_AXIOM: Proof object used to justify Tseitin's like axioms: - - {e - (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). - - - OP_PR_DEF_INTRO: 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) - - - OP_PR_APPLY_DEF: - [apply-def T1]: F ~ n - F is 'equivalent' to n, given that T1 is a proof that - n is a name for F. - - - OP_PR_IFF_OEQ: - T1: (iff p q) - [iff~ T1]: (~ p q) - - - OP_PR_NNF_POS: Proof for a (positive) NNF step. Example: - {e - 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 - {e - 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'. - - - - OP_PR_NFF_NEG: Proof for a (negative) NNF step. Examples: - {e - 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'))) - } - - OP_PR_NNF_STAR: 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. - - - OP_PR_CNF_STAR: 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. - - - OP_PR_SKOLEMIZE: Proof for: - - {e - [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. - - - OP_PR_MODUS_PONENS_OEQ: Modus ponens style rule for equi-satisfiability. - {e - T1: p - T2: (~ p q) - [mp~ T1 T2]: q - } - - - OP_PR_TH_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: - {e - (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - } - - - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. - - - - OP_PR_HYPER_RESOLVE: Hyper-resolution rule. - - The premises of the rules is a sequence of clauses. - The first clause argument is the main clause of the rule. - One literal from the second, third, .. clause is resolved - with a literal from the first (main) clause. - - Premises of the rules are of the form - {e - (or l0 l1 l2 .. ln) - } - or - {e - (=> (and ln+1 ln+2 .. ln+m) l0) - } - or in the most general (ground) form: - {e - (=> (and ln+1 ln+2 .. ln+m) (or l0 l1 .. ln-1)) - } - In other words we use the following (Prolog style) convention for Horn - implications: - The head of a Horn implication is position 0, - the first conjunct in the body of an implication is position 1 - the second conjunct in the body of an implication is position 2 - - For general implications where the head is a disjunction, the - first n positions correspond to the n disjuncts in the head. - The next m positions correspond to the m conjuncts in the body. - - The premises can be universally quantified so that the most - general non-ground form is: - - {e - (forall (vars) (=> (and ln+1 ln+2 .. ln+m) (or l0 l1 .. ln-1))) - } - - The hyper-resolution rule takes a sequence of parameters. - The parameters are substitutions of bound variables separated by pairs - of literal positions from the main clause and side clause. - - - - OP_RA_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. - - - OP_RA_EMPTY: Creates the empty relation. - - - OP_RA_IS_EMPTY: Tests if the relation is empty. - - - OP_RA_JOIN: Create the relational join. - - - OP_RA_UNION: Create the union or convex hull of two relations. - The function takes two arguments. - - - OP_RA_WIDEN: Widen two relations. - The function takes two arguments. - - - OP_RA_PROJECT: Project the columns (provided as numbers in the parameters). - The function takes one argument. - - - OP_RA_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. - - - OP_RA_NEGATION_FILTER: 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. - - - - OP_RA_RENAME: rename columns in the relation. - The function takes one argument. - The parameters contain the renaming as a cycle. - - - OP_RA_COMPLEMENT: Complement the relation. - - - OP_RA_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. - - - OP_RA_CLONE: Create a fresh copy (clone) of a relation. - The function is logically the identity, but - in the context of a register machine allows - for [OP_RA_UNION] - to perform destructive updates to the first argument. - - - - OP_FD_LT: A less than predicate over the finite domain FINITE_DOMAIN_SORT. - - - OP_LABEL: 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. - - - OP_LABEL_LIT: A label literal (used by the Boogie Verification condition generator). - A label literal has a set of string parameters. It takes no arguments. - - - OP_DT_CONSTRUCTOR: datatype constructor. - - - OP_DT_RECOGNISER: datatype recognizer. - - - OP_DT_ACCESSOR: datatype accessor. - - - OP_UNINTERPRETED: kind used for uninterpreted symbols. -*) -(** - {!param_kind} - - The different kinds of parameters that can be associated with parameter sets. - (see {!mk_params}). - - - PK_UINT integer parameters. - - PK_BOOL boolean parameters. - - PK_DOUBLE double parameters. - - PK_SYMBOL symbol parameters. - - PK_STRING string parameters. - - PK_OTHER all internal parameter kinds which are not exposed in the API. - - PK_INVALID invalid parameter. -*) -(** - {!search_failure} - The different kinds of search failure types. - - - NO_FAILURE: The last search was successful - - UNKNOWN: Undocumented failure reason - - TIMEOUT: Timeout - - MEMOUT_WATERMAK: Search hit a memory high-watermak limit - - CANCELED: External cancel flag was set - - NUM_CONFLICTS: Maximum number of conflicts was reached - - THEORY: Theory is incomplete - - QUANTIFIERS: Logical context contains universal quantifiers -*) -(** - {!ast_print_mode} - Z3 pretty printing modes (See {!set_ast_print_mode}). - - - PRINT_SMTLIB_FULL: Print AST nodes in SMTLIB verbose format. - - PRINT_LOW_LEVEL: Print AST nodes using a low-level format. - - PRINT_SMTLIB_COMPLIANT: Print AST nodes in SMTLIB 1.x compliant format. - - PRINT_SMTLIB2_COMPLIANT: Print AST nodes in SMTLIB 2.x compliant format. -*) -(** - Definitions for update_api.py - def_Type('CONFIG', 'config', 'Config') - def_Type('CONTEXT', 'context', 'ContextObj') - def_Type('AST', 'ast', 'Ast') - def_Type('APP', 'app', 'Ast') - def_Type('SORT', 'sort', 'Sort') - def_Type('FUNC_DECL', 'func_decl', 'FuncDecl') - def_Type('PATTERN', 'pattern', 'Pattern') - def_Type('MODEL', 'model', 'Model') - def_Type('LITERALS', 'literals', 'Literals') - def_Type('CONSTRUCTOR', 'constructor', 'Constructor') - def_Type('CONSTRUCTOR_LIST', 'constructor_list', 'ConstructorList') - def_Type('THEORY', 'theory', 'ctypes.c_void_p') - def_Type('THEORY_DATA', 'theory_data', 'ctypes.c_void_p') - def_Type('SOLVER', 'solver', 'SolverObj') - def_Type('GOAL', 'goal', 'GoalObj') - def_Type('TACTIC', 'tactic', 'TacticObj') - def_Type('PARAMS', 'params', 'Params') - def_Type('PROBE', 'probe', 'ProbeObj') - def_Type('STATS', 'stats', 'StatsObj') - def_Type('AST_VECTOR', 'ast_vector', 'AstVectorObj') - def_Type('AST_MAP', 'ast_map', 'AstMapObj') - def_Type('APPLY_RESULT', 'apply_result', 'ApplyResultObj') - def_Type('FUNC_INTERP', 'func_interp', 'FuncInterpObj') - def_Type('FUNC_ENTRY', 'func_entry', 'FuncEntryObj') - def_Type('FIXEDPOINT', 'fixedpoint', 'FixedpointObj') - def_Type('PARAM_DESCRS', 'param_descrs', 'ParamDescrs') -*) -(** - {2 {L Configuration}} -*) -(** - Summary: Set a global (or module) parameter. - This setting is shared by all Z3 contexts. - When a Z3 module is initialized it will use the value of these parameters - when params objects are not provided. - The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. - The character '.' is a delimiter (more later). - The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. - Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". - This function can be used to set parameters for a specific Z3 module. - This can be done by using .. - For example: - global_param_set('pp.decimal', 'true') - will set the parameter "decimal" in the module "pp" to true. - def_API('global_param_set', VOID, (_in(STRING), _in(STRING))) -*) -external global_param_set : string -> string -> unit - = "camlidl_z3V3_Z3_global_param_set" - -(** - Summary: Restore the value of all global (and module) parameters. - This command will not affect already created objects (such as tactics and solvers). - - {b See also}: {!global_param_set} - def_API('global_param_reset_all', VOID, ()) -*) -external global_param_reset_all : unit -> unit - = "camlidl_z3V3_Z3_global_param_reset_all" - -(** - Summary: Get a global (or module) parameter. - Returns [None] - if the parameter value does not exist. - - {b See also}: {!global_param_set} - The caller must invoke {!global_param_del_value} to delete the value returned at [param_value]. - - {b Remarks}: This function cannot be invoked simultaneously from different threads without synchronization. - The result string stored in param_value is stored in shared location. - def_API('global_param_get', BOOL, (_in(STRING), _out(STRING))) -*) -external global_param_get : string -> string option - = "camlidl_z3V3_Z3_global_param_get" - -(** - {2 {L Create configuration}} -*) -(** - Summary: Create a configuration object for the Z3 context object. - Configurations are created in order to assign parameters prior to creating - contexts for Z3 interaction. For example, if the users wishes to use proof - generation, then call: - [set_param_value cfg "proof" "true"] - - {b Remarks}: Consider using {!mk_context_x} instead of using - explicit configuration objects. The function {!mk_context_x} - receives an array of string pairs. This array represents the - configuration options. - - {b Remarks}: In previous versions of Z3, the [config] was used to store - global and module configurations. Now, we should use [global_param_set]. - The following parameters can be set: - - proof (Boolean) Enable proof generation - - debug_ref_count (Boolean) Enable debug support for ast reference counting - - trace (Boolean) Tracing support for VCC - - trace_file_name (String) Trace out file for VCC traces - - timeout (unsigned) default timeout (in milliseconds) used for solvers - - well_sorted_check type checker - - auto_config use heuristics to automatically select solver and configure it - - model model generation for solvers, this parameter can be overwritten when creating a solver - - model_validate validate models produced by solvers - - unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver - - {b See also}: {!set_param_value} - - {b See also}: {!del_config} - def_API('mk_config', CONFIG, ()) -*) -external mk_config : unit -> config - = "camlidl_z3V3_Z3_mk_config" - -(** - Summary: Delete the given configuration object. - - {b See also}: {!mk_config} - def_API('del_config', VOID, (_in(CONFIG),)) -*) -external del_config : config -> unit - = "camlidl_z3V3_Z3_del_config" - -(** - Summary: Set a configuration parameter. - The following parameters can be set for - - {b See also}: {!mk_config} - def_API('set_param_value', VOID, (_in(CONFIG), _in(STRING), _in(STRING))) -*) -external set_param_value : config -> string -> string -> unit - = "camlidl_z3V3_Z3_set_param_value" - -(** - {2 {L Create context}} -*) -(** - Summary: Create a context using the given configuration. - After a context is created, the configuration cannot be changed, - although some parameters can be changed using {!update_param_value}. - All main interaction with Z3 happens in the context of a [context]. - def_API('mk_context', CONTEXT, (_in(CONFIG),)) -*) -external mk_context : config -> context - = "camlidl_z3V3_Z3_mk_context" - -(** - Summary: Delete the given logical context. - - {b See also}: {!mk_context} - def_API('del_context', VOID, (_in(CONTEXT),)) -*) -external del_context : context -> unit - = "camlidl_z3V3_Z3_del_context" - -(** - Summary: Set a value of a context parameter. - - {b See also}: {!global_param_set} - def_API('update_param_value', VOID, (_in(CONTEXT), _in(STRING), _in(STRING))) -*) -external update_param_value : context -> string -> string -> unit - = "camlidl_z3V3_Z3_update_param_value" - -(** - Summary: Return the value of a context parameter. - - {b See also}: {!global_param_get} - def_API('get_param_value', BOOL, (_in(CONTEXT), _in(STRING), _out(STRING))) -*) -external get_param_value : context -> string -> string option - = "camlidl_z3V3_Z3_get_param_value" - -(** - {2 {L Symbols}} -*) -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Create a Z3 symbol using an integer. - Symbols are used to name several term and type constructors. - NB. Not all integers can be passed to this function. - The legal range of unsigned int integers is 0 to 2^30-1. - - {b See also}: {!mk_string_symbol} - def_API('mk_int_symbol', SYMBOL, (_in(CONTEXT), _in(INT))) -*) -external mk_int_symbol : context -> int -> symbol - = "camlidl_z3V3_Z3_mk_int_symbol" - -(** - Summary: Create a Z3 symbol using a C string. - Symbols are used to name several term and type constructors. - - {b See also}: {!mk_int_symbol} - def_API('mk_string_symbol', SYMBOL, (_in(CONTEXT), _in(STRING))) -*) -external mk_string_symbol : context -> string -> symbol - = "camlidl_z3V3_Z3_mk_string_symbol" - -(** - {2 {L Sorts}} -*) -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Create a free (uninterpreted) type using the given name (symbol). - Two free types are considered the same iff the have the same name. - def_API('mk_uninterpreted_sort', SORT, (_in(CONTEXT), _in(SYMBOL))) -*) -external mk_uninterpreted_sort : context -> symbol -> sort - = "camlidl_z3V3_Z3_mk_uninterpreted_sort" - -(** - Summary: Create the Boolean type. - This type is used to create propositional variables and predicates. - def_API('mk_bool_sort', SORT, (_in(CONTEXT), )) -*) -external mk_bool_sort : context -> sort - = "camlidl_z3V3_Z3_mk_bool_sort" - -(** - Summary: Create the integer type. - This type is not the int type found in programming languages. - A machine integer can be represented using bit-vectors. The function - {!mk_bv_sort} creates a bit-vector type. - - {b See also}: {!mk_bv_sort} - def_API('mk_int_sort', SORT, (_in(CONTEXT), )) -*) -external mk_int_sort : context -> sort - = "camlidl_z3V3_Z3_mk_int_sort" - -(** - Summary: Create the real type. - This type is not a floating point number. - Z3 does not have support for floating point numbers yet. - def_API('mk_real_sort', SORT, (_in(CONTEXT), )) -*) -external mk_real_sort : context -> sort - = "camlidl_z3V3_Z3_mk_real_sort" - -(** - Summary: Create a bit-vector type of the given size. - This type can also be seen as a machine integer. - - {b Remarks}: The size of the bitvector type must be greater than zero. - def_API('mk_bv_sort', SORT, (_in(CONTEXT), _in(UINT))) -*) -external mk_bv_sort : context -> int -> sort - = "camlidl_z3V3_Z3_mk_bv_sort" - -(** - Summary: Create a named finite domain sort. - To create constants that belong to the finite domain, - use the APIs for creating numerals and pass a numeric - constant together with the sort returned by this call. - - {b See also}: {!get_finite_domain_sort_size} - def_API('mk_finite_domain_sort', SORT, (_in(CONTEXT), _in(SYMBOL), _in(UINT64))) -*) -external mk_finite_domain_sort : context -> symbol -> int64 -> sort - = "camlidl_z3V3_Z3_mk_finite_domain_sort" - -(** - Summary: Create an array type. - We usually represent the array type as: {e [domain -> range] }. - Arrays are usually used to model the heap/memory in software verification. - - {b See also}: {!mk_select} - - {b See also}: {!mk_store} - def_API('mk_array_sort', SORT, (_in(CONTEXT), _in(SORT), _in(SORT))) -*) -external mk_array_sort : context -> sort -> sort -> sort - = "camlidl_z3V3_Z3_mk_array_sort" - -(** - Summary: Create a tuple type. - [mk_tuple_sort c name field_names field_sorts] creates a tuple with a constructor named [name], - a [n] fields, where [n] is the size of the arrays [field_names] and [field_sorts]. - @param c logical context - @param mk_tuple_name name of the constructor function associated with the tuple type. - @param num_fields number of fields in the tuple type. - @param field_names name of the projection functions. - @param field_sorts type of the tuple fields. - @param mk_tuple_decl output parameter that will contain the constructor declaration. - @param proj_decl output parameter that will contain the projection function declarations. This field must be a buffer of size [num_fields] allocated by the user. - def_API('mk_tuple_sort', SORT, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _out(FUNC_DECL), _out_array(2, FUNC_DECL))) -*) -external mk_tuple_sort : context -> symbol -> symbol array -> sort array -> sort * func_decl * func_decl array - = "camlidl_z3V3_Z3_mk_tuple_sort" - -(** - Summary: Create a enumeration sort. - [mk_enumeration_sort c enums] creates an enumeration sort with enumeration names [enums], - it also returns [n] predicates, where [n] is the number of [enums] corresponding - to testing whether an element is one of the enumerants. - @param c logical context - @param name name of the enumeration sort. - @param n number of elemenets in enumeration sort. - @param enum_names names of the enumerated elements. - @param enum_consts constants corresponding to the enumerated elements. - @param enum_testers predicates testing if terms of the enumeration sort correspond to an enumeration. - For example, if this function is called with three symbols A, B, C and the name S, then - [s] is a sort whose name is S, and the function returns three terms corresponding to A, B, C in - [enum_consts]. The array [enum_testers] has three predicates of type {e (s -> Bool) }. - The first predicate (corresponding to A) is true when applied to A, and false otherwise. - Similarly for the other predicates. - def_API('mk_enumeration_sort', SORT, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _in_array(2, SYMBOL), _out_array(2, FUNC_DECL), _out_array(2, FUNC_DECL))) -*) -external mk_enumeration_sort : context -> symbol -> symbol array -> sort * func_decl array * func_decl array - = "camlidl_z3V3_Z3_mk_enumeration_sort" - -(** - Summary: Create a list sort - [mk_list_sort c name elem_sort] creates a list sort of [name], over elements of sort [elem_sort]. - @param c logical context - @param name name of the list sort. - @param elem_sort sort of list elements. - @param nil_decl declaration for the empty list. - @param is_nil_decl test for the empty list. - @param cons_decl declaration for a cons cell. - @param is_cons_decl cons cell test. - @param head_decl list head. - @param tail_decl list tail. - def_API('mk_list_sort', SORT, (_in(CONTEXT), _in(SYMBOL), _in(SORT), _out(FUNC_DECL), _out(FUNC_DECL), _out(FUNC_DECL), _out(FUNC_DECL), _out(FUNC_DECL), _out(FUNC_DECL))) -*) -external mk_list_sort : context -> symbol -> sort -> sort * func_decl * func_decl * func_decl * func_decl * func_decl * func_decl - = "camlidl_z3V3_Z3_mk_list_sort" - -(** - Summary: Create a constructor. - @param c logical context. - @param name constructor name. - @param recognizer name of recognizer function. - @param num_fields number of fields in constructor. - @param field_names names of the constructor fields. - @param sorts field sorts, [None] - if the field sort refers to a recursive sort. - @param sort_refs reference to datatype sort that is an argument to the constructor; if the corresponding - sort reference is [None], - then the value in sort_refs should be an index referring to - one of the recursive datatypes that is declared. - def_API('mk_constructor', CONSTRUCTOR, (_in(CONTEXT), _in(SYMBOL), _in(SYMBOL), _in(UINT), _in_array(3, SYMBOL), _in_array(3, SORT), _in_array(3, UINT))) -*) -external mk_constructor : context -> symbol -> symbol -> symbol array -> sort array -> int array -> constructor - = "camlidl_z3V3_Z3_mk_constructor_bytecode" "camlidl_z3V3_Z3_mk_constructor" - -(** - Summary: Reclaim memory allocated to constructor. - @param c logical context. - @param constr constructor. - def_API('del_constructor', VOID, (_in(CONTEXT), _in(CONSTRUCTOR))) -*) -external del_constructor : context -> constructor -> unit - = "camlidl_z3V3_Z3_del_constructor" - -(** - Summary: Create datatype, such as lists, trees, records, enumerations or unions of records. - The datatype may be recursive. Return the datatype sort. - @param c logical context. - @param name name of datatype. - @param num_constructors number of constructors passed in. - @param constructors array of constructor containers. - def_API('mk_datatype', SORT, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _inout_array(2, CONSTRUCTOR))) -*) -external mk_datatype : context -> symbol -> constructor array -> sort * constructor array - = "camlidl_z3V3_Z3_mk_datatype" - -(** - Summary: Create list of constructors. - @param c logical context. - @param num_constructors number of constructors in list. - @param constructors list of constructors. - def_API('mk_constructor_list', CONSTRUCTOR_LIST, (_in(CONTEXT), _in(UINT), _in_array(1, CONSTRUCTOR))) -*) -external mk_constructor_list : context -> constructor array -> constructor_list - = "camlidl_z3V3_Z3_mk_constructor_list" - -(** - Summary: Reclaim memory allocated for constructor list. - Each constructor inside the constructor list must be independently reclaimed using {!del_constructor}. - @param c logical context. - @param clist constructor list container. - def_API('del_constructor_list', VOID, (_in(CONTEXT), _in(CONSTRUCTOR_LIST))) -*) -external del_constructor_list : context -> constructor_list -> unit - = "camlidl_z3V3_Z3_del_constructor_list" - -(** - Summary: Create mutually recursive datatypes. - @param c logical context. - @param num_sorts number of datatype sorts. - @param sort_names names of datatype sorts. - @param sorts array of datatype sorts. - @param constructor_lists list of constructors, one list per sort. - def_API('mk_datatypes', VOID, (_in(CONTEXT), _in(UINT), _in_array(1, SYMBOL), _out_array(1, SORT), _inout_array(1, CONSTRUCTOR_LIST))) -*) -external mk_datatypes : context -> symbol array -> constructor_list array -> sort array * constructor_list array - = "camlidl_z3V3_Z3_mk_datatypes" - -(** - Summary: Query constructor for declared functions. - @param c logical context. - @param constr constructor container. The container must have been passed in to a {!mk_datatype} call. - @param num_fields number of accessor fields in the constructor. - @param constructor constructor function declaration. - @param tester constructor test function declaration. - @param accessors array of accessor function declarations. - def_API('query_constructor', VOID, (_in(CONTEXT), _in(CONSTRUCTOR), _in(UINT), _out(FUNC_DECL), _out(FUNC_DECL), _out_array(2, FUNC_DECL))) -*) -external query_constructor : context -> constructor -> int -> func_decl * func_decl * func_decl array - = "camlidl_z3V3_Z3_query_constructor" - -(** - {2 {L Constants and Applications}} -*) -(** - Summary: Declare a constant or function. - [mk_func_decl c n d r] creates a function with name [n], domain [d], and range [r]. - The arity of the function is the size of the array [d]. - @param c logical context. - @param s name of the constant or function. - @param domain_size number of arguments. It is 0 when declaring a constant. - @param domain array containing the sort of each argument. The array must contain domain_size elements. It is 0 when declaring a constant. - @param range sort of the constant or the return sort of the function. - After declaring a constant or function, the function - {!mk_app} can be used to create a constant or function - application. - - {b See also}: {!mk_app} - def_API('mk_func_decl', FUNC_DECL, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _in_array(2, SORT), _in(SORT))) -*) -external mk_func_decl : context -> symbol -> sort array -> sort -> func_decl - = "camlidl_z3V3_Z3_mk_func_decl" - -(** - Summary: Create a constant or function application. - - {b See also}: {!mk_func_decl} - def_API('mk_app', AST, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT), _in_array(2, AST))) -*) -external mk_app : context -> func_decl -> ast array -> ast - = "camlidl_z3V3_Z3_mk_app" - -(** - Summary: Declare and create a constant. - [mk_const c s t] is a shorthand for [mk_app c (mk_func_decl c s [||] t) [||]] - - {b See also}: {!mk_func_decl} - - {b See also}: {!mk_app} - def_API('mk_const', AST, (_in(CONTEXT), _in(SYMBOL), _in(SORT))) -*) -external mk_const : context -> symbol -> sort -> ast - = "camlidl_z3V3_Z3_mk_const" - -(** - Summary: Declare a fresh constant or function. - Z3 will generate an unique name for this function declaration. - - {b See also}: {!mk_func_decl} - def_API('mk_fresh_func_decl', FUNC_DECL, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SORT), _in(SORT))) -*) -external mk_fresh_func_decl : context -> string -> sort array -> sort -> func_decl - = "camlidl_z3V3_Z3_mk_fresh_func_decl" - -(** - Summary: Declare and create a fresh constant. - [mk_fresh_const c p t] is a shorthand for [mk_app c (mk_fresh_func_decl c p [||] t) [||]]. - - {b See also}: {!mk_func_decl} - - {b See also}: {!mk_app} - def_API('mk_fresh_const', AST, (_in(CONTEXT), _in(STRING), _in(SORT))) -*) -external mk_fresh_const : context -> string -> sort -> ast - = "camlidl_z3V3_Z3_mk_fresh_const" - -(** - {2 {L Propositional Logic and Equality}} -*) -(** - Summary: Create an AST node representing [true]. - def_API('mk_true', AST, (_in(CONTEXT), )) -*) -external mk_true : context -> ast - = "camlidl_z3V3_Z3_mk_true" - -(** - Summary: Create an AST node representing [false]. - def_API('mk_false', AST, (_in(CONTEXT), )) -*) -external mk_false : context -> ast - = "camlidl_z3V3_Z3_mk_false" - -(** - Summary: \[ [ mk_eq c l r ] \] - Create an AST node representing {e l = r }. - The nodes [l] and [r] must have the same type. - def_API('mk_eq', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_eq : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_eq" - -(** - Summary: \[ [mk_distinct c [| t_1; ...; t_n |]] \] Create an AST - node represeting a distinct construct. It is used for declaring - the arguments t_i pairwise distinct. - The [distinct] construct is used for declaring the arguments pairwise distinct. - That is, {e Forall 0 <= i < j < num_args. not args[i] = args[j] }. - All arguments must have the same sort. - - {b Remarks}: The number of arguments of a distinct construct must be greater than one. - def_API('mk_distinct', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_distinct : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_distinct" - -(** - Summary: \[ [ mk_not c a ] \] - Create an AST node representing {e not(a) }. - The node [a] must have Boolean sort. - def_API('mk_not', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_not : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_not" - -(** - Summary: \[ [ mk_ite c t1 t2 t2 ] \] - Create an AST node representing an if-then-else: {e ite(t1, t2, - t3) }. - The node [t1] must have Boolean sort, [t2] and [t3] must have the same sort. - The sort of the new node is equal to the sort of [t2] and [t3]. - def_API('mk_ite', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(AST))) -*) -external mk_ite : context -> ast -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_ite" - -(** - Summary: \[ [ mk_iff c t1 t2 ] \] - Create an AST node representing {e t1 iff t2 }. - The nodes [t1] and [t2] must have Boolean sort. - def_API('mk_iff', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_iff : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_iff" - -(** - Summary: \[ [ mk_implies c t1 t2 ] \] - Create an AST node representing {e t1 implies t2 }. - The nodes [t1] and [t2] must have Boolean sort. - def_API('mk_implies', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_implies : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_implies" - -(** - Summary: \[ [ mk_xor c t1 t2 ] \] - Create an AST node representing {e t1 xor t2 }. - The nodes [t1] and [t2] must have Boolean sort. - def_API('mk_xor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_xor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_xor" - -(** - Summary: \[ [mk_and c [| t_1; ...; t_n |]] \] Create the conjunction: {e t_1 and ... and t_n}. - All arguments must have Boolean sort. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_and', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_and : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_and" - -(** - Summary: \[ [mk_or c [| t_1; ...; t_n |]] \] Create the disjunction: {e t_1 or ... or t_n}. - All arguments must have Boolean sort. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_or', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_or : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_or" - -(** - {2 {L Arithmetic: Integers and Reals}} -*) -(** - Summary: \[ [mk_add c [| t_1; ...; t_n |]] \] Create the term: {e t_1 + ... + t_n}. - All arguments must have int or real sort. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_add', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_add : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_add" - -(** - Summary: \[ [mk_mul c [| t_1; ...; t_n |]] \] Create the term: {e t_1 * ... * t_n}. - All arguments must have int or real sort. - - {b Remarks}: Z3 has limited support for non-linear arithmetic. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_mul', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_mul : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_mul" - -(** - Summary: \[ [mk_sub c [| t_1; ...; t_n |]] \] Create the term: {e t_1 - ... - t_n}. - All arguments must have int or real sort. - - {b Remarks}: The number of arguments must be greater than zero. - def_API('mk_sub', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_sub : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_sub" - -(** - Summary: \[ [mk_unary_minus c arg] \] Create the term: {e - arg}. - The arguments must have int or real type. - def_API('mk_unary_minus', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_unary_minus : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_unary_minus" - -(** - Summary: \[ [mk_div c t_1 t_2] \] Create the term: {e t_1 div t_2}. - The arguments must either both have int type or both have real type. - If the arguments have int type, then the result type is an int type, otherwise the - the result type is real. - def_API('mk_div', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_div : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_div" - -(** - Summary: \[ [mk_mod c t_1 t_2] \] Create the term: {e t_1 mod t_2}. - The arguments must have int type. - def_API('mk_mod', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_mod : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_mod" - -(** - Summary: \[ [mk_rem c t_1 t_2] \] Create the term: {e t_1 rem t_2}. - The arguments must have int type. - def_API('mk_rem', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_rem : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_rem" - -(** - The arguments must have int or real type. - def_API('mk_power', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_power : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_power" - -(** - Summary: \[ [ mk_lt c t1 t2 ] \] - Create less than. - The nodes [t1] and [t2] must have the same sort, and must be int or real. - def_API('mk_lt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_lt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_lt" - -(** - Summary: \[ [ mk_le c t1 t2 ] \] - Create less than or equal to. - The nodes [t1] and [t2] must have the same sort, and must be int or real. - def_API('mk_le', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_le : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_le" - -(** - Summary: \[ [ mk_gt c t1 t2 ] \] - Create greater than. - The nodes [t1] and [t2] must have the same sort, and must be int or real. - def_API('mk_gt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_gt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_gt" - -(** - Summary: \[ [ mk_ge c t1 t2 ] \] - Create greater than or equal to. - The nodes [t1] and [t2] must have the same sort, and must be int or real. - def_API('mk_ge', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_ge : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_ge" - -(** - Summary: \[ [ mk_int2real c t1 ] \] - 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 constant [k] and - and asserting {e mk_int2real(k) <= t1 < mk_int2real(k)+1 }. - The node [t1] must have sort integer. - - {b See also}: {!mk_real2int} - - {b See also}: {!mk_is_int} - def_API('mk_int2real', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_int2real : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_int2real" - -(** - Summary: \[ [ mk_real2int c t1 ] \] - Coerce a real to an integer. - The semantics of this function follows the SMT-LIB standard - for the function to_int - - {b See also}: {!mk_int2real} - - {b See also}: {!mk_is_int} - def_API('mk_real2int', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_real2int : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_real2int" - -(** - Summary: \[ [ mk_is_int c t1 ] \] - Check if a real number is an integer. - - {b See also}: {!mk_int2real} - - {b See also}: {!mk_real2int} - def_API('mk_is_int', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_is_int : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_is_int" - -(** - {2 {L Bit-vectors}} -*) -(** - Summary: \[ [ mk_bvnot c t1 ] \] - Bitwise negation. - The node [t1] must have a bit-vector sort. - def_API('mk_bvnot', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvnot : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvnot" - -(** - Summary: \[ [ mk_bvredand c t1 ] \] - Take conjunction of bits in vector, return vector of length 1. - The node [t1] must have a bit-vector sort. - def_API('mk_bvredand', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvredand : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvredand" - -(** - Summary: \[ [ mk_bvredor c t1 ] \] - Take disjunction of bits in vector, return vector of length 1. - The node [t1] must have a bit-vector sort. - def_API('mk_bvredor', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvredor : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvredor" - -(** - Summary: \[ [ mk_bvand c t1 t2 ] \] - Bitwise and. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvand', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvand : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvand" - -(** - Summary: \[ [ mk_bvor c t1 t2 ] \] - Bitwise or. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvor" - -(** - Summary: \[ [ mk_bvxor c t1 t2 ] \] - Bitwise exclusive-or. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvxor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvxor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvxor" - -(** - Summary: \[ [ mk_bvnand c t1 t2 ] \] - Bitwise nand. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvnand', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvnand : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvnand" - -(** - Summary: \[ [ mk_bvnor c t1 t2 ] \] - Bitwise nor. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvnor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvnor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvnor" - -(** - Summary: \[ [ mk_bvxnor c t1 t2 ] \] - Bitwise xnor. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvxnor', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvxnor : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvxnor" - -(** - Summary: \[ [ mk_bvneg c t1 ] \] - Standard two's complement unary minus. - The node [t1] must have bit-vector sort. - def_API('mk_bvneg', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvneg : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvneg" - -(** - Summary: \[ [ mk_bvadd c t1 t2 ] \] - Standard two's complement addition. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvadd', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvadd : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvadd" - -(** - Summary: \[ [ mk_bvsub c t1 t2 ] \] - Standard two's complement subtraction. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsub', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsub : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsub" - -(** - Summary: \[ [ mk_bvmul c t1 t2 ] \] - Standard two's complement multiplication. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvmul', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvmul : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvmul" - -(** - Summary: \[ [ mk_bvudiv c t1 t2 ] \] - Unsigned division. - It is defined as the [floor] of {e t1/t2 } if [t2] is - different from zero. If {e t2 } is zero, then the result - is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvudiv', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvudiv : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvudiv" - -(** - Summary: \[ [ mk_bvsdiv c t1 t2 ] \] - Two's complement signed division. - It is defined in the following way: - - The [floor] of {e t1/t2 } if [t2] is different from zero, and {e t1*t2 >= 0 }. - - The [ceiling] of {e t1/t2 } if [t2] is different from zero, and {e t1*t2 < 0 }. - If {e t2 } is zero, then the result is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsdiv', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsdiv : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsdiv" - -(** - Summary: \[ [ mk_bvurem c t1 t2 ] \] - Unsigned remainder. - It is defined as {e t1 - (t1 /u t2) * t2 }, where {e /u } represents unsigned int division. - If {e t2 } is zero, then the result is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvurem', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvurem : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvurem" - -(** - Summary: \[ [ mk_bvsrem c t1 t2 ] \] - Two's complement signed remainder (sign follows dividend). - It is defined as {e t1 - (t1 /s t2) * t2 }, where {e /s } represents signed division. - The most significant bit (sign) of the result is equal to the most significant bit of [t1]. - If {e t2 } is zero, then the result is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - - {b See also}: {!mk_bvsmod} - def_API('mk_bvsrem', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsrem : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsrem" - -(** - Summary: \[ [ mk_bvsmod c t1 t2 ] \] - Two's complement signed remainder (sign follows divisor). - If {e t2 } is zero, then the result is undefined. - The nodes [t1] and [t2] must have the same bit-vector sort. - - {b See also}: {!mk_bvsrem} - def_API('mk_bvsmod', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsmod : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsmod" - -(** - Summary: \[ [ mk_bvult c t1 t2 ] \] - Unsigned less than. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvult', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvult : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvult" - -(** - Summary: \[ [ mk_bvslt c t1 t2 ] \] - Two's complement signed less than. - It abbreviates: - {v - (or (and (= (extract[|m-1|:|m-1|] t1) bit1) - (= (extract[|m-1|:|m-1|] t2) bit0)) - (and (= (extract[|m-1|:|m-1|] t1) (extract[|m-1|:|m-1|] t2)) - (bvult t1 t2))) - v} - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvslt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvslt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvslt" - -(** - Summary: \[ [ mk_bvule c t1 t2 ] \] - Unsigned less than or equal to. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvule', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvule : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvule" - -(** - Summary: \[ [ mk_bvsle c t1 t2 ] \] - Two's complement signed less than or equal to. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsle', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsle : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsle" - -(** - Summary: \[ [ mk_bvuge c t1 t2 ] \] - Unsigned greater than or equal to. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvuge', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvuge : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvuge" - -(** - Summary: \[ [ mk_bvsge c t1 t2 ] \] - Two's complement signed greater than or equal to. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsge', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsge : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsge" - -(** - Summary: \[ [ mk_bvugt c t1 t2 ] \] - Unsigned greater than. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvugt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvugt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvugt" - -(** - Summary: \[ [ mk_bvsgt c t1 t2 ] \] - Two's complement signed greater than. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsgt', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsgt : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsgt" - -(** - Summary: \[ [ mk_concat c t1 t2 ] \] - Concatenate the given bit-vectors. - The nodes [t1] and [t2] must have (possibly different) bit-vector sorts - The result is a bit-vector of size {e n1+n2 }, where [n1] ([n2)] is the size - of [t1] ([t2)]. - def_API('mk_concat', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_concat : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_concat" - -(** - Summary: \[ [ mk_extract c high low t1 ] \] - Extract the bits [high] down to [low] from a bitvector of - size [m] to yield a new bitvector of size [n], where {e n = - high - low + 1 }. - The node [t1] must have a bit-vector sort. - def_API('mk_extract', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in(AST))) -*) -external mk_extract : context -> int -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_extract" - -(** - Summary: \[ [ mk_sign_ext c i t1 ] \] - Sign-extend of the given bit-vector to the (signed) equivalent bitvector of - size {e m+i }, where [m] is the size of the given - bit-vector. - The node [t1] must have a bit-vector sort. - def_API('mk_sign_ext', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_sign_ext : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_sign_ext" - -(** - Summary: \[ [ mk_zero_ext c i t1 ] \] - Extend the given bit-vector with zeros to the (unsigned) equivalent - bitvector of size {e m+i }, where [m] is the size of the - given bit-vector. - The node [t1] must have a bit-vector sort. - def_API('mk_zero_ext', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_zero_ext : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_zero_ext" - -(** - Summary: \[ [ mk_repeat c i t1 ] \] - Repeat the given bit-vector up length {e i }. - The node [t1] must have a bit-vector sort. - def_API('mk_repeat', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_repeat : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_repeat" - -(** - Summary: \[ [ mk_bvshl c t1 t2 ] \] - Shift left. - It is equivalent to multiplication by {e 2^x } where [x] is the value of the - third 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 nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvshl', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvshl : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvshl" - -(** - Summary: \[ [ mk_bvlshr c t1 t2 ] \] - Logical shift right. - It is equivalent to unsigned int division by {e 2^x } where [x] is the - value of the third 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 nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvlshr', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvlshr : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvlshr" - -(** - Summary: \[ [ mk_bvashr c t1 t2 ] \] - 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. - 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 nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvashr', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvashr : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvashr" - -(** - Summary: \[ [ mk_rotate_left c i t1 ] \] - Rotate bits of [t1] to the left [i] times. - The node [t1] must have a bit-vector sort. - def_API('mk_rotate_left', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_rotate_left : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_rotate_left" - -(** - Summary: \[ [ mk_rotate_right c i t1 ] \] - Rotate bits of [t1] to the right [i] times. - The node [t1] must have a bit-vector sort. - def_API('mk_rotate_right', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_rotate_right : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_rotate_right" - -(** - Summary: \[ [ mk_ext_rotate_left c t1 t2 ] \] - Rotate bits of [t1] to the left [t2] times. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_ext_rotate_left', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_ext_rotate_left : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_ext_rotate_left" - -(** - Summary: \[ [ mk_ext_rotate_right c t1 t2 ] \] - Rotate bits of [t1] to the right [t2] times. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_ext_rotate_right', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_ext_rotate_right : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_ext_rotate_right" - -(** - Summary: \[ [ mk_int2bv c n t1 ] \] - Create an [n] bit bit-vector from the integer argument [t1]. - NB. This function is essentially treated as uninterpreted. + (** Create an n-bit bit-vector from an 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 node [t1] must have integer sort. - def_API('mk_int2bv', AST, (_in(CONTEXT), _in(UINT), _in(AST))) -*) -external mk_int2bv : context -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_int2bv" - -(** - Summary: \[ [ mk_bv2int c t1 is_signed ] \] - Create an integer from the bit-vector argument [t1]. - If [is_signed] is false, then the bit-vector [t1] is treated as unsigned int. - So the result is non-negative - and in the range {e [0..2^N-1] }, where N are the number of bits in [t1]. - If [is_signed] is true, [t1] is treated as a signed bit-vector. - 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 node [t1] must have a bit-vector sort. - def_API('mk_bv2int', AST, (_in(CONTEXT), _in(AST), _in(BOOL))) -*) -external mk_bv2int : context -> ast -> bool -> ast - = "camlidl_z3V3_Z3_mk_bv2int" - -(** - Summary: \[ [ mk_bvadd_no_overflow c t1 t2 is_signed ] \] - Create a predicate that checks that the bit-wise addition - of [t1] and [t2] does not overflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvadd_no_overflow', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(BOOL))) -*) -external mk_bvadd_no_overflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3V3_Z3_mk_bvadd_no_overflow" - -(** - Summary: \[ [ mk_bvadd_no_underflow c t1 t2 ] \] - Create a predicate that checks that the bit-wise signed addition - of [t1] and [t2] does not underflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvadd_no_underflow', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvadd_no_underflow : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvadd_no_underflow" - -(** - Summary: \[ [ mk_bvsub_no_overflow c t1 t2 ] \] - Create a predicate that checks that the bit-wise signed subtraction - of [t1] and [t2] does not overflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsub_no_overflow', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsub_no_overflow : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsub_no_overflow" - -(** - Summary: \[ [ mk_bvsub_no_underflow c t1 t2 is_signed ] \] - Create a predicate that checks that the bit-wise subtraction - of [t1] and [t2] does not underflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsub_no_underflow', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(BOOL))) -*) -external mk_bvsub_no_underflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3V3_Z3_mk_bvsub_no_underflow" - -(** - Summary: \[ [ mk_bvsdiv_no_overflow c t1 t2 ] \] - Create a predicate that checks that the bit-wise signed division - of [t1] and [t2] does not overflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvsdiv_no_overflow', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvsdiv_no_overflow : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvsdiv_no_overflow" - -(** - Summary: \[ [ mk_bvneg_no_overflow c t1 ] \] - Check that bit-wise negation does not overflow when - [t1] is interpreted as a signed bit-vector. - The node [t1] must have bit-vector sort. - def_API('mk_bvneg_no_overflow', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_bvneg_no_overflow : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvneg_no_overflow" - -(** - Summary: \[ [ mk_bvmul_no_overflow c t1 t2 is_signed ] \] - Create a predicate that checks that the bit-wise multiplication - of [t1] and [t2] does not overflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvmul_no_overflow', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(BOOL))) -*) -external mk_bvmul_no_overflow : context -> ast -> ast -> bool -> ast - = "camlidl_z3V3_Z3_mk_bvmul_no_overflow" - -(** - Summary: \[ [ mk_bvmul_no_underflow c t1 t2 ] \] - Create a predicate that checks that the bit-wise signed multiplication - of [t1] and [t2] does not underflow. - The nodes [t1] and [t2] must have the same bit-vector sort. - def_API('mk_bvmul_no_underflow', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_bvmul_no_underflow : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_bvmul_no_underflow" + + The argument must be of integer sort. *) + val mk_int2bv : context -> int -> Expr.expr -> Expr.expr + end + + (** Real Arithmetic *) + module Real : + sig + (** Create a real sort. *) + val mk_sort : context -> Sort.sort + + (** The numerator of a rational numeral. *) + val get_numerator : Expr.expr-> Expr.expr + + (** The denominator of a rational numeral. *) + val get_denominator : Expr.expr-> Expr.expr + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as indicated by the int argument.*) + val to_decimal_string : Expr.expr-> int -> string + + (** Returns a string representation of the numeral. *) + val to_string : Expr.expr-> string + + (** Creates a real constant. *) + val mk_const : context -> Symbol.symbol -> Expr.expr -(** - {2 {L Arrays}} -*) -(** - Summary: \[ [ mk_select c a i ] \] - 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 {e [domain -> range] }, - and [i] must have the sort [domain]. - The sort of the result is [range]. - - {b See also}: {!mk_array_sort} - - {b See also}: {!mk_store} - def_API('mk_select', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_select : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_select" - -(** - Summary: \[ [ mk_store c a i v ] \] - Array update. - The node [a] must have an array sort {e [domain -> range] }, [i] must have sort [domain], - [v] must have sort range. The sort of the result is {e [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). - - {b See also}: {!mk_array_sort} - - {b See also}: {!mk_select} - def_API('mk_store', AST, (_in(CONTEXT), _in(AST), _in(AST), _in(AST))) -*) -external mk_store : context -> ast -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_store" - -(** - Summary: Create the constant array. - The resulting term is an array, such that a [select] on an arbitrary index - produces the value [v]. - @param c logical context. - @param domain domain sort for the array. - @param v value that the array maps to. - def_API('mk_const_array', AST, (_in(CONTEXT), _in(SORT), _in(AST))) -*) -external mk_const_array : context -> sort -> ast -> ast - = "camlidl_z3V3_Z3_mk_const_array" - -(** - Summary: \[ [ mk_map f n args ] \] - map f on the the argument arrays. - The [n] nodes [args] must be of array sorts {e [domain_i -> range_i] }. - The function declaration [f] must have type {e range_1 .. range_n -> range }. - [v] must have sort range. The sort of the result is {e [domain_i -> range] }. - - {b See also}: {!mk_array_sort} - - {b See also}: {!mk_store} - - {b See also}: {!mk_select} - def_API('mk_map', AST, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT), _in_array(2, AST))) -*) -external mk_map : context -> func_decl -> int -> ast -> ast - = "camlidl_z3V3_Z3_mk_map" - -(** - Summary: Access the array default value. - Produces the default range value, for arrays that can be represented as - finite maps with a default range value. - @param c logical context. - @param array array value whose default range value is accessed. - def_API('mk_array_default', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_array_default : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_array_default" + (** Creates a real constant. *) + val mk_const_s : context -> string -> Expr.expr -(** - {2 {L Sets}} -*) -(** - Summary: Create Set type. - def_API('mk_set_sort', SORT, (_in(CONTEXT), _in(SORT))) -*) -external mk_set_sort : context -> sort -> sort - = "camlidl_z3V3_Z3_mk_set_sort" + (** Create a real numeral from a fraction. + @return A Term with rational value and sort Real + {!mk_numeral_s} *) + val mk_numeral_nd : context -> int -> int -> Expr.expr -(** - Summary: Create the empty set. - def_API('mk_empty_set', AST, (_in(CONTEXT), _in(SORT))) -*) -external mk_empty_set : context -> sort -> ast - = "camlidl_z3V3_Z3_mk_empty_set" + (** Create a real numeral. + @return A Term with the given value and sort Real *) + val mk_numeral_s : context -> string -> Expr.expr -(** - Summary: Create the full set. - def_API('mk_full_set', AST, (_in(CONTEXT), _in(SORT))) -*) -external mk_full_set : context -> sort -> ast - = "camlidl_z3V3_Z3_mk_full_set" + (** Create a real numeral. + @return A Term with the given value and sort Real *) + val mk_numeral_i : context -> int -> Expr.expr -(** - Summary: Add an element to a set. - The first argument must be a set, the second an element. - def_API('mk_set_add', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_add : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_add" + (** Creates an expression that checks whether a real number is an integer. *) + val mk_is_integer : context -> Expr.expr -> Expr.expr -(** - Summary: Remove an element to a set. - The first argument must be a set, the second an element. - def_API('mk_set_del', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_del : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_del" + (** Coerce a real to an integer. -(** - Summary: Take the union of a list of sets. - def_API('mk_set_union', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_set_union : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_set_union" + The semantics of this function follows the SMT-LIB standard for the function to_int. + The argument must be of real sort. *) + val mk_real2int : context -> Expr.expr -> Expr.expr + + (** Algebraic Numbers *) + module AlgebraicNumber : + sig + (** Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) + val to_upper : Expr.expr -> int -> Expr.expr + + (** Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) + val to_lower : Expr.expr -> int -> Expr.expr + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as the int argument provided.*) + val to_decimal_string : Expr.expr -> int -> string + + (** Returns a string representation of the numeral. *) + val to_string : Expr.expr -> string + end + end -(** - Summary: Take the intersection of a list of sets. - def_API('mk_set_intersect', AST, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_set_intersect : context -> ast array -> ast - = "camlidl_z3V3_Z3_mk_set_intersect" + (** Indicates whether the term is of integer sort. *) + val is_int : Expr.expr -> bool -(** - Summary: Take the set difference between two sets. - def_API('mk_set_difference', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_difference : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_difference" + (** Indicates whether the term is an arithmetic numeral. *) + val is_arithmetic_numeral : Expr.expr -> bool -(** - Summary: Take the complement of a set. - def_API('mk_set_complement', AST, (_in(CONTEXT), _in(AST))) -*) -external mk_set_complement : context -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_complement" + (** Indicates whether the term is a less-than-or-equal *) + val is_le : Expr.expr -> bool -(** - Summary: Check for set membership. - The first argument should be an element type of the set. - def_API('mk_set_member', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_member : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_member" + (** Indicates whether the term is a greater-than-or-equal *) + val is_ge : Expr.expr -> bool -(** - Summary: Check for subsetness of sets. - def_API('mk_set_subset', AST, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external mk_set_subset : context -> ast -> ast -> ast - = "camlidl_z3V3_Z3_mk_set_subset" + (** Indicates whether the term is a less-than *) + val is_lt : Expr.expr -> bool -(** - {2 {L Numerals}} -*) -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Create a numeral of a given sort. - @param c logical context. - @param numeral A string representing the numeral value in decimal notation. If the given sort is a real, then the numeral can be a rational, that is, a string of the form {e [num]* / [num]* }. - @param ty The sort of the numeral. In the current implementation, the given sort can be an int, real, finite-domain, or bit-vectors of arbitrary size. - - {b See also}: {!mk_int} - def_API('mk_numeral', AST, (_in(CONTEXT), _in(STRING), _in(SORT))) -*) -external mk_numeral : context -> string -> sort -> ast - = "camlidl_z3V3_Z3_mk_numeral" - -(** - Summary: Create a real from a fraction. - @param c logical context. - @param num numerator of rational. - @param den denomerator of rational. - - {b Precondition}: den != 0 - - {b See also}: {!mk_numeral} - - {b See also}: {!mk_int} - def_API('mk_real', AST, (_in(CONTEXT), _in(INT), _in(INT))) -*) -external mk_real : context -> int -> int -> ast - = "camlidl_z3V3_Z3_mk_real" - -(** - Summary: Create a numeral of an int, bit-vector, or finite-domain sort. - This function can be use to create numerals that fit in a machine integer. - It is slightly faster than {!mk_numeral} since it is not necessary to parse a string. - - {b See also}: {!mk_numeral} - def_API('mk_int', AST, (_in(CONTEXT), _in(INT), _in(SORT))) -*) -external mk_int : context -> int -> sort -> ast - = "camlidl_z3V3_Z3_mk_int" - -(** - Summary: Create a numeral of a int, bit-vector, or finite-domain sort. - This function can be use to create numerals that fit in a machine long long integer. - It is slightly faster than {!mk_numeral} since it is not necessary to parse a string. - - {b See also}: {!mk_numeral} - def_API('mk_int64', AST, (_in(CONTEXT), _in(INT64), _in(SORT))) -*) -external mk_int64 : context -> int64 -> sort -> ast - = "camlidl_z3V3_Z3_mk_int64" + (** Indicates whether the term is a greater-than *) + val is_gt : Expr.expr -> bool -(** - {2 {L Quantifiers}} -*) -(** - Summary: Create a pattern for quantifier instantiation. - Z3 uses pattern matching to instantiate quantifiers. If a - pattern is not provided for a quantifier, then Z3 will - automatically compute a set of patterns for it. However, for - optimal performance, the user should provide the patterns. - Patterns comprise a list of terms. The list should be - non-empty. If the list comprises of more than one term, it is - a called a multi-pattern. - In general, one can pass in a list of (multi-)patterns in the - quantifier constructor. - - {b See also}: {!mk_forall} - - {b See also}: {!mk_exists} - def_API('mk_pattern', PATTERN, (_in(CONTEXT), _in(UINT), _in_array(1, AST))) -*) -external mk_pattern : context -> ast array -> pattern - = "camlidl_z3V3_Z3_mk_pattern" - -(** - Summary: Create 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. - {v - 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)) - v} - 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. - @param c logical context - @param index de-Bruijn index - @param ty sort of the bound variable - - {b See also}: {!mk_forall} - - {b See also}: {!mk_exists} - def_API('mk_bound', AST, (_in(CONTEXT), _in(UINT), _in(SORT))) -*) -external mk_bound : context -> int -> sort -> ast - = "camlidl_z3V3_Z3_mk_bound" - -(** - Summary: Create a forall formula. It takes an expression [body] that contains bound variables - of the same sorts as the sorts listed in the array [sorts]. The bound variables are de-Bruijn indices created - using {!mk_bound}. The array [decl_names] contains the names that the quantified formula uses for the - bound variables. Z3 applies the convention that the last element in the [decl_names] and [sorts] array - refers to the variable with index 0, the second to last element of [decl_names] and [sorts] refers - to the variable with index 1, etc. - [mk_forall c w p t n b] creates a forall formula, where - [w] is the weight, [p] is an array of patterns, [t] is an array - with the sorts of the bound variables, [n] is an array with the - 'names' of the bound variables, and [b] is the body of the - quantifier. Quantifiers are associated with weights indicating - the importance of using the quantifier during - instantiation. - @param c logical context. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param num_decls number of variables to be bound. - @param sorts the sorts of the bound variables. - @param decl_names names of the bound variables - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_bound} - - {b See also}: {!mk_exists} - def_API('mk_forall', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in_array(2, PATTERN), _in(UINT), _in_array(4, SORT), _in_array(4, SYMBOL), _in(AST))) -*) -external mk_forall : context -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3V3_Z3_mk_forall_bytecode" "camlidl_z3V3_Z3_mk_forall" - -(** - Summary: Create an exists formula. Similar to {!mk_forall}. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_bound} - - {b See also}: {!mk_forall} - - {b See also}: {!mk_quantifier} - def_API('mk_exists', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in_array(2, PATTERN), _in(UINT), _in_array(4, SORT), _in_array(4, SYMBOL), _in(AST))) -*) -external mk_exists : context -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3V3_Z3_mk_exists_bytecode" "camlidl_z3V3_Z3_mk_exists" - -(** - Summary: Create a quantifier - universal or existential, with pattern hints. - See the documentation for {!mk_forall} for an explanation of the parameters. - @param c logical context. - @param is_forall flag to indicate if this is a universal or existential quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param num_decls number of variables to be bound. - @param sorts array of sorts of the bound variables. - @param decl_names names of the bound variables. - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_bound} - - {b See also}: {!mk_forall} - - {b See also}: {!mk_exists} - def_API('mk_quantifier', AST, (_in(CONTEXT), _in(BOOL), _in(UINT), _in(UINT), _in_array(3, PATTERN), _in(UINT), _in_array(5, SORT), _in_array(5, SYMBOL), _in(AST))) -*) -external mk_quantifier : context -> bool -> int -> pattern array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3V3_Z3_mk_quantifier_bytecode" "camlidl_z3V3_Z3_mk_quantifier" - -(** - Summary: Create a quantifier - universal or existential, with pattern hints, no patterns, and attributes - @param c logical context. - @param is_forall flag to indicate if this is a universal or existential quantifier. - @param quantifier_id identifier to identify quantifier - @param skolem_id identifier to identify skolem constants introduced by quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param num_no_patterns number of no_patterns. - @param no_patterns array containing subexpressions to be excluded from inferred patterns. - @param num_decls number of variables to be bound. - @param sorts array of sorts of the bound variables. - @param decl_names names of the bound variables. - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_bound} - - {b See also}: {!mk_forall} - - {b See also}: {!mk_exists} - def_API('mk_quantifier_ex', AST, (_in(CONTEXT), _in(BOOL), _in(UINT), _in(SYMBOL), _in(SYMBOL), _in(UINT), _in_array(5, PATTERN), _in(UINT), _in_array(7, AST), _in(UINT), _in_array(9, SORT), _in_array(9, SYMBOL), _in(AST))) -*) -external mk_quantifier_ex : context -> bool -> int -> symbol -> symbol -> pattern array -> ast array -> sort array -> symbol array -> ast -> ast - = "camlidl_z3V3_Z3_mk_quantifier_ex_bytecode" "camlidl_z3V3_Z3_mk_quantifier_ex" - -(** - Summary: Create a universal quantifier using a list of constants that - will form the set of bound variables. - @param c logical context. - @param weight quantifiers are associated with weights indicating the importance of using - the quantifier during instantiation. By default, pass the weight 0. - @param num_bound number of constants to be abstracted into bound variables. - @param bound array of constants to be abstracted into bound variables. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_exists_const} - def_API('mk_forall_const', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in_array(2, APP), _in(UINT), _in_array(4, PATTERN), _in(AST))) -*) -external mk_forall_const : context -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3V3_Z3_mk_forall_const" - -(** - Summary: Similar to {!mk_forall_const}. - Summary: Create an existential quantifier using a list of constants that - will form the set of bound variables. - @param c logical context. - @param weight quantifiers are associated with weights indicating the importance of using - the quantifier during instantiation. By default, pass the weight 0. - @param num_bound number of constants to be abstracted into bound variables. - @param bound array of constants to be abstracted into bound variables. - @param num_patterns number of patterns. - @param patterns array containing the patterns created using {!mk_pattern}. - @param body the body of the quantifier. - - {b See also}: {!mk_pattern} - - {b See also}: {!mk_forall_const} - def_API('mk_exists_const', AST, (_in(CONTEXT), _in(UINT), _in(UINT), _in_array(2, APP), _in(UINT), _in_array(4, PATTERN), _in(AST))) -*) -external mk_exists_const : context -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3V3_Z3_mk_exists_const" - -(** - Summary: Create a universal or existential - quantifier using a list of constants that - will form the set of bound variables. - def_API('mk_quantifier_const', AST, (_in(CONTEXT), _in(BOOL), _in(UINT), _in(UINT), _in_array(3, APP), _in(UINT), _in_array(5, PATTERN), _in(AST))) -*) -external mk_quantifier_const : context -> bool -> int -> app array -> pattern array -> ast -> ast - = "camlidl_z3V3_Z3_mk_quantifier_const_bytecode" "camlidl_z3V3_Z3_mk_quantifier_const" - -(** - Summary: Create a universal or existential - quantifier using a list of constants that - will form the set of bound variables. - def_API('mk_quantifier_const_ex', AST, (_in(CONTEXT), _in(BOOL), _in(UINT), _in(SYMBOL), _in(SYMBOL), _in(UINT), _in_array(5, APP), _in(UINT), _in_array(7, PATTERN), _in(UINT), _in_array(9, AST), _in(AST))) -*) -external mk_quantifier_const_ex : context -> bool -> int -> symbol -> symbol -> app array -> pattern array -> ast array -> ast -> ast - = "camlidl_z3V3_Z3_mk_quantifier_const_ex_bytecode" "camlidl_z3V3_Z3_mk_quantifier_const_ex" + (** Indicates whether the term is addition (binary) *) + val is_add : Expr.expr -> bool -(** - {2 {L Accessors}} -*) -(** - {3 {L Symbols}} -*) -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Return [INT_SYMBOL] if the symbol was constructed - using {!mk_int_symbol}, and [STRING_SYMBOL] if the symbol - was constructed using {!mk_string_symbol}. - def_API('get_symbol_kind', UINT, (_in(CONTEXT), _in(SYMBOL))) -*) -external get_symbol_kind : context -> symbol -> symbol_kind - = "camlidl_z3V3_Z3_get_symbol_kind" - -(** - Summary: \[ [ get_symbol_int c s ] \] - Return the symbol int value. - - {b Precondition}: get_symbol_kind s == INT_SYMBOL - - {b See also}: {!mk_int_symbol} - def_API('get_symbol_int', INT, (_in(CONTEXT), _in(SYMBOL))) -*) -external get_symbol_int : context -> symbol -> int - = "camlidl_z3V3_Z3_get_symbol_int" - -(** - Summary: \[ [ get_symbol_string c s ] \] - Return the symbol name. - - {b Precondition}: get_symbol_string s == STRING_SYMBOL - - {b See also}: {!mk_string_symbol} - def_API('get_symbol_string', STRING, (_in(CONTEXT), _in(SYMBOL))) -*) -external get_symbol_string : context -> symbol -> string - = "camlidl_z3V3_Z3_get_symbol_string" + (** Indicates whether the term is subtraction (binary) *) + val is_sub : Expr.expr -> bool -(** - {3 {L Sorts}} -*) -(** - Summary: Return the sort name as a symbol. - def_API('get_sort_name', SYMBOL, (_in(CONTEXT), _in(SORT))) -*) -external get_sort_name : context -> sort -> symbol - = "camlidl_z3V3_Z3_get_sort_name" + (** Indicates whether the term is a unary minus *) + val is_uminus : Expr.expr -> bool -(** - Summary: Return a unique identifier for [s]. - - {b Remarks}: Implicitly used by [Pervasives.( = )] and [Pervasives.compare]. - def_API('get_sort_id', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_sort_id : context -> sort -> int - = "camlidl_z3V3_Z3_get_sort_id" + (** Indicates whether the term is multiplication (binary) *) + val is_mul : Expr.expr -> bool -(** - {4 {L Redundant low-level API}} -*) -(** - Summary: Convert a [sort] into [ast]. - - {b Remarks}: [sort_to_ast c s] can be replaced by [(s :> ast)]. - def_API('sort_to_ast', AST, (_in(CONTEXT), _in(SORT))) -*) -external sort_to_ast : context -> sort -> ast - = "camlidl_z3V3_Z3_sort_to_ast" + (** Indicates whether the term is division (binary) *) + val is_div : Expr.expr -> bool -(** - Summary: compare sorts. - - {b Remarks}: [Pervasives.( = )] or [Pervasives.compare] can also be used. - def_API('is_eq_sort', BOOL, (_in(CONTEXT), _in(SORT), _in(SORT))) -*) -external is_eq_sort : context -> sort -> sort -> bool - = "camlidl_z3V3_Z3_is_eq_sort" + (** Indicates whether the term is integer division (binary) *) + val is_idiv : Expr.expr -> bool -(** - Summary: Return the sort kind (e.g., array, tuple, int, bool, etc). - - {b See also}: {!sort_kind} - def_API('get_sort_kind', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_sort_kind : context -> sort -> sort_kind - = "camlidl_z3V3_Z3_get_sort_kind" - -(** - Summary: \[ [ get_bv_sort_size c t ] \] - Return the size of the given bit-vector sort. - - {b Precondition}: get_sort_kind c t == BV_SORT - - {b See also}: {!mk_bv_sort} - - {b See also}: {!get_sort_kind} - def_API('get_bv_sort_size', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_bv_sort_size : context -> sort -> int - = "camlidl_z3V3_Z3_get_bv_sort_size" + (** Indicates whether the term is remainder (binary) *) + val is_remainder : Expr.expr -> bool -(** - Summary: Return the size of the sort in [r]. Return [None] if the call failed. - That is, get_sort_kind(s) == FINITE_DOMAIN_SORT - def_API('get_finite_domain_sort_size', BOOL, (_in(CONTEXT), _in(SORT), _out(UINT64))) -*) -external get_finite_domain_sort_size : context -> sort -> int64 option - = "camlidl_z3V3_Z3_get_finite_domain_sort_size" - -(** - Summary: \[ [ get_array_sort_domain c t ] \] - Return the domain of the given array sort. - - {b Precondition}: get_sort_kind c t == ARRAY_SORT - - {b See also}: {!mk_array_sort} - - {b See also}: {!get_sort_kind} - def_API('get_array_sort_domain', SORT, (_in(CONTEXT), _in(SORT))) -*) -external get_array_sort_domain : context -> sort -> sort - = "camlidl_z3V3_Z3_get_array_sort_domain" - -(** - Summary: \[ [ get_array_sort_range c t ] \] - Return the range of the given array sort. - - {b Precondition}: get_sort_kind c t == ARRAY_SORT - - {b See also}: {!mk_array_sort} - - {b See also}: {!get_sort_kind} - def_API('get_array_sort_range', SORT, (_in(CONTEXT), _in(SORT))) -*) -external get_array_sort_range : context -> sort -> sort - = "camlidl_z3V3_Z3_get_array_sort_range" - -(** - Summary: \[ [ get_tuple_sort_mk_decl c t ] \] - Return the constructor declaration of the given tuple - sort. - - {b Precondition}: get_sort_kind c t == DATATYPE_SORT - - {b See also}: {!mk_tuple_sort} - - {b See also}: {!get_sort_kind} - def_API('get_tuple_sort_mk_decl', FUNC_DECL, (_in(CONTEXT), _in(SORT))) -*) -external get_tuple_sort_mk_decl : context -> sort -> func_decl - = "camlidl_z3V3_Z3_get_tuple_sort_mk_decl" - -(** - Summary: \[ [ get_tuple_sort_num_fields c t ] \] - Return the number of fields of the given tuple sort. - - {b Precondition}: get_sort_kind c t == DATATYPE_SORT - - {b See also}: {!mk_tuple_sort} - - {b See also}: {!get_sort_kind} - def_API('get_tuple_sort_num_fields', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_tuple_sort_num_fields : context -> sort -> int - = "camlidl_z3V3_Z3_get_tuple_sort_num_fields" - -(** - Summary: \[ [ get_tuple_sort_field_decl c t i ] \] - Return the i-th field declaration (i.e., projection function declaration) - of the given tuple sort. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b Precondition}: i < get_tuple_sort_num_fields c t - - {b See also}: {!mk_tuple_sort} - - {b See also}: {!get_sort_kind} - def_API('get_tuple_sort_field_decl', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT))) -*) -external get_tuple_sort_field_decl : context -> sort -> int -> func_decl - = "camlidl_z3V3_Z3_get_tuple_sort_field_decl" - -(** - Summary: Return number of constructors for datatype. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b See also}: {!get_datatype_sort_constructor} - - {b See also}: {!get_datatype_sort_recognizer} - - {b See also}: {!get_datatype_sort_constructor_accessor} - def_API('get_datatype_sort_num_constructors', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_datatype_sort_num_constructors : context -> sort -> int - = "camlidl_z3V3_Z3_get_datatype_sort_num_constructors" - -(** - Summary: Return idx'th constructor. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b Precondition}: idx < get_datatype_sort_num_constructors c t - - {b See also}: {!get_datatype_sort_num_constructors} - - {b See also}: {!get_datatype_sort_recognizer} - - {b See also}: {!get_datatype_sort_constructor_accessor} - def_API('get_datatype_sort_constructor', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT))) -*) -external get_datatype_sort_constructor : context -> sort -> int -> func_decl - = "camlidl_z3V3_Z3_get_datatype_sort_constructor" - -(** - Summary: Return idx'th recognizer. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b Precondition}: idx < get_datatype_sort_num_constructors c t - - {b See also}: {!get_datatype_sort_num_constructors} - - {b See also}: {!get_datatype_sort_constructor} - - {b See also}: {!get_datatype_sort_constructor_accessor} - def_API('get_datatype_sort_recognizer', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT))) -*) -external get_datatype_sort_recognizer : context -> sort -> int -> func_decl - = "camlidl_z3V3_Z3_get_datatype_sort_recognizer" - -(** - Summary: Return idx_a'th accessor for the idx_c'th constructor. - - {b Precondition}: get_sort_kind t == DATATYPE_SORT - - {b Precondition}: idx_c < get_datatype_sort_num_constructors c t - - {b Precondition}: idx_a < get_domain_size c get_datatype_sort_constructor c idx_c - - {b See also}: {!get_datatype_sort_num_constructors} - - {b See also}: {!get_datatype_sort_constructor} - - {b See also}: {!get_datatype_sort_recognizer} - def_API('get_datatype_sort_constructor_accessor', FUNC_DECL, (_in(CONTEXT), _in(SORT), _in(UINT), _in(UINT))) -*) -external get_datatype_sort_constructor_accessor : context -> sort -> int -> int -> func_decl - = "camlidl_z3V3_Z3_get_datatype_sort_constructor_accessor" - -(** - Summary: Return arity of relation. - - {b Precondition}: get_sort_kind s == RELATION_SORT - - {b See also}: {!get_relation_column} - def_API('get_relation_arity', UINT, (_in(CONTEXT), _in(SORT))) -*) -external get_relation_arity : context -> sort -> int - = "camlidl_z3V3_Z3_get_relation_arity" - -(** - Summary: Return sort at i'th column of relation sort. - - {b Precondition}: get_sort_kind c s == RELATION_SORT - - {b Precondition}: col < get_relation_arity c s - - {b See also}: {!get_relation_arity} - def_API('get_relation_column', SORT, (_in(CONTEXT), _in(SORT), _in(UINT))) -*) -external get_relation_column : context -> sort -> int -> sort - = "camlidl_z3V3_Z3_get_relation_column" + (** Indicates whether the term is modulus (binary) *) + val is_modulus : Expr.expr -> bool -(** - {3 {L Function Declarations}} -*) -(** - Summary: Convert a [func_decl] into [ast]. - - {b Remarks}: [func_decl_to_ast c f] can be replaced by [(f :> ast)]. - def_API('func_decl_to_ast', AST, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external func_decl_to_ast : context -> func_decl -> ast - = "camlidl_z3V3_Z3_func_decl_to_ast" + (** Indicates whether the term is a coercion of integer to real (unary) *) + val is_inttoreal : Expr.expr -> bool -(** - Summary: compare terms. - - {b Remarks}: [Pervasives.( = )] or [Pervasives.compare] can also be used. - def_API('is_eq_func_decl', BOOL, (_in(CONTEXT), _in(FUNC_DECL), _in(FUNC_DECL))) -*) -external is_eq_func_decl : context -> func_decl -> func_decl -> bool - = "camlidl_z3V3_Z3_is_eq_func_decl" + (** Indicates whether the term is a coercion of real to integer (unary) *) + val is_real_to_int : Expr.expr -> bool -(** - Summary: Return a unique identifier for [f]. - - {b Remarks}: Implicitly used by [Pervasives.( = )] and [Pervasives.compare]. - def_API('get_func_decl_id', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_func_decl_id : context -> func_decl -> int - = "camlidl_z3V3_Z3_get_func_decl_id" + (** Indicates whether the term is a check that tests whether a real is integral (unary) *) + val is_real_is_int : Expr.expr -> bool -(** - Summary: Return the constant declaration name as a symbol. - def_API('get_decl_name', SYMBOL, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_decl_name : context -> func_decl -> symbol - = "camlidl_z3V3_Z3_get_decl_name" + (** Indicates whether the term is of sort real. *) + val is_real : Expr.expr -> bool -(** - Summary: Return declaration kind corresponding to declaration. - def_API('get_decl_kind', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_decl_kind : context -> func_decl -> decl_kind - = "camlidl_z3V3_Z3_get_decl_kind" + (** Indicates whether the term is an integer numeral. *) + val is_int_numeral : Expr.expr -> bool -(** - Summary: Return the number of parameters of the given declaration. - - {b See also}: {!get_arity} - def_API('get_domain_size', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_domain_size : context -> func_decl -> int - = "camlidl_z3V3_Z3_get_domain_size" + (** Indicates whether the term is a real numeral. *) + val is_rat_num : Expr.expr -> bool -(** - Summary: Alias for [get_domain_size]. - - {b See also}: {!get_domain_size} - def_API('get_arity', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_arity : context -> func_decl -> int - = "camlidl_z3V3_Z3_get_arity" - -(** - Summary: \[ [ get_domain c d i ] \] - Return the sort of the i-th parameter of the given function declaration. - - {b Precondition}: i < get_domain_size d - - {b See also}: {!get_domain_size} - def_API('get_domain', SORT, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_domain : context -> func_decl -> int -> sort - = "camlidl_z3V3_Z3_get_domain" - -(** - Summary: \[ [ get_range c d ] \] - Return the range of the given declaration. - If [d] is a constant (i.e., has zero arguments), then this - function returns the sort of the constant. - def_API('get_range', SORT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_range : context -> func_decl -> sort - = "camlidl_z3V3_Z3_get_range" + (** Indicates whether the term is an algebraic number *) + val is_algebraic_number : Expr.expr -> bool -(** - Summary: Return the number of parameters associated with a declaration. - def_API('get_decl_num_parameters', UINT, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external get_decl_num_parameters : context -> func_decl -> int - = "camlidl_z3V3_Z3_get_decl_num_parameters" - -(** - Summary: Return the parameter type associated with a declaration. - @param c the context - @param d the function declaration - @param idx is the index of the named parameter it should be between 0 and the number of parameters. - def_API('get_decl_parameter_kind', UINT, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_parameter_kind : context -> func_decl -> int -> parameter_kind - = "camlidl_z3V3_Z3_get_decl_parameter_kind" + (** Create an expression representing t[0] + t[1] + .... *) + val mk_add : context -> Expr.expr list -> Expr.expr -(** - Summary: Return the integer value associated with an integer parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_INT - def_API('get_decl_int_parameter', INT, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_int_parameter : context -> func_decl -> int -> int - = "camlidl_z3V3_Z3_get_decl_int_parameter" + (** Create an expression representing t[0] * t[1] * .... *) + val mk_mul : context -> Expr.expr list -> Expr.expr -(** - Summary: Return the double value associated with an double parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_DOUBLE - def_API('get_decl_double_parameter', DOUBLE, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_double_parameter : context -> func_decl -> int -> float - = "camlidl_z3V3_Z3_get_decl_double_parameter" + (** Create an expression representing t[0] - t[1] - .... *) + val mk_sub : context -> Expr.expr list -> Expr.expr -(** - Summary: Return the double value associated with an double parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_SYMBOL - def_API('get_decl_symbol_parameter', SYMBOL, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_symbol_parameter : context -> func_decl -> int -> symbol - = "camlidl_z3V3_Z3_get_decl_symbol_parameter" + (** Create an expression representing -t. *) + val mk_unary_minus : context -> Expr.expr -> Expr.expr -(** - Summary: Return the sort value associated with a sort parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_SORT - def_API('get_decl_sort_parameter', SORT, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_sort_parameter : context -> func_decl -> int -> sort - = "camlidl_z3V3_Z3_get_decl_sort_parameter" + (** Create an expression representing t1 / t2. *) + val mk_div : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: Return the expresson value associated with an expression parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_AST - def_API('get_decl_ast_parameter', AST, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_ast_parameter : context -> func_decl -> int -> ast - = "camlidl_z3V3_Z3_get_decl_ast_parameter" + (** Create an expression representing t1 ^ t2. *) + val mk_power : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: Return the expresson value associated with an expression parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_FUNC_DECL - def_API('get_decl_func_decl_parameter', FUNC_DECL, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_func_decl_parameter : context -> func_decl -> int -> func_decl - = "camlidl_z3V3_Z3_get_decl_func_decl_parameter" + (** Create an expression representing t1 < t2 *) + val mk_lt : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: Return the rational value, as a string, associated with a rational parameter. - - {b Precondition}: get_decl_parameter_kind c d idx == PARAMETER_RATIONAL - def_API('get_decl_rational_parameter', STRING, (_in(CONTEXT), _in(FUNC_DECL), _in(UINT))) -*) -external get_decl_rational_parameter : context -> func_decl -> int -> string - = "camlidl_z3V3_Z3_get_decl_rational_parameter" + (** Create an expression representing t1 <= t2 *) + val mk_le : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - {3 {L Applications}} -*) -(** - Summary: Convert a [app] into [ast]. - - {b Remarks}: [app_to_ast c a] can be replaced by [(a :> ast)]. - def_API('app_to_ast', AST, (_in(CONTEXT), _in(APP))) -*) -external app_to_ast : context -> app -> ast - = "camlidl_z3V3_Z3_app_to_ast" + (** Create an expression representing t1 > t2 *) + val mk_gt : context -> Expr.expr -> Expr.expr -> Expr.expr -(** - Summary: Return the declaration of a constant or function application. - def_API('get_app_decl', FUNC_DECL, (_in(CONTEXT), _in(APP))) -*) -external get_app_decl : context -> app -> func_decl - = "camlidl_z3V3_Z3_get_app_decl" - -(** - Summary: \[ [ get_app_num_args c a ] \] - Return the number of argument of an application. If [t] - is an constant, then the number of arguments is 0. - def_API('get_app_num_args', UINT, (_in(CONTEXT), _in(APP))) -*) -external get_app_num_args : context -> app -> int - = "camlidl_z3V3_Z3_get_app_num_args" - -(** - Summary: \[ [ get_app_arg c a i ] \] - Return the i-th argument of the given application. - - {b Precondition}: i < get_num_args c a - def_API('get_app_arg', AST, (_in(CONTEXT), _in(APP), _in(UINT))) -*) -external get_app_arg : context -> app -> int -> ast - = "camlidl_z3V3_Z3_get_app_arg" + (** Create an expression representing t1 >= t2 *) + val mk_ge : context -> Expr.expr -> Expr.expr -> Expr.expr +end -(** - {3 {L Terms}} -*) -(** - Summary: compare terms. - - {b Remarks}: [Pervasives.( = )] or [Pervasives.compare] can also be used. - def_API('is_eq_ast', BOOL, (_in(CONTEXT), _in(AST), _in(AST))) -*) -external is_eq_ast : context -> ast -> ast -> bool - = "camlidl_z3V3_Z3_is_eq_ast" +(** Functions to manipulate bit-vector expressions *) +module BitVector : +sig + (** Create a new bit-vector sort. *) + val mk_sort : context -> int -> Sort.sort -(** - Summary: Return a unique identifier for [t]. - - {b Remarks}: Implicitly used by [Pervasives.compare] for values of type [ast], [app], [sort], [func_decl], and [pattern]. - def_API('get_ast_id', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_ast_id : context -> ast -> int - = "camlidl_z3V3_Z3_get_ast_id" + (** Indicates whether the terms is of bit-vector sort. *) + val is_bv : Expr.expr -> bool -(** - Summary: Return a hash code for the given AST. - - {b Remarks}: Implicitly used by [Hashtbl.hash] for values of type [ast], [app], [sort], [func_decl], and [pattern]. - def_API('get_ast_hash', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_ast_hash : context -> ast -> int - = "camlidl_z3V3_Z3_get_ast_hash" + (** Indicates whether the term is a bit-vector numeral *) + val is_bv_numeral : Expr.expr -> bool -(** - Summary: Return the sort of an AST node. - The AST node must be a constant, application, numeral, bound variable, or quantifier. - def_API('get_sort', SORT, (_in(CONTEXT), _in(AST))) -*) -external get_sort : context -> ast -> sort - = "camlidl_z3V3_Z3_get_sort" + (** Indicates whether the term is a one-bit bit-vector with value one *) + val is_bv_bit1 : Expr.expr -> bool -(** - Summary: Return true if the given expression [t] is well sorted. - def_API('is_well_sorted', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_well_sorted : context -> ast -> bool - = "camlidl_z3V3_Z3_is_well_sorted" + (** Indicates whether the term is a one-bit bit-vector with value zero *) + val is_bv_bit0 : Expr.expr -> bool -(** - Summary: Return L_TRUE if [a] is true, L_FALSE if it is false, and L_UNDEF otherwise. - def_API('get_bool_value', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_bool_value : context -> ast -> lbool - = "camlidl_z3V3_Z3_get_bool_value" + (** Indicates whether the term is a bit-vector unary minus *) + val is_bv_uminus : Expr.expr -> bool -(** - Summary: Return the kind of the given AST. - def_API('get_ast_kind', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_ast_kind : context -> ast -> ast_kind - = "camlidl_z3V3_Z3_get_ast_kind" + (** Indicates whether the term is a bit-vector addition (binary) *) + val is_bv_add : Expr.expr -> bool -(** - def_API('is_app', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_app : context -> ast -> bool - = "camlidl_z3V3_Z3_is_app" + (** Indicates whether the term is a bit-vector subtraction (binary) *) + val is_bv_sub : Expr.expr -> bool -(** - def_API('is_numeral_ast', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_numeral_ast : context -> ast -> bool - = "camlidl_z3V3_Z3_is_numeral_ast" + (** Indicates whether the term is a bit-vector multiplication (binary) *) + val is_bv_mul : Expr.expr -> bool -(** - Summary: Return true if the give AST is a real algebraic number. - def_API('is_algebraic_number', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_algebraic_number : context -> ast -> bool - = "camlidl_z3V3_Z3_is_algebraic_number" + (** Indicates whether the term is a bit-vector signed division (binary) *) + val is_bv_sdiv : Expr.expr -> bool -(** - Summary: Convert an [ast] into an [APP_AST]. - - {b Precondition}: {v get_ast_kind c a == [APP_AST] v} - def_API('to_app', APP, (_in(CONTEXT), _in(AST))) -*) -external to_app : context -> ast -> app - = "camlidl_z3V3_Z3_to_app" + (** Indicates whether the term is a bit-vector unsigned division (binary) *) + val is_bv_udiv : Expr.expr -> bool -(** - Summary: Convert an AST into a FUNC_DECL_AST. This is just type casting. - - {b Precondition}: {v get_ast_kind c a == FUNC_DECL_AST v} - def_API('to_func_decl', FUNC_DECL, (_in(CONTEXT), _in(AST))) -*) -external to_func_decl : context -> ast -> func_decl - = "camlidl_z3V3_Z3_to_func_decl" + (** Indicates whether the term is a bit-vector signed remainder (binary) *) + val is_bv_SRem : Expr.expr -> bool -(** - {4 {L Numerals}} -*) -(** - {5 {L Low-level API}} -*) -(** - Summary: Return numeral value, as a string of a numeric constant term - - {b Precondition}: get_ast_kind c a == NUMERAL_AST - def_API('get_numeral_string', STRING, (_in(CONTEXT), _in(AST))) -*) -external get_numeral_string : context -> ast -> string - = "camlidl_z3V3_Z3_get_numeral_string" - -(** - Summary: Return numeral as a string in decimal notation. - The result has at most [precision] decimal places. - - {b Precondition}: get_ast_kind c a == NUMERAL_AST || is_algebraic_number c a - def_API('get_numeral_decimal_string', STRING, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_numeral_decimal_string : context -> ast -> int -> string - = "camlidl_z3V3_Z3_get_numeral_decimal_string" + (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) + val is_bv_urem : Expr.expr -> bool -(** - Summary: Return the numerator (as a numeral AST) of a numeral AST of sort Real. - - {b Precondition}: get_ast_kind c a == NUMERAL_AST - def_API('get_numerator', AST, (_in(CONTEXT), _in(AST))) -*) -external get_numerator : context -> ast -> ast - = "camlidl_z3V3_Z3_get_numerator" + (** Indicates whether the term is a bit-vector signed modulus *) + val is_bv_smod : Expr.expr -> bool -(** - Summary: Return the denominator (as a numeral AST) of a numeral AST of sort Real. - - {b Precondition}: get_ast_kind c a == NUMERAL_AST - def_API('get_denominator', AST, (_in(CONTEXT), _in(AST))) -*) -external get_denominator : context -> ast -> ast - = "camlidl_z3V3_Z3_get_denominator" - -(** - Summary: Return numeral value, as a pair of 64 bit numbers if the representation fits. - @param c logical context. - @param a term. - @param num numerator. - @param den denominator. - Return [TRUE] if the numeral value fits in 64 bit numerals, [FALSE] otherwise. - - {b Precondition}: get_ast_kind a == NUMERAL_AST - def_API('get_numeral_small', BOOL, (_in(CONTEXT), _in(AST), _out(INT64), _out(INT64))) -*) -external get_numeral_small : context -> ast -> bool * int64 * int64 - = "camlidl_z3V3_Z3_get_numeral_small" - -(** - Summary: \[ [ get_numeral_int c v ] \] - Similar to {!get_numeral_string}, but only succeeds if - the value can fit in a machine int. Return TRUE if the call succeeded. - - {b Precondition}: get_ast_kind c v == NUMERAL_AST - - {b See also}: {!get_numeral_string} - def_API('get_numeral_int', BOOL, (_in(CONTEXT), _in(AST), _out(INT))) -*) -external get_numeral_int : context -> ast -> bool * int - = "camlidl_z3V3_Z3_get_numeral_int" - -(** - Summary: \[ [ get_numeral_int64 c v ] \] - Similar to {!get_numeral_string}, but only succeeds if - the value can fit in a machine long long int. Return TRUE if the call succeeded. - - {b Precondition}: get_ast_kind c v == NUMERAL_AST - - {b See also}: {!get_numeral_string} - def_API('get_numeral_int64', BOOL, (_in(CONTEXT), _in(AST), _out(INT64))) -*) -external get_numeral_int64 : context -> ast -> bool * int64 - = "camlidl_z3V3_Z3_get_numeral_int64" - -(** - Summary: \[ [ get_numeral_rational_int64 c x y] \] - Similar to {!get_numeral_string}, but only succeeds if - the value can fit as a rational number as machine long long int. Return TRUE if the call succeeded. - - {b Precondition}: get_ast_kind c v == NUMERAL_AST - - {b See also}: {!get_numeral_string} - def_API('get_numeral_rational_int64', BOOL, (_in(CONTEXT), _in(AST), _out(INT64), _out(INT64))) -*) -external get_numeral_rational_int64 : context -> ast -> bool * int64 * int64 - = "camlidl_z3V3_Z3_get_numeral_rational_int64" - -(** - Summary: Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - The result is a numeral AST of sort Real. - - {b Precondition}: is_algebraic_number c a - def_API('get_algebraic_number_lower', AST, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_algebraic_number_lower : context -> ast -> int -> ast - = "camlidl_z3V3_Z3_get_algebraic_number_lower" - -(** - Summary: Return a upper bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - The result is a numeral AST of sort Real. - - {b Precondition}: is_algebraic_number c a - def_API('get_algebraic_number_upper', AST, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_algebraic_number_upper : context -> ast -> int -> ast - = "camlidl_z3V3_Z3_get_algebraic_number_upper" + (** Indicates whether the term is a bit-vector signed division by zero *) + val is_bv_sdiv0 : Expr.expr -> bool -(** - {4 {L Patterns}} -*) -(** - Summary: Convert a pattern into ast. - - {b Remarks}: [pattern_to_ast c p] can be replaced by [(p :> ast)]. - def_API('pattern_to_ast', AST, (_in(CONTEXT), _in(PATTERN))) -*) -external pattern_to_ast : context -> pattern -> ast - = "camlidl_z3V3_Z3_pattern_to_ast" + (** Indicates whether the term is a bit-vector unsigned division by zero *) + val is_bv_udiv0 : Expr.expr -> bool -(** - Summary: Return number of terms in pattern. - def_API('get_pattern_num_terms', UINT, (_in(CONTEXT), _in(PATTERN))) -*) -external get_pattern_num_terms : context -> pattern -> int - = "camlidl_z3V3_Z3_get_pattern_num_terms" + (** Indicates whether the term is a bit-vector signed remainder by zero *) + val is_bv_srem0 : Expr.expr -> bool -(** - Summary: Return i'th ast in pattern. - def_API('get_pattern', AST, (_in(CONTEXT), _in(PATTERN), _in(UINT))) -*) -external get_pattern : context -> pattern -> int -> ast - = "camlidl_z3V3_Z3_get_pattern" + (** Indicates whether the term is a bit-vector unsigned remainder by zero *) + val is_bv_urem0 : Expr.expr -> bool -(** - {4 {L Quantifiers}} -*) -(** - Summary: Return index of de-Brujin bound variable. - - {b Precondition}: get_ast_kind a == VAR_AST - def_API('get_index_value', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_index_value : context -> ast -> int - = "camlidl_z3V3_Z3_get_index_value" + (** Indicates whether the term is a bit-vector signed modulus by zero *) + val is_bv_smod0 : Expr.expr -> bool -(** - Summary: Determine if quantifier is universal. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('is_quantifier_forall', BOOL, (_in(CONTEXT), _in(AST))) -*) -external is_quantifier_forall : context -> ast -> bool - = "camlidl_z3V3_Z3_is_quantifier_forall" + (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) + val is_bv_ule : Expr.expr -> bool -(** - Summary: Obtain weight of quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_weight', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_weight : context -> ast -> int - = "camlidl_z3V3_Z3_get_quantifier_weight" + (** Indicates whether the term is a signed bit-vector less-than-or-equal *) + val is_bv_sle : Expr.expr -> bool -(** - Summary: Return number of patterns used in quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_num_patterns', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_num_patterns : context -> ast -> int - = "camlidl_z3V3_Z3_get_quantifier_num_patterns" + (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) + val is_bv_uge : Expr.expr -> bool -(** - Summary: Return i'th pattern. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_pattern_ast', PATTERN, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_quantifier_pattern_ast : context -> ast -> int -> pattern - = "camlidl_z3V3_Z3_get_quantifier_pattern_ast" + (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) + val is_bv_sge : Expr.expr -> bool -(** - Summary: Return number of no_patterns used in quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_num_no_patterns', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_num_no_patterns : context -> ast -> int - = "camlidl_z3V3_Z3_get_quantifier_num_no_patterns" + (** Indicates whether the term is an unsigned bit-vector less-than *) + val is_bv_ult : Expr.expr -> bool -(** - Summary: Return i'th no_pattern. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_no_pattern_ast', AST, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_quantifier_no_pattern_ast : context -> ast -> int -> ast - = "camlidl_z3V3_Z3_get_quantifier_no_pattern_ast" + (** Indicates whether the term is a signed bit-vector less-than *) + val is_bv_slt : Expr.expr -> bool -(** - Summary: Return number of bound variables of quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_num_bound', UINT, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_num_bound : context -> ast -> int - = "camlidl_z3V3_Z3_get_quantifier_num_bound" + (** Indicates whether the term is an unsigned bit-vector greater-than *) + val is_bv_ugt : Expr.expr -> bool -(** - Summary: Return symbol of the i'th bound variable. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_bound_name', SYMBOL, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_quantifier_bound_name : context -> ast -> int -> symbol - = "camlidl_z3V3_Z3_get_quantifier_bound_name" + (** Indicates whether the term is a signed bit-vector greater-than *) + val is_bv_sgt : Expr.expr -> bool -(** - Summary: Return sort of the i'th bound variable. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_bound_sort', SORT, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external get_quantifier_bound_sort : context -> ast -> int -> sort - = "camlidl_z3V3_Z3_get_quantifier_bound_sort" + (** Indicates whether the term is a bit-wise AND *) + val is_bv_and : Expr.expr -> bool -(** - Summary: Return body of quantifier. - - {b Precondition}: get_ast_kind a == QUANTIFIER_AST - def_API('get_quantifier_body', AST, (_in(CONTEXT), _in(AST))) -*) -external get_quantifier_body : context -> ast -> ast - = "camlidl_z3V3_Z3_get_quantifier_body" + (** Indicates whether the term is a bit-wise OR *) + val is_bv_or : Expr.expr -> bool -(** - {3 {L Simplification}} -*) -(** - Summary: Interface to simplifier. - Provides an interface to the AST simplifier used by Z3. - def_API('simplify', AST, (_in(CONTEXT), _in(AST))) -*) -external simplify : context -> ast -> ast - = "camlidl_z3V3_Z3_simplify" + (** Indicates whether the term is a bit-wise NOT *) + val is_bv_not : Expr.expr -> bool -(** - {2 {L Modifiers}} -*) -(** - Summary: Update the arguments of term [a] using the arguments [args]. - The number of arguments [num_args] should coincide - with the number of arguments to [a]. - If [a] is a quantifier, then num_args has to be 1. - def_API('update_term', AST, (_in(CONTEXT), _in(AST), _in(UINT), _in_array(2, AST))) -*) -external update_term : context -> ast -> ast array -> ast - = "camlidl_z3V3_Z3_update_term" - -(** - Summary: Substitute every occurrence of {e from[i] } in [a] with {e to[i] }, for [i] smaller than [num_exprs]. - The result is the new AST. The arrays [from] and [to] must have size [num_exprs]. - For every [i] smaller than [num_exprs], we must have that sort of {e from[i] } must be equal to sort of {e to[i] }. - def_API('substitute', AST, (_in(CONTEXT), _in(AST), _in(UINT), _in_array(2, AST), _in_array(2, AST))) -*) -external substitute : context -> ast -> ast array -> ast array -> ast - = "camlidl_z3V3_Z3_substitute" + (** Indicates whether the term is a bit-wise XOR *) + val is_bv_xor : Expr.expr -> bool -(** - Summary: Substitute the free variables in [a] with the expressions in [to]. - For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term {e to[i] }. - def_API('substitute_vars', AST, (_in(CONTEXT), _in(AST), _in(UINT), _in_array(2, AST))) -*) -external substitute_vars : context -> ast -> ast array -> ast - = "camlidl_z3V3_Z3_substitute_vars" + (** Indicates whether the term is a bit-wise NAND *) + val is_bv_nand : Expr.expr -> bool -(** - {2 {L Interaction logging.}} -*) -(** - Summary: Log interaction to a file. - extra_API('open_log', INT, (_in(STRING),)) -*) -external open_log : string -> bool - = "camlidl_z3V3_Z3_open_log" - -(** - Summary: Append user-defined string to interaction log. - The interaction log is opened using open_log. - It contains the formulas that are checked using Z3. - You can use this command to append comments, for instance. - extra_API('append_log', VOID, (_in(STRING),)) -*) -external append_log : string -> unit - = "camlidl_z3V3_Z3_append_log" + (** Indicates whether the term is a bit-wise NOR *) + val is_bv_nor : Expr.expr -> bool -(** - Summary: Close interaction log. - extra_API('close_log', VOID, ()) -*) -external close_log : unit -> unit - = "camlidl_z3V3_Z3_close_log" - -(** - Summary: Enable/disable printing warning messages to the console. - Warnings are printed after passing [true], warning messages are - suppressed after calling this method with [false]. - def_API('toggle_warning_messages', VOID, (_in(BOOL),)) -*) -external toggle_warning_messages : bool -> unit - = "camlidl_z3V3_Z3_toggle_warning_messages" + (** Indicates whether the term is a bit-wise XNOR *) + val is_bv_xnor : Expr.expr -> bool -(** - {2 {L String conversion}} -*) -(** - Summary: Select mode for the format used for pretty-printing AST nodes. - The default mode for pretty printing AST nodes is to produce - SMT-LIB style output where common subexpressions are printed - at each occurrence. The mode is called PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - - {b See also}: {!ast_to_string} - - {b See also}: {!pattern_to_string} - - {b See also}: {!func_decl_to_string} - def_API('set_ast_print_mode', VOID, (_in(CONTEXT), _in(PRINT_MODE))) -*) -external set_ast_print_mode : context -> ast_print_mode -> unit - = "camlidl_z3V3_Z3_set_ast_print_mode" - -(** - Summary: Convert the given AST node into a string. - - {b See also}: {!pattern_to_string} - - {b See also}: {!sort_to_string} - def_API('ast_to_string', STRING, (_in(CONTEXT), _in(AST))) -*) -external ast_to_string : context -> ast -> string - = "camlidl_z3V3_Z3_ast_to_string" + (** Indicates whether the term is a bit-vector concatenation (binary) *) + val is_bv_concat : Expr.expr -> bool -(** - def_API('pattern_to_string', STRING, (_in(CONTEXT), _in(PATTERN))) -*) -external pattern_to_string : context -> pattern -> string - = "camlidl_z3V3_Z3_pattern_to_string" + (** Indicates whether the term is a bit-vector sign extension *) + val is_bv_signextension : Expr.expr -> bool -(** - def_API('sort_to_string', STRING, (_in(CONTEXT), _in(SORT))) -*) -external sort_to_string : context -> sort -> string - = "camlidl_z3V3_Z3_sort_to_string" + (** Indicates whether the term is a bit-vector zero extension *) + val is_bv_zeroextension : Expr.expr -> bool -(** - def_API('func_decl_to_string', STRING, (_in(CONTEXT), _in(FUNC_DECL))) -*) -external func_decl_to_string : context -> func_decl -> string - = "camlidl_z3V3_Z3_func_decl_to_string" + (** Indicates whether the term is a bit-vector extraction *) + val is_bv_extract : Expr.expr -> bool -(** - Summary: Convert the given model into a string. - def_API('model_to_string', STRING, (_in(CONTEXT), _in(MODEL))) -*) -external model_to_string : context -> model -> string - = "camlidl_z3V3_Z3_model_to_string" - -(** - Summary: Convert the given benchmark into SMT-LIB formatted string. - @param c - context. - @param name - name of benchmark. The argument is optional. - @param logic - the benchmark logic. - @param status - the status string (sat, unsat, or unknown) - @param attributes - other attributes, such as source, difficulty or category. - @param num_assumptions - number of assumptions. - @param assumptions - auxiliary assumptions. - @param formula - formula to be checked for consistency in conjunction with assumptions. - def_API('benchmark_to_smtlib_string', STRING, (_in(CONTEXT), _in(STRING), _in(STRING), _in(STRING), _in(STRING), _in(UINT), _in_array(5, AST), _in(AST))) -*) -external benchmark_to_smtlib_string : context -> string -> string -> string -> string -> ast array -> ast -> string - = "camlidl_z3V3_Z3_benchmark_to_smtlib_string_bytecode" "camlidl_z3V3_Z3_benchmark_to_smtlib_string" + (** Indicates whether the term is a bit-vector repetition *) + val is_bv_repeat : Expr.expr -> bool -(** - {2 {L Parser interface}} -*) -(** - Summary: \[ [ parse_smtlib2_string c str ] \] - Parse the given string using the SMT-LIB2 parser. - It returns a formula comprising of the conjunction of assertions in the scope - (up to push/pop) at the end of the string. - def_API('parse_smtlib2_string', AST, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _in(UINT), _in_array(5, SYMBOL), _in_array(5, FUNC_DECL))) -*) -external parse_smtlib2_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - = "camlidl_z3V3_Z3_parse_smtlib2_string_bytecode" "camlidl_z3V3_Z3_parse_smtlib2_string" + (** Indicates whether the term is a bit-vector reduce OR *) + val is_bv_reduceor : Expr.expr -> bool -(** - Summary: Similar to {!parse_smtlib2_string}, but reads the benchmark from a file. - def_API('parse_smtlib2_file', AST, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _in(UINT), _in_array(5, SYMBOL), _in_array(5, FUNC_DECL))) -*) -external parse_smtlib2_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - = "camlidl_z3V3_Z3_parse_smtlib2_file_bytecode" "camlidl_z3V3_Z3_parse_smtlib2_file" + (** Indicates whether the term is a bit-vector reduce AND *) + val is_bv_reduceand : Expr.expr -> bool -(** - {4 {L Low-level API}} -*) -(** - Summary: \[ [ parse_smtlib_string c str sort_names sorts decl_names decls ] \] - 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 [sort_names] and [decl_names] don't need to match the names - of the sorts and declarations in the arrays [sorts] and [decls]. This is an useful feature - since we can use arbitrary names to reference sorts and declarations defined using the C API. - The formulas, assumptions and declarations defined in [str] can be extracted using the functions: - {!get_smtlib_num_formulas}, {!get_smtlib_formula}, {!get_smtlib_num_assumptions}, {!get_smtlib_assumption}, - {!get_smtlib_num_decls}, and {!get_smtlib_decl}. - def_API('parse_smtlib_string', VOID, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _in(UINT), _in_array(5, SYMBOL), _in_array(5, FUNC_DECL))) -*) -external parse_smtlib_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - = "camlidl_z3V3_Z3_parse_smtlib_string_bytecode" "camlidl_z3V3_Z3_parse_smtlib_string" + (** Indicates whether the term is a bit-vector comparison *) + val is_bv_comp : Expr.expr -> bool -(** - Summary: Similar to {!parse_smtlib_string}, but reads the benchmark from a file. - def_API('parse_smtlib_file', VOID, (_in(CONTEXT), _in(STRING), _in(UINT), _in_array(2, SYMBOL), _in_array(2, SORT), _in(UINT), _in_array(5, SYMBOL), _in_array(5, FUNC_DECL))) -*) -external parse_smtlib_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - = "camlidl_z3V3_Z3_parse_smtlib_file_bytecode" "camlidl_z3V3_Z3_parse_smtlib_file" + (** Indicates whether the term is a bit-vector shift left *) + val is_bv_shiftleft : Expr.expr -> bool -(** - Summary: Return the number of SMTLIB formulas parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - def_API('get_smtlib_num_formulas', UINT, (_in(CONTEXT), )) -*) -external get_smtlib_num_formulas : context -> int - = "camlidl_z3V3_Z3_get_smtlib_num_formulas" - -(** - Summary: \[ [ get_smtlib_formula c i ] \] - Return the i-th formula parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - - {b Precondition}: i < get_smtlib_num_formulas c - def_API('get_smtlib_formula', AST, (_in(CONTEXT), _in(UINT))) -*) -external get_smtlib_formula : context -> int -> ast - = "camlidl_z3V3_Z3_get_smtlib_formula" + (** Indicates whether the term is a bit-vector logical shift right *) + val is_bv_shiftrightlogical : Expr.expr -> bool -(** - Summary: Return the number of SMTLIB assumptions parsed by {!parse_smtlib_string} or {!parse_smtlib_file}. - def_API('get_smtlib_num_assumptions', UINT, (_in(CONTEXT), )) -*) -external get_smtlib_num_assumptions : context -> int - = "camlidl_z3V3_Z3_get_smtlib_num_assumptions" - -(** - Summary: \[ [ get_smtlib_assumption c i ] \] - Return the i-th assumption parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - - {b Precondition}: i < get_smtlib_num_assumptions c - def_API('get_smtlib_assumption', AST, (_in(CONTEXT), _in(UINT))) -*) -external get_smtlib_assumption : context -> int -> ast - = "camlidl_z3V3_Z3_get_smtlib_assumption" + (** Indicates whether the term is a bit-vector arithmetic shift left *) + val is_bv_shiftrightarithmetic : Expr.expr -> bool -(** - Summary: Return the number of declarations parsed by {!parse_smtlib_string} or {!parse_smtlib_file}. - def_API('get_smtlib_num_decls', UINT, (_in(CONTEXT), )) -*) -external get_smtlib_num_decls : context -> int - = "camlidl_z3V3_Z3_get_smtlib_num_decls" - -(** - Summary: \[ [ get_smtlib_decl c i ] \] - Return the i-th declaration parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - - {b Precondition}: i < get_smtlib_num_decls c - def_API('get_smtlib_decl', FUNC_DECL, (_in(CONTEXT), _in(UINT))) -*) -external get_smtlib_decl : context -> int -> func_decl - = "camlidl_z3V3_Z3_get_smtlib_decl" + (** Indicates whether the term is a bit-vector rotate left *) + val is_bv_rotateleft : Expr.expr -> bool -(** - Summary: Return the number of sorts parsed by {!parse_smtlib_string} or {!parse_smtlib_file}. - def_API('get_smtlib_num_sorts', UINT, (_in(CONTEXT), )) -*) -external get_smtlib_num_sorts : context -> int - = "camlidl_z3V3_Z3_get_smtlib_num_sorts" - -(** - Summary: \[ [ get_smtlib_sort c i ] \] - Return the i-th sort parsed by the last call to {!parse_smtlib_string} or {!parse_smtlib_file}. - - {b Precondition}: i < get_smtlib_num_sorts c - def_API('get_smtlib_sort', SORT, (_in(CONTEXT), _in(UINT))) -*) -external get_smtlib_sort : context -> int -> sort - = "camlidl_z3V3_Z3_get_smtlib_sort" + (** Indicates whether the term is a bit-vector rotate right *) + val is_bv_rotateright : Expr.expr -> bool -(** - Summary: \[ [ get_smtlib_error c ] \] - Retrieve that last error message information generated from parsing. - def_API('get_smtlib_error', STRING, (_in(CONTEXT), )) -*) -external get_smtlib_error : context -> string - = "camlidl_z3V3_Z3_get_smtlib_error" + (** 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. *) + val is_bv_rotateleftextended : Expr.expr -> bool -(** - {2 {L Miscellaneous}} -*) -(** - Summary: Return Z3 version number information. - def_API('get_version', VOID, (_out(UINT), _out(UINT), _out(UINT), _out(UINT))) -*) -external get_version : unit -> int * int * int * int - = "camlidl_z3V3_Z3_get_version" + (** 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. *) + val is_bv_rotaterightextended : Expr.expr -> bool + + (** 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. *) -(** - Summary: Enable tracing messages tagged as [tag] when Z3 is compiled in debug mode. - It is a NOOP otherwise - def_API('enable_trace', VOID, (_in(STRING),)) -*) -external enable_trace : string -> unit - = "camlidl_z3V3_Z3_enable_trace" + (** 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. *) + val is_int_to_bv : Expr.expr -> bool -(** - Summary: Disable tracing messages tagged as [tag] when Z3 is compiled in debug mode. - It is a NOOP otherwise - def_API('disable_trace', VOID, (_in(STRING),)) -*) -external disable_trace : string -> unit - = "camlidl_z3V3_Z3_disable_trace" - -(** - Summary: Reset all allocated resources. - Use this facility on out-of memory errors. - It allows discharging the previous state and resuming afresh. - Any pointers previously returned by the API - become invalid. - def_API('reset_memory', VOID, ()) -*) -external reset_memory : unit -> unit - = "camlidl_z3V3_Z3_reset_memory" + (** 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. *) + val is_bv_to_int : Expr.expr -> bool -(** - {2 {L External Theory Plugins}} -*) -(** - Summary: Create an interpreted theory sort. -*) -external theory_mk_sort : context -> theory -> symbol -> sort - = "camlidl_z3V3_Z3_theory_mk_sort" + (** 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))) *) + val is_bv_carry : Expr.expr -> bool + + (** 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) *) + val is_bv_xor3 : Expr.expr -> bool -(** - Summary: Create an interpreted theory constant value. Values are assumed to be different from each other. -*) -external theory_mk_value : context -> theory -> symbol -> sort -> ast - = "camlidl_z3V3_Z3_theory_mk_value" + (** The size of a bit-vector sort. *) + val get_size : Sort.sort -> int -(** - Summary: Create an interpreted constant for the given theory. -*) -external theory_mk_constant : context -> theory -> symbol -> sort -> ast - = "camlidl_z3V3_Z3_theory_mk_constant" + (** Retrieve the int value. *) + val get_int : Expr.expr -> int + + (** Returns a string representation of the numeral. *) + val to_string : Expr.expr -> string -(** - Summary: Create an interpreted function declaration for the given theory. -*) -external theory_mk_func_decl : context -> theory -> symbol -> sort array -> sort -> func_decl - = "camlidl_z3V3_Z3_theory_mk_func_decl" + (** Creates a bit-vector constant. *) + val mk_const : context -> Symbol.symbol -> int -> Expr.expr -(** - Summary: Return the context where the given theory is installed. -*) -external theory_get_context : theory -> context - = "camlidl_z3V3_Z3_theory_get_context" - -(** - Summary: Assert a theory axiom/lemmas during the search. - An axiom added at search level [n] will remain in the logical context until - level [n] is backtracked. - The callbacks for push ({!set_push_callback}) and pop - ({!set_pop_callback}) can be used to track when the search - level is increased (i.e., new case-split) and decreased (i.e., - case-split is backtracked). - Z3 tracks the theory axioms asserted. So, multiple assertions of the same axiom are - ignored. -*) -external theory_assert_axiom : theory -> ast -> unit - = "camlidl_z3V3_Z3_theory_assert_axiom" - -(** - Summary: Inform to the logical context that [lhs] and [rhs] have the same interpretation - in the model being built by theory [t]. If lhs = rhs is inconsistent with other theories, - then the logical context will backtrack. - For more information, see the paper "Model-Based Theory Combination" in the Z3 website. -*) -external theory_assume_eq : theory -> ast -> ast -> unit - = "camlidl_z3V3_Z3_theory_assume_eq" - -(** - Summary: Enable/disable the simplification of theory axioms asserted using {!theory_assert_axiom}. - By default, the simplification of theory specific operators is disabled. - That is, the reduce theory callbacks are not invoked for theory axioms. - The default behavior is useful when asserting axioms stating properties of theory operators. -*) -external theory_enable_axiom_simplification : theory -> bool -> unit - = "camlidl_z3V3_Z3_theory_enable_axiom_simplification" + (** Creates a bit-vector constant. *) + val mk_const_s : context -> string -> int -> Expr.expr -(** - Summary: Return the root of the equivalence class containing [n]. -*) -external theory_get_eqc_root : theory -> ast -> ast - = "camlidl_z3V3_Z3_theory_get_eqc_root" - -(** - Summary: Return the next element in the equivalence class containing [n]. - The elements in an equivalence class are organized in a circular list. - You can traverse the list by calling this function multiple times - using the result from the previous call. This is illustrated in the - code snippet below. - {v - ast curr = n; - do - curr = theory_get_eqc_next(theory, curr); - while (curr != n); - v} -*) -external theory_get_eqc_next : theory -> ast -> ast - = "camlidl_z3V3_Z3_theory_get_eqc_next" + (** Bitwise negation. + The argument must have a bit-vector sort. *) + val mk_not : context -> Expr.expr -> Expr.expr -(** - Summary: Return the number of parents of [n] that are operators of the given theory. -*) -external theory_get_num_parents : theory -> ast -> int - = "camlidl_z3V3_Z3_theory_get_num_parents" + (** Take conjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. *) + val mk_redand : context -> Expr.expr -> Expr.expr -(** - Summary: Return the i-th parent of [n]. - See {!theory_get_num_parents}. -*) -external theory_get_parent : theory -> ast -> int -> ast - = "camlidl_z3V3_Z3_theory_get_parent" + (** Take disjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. *) + val mk_redor : context -> Expr.expr -> Expr.expr + + (** Bitwise conjunction. + The arguments must have a bit-vector sort. *) + val mk_and : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Bitwise disjunction. + The arguments must have a bit-vector sort. *) + val mk_or : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Bitwise XOR. + The arguments must have a bit-vector sort. *) + val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Bitwise NAND. + The arguments must have a bit-vector sort. *) + val mk_nand : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Bitwise NOR. + The arguments must have a bit-vector sort. *) + val mk_nor : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Bitwise XNOR. + The arguments must have a bit-vector sort. *) + val mk_xnor : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Standard two's complement unary minus. + The arguments must have a bit-vector sort. *) + val mk_neg : context -> Expr.expr -> Expr.expr + + (** Two's complement addition. + The arguments must have the same bit-vector sort. *) + val mk_add : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Two's complement subtraction. + The arguments must have the same bit-vector sort. *) + val mk_sub : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Two's complement multiplication. + The arguments must have the same bit-vector sort. *) + val mk_mul : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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. *) + val mk_udiv : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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. *) + val mk_sdiv : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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. *) + val mk_urem : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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. *) + val mk_srem : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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. *) + val mk_smod : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Unsigned less-than + + The arguments must have the same bit-vector sort. *) + val mk_ult : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Two's complement signed less-than + + The arguments must have the same bit-vector sort. *) + val mk_slt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Unsigned less-than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_ule : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Two's complement signed less-than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_sle : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Unsigned greater than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_uge : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Two's complement signed greater than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_sge : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Unsigned greater-than. + + The arguments must have the same bit-vector sort. *) + val mk_ugt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Two's complement signed greater-than. + + The arguments must have the same bit-vector sort. *) + val mk_sgt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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). *) + val mk_concat : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Bit-vector extraction. + + Extract the bits between two limits from a bitvector of + size m to yield a new bitvector of size n, where + n = high - low + 1. *) + val mk_extract : context -> int -> int -> Expr.expr -> Expr.expr + + (** 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. *) + val mk_sign_ext : context -> int -> Expr.expr -> Expr.expr + + (** 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. *) + val mk_zero_ext : context -> int -> Expr.expr -> Expr.expr + + (** Bit-vector repetition. *) + val mk_repeat : context -> int -> Expr.expr -> Expr.expr + + (** Shift left. + + It is equivalent to multiplication by 2^x where \c x is the value of third 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.*) + val mk_shl : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Logical shift right + + It is equivalent to unsigned division by 2^x where \c x is the value of the third 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. *) + val mk_lshr : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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. *) + val mk_ashr : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Rotate Left. + Rotate bits of \c t to the left \c i times. *) + val mk_rotate_left : context -> int -> Expr.expr -> Expr.expr + + (** Rotate Right. + Rotate bits of \c t to the right \c i times.*) + val mk_rotate_right : context -> int -> Expr.expr -> Expr.expr + + (** Rotate Left. + Rotate bits of the second argument to the left.*) + val mk_ext_rotate_left : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Rotate Right. + Rotate bits of the second argument to the right. *) + val mk_ext_rotate_right : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** 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 the argument. + 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.*) + val mk_bv2int : context -> Expr.expr -> bool -> Expr.expr + + (** Create a predicate that checks that the bit-wise addition does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_add_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr + + (** Create a predicate that checks that the bit-wise addition does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_add_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create a predicate that checks that the bit-wise subtraction does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_sub_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create a predicate that checks that the bit-wise subtraction does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_sub_no_underflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr + + (** Create a predicate that checks that the bit-wise signed division does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_sdiv_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create a predicate that checks that the bit-wise negation does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_neg_no_overflow : context -> Expr.expr -> Expr.expr + + (** Create a predicate that checks that the bit-wise multiplication does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_mul_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr + + (** Create a predicate that checks that the bit-wise multiplication does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_mul_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create a bit-vector numeral. *) + val mk_numeral : context -> string -> int -> Expr.expr +end + +(** Functions to manipulate proof expressions *) +module Proof : +sig + (** Indicates whether the term is a Proof for the expression 'true'. *) + val is_true : Expr.expr -> bool + + (** Indicates whether the term is a proof for a fact asserted by the user. *) + val is_asserted : Expr.expr -> bool + + (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) + val is_goal : Expr.expr -> bool + + (** 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). *) + val is_modus_ponens : Expr.expr -> bool + + (** 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'. *) + val is_reflexivity : Expr.expr -> bool + + (** 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. *) + val is_symmetry : Expr.expr -> bool + + (** 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) *) + val is_transitivity : Expr.expr -> bool + + (** 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. *) + val is_Transitivity_star : Expr.expr -> bool + + (** 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. *) + val is_monotonicity : Expr.expr -> bool + + (** 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)) *) + val is_quant_intro : Expr.expr -> bool + + (** 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. *) + val is_distributivity : Expr.expr -> bool + + (** 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 *) + val is_and_elimination : Expr.expr -> bool + + (** 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) *) + val is_or_elimination : Expr.expr -> bool + + (** 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 : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) *) + val is_rewrite : Expr.expr -> bool + + (** 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) *) + val is_rewrite_star : Expr.expr -> bool + + (** 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. *) + val is_pull_quant : Expr.expr -> bool + + (** 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 *) + val is_pull_quant_star : Expr.expr -> bool + + (** 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 *) + val is_push_quant : Expr.expr -> bool + + (** 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. *) + val is_elim_unused_vars : Expr.expr -> bool + + (** Indicates whether the term is a proof for destructive equality resolution + + A proof for destructive equality resolution: + (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. + + This proof object has no antecedents. + + Several variables can be eliminated simultaneously. *) + val is_der : Expr.expr -> bool + + (** Indicates whether the term is a proof for quantifier instantiation + + A proof of (or (not (forall (x) (P x))) (P a)) *) + val is_quant_inst : Expr.expr -> bool + + (** Indicates whether the term is a hypthesis marker. + Mark a hypothesis in a natural deduction style proof. *) + val is_hypothesis : Expr.expr -> bool + + (** 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. *) + val is_lemma : Expr.expr -> bool + + (** 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') *) + val is_unit_resolution : Expr.expr -> bool + + (** Indicates whether the term is a proof by iff-true + + T1: p + [iff-true T1]: (iff p true) *) + val is_iff_true : Expr.expr -> bool + + (** Indicates whether the term is a proof by iff-false + + T1: (not p) + [iff-false T1]: (iff p false) *) + val is_iff_false : Expr.expr -> bool + + (** 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. *) + val is_commutativity : Expr.expr -> bool + + (** 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). *) + val is_def_axiom : Expr.expr -> bool + + (** 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) *) + val is_def_intro : Expr.expr -> bool + + (** 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. *) + val is_apply_def : Expr.expr -> bool + + (** Indicates whether the term is a proof iff-oeq + + T1: (iff p q) + [iff~ T1]: (~ p q) *) + val is_iff_oeq : Expr.expr -> bool + + (** 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'. *) + val is_nnf_pos : Expr.expr -> bool + + (** 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'))) *) + val is_nnf_neg : Expr.expr -> bool + + (** 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. *) + val is_nnf_star : Expr.expr -> bool + + (** 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. *) + val is_cnf_star : Expr.expr -> bool + + (** Indicates whether the term is a proof for a Skolemization step + + Proof for: + + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + + This proof object has no antecedents. *) + val is_skolemize : Expr.expr -> bool + + (** 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 *) + val is_modus_ponens_oeq : Expr.expr -> bool + + (** 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. *) + val is_theory_lemma : Expr.expr -> bool +end + +(** Goals + + A goal (aka problem). A goal is essentially a + of formulas, that can be solved and/or transformed using + tactics and solvers. *) +module Goal : +sig + type goal + + (** 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. *) + val get_precision : goal -> Z3enums.goal_prec + + (** Indicates whether the goal is precise. *) + val is_precise : goal -> bool + + (** Indicates whether the goal is an under-approximation. *) + val is_underapproximation : goal -> bool + + (** Indicates whether the goal is an over-approximation. *) + val is_overapproximation : goal -> bool + + (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) + val is_garbage : goal -> bool + + (** Adds the constraints to the given goal. *) + val add : goal -> Expr.expr list -> unit + + (** Indicates whether the goal contains `false'. *) + val is_inconsistent : goal -> bool + + (** The depth of the goal. + This tracks how many transformations were applied to it. *) + val get_depth : goal -> int + + (** Erases all formulas from the given goal. *) + val reset : goal -> unit + + (** The number of formulas in the goal. *) + val get_size : goal -> int + + (** The formulas in the goal. *) + val get_formulas : goal -> Expr.expr list + + (** The number of formulas, subformulas and terms in the goal. *) + val get_num_exprs : goal -> int + + (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) + val is_decided_sat : goal -> bool + + (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) + val is_decided_unsat : goal -> bool + + (** Translates (copies) the Goal to another context.. *) + val translate : goal -> context -> goal + + (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) + val simplify : goal -> Params.params option -> goal + + (** Creates a new Goal. + + Note that the Context must have been created with proof generation support if + the fourth argument is set to true here. *) + val mk_goal : context -> bool -> bool -> bool -> goal + + (** A string representation of the Goal. *) + val to_string : goal -> string +end + +(** Models + + A Model contains interpretations (assignments) of constants and functions. *) +module Model : +sig + type model + + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. *) + module FuncInterp : + sig + type func_interp + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. *) + module FuncEntry : + sig + type func_entry + + (** Return the (symbolic) value of this entry. + *) + val get_value : func_entry -> Expr.expr + + (** The number of arguments of the entry. + *) + val get_num_args : func_entry -> int + + (** The arguments of the function entry. + *) + val get_args : func_entry -> Expr.expr list + + (** A string representation of the function entry. + *) + val to_string : func_entry -> string + end -(** - Summary: Return [TRUE] if [n] is an interpreted theory value. -*) -external theory_is_value : theory -> ast -> bool - = "camlidl_z3V3_Z3_theory_is_value" + (** The number of entries in the function interpretation. *) + val get_num_entries : func_interp -> int -(** - Summary: Return [TRUE] if [d] is an interpreted theory declaration. -*) -external theory_is_decl : theory -> func_decl -> bool - = "camlidl_z3V3_Z3_theory_is_decl" + (** The entries in the function interpretation *) + val get_entries : func_interp -> FuncEntry.func_entry list -(** - Summary: Return the number of expressions of the given theory in - the logical context. These are the expressions notified using the - callback {!set_new_elem_callback}. -*) -external theory_get_num_elems : theory -> int - = "camlidl_z3V3_Z3_theory_get_num_elems" + (** The (symbolic) `else' value of the function interpretation. *) + val get_else : func_interp -> Expr.expr -(** - Summary: Return the i-th elem of the given theory in the logical context. - - {b See}: {!theory_get_num_elems} -*) -external theory_get_elem : theory -> int -> ast - = "camlidl_z3V3_Z3_theory_get_elem" + (** The arity of the function interpretation *) + val get_arity : func_interp -> int -(** - Summary: Return the number of theory applications in the logical - context. These are the expressions notified using the callback - {!set_new_app_callback}. -*) -external theory_get_num_apps : theory -> int - = "camlidl_z3V3_Z3_theory_get_num_apps" + (** A string representation of the function interpretation. *) + val to_string : func_interp -> string + end -(** - Summary: Return the i-th application of the given theory in the logical context. - - {b See}: {!theory_get_num_apps} -*) -external theory_get_app : theory -> int -> ast - = "camlidl_z3V3_Z3_theory_get_app" + (** Retrieves the interpretation (the assignment) of a func_decl in the model. + An expression if the function has an interpretation in the model, null otherwise. *) + val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option -<<<<<<< HEAD -(** - {2 {L Deprecated Injective functions API}} -*) -(** - Summary: Create injective function declaration - @deprecated This method just asserts a (universally quantified) formula that asserts that - the new function is injective. It is compatible with the old interface for solving: - {!assert_cnstr}, {!check_assumptions}, etc. - def_API('mk_injective_function', FUNC_DECL, (_in(CONTEXT), _in(SYMBOL), _in(UINT), _in_array(2, SORT), _in(SORT))) -*) -external mk_injective_function : context -> symbol -> sort array -> sort -> func_decl - = "camlidl_z3V3_Z3_mk_injective_function" + (** Retrieves the interpretation (the assignment) of an expression in the model. + An expression if the constant has an interpretation in the model, null otherwise. *) + val get_const_interp_e : model -> Expr.expr -> Expr.expr option -(** - {2 {L Deprecated Constraints API}} -*) -(** - Summary: Set the SMTLIB logic to be used in the given logical context. - It is incorrect to invoke this function after invoking - {!check}, {!check_and_get_model}, {!check_assumptions} and {!push}. - Return [TRUE] if the logic was changed successfully, and [FALSE] otherwise. - @deprecated Subsumed by {!mk_solver_for_logic} - def_API('set_logic', VOID, (_in(CONTEXT), _in(STRING))) -*) -external set_logic : context -> string -> bool - = "camlidl_z3V3_Z3_set_logic" - -(** - Summary: Create a backtracking point. - The logical context can be viewed as a stack of contexts. The - scope level is the number of elements on this stack. The stack - of contexts is simulated using trail (undo) stacks. - - {b See also}: {!pop} - @deprecated Subsumed by {!solver_push} - def_API('push', VOID, (_in(CONTEXT),)) -*) -external push : context -> unit - = "camlidl_z3V3_Z3_push" - -(** - Summary: Backtrack. - Restores the context from the top of the stack, and pops it off the - stack. Any changes to the logical context (by {!assert_cnstr} or - other functions) between the matching {!push} and [pop] - operators are flushed, and the context is completely restored to - what it was right before the {!push}. - - {b See also}: {!push} - @deprecated Subsumed by {!solver_pop} - def_API('pop', VOID, (_in(CONTEXT), _in(UINT))) -*) -external pop : context -> int -> unit - = "camlidl_z3V3_Z3_pop" - -(** - Summary: Retrieve the current scope level. - It retrieves the number of scopes that have been pushed, but not yet popped. - - {b See also}: {!push} - - {b See also}: {!pop} - @deprecated Subsumed by {!solver_get_num_scopes}. - def_API('get_num_scopes', UINT, (_in(CONTEXT),)) -*) -external get_num_scopes : context -> int - = "camlidl_z3V3_Z3_get_num_scopes" + (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option -(** - @deprecated This function has no effect. - def_API('persist_ast', VOID, (_in(CONTEXT), _in(AST), _in(UINT))) -*) -external persist_ast : context -> ast -> int -> unit - = "camlidl_z3V3_Z3_persist_ast" - -(** - Summary: Assert a constraint into the logical context. - After one assertion, the logical context may become - inconsistent. - The functions {!check} or {!check_and_get_model} should be - used to check whether the logical context is consistent or not. - - {b See also}: {!check} - - {b See also}: {!check_and_get_model} - @deprecated Subsumed by {!solver_assert} - def_API('assert_cnstr', VOID, (_in(CONTEXT), _in(AST))) -*) -external assert_cnstr : context -> ast -> unit - = "camlidl_z3V3_Z3_assert_cnstr" - -(** - Summary: Check whether the given logical context is consistent or not. - If the logical context is not unsatisfiable (i.e., the return value is different from [L_FALSE)] - and model construction is enabled (see {!mk_config}), - then a valid model is returned. Otherwise, it is unsafe to use the returned model. - - {b Remarks}: Model construction must be enabled using configuration - parameters (See, {!mk_config}). - - {b See also}: {!check} - @deprecated Subsumed by {!solver_check} - def_API('check_and_get_model', INT, (_in(CONTEXT), _out(MODEL))) -*) -external check_and_get_model : context -> lbool * model - = "camlidl_z3V3_Z3_check_and_get_model" - -(** - Summary: Check whether the given logical context is consistent or not. - The function {!check_and_get_model} should be used when models are needed. - - {b See also}: {!check_and_get_model} - @deprecated Subsumed by {!solver_check} - def_API('check', INT, (_in(CONTEXT),)) -*) -external check : context -> lbool - = "camlidl_z3V3_Z3_check" - -(** - Summary: Check whether the given logical context and optional assumptions is consistent or not. - If the logical context is not unsatisfiable (i.e., the return value is different from [L_FALSE)], - and model construction is enabled (see {!mk_config}), - then a valid model is returned. Otherwise, it is unsafe to use the returned model. - @param c logical context. - @param num_assumptions number of auxiliary assumptions. - @param assumptions array of auxiliary assumptions - @param m optional pointer to a model. - @param proof optional pointer to a proof term. - @param core_size size of unsatisfiable core. - @param core pointer to an array receiving unsatisfiable core. - The unsatisfiable core is a subset of the assumptions, so the array has the same size as the assumptions. - The [core] array is not populated if [core_size] is set to 0. - - {b Precondition}: assumptions comprises of propositional literals. - In other words, you cannot use compound formulas for assumptions, - but should use propositional variables or negations of propositional variables. - - {b See also}: {!check} - @deprecated Subsumed by {!solver_check_assumptions} - def_API('check_assumptions', INT, (_in(CONTEXT), _in(UINT), _in_array(1, AST), _out(MODEL), _out(AST), _out(UINT), _out_array2(1, 5, AST))) -*) -external check_assumptions : context -> ast array -> int -> ast array -> lbool * model * ast * int * ast array - = "camlidl_z3V3_Z3_check_assumptions" - -(** - Summary: Delete a model object. - - {b See also}: {!check_and_get_model} - @deprecated Subsumed by solver API - def_API('del_model', VOID, (_in(CONTEXT), _in(MODEL))) -*) -external del_model : context -> model -> unit - = "camlidl_z3V3_Z3_del_model" + (** The number of constant interpretations in the model. *) + val get_num_consts : model -> int -(** - {2 {L Deprecated Search control API}} -*) -(** - Summary: Cancel an ongoing check. - Notifies the current check to abort and return. - This method should be called from a different thread - than the one performing the check. - @deprecated Use {!interrupt} instead. - def_API('soft_check_cancel', VOID, (_in(CONTEXT), )) -*) -external soft_check_cancel : context -> unit - = "camlidl_z3V3_Z3_soft_check_cancel" - -(** - Summary: Retrieve reason for search failure. - If a call to {!check} or {!check_and_get_model} returns L_UNDEF, - use this facility to determine the more detailed cause of search failure. - @deprecated Subsumed by {!solver_get_reason_unknown} - def_API('get_search_failure', UINT, (_in(CONTEXT), )) -*) -external get_search_failure : context -> search_failure - = "camlidl_z3V3_Z3_get_search_failure" + (** The function declarations of the constants in the model. *) + val get_const_decls : model -> FuncDecl.func_decl list -(** - {2 {L Deprecated Labels API}} -*) -(** - Summary: Create a labeled formula. - @param c logical context. - @param s name of the label. - @param is_pos label polarity. - @param f formula being labeled. - A label behaves as an identity function, so the truth value of the - labeled formula is unchanged. Labels are used for identifying - useful sub-formulas when generating counter-examples. - @deprecated Labels are only supported by the old Solver API. - This feature is not essential (it can be simulated using auxiliary Boolean variables). - It is only available for backward compatibility. - def_API('mk_label', AST, (_in(CONTEXT), _in(SYMBOL), _in(BOOL), _in(AST))) -*) -external mk_label : context -> symbol -> bool -> ast -> ast - = "camlidl_z3V3_Z3_mk_label" - -(** - Summary: Retrieve the set of labels that were relevant in - the context of the current satisfied context. - - {b See also}: {!del_literals} - - {b See also}: {!get_num_literals} - - {b See also}: {!get_label_symbol} - - {b See also}: {!get_literal} - @deprecated This procedure is based on the old Solver API. - def_API('get_relevant_labels', LITERALS, (_in(CONTEXT), )) -*) -external get_relevant_labels : context -> literals - = "camlidl_z3V3_Z3_get_relevant_labels" - -(** - Summary: Retrieve the set of literals that satisfy the current context. - - {b See also}: {!del_literals} - - {b See also}: {!get_num_literals} - - {b See also}: {!get_label_symbol} - - {b See also}: {!get_literal} - @deprecated This procedure is based on the old Solver API. - def_API('get_relevant_literals', LITERALS, (_in(CONTEXT), )) -*) -external get_relevant_literals : context -> literals - = "camlidl_z3V3_Z3_get_relevant_literals" - -(** - Summary: Retrieve the set of literals that whose assignment were - guess, but not propagated during the search. - - {b See also}: {!del_literals} - - {b See also}: {!get_num_literals} - - {b See also}: {!get_label_symbol} - - {b See also}: {!get_literal} - @deprecated This procedure is based on the old Solver API. - def_API('get_guessed_literals', LITERALS, (_in(CONTEXT), )) -*) -external get_guessed_literals : context -> literals - = "camlidl_z3V3_Z3_get_guessed_literals" - -(** - Summary: Delete a labels context. - - {b See also}: {!get_relevant_labels} - @deprecated This procedure is based on the old Solver API. - def_API('del_literals', VOID, (_in(CONTEXT), _in(LITERALS))) -*) -external del_literals : context -> literals -> unit - = "camlidl_z3V3_Z3_del_literals" - -(** - Summary: Retrieve the number of label symbols that were returned. - - {b See also}: {!get_relevant_labels} - @deprecated This procedure is based on the old Solver API. - def_API('get_num_literals', UINT, (_in(CONTEXT), _in(LITERALS))) -*) -external get_num_literals : context -> literals -> int - = "camlidl_z3V3_Z3_get_num_literals" + (** The number of function interpretations in the model. *) + val get_num_funcs : model -> int -(** - Summary: Retrieve label symbol at idx. - @deprecated This procedure is based on the old Solver API. - def_API('get_label_symbol', SYMBOL, (_in(CONTEXT), _in(LITERALS), _in(UINT))) -*) -external get_label_symbol : context -> literals -> int -> symbol - = "camlidl_z3V3_Z3_get_label_symbol" + (** The function declarations of the function interpretations in the model. *) + val get_func_decls : model -> FuncDecl.func_decl list -(** - Summary: Retrieve literal expression at idx. - @deprecated This procedure is based on the old Solver API. - def_API('get_literal', AST, (_in(CONTEXT), _in(LITERALS), _in(UINT))) -*) -external get_literal : context -> literals -> int -> ast - = "camlidl_z3V3_Z3_get_literal" - -(** - Summary: Disable label. - The disabled label is not going to be used when blocking the subsequent search. - - {b See also}: {!block_literals} - @deprecated This procedure is based on the old Solver API. - def_API('disable_literal', VOID, (_in(CONTEXT), _in(LITERALS), _in(UINT))) -*) -external disable_literal : context -> literals -> int -> unit - = "camlidl_z3V3_Z3_disable_literal" + (** All symbols that have an interpretation in the model. *) + val get_decls : model -> FuncDecl.func_decl list -(** - Summary: Block subsequent checks using the remaining enabled labels. - @deprecated This procedure is based on the old Solver API. - def_API('block_literals', VOID, (_in(CONTEXT), _in(LITERALS))) -*) -external block_literals : context -> literals -> unit - = "camlidl_z3V3_Z3_block_literals" + (** Evaluates an expression in the current model. + + This function may fail if the argument contains quantifiers, + is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. + In this case a ModelEvaluationFailedException is thrown. + *) + val eval : model -> Expr.expr -> bool -> Expr.expr option -(** - {2 {L Deprecated Model API}} -*) -(** - Summary: Return the number of constants assigned by the given model. - - {b Remarks}: Consider using {!get_model_constants}. - - {b See also}: {!get_model_constant} - @deprecated use {!model_get_num_consts} - def_API('get_model_num_constants', UINT, (_in(CONTEXT), _in(MODEL))) -*) -external get_model_num_constants : context -> model -> int - = "camlidl_z3V3_Z3_get_model_num_constants" - -(** - Summary: \[ [ get_model_constant c m i ] \] - Return the i-th constant in the given model. - - {b Remarks}: Consider using {!get_model_constants}. - - {b Precondition}: i < get_model_num_constants c m - @deprecated use {!model_get_const_decl} - def_API('get_model_constant', FUNC_DECL, (_in(CONTEXT), _in(MODEL), _in(UINT))) -*) -external get_model_constant : context -> model -> int -> func_decl - = "camlidl_z3V3_Z3_get_model_constant" - -(** - Summary: Return the number of function interpretations in the given model. - 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. - @deprecated use {!model_get_num_funcs} - def_API('get_model_num_funcs', UINT, (_in(CONTEXT), _in(MODEL))) -*) -external get_model_num_funcs : context -> model -> int - = "camlidl_z3V3_Z3_get_model_num_funcs" - -(** - Summary: \[ [ get_model_func_decl c m i ] \] - Return the declaration of the i-th function in the given model. - - {b Precondition}: i < get_model_num_funcs c m - - {b See also}: {!get_model_num_funcs} - @deprecated use {!model_get_func_decl} - def_API('get_model_func_decl', FUNC_DECL, (_in(CONTEXT), _in(MODEL), _in(UINT))) + (** Alias for eval. *) + val evaluate : model -> Expr.expr -> bool -> Expr.expr option + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + val get_num_sorts : model -> int + + (** 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. + {!get_num_sorts} + {!sort_universe} *) + val get_sorts : model -> Sort.sort list + + (** The finite set of distinct values that represent the interpretation of a sort. + {!get_sorts} + @returns A list of expressions, where each is an element of the universe of the sort *) + val sort_universe : model -> Sort.sort -> AST.ast list + + (** Conversion of models to strings. + A string representation of the model. *) + val to_string : model -> string +end + +(** Probes + + 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. *) -external get_model_func_decl : context -> model -> int -> func_decl - = "camlidl_z3V3_Z3_get_model_func_decl" - -(** - Summary: Return the value of the given constant or function - in the given model. - @deprecated Consider using {!model_eval} or {!model_get_func_interp} - def_API('eval_func_decl', BOOL, (_in(CONTEXT), _in(MODEL), _in(FUNC_DECL), _out(AST))) +module Probe : +sig + type probe + + (** Execute the probe over the goal. + A probe always produce a float value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) + val apply : probe -> Goal.goal -> float + + (** The number of supported Probes. *) + val get_num_probes : context -> int + + (** The names of all supported Probes. *) + val get_probe_names : context -> string list + + (** Returns a string containing a description of the probe with the given name. *) + val get_probe_description : context -> string -> string + + (** Creates a new Probe. *) + val mk_probe : context -> string -> probe + + (** Create a probe that always evaluates to a float value. *) + val const : context -> float -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is less than the value returned by second argument *) + val lt : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is greater than the value returned by second argument *) + val gt : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is less than or equal the value returned by second argument *) + val le : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is greater than or equal the value returned by second argument *) + val ge : context -> probe -> probe -> probe + + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is equal the value returned by second argument *) + val eq : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when both of two probes evaluate to "true". *) + val and_ : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when either of two probes evaluates to "true". *) + val or_ : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when another probe does not evaluate to "true". *) + val not_ : context -> probe -> probe +end + +(** Tactics + + Tactics are the basic building block for creating custom solvers for specific problem domains. + The complete list of tactics may be obtained using Context.get_num_tactics + and Context.get_tactic_names. + It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. *) -external eval_func_decl : context -> model -> func_decl -> bool * ast - = "camlidl_z3V3_Z3_eval_func_decl" -======= +module Tactic : +sig + type tactic + + (** Tactic application results + + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) + module ApplyResult : + sig + type apply_result + + (** The number of Subgoals. *) + val get_num_subgoals : apply_result -> int + + (** Retrieves the subgoals from the apply_result. *) + val get_subgoals : apply_result -> Goal.goal list + + (** Retrieves a subgoal from the apply_result. *) + val get_subgoal : apply_result -> int -> Goal.goal + + (** Convert a model for a subgoal into a model for the original + goal g, that the ApplyResult was obtained from. + #return A model for g *) + val convert_model : apply_result -> int -> Model.model -> Model.model + + (** A string representation of the ApplyResult. *) + val to_string : apply_result -> string + end + + (** A string containing a description of parameters accepted by the tactic. *) + val get_help : tactic -> string + + (** Retrieves parameter descriptions for Tactics. *) + val get_param_descrs : tactic -> Params.ParamDescrs.param_descrs + + (** Apply the tactic to the goal. *) + val apply : tactic -> Goal.goal -> Params.params option -> ApplyResult.apply_result + + (** The number of supported tactics. *) + val get_num_tactics : context -> int + + (** The names of all supported tactics. *) + val get_tactic_names : context -> string list + + (** Returns a string containing a description of the tactic with the given name. *) + val get_tactic_description : context -> string -> string + + (** Creates a new Tactic. *) + val mk_tactic : context -> string -> tactic + + (** Create a tactic that applies one tactic to a Goal and + then another one to every subgoal produced by the first one. *) + val and_then : context -> tactic -> tactic -> tactic list -> tactic + + (** Create a tactic that first applies one tactic to a Goal and + if it fails then returns the result of another tactic applied to the Goal. *) + val or_else : context -> tactic -> tactic -> tactic + + (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). + + If the tactic does not terminate within the timeout, then it fails. *) + val try_for : context -> tactic -> int -> tactic + + (** Create a tactic that applies one tactic to a given goal if the probe + evaluates to true. + + If the probe evaluates to false, then the new tactic behaves like the skip tactic. *) + val when_ : context -> Probe.probe -> tactic -> tactic + + (** Create a tactic that applies a tactic to a given goal if the probe + evaluates to true and another tactic otherwise. *) + val cond : context -> Probe.probe -> tactic -> tactic -> tactic + + (** Create a tactic that keeps applying one tactic until the goal is not + modified anymore or the maximum number of iterations is reached. *) + val repeat : context -> tactic -> int -> tactic + + (** Create a tactic that just returns the given goal. *) + val skip : context -> tactic + + (** Create a tactic always fails. *) + val fail : context -> tactic + + (** Create a tactic that fails if the probe evaluates to false. *) + val fail_if : context -> Probe.probe -> tactic + + (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) + or trivially unsatisfiable (i.e., contains `false'). *) + val fail_if_not_decided : context -> tactic + + (** Create a tactic that applies a tactic using the given set of parameters. *) + val using_params : context -> tactic -> Params.params -> tactic + + (** Create a tactic that applies a tactic using the given set of parameters. + Alias for UsingParams*) + val with_ : context -> tactic -> Params.params -> tactic + + (** Create a tactic that applies the given tactics in parallel. *) + val par_or : context -> tactic list -> tactic + + (** Create a tactic that applies a tactic to a given goal and then another tactic + to every subgoal produced by the first one. The subgoals are processed in parallel. *) + val par_and_then : context -> tactic -> tactic -> tactic + + (** Interrupt the execution of a Z3 procedure. + This procedure can be used to interrupt: solvers, simplifiers and tactics. *) + val interrupt : context -> unit +end + +(** Solvers *) +module Solver : +sig + type solver + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + + val string_of_status : status -> string + + (** Objects that track statistical information about solvers. *) + module Statistics : + sig + type statistics + + (** Statistical data is organized into pairs of \[Key, Entry\], where every + Entry is either a floating point or integer value. + *) + module Entry : + sig + type statistics_entry + + (** The key of the entry. *) + val get_key : statistics_entry -> string + + (** The int-value of the entry. *) + val get_int : statistics_entry -> int + + (** The float-value of the entry. *) + val get_float : statistics_entry -> float + + (** True if the entry is uint-valued. *) + val is_int : statistics_entry -> bool + + (** True if the entry is float-valued. *) + val is_float : statistics_entry -> bool + + (** The string representation of the the entry's value. *) + val to_string_value : statistics_entry -> string + + (** The string representation of the entry (key and value) *) + val to_string : statistics_entry -> string + end + + (** A string representation of the statistical data. *) + val to_string : statistics -> string + + (** The number of statistical data. *) + val get_size : statistics -> int + + (** The data entries. *) + val get_entries : statistics -> Entry.statistics_entry list + + (** The statistical counters. *) + val get_keys : statistics -> string list + + (** The value of a particular statistical counter. *) + val get : statistics -> string -> Entry.statistics_entry option + end + + (** A string that describes all available solver parameters. *) + val get_help : solver -> string + + (** Sets the solver parameters. *) + val set_parameters : solver -> Params.params -> unit + + (** Retrieves parameter descriptions for solver. *) + val get_param_descrs : solver -> Params.ParamDescrs.param_descrs + + (** The current number of backtracking points (scopes). + {!pop} + {!push} *) + val get_num_scopes : solver -> int + + (** Creates a backtracking point. + {!pop} *) + val push : solver -> unit + + (** Backtracks a number of backtracking points. + Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} + {!push} *) + val pop : solver -> int -> unit + + (** Resets the Solver. + This removes all assertions from the solver. *) + val reset : solver -> unit + + (** Assert a constraint (or multiple) into the solver. *) + val add : solver -> Expr.expr list -> unit + + (** * Assert multiple constraints (cs) into the solver, and track them (in the + * unsat) core + * using the Boolean constants in ps. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) + val assert_and_track_l : solver -> Expr.expr list -> Expr.expr list -> unit + + (** * Assert a constraint (c) into the solver, and track it (in the unsat) core + * using the Boolean constant p. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) + val assert_and_track : solver -> Expr.expr -> Expr.expr -> unit + + (** The number of assertions in the solver. *) + val get_num_assertions : solver -> int + + (** The set of asserted formulas. *) + val get_assertions : solver -> Expr.expr list + + (** Checks whether the assertions in the solver are consistent or not. + + {!Model} + {!get_unsat_core} + {!Proof} *) + val check : solver -> Expr.expr list -> status + + (** The model of the last Check. + + The result is None if Check was not invoked before, + if its results was not SATISFIABLE, or if model production is not enabled. *) + val get_model : solver -> Model.model option + + (** 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. *) + val get_proof : solver -> Expr.expr option + + (** 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. *) + val get_unsat_core : solver -> AST.ast list + + (** A brief justification of why the last call to Check returned UNKNOWN. *) + val get_reason_unknown : solver -> string + + (** Solver statistics. *) + val get_statistics : solver -> Statistics.statistics + + (** 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. *) + val mk_solver : context -> Symbol.symbol option -> solver + + (** Creates a new (incremental) solver. + {!mk_solver} *) + val mk_solver_s : context -> string -> solver + + (** Creates a new (incremental) solver. *) + val mk_simple_solver : context -> solver + + (** 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. *) + val mk_solver_t : context -> Tactic.tactic -> solver + + (** A string representation of the solver. *) + val to_string : solver -> string +end + +(** Fixedpoint solving *) +module Fixedpoint : +sig + type fixedpoint + + (** A string that describes all available fixedpoint solver parameters. *) + val get_help : fixedpoint -> string + + (** Sets the fixedpoint solver parameters. *) + val set_params : fixedpoint -> Params.params -> unit + + (** Retrieves parameter descriptions for Fixedpoint solver. *) + val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs + + (** Assert a constraints into the fixedpoint solver. *) + val add : fixedpoint -> Expr.expr list -> unit + + (** Register predicate as recursive relation. *) + val register_relation : fixedpoint -> FuncDecl.func_decl -> unit + + (** Add rule into the fixedpoint solver. *) + val add_rule : fixedpoint -> Expr.expr -> Symbol.symbol option -> unit + + (** Add table fact to the fixedpoint solver. *) + val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit + + (** 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. *) + val query : fixedpoint -> Expr.expr -> Solver.status + + (** 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. *) + val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status + + (** Creates a backtracking point. + {!pop} *) + val push : fixedpoint -> unit + + (** Backtrack one backtracking point. + + Note that an exception is thrown if Pop is called without a corresponding Push + {!push} *) + val pop : fixedpoint -> unit + + (** Update named rule into in the fixedpoint solver. *) + val update_rule : fixedpoint -> Expr.expr -> Symbol.symbol -> unit + + (** Retrieve satisfying instance or instances of solver, + or definitions for the recursive predicates that show unsatisfiability. *) + val get_answer : fixedpoint -> Expr.expr option + + (** Retrieve explanation why fixedpoint engine returned status Unknown. *) + val get_reason_unknown : fixedpoint -> string + + (** Retrieve the number of levels explored for a given predicate. *) + val get_num_levels : fixedpoint -> FuncDecl.func_decl -> int + + (** Retrieve the cover of a predicate. *) + val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option + + (** Add property about the predicate. + The property is added at level. *) + val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit + + (** Retrieve internal string representation of fixedpoint object. *) + val to_string : fixedpoint -> string + + (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) + val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol list -> unit + + (** Convert benchmark given as set of axioms, rules and queries to a string. *) + val to_string_q : fixedpoint -> Expr.expr list -> string + + (** Retrieve set of rules added to fixedpoint context. *) + val get_rules : fixedpoint -> Expr.expr list + + (** Retrieve set of assertions added to fixedpoint context. *) + val get_assertions : fixedpoint -> Expr.expr list + + (** Create a Fixedpoint context. *) + val mk_fixedpoint : context -> fixedpoint +end + (** Functions for handling SMT and SMT2 expressions and files *) module SMT : sig (** Convert a benchmark into an SMT-LIB formatted string. ->>>>>>> Updates to ML API. -(** - Summary: \[ [ is_array_value c v ] \] - Determine whether the term encodes an array value. - A term encodes an array value if it is a nested sequence of - applications of store on top of a constant array. - The indices to the stores have to be values (for example, integer constants) - so that equality between the indices can be evaluated. - Array values are useful for representing interpretations for arrays. - Return the number of entries mapping to non-default values of the array. - @deprecated Use {!is_as_array} - def_API('is_array_value', BOOL, (_in(CONTEXT), _in(MODEL), _in(AST), _out(UINT))) -*) -external is_array_value : context -> model -> ast -> bool * int - = "camlidl_z3V3_Z3_is_array_value" + @return A string representation of the benchmark. *) + val benchmark_to_smtstring : context -> string -> string -> string -> string -> Expr.expr list -> Expr.expr -> string -(** - Summary: \[ [ get_array_value c v ] \] - An array values is represented as a dictionary plus a - default (else) value. This function returns the array graph. - - {b Precondition}: TRUE == is_array_value c v &num_entries - @deprecated Use func_interp objects and {!get_as_array_func_decl} - def_API('get_array_value', VOID, (_in(CONTEXT), _in(MODEL), _in(AST), _in(UINT), _out_array(3, AST), _out_array(3, AST), _out (AST))) -*) -external get_array_value : context -> model -> ast -> ast array -> ast array -> ast array * ast array * ast - = "camlidl_z3V3_Z3_get_array_value" + (** 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 in the third and fifth argument + don't need to match the names of the sorts and declarations in the arrays in the fourth + and sixth argument. This is a useful feature since we can use arbitrary names to + reference sorts and declarations. *) + val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit -(** - Summary: \[ [ get_model_func_else c m i ] \] - Return the 'else' value of the i-th function interpretation in the given model. - A function interpretation is represented as a finite map and an 'else' value. - - {b Remarks}: Consider using {!get_model_funcs}. - - {b Precondition}: i < get_model_num_funcs c m - - {b See also}: {!get_model_num_funcs} - - {b See also}: {!get_model_func_num_entries} - - {b See also}: {!get_model_func_entry_num_args} - - {b See also}: {!get_model_func_entry_arg} - @deprecated Use func_interp objects - def_API('get_model_func_else', AST, (_in(CONTEXT), _in(MODEL), _in(UINT))) -*) -external get_model_func_else : context -> model -> int -> ast - = "camlidl_z3V3_Z3_get_model_func_else" + (** Parse the given file using the SMT-LIB parser. + {!parse_smtlib_string} *) + val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit -(** - Summary: \[ [ get_model_func_num_entries c m i ] \] - Return the number of entries of the i-th function interpretation in the given model. - A function interpretation is represented as a finite map and an 'else' value. - - {b Remarks}: Consider using {!get_model_funcs}. - - {b Precondition}: i < get_model_num_funcs c m - - {b See also}: {!get_model_num_funcs} - - {b See also}: {!get_model_func_else} - - {b See also}: {!get_model_func_entry_num_args} - - {b See also}: {!get_model_func_entry_arg} - @deprecated Use func_interp objects - def_API('get_model_func_num_entries', UINT, (_in(CONTEXT), _in(MODEL), _in(UINT))) -*) -external get_model_func_num_entries : context -> model -> int -> int - = "camlidl_z3V3_Z3_get_model_func_num_entries" + (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_formulas : context -> int -(** - Summary: \[ [ get_model_func_entry_num_args c m i j ] \] - Return the number of arguments of the j-th entry of the i-th function interpretation in the given - model. - A function interpretation is represented as a finite map and an 'else' value. - This function returns the j-th entry of this map. - An entry represents the value of a function given a set of arguments. - - {b Remarks}: Consider using {!get_model_funcs}. - - {b Precondition}: i < get_model_num_funcs c m - - {b Precondition}: j < get_model_func_num_entries c m i - - {b See also}: {!get_model_num_funcs} - - {b See also}: {!get_model_func_num_entries } - - {b See also}: {!get_model_func_entry_arg} - @deprecated Use func_interp objects - def_API('get_model_func_entry_num_args', UINT, (_in(CONTEXT), _in(MODEL), _in(UINT), _in(UINT))) -*) -external get_model_func_entry_num_args : context -> model -> int -> int -> int - = "camlidl_z3V3_Z3_get_model_func_entry_num_args" + (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_formulas : context -> Expr.expr list -(** - Summary: \[ [ get_model_func_entry_arg c m i j k ] \] - Return the k-th argument of the j-th entry of the i-th function interpretation in the given - model. - A function interpretation is represented as a finite map and an 'else' value. - This function returns the j-th entry of this map. - An entry represents the value of a function given a set of arguments. - - {b Remarks}: Consider using {!get_model_funcs}. - - {b Precondition}: i < get_model_num_funcs c m - - {b Precondition}: j < get_model_func_num_entries c m i - - {b Precondition}: k < get_model_func_entry_num_args c m i j - - {b See also}: {!get_model_num_funcs} - - {b See also}: {!get_model_func_num_entries } - - {b See also}: {!get_model_func_entry_num_args} - @deprecated Use func_interp objects - def_API('get_model_func_entry_arg', AST, (_in(CONTEXT), _in(MODEL), _in(UINT), _in(UINT), _in(UINT))) -*) -external get_model_func_entry_arg : context -> model -> int -> int -> int -> ast - = "camlidl_z3V3_Z3_get_model_func_entry_arg" + (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_assumptions : context -> int -(** - Summary: \[ [ get_model_func_entry_value c m i j ] \] - Return the return value of the j-th entry of the i-th function interpretation in the given - model. - A function interpretation is represented as a finite map and an 'else' value. - This function returns the j-th entry of this map. - An entry represents the value of a function given a set of arguments. - - {b Remarks}: Consider using {!get_model_funcs}. - - {b Precondition}: i < get_model_num_funcs c m - - {b Precondition}: j < get_model_func_num_entries c m i - - {b See also}: {!get_model_num_funcs} - - {b See also}: {!get_model_func_num_entries } - @deprecated Use func_interp objects - def_API('get_model_func_entry_value', AST, (_in(CONTEXT), _in(MODEL), _in(UINT), _in(UINT))) -*) -external get_model_func_entry_value : context -> model -> int -> int -> ast - = "camlidl_z3V3_Z3_get_model_func_entry_value" + (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_assumptions : context -> Expr.expr list -(** - Summary: \[ [ eval c m t ] \] - Evaluate the AST node [t] in the given model. - Return a pair: Boolean and value. The Boolean is true if the term was successfully evaluated. - The evaluation may fail for the following reasons: - - [t] contains a quantifier. - - the model [m] is partial, that is, it doesn't have a complete interpretation for uninterpreted functions. - That is, the option {e MODEL_PARTIAL=true } was used. - - [t] is type incorrect. - @deprecated Use {!model_eval} - def_API('eval', BOOL, (_in(CONTEXT), _in(MODEL), _in(AST), _out(AST))) -*) -external eval : context -> model -> ast -> bool * ast - = "camlidl_z3V3_Z3_eval" + (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_decls : context -> int -(** - Summary: Evaluate declaration given values. - Provides direct way to evaluate declarations - without going over terms. - @deprecated Consider using {!model_eval} and {!substitute_vars} - def_API('eval_decl', BOOL, (_in(CONTEXT), _in(MODEL), _in(FUNC_DECL), _in(UINT), _in_array(3, AST), _out(AST))) -*) -external eval_decl : context -> model -> func_decl -> ast array -> bool * ast - = "camlidl_z3V3_Z3_eval_decl" + (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_decls : context -> FuncDecl.func_decl list -(** - {2 {L Deprecated String conversion API}} -*) -(** - Summary: Convert the given logical context into a string. - This function is mainly used for debugging purposes. It displays - the internal structure of a logical context. - @deprecated This method is obsolete. It just displays the internal representation of - the global solver available for backward compatibility reasons. - def_API('context_to_string', STRING, (_in(CONTEXT),)) -*) -external context_to_string : context -> string - = "camlidl_z3V3_Z3_context_to_string" + (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_sorts : context -> int -(** - Summary: Return runtime statistics as a string. - This function is mainly used for debugging purposes. It displays - statistics of the search activity. - @deprecated This method is based on the old solver API. - Use {!stats_to_string} when using the new solver API. - def_API('statistics_to_string', STRING, (_in(CONTEXT),)) -*) -external statistics_to_string : context -> string - = "camlidl_z3V3_Z3_statistics_to_string" + (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_sorts : context -> Sort.sort list -(** - Summary: Extract satisfying assignment from context as a conjunction. - This function can be used for debugging purposes. It returns a conjunction - of formulas that are assigned to true in the current context. - This conjunction will contain not only the assertions that are set to true - under the current assignment, but will also include additional literals - if there has been a call to {!check} or {!check_and_get_model}. - @deprecated This method is based on the old solver API. - def_API('get_context_assignment', AST, (_in(CONTEXT),)) -*) -external get_context_assignment : context -> ast - = "camlidl_z3V3_Z3_get_context_assignment" - - -(** {2 {L ML Extensions}} *) -(** - \[ [ mk_context_x configs] \] is a shorthand for the context with configurations in [configs]. -*) -val mk_context_x: (string * string) array -> context;; -(** - \[ [ get_app_args c a ] \] is the array of arguments of an application. If [t] is a constant, then the array is empty. - - {b See also}: {!get_app_num_args} - - {b See also}: {!get_app_arg} -*) -val get_app_args: context -> app -> ast array -(** - \[ [ get_app_args c d ] \] is the array of parameters of [d]. - - {b See also}: {!get_domain_size} - - {b See also}: {!get_domain} -*) -val get_domains: context -> func_decl -> sort array -(** - \[ [ get_array_sort c t ] \] is the domain and the range of [t]. - - {b See also}: {!get_array_sort_domain} - - {b See also}: {!get_array_sort_range} -*) -val get_array_sort: context -> sort -> sort * sort -(** - \[ [ get_tuple_sort c ty ] \] is the pair [(mk_decl, fields)] where [mk_decl] is the constructor declaration of [ty], and [fields] is the array of fields in [ty]. - - {b See also}: {!get_tuple_sort_mk_decl} - - {b See also}: {!get_tuple_sort_num_fields} - - {b See also}: {!get_tuple_sort_field_decl} -*) -val get_tuple_sort: context -> sort -> (func_decl * func_decl array) -(** - \[ [ datatype_constructor_refined ] \] is the refinement of a datatype constructor. - It contains the constructor declaration, recognizer, and list of accessor functions. -*) -type datatype_constructor_refined = { - constructor : func_decl; - recognizer : func_decl; - accessors : func_decl array -} -(** - \[ [ get_datatype_sort c ty ] \] is the array of triples [(constructor, recognizer, fields)] where [constructor] is the constructor declaration of [ty], [recognizer] is the recognizer for the [constructor], and [fields] is the array of fields in [ty]. - - {b See also}: {!get_datatype_sort_num_constructors} - - {b See also}: {!get_datatype_sort_constructor} - - {b See also}: {!get_datatype_sort_recognizer} - - {b See also}: {!get_datatype_sort_constructor_accessor} -*) -val get_datatype_sort: context -> sort -> datatype_constructor_refined array -(** - \[ [ get_model_constants c m ] \] is the array of constants in the model [m]. - - {b See also}: {!get_model_num_constants} - - {b See also}: {!get_model_constant} -*) -val get_model_constants: context -> model -> func_decl array -(** - \[ [ get_model_func_entry c m i j ] \] is the [j]'th entry in the [i]'th function in the model [m]. - - {b See also}: {!get_model_func_entry_num_args} - - {b See also}: {!get_model_func_entry_arg} - - {b See also}: {!get_model_func_entry_value} -*) -val get_model_func_entry: context -> model -> int -> int -> (ast array * ast);; -(** - \[ [ get_model_func_entries c m i ] \] is the array of entries in the [i]'th function in the model [m]. - - {b See also}: {!get_model_func_num_entries} - - {b See also}: {!get_model_func_entry} -*) -val get_model_func_entries: context -> model -> int -> (ast array * ast) array;; -(** - \[ [ get_model_funcs c m ] \] is the array of functions in the model [m]. Each function is represented by the triple [(decl, entries, else)], where [decl] is the declaration name for the function, [entries] is the array of entries in the function, and [else] is the default (else) value for the function. - - {b See also}: {!get_model_num_funcs} - - {b See also}: {!get_model_func_decl} - - {b See also}: {!get_model_func_entries} - - {b See also}: {!get_model_func_else} -*) -val get_model_funcs: context -> model -> - (symbol * - (ast array * ast) array * - ast) array -(** - \[ [ get_smtlib_formulas c ] \] is the array of formulas created by a preceding call to {!parse_smtlib_string} or {!parse_smtlib_file}. - Recommend use {!parse_smtlib_string_x} or {!parse_smtlib_file_x} for functional style interface to the SMT-LIB parser. - - {b See also}: {!parse_smtlib_string_x} - - {b See also}: {!parse_smtlib_file_x} - - {b See also}: {!parse_smtlib_string} - - {b See also}: {!parse_smtlib_file} - - {b See also}: {!get_smtlib_num_formulas} - - {b See also}: {!get_smtlib_formula} -*) -val get_smtlib_formulas: context -> ast array -(** - \[ [get_smtlib_assumptions c] \] is the array of assumptions created by a preceding call to {!parse_smtlib_string} or {!parse_smtlib_file}. - Recommend use {!parse_smtlib_string_x} or {!parse_smtlib_file_x} for functional style interface to the SMT-LIB parser. - - {b See also}: {!parse_smtlib_string_x} - - {b See also}: {!parse_smtlib_file_x} - - {b See also}: {!parse_smtlib_string} - - {b See also}: {!parse_smtlib_file} - - {b See also}: {!get_smtlib_num_assumptions} - - {b See also}: {!get_smtlib_assumption} -*) -val get_smtlib_assumptions: context -> ast array -(** - \[ [ get_smtlib_decls c ] \] is the array of declarations created by a preceding call to {!parse_smtlib_string} or {!parse_smtlib_file}. - Recommend use {!parse_smtlib_string_x} or {!parse_smtlib_file_x} for functional style interface to the SMT-LIB parser. - - {b See also}: {!parse_smtlib_string_x} - - {b See also}: {!parse_smtlib_file_x} - - {b See also}: {!parse_smtlib_string} - - {b See also}: {!parse_smtlib_file} - - {b See also}: {!get_smtlib_num_decls} - - {b See also}: {!get_smtlib_decl} -*) -val get_smtlib_decls: context -> func_decl array -(** - \[ [ get_smtlib_parse_results c ] \] is the triple [(get_smtlib_formulas c, get_smtlib_assumptions c, get_smtlib_decls c)]. - Recommend use {!parse_smtlib_string_x} or {!parse_smtlib_file_x} for functional style interface to the SMT-LIB parser. - - {b See also}: {!parse_smtlib_string_x} - - {b See also}: {!parse_smtlib_file_x} - - {b See also}: {!parse_smtlib_string} - - {b See also}: {!parse_smtlib_file} - - {b See also}: {!get_smtlib_formulas} - - {b See also}: {!get_smtlib_assumptions} - - {b See also}: {!get_smtlib_decls} -*) -val get_smtlib_parse_results: context -> (ast array * ast array * func_decl array) -(** - \[ [ parse_smtlib_string_formula c ... ] \] calls [(parse_smtlib_string c ...)] and returns the single formula produced. - Recommended for functional style interface to the SMT-LIB parser. - - {b See also}: {!parse_smtlib_file_formula} - - {b See also}: {!parse_smtlib_string_x} -*) -val parse_smtlib_string_formula: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast -(** - \[ [ parse_smtlib_file_formula c ... ] \] calls [(parse_smtlib_file c ...)] and returns the single formula produced. - Recommended for functional style interface to the SMT-LIB parser. - - {b See also}: {!parse_smtlib_file_formula} - - {b See also}: {!parse_smtlib_file_x} -*) -val parse_smtlib_file_formula: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast -(** - \[ [ parse_smtlib_string_x c ... ] \] is [(parse_smtlib_string c ...; get_smtlib_parse_results c)] - Recommended for functional style interface to the SMT-LIB parser. - - {b See also}: {!parse_smtlib_file_x} - - {b See also}: {!parse_smtlib_string} - - {b See also}: {!get_smtlib_parse_results} -*) -val parse_smtlib_string_x: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> (ast array * ast array * func_decl array) -(** - \[ [ parse_smtlib_file_x c ... ] \] is [(parse_smtlib_file c ...; get_smtlib_parse_results c)] - Recommended for functional style interface to the SMT-LIB parser. - - {b See also}: {!parse_smtlib_string_x} - - {b See also}: {!parse_smtlib_file} - - {b See also}: {!get_smtlib_parse_results} -*) -val parse_smtlib_file_x: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> (ast array * ast array * func_decl array) -(** - \[ [ symbol_refined ] \] is the refinement of a {!symbol} . - - {b See also}: {!symbol_refine} - - {b See also}: {!get_symbol_kind} -*) -type symbol_refined = - | Symbol_int of int - | Symbol_string of string - | Symbol_unknown;; -(** - \[ [ symbol_refine c s ] \] is the refined symbol of [s]. - - {b See also}: {!symbol_refined} - - {b See also}: {!get_symbol_kind} -*) -val symbol_refine: context -> symbol -> symbol_refined;; -(** - \[ [ sort_refined ] \] is the refinement of a {!sort} . - - {b See also}: {!sort_refine} - - {b See also}: {!get_sort_kind} -*) -type sort_refined = - | Sort_uninterpreted of symbol - | Sort_bool - | Sort_int - | Sort_real - | Sort_bv of int - | Sort_array of (sort * sort) - | Sort_datatype of datatype_constructor_refined array - | Sort_relation - | Sort_finite_domain - | Sort_unknown of symbol -(** - \[ [ sort_refine c t ] \] is the refined sort of [t]. - - {b See also}: {!sort_refined} - - {b See also}: {!get_sort_kind} -*) -val sort_refine: context -> sort -> sort_refined;; -(** - \[ [ binder_type ] \] is a universal or existential quantifier. - - {b See also}: {!term_refined} -*) -type binder_type = | Forall | Exists -(** - \[ [ numeral_refined ] \] is the refinement of a numeral . - Numerals whose fractional representation can be fit with - 64 bit integers are treated as small. -*) -type numeral_refined = - | Numeral_small of int64 * int64 - | Numeral_large of string -(** - \[ [ term_refined ] \] is the refinement of a {!ast} . - - {b See also}: {!term_refine} -*) -type term_refined = - | Term_app of decl_kind * func_decl * ast array - | Term_quantifier of binder_type * int * ast array array * (symbol * sort) array * ast - | Term_numeral of numeral_refined * sort - | Term_var of int * sort -(** - \[ [ term_refine c a ] \] is the refined term of [a]. - - {b See also}: {!term_refined} -*) -val term_refine : context -> ast -> term_refined -(** - \[ [mk_theory c name ] \] create a custom theory. -*) -val mk_theory : context -> string -> theory -(** - \[ [set_delete_callback th cb] \] set callback when theory gets deleted. -*) -val set_delete_callback : theory -> (unit -> unit) -> unit -(** - \[ [set_reduce_app_callback th cb] \] set callback for simplifying theory terms. -*) -val set_reduce_app_callback : theory -> (func_decl -> ast array -> ast option) -> unit -(** - \[ [set_reduce_eq_callback th cb] \] set callback for simplifying equalities over theory terms. -*) -val set_reduce_eq_callback : theory -> (ast -> ast -> ast option) -> unit -(** - \[ [set_reduce_distinct_callback th cb] \] set callback for simplifying disequalities over theory terms. -*) -val set_reduce_distinct_callback : theory -> (ast array -> ast option) -> unit -(** - \[ [set_new_app_callback th cb] \] set callback for registering new application. -*) -val set_new_app_callback : theory -> (ast -> unit) -> unit -(** - \[ [set_new_elem_callback th cb] \] set callback for registering new element. - - {b See also}: the help for the corresponding C API function. -*) -val set_new_elem_callback : theory -> (ast -> unit) -> unit -(** - \[ [set_init_search_callback th cb] \] set callback when Z3 starts searching for a satisfying assignment. -*) -val set_init_search_callback : theory -> (unit -> unit) -> unit -(** - \[ [set_push_callback th cb] \] set callback for a logical context push. -*) -val set_push_callback : theory -> (unit -> unit) -> unit -(** - \[ [set_pop_callback th cb] \] set callback for a logical context pop. -*) -val set_pop_callback : theory -> (unit -> unit) -> unit -(** - \[ [set_restart_callback th cb] \] set callback for search restart. -*) -val set_restart_callback : theory -> (unit -> unit) -> unit -val set_reset_callback : theory -> (unit -> unit) -> unit -val set_final_check_callback : theory -> (unit -> bool) -> unit -val set_new_eq_callback : theory -> (ast -> ast -> unit) -> unit -val set_new_diseq_callback : theory -> (ast -> ast -> unit) -> unit -val set_new_assignment_callback : theory -> (ast -> bool -> unit) -> unit -val set_new_relevant_callback : theory -> (ast -> unit) -> unit + (** Parse the given string using the SMT-LIB2 parser. + {!parse_smtlib_string} + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) + val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr + (** Parse the given file using the SMT-LIB2 parser. + {!parse_smtlib2_string} *) + val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr end -<<<<<<< HEAD -======= (** Set a global (or module) parameter, which is shared by all Z3 contexts. When a Z3 module is initialized it will use the value of these parameters @@ -9811,11 +2932,11 @@ val get_global_param : string -> string option {!set_global_param} *) -val global_param_reset_all : unit - - (** Enable/disable printing of warning messages to the console. - - Note that this function is static and effects the behaviour of - all contexts globally. *) - val toggle_warning_messages : bool -> unit ->>>>>>> Updates to ML API. +val global_param_reset_all : unit -> unit + +(** Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) +val toggle_warning_messages : bool -> unit + From 755ba2a2f7fe710bb4966bd19fbbd457596270d5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 4 Jun 2013 16:46:47 +0100 Subject: [PATCH 071/248] ML API: removing rich layer for now. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3_rich.ml | 3399 ---------------------------------------- src/api/ml/z3_rich.mli | 3071 ------------------------------------ 2 files changed, 6470 deletions(-) delete mode 100644 src/api/ml/z3_rich.ml delete mode 100644 src/api/ml/z3_rich.mli diff --git a/src/api/ml/z3_rich.ml b/src/api/ml/z3_rich.ml deleted file mode 100644 index 0c2f95b6b..000000000 --- a/src/api/ml/z3_rich.ml +++ /dev/null @@ -1,3399 +0,0 @@ -\(** - The Z3 ML/Ocaml Interface. - - Copyright (C) 2012 Microsoft Corporation - @author CM Wintersteiger (cwinter) 2012-12-17 -*) - -open Z3enums - -(* Some helpers. *) -let null = Z3native.mk_null() -let is_null o = (Z3native.is_null o) - -(* Internal types *) -type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } -type context = z3_native_context - -type z3_native_object = { - m_ctx : context ; - mutable m_n_obj : Z3native.ptr ; - inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; - dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - - -(** Internal stuff *) -module Internal = -struct - let dispose_context ctx = - if ctx.m_n_obj_cnt == 0 then ( - (Z3native.del_context ctx.m_n_ctx) - ) else ( - Printf.printf "ERROR: NOT DISPOSING CONTEXT (because it still has %d objects alive)\n" ctx.m_n_obj_cnt; - ) - - let create_context settings = - let cfg = Z3native.mk_config in - let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in - (List.iter f settings) ; - let v = Z3native.mk_context_rc cfg in - Z3native.del_config(cfg) ; - Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; - Z3native.set_internal_error_handler v ; - let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in - let f = fun o -> dispose_context o in - Gc.finalise f res; - res - - let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) - let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) - let context_gno ctx = ctx.m_n_ctx - - - let z3obj_gc o = o.m_ctx - let z3obj_gnc o = (context_gno o.m_ctx) - - let z3obj_gno o = o.m_n_obj - let z3obj_sno o ctx no = - (context_add1 ctx) ; - o.inc_ref (context_gno ctx) no ; - ( - if not (is_null o.m_n_obj) then - o.dec_ref (context_gno ctx) o.m_n_obj ; - (context_sub1 ctx) - ) ; - o.m_n_obj <- no - - let z3obj_dispose o = - if not (is_null o.m_n_obj) then - ( - o.dec_ref (z3obj_gnc o) o.m_n_obj ; - (context_sub1 (z3obj_gc o)) - ) ; - o.m_n_obj <- null - - let z3obj_create o = - let f = fun o -> (z3obj_dispose o) in - Gc.finalise f o - - let z3obj_nil_ref x y = () - - let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> - let res : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res -end - -open Internal - -module Log = -struct - let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) - let close = Z3native.close_log - let append s = Z3native.append_log s -end - - -module Version = -struct - let major = let (x, _, _, _) = Z3native.get_version in x - let minor = let (_, x, _, _) = Z3native.get_version in x - let build = let (_, _, x, _) = Z3native.get_version in x - let revision = let (_, _, _, x) = Z3native.get_version in x - let to_string = - let (mj, mn, bld, rev) = Z3native.get_version in - string_of_int mj ^ "." ^ - string_of_int mn ^ "." ^ - string_of_int bld ^ "." ^ - string_of_int rev ^ "." -end - - -let mk_list ( f : int -> 'a ) ( n : int ) = - let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = - if (i >= n) then - tail - else - (mk_list' f (i+1) n ((f i) :: tail)) - in - mk_list' f 0 n [] - -let list_of_array ( x : _ array ) = - let f i = (Array.get x i) in - mk_list f (Array.length x) - -let mk_context ( cfg : ( string * string ) list ) = - create_context cfg - - -module Symbol = -struct - (* Symbol types *) - type int_symbol = z3_native_object - type string_symbol = z3_native_object - - type symbol = - | S_Int of int_symbol - | S_Str of string_symbol - - - let create_i ( ctx : context ) ( no : Z3native.ptr ) = - let res : int_symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let create_s ( ctx : context ) ( no : Z3native.ptr ) = - let res : string_symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let create ( ctx : context ) ( no : Z3native.ptr ) = - match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> S_Int (create_i ctx no) - | STRING_SYMBOL -> S_Str (create_s ctx no) - - let gc ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gc n) - | S_Str(n) -> (z3obj_gc n) - - let gnc ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gnc n) - | S_Str(n) -> (z3obj_gnc n) - - let gno ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gno n) - | S_Str(n) -> (z3obj_gno n) - - let symbol_lton ( a : symbol list ) = - let f ( e : symbol ) = (gno e) in - Array.of_list (List.map f a) - - let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) - let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL - let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL - let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) - let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) - let to_string ( o : symbol ) = - match (kind o) with - | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) - | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) - - let mk_int ( ctx : context ) ( i : int ) = - S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) - - let mk_string ( ctx : context ) ( s : string ) = - S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) - - let mk_ints ( ctx : context ) ( names : int list ) = - let f elem = mk_int ( ctx : context ) elem in - (List.map f names) - - let mk_strings ( ctx : context ) ( names : string list ) = - let f elem = mk_string ( ctx : context ) elem in - (List.map f names) -end - - -module AST = -struct - type ast = z3_native_object - - let context_of_ast ( x : ast ) = (z3obj_gc x) - let nc_of_ast ( x : ast ) = (z3obj_gnc x) - let ptr_of_ast ( x : ast ) = (z3obj_gno x) - - let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST - | SORT_AST - | QUANTIFIER_AST - | APP_AST - | NUMERAL_AST - | VAR_AST -> z3_native_object_of_ast_ptr ctx no - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") - - module ASTVector = - struct - type ast_vector = z3_native_object - - let ast_vector_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let res : ast_vector = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.ast_vector_inc_ref ; - dec_ref = Z3native.ast_vector_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_size ( x : ast_vector ) = - Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) - - let get ( x : ast_vector ) ( i : int ) = - ast_of_ptr (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) - - let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) - - let resize ( x : ast_vector ) ( new_size : int ) = - Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size - - let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) - - let translate ( x : ast_vector ) ( to_ctx : context ) = - ast_vector_of_ptr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let to_string ( x : ast_vector ) = - Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) - end - - module ASTMap = - struct - type ast_map = z3_native_object - - let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let res : ast_map = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.ast_map_inc_ref ; - dec_ref = Z3native.ast_map_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let contains ( x : ast_map ) ( key : ast ) = - Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - - let find ( x : ast_map ) ( key : ast ) = - ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) - - let insert ( x : ast_map ) ( key : ast ) ( value : ast) = - Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) - - let erase ( x : ast_map ) ( key : ast ) = - Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - - let reset ( x : ast_map ) = - Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : ast_map ) = - Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) - - let get_keys ( x : ast_map ) = - let av = ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in - let f i = (ASTVector.get av i) in - mk_list f (ASTVector.get_size av) - - let to_string ( x : ast_map ) = - Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) - let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) - let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) - - let is_expr ( x : ast ) = - match get_ast_kind ( x : ast ) with - | APP_AST - | NUMERAL_AST - | QUANTIFIER_AST - | VAR_AST -> true - | _ -> false - - let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST - let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST - let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST - let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST - - let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - - - let ( = ) ( a : ast ) ( b : ast ) = (a == b) || - if (z3obj_gnc a) != (z3obj_gnc b) then - false - else - Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) - - let compare a b = - if (get_id a) < (get_id b) then -1 else - if (get_id a) > (get_id b) then 1 else - 0 - - let ( < ) (a : ast) (b : ast) = (compare a b) - - let translate ( x : ast ) ( to_ctx : context ) = - if (z3obj_gnc x) == (context_gno to_ctx) then - x - else - ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr - let unwrap_ast ( x : ast ) = (z3obj_gno x) -end - -open AST - - -module Sort = -struct - type sort = Sort of AST.ast - type uninterpreted_sort = UninterpretedSort of sort - - let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> - let q = (z3_native_object_of_ast_ptr ctx no) in - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then - raise (Z3native.Exception "Invalid coercion") - else - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with - | ARRAY_SORT - | BOOL_SORT - | BV_SORT - | DATATYPE_SORT - | INT_SORT - | REAL_SORT - | UNINTERPRETED_SORT - | FINITE_DOMAIN_SORT - | RELATION_SORT -> Sort(q) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - - let ast_of_sort s = match s with Sort(x) -> x - let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x - - let uninterpreted_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - UninterpretedSort(s) - - let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) - let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) - let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) - - let sort_lton ( a : sort list ) = - let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in - Array.of_list (List.map f a) - - let ( = ) : sort -> sort -> bool = fun a b -> - (a == b) || - if (gnc a) != (gnc b) then - false - else - (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) - - - let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) - let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) - let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) - let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) - - let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; - (z3obj_create res) ; - UninterpretedSort(Sort(res)) - - let mk_uninterpreted_s ( ctx : context ) ( s : string ) = - mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) -end - -open Sort - - -module rec FuncDecl : -sig - type func_decl = FuncDecl of AST.ast - val ast_of_func_decl : FuncDecl.func_decl -> AST.ast - val func_decl_of_ptr : context -> Z3native.ptr -> func_decl - val gc : func_decl -> context - val gnc : func_decl -> Z3native.ptr - val gno : func_decl -> Z3native.ptr - module Parameter : - sig - type parameter = - P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - val get_kind : parameter -> Z3enums.parameter_kind - val get_int : parameter -> int - val get_float : parameter -> float - val get_symbol : parameter -> Symbol.symbol - val get_sort : parameter -> Sort.sort - val get_ast : parameter -> AST.ast - val get_func_decl : parameter -> func_decl - val get_rational : parameter -> string - end - val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl - val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl - val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl - val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl - val mk_const_decl_s : context -> string -> Sort.sort -> func_decl - val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl - val ( = ) : func_decl -> func_decl -> bool - val to_string : func_decl -> string - val get_id : func_decl -> int - val get_arity : func_decl -> int - val get_domain_size : func_decl -> int - val get_domain : func_decl -> Sort.sort list - val get_range : func_decl -> Sort.sort - val get_decl_kind : func_decl -> Z3enums.decl_kind - val get_name : func_decl -> Symbol.symbol - val get_num_parameters : func_decl -> int - val get_parameters : func_decl -> Parameter.parameter list - val apply : func_decl -> Expr.expr list -> Expr.expr -end = struct - type func_decl = FuncDecl of AST.ast - - let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - FuncDecl(z3_native_object_of_ast_ptr ctx no) - - let ast_of_func_decl f = match f with FuncDecl(x) -> x - - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (List.length domain) (sort_lton domain) (Sort.gno range))) ; - (z3obj_create res) ; - FuncDecl(res) - - let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort list ) ( range : sort ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (List.length domain) (sort_lton domain) (Sort.gno range))) ; - (z3obj_create res) ; - FuncDecl(res) - - let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) - let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) - let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - - module Parameter = - struct - type parameter = - | P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - let get_kind ( x : parameter ) = - (match x with - | P_Int(_) -> PARAMETER_INT - | P_Dbl(_) -> PARAMETER_DOUBLE - | P_Sym(_) -> PARAMETER_SYMBOL - | P_Srt(_) -> PARAMETER_SORT - | P_Ast(_) -> PARAMETER_AST - | P_Fdl(_) -> PARAMETER_FUNC_DECL - | P_Rat(_) -> PARAMETER_RATIONAL) - - let get_int ( x : parameter ) = - match x with - | P_Int(x) -> x - | _ -> raise (Z3native.Exception "parameter is not an int") - - let get_float ( x : parameter ) = - match x with - | P_Dbl(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a double") - - let get_symbol ( x : parameter ) = - match x with - | P_Sym(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a symbol") - - let get_sort ( x : parameter ) = - match x with - | P_Srt(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a sort") - - let get_ast ( x : parameter ) = - match x with - | P_Ast(x) -> x - | _ -> raise (Z3native.Exception "parameter is not an ast") - - let get_func_decl ( x : parameter ) = - match x with - | P_Fdl(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a func_decl") - - let get_rational ( x : parameter ) = - match x with - | P_Rat(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a rational string") - end - - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = - create_ndr ctx name domain range - - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort list ) ( range : sort ) = - mk_func_decl ctx (Symbol.mk_string ctx name) domain range - - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort list ) ( range : sort ) = - create_pdr ctx prefix domain range - - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - create_ndr ctx name [] range - - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = - create_ndr ctx (Symbol.mk_string ctx name) [] range - - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = - create_pdr ctx prefix [] range - - - let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || - if (gnc a) != (gnc b) then - false - else - (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) - - let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) - - let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) - - let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) - - let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) - - let get_domain ( x : func_decl ) = - let n = (get_domain_size x) in - let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in - mk_list f n - - let get_range ( x : func_decl ) = - sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) - - let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) - - let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) - - let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) - - let get_parameters ( x : func_decl ) = - let n = (get_num_parameters x) in - let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> Parameter.P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> Parameter.P_Ast (AST.ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) - ) in - mk_list f n - - let apply ( x : func_decl ) ( args : Expr.expr list ) = Expr.expr_of_func_app (gc x) x args -end - - -and Params : -sig - type params = z3_native_object - module ParamDescrs : - sig - type param_descrs - val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs - val validate : param_descrs -> params -> unit - val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind - val get_names : param_descrs -> Symbol.symbol list - val get_size : param_descrs -> int - val to_string : param_descrs -> string - end - val add_bool : params -> Symbol.symbol -> bool -> unit - val add_int : params -> Symbol.symbol -> int -> unit - val add_double : params -> Symbol.symbol -> float -> unit - val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - val add_s_bool : params -> string -> bool -> unit - val add_s_int : params -> string -> int -> unit - val add_s_double : params -> string -> float -> unit - val add_s_symbol : params -> string -> Symbol.symbol -> unit - val mk_params : context -> params - val to_string : params -> string -end = struct - type params = z3_native_object - - module ParamDescrs = - struct - type param_descrs = z3_native_object - - let param_descrs_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let res : param_descrs = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.param_descrs_inc_ref ; - dec_ref = Z3native.param_descrs_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let validate ( x : param_descrs ) ( p : params ) = - Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) - - let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) - - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in - let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = - Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = - Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = - Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = - Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) - - let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = - add_bool x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_int ( x : params) ( name : string ) ( value : int ) = - add_int x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_double ( x : params ) ( name : string ) ( value : float ) = - add_double x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = - add_symbol x (Symbol.mk_string (z3obj_gc x) name) value - - let mk_params ( ctx : context ) = - let res : params = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.params_inc_ref ; - dec_ref = Z3native.params_dec_ref } in - (z3obj_sno res ctx (Z3native.mk_params (context_gno ctx))) ; - (z3obj_create res) ; - res - - let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) -end - -(** General expressions (terms) *) -and Expr : -sig - type expr = Expr of AST.ast - val expr_of_ptr : context -> Z3native.ptr -> expr - val gc : expr -> context - val gnc : expr -> Z3native.ptr - val gno : expr -> Z3native.ptr - val expr_lton : expr list -> Z3native.ptr array - val ast_of_expr : expr -> AST.ast - val expr_of_ast : AST.ast -> expr - val expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr - val simplify : expr -> Params.params option -> expr - val get_simplify_help : context -> string - val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs - val get_func_decl : expr -> FuncDecl.func_decl - val get_bool_value : expr -> Z3enums.lbool - val get_num_args : expr -> int - val get_args : expr -> expr list - val update : expr -> expr list -> expr - val substitute : expr -> expr list -> expr list -> expr - val substitute_one : expr -> expr -> expr -> expr - val substitute_vars : expr -> expr list -> expr - val translate : expr -> context -> expr - val to_string : expr -> string - val is_numeral : expr -> bool - val is_well_sorted : expr -> bool - val get_sort : expr -> Sort.sort - val is_bool : expr -> bool - val is_const : expr -> bool - val is_true : expr -> bool - val is_false : expr -> bool - val is_eq : expr -> bool - val is_distinct : expr -> bool - val is_ite : expr -> bool - val is_and : expr -> bool - val is_or : expr -> bool - val is_iff : expr -> bool - val is_xor : expr -> bool - val is_not : expr -> bool - val is_implies : expr -> bool - val is_label : expr -> bool - val is_label_lit : expr -> bool - val is_oeq : expr -> bool - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - val mk_const_s : context -> string -> Sort.sort -> expr - val mk_const_f : context -> FuncDecl.func_decl -> expr - val mk_fresh_const : context -> string -> Sort.sort -> expr - val mk_app : context -> FuncDecl.func_decl -> expr list -> expr - val mk_numeral_string : context -> string -> Sort.sort -> expr - val mk_numeral_int : context -> int -> Sort.sort -> expr -end = struct - type expr = Expr of AST.ast - - let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) - let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) - let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) - - let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then - Expr(z3_native_object_of_ast_ptr ctx no) - else - let s = Z3native.get_sort (context_gno ctx) no in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) no) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - if (Z3native.is_numeral_ast (context_gno ctx) no) then - if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - raise (Z3native.Exception "Unsupported numeral object") - else - Expr(z3_native_object_of_ast_ptr ctx no) - - let expr_of_ast a = - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Expr(a) - - let ast_of_expr e = match e with Expr(a) -> a - - let expr_lton ( a : expr list ) = - let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in - Array.of_list (List.map f a) - - let expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr = fun ctx f args -> - match f with FuncDecl.FuncDecl(fa) -> - let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (List.length args) (expr_lton args) in - expr_of_ptr ctx o - - let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> expr_of_ptr (Expr.gc x) (Z3native.simplify (Expr.gnc x) (Expr.gno x)) - | Some pp -> expr_of_ptr (Expr.gc x) (Z3native.simplify_ex (Expr.gnc x) (Expr.gno x) (z3obj_gno pp)) - - let get_simplify_help ( ctx : context ) = - Z3native.simplify_get_help (context_gno ctx) - - let get_simplify_parameter_descrs ( ctx : context ) = - Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (Expr.gnc x) (Expr.gno x)) - - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (Expr.gnc x) (Expr.gno x)) - - let get_num_args ( x : expr ) = Z3native.get_app_num_args (Expr.gnc x) (Expr.gno x) - - let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = expr_of_ptr (Expr.gc x) (Z3native.get_app_arg (Expr.gnc x) (Expr.gno x) i) in - mk_list f n - - let update ( x : expr ) ( args : expr list ) = - if (List.length args <> (get_num_args x)) then - raise (Z3native.Exception "Number of arguments does not match") - else - expr_of_ptr (Expr.gc x) (Z3native.update_term (Expr.gnc x) (Expr.gno x) (List.length args) (expr_lton args)) - - let substitute ( x : expr ) from to_ = - if (List.length from) <> (List.length to_) then - raise (Z3native.Exception "Argument sizes do not match") - else - expr_of_ptr (Expr.gc x) (Z3native.substitute (Expr.gnc x) (Expr.gno x) (List.length from) (expr_lton from) (expr_lton to_)) - - let substitute_one ( x : expr ) from to_ = - substitute ( x : expr ) [ from ] [ to_ ] - - let substitute_vars ( x : expr ) to_ = - expr_of_ptr (Expr.gc x) (Z3native.substitute_vars (Expr.gnc x) (Expr.gno x) (List.length to_) (expr_lton to_)) - - let translate ( x : expr ) to_ctx = - if (Expr.gc x) == to_ctx then - x - else - expr_of_ptr to_ctx (Z3native.translate (Expr.gnc x) (Expr.gno x) (context_gno to_ctx)) - - let to_string ( x : expr ) = Z3native.ast_to_string (Expr.gnc x) (Expr.gno x) - - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) - - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (Expr.gnc x) (Expr.gno x) - - let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)) - - let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (Expr.gnc x) - (Z3native.mk_bool_sort (Expr.gnc x)) - (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) - - let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (get_num_args x) == 0 && - (FuncDecl.get_domain_size (get_func_decl x)) == 0 - - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) - let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) - - let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = - mk_const ctx (Symbol.mk_string ctx name) range - - let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [] - - let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = - expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) - - let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr list ) = expr_of_func_app ctx f args - - let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) - - let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) -end - -open FuncDecl -open Expr - -module Boolean = -struct - type bool_sort = BoolSort of Sort.sort - type bool_expr = BoolExpr of Expr.expr - - let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let a = (AST.ast_of_ptr ctx no) in - BoolExpr(Expr.Expr(a)) - - let bool_expr_of_expr e = - match e with Expr.Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolExpr(e) - - let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - BoolSort(sort_of_ptr ctx no) - - let sort_of_bool_sort s = match s with BoolSort(x) -> x - - let bool_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolSort(s) - - let expr_of_bool_expr e = match e with BoolExpr(x) -> x - - let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.c_of_expr e) - let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.nc_of_expr e) - let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.ptr_of_expr e) - - let mk_sort ( ctx : context ) = - BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - let s = (match (mk_sort ctx) with BoolSort(q) -> q) in - BoolExpr(Expr.mk_const ctx name s) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_true ( ctx : context ) = - bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) - - let mk_false ( ctx : context ) = - bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) - - let mk_val ( ctx : context ) ( value : bool ) = - if value then mk_true ctx else mk_false ctx - - let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) - - let mk_distinct ( ctx : context ) ( args : expr list ) = - bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) - - let mk_not ( ctx : context ) ( a : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) - - let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) - - let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) - - let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) - - let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - - let mk_and ( ctx : context ) ( args : bool_expr list ) = - let f x = (Expr.gno (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) - - let mk_or ( ctx : context ) ( args : bool_expr list ) = - let f x = (Expr.gno (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) -end - - -module Quantifier = -struct - type quantifier = Quantifier of expr - - let expr_of_quantifier e = match e with Quantifier(x) -> x - - let quantifier_of_expr e = - match e with Expr.Expr(a) -> - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.QUANTIFIER_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Quantifier(e) - - let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) - let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) - let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) - - module Pattern = - struct - type pattern = Pattern of ast - - let ast_of_pattern e = match e with Pattern(x) -> x - - let pattern_of_ast a = - (* CMW: Unchecked ok? *) - Pattern(a) - - let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) - let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) - let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - - let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms (gnc x) (gno x) - - let get_terms ( x : pattern ) = - let n = (get_num_terms x) in - let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in - mk_list f n - - let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) - end - - let get_index ( x : expr ) = - if not (AST.is_var (match x with Expr.Expr(a) -> a)) then - raise (Z3native.Exception "Term is not a bound variable.") - else - Z3native.get_index_value (Expr.gnc x) (Expr.gno x) - - let is_universal ( x : quantifier ) = - Z3native.is_quantifier_forall (gnc x) (gno x) - - let is_existential ( x : quantifier ) = not (is_universal x) - - let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) - - let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) - - let get_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in - mk_list f n - - let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) - - let get_no_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in - mk_list f n - - let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) - - let get_bound_variable_names ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in - mk_list f n - - let get_bound_variable_sorts ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in - mk_list f n - - let get_body ( x : quantifier ) = - Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) - - let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) - - let mk_pattern ( ctx : context ) ( terms : expr list ) = - if (List.length terms) == 0 then - raise (Z3native.Exception "Cannot create a pattern from zero terms") - else - Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (List.length terms) (expr_lton terms))) - - let mk_forall ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (List.length sorts) != (List.length names) then - raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - - let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (Expr.gno body))) - - let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (List.length sorts) != (List.length names) then - raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - - let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (Expr.gno body))) - - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (universal) then - (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - else - (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (universal) then - mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id - else - mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id -end - - -module Array_ = -struct - type array_sort = ArraySort of sort - type array_expr = ArrayExpr of expr - - let array_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (expr_of_ptr ctx no) in - ArrayExpr(e) - - let array_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - ArraySort(s) - - let sort_of_array_sort s = match s with ArraySort(x) -> x - - let array_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArraySort(s) - - let array_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArrayExpr(e) - - let expr_of_array_expr e = match e with ArrayExpr(x) -> x - - let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gno s) - - let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gc e) - let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) - let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) - - let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = - array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) - - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) - let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) - let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) - let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) - let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) - let is_array ( x : expr ) = - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) - - let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) - let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = - ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) - - let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = - mk_const ctx (Symbol.mk_string ctx name) domain range - - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (Expr.gno i)) - - let mk_store ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = - array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (Expr.gno i) (Expr.gno v)) - - let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) - - let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr list ) = - let m x = (Expr.gno (expr_of_array_expr x)) in - array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) - - let mk_term_array ( ctx : context ) ( arg : array_expr ) = - array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) -end - - -module Set = -struct - type set_sort = SetSort of sort - - let set_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - SetSort(s) - - let sort_of_set_sort s = match s with SetSort(x) -> x - - let mk_sort ( ctx : context ) ( ty : sort ) = - set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) - - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) - let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) - let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) - let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) - - - let mk_empty ( ctx : context ) ( domain : sort ) = - (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) - - let mk_full ( ctx : context ) ( domain : sort ) = - expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) - - let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) - - let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) - - let mk_union ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) - - let mk_intersection ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) - - let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) - - let mk_complement ( ctx : context ) ( arg : expr ) = - expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) - - let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) - - let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) - -end - - -module FiniteDomain = -struct - type finite_domain_sort = FiniteDomainSort of sort - - let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x - - let finite_domain_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - FiniteDomainSort(s) - - let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) - let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) - let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in - FiniteDomainSort(s) - - let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = - mk_sort ctx (Symbol.mk_string ctx name) size - - - let is_finite_domain ( x : expr ) = - let nc = (Expr.gnc x) in - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) - - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) - - let get_size ( x : finite_domain_sort ) = - let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in - if r then v - else raise (Z3native.Exception "Conversion failed.") -end - - -module Relation = -struct - type relation_sort = RelationSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - RelationSort(s) - - let sort_of_relation_sort s = match s with RelationSort(x) -> x - - let relation_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RelationSort(s) - - let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) - let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) - let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) - - - let is_relation ( x : expr ) = - let nc = (Expr.gnc x) in - ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) - - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) - let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) - let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) - let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) - let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) - let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) - let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) - let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) - let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) - let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) - - let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) - - let get_column_sorts ( x : relation_sort ) = - let n = get_arity x in - let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in - mk_list f n - -end - - -module Datatype = -struct - type datatype_sort = DatatypeSort of sort - type datatype_expr = DatatypeExpr of expr - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - DatatypeSort(s) - - let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x - - let datatype_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeSort(s) - - let datatype_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeExpr(e) - - let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x - - let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) - - module Constructor = - struct - type constructor = z3_native_object - - let _sizes = Hashtbl.create 0 - - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = - let n = (List.length field_names) in - if n != (List.length sorts) then - raise (Z3native.Exception "Number of field names does not match number of sorts") - else - if n != (List.length sort_refs) then - raise (Z3native.Exception "Number of field names does not match number of sort refs") - else - let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) - (Symbol.gno recognizer) - n - (Symbol.symbol_lton field_names) - (sort_lton sorts) - (Array.of_list sort_refs)) in - let no : constructor = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref} in - (z3obj_sno no ctx ptr) ; - (z3obj_create no) ; - let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in - Gc.finalise f no ; - Hashtbl.add _sizes no n ; - no - - let get_num_fields ( x : constructor ) = Hashtbl.find _sizes x - - let get_constructor_decl ( x : constructor ) = - let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - func_decl_of_ptr (z3obj_gc x) a - - let get_tester_decl ( x : constructor ) = - let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - func_decl_of_ptr (z3obj_gc x) b - - let get_accessor_decls ( x : constructor ) = - let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - let f i = func_decl_of_ptr (z3obj_gc x) (Array.get c i) in - mk_list f (Array.length c) - - end - - module ConstructorList = - struct - type constructor_list = z3_native_object - - let create ( ctx : context ) ( c : Constructor.constructor list ) = - let res : constructor_list = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref} in - let f x =(z3obj_gno x) in - (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (List.length c) (Array.of_list (List.map f c)))) ; - (z3obj_create res) ; - let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in - Gc.finalise f res; - res - end - - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = - Constructor.create ctx name recognizer field_names sorts sort_refs - - - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = - mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = - let f x = (z3obj_gno x) in - let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (List.length constructors) (Array.of_list (List.map f constructors))) in - sort_of_ptr ctx x - - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor list ) = - mk_sort ctx (Symbol.mk_string ctx name) constructors - - let mk_sorts ( ctx : context ) ( names : Symbol.symbol list ) ( c : Constructor.constructor list list ) = - let n = (List.length names) in - let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in - let cla = (Array.of_list (List.map f c)) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.symbol_lton names) cla) in - let g i = (sort_of_ptr ctx (Array.get r i)) in - mk_list g (Array.length r) - - let mk_sorts_s ( ctx : context ) ( names : string list ) ( c : Constructor.constructor list list ) = - mk_sorts ctx - ( - let f e = (Symbol.mk_string ctx e) in - List.map f names - ) - c - - let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) - - let get_constructors ( x : datatype_sort ) = - let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in - mk_list f n - - let get_recognizers ( x : datatype_sort ) = - let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in - mk_list f n - - let get_accessors ( x : datatype_sort ) = - let n = (get_num_constructors x) in - let f i = ( - let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in - let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in - let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in - mk_list g ds - ) in - mk_list f n -end - - -module Enumeration = -struct - type enum_sort = EnumSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl list ) ( tdecls : Z3native.z3_func_decl list ) = - let s = (sort_of_ptr ctx no) in - let res = EnumSort(s) in - res - - let sort_of_enum_sort s = match s with EnumSort(x) -> x - - let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = - let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in - sort_of_ptr ctx a (list_of_array b) (list_of_array c) - - let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = - mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) - - let get_const_decls ( x : enum_sort ) = - let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in - let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in - mk_list f n - - let get_tester_decls ( x : enum_sort ) = - let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in - let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in - mk_list f n - -end - - -module List_ = -struct - type list_sort = ListSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - let res = ListSort(s) in - res - - let sort_of_list_sort s = match s with ListSort(x) -> x - - let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in - sort_of_ptr ctx r a b c d e f - - let mk_list_s ( ctx : context ) (name : string) elem_sort = - mk_sort ctx (Symbol.mk_string ctx name) elem_sort - - let get_nil_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) - - let get_is_nil_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) - - let get_cons_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) - - let get_is_cons_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) - - let get_head_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) - - let get_tail_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) - - let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [] -end - - -module Tuple = -struct - type tuple_sort = TupleSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - TupleSort(s) - - let sort_of_tuple_sort s = match s with TupleSort(x) -> x - - let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = - let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in - sort_of_ptr ctx r - - let get_mk_decl ( x : tuple_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) - - let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) - - let get_field_decls ( x : tuple_sort ) = - let n = get_num_fields x in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in - mk_list f n -end - - -module rec Arithmetic : -sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val sort_of_arith_sort : arith_sort -> Sort.sort - val arith_sort_of_sort : Sort.sort -> arith_sort - val expr_of_arith_expr : arith_expr -> Expr.expr - val arith_expr_of_expr : Expr.expr -> arith_expr - - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val int_expr_of_ptr : context -> Z3native.ptr -> int_expr - val int_num_of_ptr : context -> Z3native.ptr -> int_num - - val arith_sort_of_int_sort : Integer.int_sort -> arith_sort - val int_sort_of_arith_sort : arith_sort -> int_sort - val arith_expr_of_int_expr : int_expr -> arith_expr - val int_expr_of_int_num : int_num -> int_expr - val int_expr_of_arith_expr : arith_expr -> int_expr - val int_num_of_int_expr : int_expr -> int_num - - val mk_sort : context -> int_sort - val get_int : int_num -> int - val to_string : int_num -> string - val mk_const : context -> Symbol.symbol -> int_expr - val mk_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> int_expr - val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_numeral_s : context -> string -> int_num - val mk_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> Real.real_expr - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val real_expr_of_ptr : context -> Z3native.ptr -> real_expr - val rat_num_of_ptr : context -> Z3native.ptr -> rat_num - - val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort - val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort - val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr - val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr - val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr - val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num - - val mk_sort : context -> real_sort - val get_numerator : rat_num -> Integer.int_num - val get_denominator : rat_num -> Integer.int_num - val to_decimal_string : rat_num -> int -> string - val to_string : rat_num -> string - val mk_const : context -> Symbol.symbol -> real_expr - val mk_const_s : context -> string -> real_expr - val mk_numeral_nd : context -> int -> int -> rat_num - val mk_numeral_s : context -> string -> rat_num - val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - val mk_real2int : context -> real_expr -> Integer.int_expr - end - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : algebraic_num -> arith_expr - val algebraic_num_of_arith_expr : arith_expr -> algebraic_num - - val to_upper : algebraic_num -> int -> Real.rat_num - val to_lower : algebraic_num -> int -> Real.rat_num - val to_decimal_string : algebraic_num -> int -> string - val to_string : algebraic_num -> string - end - - val is_int : Expr.expr -> bool - val is_arithmetic_numeral : Expr.expr -> bool - val is_le : Expr.expr -> bool - val is_ge : Expr.expr -> bool - val is_lt : Expr.expr -> bool - val is_gt : Expr.expr -> bool - val is_add : Expr.expr -> bool - val is_sub : Expr.expr -> bool - val is_uminus : Expr.expr -> bool - val is_mul : Expr.expr -> bool - val is_div : Expr.expr -> bool - val is_idiv : Expr.expr -> bool - val is_remainder : Expr.expr -> bool - val is_modulus : Expr.expr -> bool - val is_inttoreal : Expr.expr -> bool - val is_real_to_int : Expr.expr -> bool - val is_real_is_int : Expr.expr -> bool - val is_real : Expr.expr -> bool - val is_int_numeral : Expr.expr -> bool - val is_rat_num : Expr.expr -> bool - val is_algebraic_number : Expr.expr -> bool - val mk_add : context -> arith_expr list -> arith_expr - val mk_mul : context -> arith_expr list -> arith_expr - val mk_sub : context -> arith_expr list -> arith_expr - val mk_unary_minus : context -> arith_expr -> arith_expr - val mk_div : context -> arith_expr -> arith_expr -> arith_expr - val mk_power : context -> arith_expr -> arith_expr -> arith_expr - val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr -end = struct - type arith_sort = ArithSort of sort - type arith_expr = ArithExpr of expr - - let arith_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithExpr(e) - - let arith_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - arith_expr_of_expr (expr_of_ptr ctx no) - - let sort_of_arith_sort s = match s with ArithSort(x) -> x - let expr_of_arith_expr e = match e with ArithExpr(x) -> x - - let arith_sort_of_sort s = match s with Sort(a) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithSort(s) - - let arith_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - arith_sort_of_sort (sort_of_ptr ctx no) - - let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gno s) - let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gc e) - let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) - let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) - - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val int_expr_of_ptr : context -> Z3native.ptr -> int_expr - val int_num_of_ptr : context -> Z3native.ptr -> int_num - - val arith_sort_of_int_sort : Integer.int_sort -> arith_sort - val int_sort_of_arith_sort : arith_sort -> int_sort - val arith_expr_of_int_expr : int_expr -> arith_expr - val int_expr_of_int_num : int_num -> int_expr - val int_expr_of_arith_expr : arith_expr -> int_expr - val int_num_of_int_expr : int_expr -> int_num - - val mk_sort : context -> int_sort - val get_int : int_num -> int - val to_string : int_num -> string - val mk_const : context -> Symbol.symbol -> int_expr - val mk_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> int_expr - val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_numeral_s : context -> string -> int_num - val mk_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> Real.real_expr - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end = struct - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - let int_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntExpr(e) - - let int_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) - - let int_num_of_int_expr e = - match e with IntExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - IntNum(e) - - let int_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_num_of_int_expr (int_expr_of_ptr ctx no) - - let arith_sort_of_int_sort s = match s with IntSort(x) -> x - let arith_expr_of_int_expr e = match e with IntExpr(x) -> x - let int_expr_of_int_num e = match e with IntNum(x) -> x - - let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntSort(s) - - let int_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_sort_of_arith_sort (arith_sort_of_sort (Sort.sort_of_ptr ctx no)) - - let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) - let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) - let sgno ( x : int_sort ) = match (x) with IntSort(s) -> (sgno s) - let egc ( x : int_expr ) = match (x) with IntExpr(e) -> (egc e) - let egnc ( x : int_expr ) = match (x) with IntExpr(e) -> (egnc e) - let egno ( x : int_expr ) = match (x) with IntExpr(e) -> (egno e) - let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) - let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) - let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - - let mk_sort ( ctx : context ) = - int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) - - let get_int ( x : int_num ) = - let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in - if r then v - else raise (Z3native.Exception "Conversion failed.") - - let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) - - let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) - - let mk_numeral_s ( ctx : context ) ( v : string ) = - int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - - let mk_numeral_i ( ctx : context ) ( v : int ) = - int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) - - let mk_int2real ( ctx : context ) ( t : int_expr ) = - Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) - - let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) - end - - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val real_expr_of_ptr : context -> Z3native.ptr -> real_expr - val rat_num_of_ptr : context -> Z3native.ptr -> rat_num - - val arith_sort_of_real_sort : real_sort -> arith_sort - val real_sort_of_arith_sort : arith_sort -> real_sort - val arith_expr_of_real_expr : real_expr -> arith_expr - val real_expr_of_rat_num : rat_num -> real_expr - val real_expr_of_arith_expr : arith_expr -> real_expr - val rat_num_of_real_expr : real_expr -> rat_num - - val mk_sort : context -> real_sort - val get_numerator : rat_num -> Integer.int_num - val get_denominator : rat_num -> Integer.int_num - val to_decimal_string : rat_num -> int -> string - val to_string : rat_num -> string - val mk_const : context -> Symbol.symbol -> real_expr - val mk_const_s : context -> string -> real_expr - val mk_numeral_nd : context -> int -> int -> rat_num - val mk_numeral_s : context -> string -> rat_num - val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - val mk_real2int : context -> real_expr -> Integer.int_expr - end = struct - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - let arith_sort_of_real_sort s = match s with RealSort(x) -> x - let arith_expr_of_real_expr e = match e with RealExpr(x) -> x - let real_expr_of_rat_num e = match e with RatNum(x) -> x - - let real_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealExpr(e) - - let real_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) - - let rat_num_of_real_expr e = - match e with RealExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - RatNum(e) - - let rat_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - rat_num_of_real_expr (real_expr_of_ptr ctx no) - - let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealSort(s) - - let real_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) - - let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) - let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) - let sgno ( x : real_sort ) = match (x) with RealSort(s) -> (sgno s) - let egc ( x : real_expr ) = match (x) with RealExpr(e) -> (egc e) - let egnc ( x : real_expr ) = match (x) with RealExpr(e) -> (egnc e) - let egno ( x : real_expr ) = match (x) with RealExpr(e) -> (egno e) - let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) - let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) - let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - - - let mk_sort ( ctx : context ) = - real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) - - let get_numerator ( x : rat_num ) = - Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) - - let get_denominator ( x : rat_num ) = - Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) - - let to_decimal_string ( x : rat_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision - - let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = - if (den == 0) then - raise (Z3native.Exception "Denominator is zero") - else - rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) - - let mk_numeral_s ( ctx : context ) ( v : string ) = - rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - - let mk_numeral_i ( ctx : context ) ( v : int ) = - rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) - - let mk_is_integer ( ctx : context ) ( t : real_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) - - let mk_real2int ( ctx : context ) ( t : real_expr ) = - Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) - end - - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : algebraic_num -> arith_expr - val algebraic_num_of_arith_expr : arith_expr -> algebraic_num - - val to_upper : algebraic_num -> int -> Real.rat_num - val to_lower : algebraic_num -> int -> Real.rat_num - val to_decimal_string : algebraic_num -> int -> string - val to_string : algebraic_num -> string - end = struct - type algebraic_num = AlgebraicNum of arith_expr - - let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x - - let algebraic_num_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - AlgebraicNum(e) - - let algebraic_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) - - let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) - let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) - let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - - - let to_upper ( x : algebraic_num ) ( precision : int ) = - Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) - - let to_lower ( x : algebraic_num ) precision = - Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) - - let to_decimal_string ( x : algebraic_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision - - let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - end - - let is_int ( x : expr ) = - (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) - - let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - - let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - - let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - - let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - - let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - - let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - - let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - - let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - - let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - - let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - - let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - - let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - - let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - - let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - - let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) - - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) - let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) - - let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) - - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) - - let mk_add ( ctx : context ) ( t : arith_expr list ) = - let f x = (Expr.gno (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_mul ( ctx : context ) ( t : arith_expr list ) = - let f x = (Expr.gno (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_sub ( ctx : context ) ( t : arith_expr list ) = - let f x = (Expr.gno (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) - - let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) - - let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) - - let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) - - let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) - - let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) - - let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) -end - - -and BitVector : -sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort - val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort - val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr - val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr - val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr - val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num - - val mk_sort : context -> int -> bitvec_sort - val is_bv : Expr.expr -> bool - val is_bv_numeral : Expr.expr -> bool - val is_bv_bit1 : Expr.expr -> bool - val is_bv_bit0 : Expr.expr -> bool - val is_bv_uminus : Expr.expr -> bool - val is_bv_add : Expr.expr -> bool - val is_bv_sub : Expr.expr -> bool - val is_bv_mul : Expr.expr -> bool - val is_bv_sdiv : Expr.expr -> bool - val is_bv_udiv : Expr.expr -> bool - val is_bv_SRem : Expr.expr -> bool - val is_bv_urem : Expr.expr -> bool - val is_bv_smod : Expr.expr -> bool - val is_bv_sdiv0 : Expr.expr -> bool - val is_bv_udiv0 : Expr.expr -> bool - val is_bv_srem0 : Expr.expr -> bool - val is_bv_urem0 : Expr.expr -> bool - val is_bv_smod0 : Expr.expr -> bool - val is_bv_ule : Expr.expr -> bool - val is_bv_sle : Expr.expr -> bool - val is_bv_uge : Expr.expr -> bool - val is_bv_sge : Expr.expr -> bool - val is_bv_ult : Expr.expr -> bool - val is_bv_slt : Expr.expr -> bool - val is_bv_ugt : Expr.expr -> bool - val is_bv_sgt : Expr.expr -> bool - val is_bv_and : Expr.expr -> bool - val is_bv_or : Expr.expr -> bool - val is_bv_not : Expr.expr -> bool - val is_bv_xor : Expr.expr -> bool - val is_bv_nand : Expr.expr -> bool - val is_bv_nor : Expr.expr -> bool - val is_bv_xnor : Expr.expr -> bool - val is_bv_concat : Expr.expr -> bool - val is_bv_signextension : Expr.expr -> bool - val is_bv_zeroextension : Expr.expr -> bool - val is_bv_extract : Expr.expr -> bool - val is_bv_repeat : Expr.expr -> bool - val is_bv_reduceor : Expr.expr -> bool - val is_bv_reduceand : Expr.expr -> bool - val is_bv_comp : Expr.expr -> bool - val is_bv_shiftleft : Expr.expr -> bool - val is_bv_shiftrightlogical : Expr.expr -> bool - val is_bv_shiftrightarithmetic : Expr.expr -> bool - val is_bv_rotateleft : Expr.expr -> bool - val is_bv_rotateright : Expr.expr -> bool - val is_bv_rotateleftextended : Expr.expr -> bool - val is_bv_rotaterightextended : Expr.expr -> bool - val is_int_to_bv : Expr.expr -> bool - val is_bv_to_int : Expr.expr -> bool - val is_bv_carry : Expr.expr -> bool - val is_bv_xor3 : Expr.expr -> bool - val get_size : bitvec_sort -> int - val get_int : bitvec_num -> int - val to_string : bitvec_num -> string - val mk_const : context -> Symbol.symbol -> int -> bitvec_expr - val mk_const_s : context -> string -> int -> bitvec_expr - val mk_not : context -> bitvec_expr -> Expr.expr - val mk_redand : context -> bitvec_expr -> Expr.expr - val mk_redor : context -> bitvec_expr -> Expr.expr - val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_neg : context -> bitvec_expr -> bitvec_expr - val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr - val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr - val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr - val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr - val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr - val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr - val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr - val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr - val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_numeral : context -> string -> int -> bitvec_num -end = struct - type bitvec_sort = BitVecSort of sort - type bitvec_expr = BitVecExpr of expr - type bitvec_num = BitVecNum of bitvec_expr - - let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x - - let bitvec_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecSort(s) - - let bitvec_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_sort_of_sort (sort_of_ptr ctx no) - - let bitvec_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecExpr(e) - - let bitvec_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_expr_of_expr (expr_of_ptr ctx no) - - let bitvec_num_of_bitvec_expr e = - match e with BitVecExpr(Expr(a)) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecNum(e) - - let bitvec_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_num_of_bitvec_expr (bitvec_expr_of_expr (expr_of_ptr ctx no)) - - let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x - let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x - - - let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) - let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) - let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) - let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gc e) - let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gnc e) - let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gno e) - let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) - let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) - let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - - - let mk_sort ( ctx : context ) size = - bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) - let is_bv ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) - let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) - let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) - let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) - let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) - let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) - let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) - let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) - let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) - let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) - let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) - let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) - let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) - let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) - let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) - let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) - let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) - let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) - let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) - let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) - let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) - let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) - let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) - let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) - let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) - let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) - let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) - let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) - let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) - let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) - let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) - let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) - let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) - let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) - let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) - let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) - let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) - let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) - let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) - let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) - let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) - let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) - let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) - let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) - let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) - let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) - let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) - let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) - let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) - let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) - let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) - let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) - let get_int ( x : bitvec_num ) = - let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in - if r then v - else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) - let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = - mk_const ctx (Symbol.mk_string ctx name) size - let mk_not ( ctx : context ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) - let mk_redand ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) - let mk_redor ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) - let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) - let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) - let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) - let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) - let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) - let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) - let mk_neg ( ctx : context ) ( t : bitvec_expr) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) - let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) - let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) - let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) - let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) - let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) - let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) - let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) - let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) - let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) - let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) - let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) - let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) - let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) - let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) - let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) - let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) - let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) - let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) - let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) - let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) - let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) - let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) - let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) - let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) - let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) - let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) - let mk_ext_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) - let mk_ext_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) - let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = - Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) - let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) - let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) - let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) - let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) - let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) - let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = - bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) -end - - -module Proof = -struct - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) - let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) - let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) - let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) - let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) - let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) - let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) - let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) - let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) - let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) - let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) - let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) - let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) - let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) - let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) - let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) - let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) - let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) - let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) - let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) - let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) - let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) - let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) - let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) - let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) - let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) - let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) - let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) - let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) - let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) - let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) - let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) - let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) - let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) - let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) - let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) - let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) - let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) -end - - -module Goal = -struct - type goal = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : goal = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.goal_inc_ref ; - dec_ref = Z3native.goal_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_precision ( x : goal ) = - goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) - - let is_precise ( x : goal ) = - (get_precision x) == GOAL_PRECISE - - let is_underapproximation ( x : goal ) = - (get_precision x) == GOAL_UNDER - - let is_overapproximation ( x : goal ) = - (get_precision x) == GOAL_OVER - - let is_garbage ( x : goal ) = - (get_precision x) == GOAL_UNDER_OVER - - let assert_ ( x : goal ) ( constraints : Boolean.bool_expr list ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in - ignore (List.map f constraints) ; - () - - let is_inconsistent ( x : goal ) = - Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) - - let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) - - let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) - - let get_formulas ( x : goal ) = - let n = get_size x in - let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) - (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in - mk_list f n - - let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) - - let is_decided_sat ( x : goal ) = - Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) - - let is_decided_unsat ( x : goal ) = - Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) - - let translate ( x : goal ) ( to_ctx : context ) = - create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let simplify ( x : goal ) ( p : Params.params option ) = - let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in - Z3native.tactic_inc_ref (z3obj_gnc x) tn ; - let arn = match p with - | None -> Z3native.tactic_apply (z3obj_gnc x) tn (z3obj_gno x) - | Some(pn) -> Z3native.tactic_apply_ex (z3obj_gnc x) tn (z3obj_gno x) (z3obj_gno pn) - in - Z3native.apply_result_inc_ref (z3obj_gnc x) arn ; - let sg = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) arn in - let res = if sg == 0 then - raise (Z3native.Exception "No subgoals") - else - Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in - Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; - Z3native.tactic_dec_ref (z3obj_gnc x) tn ; - create (z3obj_gc x) res - - let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) - - let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Model = -struct - type model = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : model = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.model_inc_ref ; - dec_ref = Z3native.model_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module FuncInterp = - struct - type func_interp = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : func_interp = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.func_interp_inc_ref ; - dec_ref = Z3native.func_interp_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module FuncEntry = - struct - type func_entry = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : func_entry = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.func_entry_inc_ref ; - dec_ref = Z3native.func_entry_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_value ( x : func_entry ) = - expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) - - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) - - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ List.fold_right f a ((Expr.to_string (get_value x)) ^ "]") - end - - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) - - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) - - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) - - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (List.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - List.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") - end - - let get_const_interp ( x : model ) ( f : func_decl ) = - if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then - raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") - else - let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in - if (Z3native.is_null np) then - None - else - Some (expr_of_ptr (z3obj_gc x) np) - - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - - - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in - if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in - if (Z3native.is_null n) then - None - else - match sk with - | ARRAY_SORT -> - if not (Z3native.is_as_array (z3obj_gnc x) n) then - raise (Z3native.Exception "Argument was not an array constant") - else - let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x (func_decl_of_ptr (z3obj_gc x) fd) - | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); - else - let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in - if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) - - (** The number of constants that have an interpretation in the model. *) - let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) - - let get_const_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) - - let get_func_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_decls ( x : model ) = - let n_funcs = (get_num_funcs x) in - let n_consts = (get_num_consts x ) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - (mk_list f n_funcs) @ (mk_list g n_consts) - - exception ModelEvaluationFailedException of string - - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in - if not r then - raise (ModelEvaluationFailedException "evaluation failed") - else - expr_of_ptr (z3obj_gc x) v - - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = - eval x t completion - - let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) - - let get_sorts ( x : model ) = - let n = (get_num_sorts x) in - let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in - mk_list f n - - let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Probe = -struct - type probe = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : probe = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.probe_inc_ref ; - dec_ref = Z3native.probe_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - - let apply ( x : probe ) ( g : Goal.goal ) = - Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) - - let get_num_probes ( ctx : context ) = - Z3native.get_num_probes (context_gno ctx) - - let get_probe_names ( ctx : context ) = - let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name (context_gno ctx) i) in - mk_list f n - - let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr (context_gno ctx) name - - let mk_probe ( ctx : context ) ( name : string ) = - (create ctx (Z3native.mk_probe (context_gno ctx) name)) - - let const ( ctx : context ) ( v : float ) = - (create ctx (Z3native.probe_const (context_gno ctx) v)) - - let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let not_ ( ctx : context ) ( p : probe ) = - (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) -end - - -module Tactic = -struct - type tactic = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : tactic = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.tactic_inc_ref ; - dec_ref = Z3native.tactic_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module ApplyResult = - struct - type apply_result = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : apply_result = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.apply_result_inc_ref ; - dec_ref = Z3native.apply_result_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_num_subgoals ( x : apply_result ) = - Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) - - let get_subgoals ( x : apply_result ) = - let n = (get_num_subgoals x) in - let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_subgoal ( x : apply_result ) ( i : int ) = - Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) - - let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = - Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) - - let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) - - let get_param_descrs ( x : tactic ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = - match p with - | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) - | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) - - let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) - - let get_tactic_names ( ctx : context ) = - let n = (get_num_tactics ctx ) in - let f i = (Z3native.get_tactic_name (context_gno ctx) i) in - mk_list f n - - let get_tactic_description ( ctx : context ) ( name : string ) = - Z3native.tactic_get_descr (context_gno ctx) name - - let mk_tactic ( ctx : context ) ( name : string ) = - create ctx (Z3native.mk_tactic (context_gno ctx) name) - - let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic list ) = - let f p c = (match p with - | None -> (Some (z3obj_gno c)) - | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in - match (List.fold_left f None ts) with - | None -> - create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - | Some(x) -> - let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in - create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) - - let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - - let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) - - let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = - create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) - - let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) - - let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) - - let skip ( ctx : context ) = - create ctx (Z3native.tactic_skip (context_gno ctx)) - - let fail ( ctx : context ) = - create ctx (Z3native.tactic_fail (context_gno ctx)) - - let fail_if ( ctx : context ) ( p : Probe.probe ) = - create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) - - let fail_if_not_decided ( ctx : context ) = - create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) - - let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = - create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) - - let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = - using_params ctx t p - - let par_or ( ctx : context ) ( t : tactic list ) = - let f e = (z3obj_gno e) in - create ctx (Z3native.tactic_par_or (context_gno ctx) (List.length t) (Array.of_list (List.map f t))) - - let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - - let interrupt ( ctx : context ) = - Z3native.interrupt (context_gno ctx) -end - - -module Solver = -struct - type solver = z3_native_object - type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : solver = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.solver_inc_ref ; - dec_ref = Z3native.solver_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let string_of_status ( s : status) = match s with - | UNSATISFIABLE -> "unsatisfiable" - | SATISFIABLE -> "satisfiable" - | _ -> "unknown" - - module Statistics = - struct - type statistics = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : statistics = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.stats_inc_ref ; - dec_ref = Z3native.stats_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - - module Entry = - struct - type statistics_entry = { - mutable m_key : string; - mutable m_is_int : bool ; - mutable m_is_float : bool ; - mutable m_int : int ; - mutable m_float : float } - - let create_si k v = - let res : statistics_entry = { - m_key = k ; - m_is_int = true ; - m_is_float = false ; - m_int = v ; - m_float = 0.0 - } in - res - - let create_sd k v = - let res : statistics_entry = { - m_key = k ; - m_is_int = false ; - m_is_float = true ; - m_int = 0 ; - m_float = v - } in - res - - - let get_key (x : statistics_entry) = x.m_key - let get_int (x : statistics_entry) = x.m_int - let get_float (x : statistics_entry) = x.m_float - let is_int (x : statistics_entry) = x.m_is_int - let is_float (x : statistics_entry) = x.m_is_float - let to_string_value (x : statistics_entry) = - if (is_int x) then - string_of_int (get_int x) - else if (is_float x) then - string_of_float (get_float x) - else - raise (Z3native.Exception "Unknown statistical entry type") - let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) - end - - let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) - - let get_entries ( x : statistics ) = - let n = (get_size x ) in - let f i = ( - let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in - if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then - (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) - else - (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) - ) in - mk_list f n - - let get_keys ( x : statistics ) = - let n = (get_size x) in - let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get ( x : statistics ) ( key : string ) = - let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in - List.fold_left f None (get_entries x) - end - - let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) - - let set_parameters ( x : solver ) ( p : Params.params )= - Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - - let get_param_descrs ( x : solver ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) - - let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) - - let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n - - let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - - let assert_ ( x : solver ) ( constraints : Boolean.bool_expr list ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in - ignore (List.map f constraints) - - let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr list ) ( ps : Boolean.bool_expr list ) = - if ((List.length cs) != (List.length ps)) then - raise (Z3native.Exception "Argument size mismatch") - else - let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno a) (Boolean.gno b)) in - ignore (List.iter2 f cs ps) - - let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) - - let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - (AST.ASTVector.get_size a) - - let get_assertions ( x : solver ) = - let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size a) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in - mk_list f n - - let check ( x : solver ) ( assumptions : Boolean.bool_expr list ) = - let r = - if ((List.length assumptions) == 0) then - lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) - else - let f x = (Expr.gno (Boolean.expr_of_bool_expr x)) in - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) - in - match r with - | L_TRUE -> SATISFIABLE - | L_FALSE -> UNSATISFIABLE - | _ -> UNKNOWN - - let get_model ( x : solver ) = - let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in - if (Z3native.is_null q) then - None - else - Some (Model.create (z3obj_gc x) q) - - let get_proof ( x : solver ) = - let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size cn) in - let f i = (AST.ASTVector.get cn i) in - mk_list f n - - let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - - let get_statistics ( x : solver ) = - (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) - - let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = - match logic with - | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) - - let mk_solver_s ( ctx : context ) ( logic : string ) = - mk_solver ctx (Some (Symbol.mk_string ctx logic)) - - let mk_simple_solver ( ctx : context ) = - (create ctx (Z3native.mk_simple_solver (context_gno ctx))) - - let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = - (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) - - let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Fixedpoint = -struct - type fixedpoint = z3_native_object - - let create ( ctx : context ) = - let res : fixedpoint = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.fixedpoint_inc_ref ; - dec_ref = Z3native.fixedpoint_dec_ref } in - (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; - (z3obj_create res) ; - res - - - let get_help ( x : fixedpoint ) = - Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) - - let set_params ( x : fixedpoint ) ( p : Params.params )= - Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - - let get_param_descrs ( x : fixedpoint ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr list ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in - ignore (List.map f constraints) ; - () - - let register_relation ( x : fixedpoint ) ( f : func_decl ) = - Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) - - let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = - match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) - - let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = - Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) - - let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN - - let query_r ( x : fixedpoint ) ( relations : func_decl list ) = - let f x = ptr_of_ast (ast_of_func_decl x) in - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (List.length relations) (Array.of_list (List.map f relations)))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN - - let push ( x : fixedpoint ) = - Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) - - let pop ( x : fixedpoint ) = - Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) - - let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) - - let get_answer ( x : fixedpoint ) = - let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let get_reason_unknown ( x : fixedpoint ) = - Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - - let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = - Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) - - let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = - let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) - - let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) - - let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr list ) = - let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) - - let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - mk_list f n - - let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - mk_list f n - - let mk_fixedpoint ( ctx : context ) = create ctx -end - -module Options = -struct - - let update_param_value ( ctx : context ) ( id : string) ( value : string )= - Z3native.update_param_value (context_gno ctx) id value - - let get_param_value ( ctx : context ) ( id : string ) = - let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in - if not r then - None - else - Some v - - let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = - Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) - - let toggle_warning_messages ( enabled: bool ) = - Z3native.toggle_warning_messages enabled -end - - -module SMT = -struct - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr list ) ( formula : Boolean.bool_expr ) = - Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (List.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.of_list (List.map f assumptions))) - (Boolean.gno formula) - - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Z3native.parse_smtlib_string (context_gno ctx) str - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) - - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Z3native.parse_smtlib_file (context_gno ctx) file_name - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) - - let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) - - let get_smtlib_formulas ( ctx : context ) = - let n = (get_num_smtlib_formulas ctx ) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in - mk_list f n - - let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) - - let get_smtlib_assumptions ( ctx : context ) = - let n = (get_num_smtlib_assumptions ctx ) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in - mk_list f n - - let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) - - let get_smtlib_decls ( ctx : context ) = - let n = (get_num_smtlib_decls ctx) in - let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in - mk_list f n - - let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) - - let get_smtlib_sorts ( ctx : context ) = - let n = (get_num_smtlib_sorts ctx) in - let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in - mk_list f n - - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) - - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) -end - - -let set_global_param ( id : string ) ( value : string ) = - (Z3native.global_param_set id value) - -let get_global_param ( id : string ) = - let (r, v) = (Z3native.global_param_get id) in - if not r then - None - else - Some v - -let global_param_reset_all = - Z3native.global_param_reset_all diff --git a/src/api/ml/z3_rich.mli b/src/api/ml/z3_rich.mli deleted file mode 100644 index f2ecd326d..000000000 --- a/src/api/ml/z3_rich.mli +++ /dev/null @@ -1,3071 +0,0 @@ -(** - The Z3 ML/Ocaml Interface. - - Copyright (C) 2012 Microsoft Corporation - @author CM Wintersteiger (cwinter) 2012-12-17 - - NOTE: This is the *rich* version of the interface, using more - type information directly in the type system. Coercion functions - are provided to tran coerce on type into another where applicable. -*) - -(** Context objects. - - Most interactions with Z3 are interpreted in some context; many users will only - require one such object, but power users may require more than one. To start using - Z3, do - - - let ctx = (mk_context []) in - (...) - - - where a list of pairs of strings may be passed to set options on - the context, e.g., like so: - - - let cfg = [("model", "true"); ("...", "...")] in - let ctx = (mk_context cfg) in - (...) - -*) -type context - -(** Create a context object *) -val mk_context : (string * string) list -> context - -(** 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. *) -module Log : -sig - (** Open an interaction log file. - @return True if opening the log file succeeds, false otherwise. *) - (* CMW: "open" seems to be a reserved keyword? *) - val open_ : string -> bool - - (** Closes the interaction log. *) - val close : unit - - (** Appends a user-provided string to the interaction log. *) - val append : string -> unit -end - -(** Version information *) -module Version : -sig - (** The major version. *) - val major : int - - (** The minor version. *) - val minor : int - - (** The build version. *) - val build : int - - (** The revision. *) - val revision : int - - (** A string representation of the version information. *) - val to_string : string -end - -(** Symbols are used to name several term and type constructors *) -module Symbol : -sig - (** Numbered Symbols *) - type int_symbol - - (** Named Symbols *) - type string_symbol - - (** Symbols *) - type symbol = S_Int of int_symbol | S_Str of string_symbol - - (** The kind of the symbol (int or string) *) - val kind : symbol -> Z3enums.symbol_kind - - (** Indicates whether the symbol is of Int kind *) - val is_int_symbol : symbol -> bool - - (** Indicates whether the symbol is of string kind. *) - val is_string_symbol : symbol -> bool - - (** The int value of the symbol. *) - val get_int : int_symbol -> int - - (** The string value of the symbol. *) - val get_string : string_symbol -> string - - (** A string representation of the symbol. *) - val to_string : symbol -> string - - (** 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. *) - val mk_int : context -> int -> symbol - - (** Creates a new symbol using a string. *) - val mk_string : context -> string -> symbol - - (** Create a list of symbols. *) - val mk_ints : context -> int list -> symbol list - - (** Create a list of symbols. *) - val mk_strings : context -> string list -> symbol list -end - -(** The abstract syntax tree (AST) module *) -module AST : -sig - type ast - - (** Vectors of ASTs *) - module ASTVector : - sig - type ast_vector - - (** The size of the vector *) - val get_size : ast_vector -> int - - (** - Retrieves the i-th object in the vector. - @return An AST *) - val get : ast_vector -> int -> ast - - (** Sets the i-th object in the vector. *) - val set : ast_vector -> int -> ast -> unit - - (** Resize the vector to a new size. *) - val resize : ast_vector -> int -> unit - - (** Add an ast to the back of the vector. The size - is increased by 1. *) - val push : ast_vector -> ast -> unit - - (** Translates all ASTs in the vector to another context. - @return A new ASTVector *) - val translate : ast_vector -> context -> ast_vector - - (** Retrieves a string representation of the vector. *) - val to_string : ast_vector -> string - end - - (** Map from AST to AST *) - module ASTMap : - sig - type ast_map - - (** Checks whether the map contains a key. - @return True if the key in the map, false otherwise. *) - val contains : ast_map -> ast -> bool - - (** Finds the value associated with the key. - This function signs an error when the key is not a key in the map. *) - val find : ast_map -> ast -> ast - - (** Stores or replaces a new key/value pair in the map. *) - val insert : ast_map -> ast -> ast -> unit - - (** Erases the key from the map.*) - val erase : ast_map -> ast -> unit - - (** Removes all keys from the map. *) - val reset : ast_map -> unit - - (** The size of the map *) - val get_size : ast_map -> int - - (** The keys stored in the map. *) - val get_keys : ast_map -> ast list - - (** Retrieves a string representation of the map.*) - val to_string : ast_map -> string - end - - (** The AST's hash code. - @return A hash code *) - val get_hash_code : ast -> int - - (** A unique identifier for the AST (unique among all ASTs). *) - val get_id : ast -> int - - (** The kind of the AST. *) - val get_ast_kind : ast -> Z3enums.ast_kind - - (** Indicates whether the AST is an Expr *) - val is_expr : ast -> bool - - (** Indicates whether the AST is a bound variable*) - val is_var : ast -> bool - - (** Indicates whether the AST is a Quantifier *) - val is_quantifier : ast -> bool - - (** Indicates whether the AST is a Sort *) - val is_sort : ast -> bool - - (** Indicates whether the AST is a func_decl *) - val is_func_decl : ast -> bool - - (** A string representation of the AST. *) - val to_string : ast -> string - - (** A string representation of the AST in s-expression notation. *) - val to_sexpr : ast -> string - - (** Comparison operator. - @return True if the two ast's are from the same context - and represent the same sort; false otherwise. *) - val ( = ) : ast -> ast -> bool - - (** Object Comparison. - @return Negative if the first ast should be sorted before the second, positive if after else zero. *) - val compare : ast -> ast -> int - - (** Operator < *) - val ( < ) : ast -> ast -> int - - (** Translates (copies) the AST to another context. - @return A copy of the AST which is associated with the other context. *) - val translate : ast -> context -> ast - - (** Wraps an AST. - - This function is used for transitions between native and - managed objects. Note that the native ast that is passed must be a - native object obtained from Z3 (e.g., through {!unwrap_ast}) - and that it must have a correct reference count (see e.g., - Z3native.inc_ref). *) - val wrap_ast : context -> Z3native.z3_ast -> ast - - (** 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., - Z3native.inc_ref). - {!wrap_ast} *) - val unwrap_ast : ast -> Z3native.ptr -end - -(** The Sort module implements type information for ASTs *) -module Sort : -sig - (** Sorts *) - type sort = Sort of AST.ast - - (** Uninterpreted Sorts *) - type uninterpreted_sort = UninterpretedSort of sort - - val ast_of_sort : sort -> AST.ast - val sort_of_uninterpreted_sort : uninterpreted_sort -> sort - val uninterpreted_sort_of_sort : sort -> uninterpreted_sort - - (** Comparison operator. - @return True if the two sorts are from the same context - and represent the same sort; false otherwise. *) - val ( = ) : sort -> sort -> bool - - (** Returns a unique identifier for the sort. *) - val get_id : sort -> int - - (** The kind of the sort. *) - val get_sort_kind : sort -> Z3enums.sort_kind - - (** The name of the sort *) - val get_name : sort -> Symbol.symbol - - (** A string representation of the sort. *) - val to_string : sort -> string - - (** Create a new uninterpreted sort. *) - val mk_uninterpreted : context -> Symbol.symbol -> uninterpreted_sort - - (** Create a new uninterpreted sort. *) - val mk_uninterpreted_s : context -> string -> uninterpreted_sort -end - -(** Function declarations *) -module rec FuncDecl : -sig - type func_decl = FuncDecl of AST.ast - - val ast_of_func_decl : FuncDecl.func_decl -> AST.ast - - (** Parameters of Func_Decls *) - module Parameter : - sig - (** Parameters of func_decls *) - type parameter = - P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - (** The kind of the parameter. *) - val get_kind : parameter -> Z3enums.parameter_kind - - (** The int value of the parameter.*) - val get_int : parameter -> int - - (** The double value of the parameter.*) - val get_float : parameter -> float - - (** The Symbol.Symbol value of the parameter.*) - val get_symbol : parameter -> Symbol.symbol - - (** The Sort value of the parameter.*) - val get_sort : parameter -> Sort.sort - - (** The AST value of the parameter.*) - val get_ast : parameter -> AST.ast - - (** The FunctionDeclaration value of the parameter.*) - val get_func_decl : parameter -> func_decl - - (** The rational string value of the parameter.*) - val get_rational : parameter -> string - end - - (** Creates a new function declaration. *) - val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl - - (** Creates a new function declaration. *) - val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl - (** Creates a fresh function declaration with a name prefixed with a prefix string. *) - - val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl - - (** Creates a new constant function declaration. *) - val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl - - (** Creates a new constant function declaration. *) - val mk_const_decl_s : context -> string -> Sort.sort -> func_decl - - (** Creates a fresh constant function declaration with a name prefixed with a prefix string. - {!mk_func_decl} - {!mk_func_decl} *) - val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl - - (** Comparison operator. - @return True if a and b are from the same context and represent the same func_decl; false otherwise. *) - val ( = ) : func_decl -> func_decl -> bool - - (** A string representations of the function declaration. *) - val to_string : func_decl -> string - - (** Returns a unique identifier for the function declaration. *) - val get_id : func_decl -> int - - (** The arity of the function declaration *) - val get_arity : func_decl -> int - - (** The size of the domain of the function declaration - {!get_arity} *) - val get_domain_size : func_decl -> int - - (** The domain of the function declaration *) - val get_domain : func_decl -> Sort.sort list - - (** The range of the function declaration *) - val get_range : func_decl -> Sort.sort - - (** The kind of the function declaration. *) - val get_decl_kind : func_decl -> Z3enums.decl_kind - - (** The name of the function declaration*) - val get_name : func_decl -> Symbol.symbol - - (** The number of parameters of the function declaration *) - val get_num_parameters : func_decl -> int - - (** The parameters of the function declaration *) - val get_parameters : func_decl -> Parameter.parameter list - - (** Create expression that applies function to arguments. *) - val apply : func_decl -> Expr.expr list -> Expr.expr -end - -(** Parameter sets (of Solvers, Tactics, ...) - - A Params objects represents a configuration in the form of Symbol.symbol/value pairs. *) -and Params : -sig - type params - - (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) - module ParamDescrs : - sig - type param_descrs - - (** Validate a set of parameters. *) - val validate : param_descrs -> params -> unit - - (** Retrieve kind of parameter. *) - val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind - - (** Retrieve all names of parameters. *) - val get_names : param_descrs -> Symbol.symbol list - - (** The size of the ParamDescrs. *) - val get_size : param_descrs -> int - - (** Retrieves a string representation of the ParamDescrs. *) - val to_string : param_descrs -> string - end - - (** Adds a parameter setting. *) - val add_bool : params -> Symbol.symbol -> bool -> unit - - (** Adds a parameter setting. *) - val add_int : params -> Symbol.symbol -> int -> unit - - (** Adds a parameter setting. *) - val add_double : params -> Symbol.symbol -> float -> unit - - (** Adds a parameter setting. *) - val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - - (** Adds a parameter setting. *) - val add_s_bool : params -> string -> bool -> unit - - (** Adds a parameter setting. *) - val add_s_int : params -> string -> int -> unit - - (** Adds a parameter setting. *) - val add_s_double : params -> string -> float -> unit - - (** Adds a parameter setting. *) - val add_s_symbol : params -> string -> Symbol.symbol -> unit - - (** Creates a new parameter set *) - val mk_params : context -> params - - (** A string representation of the parameter set. *) - val to_string : params -> string -end - -(** General Expressions (terms) *) -and Expr : -sig - type expr = Expr of AST.ast - - val ast_of_expr : Expr.expr -> AST.ast - val expr_of_ast : AST.ast -> Expr.expr - - (** Returns a simplified version of the expression. - {!get_simplify_help} *) - val simplify : Expr.expr -> Params.params option -> expr - - (** A string describing all available parameters to Expr.Simplify. *) - val get_simplify_help : context -> string - - (** Retrieves parameter descriptions for simplifier. *) - val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs - - (** The function declaration of the function that is applied in this expression. *) - val get_func_decl : Expr.expr -> FuncDecl.func_decl - - (** Indicates whether the expression is the true or false expression - or something else (L_UNDEF). *) - val get_bool_value : Expr.expr -> Z3enums.lbool - - (** The number of arguments of the expression. *) - val get_num_args : Expr.expr -> int - - (** The arguments of the expression. *) - val get_args : Expr.expr -> Expr.expr list - - (** Update the arguments of the expression using an array of expressions. - The number of new arguments should coincide with the current number of arguments. *) - val update : Expr.expr -> Expr.expr list -> expr - - (** 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]. *) - val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr - - (** Substitute every occurrence of from in the expression with to. - {!substitute} *) - val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr - - (** Substitute the free variables in the expression with the expressions in the expr array - - For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) - val substitute_vars : Expr.expr -> Expr.expr list -> expr - - (** Translates (copies) the term to another context. - @return A copy of the term which is associated with the other context *) - val translate : Expr.expr -> context -> expr - - (** Returns a string representation of the expression. *) - val to_string : Expr.expr -> string - - (** Indicates whether the term is a numeral *) - val is_numeral : Expr.expr -> bool - - (** Indicates whether the term is well-sorted. - @return True if the term is well-sorted, false otherwise. *) - val is_well_sorted : Expr.expr -> bool - - (** The Sort of the term. *) - val get_sort : Expr.expr -> Sort.sort - - (** Indicates whether the term has Boolean sort. *) - val is_bool : Expr.expr -> bool - - (** Indicates whether the term represents a constant. *) - val is_const : Expr.expr -> bool - - (** Indicates whether the term is the constant true. *) - val is_true : Expr.expr -> bool - - (** Indicates whether the term is the constant false. *) - val is_false : Expr.expr -> bool - - (** Indicates whether the term is an equality predicate. *) - val is_eq : Expr.expr -> bool - - (** Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). *) - val is_distinct : Expr.expr -> bool - - (** Indicates whether the term is a ternary if-then-else term *) - val is_ite : Expr.expr -> bool - - (** Indicates whether the term is an n-ary conjunction *) - val is_and : Expr.expr -> bool - - (** Indicates whether the term is an n-ary disjunction *) - val is_or : Expr.expr -> bool - - (** Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) *) - val is_iff : Expr.expr -> bool - - (** Indicates whether the term is an exclusive or *) - val is_xor : Expr.expr -> bool - - (** Indicates whether the term is a negation *) - val is_not : Expr.expr -> bool - - (** Indicates whether the term is an implication *) - val is_implies : Expr.expr -> bool - - (** 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. *) - val is_label : Expr.expr -> bool - - (** 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. - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) *) - val is_label_lit : Expr.expr -> bool - - (** 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. *) - val is_oeq : Expr.expr -> bool - - (** Creates a new constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - - (** Creates a new constant. *) - val mk_const_s : context -> string -> Sort.sort -> expr - - (** Creates a constant from the func_decl. *) - val mk_const_f : context -> FuncDecl.func_decl -> expr - - (** Creates a fresh constant with a name prefixed with a string. *) - val mk_fresh_const : context -> string -> Sort.sort -> expr - - (** Create a new function application. *) - val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr - - (** Create a numeral of a given sort. - @return A Term with the goven value and sort *) - val mk_numeral_string : context -> string -> Sort.sort -> expr - - (** Create a numeral 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. - @return A Term with the given value and sort *) - val mk_numeral_int : context -> int -> Sort.sort -> expr -end - -(** Boolean expressions *) -module Boolean : -sig - type bool_sort = BoolSort of Sort.sort - type bool_expr = BoolExpr of Expr.expr - - val expr_of_bool_expr : bool_expr -> Expr.expr - val sort_of_bool_sort : bool_sort -> Sort.sort - val bool_sort_of_sort : Sort.sort -> bool_sort - val bool_expr_of_expr : Expr.expr -> bool_expr - - (** Create a Boolean sort *) - val mk_sort : context -> bool_sort - - (** Create a Boolean constant. *) - val mk_const : context -> Symbol.symbol -> bool_expr - - (** Create a Boolean constant. *) - val mk_const_s : context -> string -> bool_expr - - (** The true Term. *) - val mk_true : context -> bool_expr - - (** The false Term. *) - val mk_false : context -> bool_expr - - (** Creates a Boolean value. *) - val mk_val : context -> bool -> bool_expr - - (** Creates the equality between two expr's. *) - val mk_eq : context -> Expr.expr -> Expr.expr -> bool_expr - - (** Creates a distinct term. *) - val mk_distinct : context -> Expr.expr list -> bool_expr - - (** Mk an expression representing not(a). *) - val mk_not : context -> bool_expr -> bool_expr - - (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) - val mk_ite : context -> bool_expr -> bool_expr -> bool_expr -> bool_expr - - (** Create an expression representing t1 iff t2. *) - val mk_iff : context -> bool_expr -> bool_expr -> bool_expr - - (** Create an expression representing t1 -> t2. *) - val mk_implies : context -> bool_expr -> bool_expr -> bool_expr - - (** Create an expression representing t1 xor t2. *) - val mk_xor : context -> bool_expr -> bool_expr -> bool_expr - - (** Create an expression representing the AND of args *) - val mk_and : context -> bool_expr list -> bool_expr - - (** Create an expression representing the OR of args *) - val mk_or : context -> bool_expr list -> bool_expr -end - -(** Quantifier expressions *) -module Quantifier : -sig - type quantifier = Quantifier of Expr.expr - - val expr_of_quantifier : quantifier -> Expr.expr - val quantifier_of_expr : Expr.expr -> quantifier - - (** Quantifier patterns - - 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. *) - module Pattern : - sig - type pattern = Pattern of AST.ast - - val ast_of_pattern : pattern -> AST.ast - val pattern_of_ast : AST.ast -> pattern - - (** The number of terms in the pattern. *) - val get_num_terms : pattern -> int - - (** The terms in the pattern. *) - val get_terms : pattern -> Expr.expr list - - (** A string representation of the pattern. *) - val to_string : pattern -> string - end - - - (** 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 : expr ) appears, the higher is its - index. *) - val get_index : Expr.expr -> int - - (** Indicates whether the quantifier is universal. *) - val is_universal : quantifier -> bool - - (** Indicates whether the quantifier is existential. *) - val is_existential : quantifier -> bool - - (** The weight of the quantifier. *) - val get_weight : quantifier -> int - - (** The number of patterns. *) - val get_num_patterns : quantifier -> int - - (** The patterns. *) - val get_patterns : quantifier -> Pattern.pattern list - - (** The number of no-patterns. *) - val get_num_no_patterns : quantifier -> int - - (** The no-patterns. *) - val get_no_patterns : quantifier -> Pattern.pattern list - - (** The number of bound variables. *) - val get_num_bound : quantifier -> int - - (** The symbols for the bound variables. *) - val get_bound_variable_names : quantifier -> Symbol.symbol list - - (** The sorts of the bound variables. *) - val get_bound_variable_sorts : quantifier -> Sort.sort list - - (** The body of the quantifier. *) - val get_body : quantifier -> Boolean.bool_expr - - (** Creates a new bound variable. *) - val mk_bound : context -> int -> Sort.sort -> Expr.expr - - (** Create a quantifier pattern. *) - val mk_pattern : context -> Expr.expr list -> Pattern.pattern - - (** Create a universal Quantifier. *) - val mk_forall : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a universal Quantifier. *) - val mk_forall_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create an existential Quantifier. *) - val mk_exists : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create an existential Quantifier. *) - val mk_exists_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a Quantifier. *) - val mk_quantifier : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a Quantifier. *) - val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier -end - -(** Functions to manipulate Array expressions *) -module Array_ : -sig - type array_sort = ArraySort of Sort.sort - type array_expr = ArrayExpr of Expr.expr - - val sort_of_array_sort : array_sort -> Sort.sort - val array_sort_of_sort : Sort.sort -> array_sort - val expr_of_array_expr : array_expr -> Expr.expr - - val array_expr_of_expr : Expr.expr -> array_expr - - (** Create a new array sort. *) - val mk_sort : context -> Sort.sort -> Sort.sort -> 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. *) - val is_store : Expr.expr -> bool - - (** Indicates whether the term is an array select. *) - val is_select : Expr.expr -> bool - - (** 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. *) - val is_constant_array : Expr.expr -> bool - - (** Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. *) - val is_default_array : Expr.expr -> bool - - (** 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. *) - val is_array_map : Expr.expr -> bool - - (** 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. *) - val is_as_array : Expr.expr -> bool - - (** Indicates whether the term is of an array sort. *) - val is_array : Expr.expr -> bool - - (** The domain of the array sort. *) - val get_domain : array_sort -> Sort.sort - - (** The range of the array sort. *) - val get_range : array_sort -> Sort.sort - - (** Create an array constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> array_expr - - (** Create an array constant. *) - val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> array_expr - - (** 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. - {!Array_.mk_sort} - {!mk_store} *) - val mk_select : context -> array_expr -> Expr.expr -> array_expr - - (** 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). - {!Array_.mk_sort} - {!mk_select} *) - val mk_store : context -> array_expr -> Expr.expr -> Expr.expr -> array_expr - - (** Create a constant array. - - The resulting term is an array, such that a selecton an arbitrary index - produces the value v. - {!Array_.mk_sort} - {!mk_select} *) - val mk_const_array : context -> Sort.sort -> Expr.expr -> array_expr - - (** 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]. - {!Array_.mk_sort} - {!mk_select} - {!mk_store} *) - val mk_map : context -> FuncDecl.func_decl -> array_expr list -> array_expr - - (** Access the array default value. - - Produces the default range value, for arrays that can be represented as - finite maps with a default range value. *) - val mk_term_array : context -> array_expr -> array_expr -end - -(** Functions to manipulate Set expressions *) -module Set : -sig - type set_sort = SetSort of Sort.sort - - val sort_of_set_sort : set_sort -> Sort.sort - - (** Create a set type. *) - val mk_sort : context -> Sort.sort -> set_sort - - (** Indicates whether the term is set union *) - val is_union : Expr.expr -> bool - - (** Indicates whether the term is set intersection *) - val is_intersect : Expr.expr -> bool - - (** Indicates whether the term is set difference *) - val is_difference : Expr.expr -> bool - - (** Indicates whether the term is set complement *) - val is_complement : Expr.expr -> bool - - (** Indicates whether the term is set subset *) - val is_subset : Expr.expr -> bool - - (** Create an empty set. *) - val mk_empty : context -> Sort.sort -> Expr.expr - - (** Create the full set. *) - val mk_full : context -> Sort.sort -> Expr.expr - - (** Add an element to the set. *) - val mk_set_add : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Remove an element from a set. *) - val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Take the union of a list of sets. *) - val mk_union : context -> Expr.expr list -> Expr.expr - - (** Take the intersection of a list of sets. *) - val mk_intersection : context -> Expr.expr list -> Expr.expr - - (** Take the difference between two sets. *) - val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Take the complement of a set. *) - val mk_complement : context -> Expr.expr -> Expr.expr - - (** Check for set membership. *) - val mk_membership : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Check for subsetness of sets. *) - val mk_subset : context -> Expr.expr -> Expr.expr -> Expr.expr -end - -(** Functions to manipulate Finite Domain expressions *) -module FiniteDomain : -sig - type finite_domain_sort = FiniteDomainSort of Sort.sort - - val sort_of_finite_domain_sort : finite_domain_sort -> Sort.sort - val finite_domain_sort_of_sort : Sort.sort -> finite_domain_sort - - (** Create a new finite domain sort. *) - val mk_sort : context -> Symbol.symbol -> int -> finite_domain_sort - - (** Create a new finite domain sort. *) - val mk_sort_s : context -> string -> int -> finite_domain_sort - - (** Indicates whether the term is of an array sort. *) - val is_finite_domain : Expr.expr -> bool - - (** Indicates whether the term is a less than predicate over a finite domain. *) - val is_lt : Expr.expr -> bool - - (** The size of the finite domain sort. *) - val get_size : finite_domain_sort -> int -end - - -(** Functions to manipulate Relation expressions *) -module Relation : -sig - type relation_sort = RelationSort of Sort.sort - - val sort_of_relation_sort : relation_sort -> Sort.sort - val relation_sort_of_sort : Sort.sort -> relation_sort - - (** Indicates whether the term is of a relation sort. *) - val is_relation : Expr.expr -> bool - - (** 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. *) - val is_store : Expr.expr -> bool - - (** Indicates whether the term is an empty relation *) - val is_empty : Expr.expr -> bool - - (** Indicates whether the term is a test for the emptiness of a relation *) - val is_is_empty : Expr.expr -> bool - - (** Indicates whether the term is a relational join *) - val is_join : Expr.expr -> bool - - (** Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. *) - val is_union : Expr.expr -> bool - - (** Indicates whether the term is the widening of two relations - The function takes two arguments. *) - val is_widen : Expr.expr -> bool - - (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. *) - val is_project : Expr.expr -> bool - - (** 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. *) - val is_filter : Expr.expr -> bool - - (** 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. *) - val is_negation_filter : Expr.expr -> bool - - (** 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. *) - val is_rename : Expr.expr -> bool - - (** Indicates whether the term is the complement of a relation *) - val is_complement : Expr.expr -> bool - - (** 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. *) - val is_select : Expr.expr -> bool - - (** 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 {!is_union} - to perform destructive updates to the first argument. *) - val is_clone : Expr.expr -> bool - - (** The arity of the relation sort. *) - val get_arity : relation_sort -> int - - (** The sorts of the columns of the relation sort. *) - val get_column_sorts : relation_sort -> relation_sort list -end - -(** Functions to manipulate Datatype expressions *) -module Datatype : -sig - type datatype_sort = DatatypeSort of Sort.sort - type datatype_expr = DatatypeExpr of Expr.expr - - val sort_of_datatype_sort : datatype_sort -> Sort.sort - val datatype_sort_of_sort : Sort.sort -> datatype_sort - val expr_of_datatype_expr : datatype_expr -> Expr.expr - val datatype_expr_of_expr : Expr.expr -> datatype_expr - - (** Datatype Constructors *) - module Constructor : - sig - type constructor - - (** The number of fields of the constructor. *) - val get_num_fields : constructor -> int - - (** The function declaration of the constructor. *) - val get_constructor_decl : constructor -> FuncDecl.func_decl - - (** The function declaration of the tester. *) - val get_tester_decl : constructor -> FuncDecl.func_decl - - (** The function declarations of the accessors *) - val get_accessor_decls : constructor -> FuncDecl.func_decl list - end - - (** Create a datatype 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. *) - val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor - - (** Create a datatype 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. *) - val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor - - (** Create a new datatype sort. *) - val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> datatype_sort - - (** Create a new datatype sort. *) - val mk_sort_s : context -> string -> Constructor.constructor list -> datatype_sort - - (** Create mutually recursive datatypes. *) - val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> datatype_sort list - - (** Create mutually recursive data-types. *) - val mk_sorts_s : context -> string list -> Constructor.constructor list list -> datatype_sort list - - - (** The number of constructors of the datatype sort. *) - val get_num_constructors : datatype_sort -> int - - (** The constructors. *) - val get_constructors : datatype_sort -> FuncDecl.func_decl list - - (** The recognizers. *) - val get_recognizers : datatype_sort -> FuncDecl.func_decl list - - (** The constructor accessors. *) - val get_accessors : datatype_sort -> FuncDecl.func_decl list list -end - -(** Functions to manipulate Enumeration expressions *) -module Enumeration : -sig - type enum_sort = EnumSort of Sort.sort - - val sort_of_enum_sort : enum_sort -> Sort.sort - - (** Create a new enumeration sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> enum_sort - - (** Create a new enumeration sort. *) - val mk_sort_s : context -> string -> string list -> enum_sort - - (** The function declarations of the constants in the enumeration. *) - val get_const_decls : enum_sort -> FuncDecl.func_decl list - - (** The test predicates for the constants in the enumeration. *) - val get_tester_decls : enum_sort -> FuncDecl.func_decl list -end - -(** Functions to manipulate List expressions *) -module List_ : -sig - type list_sort = ListSort of Sort.sort - - val sort_of_list_sort : list_sort -> Sort.sort - - (** Create a new list sort. *) - val mk_sort : context -> Symbol.symbol -> Sort.sort -> list_sort - - (** Create a new list sort. *) - val mk_list_s : context -> string -> Sort.sort -> list_sort - - (** The declaration of the nil function of this list sort. *) - val get_nil_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the isNil function of this list sort. *) - val get_is_nil_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the cons function of this list sort. *) - val get_cons_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the isCons function of this list sort. *) - val get_is_cons_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the head function of this list sort. *) - val get_head_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the tail function of this list sort. *) - val get_tail_decl : list_sort -> FuncDecl.func_decl - - (** The empty list. *) - val nil : list_sort -> Expr.expr -end - -(** Functions to manipulate Tuple expressions *) -module Tuple : -sig - type tuple_sort = TupleSort of Sort.sort - - val sort_of_tuple_sort : tuple_sort -> Sort.sort - - (** Create a new tuple sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> tuple_sort - - (** The constructor function of the tuple. *) - val get_mk_decl : tuple_sort -> FuncDecl.func_decl - - (** The number of fields in the tuple. *) - val get_num_fields : tuple_sort -> int - - (** The field declarations. *) - val get_field_decls : tuple_sort -> FuncDecl.func_decl list -end - -(** Functions to manipulate arithmetic expressions *) -module rec Arithmetic : -sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val sort_of_arith_sort : Arithmetic.arith_sort -> Sort.sort - val arith_sort_of_sort : Sort.sort -> Arithmetic.arith_sort - val expr_of_arith_expr : Arithmetic.arith_expr -> Expr.expr - val arith_expr_of_expr : Expr.expr -> Arithmetic.arith_expr - - (** Integer Arithmetic *) - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val arith_sort_of_int_sort : Arithmetic.Integer.int_sort -> Arithmetic.arith_sort - val int_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Integer.int_sort - val arith_expr_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.arith_expr - val int_expr_of_int_num : Arithmetic.Integer.int_num -> Arithmetic.Integer.int_expr - val int_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Integer.int_expr - val int_num_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.Integer.int_num - - (** Create a new integer sort. *) - val mk_sort : context -> int_sort - - (** Retrieve the int value. *) - val get_int : int_num -> int - - (** Returns a string representation of the numeral. *) - val to_string : int_num -> string - - (** Creates an integer constant. *) - val mk_const : context -> Symbol.symbol -> int_expr - - (** Creates an integer constant. *) - val mk_const_s : context -> string -> int_expr - - (** Create an expression representing t1 mod t2. - The arguments must have int type. *) - val mk_mod : context -> int_expr -> int_expr -> int_expr - - (** Create an expression representing t1 rem t2. - The arguments must have int type. *) - val mk_rem : context -> int_expr -> int_expr -> int_expr - - (** Create an integer numeral. *) - val mk_numeral_s : context -> string -> int_num - - (** Create an integer numeral. - @return A Term with the given value and sort Integer *) - val mk_numeral_i : context -> int -> int_num - - (** 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. *) - val mk_int2real : context -> int_expr -> Real.real_expr - - (** Create an n-bit bit-vector from an 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. *) - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end - - (** Real Arithmetic *) - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort - val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort - val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr - val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr - val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr - val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num - - (** Create a real sort. *) - val mk_sort : context -> real_sort - - (** The numerator of a rational numeral. *) - val get_numerator : rat_num -> Integer.int_num - - (** The denominator of a rational numeral. *) - val get_denominator : rat_num -> Integer.int_num - - (** Returns a string representation in decimal notation. - The result has at most as many decimal places as indicated by the int argument.*) - val to_decimal_string : rat_num -> int -> string - - (** Returns a string representation of the numeral. *) - val to_string : rat_num -> string - - (** Creates a real constant. *) - val mk_const : context -> Symbol.symbol -> real_expr - - (** Creates a real constant. *) - val mk_const_s : context -> string -> real_expr - - (** Create a real numeral from a fraction. - @return A Term with rational value and sort Real - {!mk_numeral_s} *) - val mk_numeral_nd : context -> int -> int -> rat_num - - (** Create a real numeral. - @return A Term with the given value and sort Real *) - val mk_numeral_s : context -> string -> rat_num - - (** Create a real numeral. - @return A Term with the given value and sort Real *) - val mk_numeral_i : context -> int -> rat_num - - (** Creates an expression that checks whether a real number is an integer. *) - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - - (** 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. *) - val mk_real2int : context -> real_expr -> Integer.int_expr - end - - (** Algebraic Numbers *) - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : Arithmetic.AlgebraicNumber.algebraic_num -> Arithmetic.arith_expr - val algebraic_num_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.AlgebraicNumber.algebraic_num - - (** Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) - val to_upper : algebraic_num -> int -> Real.rat_num - - (** Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) - val to_lower : algebraic_num -> int -> Real.rat_num - - (** Returns a string representation in decimal notation. - The result has at most as many decimal places as the int argument provided.*) - val to_decimal_string : algebraic_num -> int -> string - - (** Returns a string representation of the numeral. *) - val to_string : algebraic_num -> string - end - - (** Indicates whether the term is of integer sort. *) - val is_int : Expr.expr -> bool - - (** Indicates whether the term is an arithmetic numeral. *) - val is_arithmetic_numeral : Expr.expr -> bool - - (** Indicates whether the term is a less-than-or-equal *) - val is_le : Expr.expr -> bool - - (** Indicates whether the term is a greater-than-or-equal *) - val is_ge : Expr.expr -> bool - - (** Indicates whether the term is a less-than *) - val is_lt : Expr.expr -> bool - - (** Indicates whether the term is a greater-than *) - val is_gt : Expr.expr -> bool - - (** Indicates whether the term is addition (binary) *) - val is_add : Expr.expr -> bool - - (** Indicates whether the term is subtraction (binary) *) - val is_sub : Expr.expr -> bool - - (** Indicates whether the term is a unary minus *) - val is_uminus : Expr.expr -> bool - - (** Indicates whether the term is multiplication (binary) *) - val is_mul : Expr.expr -> bool - - (** Indicates whether the term is division (binary) *) - val is_div : Expr.expr -> bool - - (** Indicates whether the term is integer division (binary) *) - val is_idiv : Expr.expr -> bool - - (** Indicates whether the term is remainder (binary) *) - val is_remainder : Expr.expr -> bool - - (** Indicates whether the term is modulus (binary) *) - val is_modulus : Expr.expr -> bool - - (** Indicates whether the term is a coercion of integer to real (unary) *) - val is_inttoreal : Expr.expr -> bool - - (** Indicates whether the term is a coercion of real to integer (unary) *) - val is_real_to_int : Expr.expr -> bool - - (** Indicates whether the term is a check that tests whether a real is integral (unary) *) - val is_real_is_int : Expr.expr -> bool - - (** Indicates whether the term is of sort real. *) - val is_real : Expr.expr -> bool - - (** Indicates whether the term is an integer numeral. *) - val is_int_numeral : Expr.expr -> bool - - (** Indicates whether the term is a real numeral. *) - val is_rat_num : Expr.expr -> bool - - (** Indicates whether the term is an algebraic number *) - val is_algebraic_number : Expr.expr -> bool - - (** Create an expression representing t[0] + t[1] + .... *) - val mk_add : context -> arith_expr list -> arith_expr - - (** Create an expression representing t[0] * t[1] * .... *) - val mk_mul : context -> arith_expr list -> arith_expr - - (** Create an expression representing t[0] - t[1] - .... *) - val mk_sub : context -> arith_expr list -> arith_expr - - (** Create an expression representing -t. *) - val mk_unary_minus : context -> arith_expr -> arith_expr - - (** Create an expression representing t1 / t2. *) - val mk_div : context -> arith_expr -> arith_expr -> arith_expr - - (** Create an expression representing t1 ^ t2. *) - val mk_power : context -> arith_expr -> arith_expr -> arith_expr - - (** Create an expression representing t1 < t2 *) - val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - - (** Create an expression representing t1 <= t2 *) - val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr - - (** Create an expression representing t1 > t2 *) - val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - - (** Create an expression representing t1 >= t2 *) - val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr -end - -(** Functions to manipulate bit-vector expressions *) -and BitVector : -sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort - val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort - val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr - val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr - val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr - val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num - - (** Create a new bit-vector sort. *) - val mk_sort : context -> int -> bitvec_sort - - (** Indicates whether the terms is of bit-vector sort. *) - val is_bv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector numeral *) - val is_bv_numeral : Expr.expr -> bool - - (** Indicates whether the term is a one-bit bit-vector with value one *) - val is_bv_bit1 : Expr.expr -> bool - - (** Indicates whether the term is a one-bit bit-vector with value zero *) - val is_bv_bit0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unary minus *) - val is_bv_uminus : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector addition (binary) *) - val is_bv_add : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector subtraction (binary) *) - val is_bv_sub : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector multiplication (binary) *) - val is_bv_mul : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed division (binary) *) - val is_bv_sdiv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned division (binary) *) - val is_bv_udiv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed remainder (binary) *) - val is_bv_SRem : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - val is_bv_urem : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed modulus *) - val is_bv_smod : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed division by zero *) - val is_bv_sdiv0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned division by zero *) - val is_bv_udiv0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed remainder by zero *) - val is_bv_srem0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - val is_bv_urem0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed modulus by zero *) - val is_bv_smod0 : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - val is_bv_ule : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - val is_bv_sle : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - val is_bv_uge : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - val is_bv_sge : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector less-than *) - val is_bv_ult : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector less-than *) - val is_bv_slt : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector greater-than *) - val is_bv_ugt : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector greater-than *) - val is_bv_sgt : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise AND *) - val is_bv_and : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise OR *) - val is_bv_or : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NOT *) - val is_bv_not : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise XOR *) - val is_bv_xor : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NAND *) - val is_bv_nand : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NOR *) - val is_bv_nor : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise XNOR *) - val is_bv_xnor : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector concatenation (binary) *) - val is_bv_concat : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector sign extension *) - val is_bv_signextension : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector zero extension *) - val is_bv_zeroextension : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector extraction *) - val is_bv_extract : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector repetition *) - val is_bv_repeat : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector reduce OR *) - val is_bv_reduceor : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector reduce AND *) - val is_bv_reduceand : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector comparison *) - val is_bv_comp : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector shift left *) - val is_bv_shiftleft : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector logical shift right *) - val is_bv_shiftrightlogical : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector arithmetic shift left *) - val is_bv_shiftrightarithmetic : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector rotate left *) - val is_bv_rotateleft : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector rotate right *) - val is_bv_rotateright : Expr.expr -> bool - - (** 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. *) - val is_bv_rotateleftextended : Expr.expr -> bool - - (** 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. *) - val is_bv_rotaterightextended : Expr.expr -> bool - - (** 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. *) - - (** 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. *) - val is_int_to_bv : Expr.expr -> bool - - (** 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. *) - val is_bv_to_int : Expr.expr -> bool - - (** 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))) *) - val is_bv_carry : Expr.expr -> bool - - (** 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) *) - val is_bv_xor3 : Expr.expr -> bool - - (** The size of a bit-vector sort. *) - val get_size : bitvec_sort -> int - - (** Retrieve the int value. *) - val get_int : bitvec_num -> int - - (** Returns a string representation of the numeral. *) - val to_string : bitvec_num -> string - - (** Creates a bit-vector constant. *) - val mk_const : context -> Symbol.symbol -> int -> bitvec_expr - - (** Creates a bit-vector constant. *) - val mk_const_s : context -> string -> int -> bitvec_expr - - (** Bitwise negation. - The argument must have a bit-vector sort. *) - val mk_not : context -> bitvec_expr -> Expr.expr - - (** Take conjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) - val mk_redand : context -> bitvec_expr -> Expr.expr - - (** Take disjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) - val mk_redor : context -> bitvec_expr -> Expr.expr - - (** Bitwise conjunction. - The arguments must have a bit-vector sort. *) - val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise disjunction. - The arguments must have a bit-vector sort. *) - val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise XOR. - The arguments must have a bit-vector sort. *) - val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise NAND. - The arguments must have a bit-vector sort. *) - val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise NOR. - The arguments must have a bit-vector sort. *) - val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise XNOR. - The arguments must have a bit-vector sort. *) - val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Standard two's complement unary minus. - The arguments must have a bit-vector sort. *) - val mk_neg : context -> bitvec_expr -> bitvec_expr - - (** Two's complement addition. - The arguments must have the same bit-vector sort. *) - val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Two's complement subtraction. - The arguments must have the same bit-vector sort. *) - val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Two's complement multiplication. - The arguments must have the same bit-vector sort. *) - val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Unsigned less-than - - The arguments must have the same bit-vector sort. *) - val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Two's complement signed less-than - - The arguments must have the same bit-vector sort. *) - val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Unsigned less-than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Two's complement signed less-than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Unsigned greater than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Two's complement signed greater than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Unsigned greater-than. - - The arguments must have the same bit-vector sort. *) - val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Two's complement signed greater-than. - - The arguments must have the same bit-vector sort. *) - val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** 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). *) - val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bit-vector extraction. - - Extract the bits between two limits from a bitvector of - size m to yield a new bitvector of size n, where - n = high - low + 1. *) - val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr - - (** Bit-vector repetition. *) - val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr - - (** Shift left. - - It is equivalent to multiplication by 2^x where \c x is the value of third 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.*) - val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Logical shift right - - It is equivalent to unsigned division by 2^x where \c x is the value of the third 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. *) - val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Rotate Left. - Rotate bits of \c t to the left \c i times. *) - val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr - - (** Rotate Right. - Rotate bits of \c t to the right \c i times.*) - val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr - - (** Rotate Left. - Rotate bits of the second argument to the left.*) - val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Rotate Right. - Rotate bits of the second argument to the right. *) - val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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 the argument. - 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.*) - val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr - - (** Create a predicate that checks that the bit-wise addition does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise addition does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise subtraction does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise subtraction does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise signed division does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise negation does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise multiplication does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise multiplication does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Create a bit-vector numeral. *) - val mk_numeral : context -> string -> int -> bitvec_num -end - -(** Functions to manipulate proof expressions *) -module Proof : -sig - (** Indicates whether the term is a Proof for the expression 'true'. *) - val is_true : Expr.expr -> bool - - (** Indicates whether the term is a proof for a fact asserted by the user. *) - val is_asserted : Expr.expr -> bool - - (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - val is_goal : Expr.expr -> bool - - (** 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). *) - val is_modus_ponens : Expr.expr -> bool - - (** 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'. *) - val is_reflexivity : Expr.expr -> bool - - (** 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. *) - val is_symmetry : Expr.expr -> bool - - (** 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) *) - val is_transitivity : Expr.expr -> bool - - (** 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. *) - val is_Transitivity_star : Expr.expr -> bool - - (** 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. *) - val is_monotonicity : Expr.expr -> bool - - (** 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)) *) - val is_quant_intro : Expr.expr -> bool - - (** 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. *) - val is_distributivity : Expr.expr -> bool - - (** 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 *) - val is_and_elimination : Expr.expr -> bool - - (** 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) *) - val is_or_elimination : Expr.expr -> bool - - (** 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 : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) *) - val is_rewrite : Expr.expr -> bool - - (** 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) *) - val is_rewrite_star : Expr.expr -> bool - - (** 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. *) - val is_pull_quant : Expr.expr -> bool - - (** 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 *) - val is_pull_quant_star : Expr.expr -> bool - - (** 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 *) - val is_push_quant : Expr.expr -> bool - - (** 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. *) - val is_elim_unused_vars : Expr.expr -> bool - - (** Indicates whether the term is a proof for destructive equality resolution - - A proof for destructive equality resolution: - (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. - - This proof object has no antecedents. - - Several variables can be eliminated simultaneously. *) - val is_der : Expr.expr -> bool - - (** Indicates whether the term is a proof for quantifier instantiation - - A proof of (or (not (forall (x) (P x))) (P a)) *) - val is_quant_inst : Expr.expr -> bool - - (** Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. *) - val is_hypothesis : Expr.expr -> bool - - (** 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. *) - val is_lemma : Expr.expr -> bool - - (** 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') *) - val is_unit_resolution : Expr.expr -> bool - - (** Indicates whether the term is a proof by iff-true - - T1: p - [iff-true T1]: (iff p true) *) - val is_iff_true : Expr.expr -> bool - - (** Indicates whether the term is a proof by iff-false - - T1: (not p) - [iff-false T1]: (iff p false) *) - val is_iff_false : Expr.expr -> bool - - (** 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. *) - val is_commutativity : Expr.expr -> bool - - (** 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). *) - val is_def_axiom : Expr.expr -> bool - - (** 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) *) - val is_def_intro : Expr.expr -> bool - - (** 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. *) - val is_apply_def : Expr.expr -> bool - - (** Indicates whether the term is a proof iff-oeq - - T1: (iff p q) - [iff~ T1]: (~ p q) *) - val is_iff_oeq : Expr.expr -> bool - - (** 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'. *) - val is_nnf_pos : Expr.expr -> bool - - (** 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'))) *) - val is_nnf_neg : Expr.expr -> bool - - (** 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. *) - val is_nnf_star : Expr.expr -> bool - - (** 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. *) - val is_cnf_star : Expr.expr -> bool - - (** Indicates whether the term is a proof for a Skolemization step - - Proof for: - - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) - - This proof object has no antecedents. *) - val is_skolemize : Expr.expr -> bool - - (** 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 *) - val is_modus_ponens_oeq : Expr.expr -> bool - - (** 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. *) - val is_theory_lemma : Expr.expr -> bool -end - -(** Goals - - A goal (aka problem). A goal is essentially a - of formulas, that can be solved and/or transformed using - tactics and solvers. *) -module Goal : -sig - type goal - - (** 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. *) - val get_precision : goal -> Z3enums.goal_prec - - (** Indicates whether the goal is precise. *) - val is_precise : goal -> bool - - (** Indicates whether the goal is an under-approximation. *) - val is_underapproximation : goal -> bool - - (** Indicates whether the goal is an over-approximation. *) - val is_overapproximation : goal -> bool - - (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) - val is_garbage : goal -> bool - - (** Adds the constraints to the given goal. *) - val assert_ : goal -> Boolean.bool_expr list -> unit - - (** Indicates whether the goal contains `false'. *) - val is_inconsistent : goal -> bool - - (** The depth of the goal. - This tracks how many transformations were applied to it. *) - val get_depth : goal -> int - - (** Erases all formulas from the given goal. *) - val reset : goal -> unit - - (** The number of formulas in the goal. *) - val get_size : goal -> int - - (** The formulas in the goal. *) - val get_formulas : goal -> Boolean.bool_expr list - - (** The number of formulas, subformulas and terms in the goal. *) - val get_num_exprs : goal -> int - - (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) - val is_decided_sat : goal -> bool - - (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) - val is_decided_unsat : goal -> bool - - (** Translates (copies) the Goal to another context.. *) - val translate : goal -> context -> goal - - (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - val simplify : goal -> Params.params option -> goal - - (** Creates a new Goal. - - Note that the Context must have been created with proof generation support if - the fourth argument is set to true here. *) - val mk_goal : context -> bool -> bool -> bool -> goal - - (** A string representation of the Goal. *) - val to_string : goal -> string -end - -(** Models - - A Model contains interpretations (assignments) of constants and functions. *) -module Model : -sig - type model - - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. *) - module FuncInterp : - sig - type func_interp - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. *) - module FuncEntry : - sig - type func_entry - - (** Return the (symbolic) value of this entry. - *) - val get_value : func_entry -> Expr.expr - - (** The number of arguments of the entry. - *) - val get_num_args : func_entry -> int - - (** The arguments of the function entry. - *) - val get_args : func_entry -> Expr.expr list - - (** A string representation of the function entry. - *) - val to_string : func_entry -> string - end - - (** The number of entries in the function interpretation. *) - val get_num_entries : func_interp -> int - - (** The entries in the function interpretation *) - val get_entries : func_interp -> FuncEntry.func_entry list - - (** The (symbolic) `else' value of the function interpretation. *) - val get_else : func_interp -> Expr.expr - - (** The arity of the function interpretation *) - val get_arity : func_interp -> int - - (** A string representation of the function interpretation. *) - val to_string : func_interp -> string - end - - (** Retrieves the interpretation (the assignment) of a func_decl in the model. - An expression if the function has an interpretation in the model, null otherwise. *) - val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option - - (** Retrieves the interpretation (the assignment) of an expression in the model. - An expression if the constant has an interpretation in the model, null otherwise. *) - val get_const_interp_e : model -> Expr.expr -> Expr.expr option - - (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option - - (** The number of constant interpretations in the model. *) - val get_num_consts : model -> int - - (** The function declarations of the constants in the model. *) - val get_const_decls : model -> FuncDecl.func_decl list - - (** The number of function interpretations in the model. *) - val get_num_funcs : model -> int - - (** The function declarations of the function interpretations in the model. *) - val get_func_decls : model -> FuncDecl.func_decl list - - (** All symbols that have an interpretation in the model. *) - val get_decls : model -> FuncDecl.func_decl list - - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) - exception ModelEvaluationFailedException of string - - (** Evaluates an expression in the current model. - - This function may fail if the argument contains quantifiers, - is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. - In this case a ModelEvaluationFailedException is thrown. - *) - val eval : model -> Expr.expr -> bool -> Expr.expr - - (** Alias for eval. *) - val evaluate : model -> Expr.expr -> bool -> Expr.expr - - (** The number of uninterpreted sorts that the model has an interpretation for. *) - val get_num_sorts : model -> int - - (** 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. - {!get_num_sorts} - {!sort_universe} *) - val get_sorts : model -> Sort.sort list - - (** The finite set of distinct values that represent the interpretation of a sort. - {!get_sorts} - @returns A list of expressions, where each is an element of the universe of the sort *) - val sort_universe : model -> Sort.sort -> AST.ast list - - (** Conversion of models to strings. - A string representation of the model. *) - val to_string : model -> string -end - -(** Probes - - 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. -*) -module Probe : -sig - type probe - - (** Execute the probe over the goal. - A probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - val apply : probe -> Goal.goal -> float - - (** The number of supported Probes. *) - val get_num_probes : context -> int - - (** The names of all supported Probes. *) - val get_probe_names : context -> string list - - (** Returns a string containing a description of the probe with the given name. *) - val get_probe_description : context -> string -> string - - (** Creates a new Probe. *) - val mk_probe : context -> string -> probe - - (** Create a probe that always evaluates to a float value. *) - val const : context -> float -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is less than the value returned by second argument *) - val lt : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is greater than the value returned by second argument *) - val gt : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is less than or equal the value returned by second argument *) - val le : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is greater than or equal the value returned by second argument *) - val ge : context -> probe -> probe -> probe - - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is equal the value returned by second argument *) - val eq : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when both of two probes evaluate to "true". *) - val and_ : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when either of two probes evaluates to "true". *) - val or_ : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when another probe does not evaluate to "true". *) - val not_ : context -> probe -> probe -end - -(** Tactics - - Tactics are the basic building block for creating custom solvers for specific problem domains. - The complete list of tactics may be obtained using Context.get_num_tactics - and Context.get_tactic_names. - It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. -*) -module Tactic : -sig - type tactic - - (** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) - module ApplyResult : - sig - type apply_result - - (** The number of Subgoals. *) - val get_num_subgoals : apply_result -> int - - (** Retrieves the subgoals from the apply_result. *) - val get_subgoals : apply_result -> Goal.goal list - - (** Retrieves a subgoal from the apply_result. *) - val get_subgoal : apply_result -> int -> Goal.goal - - (** Convert a model for a subgoal into a model for the original - goal g, that the ApplyResult was obtained from. - #return A model for g *) - val convert_model : apply_result -> int -> Model.model -> Model.model - - (** A string representation of the ApplyResult. *) - val to_string : apply_result -> string - end - - (** A string containing a description of parameters accepted by the tactic. *) - val get_help : tactic -> string - - (** Retrieves parameter descriptions for Tactics. *) - val get_param_descrs : tactic -> Params.ParamDescrs.param_descrs - - (** Apply the tactic to the goal. *) - val apply : tactic -> Goal.goal -> Params.params option -> ApplyResult.apply_result - - (** The number of supported tactics. *) - val get_num_tactics : context -> int - - (** The names of all supported tactics. *) - val get_tactic_names : context -> string list - - (** Returns a string containing a description of the tactic with the given name. *) - val get_tactic_description : context -> string -> string - - (** Creates a new Tactic. *) - val mk_tactic : context -> string -> tactic - - (** Create a tactic that applies one tactic to a Goal and - then another one to every subgoal produced by the first one. *) - val and_then : context -> tactic -> tactic -> tactic list -> tactic - - (** Create a tactic that first applies one tactic to a Goal and - if it fails then returns the result of another tactic applied to the Goal. *) - val or_else : context -> tactic -> tactic -> tactic - - (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). - - If the tactic does not terminate within the timeout, then it fails. *) - val try_for : context -> tactic -> int -> tactic - - (** Create a tactic that applies one tactic to a given goal if the probe - evaluates to true. - - If the probe evaluates to false, then the new tactic behaves like the skip tactic. *) - val when_ : context -> Probe.probe -> tactic -> tactic - - (** Create a tactic that applies a tactic to a given goal if the probe - evaluates to true and another tactic otherwise. *) - val cond : context -> Probe.probe -> tactic -> tactic -> tactic - - (** Create a tactic that keeps applying one tactic until the goal is not - modified anymore or the maximum number of iterations is reached. *) - val repeat : context -> tactic -> int -> tactic - - (** Create a tactic that just returns the given goal. *) - val skip : context -> tactic - - (** Create a tactic always fails. *) - val fail : context -> tactic - - (** Create a tactic that fails if the probe evaluates to false. *) - val fail_if : context -> Probe.probe -> tactic - - (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). *) - val fail_if_not_decided : context -> tactic - - (** Create a tactic that applies a tactic using the given set of parameters. *) - val using_params : context -> tactic -> Params.params -> tactic - - (** Create a tactic that applies a tactic using the given set of parameters. - Alias for UsingParams*) - val with_ : context -> tactic -> Params.params -> tactic - - (** Create a tactic that applies the given tactics in parallel. *) - val par_or : context -> tactic list -> tactic - - (** Create a tactic that applies a tactic to a given goal and then another tactic - to every subgoal produced by the first one. The subgoals are processed in parallel. *) - val par_and_then : context -> tactic -> tactic -> tactic - - (** Interrupt the execution of a Z3 procedure. - This procedure can be used to interrupt: solvers, simplifiers and tactics. *) - val interrupt : context -> unit -end - -(** Solvers *) -module Solver : -sig - type solver - type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE - - val string_of_status : status -> string - - (** Objects that track statistical information about solvers. *) - module Statistics : - sig - type statistics - - (** Statistical data is organized into pairs of \[Key, Entry\], where every - Entry is either a floating point or integer value. - *) - module Entry : - sig - type statistics_entry - - (** The key of the entry. *) - val get_key : statistics_entry -> string - - (** The int-value of the entry. *) - val get_int : statistics_entry -> int - - (** The float-value of the entry. *) - val get_float : statistics_entry -> float - - (** True if the entry is uint-valued. *) - val is_int : statistics_entry -> bool - - (** True if the entry is double-valued. *) - val is_float : statistics_entry -> bool - - (** The string representation of the the entry's value. *) - val to_string_value : statistics_entry -> string - - (** The string representation of the entry (key and value) *) - val to_string : statistics_entry -> string - end - - (** A string representation of the statistical data. *) - val to_string : statistics -> string - - (** The number of statistical data. *) - val get_size : statistics -> int - - (** The data entries. *) - val get_entries : statistics -> Entry.statistics_entry list - - (** The statistical counters. *) - val get_keys : statistics -> string list - - (** The value of a particular statistical counter. *) - val get : statistics -> string -> Entry.statistics_entry option - end - - (** A string that describes all available solver parameters. *) - val get_help : solver -> string - - (** Sets the solver parameters. *) - val set_parameters : solver -> Params.params -> unit - - (** Retrieves parameter descriptions for solver. *) - val get_param_descrs : solver -> Params.ParamDescrs.param_descrs - - (** The current number of backtracking points (scopes). - {!pop} - {!push} *) - val get_num_scopes : solver -> int - - (** Creates a backtracking point. - {!pop} *) - val push : solver -> unit - - (** Backtracks a number of backtracking points. - Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} - {!push} *) - val pop : solver -> int -> unit - - (** Resets the Solver. - This removes all assertions from the solver. *) - val reset : solver -> unit - - (** Assert a constraint (or multiple) into the solver. *) - val assert_ : solver -> Boolean.bool_expr list -> unit - - (** * Assert multiple constraints (cs) into the solver, and track them (in the - * unsat) core - * using the Boolean constants in ps. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) - val assert_and_track_a : solver -> Boolean.bool_expr list -> Boolean.bool_expr list -> unit - - (** * Assert a constraint (c) into the solver, and track it (in the unsat) core - * using the Boolean constant p. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) - val assert_and_track : solver -> Boolean.bool_expr -> Boolean.bool_expr -> unit - - (** The number of assertions in the solver. *) - val get_num_assertions : solver -> int - - (** The set of asserted formulas. *) - val get_assertions : solver -> Boolean.bool_expr list - - (** Checks whether the assertions in the solver are consistent or not. - - {!Model} - {!get_unsat_core} - {!Proof} *) - val check : solver -> Boolean.bool_expr list -> status - - (** The model of the last Check. - - The result is None if Check was not invoked before, - if its results was not SATISFIABLE, or if model production is not enabled. *) - val get_model : solver -> Model.model option - - (** 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. *) - val get_proof : solver -> Expr.expr option - - (** 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. *) - val get_unsat_core : solver -> AST.ast list - - (** A brief justification of why the last call to Check returned UNKNOWN. *) - val get_reason_unknown : solver -> string - - (** Solver statistics. *) - val get_statistics : solver -> Statistics.statistics - - (** 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. *) - val mk_solver : context -> Symbol.symbol option -> solver - - (** Creates a new (incremental) solver. - {!mk_solver} *) - val mk_solver_s : context -> string -> solver - - (** Creates a new (incremental) solver. *) - val mk_simple_solver : context -> solver - - (** 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. *) - val mk_solver_t : context -> Tactic.tactic -> solver - - (** A string representation of the solver. *) - val to_string : solver -> string -end - -(** Fixedpoint solving *) -module Fixedpoint : -sig - type fixedpoint - - (** A string that describes all available fixedpoint solver parameters. *) - val get_help : fixedpoint -> string - - (** Sets the fixedpoint solver parameters. *) - val set_params : fixedpoint -> Params.params -> unit - - (** Retrieves parameter descriptions for Fixedpoint solver. *) - val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs - - (** Assert a constraints into the fixedpoint solver. *) - val assert_ : fixedpoint -> Boolean.bool_expr list -> unit - - (** Register predicate as recursive relation. *) - val register_relation : fixedpoint -> FuncDecl.func_decl -> unit - - (** Add rule into the fixedpoint solver. *) - val add_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol option -> unit - - (** Add table fact to the fixedpoint solver. *) - val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit - - (** 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. *) - val query : fixedpoint -> Boolean.bool_expr -> Solver.status - - (** 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. *) - val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status - - (** Creates a backtracking point. - {!pop} *) - val push : fixedpoint -> unit - - (** Backtrack one backtracking point. - - Note that an exception is thrown if Pop is called without a corresponding Push - {!push} *) - val pop : fixedpoint -> unit - - (** Update named rule into in the fixedpoint solver. *) - val update_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol -> unit - - (** Retrieve satisfying instance or instances of solver, - or definitions for the recursive predicates that show unsatisfiability. *) - val get_answer : fixedpoint -> Expr.expr option - - (** Retrieve explanation why fixedpoint engine returned status Unknown. *) - val get_reason_unknown : fixedpoint -> string - - (** Retrieve the number of levels explored for a given predicate. *) - val get_num_levels : fixedpoint -> FuncDecl.func_decl -> int - - (** Retrieve the cover of a predicate. *) - val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option - - (** Add property about the predicate. - The property is added at level. *) - val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit - - (** Retrieve internal string representation of fixedpoint object. *) - val to_string : fixedpoint -> string - - (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol list -> unit - - (** Convert benchmark given as set of axioms, rules and queries to a string. *) - val to_string_q : fixedpoint -> Boolean.bool_expr list -> string - - (** Retrieve set of rules added to fixedpoint context. *) - val get_rules : fixedpoint -> Boolean.bool_expr list - - (** Retrieve set of assertions added to fixedpoint context. *) - val get_assertions : fixedpoint -> Boolean.bool_expr list - - (** Create a Fixedpoint context. *) - val mk_fixedpoint : context -> fixedpoint -end - -(** Global and context options - - Note: This module contains functions that set parameters/options for context - objects as well as functions that set options that are used globally, across - contexts.*) -module Options : -sig - (** 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. - {!get_param_value} *) - val update_param_value : context -> string -> string -> unit - - (** Get a configuration parameter. - - Returns None if the parameter value does not exist. - {!update_param_value} *) - val get_param_value : context -> string -> string option - - (** 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 PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - {!AST.to_string} - {!Quantifier.Pattern.to_string} - {!FuncDecl.to_string} - {!Sort.to_string} *) - val set_print_mode : context -> Z3enums.ast_print_mode -> unit - - (** Enable/disable printing of warning messages to the console. - - Note that this function is static and effects the behaviour of - all contexts globally. *) - val toggle_warning_messages : bool -> unit -end - -(** Functions for handling SMT and SMT2 expressions and files *) -module SMT : -sig - (** Convert a benchmark into an SMT-LIB formatted string. - - @return A string representation of the benchmark. *) - val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr list -> Boolean.bool_expr -> string - - (** 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 in the third and fifth argument - don't need to match the names of the sorts and declarations in the arrays in the fourth - and sixth argument. This is a useful feature since we can use arbitrary names to - reference sorts and declarations. *) - val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit - - (** Parse the given file using the SMT-LIB parser. - {!parse_smtlib_string} *) - val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit - - (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_num_smtlib_formulas : context -> int - - (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_formulas : context -> Boolean.bool_expr list - - (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_num_smtlib_assumptions : context -> int - - (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_assumptions : context -> Boolean.bool_expr list - - (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_num_smtlib_decls : context -> int - - (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_decls : context -> FuncDecl.func_decl list - - (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_num_smtlib_sorts : context -> int - - (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_sorts : context -> Sort.sort list - - (** Parse the given string using the SMT-LIB2 parser. - - {!parse_smtlib_string} - @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr - - (** Parse the given file using the SMT-LIB2 parser. - {!parse_smtlib2_string} *) - val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr -end - -(** Set a global (or module) parameter, which is shared by all Z3 contexts. - - When a Z3 module is initialized it will use the value of these parameters - when Z3_params objects are not provided. - The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. - The character '.' is a delimiter (more later). - The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. - Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". - This function can be used to set parameters for a specific Z3 module. - This can be done by using .. - For example: - (set_global_param "pp.decimal" "true") - will set the parameter "decimal" in the module "pp" to true. -*) -val set_global_param : string -> string -> unit - -(** Get a global (or module) parameter. - - Returns None if the parameter does not exist. - The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. - This function cannot be invoked simultaneously from different threads without synchronization. - The result string stored in param_value is stored in a shared location. -*) -val get_global_param : string -> string option - -(** Restore the value of all global (and module) parameters. - - This command will not affect already created objects (such as tactics and solvers) - {!set_global_param} -*) -val global_param_reset_all : unit From 3e336592a290c07b2937c84ce415776b3563240d Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 4 Jun 2013 18:00:48 +0100 Subject: [PATCH 072/248] ML API: bug and build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 28 ++++++++++++++++------------ scripts/update_api.py | 5 ++++- src/api/ml/z3.ml | 27 +++++++++++++++++---------- src/api/ml/z3.mli | 6 +++--- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index a30e074b0..f46339f5c 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1340,26 +1340,30 @@ class MLComponent(Component): mk_dir(os.path.join(BUILD_DIR, sub_dir)) api_src = get_component(API_COMPONENT).to_src_dir for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): - out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) - str = '\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f) - if IS_WINDOWS: str = str.replace('/','\\') + out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) + str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) + out.write(str) + for f in filter(lambda f: f.endswith('.mli'), os.listdir(self.src_dir)): + out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) + str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): - out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) - str = '\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f) - if IS_WINDOWS: str = str.replace('/','\\') + out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) + str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! prev = '' for m in modules: - out.write('%s/%s.mli: %s/%s.ml %s\n' % (sub_dir,m,sub_dir,m,prev)) - out.write('\t%s -I %s -i -c %s/%s.ml > %s/%s.mli\n' % (OCAMLC,sub_dir,sub_dir,m,sub_dir,m)) - prev = prev + ' ' + sub_dir + '/' + m + '.mli' + fn = os.path.join(self.src_dir, ('%s.mli' % m)) + if not os.path.exists(fn): + out.write('%s.mli: %s.ml %s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),prev)) + out.write('\t%s -I %s -i -c %s.ml > %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir, m),os.path.join(sub_dir, m))) + prev = prev + ' ' + os.path.join(sub_dir, m) + '.mli' cmis = '' for m in modules: - out.write('%s/%s.cmi: %s/%s.mli\n' % (sub_dir,m,sub_dir,m)) - out.write('\t%s -I %s -c %s/%s.mli\n' % (OCAMLC,sub_dir,sub_dir,m)) - cmis = cmis + ' ' + sub_dir + '/' + m + '.cmi' + out.write('%s.cmi: %s.mli\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m))) + out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) + cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') diff --git a/scripts/update_api.py b/scripts/update_api.py index 44d871348..77a5bf7f2 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1185,7 +1185,8 @@ def mk_ml(): ip = inparams(params) op = outparams(params) if len(ip) == 0: - ml_native.write(' unit -> ') + ml_native.write(' unit -> ') + ml_i.write(' unit -> ') for p in ip: ml_native.write('%s -> ' % param2ml(p)) ml_i.write('%s -> ' % param2ml(p)) @@ -1233,6 +1234,8 @@ def mk_ml(): ml_native.write(' ') ml_native.write('a%d' % i) i = i + 1 + if len(ip) == 0: + ml_native.write('()') ml_native.write(' = \n') ml_native.write(' ') if result == VOID and len(op) == 0: diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 081433f1f..8b783d25d 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -34,7 +34,7 @@ struct ) let create_context settings = - let cfg = Z3native.mk_config in + let cfg = Z3native.mk_config () in let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; let v = Z3native.mk_context_rc cfg in @@ -101,12 +101,12 @@ end module Version = struct - let major = let (x, _, _, _) = Z3native.get_version in x - let minor = let (_, x, _, _) = Z3native.get_version in x - let build = let (_, _, x, _) = Z3native.get_version in x - let revision = let (_, _, _, x) = Z3native.get_version in x + let major = let (x, _, _, _) = Z3native.get_version () in x + let minor = let (_, x, _, _) = Z3native.get_version () in x + let build = let (_, _, x, _) = Z3native.get_version () in x + let revision = let (_, _, _, x) = Z3native.get_version () in x let to_string = - let (mj, mn, bld, rev) = Z3native.get_version in + let (mj, mn, bld, rev) = Z3native.get_version () in string_of_int mj ^ "." ^ string_of_int mn ^ "." ^ string_of_int bld ^ "." ^ @@ -609,6 +609,10 @@ sig val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit val mk_params : context -> params val to_string : params -> string + + val update_param_value : context -> string -> string -> unit + val get_param_value : context -> string -> string option + val set_print_mode : context -> Z3enums.ast_print_mode -> unit end = struct type params = z3_native_object @@ -1099,7 +1103,7 @@ struct end -module Array = +module Z3Array = struct let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) @@ -1382,7 +1386,7 @@ struct end -module List = +module Z3List = struct let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = let (r, _, _, _, _, _, _) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in @@ -2038,7 +2042,7 @@ struct if not r then None else - expr_of_ptr (z3obj_gc x) v + Some(expr_of_ptr (z3obj_gc x) v) let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = eval x t completion @@ -2331,7 +2335,7 @@ struct if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - (Entry.create_sd k (Z3native.stats_get_float_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in mk_list f n @@ -2667,3 +2671,6 @@ let global_param_reset_all = let toggle_warning_messages ( enabled: bool ) = Z3native.toggle_warning_messages enabled + +module Array = Z3Array +module List = Z3List diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 570ff8717..3f83ef6b2 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -8,7 +8,7 @@ (** General Z3 exceptions Many functions in this API may throw an exception; if they do, it is this one.*) -exception Error +exception Error of string (** Context objects. @@ -55,11 +55,11 @@ module Log : sig (** Open an interaction log file. @return True if opening the log file succeeds, false otherwise. *) - (* CMW: "open" seems to be a reserved keyword? *) + (* CMW: "open" is a reserved keyword. *) val open_ : string -> bool (** Closes the interaction log. *) - val close : unit + val close : unit -> unit (** Appends a user-provided string to the interaction log. *) val append : string -> unit From 2ee3ff518fcd1e305f4d58cccc52e69af5d21294 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 21 Oct 2013 11:22:42 +0100 Subject: [PATCH 073/248] ML bindings: list/array are now called z3array/z3list to avoid confusion. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 4 ---- src/api/ml/z3.mli | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 8b783d25d..ed815d720 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -2670,7 +2670,3 @@ let global_param_reset_all = let toggle_warning_messages ( enabled: bool ) = Z3native.toggle_warning_messages enabled - - -module Array = Z3Array -module List = Z3List diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 3f83ef6b2..ff1898185 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -761,7 +761,7 @@ sig end (** Functions to manipulate Array expressions *) -module Array : +module Z3Array : sig (** Create a new array sort. *) val mk_sort : context -> Sort.sort -> Sort.sort -> Sort.sort @@ -1093,7 +1093,7 @@ sig end (** Functions to manipulate List expressions *) -module List : +module Z3List : sig (** Create a new list sort. *) val mk_sort : context -> Symbol.symbol -> Sort.sort -> Sort.sort From f7c371ac4d2228669c457ce8e9a27dc622bb3df6 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 28 Oct 2013 12:17:58 +0000 Subject: [PATCH 074/248] ML API: bugfix for native function with more than 5 parameters. Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index 77a5bf7f2..dd1e46c4f 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1211,9 +1211,11 @@ def mk_ml(): ml_i.write(')') ml_native.write('\n') ml_i.write('\n') - ml_native.write(' = "n_%s"\n' % ml_method_name(name)) if len(ip) > 5: - ml_native.write(' "n_%s_bytecode"\n' % ml_method_name(name)) + ml_native.write(' = "n_%s_bytecode"\n' % ml_method_name(name)) + ml_native.write(' "n_%s"\n' % ml_method_name(name)) + else: + ml_native.write(' = "n_%s"\n' % ml_method_name(name)) ml_native.write('\n') ml_native.write(' end\n\n') ml_i.write('\n(**/**)\n'); From 832e119b9858c60ec4538fbfb21275da1120d953 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 2 Apr 2014 19:08:59 +0100 Subject: [PATCH 075/248] ML API bugfix (Codeplex issue 102) Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 43 ++++++ src/api/ml/z3.ml | 289 +++++++++++++++++++------------------- src/api/ml/z3.mli | 3 + 3 files changed, 192 insertions(+), 143 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index c9ed1d948..0dd227784 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -196,6 +196,48 @@ let basic_tests ( ctx : context ) = Printf.printf "Exception caught, OK.\n" ) +(** + A basic example of how to use quantifiers. +**) +let quantifierExample1 ( ctx : context ) = + Printf.printf "QuantifierExample\n" ; + let is = (Integer.mk_sort ctx) in + let types = [ is; is; is ] in + let names = [ (Symbol.mk_string ctx "x_0"); + (Symbol.mk_string ctx "x_1"); + (Symbol.mk_string ctx "x_2") ] in + let vars = [ (Quantifier.mk_bound ctx 2 (List.nth types 0)); + (Quantifier.mk_bound ctx 2 (List.nth types 1)); + (Quantifier.mk_bound ctx 2 (List.nth types 2)) ] in + let xs = [ (Integer.mk_const ctx (List.nth names 0)); + (Integer.mk_const ctx (List.nth names 1)); + (Integer.mk_const ctx (List.nth names 2)) ] in + + let body_vars = (Boolean.mk_and ctx + [ (mk_eq ctx + (Arithmetic.mk_add ctx [ (List.nth vars 0) ; (Integer.mk_numeral_i ctx 1)]) + (Integer.mk_numeral_i ctx 2)) ; + (mk_eq ctx + (Arithmetic.mk_add ctx [ (List.nth vars 1); (Integer.mk_numeral_i ctx 2)]) + (Arithmetic.mk_add ctx [ (List.nth vars 2); (Integer.mk_numeral_i ctx 3)])) ]) in + let body_const = (Boolean.mk_and ctx + [ (mk_eq ctx + (Arithmetic.mk_add ctx [ (List.nth xs 0); (Integer.mk_numeral_i ctx 1)]) + (Integer.mk_numeral_i ctx 2)) ; + (mk_eq ctx + (Arithmetic.mk_add ctx [ (List.nth xs 1); (Integer.mk_numeral_i ctx 2)]) + (Arithmetic.mk_add ctx [ (List.nth xs 2); (Integer.mk_numeral_i ctx 3)])) ]) in + + let x = (Quantifier.mk_forall ctx types names body_vars (Some 1) [] [] (Some (Symbol.mk_string ctx "Q1")) (Some (Symbol.mk_string ctx "skid1"))) in + Printf.printf "Quantifier X: %s\n" (Quantifier.to_string x) ; + let y = (Quantifier.mk_forall_const ctx xs body_const (Some 1) [] [] (Some (Symbol.mk_string ctx "Q2")) (Some (Symbol.mk_string ctx "skid2"))) in + Printf.printf "Quantifier Y: %s\n" (Quantifier.to_string y) ; + if (is_true (Quantifier.expr_of_quantifier x)) then + raise (TestFailedException "") (* unreachable *) + else if (is_false (Quantifier.expr_of_quantifier x)) then + raise (TestFailedException "") (* unreachable *) + else if (is_const (Quantifier.expr_of_quantifier x)) then + raise (TestFailedException "") (* unreachable *) let _ = try ( @@ -217,6 +259,7 @@ let _ = Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); basic_tests ctx ; + quantifierExample1 ctx ; Printf.printf "Disposing...\n"; Gc.full_major () ); diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index ed815d720..d91d3ca8d 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -297,6 +297,7 @@ struct | VAR_AST -> true | _ -> false + let is_app ( x : ast ) = (get_ast_kind x) == APP_AST let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST @@ -828,22 +829,22 @@ end = struct (Z3native.mk_bool_sort (gnc x)) (Z3native.get_sort (gnc x) (gno x))) - let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_app a)) && (get_num_args x) == 0 && (FuncDecl.get_domain_size (get_func_decl x)) == 0 - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) + let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) + let is_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) + let is_eq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) + let is_distinct ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) + let is_ite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) + let is_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) + let is_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) + let is_iff ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) + let is_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) + let is_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) + let is_implies ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) + let is_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) @@ -1100,6 +1101,8 @@ struct mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id + + let to_string ( x : quantifier ) = (Expr.to_string (expr_of_quantifier x)) end @@ -1108,12 +1111,12 @@ struct let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) - let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) - let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) - let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) - let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + let is_store ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) + let is_select ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) + let is_constant_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) + let is_default_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) + let is_array_map ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) + let is_as_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) let is_array ( x : expr ) = (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) @@ -1150,11 +1153,11 @@ struct let mk_sort ( ctx : context ) ( ty : sort ) = sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) - let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) - let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) - let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + let is_union ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_intersect ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_difference ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_complement ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_subset ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) let mk_empty ( ctx : context ) ( domain : sort ) = @@ -1203,7 +1206,7 @@ struct (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) let get_size ( x : sort ) = let (r, v) = (Z3native.get_finite_domain_sort_size (Sort.gnc x) (Sort.gno x)) in @@ -1219,19 +1222,19 @@ struct ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) - let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) - let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) - let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) - let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) - let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) - let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) - let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) - let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) - let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + let is_store ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + let is_empty ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + let is_is_empty ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + let is_join ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + let is_union ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + let is_widen ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + let is_project ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) + let is_filter ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) + let is_negation_filter ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) + let is_rename ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + let is_complement ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) + let is_select ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) + let is_clone ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) let get_arity ( x : sort ) = Z3native.get_relation_arity (Sort.gnc x) (Sort.gno x) @@ -1534,37 +1537,37 @@ struct (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) - let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + let is_arithmetic_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + let is_le ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + let is_ge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + let is_gt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + let is_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + let is_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + let is_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + let is_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + let is_div ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + let is_idiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + let is_remainder ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + let is_modulus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + let is_inttoreal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + let is_real_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + let is_real_is_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) let is_real ( x : expr ) = ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) @@ -1616,57 +1619,57 @@ struct sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) let is_bv ( x : expr ) = ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) - let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) - let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) - let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) - let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) - let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) - let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) - let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) - let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) - let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) - let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) - let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) - let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) - let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) - let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) - let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) - let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) - let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) - let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) - let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) - let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) - let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) - let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) - let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) - let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) - let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) - let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) - let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) - let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) - let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) - let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) - let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) - let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) - let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) - let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) - let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) - let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) - let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) - let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) - let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) - let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) - let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) - let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) - let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) - let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) - let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) - let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) - let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) - let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) - let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) - let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + let is_bv_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) + let is_bv_bit1 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) + let is_bv_bit0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) + let is_bv_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) + let is_bv_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) + let is_bv_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) + let is_bv_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) + let is_bv_sdiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) + let is_bv_udiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) + let is_bv_SRem ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) + let is_bv_urem ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) + let is_bv_smod ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) + let is_bv_sdiv0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) + let is_bv_udiv0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) + let is_bv_srem0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) + let is_bv_urem0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) + let is_bv_smod0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) + let is_bv_ule ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) + let is_bv_sle ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) + let is_bv_uge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) + let is_bv_sge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) + let is_bv_ult ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) + let is_bv_slt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) + let is_bv_ugt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) + let is_bv_sgt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) + let is_bv_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) + let is_bv_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) + let is_bv_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) + let is_bv_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) + let is_bv_nand ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) + let is_bv_nor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) + let is_bv_xnor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) + let is_bv_concat ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) + let is_bv_signextension ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) + let is_bv_zeroextension ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) + let is_bv_extract ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) + let is_bv_repeat ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) + let is_bv_reduceor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) + let is_bv_reduceand ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) + let is_bv_comp ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) + let is_bv_shiftleft ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) + let is_bv_shiftrightlogical ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightarithmetic ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) + let is_bv_rotateleft ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateright ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateleftextended ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotaterightextended ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_int_to_bv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_bv_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_bv_carry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) + let is_bv_xor3 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) let get_size (x : sort ) = Z3native.get_bv_sort_size (Sort.gnc x) (Sort.gno x) let get_int ( x : expr ) = let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in @@ -1778,44 +1781,44 @@ end module Proof = struct - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) - let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) - let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) - let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) - let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) - let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) - let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) - let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) - let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) - let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) - let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) - let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) - let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) - let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) - let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) - let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) - let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) - let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) - let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) - let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) - let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) - let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) - let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) - let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) - let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) - let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) - let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) - let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) - let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) - let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) - let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) - let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) - let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) - let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) - let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) - let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) - let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) - let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) + let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) + let is_asserted ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) + let is_goal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_modus_ponens ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) + let is_reflexivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) + let is_symmetry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) + let is_transitivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) + let is_Transitivity_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_monotonicity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) + let is_quant_intro ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) + let is_distributivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_and_elimination ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) + let is_or_elimination ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_rewrite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) + let is_rewrite_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) + let is_pull_quant ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_push_quant ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) + let is_elim_unused_vars ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + let is_der ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) + let is_quant_inst ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) + let is_hypothesis ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) + let is_lemma ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) + let is_unit_resolution ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_iff_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) + let is_commutativity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_def_axiom ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_intro ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) + let is_apply_def ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) + let is_iff_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) + let is_nnf_pos ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_neg ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) + let is_cnf_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) + let is_skolemize ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) + let is_modus_ponens_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_theory_lemma ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index ff1898185..5c9c56dbf 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -758,6 +758,9 @@ sig (** Create a Quantifier. *) val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** A string representation of the quantifier. *) + val to_string : quantifier -> string end (** Functions to manipulate Array expressions *) From 0da912e5578cfa56c5cc4a8d804d505794bc3fe3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 2 Apr 2014 19:18:43 +0100 Subject: [PATCH 076/248] ML API bugfix Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index d91d3ca8d..5f8d96d2a 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -793,7 +793,7 @@ end = struct mk_list f n let update ( x : expr ) ( args : expr list ) = - if (List.length args <> (get_num_args x)) then + if ((AST.is_app (ast_of_expr x)) && (List.length args <> (get_num_args x))) then raise (Z3native.Exception "Number of arguments does not match") else expr_of_ptr (Expr.gc x) (Z3native.update_term (gnc x) (gno x) (List.length args) (expr_lton args)) From 20be39006ec2b86ebb02e46be0cc7c4dec951f18 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:32:06 +0100 Subject: [PATCH 077/248] ML API `or' is deprecated, changed to `||' Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 5f8d96d2a..c037a9263 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -748,7 +748,7 @@ end = struct Expr(z3_native_object_of_ast_ptr ctx no) else if (Z3native.is_numeral_ast (context_gno ctx) no) then - if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + if (sk == INT_SORT || sk == REAL_SORT || sk == BV_SORT) then Expr(z3_native_object_of_ast_ptr ctx no) else raise (Z3native.Exception "Unsupported numeral object") From a028f200af844393bf8c9e0a35107303b325fd5c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:33:52 +0100 Subject: [PATCH 078/248] ML example; `or' is deprecated, changed to `||' Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 0dd227784..25862b2d7 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -168,7 +168,7 @@ let basic_tests ( ctx : context ) = let inum = (get_numerator rn) in let iden = get_denominator rn in Printf.printf "Numerator: %s Denominator: %s\n" (Real.to_string inum) (Real.to_string iden) ; - if ((Real.to_string inum) <> "42" or (Real.to_string iden) <> "43") then + if ((Real.to_string inum) <> "42" || (Real.to_string iden) <> "43") then raise (TestFailedException "") else Printf.printf "Test passed.\n" From a3d17a0e24f288b3a3fd1b0572bb5488750aa128 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:38:29 +0100 Subject: [PATCH 079/248] ML API build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index f46339f5c..8017c8c61 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1385,6 +1385,15 @@ class MLComponent(Component): out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') out.write('\n') + # Generate META file and package installation commands + self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) + out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') + out.write('\tocamlfind remove Z3\n') + out.write('\tocamlfind install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)') + if IS_WINDOWS: + out.write(' libz3$(LIB_EXT)') + out.write('\n') + out.write('\n') def main_component(self): return is_ml_enabled() From d0588c0565b3d96fae32e3d9967092167925c8ab Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:39:53 +0100 Subject: [PATCH 080/248] ML API build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8017c8c61..41efe90f1 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1821,6 +1821,8 @@ def mk_install(out): for c in get_components(): c.mk_install_deps(out) out.write(' ') + if is_ml_enabled(): + out.write('ocamlfind_install') out.write('\n') out.write('\t@mkdir -p %s\n' % os.path.join('$(PREFIX)', 'bin')) out.write('\t@mkdir -p %s\n' % os.path.join('$(PREFIX)', 'include')) From 3228c3ff5ca5784e948b5ceea873ea013d3e80d0 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:49:05 +0100 Subject: [PATCH 081/248] ML API build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 41efe90f1..c74836a27 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -35,6 +35,7 @@ JNI_HOME=getenv("JNI_HOME", None) OCAMLC=getenv("OCAMLC", "ocamlc") OCAMLOPT=getenv("OCAMLOPT", "ocamlopt") OCAML_LIB=getenv("OCAML_LIB", None) +OCAMLFIND=getenv("OCAMLFIND", "ocamlfind") CXX_COMPILERS=['g++', 'clang++'] C_COMPILERS=['gcc', 'clang'] @@ -357,6 +358,15 @@ def check_ml(): rmf('hello.cmx') rmf('a.out') find_ml_lib() + find_ocaml_find() + +def find_ocaml_find(): + global OCAMLFIND + if is_verbose(): + print "Testing %s..." % OCAMLFIND + r = exec_cmd([OCAMLFIND, 'printconf']) + if r != 0: + OCAMLFIND='' def find_ml_lib(): global OCAML_LIB @@ -1387,13 +1397,14 @@ class MLComponent(Component): out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) - out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') - out.write('\tocamlfind remove Z3\n') - out.write('\tocamlfind install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)') - if IS_WINDOWS: - out.write(' libz3$(LIB_EXT)') - out.write('\n') - out.write('\n') + if OCAMLFIND != '': + out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') + out.write('\t%s remove Z3\n' % (OCAMLFIND)) + out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) + if IS_WINDOWS: + out.write(' libz3$(LIB_EXT)') + out.write('\n') + out.write('\n') def main_component(self): return is_ml_enabled() @@ -1821,7 +1832,7 @@ def mk_install(out): for c in get_components(): c.mk_install_deps(out) out.write(' ') - if is_ml_enabled(): + if is_ml_enabled() and OCAMLFIND != '': out.write('ocamlfind_install') out.write('\n') out.write('\t@mkdir -p %s\n' % os.path.join('$(PREFIX)', 'bin')) From 10fe6b7759f2b117a71d4129dbe18cfdfa1397ff Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 12:55:23 +0100 Subject: [PATCH 082/248] ML API refactoring Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 72 ++++++++----------- src/api/ml/z3.mli | 180 +++++++++++++++++++++++----------------------- 2 files changed, 119 insertions(+), 133 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c037a9263..051a54696 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,5 +1,5 @@ (** - The Z3 ML/Ocaml Interface. + The Z3 ML/OCaml Interface. Copyright (C) 2012 Microsoft Corporation @author CM Wintersteiger (cwinter) 2012-12-17 @@ -698,7 +698,6 @@ sig val get_simplify_help : context -> string val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs val get_func_decl : expr -> FuncDecl.func_decl - val get_bool_value : expr -> Z3enums.lbool val get_num_args : expr -> int val get_args : expr -> expr list val update : expr -> expr list -> expr @@ -710,20 +709,7 @@ sig val is_numeral : expr -> bool val is_well_sorted : expr -> bool val get_sort : expr -> Sort.sort - val is_bool : expr -> bool val is_const : expr -> bool - val is_true : expr -> bool - val is_false : expr -> bool - val is_eq : expr -> bool - val is_distinct : expr -> bool - val is_ite : expr -> bool - val is_and : expr -> bool - val is_or : expr -> bool - val is_iff : expr -> bool - val is_xor : expr -> bool - val is_not : expr -> bool - val is_implies : expr -> bool - val is_oeq : expr -> bool val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val mk_const_s : context -> string -> Sort.sort -> expr val mk_const_f : context -> FuncDecl.func_decl -> expr @@ -782,9 +768,7 @@ end = struct let get_simplify_parameter_descrs ( ctx : context ) = Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (gnc x) (gno x)) - - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) + let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (gnc x) (gno x)) let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) @@ -823,29 +807,11 @@ end = struct let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (gnc x) (gno x)) - - let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (gnc x) - (Z3native.mk_bool_sort (gnc x)) - (Z3native.get_sort (gnc x) (gno x))) - + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_app a)) && (get_num_args x) == 0 && (FuncDecl.get_domain_size (get_func_decl x)) == 0 - let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - let is_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - let is_eq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - let is_distinct ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - let is_ite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - let is_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - let is_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - let is_iff ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - let is_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - let is_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - let is_implies ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - let is_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) @@ -888,12 +854,6 @@ struct let mk_val ( ctx : context ) ( value : bool ) = if value then mk_true ctx else mk_false ctx - - let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) - - let mk_distinct ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) let mk_not ( ctx : context ) ( a : expr ) = expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) @@ -917,6 +877,31 @@ struct let mk_or ( ctx : context ) ( args : expr list ) = let f x = (Expr.gno (x)) in expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) + + let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = + expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + + let mk_distinct ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) + + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) + + let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + (Z3native.is_eq_sort (gnc x) + (Z3native.mk_bool_sort (gnc x)) + (Z3native.get_sort (gnc x) (gno x))) + + let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) + let is_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) + let is_eq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) + let is_distinct ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) + let is_ite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) + let is_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) + let is_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) + let is_iff ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) + let is_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) + let is_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) + let is_implies ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) end @@ -1784,6 +1769,7 @@ struct let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) let is_asserted ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) let is_goal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_OEQ) let is_modus_ponens ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) let is_reflexivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) let is_symmetry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 5c9c56dbf..c554d7564 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1,5 +1,5 @@ (** - The Z3 ML/Ocaml Interface. + The Z3 ML/OCaml Interface. Copyright (C) 2012 Microsoft Corporation @author CM Wintersteiger (cwinter) 2012-12-17 @@ -488,10 +488,6 @@ sig (** The function declaration of the function that is applied in this expression. *) val get_func_decl : Expr.expr -> FuncDecl.func_decl - (** Indicates whether the expression is the true or false expression - or something else (L_UNDEF). *) - val get_bool_value : Expr.expr -> Z3enums.lbool - (** The number of arguments of the expression. *) val get_num_args : Expr.expr -> int @@ -535,11 +531,88 @@ sig (** The Sort of the term. *) val get_sort : Expr.expr -> Sort.sort - (** Indicates whether the term has Boolean sort. *) - val is_bool : Expr.expr -> bool - (** Indicates whether the term represents a constant. *) val is_const : Expr.expr -> bool + + (** Creates a new constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + + (** Creates a new constant. *) + val mk_const_s : context -> string -> Sort.sort -> expr + + (** Creates a constant from the func_decl. *) + val mk_const_f : context -> FuncDecl.func_decl -> expr + + (** Creates a fresh constant with a name prefixed with a string. *) + val mk_fresh_const : context -> string -> Sort.sort -> expr + + (** Create a new function application. *) + val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr + + (** Create a numeral of a given sort. + @return A Term with the given value and sort *) + val mk_numeral_string : context -> string -> Sort.sort -> expr + + (** Create a numeral 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. + @return A Term with the given value and sort *) + val mk_numeral_int : context -> int -> Sort.sort -> expr +end + +(** Boolean expressions; Propositional logic and equality *) +module Boolean : +sig + (** Create a Boolean sort *) + val mk_sort : context -> Sort.sort + + (** Create a Boolean constant. *) + val mk_const : context -> Symbol.symbol -> Expr.expr + + (** Create a Boolean constant. *) + val mk_const_s : context -> string -> Expr.expr + + (** The true Term. *) + val mk_true : context -> Expr.expr + + (** The false Term. *) + val mk_false : context -> Expr.expr + + (** Creates a Boolean value. *) + val mk_val : context -> bool -> Expr.expr + + (** Mk an expression representing not(a). *) + val mk_not : context -> Expr.expr -> Expr.expr + + (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) + val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 iff t2. *) + val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 -> t2. *) + val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 xor t2. *) + val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing the AND of args *) + val mk_and : context -> Expr.expr list -> Expr.expr + + (** Create an expression representing the OR of args *) + val mk_or : context -> Expr.expr list -> Expr.expr + + (** Creates the equality between two expr's. *) + val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Creates a distinct term. *) + val mk_distinct : context -> Expr.expr list -> Expr.expr + + (** Indicates whether the expression is the true or false expression + or something else (L_UNDEF). *) + val get_bool_value : Expr.expr -> Z3enums.lbool + + (** Indicates whether the term has Boolean sort. *) + val is_bool : Expr.expr -> bool (** Indicates whether the term is the constant true. *) val is_true : Expr.expr -> bool @@ -573,84 +646,6 @@ sig (** Indicates whether the term is an implication *) val is_implies : Expr.expr -> bool - - (** 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. *) - val is_oeq : Expr.expr -> bool - - (** Creates a new constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - - (** Creates a new constant. *) - val mk_const_s : context -> string -> Sort.sort -> expr - - (** Creates a constant from the func_decl. *) - val mk_const_f : context -> FuncDecl.func_decl -> expr - - (** Creates a fresh constant with a name prefixed with a string. *) - val mk_fresh_const : context -> string -> Sort.sort -> expr - - (** Create a new function application. *) - val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr - - (** Create a numeral of a given sort. - @return A Term with the goven value and sort *) - val mk_numeral_string : context -> string -> Sort.sort -> expr - - (** Create a numeral 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. - @return A Term with the given value and sort *) - val mk_numeral_int : context -> int -> Sort.sort -> expr -end - -(** Boolean expressions *) -module Boolean : -sig - (** Create a Boolean sort *) - val mk_sort : context -> Sort.sort - - (** Create a Boolean constant. *) - val mk_const : context -> Symbol.symbol -> Expr.expr - - (** Create a Boolean constant. *) - val mk_const_s : context -> string -> Expr.expr - - (** The true Term. *) - val mk_true : context -> Expr.expr - - (** The false Term. *) - val mk_false : context -> Expr.expr - - (** Creates a Boolean value. *) - val mk_val : context -> bool -> Expr.expr - - (** Creates the equality between two expr's. *) - val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Creates a distinct term. *) - val mk_distinct : context -> Expr.expr list -> Expr.expr - - (** Mk an expression representing not(a). *) - val mk_not : context -> Expr.expr -> Expr.expr - - (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) - val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing t1 iff t2. *) - val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing t1 -> t2. *) - val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing t1 xor t2. *) - val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing the AND of args *) - val mk_and : context -> Expr.expr list -> Expr.expr - - (** Create an expression representing the OR of args *) - val mk_or : context -> Expr.expr list -> Expr.expr end (** Quantifier expressions *) @@ -817,7 +812,7 @@ sig The node a must have an array sort [domain -> range], and i must have the sort domain. The sort of the result is range. - {!Array.mk_sort} + {!Z3Array.mk_sort} {!mk_store} *) val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -833,7 +828,7 @@ sig 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). - {!Array.mk_sort} + {!Z3Array.mk_sort} {!mk_select} *) val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr @@ -841,7 +836,7 @@ sig The resulting term is an array, such that a selecton an arbitrary index produces the value v. - {!Array.mk_sort} + {!Z3Array.mk_sort} {!mk_select} *) val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr @@ -850,7 +845,7 @@ sig 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]. - {!Array.mk_sort} + {!Z3Array.mk_sort} {!mk_select} {!mk_store} *) val mk_map : context -> FuncDecl.func_decl -> Expr.expr list -> Expr.expr @@ -1837,6 +1832,11 @@ sig (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) val is_goal : Expr.expr -> bool + (** 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. *) + val is_oeq : Expr.expr -> bool + (** 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. From 2f00968b4febd0b2128b50511340e558e026cf98 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 13:05:22 +0100 Subject: [PATCH 083/248] ML example doc fix Signed-off-by: Christoph M. Wintersteiger --- examples/ml/README | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/ml/README b/examples/ml/README index 3e1eb0d1c..7d33df743 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -12,3 +12,13 @@ or LD_LIBRARY_PATH=. ./ml_example.byte for the byte-code version. +If Z3 was installed into the ocamlfind package repository (see src/api/ml/README), +then we can compile this example as follows: + +ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg +ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg + +Note that the resulting binaries depend on the shared z3 library, which needs to be +in the PATH (Windows), LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX). If Z3 was +installed into ocamlfind, the path that should be added is +`ocamlfind printconf destdir`/Z3 From e5932efc44d5dd3e379e7f77321113909ee06a31 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 13:05:50 +0100 Subject: [PATCH 084/248] ML API refactoring (z3native.c -> z3native_stubs.c) Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 8 ++++---- scripts/update_api.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index c74836a27..8aa582d12 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1374,10 +1374,10 @@ class MLComponent(Component): out.write('%s.cmi: %s.mli\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m))) out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) - out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') - out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) + out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') + out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) out.write('\n') diff --git a/scripts/update_api.py b/scripts/update_api.py index dd1e46c4f..0ed9b29ca 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1148,7 +1148,7 @@ def mk_ml(): ml_dir = get_component('ml').src_dir ml_nativef = os.path.join(ml_dir, 'z3native.ml') ml_nativefi = os.path.join(ml_dir, 'z3native.mli') - ml_wrapperf = os.path.join(ml_dir, 'z3native.c') + ml_wrapperf = os.path.join(ml_dir, 'z3native_stubs.c') ml_native = open(ml_nativef, 'w') ml_i = open(ml_nativefi, 'w') ml_native.write('(* Automatically generated file *)\n\n') From 4f0e8a1057069ffb3c34926faad1fe2b582052c0 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 13:06:29 +0100 Subject: [PATCH 085/248] ML API refactoring (z3native.c -> z3native_stubs.c) Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fccf9424d..9c9707c4b 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ src/api/ml/native.c src/api/ml/z3.ml src/api/ml/enumerations.ml src/api/ml/z3native.c +src/api/ml/z3native_stubs.c src/api/ml/z3native.ml src/api/ml/z3enums.ml src/api/ml/z3.mllib From e2f0dc31f471af42edce1703719e5da32476c38a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 14:18:46 +0100 Subject: [PATCH 086/248] ML API: Added get_bit_int and get_ratio Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 4 +- src/api/ml/META | 7 ++++ src/api/ml/z3.ml | 101 +++++++++++++++++++++++++-------------------- src/api/ml/z3.mli | 12 ++++-- 4 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 src/api/ml/META diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8aa582d12..b19e95cee 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1534,7 +1534,7 @@ class MLExampleComponent(ExampleComponent): out.write('\t%s ' % OCAMLC) if DEBUG_MODE: out.write('-g ') - out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" z3.cma') + out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" nums.cma z3.cma') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') @@ -1545,7 +1545,7 @@ class MLExampleComponent(ExampleComponent): out.write('\t%s ' % OCAMLOPT) if DEBUG_MODE: out.write('-g ') - out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" z3.cmxa') + out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" nums.cmxa z3.cmxa') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') diff --git a/src/api/ml/META b/src/api/ml/META new file mode 100644 index 000000000..d275d98be --- /dev/null +++ b/src/api/ml/META @@ -0,0 +1,7 @@ +# META file for the "z3" package: +version = "VERSION" +description = "Z3 Theorem Prover (OCaml API)" +requires = "num" +archive(byte) = "z3.cma" +archive(native) = "z3.cmxa" +linkopts = "-cclib -lz3" \ No newline at end of file diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 051a54696..dda8807c9 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1425,6 +1425,50 @@ end module Arithmetic = struct + let is_int ( x : expr ) = + (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) + + let is_arithmetic_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + + let is_le ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + + let is_ge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + + let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + + let is_gt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + + let is_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + + let is_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + + let is_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + + let is_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + + let is_div ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + + let is_idiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + + let is_remainder ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + + let is_modulus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + + let is_inttoreal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + + let is_real_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + + let is_real_is_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + + let is_real ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) + + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) + + let is_rat_numeral ( x : expr ) = (Expr.is_numeral x) && (is_real x) + + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) module Integer = struct @@ -1435,6 +1479,12 @@ struct let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in if r then v else raise (Z3native.Exception "Conversion failed.") + + let get_big_int ( x : expr ) = + if (is_int_numeral x) then + let s = to_string(x) in + (Big_int.big_int_of_string s) + else raise (Z3native.Exception "Conversion failed.") let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) @@ -1474,6 +1524,12 @@ struct let get_denominator ( x : expr ) = expr_of_ptr (Expr.gc x) (Z3native.get_denominator (Expr.gnc x) (Expr.gno x)) + let get_ratio ( x : expr ) = + if (is_rat_numeral x) then + let s = to_string(x) in + (Ratio.ratio_of_string s) + else raise (Z3native.Exception "Conversion failed.") + let to_decimal_string ( x : expr ) ( precision : int ) = Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision @@ -1518,51 +1574,6 @@ struct end end - let is_int ( x : expr ) = - (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) - - let is_arithmetic_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - - let is_le ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - - let is_ge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - - let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - - let is_gt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - - let is_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - - let is_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - - let is_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - - let is_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - - let is_div ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - - let is_idiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - - let is_remainder ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - - let is_modulus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - - let is_inttoreal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - - let is_real_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - - let is_real_is_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) - - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) - - let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) - - let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) - - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) - let mk_add ( ctx : context ) ( t : expr list ) = let f x = (Expr.gno x) in (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index c554d7564..4122f40f2 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1149,6 +1149,9 @@ sig (** Retrieve the int value. *) val get_int : Expr.expr -> int + (** Get a big_int from an integer numeral *) + val get_big_int : Expr.expr -> Big_int.big_int + (** Returns a string representation of the numeral. *) val to_string : Expr.expr -> string @@ -1201,10 +1204,13 @@ sig val mk_sort : context -> Sort.sort (** The numerator of a rational numeral. *) - val get_numerator : Expr.expr-> Expr.expr + val get_numerator : Expr.expr -> Expr.expr (** The denominator of a rational numeral. *) - val get_denominator : Expr.expr-> Expr.expr + val get_denominator : Expr.expr -> Expr.expr + + (** Get a ratio from a real numeral *) + val get_ratio : Expr.expr -> Ratio.ratio (** Returns a string representation in decimal notation. The result has at most as many decimal places as indicated by the int argument.*) @@ -1323,7 +1329,7 @@ sig val is_int_numeral : Expr.expr -> bool (** Indicates whether the term is a real numeral. *) - val is_rat_num : Expr.expr -> bool + val is_rat_numeral : Expr.expr -> bool (** Indicates whether the term is an algebraic number *) val is_algebraic_number : Expr.expr -> bool From 6394dde85d18b350a5c52916c109582343952340 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 15:33:07 +0100 Subject: [PATCH 087/248] ML API: build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index b19e95cee..84621e396 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1375,7 +1375,7 @@ class MLComponent(Component): out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) + out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): From 1e4b14af675c30f38c950672d112b8c463a3d8cb Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 16:10:18 +0100 Subject: [PATCH 088/248] ML API: ocamlfind installation fixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/README | 4 ++-- scripts/mk_util.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/ml/README b/examples/ml/README index 7d33df743..844638552 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -15,8 +15,8 @@ for the byte-code version. If Z3 was installed into the ocamlfind package repository (see src/api/ml/README), then we can compile this example as follows: -ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg -ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg +ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg ml_example.ml +ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg ml_example.ml Note that the resulting binaries depend on the shared z3 library, which needs to be in the PATH (Windows), LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX). If Z3 was diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 84621e396..8577479b7 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1401,6 +1401,9 @@ class MLComponent(Component): out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) + for m in modules: + out.write(' %s.cmi' % (os.path.join(sub_dir, m))) + out.write(' %s.cmx' % (os.path.join(sub_dir, m))) if IS_WINDOWS: out.write(' libz3$(LIB_EXT)') out.write('\n') From f72ac1afb69ea38b77333b11e2cd10d2b108eb68 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 16:10:29 +0100 Subject: [PATCH 089/248] ML API: bugfix Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index 0ed9b29ca..8ce652ed5 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1254,7 +1254,7 @@ def mk_ml(): ml_native.write(' a%d' % i) i = i + 1 ml_native.write(') in\n') - if len(params) > 0 and param_type(params[0]) == CONTEXT: + if name not in Unwrapped and len(params) > 0 and param_type(params[0]) == CONTEXT: ml_native.write(' let err = (error_code_of_int (ML2C.n_get_error_code a0)) in \n') ml_native.write(' if err <> OK then\n') ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (int_of_error_code err)))\n') From d8a84c9f8990470736c7b3f62e2a6b27aa846f0f Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 16:12:55 +0100 Subject: [PATCH 090/248] ML API doc fix Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 4122f40f2..8a88a91bb 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -2404,7 +2404,7 @@ sig (** The finite set of distinct values that represent the interpretation of a sort. {!get_sorts} - @returns A list of expressions, where each is an element of the universe of the sort *) + @return A list of expressions, where each is an element of the universe of the sort *) val sort_universe : model -> Sort.sort -> AST.ast list (** Conversion of models to strings. From 47997e175f10ddfbb20dd103c92261064852bfd1 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 16:16:40 +0100 Subject: [PATCH 091/248] ML API doc fixes Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.mli | 220 +++++++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 8a88a91bb..ff45fb0f2 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -241,7 +241,7 @@ sig 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., - Z3native.inc_ref). + [Z3native.inc_ref]). {!wrap_ast} *) val unwrap_ast : ast -> Z3native.ptr @@ -251,7 +251,7 @@ sig managed objects. Note that the native ast that is passed must be a native object obtained from Z3 (e.g., through {!unwrap_ast}) and that it must have a correct reference count (see e.g., - Z3native.inc_ref). *) + [Z3native.inc_ref]). *) val wrap_ast : context -> Z3native.z3_ast -> ast end @@ -439,7 +439,7 @@ sig (** Update a mutable configuration parameter. The list of all configuration parameters can be obtained using the Z3 executable: - z3.exe -p + [z3.exe -p] Only a few configuration parameters are mutable once the context is created. An exception is thrown when trying to modify an immutable parameter. {!get_param_value} *) @@ -479,7 +479,7 @@ sig {!get_simplify_help} *) val simplify : Expr.expr -> Params.params option -> expr - (** A string describing all available parameters to Expr.Simplify. *) + (** A string describing all available parameters to [Expr.Simplify]. *) val get_simplify_help : context -> string (** Retrieves parameter descriptions for simplifier. *) @@ -498,20 +498,20 @@ sig The number of new arguments should coincide with the current number of arguments. *) val update : Expr.expr -> Expr.expr list -> expr - (** Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. + (** 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]. *) + 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]]. *) val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr - (** Substitute every occurrence of from in the expression with to. + (** Substitute every occurrence of [from] in the expression with [to]. {!substitute} *) val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr (** Substitute the free variables in the expression with the expressions in the expr array - For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) + For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term [to[i]]. *) val substitute_vars : Expr.expr -> Expr.expr list -> expr (** Translates (copies) the term to another context. @@ -554,7 +554,7 @@ sig val mk_numeral_string : context -> string -> Sort.sort -> expr (** Create a numeral 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. + It is slightly faster than [MakeNumeral] since it is not necessary to parse a string. @return A Term with the given value and sort *) val mk_numeral_int : context -> int -> Sort.sort -> expr end @@ -580,19 +580,19 @@ sig (** Creates a Boolean value. *) val mk_val : context -> bool -> Expr.expr - (** Mk an expression representing not(a). *) + (** Mk an expression representing [not(a)]. *) val mk_not : context -> Expr.expr -> Expr.expr - (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) + (** Create an expression representing an if-then-else: [ite(t1, t2, t3)]. *) val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 iff t2. *) + (** Create an expression representing [t1 iff t2]. *) val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 -> t2. *) + (** Create an expression representing [t1 -> t2]. *) val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 xor t2. *) + (** Create an expression representing [t1 xor t2]. *) val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing the AND of args *) @@ -604,7 +604,7 @@ sig (** Creates the equality between two expr's. *) val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Creates a distinct term. *) + (** Creates a [distinct] term. *) val mk_distinct : context -> Expr.expr list -> Expr.expr (** Indicates whether the expression is the true or false expression @@ -806,45 +806,45 @@ sig (** Array read. - The argument a is the array and i is the index + 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. + The node [a] must have an array sort [[domain -> range]], + and [i] must have the sort [domain]. + The sort of the result is [range]. {!Z3Array.mk_sort} {!mk_store} *) val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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 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). + 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). {!Z3Array.mk_sort} {!mk_select} *) val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr (** Create a constant array. - The resulting term is an array, such that a selecton an arbitrary index - produces the value v. + The resulting term is an array, such that a [select]on an arbitrary index + produces the value [v]. {!Z3Array.mk_sort} {!mk_select} *) val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr (** 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]. + 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]]. {!Z3Array.mk_sort} {!mk_select} {!mk_store} *) @@ -938,8 +938,8 @@ sig (** 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. *) + 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. *) val is_store : Expr.expr -> bool (** Indicates whether the term is an empty relation *) @@ -997,8 +997,8 @@ sig (** 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. *) + The function takes [n+1] arguments, where the first argument is a relation, + and the remaining [n] arguments correspond to a record. *) val is_select : Expr.expr -> bool (** Indicates whether the term is a relational clone (copy) @@ -1161,11 +1161,11 @@ sig (** Creates an integer constant. *) val mk_const_s : context -> string -> Expr.expr - (** Create an expression representing t1 mod t2. + (** Create an expression representing [t1 mod t2]. The arguments must have int type. *) val mk_mod : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 rem t2. + (** Create an expression representing [t1 rem t2]. The arguments must have int type. *) val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -1181,8 +1181,8 @@ sig 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. + 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. *) val mk_int2real : context -> Expr.expr -> Expr.expr @@ -1334,34 +1334,34 @@ sig (** Indicates whether the term is an algebraic number *) val is_algebraic_number : Expr.expr -> bool - (** Create an expression representing t[0] + t[1] + .... *) + (** Create an expression representing [t[0] + t[1] + ...]. *) val mk_add : context -> Expr.expr list -> Expr.expr - (** Create an expression representing t[0] * t[1] * .... *) + (** Create an expression representing [t[0] * t[1] * ...]. *) val mk_mul : context -> Expr.expr list -> Expr.expr - (** Create an expression representing t[0] - t[1] - .... *) + (** Create an expression representing [t[0] - t[1] - ...]. *) val mk_sub : context -> Expr.expr list -> Expr.expr - (** Create an expression representing -t. *) + (** Create an expression representing [-t]. *) val mk_unary_minus : context -> Expr.expr -> Expr.expr - (** Create an expression representing t1 / t2. *) + (** Create an expression representing [t1 / t2]. *) val mk_div : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 ^ t2. *) + (** Create an expression representing [t1 ^ t2]. *) val mk_power : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 < t2 *) + (** Create an expression representing [t1 < t2] *) val mk_lt : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 <= t2 *) + (** Create an expression representing [t1 <= t2] *) val mk_le : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 > t2 *) + (** Create an expression representing [t1 > t2] *) val mk_gt : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 >= t2 *) + (** Create an expression representing [t1 >= t2] *) val mk_ge : context -> Expr.expr -> Expr.expr -> Expr.expr end @@ -1610,8 +1610,8 @@ sig (** 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 + 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. *) val mk_udiv : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -1620,33 +1620,33 @@ sig 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 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. + - 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. + If [t2] is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) val mk_sdiv : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. + 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. *) val mk_urem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Signed remainder. - It is defined as t1 - (t1 /s t2) * t2, where /s represents signed division. + 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. + If [t2] is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) val mk_srem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed remainder (sign follows divisor). - If t2 is zero, then the result is undefined. + If [t2] is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) val mk_smod : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -1694,27 +1694,27 @@ sig 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). *) + The result is a bit-vector of size [n1+n2], where [n1] ([n2]) + is the size of [t1] ([t2]). *) val mk_concat : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bit-vector extraction. Extract the bits between two limits from a bitvector of - size m to yield a new bitvector of size n, where - n = high - low + 1. *) + size [m] to yield a new bitvector of size [n], where + [n = high - low + 1]. *) val mk_extract : context -> int -> int -> Expr.expr -> Expr.expr (** 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. *) + size [m+i], where \c m is the size of the given bit-vector. *) val mk_sign_ext : context -> int -> Expr.expr -> Expr.expr (** 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 + bitvector of size [m+i], where \c m is the size of the given bit-vector. *) val mk_zero_ext : context -> int -> Expr.expr -> Expr.expr @@ -1723,7 +1723,7 @@ sig (** Shift left. - It is equivalent to multiplication by 2^x where \c x is the value of third argument. + It is equivalent to multiplication by [2^x] where \c x is the value of third argument. NB. The semantics of shift operations varies between environments. This definition does not necessarily capture directly the semantics of the @@ -1732,7 +1732,7 @@ sig (** Logical shift right - It is equivalent to unsigned division by 2^x where \c x is the value of the third argument. + It is equivalent to unsigned division by [2^x] where \c x is the value of the third argument. NB. The semantics of shift operations varies between environments. This definition does not necessarily capture directly the semantics of the @@ -1773,7 +1773,7 @@ sig (** 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 + So the result is non-negative and in the range [[0..2^N-1]], where N are the number of bits in the argument. If \c is_signed is true, \c t1 is treated as a signed bit-vector. @@ -2353,15 +2353,15 @@ sig end (** Retrieves the interpretation (the assignment) of a func_decl in the model. - An expression if the function has an interpretation in the model, null otherwise. *) + @return An expression if the function has an interpretation in the model, null otherwise. *) val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option (** Retrieves the interpretation (the assignment) of an expression in the model. - An expression if the constant has an interpretation in the model, null otherwise. *) + @return An expression if the constant has an interpretation in the model, null otherwise. *) val get_const_interp_e : model -> Expr.expr -> Expr.expr option (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + @return A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option (** The number of constant interpretations in the model. *) @@ -2383,11 +2383,11 @@ sig This function may fail if the argument contains quantifiers, is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. - In this case a ModelEvaluationFailedException is thrown. + In this case a [ModelEvaluationFailedException] is thrown. *) val eval : model -> Expr.expr -> bool -> Expr.expr option - (** Alias for eval. *) + (** Alias for [eval]. *) val evaluate : model -> Expr.expr -> bool -> Expr.expr option (** The number of uninterpreted sorts that the model has an interpretation for. *) @@ -2408,7 +2408,7 @@ sig val sort_universe : model -> Sort.sort -> AST.ast list (** Conversion of models to strings. - A string representation of the model. *) + @return A string representation of the model. *) val to_string : model -> string end @@ -2416,17 +2416,17 @@ end 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. + 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. *) module Probe : sig type probe (** Execute the probe over the goal. - A probe always produce a float value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) + @return A probe always produce a float value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) val apply : probe -> Goal.goal -> float (** The number of supported Probes. *) @@ -2478,9 +2478,9 @@ end (** Tactics Tactics are the basic building block for creating custom solvers for specific problem domains. - The complete list of tactics may be obtained using Context.get_num_tactics - and Context.get_tactic_names. - It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. + The complete list of tactics may be obtained using [Context.get_num_tactics] + and [Context.get_tactic_names]. + It may also be obtained using the command [(help-tactics)] in the SMT 2.0 front-end. *) module Tactic : sig @@ -2504,8 +2504,8 @@ sig val get_subgoal : apply_result -> int -> Goal.goal (** Convert a model for a subgoal into a model for the original - goal g, that the ApplyResult was obtained from. - #return A model for g *) + goal [g], that the ApplyResult was obtained from. + #return A model for [g] *) val convert_model : apply_result -> int -> Model.model -> Model.model (** A string representation of the ApplyResult. *) @@ -2549,7 +2549,7 @@ sig (** Create a tactic that applies one tactic to a given goal if the probe evaluates to true. - If the probe evaluates to false, then the new tactic behaves like the skip tactic. *) + If the probe evaluates to false, then the new tactic behaves like the [skip] tactic. *) val when_ : context -> Probe.probe -> tactic -> tactic (** Create a tactic that applies a tactic to a given goal if the probe @@ -2577,7 +2577,7 @@ sig val using_params : context -> tactic -> Params.params -> tactic (** Create a tactic that applies a tactic using the given set of parameters. - Alias for UsingParams*) + Alias for [UsingParams]*) val with_ : context -> tactic -> Params.params -> tactic (** Create a tactic that applies the given tactics in parallel. *) @@ -2718,26 +2718,26 @@ sig {!Proof} *) val check : solver -> Expr.expr list -> status - (** The model of the last Check. + (** The model of the last [Check]. - The result is None if Check was not invoked before, - if its results was not SATISFIABLE, or if model production is not enabled. *) + The result is [None] if [Check] was not invoked before, + if its results was not [SATISFIABLE], or if model production is not enabled. *) val get_model : solver -> Model.model option - (** The proof of the last Check. + (** 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. *) + The result is [null] if [Check] was not invoked before, + if its results was not [UNSATISFIABLE], or if proof production is disabled. *) val get_proof : solver -> Expr.expr option - (** The unsat core of the last Check. + (** 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. *) + 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. *) val get_unsat_core : solver -> AST.ast list - (** A brief justification of why the last call to Check returned UNKNOWN. *) + (** A brief justification of why the last call to [Check] returned [UNKNOWN]. *) val get_reason_unknown : solver -> string (** Solver statistics. *) @@ -2759,7 +2759,7 @@ sig (** Creates a solver that is implemented using the given tactic. - The solver supports the commands Push and Pop, but it + The solver supports the commands [Push] and [Pop], but it will always solve each check from scratch. *) val mk_solver_t : context -> Tactic.tactic -> solver @@ -2811,7 +2811,7 @@ sig (** Backtrack one backtracking point. - Note that an exception is thrown if Pop is called without a corresponding Push + Note that an exception is thrown if Pop is called without a corresponding [Push] {!push} *) val pop : fixedpoint -> unit @@ -2875,28 +2875,28 @@ sig {!parse_smtlib_string} *) val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit - (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The number of SMTLIB formulas parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_num_smtlib_formulas : context -> int - (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The formulas parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_smtlib_formulas : context -> Expr.expr list - (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The number of SMTLIB assumptions parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_num_smtlib_assumptions : context -> int - (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The assumptions parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_smtlib_assumptions : context -> Expr.expr list - (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The number of SMTLIB declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_num_smtlib_decls : context -> int - (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_smtlib_decls : context -> FuncDecl.func_decl list - (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The number of SMTLIB sorts parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_num_smtlib_sorts : context -> int - (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The sort declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_smtlib_sorts : context -> Sort.sort list (** Parse the given string using the SMT-LIB2 parser. From 2a67301c50033dd3a9e2a02bcf1ad6bbf153f7a0 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 17 Apr 2014 15:06:32 +0100 Subject: [PATCH 092/248] ML API bugfix Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index dda8807c9..e2fa01478 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1482,7 +1482,7 @@ struct let get_big_int ( x : expr ) = if (is_int_numeral x) then - let s = to_string(x) in + let s = (Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x)) in (Big_int.big_int_of_string s) else raise (Z3native.Exception "Conversion failed.") @@ -1526,7 +1526,7 @@ struct let get_ratio ( x : expr ) = if (is_rat_numeral x) then - let s = to_string(x) in + let s = (Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x)) in (Ratio.ratio_of_string s) else raise (Z3native.Exception "Conversion failed.") From 4c54b6816a1e2669398172391d4c5c93612fcb3d Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 22 Apr 2014 11:49:47 +0100 Subject: [PATCH 093/248] ML API bugfix Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index e2fa01478..dafd255f8 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -119,7 +119,7 @@ let mk_list ( f : int -> 'a ) ( n : int ) = if (i >= n) then tail else - (mk_list' f (i+1) n ((f i) :: tail)) + (f i) :: (mk_list' f (i+1) n tail) in mk_list' f 0 n [] From 1c34842ca6839a3833638e58d18b5e9c1f8f8ff6 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 23 Apr 2014 15:15:59 +0100 Subject: [PATCH 094/248] ML API: added Expr.equal and Expr.compare Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 6 ++++++ src/api/ml/z3.mli | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index dafd255f8..3f40b288c 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -717,6 +717,8 @@ sig val mk_app : context -> FuncDecl.func_decl -> expr list -> expr val mk_numeral_string : context -> string -> Sort.sort -> expr val mk_numeral_int : context -> int -> Sort.sort -> expr + val equal : expr -> expr -> bool + val compare : expr -> expr -> int end = struct type expr = Expr of AST.ast @@ -830,6 +832,10 @@ end = struct let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) + + let equal ( a : expr ) ( b : expr ) = AST.equal (ast_of_expr a) (ast_of_expr b) + + let compare a b = AST.compare (ast_of_expr a) (ast_of_expr b) end open FuncDecl diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index ff45fb0f2..84f230d95 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -554,9 +554,17 @@ sig val mk_numeral_string : context -> string -> Sort.sort -> expr (** Create a numeral 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. - @return A Term with the given value and sort *) + It is slightly faster than [MakeNumeral] since it is not necessary to parse a string. + @return A Term with the given value and sort *) val mk_numeral_int : context -> int -> Sort.sort -> expr + + (** Comparison operator. + @return True if the two expr's are equal; false otherwise. *) + val equal : expr -> expr -> bool + + (** Object Comparison. + @return Negative if the first expr should be sorted before the second, positive if after, else zero. *) + val compare : expr -> expr -> int end (** Boolean expressions; Propositional logic and equality *) From ce94a8b2e0f5f56b2b8c469aeeaef3d4854f0aa5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 23 Apr 2014 15:25:08 +0100 Subject: [PATCH 095/248] ML API: added constructors for ast_map and ast_vector Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 31 ++++++++++++++++++++++--------- src/api/ml/z3.mli | 20 ++++++++++++-------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 3f40b288c..b48681b87 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -214,7 +214,7 @@ struct struct type ast_vector = z3_native_object - let ast_vector_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_vector_inc_ref ; @@ -223,6 +223,8 @@ struct (z3obj_create res) ; res + let mk_ast_vector ( ctx : context ) = (create ctx (Z3native.mk_ast_vector (context_gno ctx))) + let get_size ( x : ast_vector ) = Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) @@ -239,7 +241,7 @@ struct Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) let translate ( x : ast_vector ) ( to_ctx : context ) = - ast_vector_of_ptr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) let to_string ( x : ast_vector ) = Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) @@ -248,7 +250,18 @@ struct module ASTMap = struct type ast_map = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_map = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_map_inc_ref ; + dec_ref = Z3native.ast_map_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + let mk_ast_map ( ctx : context ) = (create ctx (Z3native.mk_ast_map (context_gno ctx))) + let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_map = { m_ctx = ctx ; m_n_obj = null ; @@ -277,7 +290,7 @@ struct Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) let get_keys ( x : ast_map ) = - let av = ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in + let av = ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in let f i = (ASTVector.get av i) in mk_list f (ASTVector.get_size av) @@ -2061,7 +2074,7 @@ struct mk_list f n let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in mk_list f n @@ -2386,11 +2399,11 @@ struct Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Expr.gno c) (Expr.gno p) let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) let get_assertions ( x : solver ) = - let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in let f i = (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in mk_list f n @@ -2423,7 +2436,7 @@ struct Some (expr_of_ptr (z3obj_gc x) q) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in mk_list f n @@ -2545,13 +2558,13 @@ struct Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in mk_list f n let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in mk_list f n diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 84f230d95..4347c7431 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -107,10 +107,9 @@ sig (** A string representation of the symbol. *) val to_string : symbol -> string - (** 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. *) + (** 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. *) val mk_int : context -> int -> symbol (** Creates a new symbol using a string. *) @@ -132,12 +131,14 @@ sig module ASTVector : sig type ast_vector + + (** Create an empty AST vector *) + val mk_ast_vector : context -> ast_vector (** The size of the vector *) val get_size : ast_vector -> int - (** - Retrieves the i-th object in the vector. + (** Retrieves the i-th object in the vector. @return An AST *) val get : ast_vector -> int -> ast @@ -162,7 +163,10 @@ sig (** Map from AST to AST *) module ASTMap : sig - type ast_map + type ast_map + + (** Create an empty mapping from AST to AST *) + val mk_ast_map : context -> ast_map (** Checks whether the map contains a key. @return True if the key in the map, false otherwise. *) @@ -2297,7 +2301,7 @@ sig (** Creates a new Goal. - Note that the Context must have been created with proof generation support if + Note that the Context must have been created with proof generation support if the fourth argument is set to true here. *) val mk_goal : context -> bool -> bool -> bool -> goal From bcbfaad3cc9d0ead2118432a7f04ae7d1c2e0e07 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 24 Jul 2014 18:50:11 +0100 Subject: [PATCH 096/248] ML API bugfix. Thanks to Martin Neuhaeusser for reporting this one! Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index b48681b87..bdcf1a26b 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -2045,7 +2045,7 @@ struct let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) let get_func_decls ( x : model ) = - let n = (get_num_consts x) in + let n = (get_num_funcs x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in mk_list f n From 8bd4ea293e9f427fc118fcc90cf2d10ec4a7f8b5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 24 Jul 2014 18:59:03 +0100 Subject: [PATCH 097/248] ML API fix for datatype construction (Issue #121). Thanks to Elarnon for reporting this one! Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 12 ++++++++---- src/api/ml/z3.mli | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index bdcf1a26b..f34ce0ca7 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -374,6 +374,10 @@ struct let sort_lton ( a : sort list ) = let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in Array.of_list (List.map f a) + + let sort_option_lton ( a : sort option list ) = + let f ( e : sort option ) = match e with None -> null | Some(Sort(a)) -> (AST.ptr_of_ast a) in + Array.of_list (List.map f a) let equal : sort -> sort -> bool = fun a b -> (a == b) || @@ -1257,7 +1261,7 @@ struct let _sizes = Hashtbl.create 0 - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = let n = (List.length field_names) in if n != (List.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -1269,7 +1273,7 @@ struct (Symbol.gno recognizer) n (Symbol.symbol_lton field_names) - (sort_lton sorts) + (sort_option_lton sorts) (Array.of_list sort_refs)) in let no : constructor = { m_ctx = ctx ; m_n_obj = null ; @@ -1316,11 +1320,11 @@ struct res end - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = Constructor.create ctx name recognizer field_names sorts sort_refs - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 4347c7431..1342bb4bc 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1053,12 +1053,12 @@ sig (** Create a datatype 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. *) - val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor (** Create a datatype 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. *) - val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor (** Create a new datatype sort. *) val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> Sort.sort From 662039938c7999a5cf4925943c7d8b90d825cb27 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 24 Jul 2014 19:16:16 +0100 Subject: [PATCH 098/248] ML API bugfix (Issue #119). Thanks to user Elarnon for reporting this! Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index 8ce652ed5..fba194bac 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1464,7 +1464,7 @@ def mk_ml(): for p in params: if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) - ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) + ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s_val, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) elif is_out_param(p): ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) i = i + 1 From d84e728f7ae460a9860d2c16b19ab26eac62a344 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 24 Jul 2014 19:29:06 +0100 Subject: [PATCH 099/248] ML API bugfix for datatype module (Issue #120). Thanks to user Elarnon for reporting this! Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index f34ce0ca7..013101398 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -277,7 +277,7 @@ struct let find ( x : ast_map ) ( key : ast ) = ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) - let insert ( x : ast_map ) ( key : ast ) ( value : ast) = + let insert ( x : ast_map ) ( key : ast ) ( value : ast ) = Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) let erase ( x : ast_map ) ( key : ast ) = @@ -1259,7 +1259,13 @@ struct struct type constructor = z3_native_object - let _sizes = Hashtbl.create 0 + module FieldNumTable = Hashtbl.Make(struct + type t = AST.ast + let equal x y = AST.compare x y = 0 + let hash = AST.hash + end) + + let _field_nums = FieldNumTable.create 0 let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = let n = (List.length field_names) in @@ -1283,10 +1289,10 @@ struct (z3obj_create no) ; let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; - Hashtbl.add _sizes no n ; + FieldNumTable.add _field_nums no n ; no - let get_num_fields ( x : constructor ) = Hashtbl.find _sizes x + let get_num_fields ( x : constructor ) = FieldNumTable.find _field_nums x let get_constructor_decl ( x : constructor ) = let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in From 2a67befe9d7195708614c2603e11cf8e6a2099bc Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 14 Aug 2014 18:58:52 +0100 Subject: [PATCH 100/248] ML API: added .cmxs to the distribution. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 17 +++++++++++------ src/api/ml/META | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8577479b7..b3c21b552 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1384,23 +1384,28 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) - out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + out.write('\t%s ' % (OCAMLOPT)) + if DEBUG_MODE: + out.write('-g ') + out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) out.write('\n') out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) - out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') + out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') + out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs\n') out.write('\t%s remove Z3\n' % (OCAMLFIND)) - out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) + out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) for m in modules: out.write(' %s.cmi' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) diff --git a/src/api/ml/META b/src/api/ml/META index d275d98be..6238403a3 100644 --- a/src/api/ml/META +++ b/src/api/ml/META @@ -4,4 +4,6 @@ description = "Z3 Theorem Prover (OCaml API)" requires = "num" archive(byte) = "z3.cma" archive(native) = "z3.cmxa" +archive(byte, plugin) = "z3.cma" +archive(native, plugin) = "z3.cmxs" linkopts = "-cclib -lz3" \ No newline at end of file From 45ec0c1b991f98645f2df834e6b22f32d5e8d3a4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:02:00 +0100 Subject: [PATCH 101/248] ML API: bugfixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 6 +++--- src/api/ml/META | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index b3c21b552..16286d62e 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1384,12 +1384,12 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib -lz3ml -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + out.write('-shared -o %s %s -linkall\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) @@ -1397,7 +1397,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib -lz3ml -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands diff --git a/src/api/ml/META b/src/api/ml/META index 6238403a3..f1d34ba3d 100644 --- a/src/api/ml/META +++ b/src/api/ml/META @@ -6,4 +6,4 @@ archive(byte) = "z3.cma" archive(native) = "z3.cmxa" archive(byte, plugin) = "z3.cma" archive(native, plugin) = "z3.cmxs" -linkopts = "-cclib -lz3" \ No newline at end of file +linkopts = "-cclib -lz3 -lz3ml" \ No newline at end of file From bd9c863e6bf820e918436547fc7caebe3d423f41 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:09:01 +0100 Subject: [PATCH 102/248] ML API: bugfixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 16286d62e..da3dd8692 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1384,7 +1384,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib -lz3ml -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-Lapi/ml -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: @@ -1397,7 +1397,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib -lz3ml -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-Lapi/ml -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands From 4109d19cecd016a134baab74261336081362e958 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:18:40 +0100 Subject: [PATCH 103/248] ML API: bugfixes --- scripts/mk_util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index da3dd8692..362c74834 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1384,12 +1384,12 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-Lapi/ml -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L%s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir,sub_dir)) out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-shared -o %s %s -linkall\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + out.write('-shared -cclib "-L%s -lz3ml" -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir,'z3.cmxa'))) out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) @@ -1397,7 +1397,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-Lapi/ml -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L%s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands From 30a30e8dd033395bee17de5e88ac435f292ac338 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:22:40 +0100 Subject: [PATCH 104/248] ML API: bugfixes Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/META | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/META b/src/api/ml/META index f1d34ba3d..6238403a3 100644 --- a/src/api/ml/META +++ b/src/api/ml/META @@ -6,4 +6,4 @@ archive(byte) = "z3.cma" archive(native) = "z3.cmxa" archive(byte, plugin) = "z3.cma" archive(native, plugin) = "z3.cmxs" -linkopts = "-cclib -lz3 -lz3ml" \ No newline at end of file +linkopts = "-cclib -lz3" \ No newline at end of file From fc32a2e4735daa6a290b30767ca9fecf3ef940ef Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:32:33 +0100 Subject: [PATCH 105/248] ML API: Undoing earlier changes. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 362c74834..b3c21b552 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1384,12 +1384,12 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L%s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-shared -cclib "-L%s -lz3ml" -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir,'z3.cmxa'))) + out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) @@ -1397,7 +1397,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L%s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands From 16ba29e991729c05c71e424178f71a46345a70e4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 2 Dec 2014 19:39:13 +0000 Subject: [PATCH 106/248] ML API: added interpolation, bugfixes. Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 10 +- src/api/ml/z3.ml | 121 ++-- src/api/ml/z3.mli | 1386 +++++++++++++++++++++-------------------- 3 files changed, 806 insertions(+), 711 deletions(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index fba194bac..4669b78fc 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -334,6 +334,8 @@ def param2ml(p): return "ptr" elif k == IN_ARRAY or k == INOUT_ARRAY or k == OUT_ARRAY: return "%s array" % type2ml(param_type(p)) + elif k == OUT_MANAGED_ARRAY: + return "%s array" % type2ml(param_type(p)); else: return type2ml(param_type(p)) @@ -1067,7 +1069,7 @@ def ml_method_name(name): return name[3:] # Remove Z3_ def is_out_param(p): - if param_kind(p) == OUT or param_kind(p) == INOUT or param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: + if param_kind(p) == OUT or param_kind(p) == INOUT or param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY or param_kind(p) == OUT_MANAGED_ARRAY: return True else: return False @@ -1411,6 +1413,8 @@ def mk_ml(): type2str(param_type(param)), type2str(param_type(param)), param_array_capacity_pos(param))) + elif k == OUT_MANAGED_ARRAY: + ml_wrapper.write(' %s * _a%s = 0;\n' % (type2str(param_type(param)), i)) elif k == IN_ARRAY or k == INOUT_ARRAY: t = param_type(param) ts = type2str(t) @@ -1449,7 +1453,7 @@ def mk_ml(): else: ml_wrapper.write(', ') k = param_kind(param) - if k == OUT or k == INOUT: + if k == OUT or k == INOUT or k == OUT_MANAGED_ARRAY: ml_wrapper.write('&_a%s' % i) else: ml_wrapper.write('_a%i' % i) @@ -1465,6 +1469,8 @@ def mk_ml(): if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s_val, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) + elif param_kind(p) == OUT_MANAGED_ARRAY: + ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) elif is_out_param(p): ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) i = i + 1 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 013101398..2b54a1113 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -165,7 +165,7 @@ struct let symbol_lton ( a : symbol list ) = let f ( e : symbol ) = (gno e) in Array.of_list (List.map f a) - + let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL @@ -213,7 +213,7 @@ struct module ASTVector = struct type ast_vector = z3_native_object - + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; @@ -224,7 +224,7 @@ struct res let mk_ast_vector ( ctx : context ) = (create ctx (Z3native.mk_ast_vector (context_gno ctx))) - + let get_size ( x : ast_vector ) = Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) @@ -259,7 +259,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + let mk_ast_map ( ctx : context ) = (create ctx (Z3native.mk_ast_map (context_gno ctx))) let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = @@ -330,7 +330,7 @@ struct if (get_id a) < (get_id b) then -1 else if (get_id a) > (get_id b) then 1 else 0 - + let translate ( x : ast ) ( to_ctx : context ) = if (z3obj_gnc x) == (context_gno to_ctx) then x @@ -366,7 +366,7 @@ struct | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") let ast_of_sort s = match s with Sort(x) -> x - + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) @@ -378,7 +378,7 @@ struct let sort_option_lton ( a : sort option list ) = let f ( e : sort option ) = match e with None -> null | Some(Sort(a)) -> (AST.ptr_of_ast a) in Array.of_list (List.map f a) - + let equal : sort -> sort -> bool = fun a b -> (a == b) || if (gnc a) != (gnc b) then @@ -629,7 +629,6 @@ sig val to_string : params -> string val update_param_value : context -> string -> string -> unit - val get_param_value : context -> string -> string option val set_print_mode : context -> Z3enums.ast_print_mode -> unit end = struct type params = z3_native_object @@ -688,13 +687,6 @@ end = struct let update_param_value ( ctx : context ) ( id : string) ( value : string )= Z3native.update_param_value (context_gno ctx) id value - let get_param_value ( ctx : context ) ( id : string ) = - let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in - if not r then - None - else - Some v - let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) end @@ -826,11 +818,11 @@ end = struct let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (gnc x) (gno x)) - + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_app a)) && (get_num_args x) == 0 && (FuncDecl.get_domain_size (get_func_decl x)) == 0 - + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) @@ -851,7 +843,7 @@ end = struct expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) let equal ( a : expr ) ( b : expr ) = AST.equal (ast_of_expr a) (ast_of_expr b) - + let compare a b = AST.compare (ast_of_expr a) (ast_of_expr b) end @@ -941,7 +933,7 @@ struct raise (Z3native.Exception "Invalid coercion") else Quantifier(e) - + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) @@ -949,13 +941,13 @@ struct module Pattern = struct type pattern = Pattern of ast - + let ast_of_pattern e = match e with Pattern(x) -> x let pattern_of_ast a = - (* CMW: Unchecked ok? *) + (* CMW: Unchecked ok? *) Pattern(a) - + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) @@ -1258,11 +1250,11 @@ struct module Constructor = struct type constructor = z3_native_object - + module FieldNumTable = Hashtbl.Make(struct - type t = AST.ast - let equal x y = AST.compare x y = 0 - let hash = AST.hash + type t = AST.ast + let equal x y = AST.compare x y = 0 + let hash = AST.hash end) let _field_nums = FieldNumTable.create 0 @@ -1291,7 +1283,7 @@ struct Gc.finalise f no ; FieldNumTable.add _field_nums no n ; no - + let get_num_fields ( x : constructor ) = FieldNumTable.find _field_nums x let get_constructor_decl ( x : constructor ) = @@ -1613,16 +1605,16 @@ struct let mk_sub ( ctx : context ) ( t : expr list ) = let f x = (Expr.gno x) in - (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) let mk_unary_minus ( ctx : context ) ( t : expr ) = - (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (Expr.gno t))) + (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (Expr.gno t))) let mk_div ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) let mk_power ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) let mk_lt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) @@ -1893,7 +1885,7 @@ struct let get_formulas ( x : goal ) = let n = get_size x in let f i = ((expr_of_ptr (z3obj_gc x) - (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in + (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in mk_list f n let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) @@ -2065,7 +2057,7 @@ struct let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in (mk_list f n_funcs) @ (mk_list g n_consts) - + let eval ( x : model ) ( t : expr ) ( completion : bool ) = let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in if not r then @@ -2316,7 +2308,7 @@ struct mutable m_is_float : bool ; mutable m_int : int ; mutable m_float : float } - + let create_si k v = let res : statistics_entry = { m_key = k ; @@ -2644,7 +2636,7 @@ struct mk_list f n let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) - + let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in @@ -2683,6 +2675,65 @@ struct (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) end +module Interpolation = +struct + let mk_interpolant ( ctx : context ) ( a : expr ) = + (expr_of_ptr ctx (Z3native.mk_interpolant (context_gno ctx) (Expr.gno a))) + + let mk_interpolation_context ( settings : ( string * string ) list ) = + let cfg = Z3native.mk_config () in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = Z3native.mk_interpolation_context cfg in + Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + Z3native.set_internal_error_handler v ; + let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in + let f = fun o -> dispose_context o in + Gc.finalise f res; + res + + let get_interpolant ( ctx : context ) ( pf : expr ) ( pat: expr ) ( p : Params.params ) = + (ASTVector.create ctx (Z3native.get_interpolant (context_gno ctx) (Expr.gno pf) (Expr.gno pat) (z3obj_gno p))) + + let compute_interpolant ( ctx : context ) ( pat : expr ) ( p : Params.params ) = + let (r, interp, model) = (Z3native.compute_interpolant (context_gno ctx) (Expr.gno pat) (z3obj_gno p)) in + match (lbool_of_int r) with + | L_TRUE -> ((ASTVector.create ctx interp), (Model.create ctx model)) + | _ -> raise (Z3native.Exception "Error computing interpolant.") + + let get_interpolation_profile ( ctx : context ) = + (Z3native.interpolation_profile (context_gno ctx)) + + let read_interpolation_problem ( ctx : context ) ( filename : string ) = + let (r, num, cnsts, parents, error, num_theory, theory) = (Z3native.read_interpolation_problem (context_gno ctx) filename) in + match r with + | 0 -> raise (Z3native.Exception "Interpolation problem could not be read.") + | _ -> + let f1 i = (expr_of_ptr ctx (Array.get cnsts i)) in + let f2 i = (Array.get parents i) in + let f3 i = (expr_of_ptr ctx (Array.get theory i)) in + ((mk_list f1 num), + (mk_list f2 num), + (mk_list f3 num_theory)) + + let check_interpolant ( ctx : context ) ( num : int ) ( cnsts : Expr.expr list ) ( parents : int list ) ( interps : Expr.expr list ) ( num_theory : int ) ( theory : Expr.expr list ) = + let (r, str) = (Z3native.check_interpolant (context_gno ctx) + num + (let f x = Expr.gno x in (Array.of_list (List.map f cnsts))) + (Array.of_list parents) + (let f x = Expr.gno x in (Array.of_list (List.map f interps))) + num_theory + (let f x = Expr.gno x in (Array.of_list (List.map f theory)))) in + match (lbool_of_int r) with + | L_UNDEF -> raise (Z3native.Exception "Interpolant could not be verified.") + | L_FALSE -> raise (Z3native.Exception "Interpolant could not be verified.") + | _ -> () + + let write_interpolation_problem ( ctx : context ) ( num : int ) ( cnsts : Expr.expr list ) ( parents : int list ) ( filename : string ) ( num_theory : int ) ( theory : Expr.expr list ) = + (Z3native.write_interpolation_problem (context_gno ctx) num (expr_lton cnsts) (Array.of_list parents) filename num_theory (expr_lton theory)) ; + () +end let set_global_param ( id : string ) ( value : string ) = (Z3native.global_param_set id value) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 1342bb4bc..b2f0939d0 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -149,11 +149,11 @@ sig val resize : ast_vector -> int -> unit (** Add an ast to the back of the vector. The size - is increased by 1. *) + is increased by 1. *) val push : ast_vector -> ast -> unit (** Translates all ASTs in the vector to another context. - @return A new ASTVector *) + @return A new ASTVector *) val translate : ast_vector -> context -> ast_vector (** Retrieves a string representation of the vector. *) @@ -196,7 +196,7 @@ sig end (** The AST's hash code. - @return A hash code *) + @return A hash code *) val hash : ast -> int (** A unique identifier for the AST (unique among all ASTs). *) @@ -227,34 +227,34 @@ sig val to_sexpr : ast -> string (** Comparison operator. - @return True if the two ast's are from the same context - and represent the same sort; false otherwise. *) + @return True if the two ast's are from the same context + and represent the same sort; false otherwise. *) val equal : ast -> ast -> bool (** Object Comparison. - @return Negative if the first ast should be sorted before the second, positive if after else zero. *) + @return Negative if the first ast should be sorted before the second, positive if after else zero. *) val compare : ast -> ast -> int (** Translates (copies) the AST to another context. - @return A copy of the AST which is associated with the other context. *) + @return A copy of the AST which is associated with the other context. *) val translate : ast -> context -> ast (** 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., - [Z3native.inc_ref]). - {!wrap_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., + [Z3native.inc_ref]). + {!wrap_ast} *) val unwrap_ast : ast -> Z3native.ptr (** Wraps an AST. - This function is used for transitions between native and - managed objects. Note that the native ast that is passed must be a - native object obtained from Z3 (e.g., through {!unwrap_ast}) - and that it must have a correct reference count (see e.g., + This function is used for transitions between native and + managed objects. Note that the native ast that is passed must be a + native object obtained from Z3 (e.g., through {!unwrap_ast}) + and that it must have a correct reference count (see e.g., [Z3native.inc_ref]). *) val wrap_ast : context -> Z3native.z3_ast -> ast end @@ -267,8 +267,8 @@ sig val ast_of_sort : sort -> AST.ast (** Comparison operator. - @return True if the two sorts are from the same context - and represent the same sort; false otherwise. *) + @return True if the two sorts are from the same context + and represent the same sort; false otherwise. *) val equal : sort -> sort -> bool (** Returns a unique identifier for the sort. *) @@ -441,33 +441,26 @@ sig val to_string : params -> string (** Update a mutable configuration parameter. - - The list of all configuration parameters can be obtained using the Z3 executable: - [z3.exe -p] - Only a few configuration parameters are mutable once the context is created. - An exception is thrown when trying to modify an immutable parameter. - {!get_param_value} *) + + The list of all configuration parameters can be obtained using the Z3 executable: + [z3.exe -p] + Only a few configuration parameters are mutable once the context is created. + An exception is thrown when trying to modify an immutable parameter. *) val update_param_value : context -> string -> string -> unit - - (** Get a configuration parameter. - - Returns None if the parameter value does not exist. - {!update_param_value} *) - val get_param_value : context -> string -> string option - + (** 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 PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - {!AST.to_string} - {!Quantifier.Pattern.to_string} - {!FuncDecl.to_string} - {!Sort.to_string} *) + + 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + {!AST.to_string} + {!Quantifier.Pattern.to_string} + {!FuncDecl.to_string} + {!Sort.to_string} *) val set_print_mode : context -> Z3enums.ast_print_mode -> unit end @@ -480,7 +473,7 @@ sig val expr_of_ast : AST.ast -> Expr.expr (** Returns a simplified version of the expression. - {!get_simplify_help} *) + {!get_simplify_help} *) val simplify : Expr.expr -> Params.params option -> expr (** A string describing all available parameters to [Expr.Simplify]. *) @@ -503,23 +496,23 @@ sig val update : Expr.expr -> Expr.expr list -> expr (** 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]]. *) + + 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]]. *) val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr (** Substitute every occurrence of [from] in the expression with [to]. - {!substitute} *) + {!substitute} *) val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr (** Substitute the free variables in the expression with the expressions in the expr array - For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term [to[i]]. *) + For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term [to[i]]. *) val substitute_vars : Expr.expr -> Expr.expr list -> expr (** Translates (copies) the term to another context. - @return A copy of the term which is associated with the other context *) + @return A copy of the term which is associated with the other context *) val translate : Expr.expr -> context -> expr (** Returns a string representation of the expression. *) @@ -529,7 +522,7 @@ sig val is_numeral : Expr.expr -> bool (** Indicates whether the term is well-sorted. - @return True if the term is well-sorted, false otherwise. *) + @return True if the term is well-sorted, false otherwise. *) val is_well_sorted : Expr.expr -> bool (** The Sort of the term. *) @@ -537,26 +530,26 @@ sig (** Indicates whether the term represents a constant. *) val is_const : Expr.expr -> bool - + (** Creates a new constant. *) val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - + (** Creates a new constant. *) val mk_const_s : context -> string -> Sort.sort -> expr - + (** Creates a constant from the func_decl. *) val mk_const_f : context -> FuncDecl.func_decl -> expr - + (** Creates a fresh constant with a name prefixed with a string. *) val mk_fresh_const : context -> string -> Sort.sort -> expr - + (** Create a new function application. *) val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr - + (** Create a numeral of a given sort. - @return A Term with the given value and sort *) + @return A Term with the given value and sort *) val mk_numeral_string : context -> string -> Sort.sort -> expr - + (** Create a numeral 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. @return A Term with the given value and sort *) @@ -692,21 +685,21 @@ sig (** 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 : expr ) appears, the higher is its - index. *) + + 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 : expr ) appears, the higher is its + index. *) val get_index : Expr.expr -> int (** Indicates whether the quantifier is universal. *) @@ -723,19 +716,19 @@ sig (** The patterns. *) val get_patterns : quantifier -> Pattern.pattern list - - (** The number of no-patterns. *) + + (** The number of no-patterns. *) val get_num_no_patterns : quantifier -> int (** The no-patterns. *) val get_no_patterns : quantifier -> Pattern.pattern list - (** The number of bound variables. *) - val get_num_bound : quantifier -> int - - (** The symbols for the bound variables. *) + (** The number of bound variables. *) + val get_num_bound : quantifier -> int + + (** The symbols for the bound variables. *) val get_bound_variable_names : quantifier -> Symbol.symbol list - + (** The sorts of the bound variables. *) val get_bound_variable_sorts : quantifier -> Sort.sort list @@ -767,7 +760,7 @@ sig val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier (** A string representation of the quantifier. *) - val to_string : quantifier -> string + val to_string : quantifier -> string end (** Functions to manipulate Array expressions *) @@ -777,28 +770,28 @@ sig val mk_sort : context -> Sort.sort -> Sort.sort -> Sort.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. *) + It satisfies select(store(a,i,v),j) = if i = j then v else select(a,j). + Array store takes at least 3 arguments. *) val is_store : Expr.expr -> bool (** Indicates whether the term is an array select. *) val is_select : Expr.expr -> bool (** 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. *) + For example, select(const(v),i) = v holds for every v and i. The function is unary. *) val is_constant_array : Expr.expr -> bool (** Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. *) + For example default(const(v)) = v. The function is unary. *) val is_default_array : Expr.expr -> bool (** 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. *) + It satisfies map[f](a1,..,a_n)[i] = f(a1[i],...,a_n[i]) for every i. *) val is_array_map : Expr.expr -> bool (** 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. *) + An as-array term is n array value that behaves as the function graph of the + function passed as parameter. *) val is_as_array : Expr.expr -> bool (** Indicates whether the term is of an array sort. *) @@ -806,66 +799,66 @@ sig (** The domain of the array sort. *) val get_domain : Sort.sort -> Sort.sort - + (** The range of the array sort. *) val get_range : Sort.sort -> Sort.sort - + (** Create an array constant. *) val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> Expr.expr - + (** Create an array constant. *) val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> Expr.expr - + (** 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]. - {!Z3Array.mk_sort} - {!mk_store} *) + + 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]. + {!Z3Array.mk_sort} + {!mk_store} *) val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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). - {!Z3Array.mk_sort} - {!mk_select} *) + + 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). + {!Z3Array.mk_sort} + {!mk_select} *) val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr (** Create a constant array. - - The resulting term is an array, such that a [select]on an arbitrary index - produces the value [v]. - {!Z3Array.mk_sort} - {!mk_select} *) + + The resulting term is an array, such that a [select]on an arbitrary index + produces the value [v]. + {!Z3Array.mk_sort} + {!mk_select} *) val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr (** 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]]. - {!Z3Array.mk_sort} - {!mk_select} - {!mk_store} *) + + 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]]. + {!Z3Array.mk_sort} + {!mk_select} + {!mk_store} *) val mk_map : context -> FuncDecl.func_decl -> Expr.expr list -> Expr.expr (** Access the array default value. - - Produces the default range value, for arrays that can be represented as - finite maps with a default range value. *) + + Produces the default range value, for arrays that can be represented as + finite maps with a default range value. *) val mk_term_array : context -> Expr.expr -> Expr.expr end @@ -948,10 +941,10 @@ sig val is_relation : Expr.expr -> bool (** 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. *) + + 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. *) val is_store : Expr.expr -> bool (** Indicates whether the term is an empty relation *) @@ -964,62 +957,62 @@ sig val is_join : Expr.expr -> bool (** Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. *) + The function takes two arguments. *) val is_union : Expr.expr -> bool (** Indicates whether the term is the widening of two relations - The function takes two arguments. *) + The function takes two arguments. *) val is_widen : Expr.expr -> bool (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. *) + The function takes one argument. *) val is_project : Expr.expr -> bool (** 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. *) + + 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. *) val is_filter : Expr.expr -> bool (** 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. *) + + 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. *) val is_negation_filter : Expr.expr -> bool (** 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. *) + + The function takes one argument. + The parameters contain the renaming as a cycle. *) val is_rename : Expr.expr -> bool (** Indicates whether the term is the complement of a relation *) val is_complement : Expr.expr -> bool (** 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. *) + + 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. *) val is_select : Expr.expr -> bool (** 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 {!is_union} - to perform destructive updates to the first argument. *) + + 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 {!is_union} + to perform destructive updates to the first argument. *) val is_clone : Expr.expr -> bool (** The arity of the relation sort. *) @@ -1039,25 +1032,25 @@ sig (** The number of fields of the constructor. *) val get_num_fields : constructor -> int - + (** The function declaration of the constructor. *) val get_constructor_decl : constructor -> FuncDecl.func_decl (** The function declaration of the tester. *) val get_tester_decl : constructor -> FuncDecl.func_decl - + (** The function declarations of the accessors *) val get_accessor_decls : constructor -> FuncDecl.func_decl list end (** Create a datatype 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. *) + 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. *) val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor (** Create a datatype 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. *) + 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. *) val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor (** Create a new datatype sort. *) @@ -1078,7 +1071,7 @@ sig (** The constructors. *) val get_constructors : Sort.sort -> FuncDecl.func_decl list - + (** The recognizers. *) val get_recognizers : Sort.sort -> FuncDecl.func_decl list @@ -1174,38 +1167,38 @@ sig val mk_const_s : context -> string -> Expr.expr (** Create an expression representing [t1 mod t2]. - The arguments must have int type. *) + The arguments must have int type. *) val mk_mod : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing [t1 rem t2]. - The arguments must have int type. *) + The arguments must have int type. *) val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an integer numeral. *) val mk_numeral_s : context -> string -> Expr.expr (** Create an integer numeral. - @return A Term with the given value and sort Integer *) + @return A Term with the given value and sort Integer *) val mk_numeral_i : context -> int -> Expr.expr (** 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. *) + + + 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. *) val mk_int2real : context -> Expr.expr -> Expr.expr (** Create an n-bit bit-vector from an 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. *) + + + 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. *) val mk_int2bv : context -> int -> Expr.expr -> Expr.expr end @@ -1238,16 +1231,16 @@ sig val mk_const_s : context -> string -> Expr.expr (** Create a real numeral from a fraction. - @return A Term with rational value and sort Real - {!mk_numeral_s} *) + @return A Term with rational value and sort Real + {!mk_numeral_s} *) val mk_numeral_nd : context -> int -> int -> Expr.expr (** Create a real numeral. - @return A Term with the given value and sort Real *) + @return A Term with the given value and sort Real *) val mk_numeral_s : context -> string -> Expr.expr (** Create a real numeral. - @return A Term with the given value and sort Real *) + @return A Term with the given value and sort Real *) val mk_numeral_i : context -> int -> Expr.expr (** Creates an expression that checks whether a real number is an integer. *) @@ -1255,8 +1248,8 @@ sig (** 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. *) + The semantics of this function follows the SMT-LIB standard for the function to_int. + The argument must be of real sort. *) val mk_real2int : context -> Expr.expr -> Expr.expr (** Algebraic Numbers *) @@ -1522,34 +1515,34 @@ sig val is_bv_rotateright : Expr.expr -> bool (** 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. *) + Similar to Z3_OP_ROTATE_LEFT, but it is a binary operator instead of a parametric one. *) val is_bv_rotateleftextended : Expr.expr -> bool (** 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. *) + Similar to Z3_OP_ROTATE_RIGHT, but it is a binary operator instead of a parametric one. *) val is_bv_rotaterightextended : Expr.expr -> bool - + (** 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. *) + This function is not supported by the decision procedures. Only the most + rudimentary simplification rules are applied to this function. *) (** 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. *) + This function is not supported by the decision procedures. Only the most + rudimentary simplification rules are applied to this function. *) val is_int_to_bv : Expr.expr -> bool (** 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. *) + This function is not supported by the decision procedures. Only the most + rudimentary simplification rules are applied to this function. *) val is_bv_to_int : Expr.expr -> bool (** 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))) *) + 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))) *) val is_bv_carry : Expr.expr -> bool - + (** 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) *) + The meaning is given by the equivalence (xor3 l1 l2 l3) <=> (xor (xor l1 l2) l3) *) val is_bv_xor3 : Expr.expr -> bool (** The size of a bit-vector sort. *) @@ -1557,7 +1550,7 @@ sig (** Retrieve the int value. *) val get_int : Expr.expr -> int - + (** Returns a string representation of the numeral. *) val to_string : Expr.expr -> string @@ -1568,146 +1561,145 @@ sig val mk_const_s : context -> string -> int -> Expr.expr (** Bitwise negation. - The argument must have a bit-vector sort. *) + The argument must have a bit-vector sort. *) val mk_not : context -> Expr.expr -> Expr.expr (** Take conjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) + The argument must have a bit-vector sort. *) val mk_redand : context -> Expr.expr -> Expr.expr (** Take disjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) + The argument must have a bit-vector sort. *) val mk_redor : context -> Expr.expr -> Expr.expr (** Bitwise conjunction. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_and : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise disjunction. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_or : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise XOR. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise NAND. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_nand : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise NOR. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_nor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise XNOR. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_xnor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Standard two's complement unary minus. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_neg : context -> Expr.expr -> Expr.expr (** Two's complement addition. - The arguments must have the same bit-vector sort. *) + The arguments must have the same bit-vector sort. *) val mk_add : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement subtraction. - The arguments must have the same bit-vector sort. *) + The arguments must have the same bit-vector sort. *) val mk_sub : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement multiplication. - The arguments must have the same bit-vector sort. *) + The arguments must have the same bit-vector sort. *) val mk_mul : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. *) + + 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. *) val mk_udiv : context -> Expr.expr -> Expr.expr -> Expr.expr (** Signed division. - - It is defined in the following way: + + 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 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]. + - 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. *) + If [t2] is zero, then the result is undefined. + The arguments must have the same bit-vector sort. *) val mk_sdiv : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. *) + + 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. *) val mk_urem : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. + + 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. *) + If [t2] is zero, then the result is undefined. + The arguments must have the same bit-vector sort. *) val mk_srem : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. *) + + If [t2] is zero, then the result is undefined. + The arguments must have the same bit-vector sort. *) val mk_smod : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned less-than - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_ult : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed less-than - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_slt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned less-than or equal to. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_ule : context -> Expr.expr -> Expr.expr -> Expr.expr - + (** Two's complement signed less-than or equal to. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_sle : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned greater than or equal to. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_uge : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed greater than or equal to. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_sge : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned greater-than. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_ugt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed greater-than. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_sgt : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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]). *) + + 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]). *) val mk_concat : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bit-vector extraction. @@ -1719,17 +1711,17 @@ sig (** 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. *) + 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. *) val mk_sign_ext : context -> int -> Expr.expr -> Expr.expr (** 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. *) + 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. *) val mk_zero_ext : context -> int -> Expr.expr -> Expr.expr - + (** Bit-vector repetition. *) val mk_repeat : context -> int -> Expr.expr -> Expr.expr @@ -1743,27 +1735,27 @@ sig val mk_shl : context -> Expr.expr -> Expr.expr -> Expr.expr (** Logical shift right - - It is equivalent to unsigned division by [2^x] where \c x is the value of the third argument. + + It is equivalent to unsigned division by [2^x] where \c x is the value of the third 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. + 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. *) + The arguments must have a bit-vector sort. *) val mk_lshr : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. + + 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. + 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. *) + The arguments must have a bit-vector sort. *) val mk_ashr : context -> Expr.expr -> Expr.expr -> Expr.expr (** Rotate Left. @@ -1783,7 +1775,7 @@ sig val mk_ext_rotate_right : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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 the argument. @@ -1795,45 +1787,45 @@ sig val mk_bv2int : context -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise addition does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_add_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise addition does not underflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_add_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise subtraction does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_sub_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise subtraction does not underflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_sub_no_underflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise signed division does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_sdiv_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise negation does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_neg_no_overflow : context -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise multiplication does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_mul_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise multiplication does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_mul_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr + The arguments must be of bit-vector sort. *) + val mk_mul_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr + (** Create a bit-vector numeral. *) val mk_numeral : context -> string -> int -> Expr.expr end @@ -1851,389 +1843,389 @@ sig val is_goal : Expr.expr -> bool (** 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. *) + This binary predicate is used in proof terms. + It captures equisatisfiability and equivalence modulo renamings. *) val is_oeq : Expr.expr -> bool (** 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). *) + + 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). *) val is_modus_ponens : Expr.expr -> bool (** 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'. *) + 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'. *) val is_reflexivity : Expr.expr -> bool (** 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. *) + + 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. *) val is_symmetry : Expr.expr -> bool (** 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) *) + + 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) *) val is_transitivity : Expr.expr -> bool (** 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. *) + + 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. *) val is_Transitivity_star : Expr.expr -> bool (** 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. *) + + 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. *) val is_monotonicity : Expr.expr -> bool (** 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)) *) + + 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)) *) val is_quant_intro : Expr.expr -> bool (** 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. *) + + 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. *) val is_distributivity : Expr.expr -> bool (** 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 *) + + 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 *) val is_and_elimination : Expr.expr -> bool (** 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) *) + + 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) *) val is_or_elimination : Expr.expr -> bool (** 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 : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) *) + + 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 : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) *) val is_rewrite : Expr.expr -> bool (** 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) *) + + 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) *) val is_rewrite_star : Expr.expr -> bool (** 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. *) + + A proof for (iff (f (forall (x) q(x)) r) (forall (x) (f (q x) r))). This proof object has no antecedents. *) val is_pull_quant : Expr.expr -> bool (** 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 *) + + 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 *) val is_pull_quant_star : Expr.expr -> bool (** 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 *) + + 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 *) val is_push_quant : Expr.expr -> bool (** 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. *) + + 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. *) val is_elim_unused_vars : Expr.expr -> bool (** Indicates whether the term is a proof for destructive equality resolution - - A proof for destructive equality resolution: - (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. - - This proof object has no antecedents. - - Several variables can be eliminated simultaneously. *) + + A proof for destructive equality resolution: + (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. + + This proof object has no antecedents. + + Several variables can be eliminated simultaneously. *) val is_der : Expr.expr -> bool - + (** Indicates whether the term is a proof for quantifier instantiation - - A proof of (or (not (forall (x) (P x))) (P a)) *) + + A proof of (or (not (forall (x) (P x))) (P a)) *) val is_quant_inst : Expr.expr -> bool (** Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. *) + Mark a hypothesis in a natural deduction style proof. *) val is_hypothesis : Expr.expr -> bool (** 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. *) + + 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. *) val is_lemma : Expr.expr -> bool (** 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') *) + + 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') *) val is_unit_resolution : Expr.expr -> bool (** Indicates whether the term is a proof by iff-true - - T1: p - [iff-true T1]: (iff p true) *) + + T1: p + [iff-true T1]: (iff p true) *) val is_iff_true : Expr.expr -> bool (** Indicates whether the term is a proof by iff-false - - T1: (not p) - [iff-false T1]: (iff p false) *) + + T1: (not p) + [iff-false T1]: (iff p false) *) val is_iff_false : Expr.expr -> bool (** 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. *) + + [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. *) val is_commutativity : Expr.expr -> bool (** 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). *) + + 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). *) val is_def_axiom : Expr.expr -> bool (** 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) *) + + 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) *) val is_def_intro : Expr.expr -> bool (** 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. *) + + [apply-def T1]: F ~ n + F is 'equivalent' to n, given that T1 is a proof that + n is a name for F. *) val is_apply_def : Expr.expr -> bool (** Indicates whether the term is a proof iff-oeq - - T1: (iff p q) - [iff~ T1]: (~ p q) *) + + T1: (iff p q) + [iff~ T1]: (~ p q) *) val is_iff_oeq : Expr.expr -> bool (** 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'. *) + + 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'. *) val is_nnf_pos : Expr.expr -> bool (** 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'))) *) + + 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'))) *) val is_nnf_neg : Expr.expr -> bool (** 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. *) + + 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. *) val is_nnf_star : Expr.expr -> bool (** 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. *) + + 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. *) val is_cnf_star : Expr.expr -> bool (** Indicates whether the term is a proof for a Skolemization step - - Proof for: - - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) - - This proof object has no antecedents. *) + + Proof for: + + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + + This proof object has no antecedents. *) val is_skolemize : Expr.expr -> bool (** 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 *) + + Modus ponens style rule for equi-satisfiability. + T1: p + T2: (~ p q) + [mp~ T1 T2]: q *) val is_modus_ponens_oeq : Expr.expr -> bool (** 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. *) + + 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. *) val is_theory_lemma : Expr.expr -> bool end @@ -2265,12 +2257,12 @@ sig (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) val is_garbage : goal -> bool - (** Adds the constraints to the given goal. *) + (** Adds the constraints to the given goal. *) val add : goal -> Expr.expr list -> unit - + (** Indicates whether the goal contains `false'. *) val is_inconsistent : goal -> bool - + (** The depth of the goal. This tracks how many transformations were applied to it. *) val get_depth : goal -> int @@ -2300,7 +2292,7 @@ sig val simplify : goal -> Params.params option -> goal (** Creates a new Goal. - + Note that the Context must have been created with proof generation support if the fourth argument is set to true here. *) val mk_goal : context -> bool -> bool -> bool -> goal @@ -2323,7 +2315,7 @@ sig module FuncInterp : sig type func_interp - + (** Function interpretations entries An Entry object represents an element in the finite map used to a function interpretation. *) @@ -2418,7 +2410,7 @@ sig {!get_sorts} @return A list of expressions, where each is an element of the universe of the sort *) val sort_universe : model -> Sort.sort -> AST.ast list - + (** Conversion of models to strings. @return A string representation of the model. *) val to_string : model -> string @@ -2437,8 +2429,8 @@ sig type probe (** Execute the probe over the goal. - @return A probe always produce a float value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) + @return A probe always produce a float value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) val apply : probe -> Goal.goal -> float (** The number of supported Probes. *) @@ -2546,21 +2538,21 @@ sig val mk_tactic : context -> string -> tactic (** Create a tactic that applies one tactic to a Goal and - then another one to every subgoal produced by the first one. *) + then another one to every subgoal produced by the first one. *) val and_then : context -> tactic -> tactic -> tactic list -> tactic (** Create a tactic that first applies one tactic to a Goal and - if it fails then returns the result of another tactic applied to the Goal. *) + if it fails then returns the result of another tactic applied to the Goal. *) val or_else : context -> tactic -> tactic -> tactic (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). - - If the tactic does not terminate within the timeout, then it fails. *) + + If the tactic does not terminate within the timeout, then it fails. *) val try_for : context -> tactic -> int -> tactic (** Create a tactic that applies one tactic to a given goal if the probe evaluates to true. - + If the probe evaluates to false, then the new tactic behaves like the [skip] tactic. *) val when_ : context -> Probe.probe -> tactic -> tactic @@ -2569,7 +2561,7 @@ sig val cond : context -> Probe.probe -> tactic -> tactic -> tactic (** Create a tactic that keeps applying one tactic until the goal is not - modified anymore or the maximum number of iterations is reached. *) + modified anymore or the maximum number of iterations is reached. *) val repeat : context -> tactic -> int -> tactic (** Create a tactic that just returns the given goal. *) @@ -2582,14 +2574,14 @@ sig val fail_if : context -> Probe.probe -> tactic (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). *) + or trivially unsatisfiable (i.e., contains `false'). *) val fail_if_not_decided : context -> tactic (** Create a tactic that applies a tactic using the given set of parameters. *) val using_params : context -> tactic -> Params.params -> tactic (** Create a tactic that applies a tactic using the given set of parameters. - Alias for [UsingParams]*) + Alias for [UsingParams]*) val with_ : context -> tactic -> Params.params -> tactic (** Create a tactic that applies the given tactics in parallel. *) @@ -2600,7 +2592,7 @@ sig val par_and_then : context -> tactic -> tactic -> tactic (** Interrupt the execution of a Z3 procedure. - This procedure can be used to interrupt: solvers, simplifiers and tactics. *) + This procedure can be used to interrupt: solvers, simplifiers and tactics. *) val interrupt : context -> unit end @@ -2618,8 +2610,8 @@ sig type statistics (** Statistical data is organized into pairs of \[Key, Entry\], where every - Entry is either a floating point or integer value. - *) + Entry is either a floating point or integer value. + *) module Entry : sig type statistics_entry @@ -2641,7 +2633,7 @@ sig (** The string representation of the the entry's value. *) val to_string_value : statistics_entry -> string - + (** The string representation of the entry (key and value) *) val to_string : statistics_entry -> string end @@ -2672,49 +2664,49 @@ sig val get_param_descrs : solver -> Params.ParamDescrs.param_descrs (** The current number of backtracking points (scopes). - {!pop} - {!push} *) + {!pop} + {!push} *) val get_num_scopes : solver -> int (** Creates a backtracking point. - {!pop} *) + {!pop} *) val push : solver -> unit (** Backtracks a number of backtracking points. - Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} - {!push} *) + Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} + {!push} *) val pop : solver -> int -> unit (** Resets the Solver. - This removes all assertions from the solver. *) + This removes all assertions from the solver. *) val reset : solver -> unit (** Assert a constraint (or multiple) into the solver. *) val add : solver -> Expr.expr list -> unit (** * Assert multiple constraints (cs) into the solver, and track them (in the - * unsat) core - * using the Boolean constants in ps. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) + * unsat) core + * using the Boolean constants in ps. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) val assert_and_track_l : solver -> Expr.expr list -> Expr.expr list -> unit (** * Assert a constraint (c) into the solver, and track it (in the unsat) core - * using the Boolean constant p. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) + * using the Boolean constant p. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) val assert_and_track : solver -> Expr.expr -> Expr.expr -> unit (** The number of assertions in the solver. *) @@ -2724,29 +2716,29 @@ sig val get_assertions : solver -> Expr.expr list (** Checks whether the assertions in the solver are consistent or not. - - {!Model} - {!get_unsat_core} - {!Proof} *) + + {!Model} + {!get_unsat_core} + {!Proof} *) val check : solver -> Expr.expr list -> status (** The model of the last [Check]. - - The result is [None] if [Check] was not invoked before, - if its results was not [SATISFIABLE], or if model production is not enabled. *) + + The result is [None] if [Check] was not invoked before, + if its results was not [SATISFIABLE], or if model production is not enabled. *) val get_model : solver -> Model.model option (** 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. *) + + The result is [null] if [Check] was not invoked before, + if its results was not [UNSATISFIABLE], or if proof production is disabled. *) val get_proof : solver -> Expr.expr option (** 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. *) + + 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. *) val get_unsat_core : solver -> AST.ast list (** A brief justification of why the last call to [Check] returned [UNKNOWN]. *) @@ -2756,23 +2748,23 @@ sig val get_statistics : solver -> Statistics.statistics (** 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. *) + + 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. *) val mk_solver : context -> Symbol.symbol option -> solver (** Creates a new (incremental) solver. - {!mk_solver} *) + {!mk_solver} *) val mk_solver_s : context -> string -> solver (** Creates a new (incremental) solver. *) val mk_simple_solver : context -> solver (** 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. *) + + The solver supports the commands [Push] and [Pop], but it + will always solve each check from scratch. *) val mk_solver_t : context -> Tactic.tactic -> solver (** A string representation of the solver. *) @@ -2806,32 +2798,32 @@ sig val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit (** 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. *) + 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. *) val query : fixedpoint -> Expr.expr -> Solver.status (** 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. *) + 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. *) val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status (** Creates a backtracking point. - {!pop} *) + {!pop} *) val push : fixedpoint -> unit (** Backtrack one backtracking point. - Note that an exception is thrown if Pop is called without a corresponding [Push] - {!push} *) + Note that an exception is thrown if Pop is called without a corresponding [Push] + {!push} *) val pop : fixedpoint -> unit (** Update named rule into in the fixedpoint solver. *) val update_rule : fixedpoint -> Expr.expr -> Symbol.symbol -> unit (** Retrieve satisfying instance or instances of solver, - or definitions for the recursive predicates that show unsatisfiability. *) + or definitions for the recursive predicates that show unsatisfiability. *) val get_answer : fixedpoint -> Expr.expr option (** Retrieve explanation why fixedpoint engine returned status Unknown. *) @@ -2844,7 +2836,7 @@ sig val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option (** Add property about the predicate. - The property is added at level. *) + The property is added at level. *) val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit (** Retrieve internal string representation of fixedpoint object. *) @@ -2871,7 +2863,7 @@ module SMT : sig (** Convert a benchmark into an SMT-LIB formatted string. - @return A string representation of the benchmark. *) + @return A string representation of the benchmark. *) val benchmark_to_smtstring : context -> string -> string -> string -> string -> Expr.expr list -> Expr.expr -> string (** Parse the given string using the SMT-LIB parser. @@ -2884,7 +2876,7 @@ sig val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit (** Parse the given file using the SMT-LIB parser. - {!parse_smtlib_string} *) + {!parse_smtlib_string} *) val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit (** The number of SMTLIB formulas parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) @@ -2913,15 +2905,61 @@ sig (** Parse the given string using the SMT-LIB2 parser. - {!parse_smtlib_string} - @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) + {!parse_smtlib_string} + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr (** Parse the given file using the SMT-LIB2 parser. - {!parse_smtlib2_string} *) + {!parse_smtlib2_string} *) val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr end +(** Interpolation *) +module Interpolation : +sig + + (** Create an AST node marking a formula position for interpolation. + The expression must have Boolean sort. *) + val mk_interpolant : context -> Expr.expr -> Expr.expr + + (** The interpolation context is suitable for generation of interpolants. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val mk_interpolation_context : (string * string) list -> context + + (** Gets an interpolant. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val get_interpolant : context -> Expr.expr -> Expr.expr -> Params.params -> AST.ASTVector.ast_vector + + (** Computes an interpolant. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val compute_interpolant : context -> Expr.expr -> Params.params -> (AST.ASTVector.ast_vector * Model.model) + + (** Retrieves an interpolation profile. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val get_interpolation_profile : context -> string + + (** Read an interpolation problem from file. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val read_interpolation_problem : context -> string -> (Expr.expr list * int list * Expr.expr list) + + (** Check the correctness of an interpolant. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val check_interpolant : context -> int -> Expr.expr list -> int list -> Expr.expr list -> int -> Expr.expr list -> unit + + (** Write an interpolation problem to file suitable for reading with + Z3_read_interpolation_problem. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val write_interpolation_problem : context -> int -> Expr.expr list -> int list -> string -> int -> Expr.expr list -> unit + +end + (** Set a global (or module) parameter, which is shared by all Z3 contexts. When a Z3 module is initialized it will use the value of these parameters @@ -2939,9 +2977,9 @@ end val set_global_param : string -> string -> unit (** Get a global (or module) parameter. - + Returns None if the parameter does not exist. - The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. + The caller must invoke #Z3_global_param_del_value to delete the value returned at param_value. This function cannot be invoked simultaneously from different threads without synchronization. The result string stored in param_value is stored in a shared location. *) From 8b266cff529fd4412f3a879a1bf2aafadfee0fc9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 2 Dec 2014 20:21:30 +0000 Subject: [PATCH 107/248] ML API: build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index b3c21b552..1f8bf9fd6 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1361,6 +1361,10 @@ class MLComponent(Component): out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) + for f in filter(lambda f: f=='META', os.listdir(self.src_dir)): + out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) + str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) + out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! prev = '' for m in modules: @@ -1403,7 +1407,7 @@ class MLComponent(Component): # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs\n') + out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/META\n') out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) for m in modules: From 5f9d1af04ad9eda20b05c1e8d69adb1ad6482753 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 2 Dec 2014 20:31:16 +0000 Subject: [PATCH 108/248] ML API build fix --- scripts/mk_util.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 1f8bf9fd6..6ef3df13c 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1361,10 +1361,6 @@ class MLComponent(Component): out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) - for f in filter(lambda f: f=='META', os.listdir(self.src_dir)): - out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) - str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) - out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! prev = '' for m in modules: From fcee69af4b6ea775d4acc5f2b61f5de853a99380 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 2 Dec 2014 22:00:58 +0000 Subject: [PATCH 109/248] ML API build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 6ef3df13c..62078cf84 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1374,9 +1374,14 @@ class MLComponent(Component): out.write('%s.cmi: %s.mli\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m))) out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('api/ml/z3native_stubs$(OBJ_EXT): %s/z3native_stubs.c\n' % (sub_dir)); out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) + out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') + out.write('api/ml/libz3mldyn$(SO_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)api/ml/libz3ml$(SO_EXT) $(SLINK_FLAGS) -I %s -I %s api/ml/z3native_stubs$(OBJ_EXT) %s$(LIB_EXT)\n' % (OCAML_LIB, api_src, get_component(Z3_DLL_COMPONENT).dll_name)) + out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) From e11cc5a1f1a0f4be80ffe5b9c7e8886b2dc63837 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 13:45:49 +0000 Subject: [PATCH 110/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 98 ++++++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 38 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 62078cf84..90618edc3 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1366,58 +1366,80 @@ class MLComponent(Component): for m in modules: fn = os.path.join(self.src_dir, ('%s.mli' % m)) if not os.path.exists(fn): - out.write('%s.mli: %s.ml %s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),prev)) + out.write('%s.mli: %s.ml%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),prev)) out.write('\t%s -I %s -i -c %s.ml > %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir, m),os.path.join(sub_dir, m))) prev = prev + ' ' + os.path.join(sub_dir, m) + '.mli' cmis = '' for m in modules: - out.write('%s.cmi: %s.mli\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m))) + out.write('%s.cmi: %s.mli%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m), cmis)) out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - out.write('api/ml/z3native_stubs$(OBJ_EXT): %s/z3native_stubs.c\n' % (sub_dir)); - out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) - out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') - out.write('api/ml/libz3mldyn$(SO_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)api/ml/libz3ml$(SO_EXT) $(SLINK_FLAGS) -I %s -I %s api/ml/z3native_stubs$(OBJ_EXT) %s$(LIB_EXT)\n' % (OCAML_LIB, api_src, get_component(Z3_DLL_COMPONENT).dll_name)) + + out.write('%s: %s %s\n' % + (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'), + os.path.join(sub_dir, 'z3native_stubs.c'), + get_component(Z3_DLL_COMPONENT).dll_name+'$(SO_EXT)')); + out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s $(CXX_OUT_FLAG)%s$(OBJ_EXT)\n' % + (OCAML_LIB, api_src, os.path.join(sub_dir, 'z3native_stubs.c'), os.path.join(sub_dir, 'z3native_stubs'))) - out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(sub_dir, mlfile)) - out.write('\n') - out.write('\t%s ' % (OCAMLOPT)) - if DEBUG_MODE: - out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) - out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - out.write('\t%s ' % (OCAMLOPT)) - if DEBUG_MODE: - out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(sub_dir, mlfile)) - out.write('\n') - out.write('\t%s ' % (OCAMLC)) - if DEBUG_MODE: - out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) - out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) - out.write('\n') + # out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + # out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') + + # out.write('api/ml/libz3ml$(SO_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + # out.write('\t$(SLINK) $(SLINK_OUT_FLAG)api/ml/libz3ml$(SO_EXT) $(SLINK_FLAGS) -I %s -I %s api/ml/z3native_stubs$(OBJ_EXT) %s$(LIB_EXT)\n' % (OCAML_LIB, api_src, get_component(Z3_DLL_COMPONENT).dll_name)) + + + # out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + + # for mlfile in get_ml_files(self.src_dir): + # out.write(' %s' % os.path.join(sub_dir, mlfile)) + # out.write('\n') + # out.write('\t%s ' % (OCAMLOPT)) + # if DEBUG_MODE: + # out.write('-g ') + # out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + + # out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + # out.write('\t%s ' % (OCAMLOPT)) + # if DEBUG_MODE: + # out.write('-g ') + # out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + # out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + # for mlfile in get_ml_files(self.src_dir): + # out.write(' %s' % os.path.join(sub_dir, mlfile)) + # out.write('\n') + # out.write('\t%s ' % (OCAMLC)) + # if DEBUG_MODE: + # out.write('-g ') + # out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + + out.write('%s:' % (os.path.join(sub_dir, "z3.cmxa"))) + for m in modules: + out.write(' %s.cmi' % (os.path.join(sub_dir, m))) + out.write(' %s.cmx' % (os.path.join(sub_dir, m))) + out.write(' %s.cmo' % (os.path.join(sub_dir, m))) + out.write('%s/z3native_stubs.o\n' % (sub_dir)) + out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) + for m in modules: + out.write(' ' + m) + out.write('z3native_stubs$(OBJ_EXT) ; cd -' ) + out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) + #out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/META\n') + out.write('\nocamlfind_install: api/ml/z3.cmxa api/ml/META\n') out.write('\t%s remove Z3\n' % (OCAMLFIND)) - out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) + out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) for m in modules: + out.write(' %s.cma' % (os.path.join(sub_dir, m))) + out.write(' %s.cmxa' % (os.path.join(sub_dir, m))) + out.write(' %s.cmxx' % (os.path.join(sub_dir, m))) out.write(' %s.cmi' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - if IS_WINDOWS: - out.write(' libz3$(LIB_EXT)') - out.write('\n') - out.write('\n') + out.write(' %s' % ((os.path.join(sub_dir, 'libz3$(LIB_EXT)')))) + out.write(' %s' % ((os.path.join(sub_dir, 'dllz3$(SO_EXT)')))) + out.write('\n\n') def main_component(self): return is_ml_enabled() From 7d577eeb71e26b488ef7437a36b80e46e370034e Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 13:51:17 +0000 Subject: [PATCH 111/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 90618edc3..c4f780358 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1422,8 +1422,9 @@ class MLComponent(Component): out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) for m in modules: out.write(' ' + m) - out.write('z3native_stubs$(OBJ_EXT) ; cd -' ) - out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) + out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') + out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) + # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) #out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) From 6e1e28dd58fbf0d60aa3b2c53c0c909c968deea6 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 14:11:19 +0000 Subject: [PATCH 112/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index c4f780358..6803e97e4 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1416,8 +1416,8 @@ class MLComponent(Component): out.write('%s:' % (os.path.join(sub_dir, "z3.cmxa"))) for m in modules: out.write(' %s.cmi' % (os.path.join(sub_dir, m))) - out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - out.write(' %s.cmo' % (os.path.join(sub_dir, m))) + # out.write(' %s.cmx' % (os.path.join(sub_dir, m))) + # out.write(' %s.cmo' % (os.path.join(sub_dir, m))) out.write('%s/z3native_stubs.o\n' % (sub_dir)) out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) for m in modules: @@ -1435,11 +1435,15 @@ class MLComponent(Component): for m in modules: out.write(' %s.cma' % (os.path.join(sub_dir, m))) out.write(' %s.cmxa' % (os.path.join(sub_dir, m))) - out.write(' %s.cmxx' % (os.path.join(sub_dir, m))) - out.write(' %s.cmi' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) + out.write(' %s.cmxs' % (os.path.join(sub_dir, m))) + out.write(' %s.cmi' % (os.path.join(sub_dir, m))) out.write(' %s' % ((os.path.join(sub_dir, 'libz3$(LIB_EXT)')))) - out.write(' %s' % ((os.path.join(sub_dir, 'dllz3$(SO_EXT)')))) + out.write(' %s' % ((os.path.join(sub_dir, 'dllz3')))) + if IS_WINDOWS: + out.write('.lib') + else: + out.write('.so') # .so also on OSX! out.write('\n\n') def main_component(self): From b95ada16f32436b140da15853e8e2fc75a2e54e1 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 14:14:14 +0000 Subject: [PATCH 113/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 6803e97e4..3d10468c0 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1418,7 +1418,7 @@ class MLComponent(Component): out.write(' %s.cmi' % (os.path.join(sub_dir, m))) # out.write(' %s.cmx' % (os.path.join(sub_dir, m))) # out.write(' %s.cmo' % (os.path.join(sub_dir, m))) - out.write('%s/z3native_stubs.o\n' % (sub_dir)) + out.write(' %s/z3native_stubs.o\n' % (sub_dir)) out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) for m in modules: out.write(' ' + m) From c7b73c98a5cac51880ed224e8b42fcf7838a9e31 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 14:18:03 +0000 Subject: [PATCH 114/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 3d10468c0..6fdbdd2a3 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1421,7 +1421,7 @@ class MLComponent(Component): out.write(' %s/z3native_stubs.o\n' % (sub_dir)) out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) for m in modules: - out.write(' ' + m) + out.write(' %s.ml' % m) out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) From 5de8f880116c555cbfaef76917fac7710907ffa1 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 15:03:10 +0000 Subject: [PATCH 115/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 6fdbdd2a3..c8bcd6e12 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1418,28 +1418,28 @@ class MLComponent(Component): out.write(' %s.cmi' % (os.path.join(sub_dir, m))) # out.write(' %s.cmx' % (os.path.join(sub_dir, m))) # out.write(' %s.cmo' % (os.path.join(sub_dir, m))) - out.write(' %s/z3native_stubs.o\n' % (sub_dir)) - out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) + out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) + out.write('\tcd %s ; ocamlmklib -o z3ml' % (sub_dir)) for m in modules: out.write(' %s.ml' % m) out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') - out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) + out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) #out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('\nocamlfind_install: api/ml/z3.cmxa api/ml/META\n') + out.write('\nocamlfind_install: %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'META'))) out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) for m in modules: out.write(' %s.cma' % (os.path.join(sub_dir, m))) out.write(' %s.cmxa' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - out.write(' %s.cmxs' % (os.path.join(sub_dir, m))) + #out.write(' %s.cmxs' % (os.path.join(sub_dir, m))) out.write(' %s.cmi' % (os.path.join(sub_dir, m))) - out.write(' %s' % ((os.path.join(sub_dir, 'libz3$(LIB_EXT)')))) - out.write(' %s' % ((os.path.join(sub_dir, 'dllz3')))) + out.write(' %s' % ((os.path.join(sub_dir, 'libz3ml$(LIB_EXT)')))) + out.write(' %s' % ((os.path.join(sub_dir, 'dllz3ml')))) if IS_WINDOWS: out.write('.lib') else: From 1ce0cd3209131ee01e6ba8462f8aa21b12592905 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 15:38:15 +0000 Subject: [PATCH 116/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index c8bcd6e12..c169a21f7 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1404,14 +1404,19 @@ class MLComponent(Component): # if DEBUG_MODE: # out.write('-g ') # out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - # out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - # for mlfile in get_ml_files(self.src_dir): - # out.write(' %s' % os.path.join(sub_dir, mlfile)) - # out.write('\n') - # out.write('\t%s ' % (OCAMLC)) - # if DEBUG_MODE: - # out.write('-g ') - # out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('%s: %s %s$(SO_EXT) %s' % ( + os.path.join(sub_dir, 'z3.cma'), + os.path.join(sub_dir, 'libz3ml$(LIB_EXT)'), + get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + for mlfile in get_ml_files(self.src_dir): + out.write(' %s' % os.path.join(sub_dir, mlfile)) + out.write('\n') + out.write('\t%s ' % (OCAMLC)) + if DEBUG_MODE: + out.write('-g ') + out.write('-I %s -a -o %s -linkall' % (sub_dir, os.path.join(sub_dir, 'z3.cma'))) + for m in modules: + out.write(' %s.ml' % (os.path.join(sub_dir, m))) out.write('%s:' % (os.path.join(sub_dir, "z3.cmxa"))) for m in modules: From f0d66388d4af4c29531978473885d7296ea49ab9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 19:22:23 +0000 Subject: [PATCH 117/248] ML API: build fixes --- scripts/mk_util.py | 96 ++++++++++++++++++---------------------------- src/api/ml/META | 10 ++--- src/api/ml/z3.ml | 2 +- 3 files changed, 43 insertions(+), 65 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index c169a21f7..caad10555 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1362,19 +1362,25 @@ class MLComponent(Component): str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! - prev = '' + mls = '' + mlis = '' + cmis = '' + archives = '' + for m in modules: fn = os.path.join(self.src_dir, ('%s.mli' % m)) if not os.path.exists(fn): - out.write('%s.mli: %s.ml%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),prev)) + out.write('%s.mli: %s.ml%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),mlis)) out.write('\t%s -I %s -i -c %s.ml > %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir, m),os.path.join(sub_dir, m))) - prev = prev + ' ' + os.path.join(sub_dir, m) + '.mli' - cmis = '' - for m in modules: out.write('%s.cmi: %s.mli%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m), cmis)) out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) + out.write('%s.cma: %s.ml %s.cmi%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),os.path.join(sub_dir,m), archives)) + out.write('\t%s -a -o %s.ml -o %s.cma\n' % (OCAMLC,os.path.join(sub_dir,m), os.path.join(sub_dir,m))) + mlis = mlis + ' ' + os.path.join(sub_dir, m) + '.mli' cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - + archives = archives + ' ' + os.path.join(sub_dir,m) + '.cma' + mls = mls + ' ' + os.path.join(sub_dir, m) + '.ml' + out.write('%s: %s %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'), os.path.join(sub_dir, 'z3native_stubs.c'), @@ -1382,73 +1388,43 @@ class MLComponent(Component): out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s $(CXX_OUT_FLAG)%s$(OBJ_EXT)\n' % (OCAML_LIB, api_src, os.path.join(sub_dir, 'z3native_stubs.c'), os.path.join(sub_dir, 'z3native_stubs'))) - # out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - # out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') - - # out.write('api/ml/libz3ml$(SO_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - # out.write('\t$(SLINK) $(SLINK_OUT_FLAG)api/ml/libz3ml$(SO_EXT) $(SLINK_FLAGS) -I %s -I %s api/ml/z3native_stubs$(OBJ_EXT) %s$(LIB_EXT)\n' % (OCAML_LIB, api_src, get_component(Z3_DLL_COMPONENT).dll_name)) - - - # out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - - # for mlfile in get_ml_files(self.src_dir): - # out.write(' %s' % os.path.join(sub_dir, mlfile)) - # out.write('\n') - # out.write('\t%s ' % (OCAMLOPT)) - # if DEBUG_MODE: - # out.write('-g ') - # out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) - - # out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - # out.write('\t%s ' % (OCAMLOPT)) - # if DEBUG_MODE: - # out.write('-g ') - # out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - out.write('%s: %s %s$(SO_EXT) %s' % ( - os.path.join(sub_dir, 'z3.cma'), - os.path.join(sub_dir, 'libz3ml$(LIB_EXT)'), - get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(sub_dir, mlfile)) - out.write('\n') - out.write('\t%s ' % (OCAMLC)) - if DEBUG_MODE: - out.write('-g ') - out.write('-I %s -a -o %s -linkall' % (sub_dir, os.path.join(sub_dir, 'z3.cma'))) - for m in modules: - out.write(' %s.ml' % (os.path.join(sub_dir, m))) - - out.write('%s:' % (os.path.join(sub_dir, "z3.cmxa"))) - for m in modules: - out.write(' %s.cmi' % (os.path.join(sub_dir, m))) - # out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - # out.write(' %s.cmo' % (os.path.join(sub_dir, m))) + out.write('%s: %s %s %s$(SO_EXT)' % ( + os.path.join(sub_dir, "z3ml.cmxa"), + cmis, + archives, + get_component(Z3_DLL_COMPONENT).dll_name)) out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) - out.write('\tcd %s ; ocamlmklib -o z3ml' % (sub_dir)) + out.write('\tcd %s ; ocamlmklib -o z3ml -ldopt \'-L../.. -lz3\' ' % (sub_dir)) for m in modules: out.write(' %s.ml' % m) out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') - out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) - # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) - #out.write('\n') - # Generate META file and package installation commands + out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3ml.cmxa'))) self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('\nocamlfind_install: %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'META'))) + out.write('\nocamlfind_install: %s %s %s\n' % ( + get_component(Z3_DLL_COMPONENT).dll_name)+'$(SO_EXT)', + os.path.join(sub_dir, 'z3ml.cmxa'), + os.path.join(sub_dir, 'META'))) out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) for m in modules: out.write(' %s.cma' % (os.path.join(sub_dir, m))) - out.write(' %s.cmxa' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - #out.write(' %s.cmxs' % (os.path.join(sub_dir, m))) out.write(' %s.cmi' % (os.path.join(sub_dir, m))) + out.write(' %s.cmo' % (os.path.join(sub_dir, m))) + out.write(' %s.ml' % (os.path.join(sub_dir, m))) + out.write(' %s.mli' % (os.path.join(sub_dir, m))) + out.write(' %s$(OBJ_EXT)' % (os.path.join(sub_dir, m))) + out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.a')))) + out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cma')))) + out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cmxa')))) out.write(' %s' % ((os.path.join(sub_dir, 'libz3ml$(LIB_EXT)')))) out.write(' %s' % ((os.path.join(sub_dir, 'dllz3ml')))) if IS_WINDOWS: out.write('.lib') else: out.write('.so') # .so also on OSX! + out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name) + '$(SO_EXT)')))) out.write('\n\n') def main_component(self): @@ -1572,25 +1548,25 @@ class MLExampleComponent(ExampleComponent): def mk_makefile(self, out): if ML_ENABLED: - out.write('ml_example.byte: api/ml/z3.cma ') + out.write('ml_example.byte: api/ml/z3ml.cma ') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') out.write('\t%s ' % OCAMLC) if DEBUG_MODE: out.write('-g ') - out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" nums.cma z3.cma') + out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" nums.cma z3ml.cma') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('ml_example$(EXE_EXT): api/ml/z3.cmxa ml_example.byte') + out.write('ml_example$(EXE_EXT): api/ml/z3ml.cmxa ml_example.byte') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') out.write('\t%s ' % OCAMLOPT) if DEBUG_MODE: out.write('-g ') - out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" nums.cmxa z3.cmxa') + out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" nums.cmxa z3ml.cmxa') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') @@ -3035,3 +3011,5 @@ def mk_unix_dist(build_path, dist_path): if __name__ == '__main__': import doctest doctest.testmod() + + diff --git a/src/api/ml/META b/src/api/ml/META index 6238403a3..8634b53b1 100644 --- a/src/api/ml/META +++ b/src/api/ml/META @@ -2,8 +2,8 @@ version = "VERSION" description = "Z3 Theorem Prover (OCaml API)" requires = "num" -archive(byte) = "z3.cma" -archive(native) = "z3.cmxa" -archive(byte, plugin) = "z3.cma" -archive(native, plugin) = "z3.cmxs" -linkopts = "-cclib -lz3" \ No newline at end of file +archive(byte) = "z3ml.cma" +archive(native) = "z3ml.cmxa" +archive(byte, plugin) = "z3ml.cma" +archive(native, plugin) = "z3ml.cmxs" +linkopts = "-cclib -lz3" diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 2b54a1113..350457525 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -110,7 +110,7 @@ struct string_of_int mj ^ "." ^ string_of_int mn ^ "." ^ string_of_int bld ^ "." ^ - string_of_int rev ^ "." + string_of_int rev end From 6022ae68737122ab1142f851c2328946e30e43d4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 19:42:03 +0000 Subject: [PATCH 118/248] ML API: build fixes? --- scripts/mk_util.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index caad10555..99f413090 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1394,16 +1394,18 @@ class MLComponent(Component): archives, get_component(Z3_DLL_COMPONENT).dll_name)) out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) - out.write('\tcd %s ; ocamlmklib -o z3ml -ldopt \'-L../.. -lz3\' ' % (sub_dir)) + out.write('\tocamlmklib -o %s -I %s -ldopt \'-L. -lz3\' ' % ( + os.path.join(sub_dir, 'z3ml'), + sub_dir)) for m in modules: - out.write(' %s.ml' % m) - out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') + out.write(' %s' % (os.path.join(sub_dir, m+'.ml'))) + out.write(' z3native_stubs$(OBJ_EXT)\n') out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3ml.cmxa'))) self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': out.write('\nocamlfind_install: %s %s %s\n' % ( - get_component(Z3_DLL_COMPONENT).dll_name)+'$(SO_EXT)', - os.path.join(sub_dir, 'z3ml.cmxa'), + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)', + os.path.join(sub_dir, 'z3ml.cmxa'), os.path.join(sub_dir, 'META'))) out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) @@ -1424,7 +1426,7 @@ class MLComponent(Component): out.write('.lib') else: out.write('.so') # .so also on OSX! - out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name) + '$(SO_EXT)')))) + out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)') out.write('\n\n') def main_component(self): From 0fee9659ab7e7df991778995baeb3bd7fbf9a8a5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 5 Dec 2014 16:40:40 +0000 Subject: [PATCH 119/248] ML API: Windows build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 99f413090..d2d9dd983 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1394,12 +1394,10 @@ class MLComponent(Component): archives, get_component(Z3_DLL_COMPONENT).dll_name)) out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) - out.write('\tocamlmklib -o %s -I %s -ldopt \'-L. -lz3\' ' % ( - os.path.join(sub_dir, 'z3ml'), - sub_dir)) + out.write('\tocamlmklib -o %s -I %s -ldopt \"-L. -lz3\" ' % (os.path.join(sub_dir, 'z3ml'), sub_dir)) for m in modules: out.write(' %s' % (os.path.join(sub_dir, m+'.ml'))) - out.write(' z3native_stubs$(OBJ_EXT)\n') + out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3ml.cmxa'))) self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': @@ -1417,13 +1415,13 @@ class MLComponent(Component): out.write(' %s.ml' % (os.path.join(sub_dir, m))) out.write(' %s.mli' % (os.path.join(sub_dir, m))) out.write(' %s$(OBJ_EXT)' % (os.path.join(sub_dir, m))) - out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.a')))) + out.write(' %s' % ((os.path.join(sub_dir, 'z3ml$(LIB_EXT)')))) out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cma')))) out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cmxa')))) out.write(' %s' % ((os.path.join(sub_dir, 'libz3ml$(LIB_EXT)')))) out.write(' %s' % ((os.path.join(sub_dir, 'dllz3ml')))) if IS_WINDOWS: - out.write('.lib') + out.write('.dll') else: out.write('.so') # .so also on OSX! out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)') @@ -1550,7 +1548,7 @@ class MLExampleComponent(ExampleComponent): def mk_makefile(self, out): if ML_ENABLED: - out.write('ml_example.byte: api/ml/z3ml.cma ') + out.write('ml_example.byte: api/ml/z3ml.cmxa ') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') From ae2c4d738c850cb9617179eaa567bac27ca1bd13 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 6 Dec 2014 18:14:26 +0000 Subject: [PATCH 120/248] ML API: build fix --- src/api/ml/META | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/ml/META b/src/api/ml/META index 8634b53b1..635de613c 100644 --- a/src/api/ml/META +++ b/src/api/ml/META @@ -4,6 +4,8 @@ description = "Z3 Theorem Prover (OCaml API)" requires = "num" archive(byte) = "z3ml.cma" archive(native) = "z3ml.cmxa" -archive(byte, plugin) = "z3ml.cma" -archive(native, plugin) = "z3ml.cmxs" +archive(byte,plugin) = "z3ml.cma" +archive(native,plugin) = "z3ml.cmxa" +archive(byte,toploop) = "z3ml.cma" +archive(native,toploop) = "z3ml.cmxa" linkopts = "-cclib -lz3" From ccffea2bc997e955e605da6fb7c4d43497e9fcf1 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 6 Dec 2014 18:21:27 +0000 Subject: [PATCH 121/248] ML API: build fix --- examples/ml/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ml/README b/examples/ml/README index 844638552..c61716b65 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -15,7 +15,7 @@ for the byte-code version. If Z3 was installed into the ocamlfind package repository (see src/api/ml/README), then we can compile this example as follows: -ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg ml_example.ml +ocamlfind ocamlc -o ml_example.byte -package Z3 -linkpkg ml_example.ml ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg ml_example.ml Note that the resulting binaries depend on the shared z3 library, which needs to be From decb09bb9ecc95c1e59c2381131f10e207d779e9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 6 Dec 2014 18:37:09 +0000 Subject: [PATCH 122/248] ML API: build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index d2d9dd983..5cfcbb4d3 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1425,6 +1425,8 @@ class MLComponent(Component): else: out.write('.so') # .so also on OSX! out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)') + if IS_WINDOWS: + out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(LIB_EXT)') out.write('\n\n') def main_component(self): From 90cb04668447edc5414f218ab6ca42733de17c34 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 11 Dec 2012 13:37:02 +0000 Subject: [PATCH 123/248] Beginnings of a new ML API Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 11 + scripts/update_api.py | 576 +++++++++++------------------------------- src/api/ml/README | 5 +- 3 files changed, 166 insertions(+), 426 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 5cfcbb4d3..7a054256d 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1428,6 +1428,13 @@ class MLComponent(Component): if IS_WINDOWS: out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(LIB_EXT)') out.write('\n\n') + mk_dir(os.path.join(BUILD_DIR, 'api', 'ml')) + libfile = '%s$(LIB_EXT)' % self.lib_name + out.write('%s: libz3$(SO_EXT) %s\n' % (libfile, os.path.join(self.to_src_dir, 'z3_native.c'))) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) %s/z3_native.c\n' % self.to_src_dir) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'z3_native')) + out.write('ml: %s\n' % libfile) + out.write('\n') def main_component(self): return is_ml_enabled() @@ -1841,7 +1848,11 @@ def mk_config(): if GPROF: print('gprof: enabled') print('Python version: %s' % distutils.sysconfig.get_python_version()) +<<<<<<< HEAD print('ML API: %s' % is_ml_enabled()) +======= + print 'ML API: %s' % is_ml_enabled() +>>>>>>> Beginnings of a new ML API if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) diff --git a/scripts/update_api.py b/scripts/update_api.py index 4669b78fc..945496781 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -213,7 +213,10 @@ def type2javaw(ty): def type2ml(ty): global Type2ML - return Type2ML[ty] + if (ty >= FIRST_OBJ_ID): + return 'long' + else: + return Type2ML[ty] def _in(ty): return (IN, ty); @@ -1066,216 +1069,76 @@ def mk_bindings(): exe_c.write("}\n") def ml_method_name(name): - return name[3:] # Remove Z3_ - -def is_out_param(p): - if param_kind(p) == OUT or param_kind(p) == INOUT or param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY or param_kind(p) == OUT_MANAGED_ARRAY: - return True - else: - return False - -def outparams(params): - op = [] - for param in params: - if is_out_param(param): - op.append(param) - return op - -def is_in_param(p): - if param_kind(p) == IN or param_kind(p) == INOUT or param_kind(p) == IN_ARRAY or param_kind(p) == INOUT_ARRAY: - return True - else: - return False - -def inparams(params): - ip = [] - for param in params: - if is_in_param(param): - ip.append(param) - return ip - -def is_array_param(p): - if param_kind(p) == IN_ARRAY or param_kind(p) == INOUT_ARRAY or param_kind(p) == OUT_ARRAY: - return True - else: - return False - -def arrayparams(params): - op = [] - for param in params: - if is_array_param(param): - op.append(param) - return op - - -def ml_unwrap(t, ts, s): - if t == STRING: - return '(' + ts + ') String_val(' + s + ')' - elif t == BOOL: - return '(' + ts + ') Bool_val(' + s + ')' - elif t == INT or t == PRINT_MODE or t == ERROR_CODE: - return '(' + ts + ') Int_val(' + s + ')' - elif t == UINT: - return '(' + ts + ') Unsigned_int_val(' + s + ')' - elif t == INT64: - return '(' + ts + ') Long_val(' + s + ')' - elif t == UINT64: - return '(' + ts + ') Unsigned_long_val(' + s + ')' - elif t == DOUBLE: - return '(' + ts + ') Double_val(' + s + ')' - else: - return '* (' + ts + '*) Data_custom_val(' + s + ')' - -def ml_set_wrap(t, d, n): - if t == VOID: - return d + ' = Val_unit;' - elif t == BOOL: - return d + ' = Val_bool(' + n + ');' - elif t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE: - return d + ' = Val_int(' + n + ');' - elif t == INT64 or t == UINT64: - return d + ' = Val_long(' + n + ');' - elif t == DOUBLE: - return 'Store_double_val(' + d + ', ' + n + ');' - elif t == STRING: - return d + ' = caml_copy_string((const char*) ' + n + ');' - else: - ts = type2str(t) - return d + ' = caml_alloc_custom(&default_custom_ops, sizeof(' + ts + '), 0, 1); memcpy( Data_custom_val(' + d + '), &' + n + ', sizeof(' + ts + '));' + result = '' + name = name[3:] # Remove Z3_ + return result def mk_ml(): - global Type2Str if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir - ml_nativef = os.path.join(ml_dir, 'z3native.ml') - ml_nativefi = os.path.join(ml_dir, 'z3native.mli') - ml_wrapperf = os.path.join(ml_dir, 'z3native_stubs.c') + ml_nativef = os.path.join(ml_dir, 'z3_native.ml') + ml_wrapperf = os.path.join(ml_dir, 'z3_native.c') ml_native = open(ml_nativef, 'w') - ml_i = open(ml_nativefi, 'w') - ml_native.write('(* Automatically generated file *)\n\n') - ml_native.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') - ml_i.write('(* Automatically generated file *)\n\n') - ml_i.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') - ml_i.write('(**/**)\n\n'); - ml_native.write('open Z3enums\n\n') - ml_native.write('(**/**)\n') - ml_native.write('type ptr\n') - ml_i.write('type ptr\n') - ml_native.write('and z3_symbol = ptr\n') - ml_i.write('and z3_symbol = ptr\n') - for k, v in Type2Str.iteritems(): - if is_obj(k): - ml_native.write('and %s = ptr\n' % v.lower()) - ml_i.write('and %s = ptr\n' % v.lower()) + ml_native.write('// Automatically generated file\n') ml_native.write('\n') - ml_i.write('\n') - ml_native.write('external is_null : ptr -> bool\n = "n_is_null"\n\n') - ml_native.write('external mk_null : unit -> ptr\n = "n_mk_null"\n\n') - ml_native.write('external set_internal_error_handler : ptr -> unit\n = "n_set_internal_error_handler"\n\n') - ml_native.write('exception Exception of string\n\n') - ml_i.write('val is_null : ptr -> bool\n') - ml_i.write('val mk_null : unit -> ptr\n') - ml_i.write('val set_internal_error_handler : ptr -> unit\n\n') - ml_i.write('exception Exception of string\n\n') - - # ML declarations - ml_native.write('module ML2C = struct\n\n') for name, result, params in _dotnet_decls: - ml_native.write(' external n_%s : ' % ml_method_name(name)) - ml_i.write('val %s : ' % ml_method_name(name)) - ip = inparams(params) - op = outparams(params) - if len(ip) == 0: - ml_native.write(' unit -> ') - ml_i.write(' unit -> ') - for p in ip: - ml_native.write('%s -> ' % param2ml(p)) - ml_i.write('%s -> ' % param2ml(p)) - if len(op) > 0: - ml_native.write('(') - ml_i.write('(') + ml_native.write(' external %s : (' % ml_method_name(name)) first = True - if result != VOID or len(op) == 0: - ml_native.write('%s' % type2ml(result)) - ml_i.write('%s' % type2ml(result)) - first = False - for p in op: + i = 0; + for param in params: if first: first = False else: - ml_native.write(' * ') - ml_i.write(' * ') - ml_native.write('%s' % param2ml(p)) - ml_i.write('%s' % param2ml(p)) - if len(op) > 0: - ml_native.write(')') - ml_i.write(')') - ml_native.write('\n') - ml_i.write('\n') - if len(ip) > 5: - ml_native.write(' = "n_%s_bytecode"\n' % ml_method_name(name)) - ml_native.write(' "n_%s"\n' % ml_method_name(name)) - else: - ml_native.write(' = "n_%s"\n' % ml_method_name(name)) - ml_native.write('\n') - ml_native.write(' end\n\n') - ml_i.write('\n(**/**)\n'); - - # Exception wrappers - for name, result, params in _dotnet_decls: - ip = inparams(params) - op = outparams(params) - ml_native.write(' let %s ' % ml_method_name(name)) - - first = True - i = 0; - for p in params: - if is_in_param(p): - if first: - first = False; - else: - ml_native.write(' ') - ml_native.write('a%d' % i) + ml_native.write(', ') + ml_native.write('%s a%d' % (param2ml(param), i)) i = i + 1 - if len(ip) == 0: - ml_native.write('()') - ml_native.write(' = \n') - ml_native.write(' ') - if result == VOID and len(op) == 0: - ml_native.write('let _ = ') - else: - ml_native.write('let res = ') - ml_native.write('(ML2C.n_%s' % (ml_method_name(name))) - if len(ip) == 0: - ml_native.write(' ()') - first = True - i = 0; - for p in params: - if is_in_param(p): - ml_native.write(' a%d' % i) - i = i + 1 - ml_native.write(') in\n') - if name not in Unwrapped and len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = (error_code_of_int (ML2C.n_get_error_code a0)) in \n') - ml_native.write(' if err <> OK then\n') - ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (int_of_error_code err)))\n') - ml_native.write(' else\n') - if result == VOID and len(op) == 0: - ml_native.write(' ()\n') - else: - ml_native.write(' res\n') - ml_native.write('\n') - ml_native.write('(**/**)\n') - - # C interface + ml_native.write('%s)\n' % (type2ml(result))) + # ml_native.write(' = "NATIVE_%s"' % ml_method_name(name)) + # ml_native.write('\n\n') + # # Exception wrappers + # for name, result, params in _dotnet_decls: + # java_native.write(' public static %s %s(' % (type2java(result), java_method_name(name))) + # first = True + # i = 0; + # for param in params: + # if first: + # first = False + # else: + # java_native.write(', ') + # java_native.write('%s a%d' % (param2java(param), i)) + # i = i + 1 + # java_native.write(')') + # if len(params) > 0 and param_type(params[0]) == CONTEXT: + # java_native.write(' throws Z3Exception') + # java_native.write('\n') + # java_native.write(' {\n') + # java_native.write(' ') + # if result != VOID: + # java_native.write('%s res = ' % type2java(result)) + # java_native.write('INTERNAL%s(' % (java_method_name(name))) + # first = True + # i = 0; + # for param in params: + # if first: + # first = False + # else: + # java_native.write(', ') + # java_native.write('a%d' % i) + # i = i + 1 + # java_native.write(');\n') + # if len(params) > 0 and param_type(params[0]) == CONTEXT: + # java_native.write(' Z3_error_code err = Z3_error_code.fromInt(INTERNALgetErrorCode(a0));\n') + # java_native.write(' if (err != Z3_error_code.Z3_OK)\n') + # java_native.write(' throw new Z3Exception(INTERNALgetErrorMsgEx(a0, err.toInt()));\n') + # if result != VOID: + # java_native.write(' return res;\n') + # java_native.write(' }\n\n') + # java_native.write('}\n') ml_wrapper = open(ml_wrapperf, 'w') ml_wrapper.write('// Automatically generated file\n\n') ml_wrapper.write('#include \n') - ml_wrapper.write('#include \n\n') - ml_wrapper.write('#ifdef __cplusplus\n') - ml_wrapper.write('extern "C" {\n') - ml_wrapper.write('#endif\n') + ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') @@ -1285,237 +1148,100 @@ def mk_ml(): ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') ml_wrapper.write('#endif\n') - ml_wrapper.write('#ifdef __cplusplus\n') - ml_wrapper.write('}\n') - ml_wrapper.write('#endif\n\n') - ml_wrapper.write('#include \n\n') - ml_wrapper.write('#define CAMLlocal6(X1,X2,X3,X4,X5,X6) \\\n') - ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal1(X6) \n') - ml_wrapper.write('#define CAMLlocal7(X1,X2,X3,X4,X5,X6,X7) \\\n') - ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal2(X6,X7) \n') - ml_wrapper.write('#define CAMLlocal8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') - ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal3(X6,X7,X8) \n') - ml_wrapper.write('\n') - ml_wrapper.write('#define CAMLparam7(X1,X2,X3,X4,X5,X6,X7) \\\n') - ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam2(X6,X7) \n') - ml_wrapper.write('#define CAMLparam8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') - ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam3(X6,X7,X8) \n') - ml_wrapper.write('#define CAMLparam9(X1,X2,X3,X4,X5,X6,X7,X8,X9) \\\n') - ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam4(X6,X7,X8,X9) \n') - ml_wrapper.write('#define CAMLparam12(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12) \\\n') - ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') - ml_wrapper.write(' CAMLxparam2(X11,X12) \n') - ml_wrapper.write('#define CAMLparam13(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13) \\\n') - ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') - ml_wrapper.write(' CAMLxparam3(X11,X12,X13) \n') - ml_wrapper.write('\n\n') - ml_wrapper.write('static struct custom_operations default_custom_ops = {\n') - ml_wrapper.write(' (char*) "default handling",\n') - ml_wrapper.write(' custom_finalize_default,\n') - ml_wrapper.write(' custom_compare_default,\n') - ml_wrapper.write(' custom_hash_default,\n') - ml_wrapper.write(' custom_serialize_default,\n') - ml_wrapper.write(' custom_deserialize_default\n') - ml_wrapper.write('};\n\n') - ml_wrapper.write('#ifdef __cplusplus\n') - ml_wrapper.write('extern "C" {\n') - ml_wrapper.write('#endif\n\n') - ml_wrapper.write('CAMLprim value n_is_null(value p) {\n') - ml_wrapper.write(' void * t = * (void**) Data_custom_val(p);\n') - ml_wrapper.write(' return Val_bool(t == 0);\n') - ml_wrapper.write('}\n\n') - ml_wrapper.write('CAMLprim value n_mk_null( void ) {\n') - ml_wrapper.write(' CAMLparam0();\n') - ml_wrapper.write(' CAMLlocal1(result);\n') - ml_wrapper.write(' void * z3_result = 0;\n') - ml_wrapper.write(' result = caml_alloc_custom(&default_custom_ops, sizeof(void*), 0, 1);\n') - ml_wrapper.write(' memcpy( Data_custom_val(result), &z3_result, sizeof(void*));\n') - ml_wrapper.write(' CAMLreturn (result);\n') - ml_wrapper.write('}\n\n') - ml_wrapper.write('void MLErrorHandler(Z3_context c, Z3_error_code e)\n') - ml_wrapper.write('{\n') - ml_wrapper.write(' // Internal do-nothing error handler. This is required to avoid that Z3 calls exit()\n') - ml_wrapper.write(' // upon errors, but the actual error handling is done by throwing exceptions in the\n') - ml_wrapper.write(' // wrappers below.\n') - ml_wrapper.write('}\n\n') - ml_wrapper.write('void n_set_internal_error_handler(value a0)\n') - ml_wrapper.write('{\n') - ml_wrapper.write(' Z3_context _a0 = * (Z3_context*) Data_custom_val(a0);\n') - ml_wrapper.write(' Z3_set_error_handler(_a0, MLErrorHandler);\n') - ml_wrapper.write('}\n\n') - for name, result, params in _dotnet_decls: - ip = inparams(params) - op = outparams(params) - ap = arrayparams(params) - ret_size = len(op) - if result != VOID: - ret_size = ret_size + 1 - - # Setup frame - ml_wrapper.write('CAMLprim value n_%s(' % ml_method_name(name)) - first = True - i = 0 - for p in params: - if is_in_param(p): - if first: - first = False - else: - ml_wrapper.write(', ') - ml_wrapper.write('value a%d' % i) - i = i + 1 - ml_wrapper.write(') {\n') - ml_wrapper.write(' CAMLparam%d(' % len(ip)) - i = 0 - first = True - for p in params: - if is_in_param(p): - if first: - first = False - else: - ml_wrapper.write(', ') - ml_wrapper.write('a%d' % i) - i = i + 1 - ml_wrapper.write(');\n') - i = 0 - if len(op) + len(ap) == 0: - ml_wrapper.write(' CAMLlocal1(result);\n') - else: - c = 0 - for p in params: - if is_out_param(p) or is_array_param(p): - c = c + 1 - ml_wrapper.write(' CAMLlocal%s(result, res_val' % (c+2)) - for p in params: - if is_out_param(p) or is_array_param(p): - ml_wrapper.write(', _a%s_val' % i) - i = i + 1 - ml_wrapper.write(');\n') + # for name, result, params in _dotnet_decls: + # java_wrapper.write('JNIEXPORT %s JNICALL Java_%s_Native_INTERNAL%s(JNIEnv * jenv, jclass cls' % (type2javaw(result), pkg_str, java_method_name(name))) + # i = 0; + # for param in params: + # java_wrapper.write(', ') + # java_wrapper.write('%s a%d' % (param2javaw(param), i)) + # i = i + 1 + # java_wrapper.write(') {\n') + # # preprocess arrays, strings, in/out arguments + # i = 0 + # for param in params: + # k = param_kind(param) + # if k == OUT or k == INOUT: + # java_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) + # elif k == IN_ARRAY or k == INOUT_ARRAY: + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i)) + # else: + # java_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i)) + # elif k == OUT_ARRAY: + # java_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)), + # i, + # type2str(param_type(param)), + # param_array_capacity_pos(param), + # type2str(param_type(param)))) + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) + # else: + # java_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i)) + # elif k == IN and param_type(param) == STRING: + # java_wrapper.write(' Z3_string _a%s = (Z3_string) jenv->GetStringUTFChars(a%s, NULL);\n' % (i, i)) + # i = i + 1 + # # invoke procedure + # java_wrapper.write(' ') + # if result != VOID: + # java_wrapper.write('%s result = ' % type2str(result)) + # java_wrapper.write('%s(' % name) + # i = 0 + # first = True + # for param in params: + # if first: + # first = False + # else: + # java_wrapper.write(', ') + # k = param_kind(param) + # if k == OUT or k == INOUT: + # java_wrapper.write('&_a%s' % i) + # elif k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: + # java_wrapper.write('_a%s' % i) + # elif k == IN and param_type(param) == STRING: + # java_wrapper.write('_a%s' % i) + # else: + # java_wrapper.write('(%s)a%i' % (param2str(param), i)) + # i = i + 1 + # java_wrapper.write(');\n') + # # cleanup + # i = 0 + # for param in params: + # k = param_kind(param) + # if k == OUT_ARRAY: + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) + # else: + # java_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i)) + # java_wrapper.write(' free(_a%s);\n' % i) + # elif k == IN_ARRAY or k == OUT_ARRAY: + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i)) + # else: + # java_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i)) - if len(ap) != 0: - ml_wrapper.write(' unsigned _i;\n') - - # declare locals, preprocess arrays, strings, in/out arguments - i = 0 - for param in params: - k = param_kind(param) - if k == OUT_ARRAY: - ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * (_a%s));\n' % ( - type2str(param_type(param)), - i, - type2str(param_type(param)), - type2str(param_type(param)), - param_array_capacity_pos(param))) - elif k == OUT_MANAGED_ARRAY: - ml_wrapper.write(' %s * _a%s = 0;\n' % (type2str(param_type(param)), i)) - elif k == IN_ARRAY or k == INOUT_ARRAY: - t = param_type(param) - ts = type2str(t) - ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * _a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) - elif k == IN: - t = param_type(param) - ml_wrapper.write(' %s _a%s = %s;\n' % (type2str(t), i, ml_unwrap(t, type2str(t), 'a' + str(i)))) - elif k == OUT: - ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) - elif k == INOUT: - ml_wrapper.write(' %s _a%s = a%s;\n' % (type2str(param_type(param)), i, i)) - i = i + 1 - - if result != VOID: - ml_wrapper.write(' %s z3_result;\n' % type2str(result)) - - i = 0 - for param in params: - k = param_kind(param) - if k == IN_ARRAY or k == INOUT_ARRAY: - t = param_type(param) - ts = type2str(t) - ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { _a%s[_i] = %s; }\n' % (param_array_capacity_pos(param), i, ml_unwrap(t, ts, 'Field(a' + str(i) + ', _i)'))) - i = i + 1 - - # invoke procedure - ml_wrapper.write(' ') - if result != VOID: - ml_wrapper.write('z3_result = ') - ml_wrapper.write('%s(' % name) - i = 0 - first = True - for param in params: - if first: - first = False - else: - ml_wrapper.write(', ') - k = param_kind(param) - if k == OUT or k == INOUT or k == OUT_MANAGED_ARRAY: - ml_wrapper.write('&_a%s' % i) - else: - ml_wrapper.write('_a%i' % i) - i = i + 1 - ml_wrapper.write(');\n') - - # convert output params - if len(op) > 0: - if result != VOID: - ml_wrapper.write(' %s\n' % ml_set_wrap(result, "res_val", "z3_result")) - i = 0; - for p in params: - if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: - ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) - ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s_val, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) - elif param_kind(p) == OUT_MANAGED_ARRAY: - ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) - elif is_out_param(p): - ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) - i = i + 1 - - # return tuples - if len(op) == 0: - ml_wrapper.write(' %s\n' % ml_set_wrap(result, "result", "z3_result")) - else: - ml_wrapper.write(' result = caml_alloc(%s, 0);\n' % ret_size) - i = j = 0 - if result != VOID: - ml_wrapper.write(' Store_field(result, 0, res_val);\n') - j = j + 1 - for p in params: - if is_out_param(p): - ml_wrapper.write(' Store_field(result, %s, _a%s_val);\n' % (j, i)) - j = j + 1; - i = i + 1 - - # local array cleanup - i = 0 - for p in params: - k = param_kind(p) - if k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: - ml_wrapper.write(' free(_a%s);\n' % i) - i = i + 1 - - # return - ml_wrapper.write(' CAMLreturn(result);\n') - ml_wrapper.write('}\n\n') - if len(ip) > 5: - ml_wrapper.write('CAMLprim value n_%s_bytecode(value * argv, int argn) {\n' % ml_method_name(name)) - ml_wrapper.write(' return n_%s(' % ml_method_name(name)) - i = 0 - while i < len(ip): - if i == 0: - ml_wrapper.write('argv[0]') - else: - ml_wrapper.write(', argv[%s]' % i) - i = i + 1 - ml_wrapper.write(');\n}\n') - ml_wrapper.write('\n\n') - ml_wrapper.write('#ifdef __cplusplus\n') - ml_wrapper.write('}\n') - ml_wrapper.write('#endif\n') + # elif k == OUT or k == INOUT: + # if param_type(param) == INT or param_type(param) == UINT: + # java_wrapper.write(' {\n') + # java_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) + # java_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "I");\n') + # java_wrapper.write(' jenv->SetIntField(a%s, fid, (jint) _a%s);\n' % (i, i)) + # java_wrapper.write(' }\n') + # else: + # java_wrapper.write(' {\n') + # java_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) + # java_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "J");\n') + # java_wrapper.write(' jenv->SetLongField(a%s, fid, (jlong) _a%s);\n' % (i, i)) + # java_wrapper.write(' }\n') + # i = i + 1 + # # return + # if result == STRING: + # java_wrapper.write(' return jenv->NewStringUTF(result);\n') + # elif result != VOID: + # java_wrapper.write(' return (%s) result;\n' % type2javaw(result)) + # java_wrapper.write('}\n') + # java_wrapper.write('#ifdef __cplusplus\n') + # java_wrapper.write('}\n') + # java_wrapper.write('#endif\n') if is_verbose(): print "Generated '%s'" % ml_nativef diff --git a/src/api/ml/README b/src/api/ml/README index beee7d864..f8984c79e 100644 --- a/src/api/ml/README +++ b/src/api/ml/README @@ -1,8 +1,11 @@ This directory is work in progress. We are currently working on a brand new ML API. +<<<<<<< HEAD On Windows, there are no less than four different ports of OCaml. The Z3 build system assumes that either the win32 or the win64 port is installed. This means that OCaml will use `cl' as the underlying C compiler and not the cygwin or -mingw compilers. \ No newline at end of file +mingw compilers. +======= +>>>>>>> Beginnings of a new ML API From 1579da02b0e49c079afe95df9fb7b36f32b9dc2a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 11 Dec 2012 15:07:33 +0000 Subject: [PATCH 124/248] More new ML API Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 9 ++-- scripts/mk_util.py | 25 +++++++++ scripts/update_api.py | 121 ++++++++++++++++++++++++------------------ 3 files changed, 99 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index 9c9707c4b..2ae719b85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ *~ *.pyc -*.pyo -# Ignore callgrind files -callgrind.out.* # .hpp files are automatically generated *.hpp .z3-trace @@ -45,6 +42,7 @@ bld_rel_x64/* # Auto generated files. config.log config.status +configure install_tactic.cpp mem_initializer.cpp gparams_register_modules.cpp @@ -56,8 +54,6 @@ src/api/api_log_macros.cpp src/api/dll/api_dll.def src/api/dotnet/Enumerations.cs src/api/dotnet/Native.cs -src/api/dotnet/Properties/AssemblyInfo.cs -src/api/dotnet/Microsoft.Z3.xml src/api/python/z3consts.py src/api/python/z3core.py src/ast/pattern/database.h @@ -78,3 +74,6 @@ src/api/ml/z3native_stubs.c src/api/ml/z3native.ml src/api/ml/z3enums.ml src/api/ml/z3.mllib +src/api/ml/z3_native.c +src/api/ml/z3_native.ml +src/api/ml/z3_enums.ml diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 7a054256d..d019e24e9 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2431,6 +2431,8 @@ def mk_bindings(api_files): mk_z3consts_ml(api_files) _execfile(os.path.join('scripts', 'update_api.py'), g) # HACK cp_z3py_to_build() + if is_ml_enabled(): + mk_z3consts_ml(api_files) # Extract enumeration types from API files, and add python definitions. def mk_z3consts_py(api_files): @@ -2718,6 +2720,7 @@ def mk_z3consts_ml(api_files): if not os.path.exists(gendir): os.mkdir(gendir) +<<<<<<< HEAD efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') efile.write('(** The enumeration types of Z3. *)\n\n') @@ -2799,6 +2802,13 @@ def mk_z3consts_ml(api_files): efile = open('%s.mli' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') efile.write('(** The enumeration types of Z3. *)\n\n') +======= + efile = open('%s.ml' % os.path.join(gendir, "z3_enums"), 'w') + efile.write('(* Automatically generated file *)\n\n') + # efile.write('module z3_enums = struct\n\n'); + + +>>>>>>> More new ML API for api_file in api_files: api_file_c = ml.find_file(api_file, ml.name) api_file = os.path.join(api_file_c.src_dir, api_file) @@ -2844,6 +2854,7 @@ def mk_z3consts_ml(api_files): if m: name = words[1] if name not in DeprecatedEnums: +<<<<<<< HEAD efile.write('(** %s *)\n' % name[3:]) efile.write('type %s =\n' % name[3:]) # strip Z3_ for k, i in decls.iteritems(): @@ -2854,6 +2865,13 @@ def mk_z3consts_ml(api_files): efile.write('(** Convert int to %s*)\n' % name[3:]) efile.write('val %s_of_int : int -> %s\n' % (name[3:],name[3:])) # strip Z3_ efile.write('\n') +======= + efile.write('\n(* %s *)\n' % name) + efile.write('type %s =\n' % name[3:]) # strip Z3_ + efile.write + for k, i in decls.iteritems(): + efile.write(' | %s \n' % k[3:]) # strip Z3_ +>>>>>>> More new ML API mode = SEARCHING else: if words[2] != '': @@ -2864,8 +2882,15 @@ def mk_z3consts_ml(api_files): decls[words[1]] = idx idx = idx + 1 linenum = linenum + 1 +<<<<<<< HEAD if VERBOSE: print "Generated '%s/z3enums.mli'" % ('%s' % gendir) +======= + efile.write('\n') + # efile.write'end\n'); + if VERBOSE: + print "Generated '%s/z3_enums.ml'" % ('%s' % gendir) +>>>>>>> More new ML API def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index 945496781..c1bb22a44 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -157,9 +157,9 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I BOOL : 'jboolean', SYMBOL : 'jlong', PRINT_MODE : 'jint', ERROR_CODE : 'jint'} # Mapping to ML types -Type2ML = { VOID : 'unit', VOID_PTR : 'VOIDP', INT : 'int', UINT : 'int', INT64 : 'int', UINT64 : 'int', DOUBLE : 'float', - STRING : 'string', STRING_PTR : 'char**', - BOOL : 'bool', SYMBOL : 'z3_symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } +Type2ML = { VOID : 'unit', VOID_PTR : 'long', INT : 'int', UINT : 'int', INT64 : 'long', UINT64 : 'long', DOUBLE : 'double', + STRING : 'string', STRING_PTR : 'char**', + BOOL : 'lbool', SYMBOL : 'symbol', PRINT_MODE : 'ast_print_mode', ERROR_CODE : 'error_code' } next_type_id = FIRST_OBJ_ID @@ -1069,9 +1069,7 @@ def mk_bindings(): exe_c.write("}\n") def ml_method_name(name): - result = '' - name = name[3:] # Remove Z3_ - return result + return name[3:] # Remove Z3_ def mk_ml(): if not is_ml_enabled(): @@ -1080,10 +1078,57 @@ def mk_ml(): ml_nativef = os.path.join(ml_dir, 'z3_native.ml') ml_wrapperf = os.path.join(ml_dir, 'z3_native.c') ml_native = open(ml_nativef, 'w') - ml_native.write('// Automatically generated file\n') + ml_native.write('(* Automatically generated file *)\n') ml_native.write('\n') + ml_native.write('module Z3 = struct\n\n') + ml_native.write('type context\n') + ml_native.write('and symbol\n') + ml_native.write('and ast\n') + ml_native.write('and sort = private ast\n') + ml_native.write('and func_decl = private ast\n') + ml_native.write('and app = private ast\n') + ml_native.write('and pattern = private ast\n') + ml_native.write('and params\n') + ml_native.write('and param_descrs\n') + ml_native.write('and model\n') + ml_native.write('and func_interp\n') + ml_native.write('and func_entry\n') + ml_native.write('and fixedpoint\n') + ml_native.write('and ast_vector\n') + ml_native.write('and ast_map\n') + ml_native.write('and goal\n') + ml_native.write('and tactic\n') + ml_native.write('and probe\n') + ml_native.write('and apply_result\n') + ml_native.write('and solver\n') + ml_native.write('and stats\n') + ml_native.write('\n') + ml_native.write(' exception Z3Exception of string\n\n') for name, result, params in _dotnet_decls: - ml_native.write(' external %s : (' % ml_method_name(name)) + ml_native.write(' external native_%s : ' % ml_method_name(name)) + i = 0; + for param in params: + ml_native.write('%s -> ' % param2ml(param)) + i = i + 1 + ml_native.write('%s\n' % (type2ml(result))) + ml_native.write(' = "Native_Z3_%s"\n\n' % ml_method_name(name)) + # Exception wrappers + for name, result, params in _dotnet_decls: + ml_native.write(' let %s ' % ml_method_name(name)) + first = True + i = 0; + for param in params: + if first: + first = False; + else: + ml_native.write(' ') + ml_native.write('a%d' % i) + i = i + 1 + ml_native.write(' = \n') + ml_native.write(' ') + if result != VOID: + ml_native.write('let res = ') + ml_native.write('n_%s(' % (ml_method_name(name))) first = True i = 0; for param in params: @@ -1091,50 +1136,24 @@ def mk_ml(): first = False else: ml_native.write(', ') - ml_native.write('%s a%d' % (param2ml(param), i)) + ml_native.write('a%d' % i) i = i + 1 - ml_native.write('%s)\n' % (type2ml(result))) - # ml_native.write(' = "NATIVE_%s"' % ml_method_name(name)) - # ml_native.write('\n\n') - # # Exception wrappers - # for name, result, params in _dotnet_decls: - # java_native.write(' public static %s %s(' % (type2java(result), java_method_name(name))) - # first = True - # i = 0; - # for param in params: - # if first: - # first = False - # else: - # java_native.write(', ') - # java_native.write('%s a%d' % (param2java(param), i)) - # i = i + 1 - # java_native.write(')') - # if len(params) > 0 and param_type(params[0]) == CONTEXT: - # java_native.write(' throws Z3Exception') - # java_native.write('\n') - # java_native.write(' {\n') - # java_native.write(' ') - # if result != VOID: - # java_native.write('%s res = ' % type2java(result)) - # java_native.write('INTERNAL%s(' % (java_method_name(name))) - # first = True - # i = 0; - # for param in params: - # if first: - # first = False - # else: - # java_native.write(', ') - # java_native.write('a%d' % i) - # i = i + 1 - # java_native.write(');\n') - # if len(params) > 0 and param_type(params[0]) == CONTEXT: - # java_native.write(' Z3_error_code err = Z3_error_code.fromInt(INTERNALgetErrorCode(a0));\n') - # java_native.write(' if (err != Z3_error_code.Z3_OK)\n') - # java_native.write(' throw new Z3Exception(INTERNALgetErrorMsgEx(a0, err.toInt()));\n') - # if result != VOID: - # java_native.write(' return res;\n') - # java_native.write(' }\n\n') - # java_native.write('}\n') + ml_native.write(')') + if result != VOID: + ml_native.write(' in\n') + else: + ml_native.write(';\n') + if len(params) > 0 and param_type(params[0]) == CONTEXT: + ml_native.write(' let err = error_code.fromInt(n_get_error_code(a0)) in \n') + ml_native.write(' if err <> Z3_enums.OK then\n') + ml_native.write(' raise (z3_exception n_get_error_msg_ex(a0, err.toInt()))\n') + ml_native.write(' else\n') + if result == VOID: + ml_native.write(' ()\n') + else: + ml_native.write(' res\n') + ml_native.write('\n') + ml_native.write('\nend\n') ml_wrapper = open(ml_wrapperf, 'w') ml_wrapper.write('// Automatically generated file\n\n') ml_wrapper.write('#include \n') From a40433aae85d0b181c355c9861cf95b163c9d422 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 11 Dec 2012 16:35:39 +0000 Subject: [PATCH 125/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 3 + scripts/mk_util.py | 6 +- scripts/update_api.py | 211 +++++++++++++++++++++++------------------- src/api/ml/Makefile | 10 -- 4 files changed, 120 insertions(+), 110 deletions(-) delete mode 100644 src/api/ml/Makefile diff --git a/.gitignore b/.gitignore index 2ae719b85..a3fa5e919 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ src/util/version.h src/api/java/Native.cpp src/api/java/Native.java src/api/java/enumerations/*.java + *.bak doc/api doc/code @@ -76,4 +77,6 @@ src/api/ml/z3enums.ml src/api/ml/z3.mllib src/api/ml/z3_native.c src/api/ml/z3_native.ml +src/api/ml/native.c +src/api/ml/Z3.ml src/api/ml/z3_enums.ml diff --git a/scripts/mk_util.py b/scripts/mk_util.py index d019e24e9..d324e5206 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1430,9 +1430,9 @@ class MLComponent(Component): out.write('\n\n') mk_dir(os.path.join(BUILD_DIR, 'api', 'ml')) libfile = '%s$(LIB_EXT)' % self.lib_name - out.write('%s: libz3$(SO_EXT) %s\n' % (libfile, os.path.join(self.to_src_dir, 'z3_native.c'))) - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) %s/z3_native.c\n' % self.to_src_dir) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'z3_native')) + out.write('%s: libz3$(SO_EXT) %s\n' % (libfile, os.path.join(self.to_src_dir, 'native.c'))) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) -I%s %s/native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'native')) out.write('ml: %s\n' % libfile) out.write('\n') diff --git a/scripts/update_api.py b/scripts/update_api.py index c1bb22a44..72fd32702 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1075,12 +1075,12 @@ def mk_ml(): if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir - ml_nativef = os.path.join(ml_dir, 'z3_native.ml') - ml_wrapperf = os.path.join(ml_dir, 'z3_native.c') + ml_nativef = os.path.join(ml_dir, 'Z3.ml') + ml_wrapperf = os.path.join(ml_dir, 'native.c') ml_native = open(ml_nativef, 'w') ml_native.write('(* Automatically generated file *)\n') ml_native.write('\n') - ml_native.write('module Z3 = struct\n\n') + ml_native.write('module Z3Native = struct\n\n') ml_native.write('type context\n') ml_native.write('and symbol\n') ml_native.write('and ast\n') @@ -1166,101 +1166,118 @@ def mk_ml(): ml_wrapper.write('#ifdef Custom_tag\n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') - ml_wrapper.write('#endif\n') - # for name, result, params in _dotnet_decls: - # java_wrapper.write('JNIEXPORT %s JNICALL Java_%s_Native_INTERNAL%s(JNIEnv * jenv, jclass cls' % (type2javaw(result), pkg_str, java_method_name(name))) - # i = 0; - # for param in params: - # java_wrapper.write(', ') - # java_wrapper.write('%s a%d' % (param2javaw(param), i)) - # i = i + 1 - # java_wrapper.write(') {\n') - # # preprocess arrays, strings, in/out arguments - # i = 0 - # for param in params: - # k = param_kind(param) - # if k == OUT or k == INOUT: - # java_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) - # elif k == IN_ARRAY or k == INOUT_ARRAY: - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i)) - # else: - # java_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i)) - # elif k == OUT_ARRAY: - # java_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)), - # i, - # type2str(param_type(param)), - # param_array_capacity_pos(param), - # type2str(param_type(param)))) - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) - # else: - # java_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i)) - # elif k == IN and param_type(param) == STRING: - # java_wrapper.write(' Z3_string _a%s = (Z3_string) jenv->GetStringUTFChars(a%s, NULL);\n' % (i, i)) - # i = i + 1 - # # invoke procedure - # java_wrapper.write(' ') - # if result != VOID: - # java_wrapper.write('%s result = ' % type2str(result)) - # java_wrapper.write('%s(' % name) - # i = 0 - # first = True - # for param in params: - # if first: - # first = False - # else: - # java_wrapper.write(', ') - # k = param_kind(param) - # if k == OUT or k == INOUT: - # java_wrapper.write('&_a%s' % i) - # elif k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: - # java_wrapper.write('_a%s' % i) - # elif k == IN and param_type(param) == STRING: - # java_wrapper.write('_a%s' % i) - # else: - # java_wrapper.write('(%s)a%i' % (param2str(param), i)) - # i = i + 1 - # java_wrapper.write(');\n') - # # cleanup - # i = 0 - # for param in params: - # k = param_kind(param) - # if k == OUT_ARRAY: - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) - # else: - # java_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i)) - # java_wrapper.write(' free(_a%s);\n' % i) - # elif k == IN_ARRAY or k == OUT_ARRAY: - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i)) - # else: - # java_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i)) + ml_wrapper.write('#endif\n\n') + ml_wrapper.write('#include \n\n') + for name, result, params in _dotnet_decls: + #return type = type2ml(result) + ml_wrapper.write('CAMLprim value n_%s(' % ml_method_name(name)) + first = True + i = 0 + for param in params: + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('value a%d' % i) + # param type = param2ml(param) + i = i + 1 + ml_wrapper.write(') {\n') + ml_wrapper.write(' CAMLparam%d(' % len(params)) + i = 0 + first = True + for param in params: + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('a%d' % i) + i = i + 1 + ml_wrapper.write(');\n') + # preprocess arrays, strings, in/out arguments + i = 0 + for param in params: + k = param_kind(param) + if k == OUT or k == INOUT: + ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) + elif k == IN_ARRAY or k == INOUT_ARRAY: + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i)) + else: + ml_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i)) + elif k == OUT_ARRAY: + ml_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)), + i, + type2str(param_type(param)), + param_array_capacity_pos(param), + type2str(param_type(param)))) + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) + else: + ml_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i)) + elif k == IN and param_type(param) == STRING: + ml_wrapper.write(' Z3_string _a%s = (Z3_string) String_val(a%s);\n' % (i, i)) + i = i + 1 + # invoke procedure + ml_wrapper.write(' ') + if result != VOID: + ml_wrapper.write('%s result = ' % type2str(result)) + ml_wrapper.write('%s(' % name) + i = 0 + first = True + for param in params: + if first: + first = False + else: + ml_wrapper.write(', ') + k = param_kind(param) + if k == OUT or k == INOUT: + ml_wrapper.write('&_a%s' % i) + elif k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: + ml_wrapper.write('_a%s' % i) + elif k == IN and param_type(param) == STRING: + ml_wrapper.write('_a%s' % i) + else: + ml_wrapper.write('(%s)a%i' % (param2str(param), i)) + i = i + 1 + ml_wrapper.write(');\n') + # cleanup + i = 0 + for param in params: + k = param_kind(param) + if k == OUT_ARRAY: + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) + else: + ml_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i)) + ml_wrapper.write(' free(_a%s);\n' % i) + elif k == IN_ARRAY or k == OUT_ARRAY: + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i)) + else: + ml_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i)) - # elif k == OUT or k == INOUT: - # if param_type(param) == INT or param_type(param) == UINT: - # java_wrapper.write(' {\n') - # java_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) - # java_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "I");\n') - # java_wrapper.write(' jenv->SetIntField(a%s, fid, (jint) _a%s);\n' % (i, i)) - # java_wrapper.write(' }\n') - # else: - # java_wrapper.write(' {\n') - # java_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) - # java_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "J");\n') - # java_wrapper.write(' jenv->SetLongField(a%s, fid, (jlong) _a%s);\n' % (i, i)) - # java_wrapper.write(' }\n') - # i = i + 1 - # # return - # if result == STRING: - # java_wrapper.write(' return jenv->NewStringUTF(result);\n') - # elif result != VOID: - # java_wrapper.write(' return (%s) result;\n' % type2javaw(result)) - # java_wrapper.write('}\n') - # java_wrapper.write('#ifdef __cplusplus\n') - # java_wrapper.write('}\n') - # java_wrapper.write('#endif\n') + elif k == OUT or k == INOUT: + if param_type(param) == INT or param_type(param) == UINT: + ml_wrapper.write(' {\n') + ml_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) + ml_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "I");\n') + ml_wrapper.write(' jenv->SetIntField(a%s, fid, (jint) _a%s);\n' % (i, i)) + ml_wrapper.write(' }\n') + else: + ml_wrapper.write(' {\n') + ml_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) + ml_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "J");\n') + ml_wrapper.write(' jenv->SetLongField(a%s, fid, (jlong) _a%s);\n' % (i, i)) + ml_wrapper.write(' }\n') + i = i + 1 + # return + if result == STRING: + ml_wrapper.write(' return caml_copy_string(result);\n') + elif result == VOID: + ml_wrapper.write(' CAMLreturn(Val_unit);\n') + elif result != VOID: + ml_wrapper.write(' return (value) result;\n') + ml_wrapper.write('}\n\n') if is_verbose(): print "Generated '%s'" % ml_nativef diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile deleted file mode 100644 index 96fd0a55d..000000000 --- a/src/api/ml/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# This is a temporary support file for emacs annotations. -# It does not compile the Z3 ML API; this will be built -# in the top-level build directory. - -all: - ocamlbuild -cflag -annot z3.cmxa - -doc: *.ml - mkdir -p doc - ocamldoc -html -d doc -I _build -sort *.mli -hide Z3 From dcd6f1f69736ace570ead5e544b670dfa0a1b42c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 11 Dec 2012 21:39:52 +0000 Subject: [PATCH 126/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 4 +-- scripts/mk_util.py | 44 ++++++++++++++++++++++++++++++--- scripts/update_api.py | 57 ++++++++++++++++++++++++------------------- 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index a3fa5e919..a1a8b7f6b 100644 --- a/.gitignore +++ b/.gitignore @@ -78,5 +78,5 @@ src/api/ml/z3.mllib src/api/ml/z3_native.c src/api/ml/z3_native.ml src/api/ml/native.c -src/api/ml/Z3.ml -src/api/ml/z3_enums.ml +src/api/ml/z3.ml +src/api/ml/enumerations.ml diff --git a/scripts/mk_util.py b/scripts/mk_util.py index d324e5206..bd6495d1b 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1428,9 +1428,17 @@ class MLComponent(Component): if IS_WINDOWS: out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(LIB_EXT)') out.write('\n\n') - mk_dir(os.path.join(BUILD_DIR, 'api', 'ml')) + bld_dir = os.path.join(BUILD_DIR, 'api', 'ml') + mk_dir(bld_dir) libfile = '%s$(LIB_EXT)' % self.lib_name - out.write('%s: libz3$(SO_EXT) %s\n' % (libfile, os.path.join(self.to_src_dir, 'native.c'))) + for mlfile in get_ml_files(self.src_dir): + out.write('%si: %s\n' % (os.path.join('api', 'ml', mlfile),os.path.join(self.to_src_dir, mlfile))) + out.write('\tocamlopt -I %s -i %s > %si\n' % (os.path.join('api', 'ml'), os.path.join(self.to_src_dir, mlfile), os.path.join('api', 'ml', mlfile))) + out.write('\tocamlopt -I %s -c %si \n' % (os.path.join('api', 'ml'), os.path.join('api','ml', mlfile))) + out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'native.c'))) + for mlfile in get_ml_files(self.src_dir): + out.write(' %si' % os.path.join('api','ml', mlfile)) + out.write('\n') out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) -I%s %s/native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'native')) out.write('ml: %s\n' % libfile) @@ -2720,6 +2728,7 @@ def mk_z3consts_ml(api_files): if not os.path.exists(gendir): os.mkdir(gendir) +<<<<<<< HEAD <<<<<<< HEAD efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') @@ -2809,6 +2818,11 @@ def mk_z3consts_ml(api_files): >>>>>>> More new ML API +======= + efile = open('%s.ml' % os.path.join(gendir, "enumerations"), 'w') + efile.write('(* Automatically generated file *)\n\n') + efile.write('module Enumerations = struct\n') +>>>>>>> More ML API for api_file in api_files: api_file_c = ml.find_file(api_file, ml.name) api_file = os.path.join(api_file_c.src_dir, api_file) @@ -2854,6 +2868,7 @@ def mk_z3consts_ml(api_files): if m: name = words[1] if name not in DeprecatedEnums: +<<<<<<< HEAD <<<<<<< HEAD efile.write('(** %s *)\n' % name[3:]) efile.write('type %s =\n' % name[3:]) # strip Z3_ @@ -2867,11 +2882,28 @@ def mk_z3consts_ml(api_files): efile.write('\n') ======= efile.write('\n(* %s *)\n' % name) +======= +>>>>>>> More ML API efile.write('type %s =\n' % name[3:]) # strip Z3_ - efile.write for k, i in decls.iteritems(): +<<<<<<< HEAD efile.write(' | %s \n' % k[3:]) # strip Z3_ >>>>>>> More new ML API +======= + efile.write(' | %s \n' % k[3:]) # strip Z3_ + efile.write('\n') + efile.write('let %s2int x : int =\n' % (name[3:])) # strip Z3_ + efile.write(' match x with\n') + for k, i in decls.iteritems(): + efile.write(' | %s -> %d\n' % (k[3:], i)) + efile.write('\n') + efile.write('let int2%s x : %s =\n' % (name[3:],name[3:])) # strip Z3_ + efile.write(' match x with\n') + for k, i in decls.iteritems(): + efile.write(' | %d -> %s\n' % (i, k[3:])) + # use Z3.Exception? + efile.write(' | _ -> raise (Failure "undefined enum value")\n\n') +>>>>>>> More ML API mode = SEARCHING else: if words[2] != '': @@ -2882,6 +2914,7 @@ def mk_z3consts_ml(api_files): decls[words[1]] = idx idx = idx + 1 linenum = linenum + 1 +<<<<<<< HEAD <<<<<<< HEAD if VERBOSE: print "Generated '%s/z3enums.mli'" % ('%s' % gendir) @@ -2891,6 +2924,11 @@ def mk_z3consts_ml(api_files): if VERBOSE: print "Generated '%s/z3_enums.ml'" % ('%s' % gendir) >>>>>>> More new ML API +======= + efile.write('end\n') + if VERBOSE: + print "Generated '%s/enumerations.ml'" % ('%s' % gendir) +>>>>>>> More ML API def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index 72fd32702..971e6eab1 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -157,9 +157,9 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I BOOL : 'jboolean', SYMBOL : 'jlong', PRINT_MODE : 'jint', ERROR_CODE : 'jint'} # Mapping to ML types -Type2ML = { VOID : 'unit', VOID_PTR : 'long', INT : 'int', UINT : 'int', INT64 : 'long', UINT64 : 'long', DOUBLE : 'double', - STRING : 'string', STRING_PTR : 'char**', - BOOL : 'lbool', SYMBOL : 'symbol', PRINT_MODE : 'ast_print_mode', ERROR_CODE : 'error_code' } +Type2ML = { VOID : 'unit', VOID_PTR : 'VOIDP', INT : 'int', UINT : 'int', INT64 : 'int', UINT64 : 'int', DOUBLE : 'float', + STRING : 'string', STRING_PTR : 'char**', + BOOL : 'int', SYMBOL : 'symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } next_type_id = FIRST_OBJ_ID @@ -214,7 +214,7 @@ def type2javaw(ty): def type2ml(ty): global Type2ML if (ty >= FIRST_OBJ_ID): - return 'long' + return 'int' else: return Type2ML[ty] @@ -331,6 +331,8 @@ def param2ml(p): if k == OUT: if param_type(p) == INT or param_type(p) == UINT or param_type(p) == INT64 or param_type(p) == UINT64: return "int" + elif param_type(p) == INT64 or param_type(p) == UINT64 or param_type(p) >= FIRST_OBJ_ID: + return "int" elif param_type(p) == STRING: return "string" else: @@ -1075,12 +1077,12 @@ def mk_ml(): if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir - ml_nativef = os.path.join(ml_dir, 'Z3.ml') + ml_nativef = os.path.join(ml_dir, 'z3.ml') ml_wrapperf = os.path.join(ml_dir, 'native.c') ml_native = open(ml_nativef, 'w') - ml_native.write('(* Automatically generated file *)\n') - ml_native.write('\n') - ml_native.write('module Z3Native = struct\n\n') + ml_native.write('(* Automatically generated file *)\n\n') + ml_native.write('open Enumerations\n\n') + ml_native.write('module Z3 = struct\n\n') ml_native.write('type context\n') ml_native.write('and symbol\n') ml_native.write('and ast\n') @@ -1103,15 +1105,17 @@ def mk_ml(): ml_native.write('and solver\n') ml_native.write('and stats\n') ml_native.write('\n') - ml_native.write(' exception Z3Exception of string\n\n') + ml_native.write(' exception Exception of string\n\n') for name, result, params in _dotnet_decls: - ml_native.write(' external native_%s : ' % ml_method_name(name)) + ml_native.write(' external n_%s : ' % ml_method_name(name)) i = 0; for param in params: ml_native.write('%s -> ' % param2ml(param)) i = i + 1 + if len(params) == 0: + ml_native.write(' unit -> ') ml_native.write('%s\n' % (type2ml(result))) - ml_native.write(' = "Native_Z3_%s"\n\n' % ml_method_name(name)) + ml_native.write(' = "n_%s"\n\n' % ml_method_name(name)) # Exception wrappers for name, result, params in _dotnet_decls: ml_native.write(' let %s ' % ml_method_name(name)) @@ -1128,25 +1132,28 @@ def mk_ml(): ml_native.write(' ') if result != VOID: ml_native.write('let res = ') - ml_native.write('n_%s(' % (ml_method_name(name))) - first = True - i = 0; - for param in params: - if first: - first = False - else: - ml_native.write(', ') - ml_native.write('a%d' % i) - i = i + 1 - ml_native.write(')') + if len(params) == 0: + ml_native.write('n_%s()' % (ml_method_name(name))) + else: + ml_native.write('(n_%s ' % (ml_method_name(name))) + first = True + i = 0; + for param in params: + if first: + first = False + else: + ml_native.write(' ') + ml_native.write('a%d' % i) + i = i + 1 + ml_native.write(')') if result != VOID: ml_native.write(' in\n') else: ml_native.write(';\n') if len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = error_code.fromInt(n_get_error_code(a0)) in \n') - ml_native.write(' if err <> Z3_enums.OK then\n') - ml_native.write(' raise (z3_exception n_get_error_msg_ex(a0, err.toInt()))\n') + ml_native.write(' let err = (Enumerations.int2error_code (n_get_error_code a0)) in \n') + ml_native.write(' if err <> Enumerations.OK then\n') + ml_native.write(' raise (Exception (n_get_error_msg_ex a0 (error_code2int err)))\n') ml_native.write(' else\n') if result == VOID: ml_native.write(' ()\n') From c4f07c7fd179313ff57b73b7336e64bc39854aa3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 04:34:36 +0000 Subject: [PATCH 127/248] New native ML API layer. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 36 ++-- scripts/update_api.py | 400 +++++++++++++++++++++++++++--------------- 2 files changed, 289 insertions(+), 147 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index bd6495d1b..33129f555 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1428,20 +1428,30 @@ class MLComponent(Component): if IS_WINDOWS: out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(LIB_EXT)') out.write('\n\n') + deffile = open('%s.mllib' % os.path.join(self.src_dir, "z3"), 'w') + for mlfile in get_ml_files(self.src_dir): + deffile.write('%s\n' % (string.upper(mlfile[0]) + mlfile[1:-3])) + deffile.close() bld_dir = os.path.join(BUILD_DIR, 'api', 'ml') mk_dir(bld_dir) - libfile = '%s$(LIB_EXT)' % self.lib_name + libfile = '%s$(SO_EXT)' % self.lib_name + # for mlfile in get_ml_files(self.src_dir): + # out.write('%si: libz3$(SO_EXT) %s\n' % (os.path.join('api', 'ml', mlfile),os.path.join(self.to_src_dir, mlfile))) + # out.write('\tocamlopt -I %s -i %s > %si\n' % (os.path.join('api', 'ml'), os.path.join(self.to_src_dir, mlfile), os.path.join('api', 'ml', mlfile))) + # out.write('\tocamlopt -I %s -c %si \n' % (os.path.join('api', 'ml'), os.path.join('api','ml', mlfile))) + out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'z3native.c'))) for mlfile in get_ml_files(self.src_dir): - out.write('%si: %s\n' % (os.path.join('api', 'ml', mlfile),os.path.join(self.to_src_dir, mlfile))) - out.write('\tocamlopt -I %s -i %s > %si\n' % (os.path.join('api', 'ml'), os.path.join(self.to_src_dir, mlfile), os.path.join('api', 'ml', mlfile))) - out.write('\tocamlopt -I %s -c %si \n' % (os.path.join('api', 'ml'), os.path.join('api','ml', mlfile))) - out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'native.c'))) - for mlfile in get_ml_files(self.src_dir): - out.write(' %si' % os.path.join('api','ml', mlfile)) + out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3_native$(OBJ_EXT) -I%s %s/native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3ml$(LIB_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % os.path.join('api', 'ml', 'native')) - out.write('ml: %s\n' % libfile) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) + out.write('z3.cmxa: %s\n' % libfile) + out.write('\tcd %s && ocamlbuild -lflags -cclib,../../../%s/libz3ml.so,-cclib,../../../%s/libz3.so -build-dir ../../../%s/api/ml z3.cmxa && cd -\n' % (self.to_src_dir,BUILD_DIR,BUILD_DIR,BUILD_DIR)) + out.write('\tcp api/ml/z3.cmxa .\n') + out.write('z3.cma: %s\n' % libfile) + out.write('\tcd %s && ocamlbuild -lflags -custom,-cclib,../../../%s/libz3ml.so,-cclib,../../../%s/libz3.so -build-dir ../../../%s/api/ml z3.cma && cd -\n' % (self.to_src_dir,BUILD_DIR,BUILD_DIR,BUILD_DIR)) + out.write('\tcp api/ml/z3.cma .\n') + out.write('ml: z3.cmxa z3.cma\n') out.write('\n') def main_component(self): @@ -2728,6 +2738,7 @@ def mk_z3consts_ml(api_files): if not os.path.exists(gendir): os.mkdir(gendir) +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') @@ -2823,6 +2834,11 @@ def mk_z3consts_ml(api_files): efile.write('(* Automatically generated file *)\n\n') efile.write('module Enumerations = struct\n') >>>>>>> More ML API +======= + efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') + efile.write('(* Automatically generated file *)\n\n') + efile.write('module Z3enums = struct\n') +>>>>>>> New native ML API layer. for api_file in api_files: api_file_c = ml.find_file(api_file, ml.name) api_file = os.path.join(api_file_c.src_dir, api_file) diff --git a/scripts/update_api.py b/scripts/update_api.py index 971e6eab1..f142c8ec1 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1073,98 +1073,145 @@ def mk_bindings(): def ml_method_name(name): return name[3:] # Remove Z3_ +def is_out_param(p): + if param_kind(p) == OUT or param_kind(p) == INOUT or param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: + return True + else: + return False + +def outparams(params): + op = [] + for param in params: + if is_out_param(param): + op.append(param) + return op + +def is_in_param(p): + if param_kind(p) == IN or param_kind(p) == INOUT or param_kind(p) == IN_ARRAY or param_kind(p) == INOUT_ARRAY: + return True + else: + return False + +def inparams(params): + ip = [] + for param in params: + if is_in_param(param): + ip.append(param) + return ip + +def is_array_param(p): + if param_kind(p) == IN_ARRAY or param_kind(p) == INOUT_ARRAY or param_kind(p) == OUT_ARRAY: + return True + else: + return False + def mk_ml(): if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir - ml_nativef = os.path.join(ml_dir, 'z3.ml') - ml_wrapperf = os.path.join(ml_dir, 'native.c') + ml_nativef = os.path.join(ml_dir, 'z3native.ml') + ml_wrapperf = os.path.join(ml_dir, 'z3native.c') ml_native = open(ml_nativef, 'w') ml_native.write('(* Automatically generated file *)\n\n') - ml_native.write('open Enumerations\n\n') - ml_native.write('module Z3 = struct\n\n') - ml_native.write('type context\n') - ml_native.write('and symbol\n') - ml_native.write('and ast\n') - ml_native.write('and sort = private ast\n') - ml_native.write('and func_decl = private ast\n') - ml_native.write('and app = private ast\n') - ml_native.write('and pattern = private ast\n') - ml_native.write('and params\n') - ml_native.write('and param_descrs\n') - ml_native.write('and model\n') - ml_native.write('and func_interp\n') - ml_native.write('and func_entry\n') - ml_native.write('and fixedpoint\n') - ml_native.write('and ast_vector\n') - ml_native.write('and ast_map\n') - ml_native.write('and goal\n') - ml_native.write('and tactic\n') - ml_native.write('and probe\n') - ml_native.write('and apply_result\n') - ml_native.write('and solver\n') - ml_native.write('and stats\n') - ml_native.write('\n') + ml_native.write('open Z3enums\n\n') + ml_native.write('module Z3native = struct\n\n') + ml_native.write(' type context\n') + ml_native.write(' and symbol\n') + ml_native.write(' and ast\n') + ml_native.write(' and sort = private ast\n') + ml_native.write(' and func_decl = private ast\n') + ml_native.write(' and app = private ast\n') + ml_native.write(' and pattern = private ast\n') + ml_native.write(' and params\n') + ml_native.write(' and param_descrs\n') + ml_native.write(' and model\n') + ml_native.write(' and func_interp\n') + ml_native.write(' and func_entry\n') + ml_native.write(' and fixedpoint\n') + ml_native.write(' and ast_vector\n') + ml_native.write(' and ast_map\n') + ml_native.write(' and goal\n') + ml_native.write(' and tactic\n') + ml_native.write(' and probe\n') + ml_native.write(' and apply_result\n') + ml_native.write(' and solver\n') + ml_native.write(' and stats\n\n') ml_native.write(' exception Exception of string\n\n') + + # ML declarations + ml_native.write(' module ML2C = struct\n\n') for name, result, params in _dotnet_decls: - ml_native.write(' external n_%s : ' % ml_method_name(name)) - i = 0; - for param in params: - ml_native.write('%s -> ' % param2ml(param)) - i = i + 1 - if len(params) == 0: + ml_native.write(' external n_%s : ' % ml_method_name(name)) + ip = inparams(params) + op = outparams(params) + if len(ip) == 0: ml_native.write(' unit -> ') - ml_native.write('%s\n' % (type2ml(result))) - ml_native.write(' = "n_%s"\n\n' % ml_method_name(name)) + for p in ip: + ml_native.write('%s -> ' % param2ml(p)) + if len(op) > 0: + ml_native.write('(') + ml_native.write('%s' % type2ml(result)) + for p in op: + ml_native.write(' * %s' % param2ml(p)) + if len(op) > 0: + ml_native.write(')') + ml_native.write('\n') + ml_native.write(' = "n_%s"\n' % ml_method_name(name)) + if len(ip) > 5: + ml_native.write(' "n_%s_bytecode"\n' % ml_method_name(name)) + ml_native.write('\n') + ml_native.write(' end\n\n') + # Exception wrappers for name, result, params in _dotnet_decls: - ml_native.write(' let %s ' % ml_method_name(name)) + ip = inparams(params) + op = outparams(params) + ml_native.write(' let %s ' % ml_method_name(name)) first = True i = 0; - for param in params: - if first: - first = False; - else: - ml_native.write(' ') - ml_native.write('a%d' % i) - i = i + 1 - ml_native.write(' = \n') - ml_native.write(' ') - if result != VOID: - ml_native.write('let res = ') - if len(params) == 0: - ml_native.write('n_%s()' % (ml_method_name(name))) - else: - ml_native.write('(n_%s ' % (ml_method_name(name))) - first = True - i = 0; - for param in params: + for p in params: + if is_in_param(p): if first: - first = False + first = False; else: ml_native.write(' ') ml_native.write('a%d' % i) - i = i + 1 - ml_native.write(')') - if result != VOID: - ml_native.write(' in\n') + i = i + 1 + ml_native.write(' = \n') + ml_native.write(' ') + if result == VOID: + ml_native.write('let _ = ') else: - ml_native.write(';\n') + ml_native.write('let res = ') + ml_native.write('(ML2C.n_%s' % (ml_method_name(name))) + first = True + i = 0; + for p in params: + if is_in_param(p): + ml_native.write(' a%d' % i) + i = i + 1 + ml_native.write(') in\n') if len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = (Enumerations.int2error_code (n_get_error_code a0)) in \n') - ml_native.write(' if err <> Enumerations.OK then\n') - ml_native.write(' raise (Exception (n_get_error_msg_ex a0 (error_code2int err)))\n') + ml_native.write(' let err = (Z3enums.int2error_code (ML2C.n_get_error_code a0)) in \n') + ml_native.write(' if err <> Z3enums.OK then\n') + ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (Z3enums.error_code2int err)))\n') ml_native.write(' else\n') if result == VOID: ml_native.write(' ()\n') else: ml_native.write(' res\n') ml_native.write('\n') - ml_native.write('\nend\n') + + ml_native.write('end\n') + + # C interface ml_wrapper = open(ml_wrapperf, 'w') ml_wrapper.write('// Automatically generated file\n\n') ml_wrapper.write('#include \n') - ml_wrapper.write('#include \n') + ml_wrapper.write('#include \n\n') + ml_wrapper.write('#ifdef __cplusplus\n') + ml_wrapper.write('extern "C" {\n') + ml_wrapper.write('#endif\n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') @@ -1173,61 +1220,119 @@ def mk_ml(): ml_wrapper.write('#ifdef Custom_tag\n') ml_wrapper.write('#include \n') ml_wrapper.write('#include \n') + ml_wrapper.write('#endif\n') + ml_wrapper.write('#ifdef __cplusplus\n') + ml_wrapper.write('}\n') ml_wrapper.write('#endif\n\n') ml_wrapper.write('#include \n\n') + ml_wrapper.write('#define CAMLlocal6(X1,X2,X3,X4,X5,X6) \\\n') + ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLlocal1(X6); \n') + ml_wrapper.write('#define CAMLlocal7(X1,X2,X3,X4,X5,X6,X7) \\\n') + ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLlocal2(X6,X7); \n') + ml_wrapper.write('#define CAMLlocal8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') + ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLlocal3(X6,X7,X8); \n') + ml_wrapper.write('\n') + ml_wrapper.write('#define CAMLparam7(X1,X2,X3,X4,X5,X6,X7) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam2(X6,X7); \n') + ml_wrapper.write('#define CAMLparam8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam3(X6,X7,X8); \n') + ml_wrapper.write('#define CAMLparam9(X1,X2,X3,X4,X5,X6,X7,X8,X9) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam4(X6,X7,X8,X9); \n') + ml_wrapper.write('#define CAMLparam12(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') + ml_wrapper.write(' CAMLxparam2(X11,X12); \n') + ml_wrapper.write('#define CAMLparam13(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13) \\\n') + ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') + ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') + ml_wrapper.write(' CAMLxparam3(X11,X12,X13); \n') + ml_wrapper.write('\n\n') + ml_wrapper.write('#ifdef __cplusplus\n') + ml_wrapper.write('extern "C" {\n') + ml_wrapper.write('#endif\n\n') for name, result, params in _dotnet_decls: - #return type = type2ml(result) + ip = inparams(params) + op = outparams(params) + ret_size = len(op) + if result != VOID: + ret_size = ret_size + 1 + + # Setup frame + n_locals = 0 + for p in params: + if is_out_param(p) or (is_in_param(p) and param_type(p) == STRING): + n_locals = n_locals + 1 ml_wrapper.write('CAMLprim value n_%s(' % ml_method_name(name)) first = True i = 0 - for param in params: - if first: - first = False - else: - ml_wrapper.write(', ') - ml_wrapper.write('value a%d' % i) - # param type = param2ml(param) + for p in params: + if is_in_param(p): + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('value a%d' % i) i = i + 1 ml_wrapper.write(') {\n') - ml_wrapper.write(' CAMLparam%d(' % len(params)) + ml_wrapper.write(' CAMLparam%d(' % len(ip)) i = 0 first = True - for param in params: - if first: - first = False - else: - ml_wrapper.write(', ') - ml_wrapper.write('a%d' % i) + for p in params: + if is_in_param(p): + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('a%d' % i) i = i + 1 ml_wrapper.write(');\n') + i = 0 + first = True + if result != VOID: + n_locals = n_locals + 1 + if ret_size > 1: + n_locals = n_locals + 1 + if n_locals > 0: + ml_wrapper.write(' CAMLlocal%s(' % (n_locals)) + if ret_size > 1: + if result != VOID: + ml_wrapper.write('result, ') + ml_wrapper.write('result_tuple') + first = False + elif result != VOID: + ml_wrapper.write('result') + first = False + for p in params: + if is_out_param(p) or (is_in_param(p) and param_type(p) == STRING): + if first: + first = False + else: + ml_wrapper.write(', ') + ml_wrapper.write('_a%s' % i) + i = i + 1 + ml_wrapper.write(');\n') + # preprocess arrays, strings, in/out arguments i = 0 for param in params: - k = param_kind(param) - if k == OUT or k == INOUT: - ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) - elif k == IN_ARRAY or k == INOUT_ARRAY: - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' %s * _a%s = (%s*) jenv->GetIntArrayElements(a%s, NULL);\n' % (type2str(param_type(param)), i, type2str(param_type(param)), i)) - else: - ml_wrapper.write(' GETLONGAELEMS(%s, a%s, _a%s);\n' % (type2str(param_type(param)), i, i)) - elif k == OUT_ARRAY: - ml_wrapper.write(' %s * _a%s = (%s *) malloc(((unsigned)a%s) * sizeof(%s));\n' % (type2str(param_type(param)), - i, - type2str(param_type(param)), - param_array_capacity_pos(param), - type2str(param_type(param)))) - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' jenv->GetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) - else: - ml_wrapper.write(' GETLONGAREGION(%s, a%s, 0, a%s, _a%s);\n' % (type2str(param_type(param)), i, param_array_capacity_pos(param), i)) - elif k == IN and param_type(param) == STRING: - ml_wrapper.write(' Z3_string _a%s = (Z3_string) String_val(a%s);\n' % (i, i)) + if param_kind(param) == OUT_ARRAY: + ml_wrapper.write(' _a%s = (long) malloc(sizeof(%s) * ((long)a%s));\n' % (i, + type2str(param_type(param)), + param_array_capacity_pos(param))) + elif param_kind(param) == IN and param_type(param) == STRING: + ml_wrapper.write(' _a%s = (value) String_val(a%s);\n' % (i, i)) i = i + 1 + # invoke procedure ml_wrapper.write(' ') if result != VOID: - ml_wrapper.write('%s result = ' % type2str(result)) + ml_wrapper.write('result = (value) ') ml_wrapper.write('%s(' % name) i = 0 first = True @@ -1238,53 +1343,74 @@ def mk_ml(): ml_wrapper.write(', ') k = param_kind(param) if k == OUT or k == INOUT: - ml_wrapper.write('&_a%s' % i) - elif k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: - ml_wrapper.write('_a%s' % i) + ml_wrapper.write('(%s)&_a%s' % (param2str(param), i)) + elif k == INOUT_ARRAY or k == IN_ARRAY: + ml_wrapper.write('(%s*)a%s' % (type2str(param_type(param)), i)) + elif k == OUT_ARRAY: + ml_wrapper.write('(%s*)_a%s' % (type2str(param_type(param)), i)) elif k == IN and param_type(param) == STRING: - ml_wrapper.write('_a%s' % i) + ml_wrapper.write('(Z3_string) _a%s' % i) else: ml_wrapper.write('(%s)a%i' % (param2str(param), i)) i = i + 1 ml_wrapper.write(');\n') - # cleanup - i = 0 - for param in params: - k = param_kind(param) - if k == OUT_ARRAY: - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' jenv->SetIntArrayRegion(a%s, 0, (jsize)a%s, (jint*)_a%s);\n' % (i, param_array_capacity_pos(param), i)) - else: - ml_wrapper.write(' SETLONGAREGION(a%s, 0, a%s, _a%s);\n' % (i, param_array_capacity_pos(param), i)) - ml_wrapper.write(' free(_a%s);\n' % i) - elif k == IN_ARRAY or k == OUT_ARRAY: - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' jenv->ReleaseIntArrayElements(a%s, (jint*)_a%s, JNI_ABORT);\n' % (i, i)) - else: - ml_wrapper.write(' RELEASELONGAELEMS(a%s, _a%s);\n' % (i, i)) - elif k == OUT or k == INOUT: - if param_type(param) == INT or param_type(param) == UINT: - ml_wrapper.write(' {\n') - ml_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) - ml_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "I");\n') - ml_wrapper.write(' jenv->SetIntField(a%s, fid, (jint) _a%s);\n' % (i, i)) - ml_wrapper.write(' }\n') + # return tuples + if len(op) > 0: + ml_wrapper.write(' result_tuple = caml_alloc(%s, 0);\n' % ret_size) + i = j = 0 + if result != VOID: + if result == STRING: + ml_wrapper.write(' Store_field(result_tuple, 0, caml_copy_string(result));\n') else: - ml_wrapper.write(' {\n') - ml_wrapper.write(' jclass mc = jenv->GetObjectClass(a%s);\n' % i) - ml_wrapper.write(' jfieldID fid = jenv->GetFieldID(mc, "value", "J");\n') - ml_wrapper.write(' jenv->SetLongField(a%s, fid, (jlong) _a%s);\n' % (i, i)) - ml_wrapper.write(' }\n') + ml_wrapper.write(' Store_field(result_tuple, 0, result);\n') + j = j + 1 + for p in params: + if param_kind(p) == OUT_ARRAY or param_kind(p) == OUT: + ml_wrapper.write(' Store_field(result_tuple, %s, _a%s);\n' % (j, i)) + j = j + 1; + elif is_out_param(p): + if param_type(p) == STRING: + ml_wrapper.write(' Store_field(result_tuple, %s, caml_copy_string((const char *)_a%s));\n' % (j, i)) + else: + ml_wrapper.write(' Store_field(result_tuple, %s, a%s);\n' % (j, i)) + j = j + 1; + i = i + 1 + + # local array cleanup + i = 0 + for p in params: + if param_kind(p) == OUT_ARRAY: + ml_wrapper.write(' free((long*)_a%s);\n' % i) i = i + 1 + # return - if result == STRING: - ml_wrapper.write(' return caml_copy_string(result);\n') - elif result == VOID: - ml_wrapper.write(' CAMLreturn(Val_unit);\n') - elif result != VOID: - ml_wrapper.write(' return (value) result;\n') + if len(op) > 0: + ml_wrapper.write(' CAMLreturn(result_tuple);\n') + else: + if result == STRING: + ml_wrapper.write(' CAMLreturn(caml_copy_string((const char*) result));\n') + elif result == VOID: + ml_wrapper.write(' CAMLreturn(Val_unit);\n') + elif result != VOID: + ml_wrapper.write(' CAMLreturn(result);\n') + ml_wrapper.write('}\n\n') + if len(ip) > 5: + ml_wrapper.write('CAMLprim value n_%s_bytecode(value * argv, int argn) {\n' % ml_method_name(name)) + ml_wrapper.write(' return n_%s(' % ml_method_name(name)) + i = 0 + while i < len(ip): + if i == 0: + ml_wrapper.write('argv[0]') + else: + ml_wrapper.write(', argv[%s]' % i) + i = i + 1 + ml_wrapper.write(');\n}\n') + ml_wrapper.write('\n\n') + ml_wrapper.write('#ifdef __cplusplus\n') + ml_wrapper.write('}\n') + ml_wrapper.write('#endif\n') if is_verbose(): print "Generated '%s'" % ml_nativef From 1ef9013c8ed4020847bdbccdf17828c3b4338d85 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 04:37:32 +0000 Subject: [PATCH 128/248] More new ML API. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2751 +--------------------------------------------- 1 file changed, 5 insertions(+), 2746 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 350457525..5251a8767 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,2752 +1,11 @@ -(** - The Z3 ML/OCaml Interface. - - Copyright (C) 2012 Microsoft Corporation - @author CM Wintersteiger (cwinter) 2012-12-17 +(* + Author: CM Wintersteiger + (C) Microsoft Research, 2012 *) open Z3enums +open Z3native -exception Error = Z3native.Exception - -(* Some helpers. *) -let null = Z3native.mk_null() -let is_null o = (Z3native.is_null o) - -(* Internal types *) -type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } -type context = z3_native_context - -type z3_native_object = { - m_ctx : context ; - mutable m_n_obj : Z3native.ptr ; - inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; - dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - -(** Internal stuff *) -module Internal = -struct - let dispose_context ctx = - if ctx.m_n_obj_cnt == 0 then ( - (Z3native.del_context ctx.m_n_ctx) - ) else ( - Printf.printf "ERROR: NOT DISPOSING CONTEXT (because it still has %d objects alive)\n" ctx.m_n_obj_cnt; - ) - - let create_context settings = - let cfg = Z3native.mk_config () in - let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in - (List.iter f settings) ; - let v = Z3native.mk_context_rc cfg in - Z3native.del_config(cfg) ; - Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; - Z3native.set_internal_error_handler v ; - let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in - let f = fun o -> dispose_context o in - Gc.finalise f res; - res - - let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) - let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) - let context_gno ctx = ctx.m_n_ctx - - - let z3obj_gc o = o.m_ctx - let z3obj_gnc o = (context_gno o.m_ctx) - - let z3obj_gno o = o.m_n_obj - let z3obj_sno o ctx no = - (context_add1 ctx) ; - o.inc_ref (context_gno ctx) no ; - ( - if not (is_null o.m_n_obj) then - o.dec_ref (context_gno ctx) o.m_n_obj ; - (context_sub1 ctx) - ) ; - o.m_n_obj <- no - - let z3obj_dispose o = - if not (is_null o.m_n_obj) then - ( - o.dec_ref (z3obj_gnc o) o.m_n_obj ; - (context_sub1 (z3obj_gc o)) - ) ; - o.m_n_obj <- null - - let z3obj_create o = - let f = fun o -> (z3obj_dispose o) in - Gc.finalise f o - - let z3obj_nil_ref x y = () - - let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> - let res : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res -end - -open Internal - -module Log = -struct - let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) - let close = Z3native.close_log - let append s = Z3native.append_log s -end - - -module Version = -struct - let major = let (x, _, _, _) = Z3native.get_version () in x - let minor = let (_, x, _, _) = Z3native.get_version () in x - let build = let (_, _, x, _) = Z3native.get_version () in x - let revision = let (_, _, _, x) = Z3native.get_version () in x - let to_string = - let (mj, mn, bld, rev) = Z3native.get_version () in - string_of_int mj ^ "." ^ - string_of_int mn ^ "." ^ - string_of_int bld ^ "." ^ - string_of_int rev -end - - -let mk_list ( f : int -> 'a ) ( n : int ) = - let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = - if (i >= n) then - tail - else - (f i) :: (mk_list' f (i+1) n tail) - in - mk_list' f 0 n [] - -let list_of_array ( x : _ array ) = - let f i = (Array.get x i) in - mk_list f (Array.length x) - -let mk_context ( cfg : ( string * string ) list ) = - create_context cfg - - -module Symbol = -struct - type symbol = z3_native_object - - let create_i ( ctx : context ) ( no : Z3native.ptr ) = - let res : symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let create_s ( ctx : context ) ( no : Z3native.ptr ) = - let res : symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let create ( ctx : context ) ( no : Z3native.ptr ) = - match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> (create_i ctx no) - | STRING_SYMBOL -> (create_s ctx no) - - let gc ( x : symbol ) = (z3obj_gc x) - let gnc ( x : symbol ) = (z3obj_gnc x) - let gno ( x : symbol ) = (z3obj_gno x) - - let symbol_lton ( a : symbol list ) = - let f ( e : symbol ) = (gno e) in - Array.of_list (List.map f a) - - let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) - let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL - let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL - let get_int (o : symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) - let get_string (o : symbol ) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) - let to_string ( o : symbol ) = - match (kind o) with - | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) - | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) - - let mk_int ( ctx : context ) ( i : int ) = - (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) - - let mk_string ( ctx : context ) ( s : string ) = - (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) - - let mk_ints ( ctx : context ) ( names : int list ) = - let f elem = mk_int ( ctx : context ) elem in - (List.map f names) - - let mk_strings ( ctx : context ) ( names : string list ) = - let f elem = mk_string ( ctx : context ) elem in - (List.map f names) -end - - -module AST = -struct - type ast = z3_native_object - - let context_of_ast ( x : ast ) = (z3obj_gc x) - let nc_of_ast ( x : ast ) = (z3obj_gnc x) - let ptr_of_ast ( x : ast ) = (z3obj_gno x) - - let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST - | SORT_AST - | QUANTIFIER_AST - | APP_AST - | NUMERAL_AST - | VAR_AST -> z3_native_object_of_ast_ptr ctx no - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") - - module ASTVector = - struct - type ast_vector = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : ast_vector = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.ast_vector_inc_ref ; - dec_ref = Z3native.ast_vector_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let mk_ast_vector ( ctx : context ) = (create ctx (Z3native.mk_ast_vector (context_gno ctx))) - - let get_size ( x : ast_vector ) = - Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) - - let get ( x : ast_vector ) ( i : int ) = - ast_of_ptr (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) - - let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) - - let resize ( x : ast_vector ) ( new_size : int ) = - Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size - - let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) - - let translate ( x : ast_vector ) ( to_ctx : context ) = - create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let to_string ( x : ast_vector ) = - Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) - end - - module ASTMap = - struct - type ast_map = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : ast_map = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.ast_map_inc_ref ; - dec_ref = Z3native.ast_map_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let mk_ast_map ( ctx : context ) = (create ctx (Z3native.mk_ast_map (context_gno ctx))) - - let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let res : ast_map = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.ast_map_inc_ref ; - dec_ref = Z3native.ast_map_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let contains ( x : ast_map ) ( key : ast ) = - Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - - let find ( x : ast_map ) ( key : ast ) = - ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) - - let insert ( x : ast_map ) ( key : ast ) ( value : ast ) = - Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) - - let erase ( x : ast_map ) ( key : ast ) = - Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - - let reset ( x : ast_map ) = - Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : ast_map ) = - Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) - - let get_keys ( x : ast_map ) = - let av = ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in - let f i = (ASTVector.get av i) in - mk_list f (ASTVector.get_size av) - - let to_string ( x : ast_map ) = - Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let hash ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) - let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) - let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) - - let is_expr ( x : ast ) = - match get_ast_kind ( x : ast ) with - | APP_AST - | NUMERAL_AST - | QUANTIFIER_AST - | VAR_AST -> true - | _ -> false - - let is_app ( x : ast ) = (get_ast_kind x) == APP_AST - let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST - let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST - let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST - let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST - - let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - - - let equal ( a : ast ) ( b : ast ) = (a == b) || - if (z3obj_gnc a) != (z3obj_gnc b) then - false - else - Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) - - let compare a b = - if (get_id a) < (get_id b) then -1 else - if (get_id a) > (get_id b) then 1 else - 0 - - let translate ( x : ast ) ( to_ctx : context ) = - if (z3obj_gnc x) == (context_gno to_ctx) then - x - else - ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let unwrap_ast ( x : ast ) = (z3obj_gno x) - let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr -end - -open AST - - -module Sort = -struct - type sort = Sort of AST.ast - - let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> - let q = (z3_native_object_of_ast_ptr ctx no) in - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then - raise (Z3native.Exception "Invalid coercion") - else - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with - | ARRAY_SORT - | BOOL_SORT - | BV_SORT - | DATATYPE_SORT - | INT_SORT - | REAL_SORT - | UNINTERPRETED_SORT - | FINITE_DOMAIN_SORT - | RELATION_SORT -> Sort(q) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - - let ast_of_sort s = match s with Sort(x) -> x - - let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) - let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) - let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) - - let sort_lton ( a : sort list ) = - let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in - Array.of_list (List.map f a) - - let sort_option_lton ( a : sort option list ) = - let f ( e : sort option ) = match e with None -> null | Some(Sort(a)) -> (AST.ptr_of_ast a) in - Array.of_list (List.map f a) - - let equal : sort -> sort -> bool = fun a b -> - (a == b) || - if (gnc a) != (gnc b) then - false - else - (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) - - - let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) - let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) - let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) - let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) - - let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; - (z3obj_create res) ; - Sort(res) - - let mk_uninterpreted_s ( ctx : context ) ( s : string ) = - mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) -end - -open Sort - - -module rec FuncDecl : -sig - type func_decl = FuncDecl of AST.ast - val ast_of_func_decl : FuncDecl.func_decl -> AST.ast - val func_decl_of_ptr : context -> Z3native.ptr -> func_decl - val gc : func_decl -> context - val gnc : func_decl -> Z3native.ptr - val gno : func_decl -> Z3native.ptr - module Parameter : - sig - type parameter = - P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - val get_kind : parameter -> Z3enums.parameter_kind - val get_int : parameter -> int - val get_float : parameter -> float - val get_symbol : parameter -> Symbol.symbol - val get_sort : parameter -> Sort.sort - val get_ast : parameter -> AST.ast - val get_func_decl : parameter -> func_decl - val get_rational : parameter -> string - end - val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl - val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl - val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl - val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl - val mk_const_decl_s : context -> string -> Sort.sort -> func_decl - val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl - val equal : func_decl -> func_decl -> bool - val to_string : func_decl -> string - val get_id : func_decl -> int - val get_arity : func_decl -> int - val get_domain_size : func_decl -> int - val get_domain : func_decl -> Sort.sort list - val get_range : func_decl -> Sort.sort - val get_decl_kind : func_decl -> Z3enums.decl_kind - val get_name : func_decl -> Symbol.symbol - val get_num_parameters : func_decl -> int - val get_parameters : func_decl -> Parameter.parameter list - val apply : func_decl -> Expr.expr list -> Expr.expr -end = struct - type func_decl = FuncDecl of AST.ast - - let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - FuncDecl(z3_native_object_of_ast_ptr ctx no) - - let ast_of_func_decl f = match f with FuncDecl(x) -> x - - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (List.length domain) (sort_lton domain) (Sort.gno range))) ; - (z3obj_create res) ; - FuncDecl(res) - - let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort list ) ( range : sort ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (List.length domain) (sort_lton domain) (Sort.gno range))) ; - (z3obj_create res) ; - FuncDecl(res) - - let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) - let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) - let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - - module Parameter = - struct - type parameter = - | P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - let get_kind ( x : parameter ) = - (match x with - | P_Int(_) -> PARAMETER_INT - | P_Dbl(_) -> PARAMETER_DOUBLE - | P_Sym(_) -> PARAMETER_SYMBOL - | P_Srt(_) -> PARAMETER_SORT - | P_Ast(_) -> PARAMETER_AST - | P_Fdl(_) -> PARAMETER_FUNC_DECL - | P_Rat(_) -> PARAMETER_RATIONAL) - - let get_int ( x : parameter ) = - match x with - | P_Int(x) -> x - | _ -> raise (Z3native.Exception "parameter is not an int") - - let get_float ( x : parameter ) = - match x with - | P_Dbl(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a float") - - let get_symbol ( x : parameter ) = - match x with - | P_Sym(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a symbol") - - let get_sort ( x : parameter ) = - match x with - | P_Srt(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a sort") - - let get_ast ( x : parameter ) = - match x with - | P_Ast(x) -> x - | _ -> raise (Z3native.Exception "parameter is not an ast") - - let get_func_decl ( x : parameter ) = - match x with - | P_Fdl(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a func_decl") - - let get_rational ( x : parameter ) = - match x with - | P_Rat(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a rational string") - end - - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = - create_ndr ctx name domain range - - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort list ) ( range : sort ) = - mk_func_decl ctx (Symbol.mk_string ctx name) domain range - - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort list ) ( range : sort ) = - create_pdr ctx prefix domain range - - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - create_ndr ctx name [] range - - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = - create_ndr ctx (Symbol.mk_string ctx name) [] range - - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = - create_pdr ctx prefix [] range - - - let equal ( a : func_decl ) ( b : func_decl ) = (a == b) || - if (gnc a) != (gnc b) then - false - else - (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) - - let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) - - let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) - - let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) - - let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) - - let get_domain ( x : func_decl ) = - let n = (get_domain_size x) in - let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in - mk_list f n - - let get_range ( x : func_decl ) = - sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) - - let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) - - let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) - - let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) - - let get_parameters ( x : func_decl ) = - let n = (get_num_parameters x) in - let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> Parameter.P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> Parameter.P_Ast (AST.ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) - ) in - mk_list f n - - let apply ( x : func_decl ) ( args : Expr.expr list ) = Expr.expr_of_func_app (gc x) x args -end - - -and Params : -sig - type params = z3_native_object - module ParamDescrs : - sig - type param_descrs - val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs - val validate : param_descrs -> params -> unit - val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind - val get_names : param_descrs -> Symbol.symbol list - val get_size : param_descrs -> int - val to_string : param_descrs -> string - end - val add_bool : params -> Symbol.symbol -> bool -> unit - val add_int : params -> Symbol.symbol -> int -> unit - val add_float : params -> Symbol.symbol -> float -> unit - val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - val mk_params : context -> params - val to_string : params -> string - - val update_param_value : context -> string -> string -> unit - val set_print_mode : context -> Z3enums.ast_print_mode -> unit -end = struct - type params = z3_native_object - - module ParamDescrs = - struct - type param_descrs = z3_native_object - - let param_descrs_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let res : param_descrs = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.param_descrs_inc_ref ; - dec_ref = Z3native.param_descrs_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let validate ( x : param_descrs ) ( p : params ) = - Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) - - let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) - - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in - let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = - Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = - Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_float ( x : params ) ( name : Symbol.symbol ) ( value : float ) = - Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = - Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) - - let mk_params ( ctx : context ) = - let res : params = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.params_inc_ref ; - dec_ref = Z3native.params_dec_ref } in - (z3obj_sno res ctx (Z3native.mk_params (context_gno ctx))) ; - (z3obj_create res) ; - res - - let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) - - let update_param_value ( ctx : context ) ( id : string) ( value : string )= - Z3native.update_param_value (context_gno ctx) id value - - let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = - Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) -end - -(** General expressions (terms) *) -and Expr : -sig - type expr = Expr of AST.ast - val expr_of_ptr : context -> Z3native.ptr -> expr - val gc : expr -> context - val gnc : expr -> Z3native.ptr - val gno : expr -> Z3native.ptr - val expr_lton : expr list -> Z3native.ptr array - val ast_of_expr : expr -> AST.ast - val expr_of_ast : AST.ast -> expr - val expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr - val simplify : expr -> Params.params option -> expr - val get_simplify_help : context -> string - val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs - val get_func_decl : expr -> FuncDecl.func_decl - val get_num_args : expr -> int - val get_args : expr -> expr list - val update : expr -> expr list -> expr - val substitute : expr -> expr list -> expr list -> expr - val substitute_one : expr -> expr -> expr -> expr - val substitute_vars : expr -> expr list -> expr - val translate : expr -> context -> expr - val to_string : expr -> string - val is_numeral : expr -> bool - val is_well_sorted : expr -> bool - val get_sort : expr -> Sort.sort - val is_const : expr -> bool - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - val mk_const_s : context -> string -> Sort.sort -> expr - val mk_const_f : context -> FuncDecl.func_decl -> expr - val mk_fresh_const : context -> string -> Sort.sort -> expr - val mk_app : context -> FuncDecl.func_decl -> expr list -> expr - val mk_numeral_string : context -> string -> Sort.sort -> expr - val mk_numeral_int : context -> int -> Sort.sort -> expr - val equal : expr -> expr -> bool - val compare : expr -> expr -> int -end = struct - type expr = Expr of AST.ast - - let gc e = match e with Expr(a) -> (z3obj_gc a) - let gnc e = match e with Expr(a) -> (z3obj_gnc a) - let gno e = match e with Expr(a) -> (z3obj_gno a) - - let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then - Expr(z3_native_object_of_ast_ptr ctx no) - else - let s = Z3native.get_sort (context_gno ctx) no in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) no) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - if (Z3native.is_numeral_ast (context_gno ctx) no) then - if (sk == INT_SORT || sk == REAL_SORT || sk == BV_SORT) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - raise (Z3native.Exception "Unsupported numeral object") - else - Expr(z3_native_object_of_ast_ptr ctx no) - - let expr_of_ast a = - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Expr(a) - - let ast_of_expr e = match e with Expr(a) -> a - - let expr_lton ( a : expr list ) = - let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in - Array.of_list (List.map f a) - - let expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr = fun ctx f args -> - match f with FuncDecl.FuncDecl(fa) -> - let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (List.length args) (expr_lton args) in - expr_of_ptr ctx o - - let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> expr_of_ptr (Expr.gc x) (Z3native.simplify (gnc x) (gno x)) - | Some pp -> expr_of_ptr (Expr.gc x) (Z3native.simplify_ex (gnc x) (gno x) (z3obj_gno pp)) - - let get_simplify_help ( ctx : context ) = - Z3native.simplify_get_help (context_gno ctx) - - let get_simplify_parameter_descrs ( ctx : context ) = - Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (gnc x) (gno x)) - - let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) - - let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = expr_of_ptr (Expr.gc x) (Z3native.get_app_arg (gnc x) (gno x) i) in - mk_list f n - - let update ( x : expr ) ( args : expr list ) = - if ((AST.is_app (ast_of_expr x)) && (List.length args <> (get_num_args x))) then - raise (Z3native.Exception "Number of arguments does not match") - else - expr_of_ptr (Expr.gc x) (Z3native.update_term (gnc x) (gno x) (List.length args) (expr_lton args)) - - let substitute ( x : expr ) from to_ = - if (List.length from) <> (List.length to_) then - raise (Z3native.Exception "Argument sizes do not match") - else - expr_of_ptr (Expr.gc x) (Z3native.substitute (gnc x) (gno x) (List.length from) (expr_lton from) (expr_lton to_)) - - let substitute_one ( x : expr ) from to_ = - substitute ( x : expr ) [ from ] [ to_ ] - - let substitute_vars ( x : expr ) to_ = - expr_of_ptr (Expr.gc x) (Z3native.substitute_vars (gnc x) (gno x) (List.length to_) (expr_lton to_)) - - let translate ( x : expr ) to_ctx = - if (Expr.gc x) == to_ctx then - x - else - expr_of_ptr to_ctx (Z3native.translate (gnc x) (gno x) (context_gno to_ctx)) - - let to_string ( x : expr ) = Z3native.ast_to_string (gnc x) (gno x) - - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (gnc x) (gno x)) - - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) - - let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (gnc x) (gno x)) - - let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_app a)) && - (get_num_args x) == 0 && - (FuncDecl.get_domain_size (get_func_decl x)) == 0 - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) - - let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = - mk_const ctx (Symbol.mk_string ctx name) range - - let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [] - - let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = - expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) - - let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr list ) = expr_of_func_app ctx f args - - let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) - - let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) - - let equal ( a : expr ) ( b : expr ) = AST.equal (ast_of_expr a) (ast_of_expr b) - - let compare a b = AST.compare (ast_of_expr a) (ast_of_expr b) -end - -open FuncDecl -open Expr - -module Boolean = -struct - let mk_sort ( ctx : context ) = - (sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - (Expr.mk_const ctx name (mk_sort ctx)) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_true ( ctx : context ) = - expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) - - let mk_false ( ctx : context ) = - expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) - - let mk_val ( ctx : context ) ( value : bool ) = - if value then mk_true ctx else mk_false ctx - - let mk_not ( ctx : context ) ( a : expr ) = - expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) - - let mk_ite ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( t3 : expr ) = - expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) - - let mk_iff ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) - - let mk_implies ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) - - let mk_xor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - - let mk_and ( ctx : context ) ( args : expr list ) = - let f x = (Expr.gno (x)) in - expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) - - let mk_or ( ctx : context ) ( args : expr list ) = - let f x = (Expr.gno (x)) in - expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) - - let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) - - let mk_distinct ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) - - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) - - let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (gnc x) - (Z3native.mk_bool_sort (gnc x)) - (Z3native.get_sort (gnc x) (gno x))) - - let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - let is_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - let is_eq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - let is_distinct ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - let is_ite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - let is_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - let is_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - let is_iff ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - let is_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - let is_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - let is_implies ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) -end - - -module Quantifier = -struct - type quantifier = Quantifier of expr - - let expr_of_quantifier e = match e with Quantifier(x) -> x - - let quantifier_of_expr e = - match e with Expr.Expr(a) -> - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.QUANTIFIER_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Quantifier(e) - - let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) - let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) - let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) - - module Pattern = - struct - type pattern = Pattern of ast - - let ast_of_pattern e = match e with Pattern(x) -> x - - let pattern_of_ast a = - (* CMW: Unchecked ok? *) - Pattern(a) - - let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) - let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) - let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - - let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms (gnc x) (gno x) - - let get_terms ( x : pattern ) = - let n = (get_num_terms x) in - let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in - mk_list f n - - let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) - end - - let get_index ( x : expr ) = - if not (AST.is_var (match x with Expr.Expr(a) -> a)) then - raise (Z3native.Exception "Term is not a bound variable.") - else - Z3native.get_index_value (Expr.gnc x) (Expr.gno x) - - let is_universal ( x : quantifier ) = - Z3native.is_quantifier_forall (gnc x) (gno x) - - let is_existential ( x : quantifier ) = not (is_universal x) - - let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) - - let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) - - let get_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in - mk_list f n - - let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) - - let get_no_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in - mk_list f n - - let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) - - let get_bound_variable_names ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in - mk_list f n - - let get_bound_variable_sorts ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in - mk_list f n - - let get_body ( x : quantifier ) = - expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) - - let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) - - let mk_pattern ( ctx : context ) ( terms : expr list ) = - if (List.length terms) == 0 then - raise (Z3native.Exception "Cannot create a pattern from zero terms") - else - Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (List.length terms) (expr_lton terms))) - - let mk_forall ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (List.length sorts) != (List.length names) then - raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - - let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (Expr.gno body))) - - let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (List.length sorts) != (List.length names) then - raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - - let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (Expr.gno body))) - - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (universal) then - (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - else - (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (universal) then - mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id - else - mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id - - let to_string ( x : quantifier ) = (Expr.to_string (expr_of_quantifier x)) -end - - -module Z3Array = -struct - let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = - sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) - - let is_store ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) - let is_select ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) - let is_constant_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) - let is_default_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) - let is_array_map ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) - let is_as_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) - let is_array ( x : expr ) = - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) - - let get_domain ( x : sort ) = Sort.sort_of_ptr (Sort.gc x) (Z3native.get_array_sort_domain (Sort.gnc x) (Sort.gno x)) - let get_range ( x : sort ) = Sort.sort_of_ptr (Sort.gc x) (Z3native.get_array_sort_range (Sort.gnc x) (Sort.gno x)) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = - (Expr.mk_const ctx name (mk_sort ctx domain range)) - - let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = - mk_const ctx (Symbol.mk_string ctx name) domain range - - let mk_select ( ctx : context ) ( a : expr ) ( i : expr ) = - expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (Expr.gno a) (Expr.gno i)) - - let mk_store ( ctx : context ) ( a : expr ) ( i : expr ) ( v : expr ) = - expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (Expr.gno a) (Expr.gno i) (Expr.gno v)) - - let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) - - let mk_map ( ctx : context ) ( f : func_decl ) ( args : expr list ) = - let m x = (Expr.gno x) in - expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) - - let mk_term_array ( ctx : context ) ( arg : expr ) = - expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (Expr.gno arg)) -end - - -module Set = -struct - let mk_sort ( ctx : context ) ( ty : sort ) = - sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) - - let is_union ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) - let is_intersect ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) - let is_difference ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) - let is_complement ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) - let is_subset ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) - - - let mk_empty ( ctx : context ) ( domain : sort ) = - (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) - - let mk_full ( ctx : context ) ( domain : sort ) = - expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) - - let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) - - let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) - - let mk_union ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) - - let mk_intersection ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) - - let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) - - let mk_complement ( ctx : context ) ( arg : expr ) = - expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) - - let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) - - let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) +module Z3 = struct end - - -module FiniteDomain = -struct - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) - - let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = - mk_sort ctx (Symbol.mk_string ctx name) size - - let is_finite_domain ( x : expr ) = - let nc = (Expr.gnc x) in - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) - - let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) - - let get_size ( x : sort ) = - let (r, v) = (Z3native.get_finite_domain_sort_size (Sort.gnc x) (Sort.gno x)) in - if r then v - else raise (Z3native.Exception "Conversion failed.") -end - - -module Relation = -struct - let is_relation ( x : expr ) = - let nc = (Expr.gnc x) in - ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) - - let is_store ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) - let is_empty ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) - let is_is_empty ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) - let is_join ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) - let is_union ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) - let is_widen ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) - let is_project ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) - let is_filter ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) - let is_negation_filter ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) - let is_rename ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) - let is_complement ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) - let is_select ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) - let is_clone ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) - - let get_arity ( x : sort ) = Z3native.get_relation_arity (Sort.gnc x) (Sort.gno x) - - let get_column_sorts ( x : sort ) = - let n = get_arity x in - let f i = (sort_of_ptr (Sort.gc x) (Z3native.get_relation_column (Sort.gnc x) (Sort.gno x) i)) in - mk_list f n -end - - -module Datatype = -struct - module Constructor = - struct - type constructor = z3_native_object - - module FieldNumTable = Hashtbl.Make(struct - type t = AST.ast - let equal x y = AST.compare x y = 0 - let hash = AST.hash - end) - - let _field_nums = FieldNumTable.create 0 - - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = - let n = (List.length field_names) in - if n != (List.length sorts) then - raise (Z3native.Exception "Number of field names does not match number of sorts") - else - if n != (List.length sort_refs) then - raise (Z3native.Exception "Number of field names does not match number of sort refs") - else - let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) - (Symbol.gno recognizer) - n - (Symbol.symbol_lton field_names) - (sort_option_lton sorts) - (Array.of_list sort_refs)) in - let no : constructor = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref} in - (z3obj_sno no ctx ptr) ; - (z3obj_create no) ; - let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in - Gc.finalise f no ; - FieldNumTable.add _field_nums no n ; - no - - let get_num_fields ( x : constructor ) = FieldNumTable.find _field_nums x - - let get_constructor_decl ( x : constructor ) = - let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - func_decl_of_ptr (z3obj_gc x) a - - let get_tester_decl ( x : constructor ) = - let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - func_decl_of_ptr (z3obj_gc x) b - - let get_accessor_decls ( x : constructor ) = - let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - let f i = func_decl_of_ptr (z3obj_gc x) (Array.get c i) in - mk_list f (Array.length c) - - end - - module ConstructorList = - struct - type constructor_list = z3_native_object - - let create ( ctx : context ) ( c : Constructor.constructor list ) = - let res : constructor_list = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref} in - let f x =(z3obj_gno x) in - (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (List.length c) (Array.of_list (List.map f c)))) ; - (z3obj_create res) ; - let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in - Gc.finalise f res; - res - end - - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = - Constructor.create ctx name recognizer field_names sorts sort_refs - - - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = - mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = - let f x = (z3obj_gno x) in - let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (List.length constructors) (Array.of_list (List.map f constructors))) in - sort_of_ptr ctx x - - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor list ) = - mk_sort ctx (Symbol.mk_string ctx name) constructors - - let mk_sorts ( ctx : context ) ( names : Symbol.symbol list ) ( c : Constructor.constructor list list ) = - let n = (List.length names) in - let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in - let cla = (Array.of_list (List.map f c)) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.symbol_lton names) cla) in - let g i = (sort_of_ptr ctx (Array.get r i)) in - mk_list g (Array.length r) - - let mk_sorts_s ( ctx : context ) ( names : string list ) ( c : Constructor.constructor list list ) = - mk_sorts ctx - ( - let f e = (Symbol.mk_string ctx e) in - List.map f names - ) - c - - let get_num_constructors ( x : sort ) = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) - - let get_constructors ( x : sort ) = - let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i) in - mk_list f n - - let get_recognizers ( x : sort ) = - let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) i) in - mk_list f n - - let get_accessors ( x : sort ) = - let n = (get_num_constructors x) in - let f i = ( - let fd = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i) in - let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in - let g j = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) i j) in - mk_list g ds - ) in - mk_list f n -end - - -module Enumeration = -struct - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = - let (a, _, _) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in - sort_of_ptr ctx a - - let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = - mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) - - let get_const_decls ( x : sort ) = - let n = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) in - let f i = (func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i)) in - mk_list f n - - let get_tester_decls ( x : sort ) = - let n = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) in - let f i = (func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) i)) in - mk_list f n - -end - - -module Z3List = -struct - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = - let (r, _, _, _, _, _, _) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in - sort_of_ptr ctx r - - let mk_list_s ( ctx : context ) (name : string) elem_sort = - mk_sort ctx (Symbol.mk_string ctx name) elem_sort - - let get_nil_decl ( x : sort ) = - func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) 0) - - let get_is_nil_decl ( x : sort ) = - func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) 0) - - let get_cons_decl ( x : sort ) = - func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) 1) - - let get_is_cons_decl ( x : sort ) = - func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) 1) - - let get_head_decl ( x : sort ) = - func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) 1 0) - - let get_tail_decl ( x : sort ) = - func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) 1 1) - - let nil ( x : sort ) = expr_of_func_app (Sort.gc x) (get_nil_decl x) [] -end - - -module Tuple = -struct - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = - let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in - sort_of_ptr ctx r - - let get_mk_decl ( x : sort ) = - func_decl_of_ptr (Sort.gc x) (Z3native.get_tuple_sort_mk_decl (Sort.gnc x) (Sort.gno x)) - - let get_num_fields ( x : sort ) = Z3native.get_tuple_sort_num_fields (Sort.gnc x) (Sort.gno x) - - let get_field_decls ( x : sort ) = - let n = get_num_fields x in - let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_tuple_sort_field_decl (Sort.gnc x) (Sort.gno x) i) in - mk_list f n -end - - -module Arithmetic = -struct - let is_int ( x : expr ) = - (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) - - let is_arithmetic_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - - let is_le ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - - let is_ge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - - let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - - let is_gt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - - let is_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - - let is_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - - let is_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - - let is_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - - let is_div ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - - let is_idiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - - let is_remainder ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - - let is_modulus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - - let is_inttoreal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - - let is_real_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - - let is_real_is_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) - - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) - - let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) - - let is_rat_numeral ( x : expr ) = (Expr.is_numeral x) && (is_real x) - - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) - - module Integer = - struct - let mk_sort ( ctx : context ) = - sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) - - let get_int ( x : expr ) = - let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in - if r then v - else raise (Z3native.Exception "Conversion failed.") - - let get_big_int ( x : expr ) = - if (is_int_numeral x) then - let s = (Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x)) in - (Big_int.big_int_of_string s) - else raise (Z3native.Exception "Conversion failed.") - - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - Expr.mk_const ctx name (mk_sort ctx) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_mod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - - let mk_rem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - - let mk_numeral_s ( ctx : context ) ( v : string ) = - expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) - - let mk_numeral_i ( ctx : context ) ( v : int ) = - expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) - - let mk_int2real ( ctx : context ) ( t : expr ) = - (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (Expr.gno t))) - - let mk_int2bv ( ctx : context ) ( n : int ) ( t : expr ) = - (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (Expr.gno t))) - end - - module Real = - struct - let mk_sort ( ctx : context ) = - sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) - - let get_numerator ( x : expr ) = - expr_of_ptr (Expr.gc x) (Z3native.get_numerator (Expr.gnc x) (Expr.gno x)) - - let get_denominator ( x : expr ) = - expr_of_ptr (Expr.gc x) (Z3native.get_denominator (Expr.gnc x) (Expr.gno x)) - - let get_ratio ( x : expr ) = - if (is_rat_numeral x) then - let s = (Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x)) in - (Ratio.ratio_of_string s) - else raise (Z3native.Exception "Conversion failed.") - - let to_decimal_string ( x : expr ) ( precision : int ) = - Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - Expr.mk_const ctx name (mk_sort ctx) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = - if (den == 0) then - raise (Z3native.Exception "Denominator is zero") - else - expr_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) - - let mk_numeral_s ( ctx : context ) ( v : string ) = - expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) - - let mk_numeral_i ( ctx : context ) ( v : int ) = - expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) - - let mk_is_integer ( ctx : context ) ( t : expr ) = - (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (Expr.gno t))) - - let mk_real2int ( ctx : context ) ( t : expr ) = - (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (Expr.gno t))) - - module AlgebraicNumber = - struct - let to_upper ( x : expr ) ( precision : int ) = - expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_upper (Expr.gnc x) (Expr.gno x) precision) - - let to_lower ( x : expr ) precision = - expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_lower (Expr.gnc x) (Expr.gno x) precision) - - let to_decimal_string ( x : expr ) ( precision : int ) = - Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) - end - end - - let mk_add ( ctx : context ) ( t : expr list ) = - let f x = (Expr.gno x) in - (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_mul ( ctx : context ) ( t : expr list ) = - let f x = (Expr.gno x) in - (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_sub ( ctx : context ) ( t : expr list ) = - let f x = (Expr.gno x) in - (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_unary_minus ( ctx : context ) ( t : expr ) = - (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (Expr.gno t))) - - let mk_div ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - - let mk_power ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - - let mk_lt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - - let mk_le ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - - let mk_gt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - - let mk_ge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) -end - - -module BitVector = -struct - let mk_sort ( ctx : context ) size = - sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) - let is_bv ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) - let is_bv_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) - let is_bv_bit1 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) - let is_bv_bit0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) - let is_bv_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) - let is_bv_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) - let is_bv_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) - let is_bv_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) - let is_bv_sdiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) - let is_bv_udiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) - let is_bv_SRem ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) - let is_bv_urem ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) - let is_bv_smod ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) - let is_bv_sdiv0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) - let is_bv_udiv0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) - let is_bv_srem0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) - let is_bv_urem0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) - let is_bv_smod0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) - let is_bv_ule ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) - let is_bv_sle ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) - let is_bv_uge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) - let is_bv_sge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) - let is_bv_ult ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) - let is_bv_slt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) - let is_bv_ugt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) - let is_bv_sgt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) - let is_bv_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) - let is_bv_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) - let is_bv_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) - let is_bv_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) - let is_bv_nand ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) - let is_bv_nor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) - let is_bv_xnor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) - let is_bv_concat ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) - let is_bv_signextension ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) - let is_bv_zeroextension ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) - let is_bv_extract ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) - let is_bv_repeat ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) - let is_bv_reduceor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) - let is_bv_reduceand ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) - let is_bv_comp ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) - let is_bv_shiftleft ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) - let is_bv_shiftrightlogical ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) - let is_bv_shiftrightarithmetic ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) - let is_bv_rotateleft ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) - let is_bv_rotateright ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) - let is_bv_rotateleftextended ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) - let is_bv_rotaterightextended ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) - let is_int_to_bv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) - let is_bv_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) - let is_bv_carry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) - let is_bv_xor3 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) - let get_size (x : sort ) = Z3native.get_bv_sort_size (Sort.gnc x) (Sort.gno x) - let get_int ( x : expr ) = - let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in - if r then v - else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - Expr.mk_const ctx name (mk_sort ctx size) - let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = - mk_const ctx (Symbol.mk_string ctx name) size - let mk_not ( ctx : context ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (Expr.gno t)) - let mk_redand ( ctx : context ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (Expr.gno t)) - let mk_redor ( ctx : context ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (Expr.gno t)) - let mk_and ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_or ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_xor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_nand ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_nor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_xnor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_neg ( ctx : context ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (Expr.gno t)) - let mk_add ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_sub ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_mul ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_udiv ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_sdiv ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_urem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_srem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_smod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_ult ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_slt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_ule ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_sle ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_uge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_sge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_ugt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_sgt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_concat ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (Expr.gno t)) - let mk_sign_ext ( ctx : context ) ( i : int ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (Expr.gno t)) - let mk_zero_ext ( ctx : context ) ( i : int ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (Expr.gno t)) - let mk_repeat ( ctx : context ) ( i : int ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (Expr.gno t)) - let mk_shl ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_lshr ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_ashr ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_rotate_left ( ctx : context ) ( i : int ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (Expr.gno t)) - let mk_rotate_right ( ctx : context ) ( i : int ) ( t : expr ) = - expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (Expr.gno t)) - let mk_ext_rotate_left ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_ext_rotate_right ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_bv2int ( ctx : context ) ( t : expr ) ( signed : bool ) = - expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (Expr.gno t) signed) - let mk_add_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = - (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) - let mk_add_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_sub_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_sub_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = - (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) - let mk_sdiv_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_neg_no_overflow ( ctx : context ) ( t : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (Expr.gno t))) - let mk_mul_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = - (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) - let mk_mul_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = - expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx size))) -end - - -module Proof = -struct - let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) - let is_asserted ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) - let is_goal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) - let is_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_OEQ) - let is_modus_ponens ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) - let is_reflexivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) - let is_symmetry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) - let is_transitivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) - let is_Transitivity_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) - let is_monotonicity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) - let is_quant_intro ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) - let is_distributivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) - let is_and_elimination ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) - let is_or_elimination ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) - let is_rewrite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) - let is_rewrite_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) - let is_pull_quant ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) - let is_pull_quant_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) - let is_push_quant ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) - let is_elim_unused_vars ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) - let is_der ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) - let is_quant_inst ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) - let is_hypothesis ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) - let is_lemma ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) - let is_unit_resolution ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) - let is_iff_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) - let is_iff_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) - let is_commutativity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) - let is_def_axiom ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) - let is_def_intro ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) - let is_apply_def ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) - let is_iff_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) - let is_nnf_pos ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) - let is_nnf_neg ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) - let is_nnf_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) - let is_cnf_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) - let is_skolemize ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) - let is_modus_ponens_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) - let is_theory_lemma ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) -end - - -module Goal = -struct - type goal = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : goal = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.goal_inc_ref ; - dec_ref = Z3native.goal_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_precision ( x : goal ) = - goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) - - let is_precise ( x : goal ) = - (get_precision x) == GOAL_PRECISE - - let is_underapproximation ( x : goal ) = - (get_precision x) == GOAL_UNDER - - let is_overapproximation ( x : goal ) = - (get_precision x) == GOAL_OVER - - let is_garbage ( x : goal ) = - (get_precision x) == GOAL_UNDER_OVER - - let add ( x : goal ) ( constraints : expr list ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e) in - ignore (List.map f constraints) ; - () - - let is_inconsistent ( x : goal ) = - Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) - - let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) - - let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) - - let get_formulas ( x : goal ) = - let n = get_size x in - let f i = ((expr_of_ptr (z3obj_gc x) - (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in - mk_list f n - - let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) - - let is_decided_sat ( x : goal ) = - Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) - - let is_decided_unsat ( x : goal ) = - Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) - - let translate ( x : goal ) ( to_ctx : context ) = - create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let simplify ( x : goal ) ( p : Params.params option ) = - let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in - Z3native.tactic_inc_ref (z3obj_gnc x) tn ; - let arn = match p with - | None -> Z3native.tactic_apply (z3obj_gnc x) tn (z3obj_gno x) - | Some(pn) -> Z3native.tactic_apply_ex (z3obj_gnc x) tn (z3obj_gno x) (z3obj_gno pn) - in - Z3native.apply_result_inc_ref (z3obj_gnc x) arn ; - let sg = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) arn in - let res = if sg == 0 then - raise (Z3native.Exception "No subgoals") - else - Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in - Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; - Z3native.tactic_dec_ref (z3obj_gnc x) tn ; - create (z3obj_gc x) res - - let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) - - let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Model = -struct - type model = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : model = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.model_inc_ref ; - dec_ref = Z3native.model_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module FuncInterp = - struct - type func_interp = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : func_interp = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.func_interp_inc_ref ; - dec_ref = Z3native.func_interp_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module FuncEntry = - struct - type func_entry = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : func_entry = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.func_entry_inc_ref ; - dec_ref = Z3native.func_entry_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_value ( x : func_entry ) = - expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) - - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) - - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ List.fold_right f a ((Expr.to_string (get_value x)) ^ "]") - end - - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) - - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) - - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) - - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (List.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - List.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") - end - - let get_const_interp ( x : model ) ( f : func_decl ) = - if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then - raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") - else - let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in - if (Z3native.is_null np) then - None - else - Some (expr_of_ptr (z3obj_gc x) np) - - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - - - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in - if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in - if (Z3native.is_null n) then - None - else - match sk with - | ARRAY_SORT -> - if not (Z3native.is_as_array (z3obj_gnc x) n) then - raise (Z3native.Exception "Argument was not an array constant") - else - let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x (func_decl_of_ptr (z3obj_gc x) fd) - | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); - else - let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in - if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) - - (** The number of constants that have an interpretation in the model. *) - let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) - - let get_const_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) - - let get_func_decls ( x : model ) = - let n = (get_num_funcs x) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_decls ( x : model ) = - let n_funcs = (get_num_funcs x) in - let n_consts = (get_num_consts x ) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - (mk_list f n_funcs) @ (mk_list g n_consts) - - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in - if not r then - None - else - Some(expr_of_ptr (z3obj_gc x) v) - - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = - eval x t completion - - let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) - - let get_sorts ( x : model ) = - let n = (get_num_sorts x) in - let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in - mk_list f n - - let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Probe = -struct - type probe = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : probe = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.probe_inc_ref ; - dec_ref = Z3native.probe_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - - let apply ( x : probe ) ( g : Goal.goal ) = - Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) - - let get_num_probes ( ctx : context ) = - Z3native.get_num_probes (context_gno ctx) - - let get_probe_names ( ctx : context ) = - let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name (context_gno ctx) i) in - mk_list f n - - let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr (context_gno ctx) name - - let mk_probe ( ctx : context ) ( name : string ) = - (create ctx (Z3native.mk_probe (context_gno ctx) name)) - - let const ( ctx : context ) ( v : float ) = - (create ctx (Z3native.probe_const (context_gno ctx) v)) - - let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let not_ ( ctx : context ) ( p : probe ) = - (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) -end - - -module Tactic = -struct - type tactic = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : tactic = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.tactic_inc_ref ; - dec_ref = Z3native.tactic_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module ApplyResult = - struct - type apply_result = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : apply_result = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.apply_result_inc_ref ; - dec_ref = Z3native.apply_result_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_num_subgoals ( x : apply_result ) = - Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) - - let get_subgoals ( x : apply_result ) = - let n = (get_num_subgoals x) in - let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_subgoal ( x : apply_result ) ( i : int ) = - Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) - - let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = - Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) - - let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) - - let get_param_descrs ( x : tactic ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = - match p with - | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) - | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) - - let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) - - let get_tactic_names ( ctx : context ) = - let n = (get_num_tactics ctx ) in - let f i = (Z3native.get_tactic_name (context_gno ctx) i) in - mk_list f n - - let get_tactic_description ( ctx : context ) ( name : string ) = - Z3native.tactic_get_descr (context_gno ctx) name - - let mk_tactic ( ctx : context ) ( name : string ) = - create ctx (Z3native.mk_tactic (context_gno ctx) name) - - let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic list ) = - let f p c = (match p with - | None -> (Some (z3obj_gno c)) - | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in - match (List.fold_left f None ts) with - | None -> - create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - | Some(x) -> - let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in - create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) - - let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - - let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) - - let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = - create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) - - let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) - - let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) - - let skip ( ctx : context ) = - create ctx (Z3native.tactic_skip (context_gno ctx)) - - let fail ( ctx : context ) = - create ctx (Z3native.tactic_fail (context_gno ctx)) - - let fail_if ( ctx : context ) ( p : Probe.probe ) = - create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) - - let fail_if_not_decided ( ctx : context ) = - create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) - - let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = - create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) - - let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = - using_params ctx t p - - let par_or ( ctx : context ) ( t : tactic list ) = - let f e = (z3obj_gno e) in - create ctx (Z3native.tactic_par_or (context_gno ctx) (List.length t) (Array.of_list (List.map f t))) - - let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - - let interrupt ( ctx : context ) = - Z3native.interrupt (context_gno ctx) -end - - -module Solver = -struct - type solver = z3_native_object - type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : solver = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.solver_inc_ref ; - dec_ref = Z3native.solver_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let string_of_status ( s : status) = match s with - | UNSATISFIABLE -> "unsatisfiable" - | SATISFIABLE -> "satisfiable" - | _ -> "unknown" - - module Statistics = - struct - type statistics = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : statistics = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.stats_inc_ref ; - dec_ref = Z3native.stats_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - - module Entry = - struct - type statistics_entry = { - mutable m_key : string; - mutable m_is_int : bool ; - mutable m_is_float : bool ; - mutable m_int : int ; - mutable m_float : float } - - let create_si k v = - let res : statistics_entry = { - m_key = k ; - m_is_int = true ; - m_is_float = false ; - m_int = v ; - m_float = 0.0 - } in - res - - let create_sd k v = - let res : statistics_entry = { - m_key = k ; - m_is_int = false ; - m_is_float = true ; - m_int = 0 ; - m_float = v - } in - res - - - let get_key (x : statistics_entry) = x.m_key - let get_int (x : statistics_entry) = x.m_int - let get_float (x : statistics_entry) = x.m_float - let is_int (x : statistics_entry) = x.m_is_int - let is_float (x : statistics_entry) = x.m_is_float - let to_string_value (x : statistics_entry) = - if (is_int x) then - string_of_int (get_int x) - else if (is_float x) then - string_of_float (get_float x) - else - raise (Z3native.Exception "Unknown statistical entry type") - let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) - end - - let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) - - let get_entries ( x : statistics ) = - let n = (get_size x ) in - let f i = ( - let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in - if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then - (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) - else - (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) - ) in - mk_list f n - - let get_keys ( x : statistics ) = - let n = (get_size x) in - let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get ( x : statistics ) ( key : string ) = - let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in - List.fold_left f None (get_entries x) - end - - let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) - - let set_parameters ( x : solver ) ( p : Params.params )= - Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - - let get_param_descrs ( x : solver ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) - - let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) - - let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n - - let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - - let add ( x : solver ) ( constraints : expr list ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in - ignore (List.map f constraints) - - let assert_and_track_l ( x : solver ) ( cs : expr list ) ( ps : expr list ) = - if ((List.length cs) != (List.length ps)) then - raise (Z3native.Exception "Argument size mismatch") - else - let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Expr.gno a) (Expr.gno b)) in - ignore (List.iter2 f cs ps) - - let assert_and_track ( x : solver ) ( c : expr ) ( p : expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Expr.gno c) (Expr.gno p) - - let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - (AST.ASTVector.get_size a) - - let get_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size a) in - let f i = (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in - mk_list f n - - let check ( x : solver ) ( assumptions : expr list ) = - let r = - if ((List.length assumptions) == 0) then - lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) - else - let f x = (Expr.gno x) in - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) - in - match r with - | L_TRUE -> SATISFIABLE - | L_FALSE -> UNSATISFIABLE - | _ -> UNKNOWN - - let get_model ( x : solver ) = - let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in - if (Z3native.is_null q) then - None - else - Some (Model.create (z3obj_gc x) q) - - let get_proof ( x : solver ) = - let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size cn) in - let f i = (AST.ASTVector.get cn i) in - mk_list f n - - let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - - let get_statistics ( x : solver ) = - (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) - - let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = - match logic with - | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) - - let mk_solver_s ( ctx : context ) ( logic : string ) = - mk_solver ctx (Some (Symbol.mk_string ctx logic)) - - let mk_simple_solver ( ctx : context ) = - (create ctx (Z3native.mk_simple_solver (context_gno ctx))) - - let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = - (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) - - let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Fixedpoint = -struct - type fixedpoint = z3_native_object - - let create ( ctx : context ) = - let res : fixedpoint = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.fixedpoint_inc_ref ; - dec_ref = Z3native.fixedpoint_dec_ref } in - (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; - (z3obj_create res) ; - res - - - let get_help ( x : fixedpoint ) = - Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) - - let set_params ( x : fixedpoint ) ( p : Params.params )= - Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - - let get_param_descrs ( x : fixedpoint ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let add ( x : fixedpoint ) ( constraints : expr list ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in - ignore (List.map f constraints) ; - () - - let register_relation ( x : fixedpoint ) ( f : func_decl ) = - Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) - - let add_rule ( x : fixedpoint ) ( rule : expr ) ( name : Symbol.symbol option ) = - match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) (Symbol.gno y) - - let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = - Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) - - let query ( x : fixedpoint ) ( query : expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Expr.gno query))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN - - let query_r ( x : fixedpoint ) ( relations : func_decl list ) = - let f x = ptr_of_ast (ast_of_func_decl x) in - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (List.length relations) (Array.of_list (List.map f relations)))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN - - let push ( x : fixedpoint ) = - Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) - - let pop ( x : fixedpoint ) = - Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) - - let update_rule ( x : fixedpoint ) ( rule : expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) (Symbol.gno name) - - let get_answer ( x : fixedpoint ) = - let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let get_reason_unknown ( x : fixedpoint ) = - Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - - let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = - Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) - - let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = - let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) - - let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) - - let to_string_q ( x : fixedpoint ) ( queries : expr list ) = - let f x = Expr.gno x in - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) - - let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - mk_list f n - - let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - mk_list f n - - let mk_fixedpoint ( ctx : context ) = create ctx -end - - -module SMT = -struct - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : expr list ) ( formula : expr ) = - Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (List.length assumptions) (let f x = Expr.gno (x) in (Array.of_list (List.map f assumptions))) - (Expr.gno formula) - - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Z3native.parse_smtlib_string (context_gno ctx) str - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) - - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Z3native.parse_smtlib_file (context_gno ctx) file_name - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) - - let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) - - let get_smtlib_formulas ( ctx : context ) = - let n = (get_num_smtlib_formulas ctx ) in - let f i =(expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in - mk_list f n - - let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) - - let get_smtlib_assumptions ( ctx : context ) = - let n = (get_num_smtlib_assumptions ctx ) in - let f i = (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in - mk_list f n - - let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) - - let get_smtlib_decls ( ctx : context ) = - let n = (get_num_smtlib_decls ctx) in - let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in - mk_list f n - - let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) - - let get_smtlib_sorts ( ctx : context ) = - let n = (get_num_smtlib_sorts ctx) in - let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in - mk_list f n - - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) - - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) -end - -module Interpolation = -struct - let mk_interpolant ( ctx : context ) ( a : expr ) = - (expr_of_ptr ctx (Z3native.mk_interpolant (context_gno ctx) (Expr.gno a))) - - let mk_interpolation_context ( settings : ( string * string ) list ) = - let cfg = Z3native.mk_config () in - let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in - (List.iter f settings) ; - let v = Z3native.mk_interpolation_context cfg in - Z3native.del_config(cfg) ; - Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; - Z3native.set_internal_error_handler v ; - let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in - let f = fun o -> dispose_context o in - Gc.finalise f res; - res - - let get_interpolant ( ctx : context ) ( pf : expr ) ( pat: expr ) ( p : Params.params ) = - (ASTVector.create ctx (Z3native.get_interpolant (context_gno ctx) (Expr.gno pf) (Expr.gno pat) (z3obj_gno p))) - - let compute_interpolant ( ctx : context ) ( pat : expr ) ( p : Params.params ) = - let (r, interp, model) = (Z3native.compute_interpolant (context_gno ctx) (Expr.gno pat) (z3obj_gno p)) in - match (lbool_of_int r) with - | L_TRUE -> ((ASTVector.create ctx interp), (Model.create ctx model)) - | _ -> raise (Z3native.Exception "Error computing interpolant.") - - let get_interpolation_profile ( ctx : context ) = - (Z3native.interpolation_profile (context_gno ctx)) - - let read_interpolation_problem ( ctx : context ) ( filename : string ) = - let (r, num, cnsts, parents, error, num_theory, theory) = (Z3native.read_interpolation_problem (context_gno ctx) filename) in - match r with - | 0 -> raise (Z3native.Exception "Interpolation problem could not be read.") - | _ -> - let f1 i = (expr_of_ptr ctx (Array.get cnsts i)) in - let f2 i = (Array.get parents i) in - let f3 i = (expr_of_ptr ctx (Array.get theory i)) in - ((mk_list f1 num), - (mk_list f2 num), - (mk_list f3 num_theory)) - - let check_interpolant ( ctx : context ) ( num : int ) ( cnsts : Expr.expr list ) ( parents : int list ) ( interps : Expr.expr list ) ( num_theory : int ) ( theory : Expr.expr list ) = - let (r, str) = (Z3native.check_interpolant (context_gno ctx) - num - (let f x = Expr.gno x in (Array.of_list (List.map f cnsts))) - (Array.of_list parents) - (let f x = Expr.gno x in (Array.of_list (List.map f interps))) - num_theory - (let f x = Expr.gno x in (Array.of_list (List.map f theory)))) in - match (lbool_of_int r) with - | L_UNDEF -> raise (Z3native.Exception "Interpolant could not be verified.") - | L_FALSE -> raise (Z3native.Exception "Interpolant could not be verified.") - | _ -> () - - let write_interpolation_problem ( ctx : context ) ( num : int ) ( cnsts : Expr.expr list ) ( parents : int list ) ( filename : string ) ( num_theory : int ) ( theory : Expr.expr list ) = - (Z3native.write_interpolation_problem (context_gno ctx) num (expr_lton cnsts) (Array.of_list parents) filename num_theory (expr_lton theory)) ; - () -end - -let set_global_param ( id : string ) ( value : string ) = - (Z3native.global_param_set id value) - -let get_global_param ( id : string ) = - let (r, v) = (Z3native.global_param_get id) in - if not r then - None - else - Some v - -let global_param_reset_all = - Z3native.global_param_reset_all - -let toggle_warning_messages ( enabled: bool ) = - Z3native.toggle_warning_messages enabled From e2ac8c73d9ad7ac7fa59f9a15ff70da94c6fc2fb Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 04:37:46 +0000 Subject: [PATCH 129/248] ML API temp files added to .gitignore Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index a1a8b7f6b..648013ca1 100644 --- a/.gitignore +++ b/.gitignore @@ -61,7 +61,6 @@ src/util/version.h src/api/java/Native.cpp src/api/java/Native.java src/api/java/enumerations/*.java - *.bak doc/api doc/code From d2d4bf7f835c65d58aa5f56b11bb36e0a5b5bee8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 08:06:10 +0000 Subject: [PATCH 130/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 45 ------------------------- scripts/update_api.py | 45 +++++++------------------ src/api/ml/z3.ml | 78 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 87 insertions(+), 81 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 33129f555..2c525861c 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1866,11 +1866,7 @@ def mk_config(): if GPROF: print('gprof: enabled') print('Python version: %s' % distutils.sysconfig.get_python_version()) -<<<<<<< HEAD print('ML API: %s' % is_ml_enabled()) -======= - print 'ML API: %s' % is_ml_enabled() ->>>>>>> Beginnings of a new ML API if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) @@ -2738,9 +2734,6 @@ def mk_z3consts_ml(api_files): if not os.path.exists(gendir): os.mkdir(gendir) -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') efile.write('(** The enumeration types of Z3. *)\n\n') @@ -2822,23 +2815,7 @@ def mk_z3consts_ml(api_files): efile = open('%s.mli' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') efile.write('(** The enumeration types of Z3. *)\n\n') -======= - efile = open('%s.ml' % os.path.join(gendir, "z3_enums"), 'w') - efile.write('(* Automatically generated file *)\n\n') - # efile.write('module z3_enums = struct\n\n'); - - ->>>>>>> More new ML API -======= - efile = open('%s.ml' % os.path.join(gendir, "enumerations"), 'w') - efile.write('(* Automatically generated file *)\n\n') - efile.write('module Enumerations = struct\n') ->>>>>>> More ML API -======= - efile = open('%s.ml' % os.path.join(gendir, "z3enums"), 'w') - efile.write('(* Automatically generated file *)\n\n') efile.write('module Z3enums = struct\n') ->>>>>>> New native ML API layer. for api_file in api_files: api_file_c = ml.find_file(api_file, ml.name) api_file = os.path.join(api_file_c.src_dir, api_file) @@ -2884,8 +2861,6 @@ def mk_z3consts_ml(api_files): if m: name = words[1] if name not in DeprecatedEnums: -<<<<<<< HEAD -<<<<<<< HEAD efile.write('(** %s *)\n' % name[3:]) efile.write('type %s =\n' % name[3:]) # strip Z3_ for k, i in decls.iteritems(): @@ -2896,17 +2871,10 @@ def mk_z3consts_ml(api_files): efile.write('(** Convert int to %s*)\n' % name[3:]) efile.write('val %s_of_int : int -> %s\n' % (name[3:],name[3:])) # strip Z3_ efile.write('\n') -======= efile.write('\n(* %s *)\n' % name) -======= ->>>>>>> More ML API efile.write('type %s =\n' % name[3:]) # strip Z3_ for k, i in decls.iteritems(): -<<<<<<< HEAD efile.write(' | %s \n' % k[3:]) # strip Z3_ ->>>>>>> More new ML API -======= - efile.write(' | %s \n' % k[3:]) # strip Z3_ efile.write('\n') efile.write('let %s2int x : int =\n' % (name[3:])) # strip Z3_ efile.write(' match x with\n') @@ -2919,7 +2887,6 @@ def mk_z3consts_ml(api_files): efile.write(' | %d -> %s\n' % (i, k[3:])) # use Z3.Exception? efile.write(' | _ -> raise (Failure "undefined enum value")\n\n') ->>>>>>> More ML API mode = SEARCHING else: if words[2] != '': @@ -2930,21 +2897,9 @@ def mk_z3consts_ml(api_files): decls[words[1]] = idx idx = idx + 1 linenum = linenum + 1 -<<<<<<< HEAD -<<<<<<< HEAD - if VERBOSE: - print "Generated '%s/z3enums.mli'" % ('%s' % gendir) -======= - efile.write('\n') - # efile.write'end\n'); - if VERBOSE: - print "Generated '%s/z3_enums.ml'" % ('%s' % gendir) ->>>>>>> More new ML API -======= efile.write('end\n') if VERBOSE: print "Generated '%s/enumerations.ml'" % ('%s' % gendir) ->>>>>>> More ML API def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index f142c8ec1..a586ad6e3 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -159,7 +159,7 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I # Mapping to ML types Type2ML = { VOID : 'unit', VOID_PTR : 'VOIDP', INT : 'int', UINT : 'int', INT64 : 'int', UINT64 : 'int', DOUBLE : 'float', STRING : 'string', STRING_PTR : 'char**', - BOOL : 'int', SYMBOL : 'symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } + BOOL : 'int', SYMBOL : 'z3_symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } next_type_id = FIRST_OBJ_ID @@ -213,10 +213,7 @@ def type2javaw(ty): def type2ml(ty): global Type2ML - if (ty >= FIRST_OBJ_ID): - return 'int' - else: - return Type2ML[ty] + return Type2ML[ty] def _in(ty): return (IN, ty); @@ -1106,6 +1103,7 @@ def is_array_param(p): return False def mk_ml(): + global Type2Str if not is_ml_enabled(): return ml_dir = get_component('ml').src_dir @@ -1114,29 +1112,12 @@ def mk_ml(): ml_native = open(ml_nativef, 'w') ml_native.write('(* Automatically generated file *)\n\n') ml_native.write('open Z3enums\n\n') - ml_native.write('module Z3native = struct\n\n') - ml_native.write(' type context\n') - ml_native.write(' and symbol\n') - ml_native.write(' and ast\n') - ml_native.write(' and sort = private ast\n') - ml_native.write(' and func_decl = private ast\n') - ml_native.write(' and app = private ast\n') - ml_native.write(' and pattern = private ast\n') - ml_native.write(' and params\n') - ml_native.write(' and param_descrs\n') - ml_native.write(' and model\n') - ml_native.write(' and func_interp\n') - ml_native.write(' and func_entry\n') - ml_native.write(' and fixedpoint\n') - ml_native.write(' and ast_vector\n') - ml_native.write(' and ast_map\n') - ml_native.write(' and goal\n') - ml_native.write(' and tactic\n') - ml_native.write(' and probe\n') - ml_native.write(' and apply_result\n') - ml_native.write(' and solver\n') - ml_native.write(' and stats\n\n') - ml_native.write(' exception Exception of string\n\n') + ml_native.write('type ptr\n') + ml_native.write('and z3_symbol = ptr\n') + for k, v in Type2Str.iteritems(): + if is_obj(k): + ml_native.write('and %s = ptr\n' % v.lower()) + ml_native.write('\nexception Exception of string\n\n') # ML declarations ml_native.write(' module ML2C = struct\n\n') @@ -1192,9 +1173,9 @@ def mk_ml(): i = i + 1 ml_native.write(') in\n') if len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = (Z3enums.int2error_code (ML2C.n_get_error_code a0)) in \n') - ml_native.write(' if err <> Z3enums.OK then\n') - ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (Z3enums.error_code2int err)))\n') + ml_native.write(' let err = (int2error_code (ML2C.n_get_error_code a0)) in \n') + ml_native.write(' if err <> OK then\n') + ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (error_code2int err)))\n') ml_native.write(' else\n') if result == VOID: ml_native.write(' ()\n') @@ -1202,8 +1183,6 @@ def mk_ml(): ml_native.write(' res\n') ml_native.write('\n') - ml_native.write('end\n') - # C interface ml_wrapper = open(ml_wrapperf, 'w') ml_wrapper.write('// Automatically generated file\n\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 5251a8767..a6a388aa7 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,11 +1,83 @@ (* Author: CM Wintersteiger (C) Microsoft Research, 2012 -*) + *) open Z3enums open Z3native -module Z3 = struct +class context = + object (self) + val m_n_ctx : Z3native.z3_context option = None + val mutable m_refCount : int = 0 + initializer Gc.finalise (fun self -> self#dispose ()) self + method dispose () = + Printf.printf "Disposing %d \n" (Oo.id self) ; + match m_n_ctx with + | Some(x) -> (del_context x) + | None -> () + method sub_one_ctx_obj = m_refCount <- m_refCount - 1 + method add_one_ctx_obj = m_refCount <- m_refCount + 1 + end + +class virtual z3object ctx_init obj_init = + object (self) + val mutable m_ctx : context option = ctx_init + val mutable m_n_obj : Z3native.ptr option = obj_init + + initializer + (match m_n_obj with + | Some (x) -> self#incref x; + (match m_ctx with + | Some(x) -> x#add_one_ctx_obj + | None -> () + ) + | None -> () + ); + Gc.finalise (fun self -> self#dispose ()) self + + method virtual incref : Z3native.ptr -> unit + method virtual decref : Z3native.ptr -> unit + + (* + Disposes of the underlying native Z3 object. + *) + method dispose () = + Printf.printf "Disposing %d \n" (Oo.id self) ; + (match m_n_obj with + | Some (x) -> self#decref x; m_n_obj <- None + | None -> () + ); + (match m_ctx with + | Some (x) -> x#sub_one_ctx_obj + | None -> () + ); + m_ctx <- None + + + method get_native_object = m_n_obj + + method set_native_object x = + (match x with + | Some(x) -> self#incref x + | None -> () + ); + (match m_n_obj with + | Some(x) -> self#decref x + | None -> () + ); + m_n_obj <- x + + method get_context = m_ctx + + method array_to_native a = + let f e = e#get_native_object in + (Array.map f a) + + method array_length a = + match a with + | Some(x) -> (Array.length x) + | None -> 0 + + end -end From f7b3529f0166facc8b94b6becbe97b56e4abc54d Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 16:33:51 +0000 Subject: [PATCH 131/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- examples/ml/MLExample.ml | 12 ++++++++ scripts/mk_util.py | 9 +++++- src/api/ml/README | 3 -- src/api/ml/z3.ml | 59 ++++++++++++++++++++++++++++++++-------- 4 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 examples/ml/MLExample.ml diff --git a/examples/ml/MLExample.ml b/examples/ml/MLExample.ml new file mode 100644 index 000000000..8cc248206 --- /dev/null +++ b/examples/ml/MLExample.ml @@ -0,0 +1,12 @@ +(* + Copyright (C) 2012 Microsoft Corporation + Author: CM Wintersteiger (cwinter) 2012-12-17 + *) + + open Z3 + + let _ = ignore(Log.open_ "z3.log") ; +let cfg = Some [("model", "true"); ("proof", "false")] in +let ctx = (new context cfg) in +ctx#dispose +;; diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 2c525861c..40828f8c3 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1597,7 +1597,14 @@ class MLExampleComponent(ExampleComponent): for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('_ex_%s: ml_example.byte ml_example$(EXE_EXT)\n\n' % self.name) + out.write('_ex_%s: z3.cmxa' % self.name) + deps = '' + for mlfile in get_ml_files(self.ex_dir): + out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) + if IS_WINDOWS: + deps = deps.replace('/', '\\') + out.write('%s\n' % deps) + out.write('\tcd %s && ocamlbuild -build-dir ../../%s -lib z3 MLExample.native && cd -\n\n' % (self.to_src_dir, BUILD_DIR)) class PythonExampleComponent(ExampleComponent): def __init__(self, name, path): diff --git a/src/api/ml/README b/src/api/ml/README index f8984c79e..36f903925 100644 --- a/src/api/ml/README +++ b/src/api/ml/README @@ -1,11 +1,8 @@ This directory is work in progress. We are currently working on a brand new ML API. -<<<<<<< HEAD On Windows, there are no less than four different ports of OCaml. The Z3 build system assumes that either the win32 or the win64 port is installed. This means that OCaml will use `cl' as the underlying C compiler and not the cygwin or mingw compilers. -======= ->>>>>>> Beginnings of a new ML API diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index a6a388aa7..0329402dd 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,27 +1,60 @@ (* - Author: CM Wintersteiger - (C) Microsoft Research, 2012 + Copyright (C) 2012 Microsoft Corporation + Author: CM Wintersteiger (cwinter) 2012-12-17 *) open Z3enums open Z3native -class context = +module Log = + struct + let m_is_open = false +(* CMW: "open" seems to be an invalid function name*) + let open_ fn = int2lbool(open_log fn) == L_TRUE + let close = (close_log) + let append s = (append_log s) + end + +class virtual idisposable = + object + method virtual dispose : unit + end + +class context settings = object (self) - val m_n_ctx : Z3native.z3_context option = None + inherit idisposable + val mutable m_n_ctx : Z3native.z3_context option = None val mutable m_refCount : int = 0 - initializer Gc.finalise (fun self -> self#dispose ()) self - method dispose () = - Printf.printf "Disposing %d \n" (Oo.id self) ; - match m_n_ctx with - | Some(x) -> (del_context x) - | None -> () + + initializer + let cfg = mk_config() in + (match settings with + | Some(x) -> + let f e = (set_param_value cfg (fst e) (snd e)) in + (List.iter f x) + | _ -> () + ) ; + m_n_ctx <- Some (mk_context_rc cfg) ; + del_config(cfg) ; + Gc.finalise (fun self -> self#dispose) self + + method dispose : unit = + if m_refCount == 0 then ( + Printf.printf "Disposing %d \n" (Oo.id self) ; + match m_n_ctx with + | Some(x) -> (del_context x) + | None -> () + ) else ( + (* re-queue for finalization? *) + ) + method sub_one_ctx_obj = m_refCount <- m_refCount - 1 method add_one_ctx_obj = m_refCount <- m_refCount + 1 end class virtual z3object ctx_init obj_init = object (self) + inherit idisposable val mutable m_ctx : context option = ctx_init val mutable m_n_obj : Z3native.ptr option = obj_init @@ -34,7 +67,7 @@ class virtual z3object ctx_init obj_init = ) | None -> () ); - Gc.finalise (fun self -> self#dispose ()) self + Gc.finalise (fun self -> self#dispose) self method virtual incref : Z3native.ptr -> unit method virtual decref : Z3native.ptr -> unit @@ -42,7 +75,7 @@ class virtual z3object ctx_init obj_init = (* Disposes of the underlying native Z3 object. *) - method dispose () = + method dispose = Printf.printf "Disposing %d \n" (Oo.id self) ; (match m_n_obj with | Some (x) -> self#decref x; m_n_obj <- None @@ -70,6 +103,7 @@ class virtual z3object ctx_init obj_init = method get_context = m_ctx +(* method array_to_native a = let f e = e#get_native_object in (Array.map f a) @@ -78,6 +112,7 @@ class virtual z3object ctx_init obj_init = match a with | Some(x) -> (Array.length x) | None -> 0 +*) end From f614f6824e63948123354c6d93597a069478b7d0 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 17:26:28 +0000 Subject: [PATCH 132/248] More ML API Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 158 +++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 0329402dd..a7d59de9f 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,118 +1,118 @@ (* Copyright (C) 2012 Microsoft Corporation Author: CM Wintersteiger (cwinter) 2012-12-17 - *) +*) open Z3enums open Z3native module Log = - struct - let m_is_open = false -(* CMW: "open" seems to be an invalid function name*) - let open_ fn = int2lbool(open_log fn) == L_TRUE - let close = (close_log) - let append s = (append_log s) - end - +struct + let m_is_open = false + (* CMW: "open" seems to be an invalid function name*) + let open_ fn = int2lbool(open_log fn) == L_TRUE + let close = (close_log) + let append s = (append_log s) +end + class virtual idisposable = - object - method virtual dispose : unit - end +object + method virtual dispose : unit +end class context settings = - object (self) - inherit idisposable - val mutable m_n_ctx : Z3native.z3_context option = None - val mutable m_refCount : int = 0 - - initializer - let cfg = mk_config() in - (match settings with - | Some(x) -> - let f e = (set_param_value cfg (fst e) (snd e)) in - (List.iter f x) - | _ -> () - ) ; - m_n_ctx <- Some (mk_context_rc cfg) ; - del_config(cfg) ; - Gc.finalise (fun self -> self#dispose) self - - method dispose : unit = - if m_refCount == 0 then ( - Printf.printf "Disposing %d \n" (Oo.id self) ; - match m_n_ctx with +object (self) + inherit idisposable + val mutable m_n_ctx : Z3native.z3_context option = None + val mutable m_refCount : int = 0 + + initializer + let cfg = mk_config() in + (match settings with + | Some(x) -> + let f e = (set_param_value cfg (fst e) (snd e)) in + (List.iter f x) + | _ -> () + ) ; + m_n_ctx <- Some (mk_context_rc cfg) ; + del_config(cfg) ; + Gc.finalise (fun self -> self#dispose) self + + method dispose : unit = + if m_refCount == 0 then ( + Printf.printf "Disposing %d \n" (Oo.id self) ; + match m_n_ctx with | Some(x) -> (del_context x) | None -> () - ) else ( - (* re-queue for finalization? *) - ) + ) else ( + (* re-queue for finalization? *) + ) - method sub_one_ctx_obj = m_refCount <- m_refCount - 1 - method add_one_ctx_obj = m_refCount <- m_refCount + 1 - end + method sub_one_ctx_obj = m_refCount <- m_refCount - 1 + method add_one_ctx_obj = m_refCount <- m_refCount + 1 +end class virtual z3object ctx_init obj_init = - object (self) - inherit idisposable - val mutable m_ctx : context option = ctx_init - val mutable m_n_obj : Z3native.ptr option = obj_init - - initializer - (match m_n_obj with +object (self) + inherit idisposable + val mutable m_ctx : context option = ctx_init + val mutable m_n_obj : Z3native.ptr option = obj_init + + initializer + (match m_n_obj with | Some (x) -> self#incref x; - (match m_ctx with + (match m_ctx with | Some(x) -> x#add_one_ctx_obj | None -> () - ) + ) | None -> () - ); - Gc.finalise (fun self -> self#dispose) self + ); + Gc.finalise (fun self -> self#dispose) self - method virtual incref : Z3native.ptr -> unit - method virtual decref : Z3native.ptr -> unit - - (* - Disposes of the underlying native Z3 object. - *) - method dispose = - Printf.printf "Disposing %d \n" (Oo.id self) ; - (match m_n_obj with + method virtual incref : Z3native.ptr -> unit + method virtual decref : Z3native.ptr -> unit + + (* + Disposes of the underlying native Z3 object. + *) + method dispose = + Printf.printf "Disposing %d \n" (Oo.id self) ; + (match m_n_obj with | Some (x) -> self#decref x; m_n_obj <- None | None -> () - ); - (match m_ctx with + ); + (match m_ctx with | Some (x) -> x#sub_one_ctx_obj | None -> () - ); - m_ctx <- None + ); + m_ctx <- None - method get_native_object = m_n_obj + method get_native_object = m_n_obj - method set_native_object x = - (match x with + method set_native_object x = + (match x with | Some(x) -> self#incref x | None -> () - ); - (match m_n_obj with + ); + (match m_n_obj with | Some(x) -> self#decref x | None -> () - ); - m_n_obj <- x + ); + m_n_obj <- x - method get_context = m_ctx + method get_context = m_ctx -(* + (* method array_to_native a = - let f e = e#get_native_object in - (Array.map f a) + let f e = e#get_native_object in + (Array.map f a) method array_length a = - match a with - | Some(x) -> (Array.length x) - | None -> 0 -*) + match a with + | Some(x) -> (Array.length x) + | None -> 0 + *) - end +end From c9cca119c5d89296da457b80d8c1fd0300e98aa1 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 20:18:53 +0000 Subject: [PATCH 133/248] File renamed Signed-off-by: Christoph M. Wintersteiger --- examples/ml/{MLExample.ml => mlexample.ml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/ml/{MLExample.ml => mlexample.ml} (100%) diff --git a/examples/ml/MLExample.ml b/examples/ml/mlexample.ml similarity index 100% rename from examples/ml/MLExample.ml rename to examples/ml/mlexample.ml From 0e98d267219e5ad3459030a772c418e9f762b5d7 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 22:25:16 +0000 Subject: [PATCH 134/248] ML API and example compilation. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/README | 10 -- examples/ml/ml_example.ml | 272 +------------------------------------- examples/ml/mlexample.ml | 12 -- scripts/mk_util.py | 33 +---- src/api/ml/z3.ml | 2 +- 5 files changed, 15 insertions(+), 314 deletions(-) delete mode 100644 examples/ml/mlexample.ml diff --git a/examples/ml/README b/examples/ml/README index c61716b65..3e1eb0d1c 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -12,13 +12,3 @@ or LD_LIBRARY_PATH=. ./ml_example.byte for the byte-code version. -If Z3 was installed into the ocamlfind package repository (see src/api/ml/README), -then we can compile this example as follows: - -ocamlfind ocamlc -o ml_example.byte -package Z3 -linkpkg ml_example.ml -ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg ml_example.ml - -Note that the resulting binaries depend on the shared z3 library, which needs to be -in the PATH (Windows), LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX). If Z3 was -installed into ocamlfind, the path that should be added is -`ocamlfind printconf destdir`/Z3 diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 25862b2d7..9c704e4d0 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,269 +4,11 @@ *) open Z3 -open Z3.Symbol -open Z3.Sort -open Z3.Expr -open Z3.Boolean -open Z3.FuncDecl -open Z3.Goal -open Z3.Tactic -open Z3.Tactic.ApplyResult -open Z3.Probe -open Z3.Solver -open Z3.Arithmetic -open Z3.Arithmetic.Integer -open Z3.Arithmetic.Real -open Z3.BitVector - -exception TestFailedException of string - -(** - Model Converter test -*) -let model_converter_test ( ctx : context ) = - Printf.printf "ModelConverterTest\n"; - let xr = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Real.mk_sort ctx)) in - let yr = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Real.mk_sort ctx)) in - let g4 = (mk_goal ctx true false false ) in - (Goal.add g4 [ (mk_gt ctx xr (Real.mk_numeral_nd ctx 10 1)) ]) ; - (Goal.add g4 [ (mk_eq ctx - yr - (Arithmetic.mk_add ctx [ xr; (Real.mk_numeral_nd ctx 1 1) ])) ]) ; - (Goal.add g4 [ (mk_gt ctx yr (Real.mk_numeral_nd ctx 1 1)) ]) ; - ( - let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in - if ((get_num_subgoals ar) == 1 && - ((is_decided_sat (get_subgoal ar 0)) || - (is_decided_unsat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ); - ( - let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") []) g4 None) in - if ((get_num_subgoals ar) == 1 && - ((is_decided_sat (get_subgoal ar 0)) || - (is_decided_unsat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ; - let solver = (mk_solver ctx None) in - let f e = (Solver.add solver [ e ]) in - ignore (List.map f (get_formulas (get_subgoal ar 0))) ; - let q = (check solver []) in - if q != SATISFIABLE then - raise (TestFailedException "") - else - let m = (get_model solver) in - match m with - | None -> raise (TestFailedException "") - | Some (m) -> - Printf.printf "Solver says: %s\n" (string_of_status q) ; - Printf.printf "Model: \n%s\n" (Model.to_string m) ; - Printf.printf "Converted Model: \n%s\n" (Model.to_string (convert_model ar 0 m)) - ) - -(** - Some basic tests. -*) -let basic_tests ( ctx : context ) = - Printf.printf "BasicTests\n" ; -(* let qi = (mk_int ctx 1) in *) - let fname = (mk_string ctx "f") in - let x = (mk_string ctx "x") in - let y = (mk_string ctx "y") in - let bs = (Boolean.mk_sort ctx) in - let domain = [ bs; bs ] in - let f = (FuncDecl.mk_func_decl ctx fname domain bs) in - let fapp = (mk_app ctx f - [ (Expr.mk_const ctx x bs); (Expr.mk_const ctx y bs) ]) in - let fargs2 = [ (mk_fresh_const ctx "cp" bs) ] in - let domain2 = [ bs ] in - let fapp2 = (mk_app ctx (mk_fresh_func_decl ctx "fp" domain2 bs) fargs2) in - let trivial_eq = (mk_eq ctx fapp fapp) in - let nontrivial_eq = (mk_eq ctx fapp fapp2) in - let g = (mk_goal ctx true false false) in - (Goal.add g [ trivial_eq ]) ; - (Goal.add g [ nontrivial_eq ]) ; - Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; - ( - let solver = (mk_solver ctx None) in - (List.iter (fun a -> (Solver.add solver [ a ])) (get_formulas g)) ; - if (check solver []) != SATISFIABLE then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ); - ( - let ar = (Tactic.apply (mk_tactic ctx "simplify") g None) in - if ((get_num_subgoals ar) == 1 && - ((is_decided_sat (get_subgoal ar 0)) || - (is_decided_unsat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ); - ( - let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_sat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ); - (Goal.add g [ (mk_eq ctx - (mk_numeral_int ctx 1 (BitVector.mk_sort ctx 32)) - (mk_numeral_int ctx 2 (BitVector.mk_sort ctx 32))) ] ) - ; - ( - let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_unsat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ); - ( - let g2 = (mk_goal ctx true true false) in - let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_sat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ); - ( - let g2 = (mk_goal ctx true true false) in - (Goal.add g2 [ (Boolean.mk_false ctx) ]) ; - let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_unsat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ); - ( - let g3 = (mk_goal ctx true true false) in - let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Integer.mk_sort ctx)) in - let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Integer.mk_sort ctx)) in - (Goal.add g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (Integer.mk_sort ctx))) ]) ; - (Goal.add g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (Integer.mk_sort ctx))) ]) ; - let constr = (mk_eq ctx xc yc) in - (Goal.add g3 [ constr ] ) ; - let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_unsat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ) ; - model_converter_test ctx ; - (* Real num/den test. *) - let rn = Real.mk_numeral_nd ctx 42 43 in - let inum = (get_numerator rn) in - let iden = get_denominator rn in - Printf.printf "Numerator: %s Denominator: %s\n" (Real.to_string inum) (Real.to_string iden) ; - if ((Real.to_string inum) <> "42" || (Real.to_string iden) <> "43") then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ; - if ((to_decimal_string rn 3) <> "0.976?") then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" - ; - if (to_decimal_string (Real.mk_numeral_s ctx "-1231231232/234234333") 5 <> "-5.25640?") then - raise (TestFailedException "") - else if (to_decimal_string (Real.mk_numeral_s ctx "-123123234234234234231232/234234333") 5 <> "-525641278361333.28170?") then - raise (TestFailedException "") - else if (to_decimal_string (Real.mk_numeral_s ctx "-234234333") 5 <> "-234234333") then - raise (TestFailedException "") - else if (to_decimal_string (Real.mk_numeral_s ctx "234234333/2") 5 <> "117117166.5") then - raise (TestFailedException "") - ; - (* Error handling test. *) - try ( - let i = Integer.mk_numeral_s ctx "1/2" in - raise (TestFailedException "") (* unreachable *) - ) - with Z3native.Exception(_) -> ( - Printf.printf "Exception caught, OK.\n" - ) - -(** - A basic example of how to use quantifiers. -**) -let quantifierExample1 ( ctx : context ) = - Printf.printf "QuantifierExample\n" ; - let is = (Integer.mk_sort ctx) in - let types = [ is; is; is ] in - let names = [ (Symbol.mk_string ctx "x_0"); - (Symbol.mk_string ctx "x_1"); - (Symbol.mk_string ctx "x_2") ] in - let vars = [ (Quantifier.mk_bound ctx 2 (List.nth types 0)); - (Quantifier.mk_bound ctx 2 (List.nth types 1)); - (Quantifier.mk_bound ctx 2 (List.nth types 2)) ] in - let xs = [ (Integer.mk_const ctx (List.nth names 0)); - (Integer.mk_const ctx (List.nth names 1)); - (Integer.mk_const ctx (List.nth names 2)) ] in - - let body_vars = (Boolean.mk_and ctx - [ (mk_eq ctx - (Arithmetic.mk_add ctx [ (List.nth vars 0) ; (Integer.mk_numeral_i ctx 1)]) - (Integer.mk_numeral_i ctx 2)) ; - (mk_eq ctx - (Arithmetic.mk_add ctx [ (List.nth vars 1); (Integer.mk_numeral_i ctx 2)]) - (Arithmetic.mk_add ctx [ (List.nth vars 2); (Integer.mk_numeral_i ctx 3)])) ]) in - let body_const = (Boolean.mk_and ctx - [ (mk_eq ctx - (Arithmetic.mk_add ctx [ (List.nth xs 0); (Integer.mk_numeral_i ctx 1)]) - (Integer.mk_numeral_i ctx 2)) ; - (mk_eq ctx - (Arithmetic.mk_add ctx [ (List.nth xs 1); (Integer.mk_numeral_i ctx 2)]) - (Arithmetic.mk_add ctx [ (List.nth xs 2); (Integer.mk_numeral_i ctx 3)])) ]) in - - let x = (Quantifier.mk_forall ctx types names body_vars (Some 1) [] [] (Some (Symbol.mk_string ctx "Q1")) (Some (Symbol.mk_string ctx "skid1"))) in - Printf.printf "Quantifier X: %s\n" (Quantifier.to_string x) ; - let y = (Quantifier.mk_forall_const ctx xs body_const (Some 1) [] [] (Some (Symbol.mk_string ctx "Q2")) (Some (Symbol.mk_string ctx "skid2"))) in - Printf.printf "Quantifier Y: %s\n" (Quantifier.to_string y) ; - if (is_true (Quantifier.expr_of_quantifier x)) then - raise (TestFailedException "") (* unreachable *) - else if (is_false (Quantifier.expr_of_quantifier x)) then - raise (TestFailedException "") (* unreachable *) - else if (is_const (Quantifier.expr_of_quantifier x)) then - raise (TestFailedException "") (* unreachable *) - -let _ = - try ( - if not (Log.open_ "z3.log") then - raise (TestFailedException "Log couldn't be opened.") - else - ( - Printf.printf "Running Z3 version %s\n" Version.to_string ; - let cfg = [("model", "true"); ("proof", "false")] in - let ctx = (mk_context cfg) in - let is = (Symbol.mk_int ctx 42) in - let ss = (Symbol.mk_string ctx "mySymbol") in - let bs = (Boolean.mk_sort ctx) in - let ints = (Integer.mk_sort ctx) in - let rs = (Real.mk_sort ctx) in - Printf.printf "int symbol: %s\n" (Symbol.to_string is); - Printf.printf "string symbol: %s\n" (Symbol.to_string ss); - Printf.printf "bool sort: %s\n" (Sort.to_string bs); - Printf.printf "int sort: %s\n" (Sort.to_string ints); - Printf.printf "real sort: %s\n" (Sort.to_string rs); - basic_tests ctx ; - quantifierExample1 ctx ; - Printf.printf "Disposing...\n"; - Gc.full_major () - ); - Printf.printf "Exiting.\n" ; - exit 0 - ) with Z3native.Exception(msg) -> ( - Printf.printf "Z3 EXCEPTION: %s\n" msg ; - exit 1 - ) + +let _ = ignore(Log.open_ "z3.log") ; + let cfg = Some [("model", "true"); ("proof", "false")] in + let ctx = (new context cfg) in + Printf.printf "Disposing...\n"; + ctx#dispose ; + Printf.printf "Exiting.\n"; ;; diff --git a/examples/ml/mlexample.ml b/examples/ml/mlexample.ml deleted file mode 100644 index 8cc248206..000000000 --- a/examples/ml/mlexample.ml +++ /dev/null @@ -1,12 +0,0 @@ -(* - Copyright (C) 2012 Microsoft Corporation - Author: CM Wintersteiger (cwinter) 2012-12-17 - *) - - open Z3 - - let _ = ignore(Log.open_ "z3.log") ; -let cfg = Some [("model", "true"); ("proof", "false")] in -let ctx = (new context cfg) in -ctx#dispose -;; diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 40828f8c3..38af3893f 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1435,10 +1435,6 @@ class MLComponent(Component): bld_dir = os.path.join(BUILD_DIR, 'api', 'ml') mk_dir(bld_dir) libfile = '%s$(SO_EXT)' % self.lib_name - # for mlfile in get_ml_files(self.src_dir): - # out.write('%si: libz3$(SO_EXT) %s\n' % (os.path.join('api', 'ml', mlfile),os.path.join(self.to_src_dir, mlfile))) - # out.write('\tocamlopt -I %s -i %s > %si\n' % (os.path.join('api', 'ml'), os.path.join(self.to_src_dir, mlfile), os.path.join('api', 'ml', mlfile))) - # out.write('\tocamlopt -I %s -c %si \n' % (os.path.join('api', 'ml'), os.path.join('api','ml', mlfile))) out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'z3native.c'))) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) @@ -1446,11 +1442,9 @@ class MLComponent(Component): out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) out.write('z3.cmxa: %s\n' % libfile) - out.write('\tcd %s && ocamlbuild -lflags -cclib,../../../%s/libz3ml.so,-cclib,../../../%s/libz3.so -build-dir ../../../%s/api/ml z3.cmxa && cd -\n' % (self.to_src_dir,BUILD_DIR,BUILD_DIR,BUILD_DIR)) - out.write('\tcp api/ml/z3.cmxa .\n') + out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) out.write('z3.cma: %s\n' % libfile) - out.write('\tcd %s && ocamlbuild -lflags -custom,-cclib,../../../%s/libz3ml.so,-cclib,../../../%s/libz3.so -build-dir ../../../%s/api/ml z3.cma && cd -\n' % (self.to_src_dir,BUILD_DIR,BUILD_DIR,BUILD_DIR)) - out.write('\tcp api/ml/z3.cma .\n') + out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -custom,-cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3native$(OBJ_EXT) z3.cma && cd -\n' % (self.to_src_dir,BUILD_DIR)) out.write('ml: z3.cmxa z3.cma\n') out.write('\n') @@ -1575,36 +1569,23 @@ class MLExampleComponent(ExampleComponent): def mk_makefile(self, out): if ML_ENABLED: - out.write('ml_example.byte: api/ml/z3ml.cmxa ') + out.write('ml_example.byte: z3.cma ') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') - out.write('\t%s ' % OCAMLC) - if DEBUG_MODE: - out.write('-g ') - out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" nums.cma z3ml.cma') + out.write('\tocamlc -g -o ml_example.byte -I . z3.cma -I api/ml') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('ml_example$(EXE_EXT): api/ml/z3ml.cmxa ml_example.byte') + out.write('ml_example($EXE_EXT): z3.cmxa ') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') - out.write('\t%s ' % OCAMLOPT) - if DEBUG_MODE: - out.write('-g ') - out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" nums.cmxa z3ml.cmxa') + out.write('\tocamlopt -g -o ml_example -I . z3.cmxa -I api/ml') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('_ex_%s: z3.cmxa' % self.name) - deps = '' - for mlfile in get_ml_files(self.ex_dir): - out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) - if IS_WINDOWS: - deps = deps.replace('/', '\\') - out.write('%s\n' % deps) - out.write('\tcd %s && ocamlbuild -build-dir ../../%s -lib z3 MLExample.native && cd -\n\n' % (self.to_src_dir, BUILD_DIR)) + out.write('_ex_%s: ml_example.byte ml_example($EXE_EXT)\n\n' % self.name) class PythonExampleComponent(ExampleComponent): def __init__(self, name, path): diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index a7d59de9f..68edd9b42 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -76,7 +76,7 @@ object (self) Disposes of the underlying native Z3 object. *) method dispose = - Printf.printf "Disposing %d \n" (Oo.id self) ; + Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with | Some (x) -> self#decref x; m_n_obj <- None | None -> () From 50560ba791c23f89ad40178e4930f7fec24155d8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 19 Dec 2012 23:31:42 +0000 Subject: [PATCH 135/248] more ML API Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 94 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 68edd9b42..9812bd790 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -23,48 +23,42 @@ end class context settings = object (self) inherit idisposable - val mutable m_n_ctx : Z3native.z3_context option = None + + val mutable m_n_ctx : Z3native.z3_context = + let cfg = mk_config() in + let f e = (set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = mk_context_rc cfg in + del_config(cfg) ; + v + val mutable m_refCount : int = 0 - initializer - let cfg = mk_config() in - (match settings with - | Some(x) -> - let f e = (set_param_value cfg (fst e) (snd e)) in - (List.iter f x) - | _ -> () - ) ; - m_n_ctx <- Some (mk_context_rc cfg) ; - del_config(cfg) ; - Gc.finalise (fun self -> self#dispose) self + initializer Gc.finalise (fun self -> self#dispose) self method dispose : unit = if m_refCount == 0 then ( Printf.printf "Disposing %d \n" (Oo.id self) ; - match m_n_ctx with - | Some(x) -> (del_context x) - | None -> () + (del_context m_n_ctx) ) else ( (* re-queue for finalization? *) ) method sub_one_ctx_obj = m_refCount <- m_refCount - 1 method add_one_ctx_obj = m_refCount <- m_refCount + 1 + method get_native = m_n_ctx end class virtual z3object ctx_init obj_init = object (self) inherit idisposable - val mutable m_ctx : context option = ctx_init + val mutable m_ctx : context = ctx_init val mutable m_n_obj : Z3native.ptr option = obj_init initializer (match m_n_obj with | Some (x) -> self#incref x; - (match m_ctx with - | Some(x) -> x#add_one_ctx_obj - | None -> () - ) + m_ctx#add_one_ctx_obj | None -> () ); Gc.finalise (fun self -> self#dispose) self @@ -78,15 +72,9 @@ object (self) method dispose = Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with - | Some (x) -> self#decref x; m_n_obj <- None + | Some (x) -> self#decref x; m_n_obj <- None; m_ctx#sub_one_ctx_obj | None -> () ); - (match m_ctx with - | Some (x) -> x#sub_one_ctx_obj - | None -> () - ); - m_ctx <- None - method get_native_object = m_n_obj @@ -102,6 +90,7 @@ object (self) m_n_obj <- x method get_context = m_ctx + method get_native_context = m_ctx#get_native (* method array_to_native a = @@ -113,6 +102,57 @@ object (self) | Some(x) -> (Array.length x) | None -> 0 *) +end + +class symbol ctx_init obj_init = +object (self) + inherit z3object ctx_init obj_init + + method incref o = () + method decref o = () + + method kind = match m_n_obj with + | Some(x) -> (int2symbol_kind (get_symbol_kind self#get_native_context x)) + | _ -> raise (Exception "Underlying object lost") + + method is_int_symbol = match m_n_obj with + | Some(x) -> self#kind == INT_SYMBOL + | _ -> false + + method is_string_symbol = match m_n_obj with + | Some(x) -> self#kind == STRING_SYMBOL + | _ -> false + + method to_string = match m_n_obj with + | Some(x) -> + ( + match self#kind with + | INT_SYMBOL -> (string_of_int (get_symbol_int self#get_native_context x)) + | STRING_SYMBOL -> (get_symbol_string self#get_native_context x) + ) + | None -> "" + + method create ctx obj = + match obj with + | Some(x) -> ( + match (int2symbol_kind (get_symbol_kind ctx#get_native x)) with + | INT_SYMBOL -> (new intsymbol ctx obj :> symbol) + | STRING_SYMBOL -> (new stringsymbol ctx obj :> symbol) + ) + | None -> raise (Exception "Can't create null objects") end +and intsymbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init + + method get_int = match m_n_obj with + | Some(x) -> (get_symbol_int m_ctx#get_native x) + | None -> 0 +end + +and stringsymbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init +end From 1685e3dd6fbf3341aadc1d6b9bfa72722b65e061 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 20 Dec 2012 04:10:38 +0000 Subject: [PATCH 136/248] ML API bugfixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 20 +++++-- scripts/update_api.py | 22 ++++--- src/api/ml/z3.ml | 121 +++++++++++++++++++++++--------------- 3 files changed, 99 insertions(+), 64 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 9c704e4d0..c79b3cdaa 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,11 +4,19 @@ *) open Z3 - -let _ = ignore(Log.open_ "z3.log") ; - let cfg = Some [("model", "true"); ("proof", "false")] in - let ctx = (new context cfg) in - Printf.printf "Disposing...\n"; - ctx#dispose ; + +exception ExampleException of string + +let _ = + if not (Log.open_ "z3.log") then + raise (ExampleException "Log couldn't be opened.") + else + ( + Printf.printf "Running Z3 version %s\n" Version.to_string ; + let cfg = [("model", "true"); ("proof", "false")] in + let ctx = (new context cfg) in + Printf.printf "Disposing...\n"; + ctx#dispose (* can do, but we'd rather let it go out of scope *) ; + ); Printf.printf "Exiting.\n"; ;; diff --git a/scripts/update_api.py b/scripts/update_api.py index a586ad6e3..25adce2af 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1,4 +1,3 @@ - ############################################ # Copyright (c) 2012 Microsoft Corporation # @@ -328,16 +327,12 @@ def param2ml(p): if k == OUT: if param_type(p) == INT or param_type(p) == UINT or param_type(p) == INT64 or param_type(p) == UINT64: return "int" - elif param_type(p) == INT64 or param_type(p) == UINT64 or param_type(p) >= FIRST_OBJ_ID: - return "int" elif param_type(p) == STRING: return "string" else: return "ptr" elif k == IN_ARRAY or k == INOUT_ARRAY or k == OUT_ARRAY: return "%s array" % type2ml(param_type(p)) - elif k == OUT_MANAGED_ARRAY: - return "%s array" % type2ml(param_type(p)); else: return type2ml(param_type(p)) @@ -1131,9 +1126,16 @@ def mk_ml(): ml_native.write('%s -> ' % param2ml(p)) if len(op) > 0: ml_native.write('(') - ml_native.write('%s' % type2ml(result)) + first = True + if result != VOID or len(op) == 0: + ml_native.write('%s' % type2ml(result)) + first = False for p in op: - ml_native.write(' * %s' % param2ml(p)) + if first: + first = False + else: + ml_native.write(' * ') + ml_native.write('%s' % param2ml(p)) if len(op) > 0: ml_native.write(')') ml_native.write('\n') @@ -1160,11 +1162,13 @@ def mk_ml(): i = i + 1 ml_native.write(' = \n') ml_native.write(' ') - if result == VOID: + if result == VOID and len(op) == 0: ml_native.write('let _ = ') else: ml_native.write('let res = ') ml_native.write('(ML2C.n_%s' % (ml_method_name(name))) + if len(ip) == 0: + ml_native.write(' ()') first = True i = 0; for p in params: @@ -1177,7 +1181,7 @@ def mk_ml(): ml_native.write(' if err <> OK then\n') ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (error_code2int err)))\n') ml_native.write(' else\n') - if result == VOID: + if result == VOID and len(op) == 0: ml_native.write(' ()\n') else: ml_native.write(' res\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 9812bd790..31bb7e5fc 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -9,12 +9,27 @@ open Z3native module Log = struct let m_is_open = false - (* CMW: "open" seems to be an invalid function name*) - let open_ fn = int2lbool(open_log fn) == L_TRUE - let close = (close_log) - let append s = (append_log s) + (* CMW: "open" seems to be an invalid function name*) + let open_ fn = let rv = (open_log fn) in + Printf.printf "ol returned %d\n" rv ; + ((int2lbool rv) == L_TRUE) + let close = close_log + let append s = append_log s end - + +module Version = +struct + let major = let (x, _, _, _) = get_version in x + let minor = let (_, x, _, _) = get_version in x + let build = let (_, _, x, _) = get_version in x + let revision = let (_, _, _, x) = get_version in x + let to_string = + string_of_int major ^ "." ^ + string_of_int minor ^ "." ^ + string_of_int build ^ "." ^ + string_of_int revision ^ "." +end + class virtual idisposable = object method virtual dispose : unit @@ -25,7 +40,7 @@ object (self) inherit idisposable val mutable m_n_ctx : Z3native.z3_context = - let cfg = mk_config() in + let cfg = mk_config in let f e = (set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; let v = mk_context_rc cfg in @@ -34,14 +49,15 @@ object (self) val mutable m_refCount : int = 0 - initializer Gc.finalise (fun self -> self#dispose) self + initializer + Gc.finalise (fun self -> self#dispose) self method dispose : unit = if m_refCount == 0 then ( Printf.printf "Disposing %d \n" (Oo.id self) ; (del_context m_n_ctx) ) else ( - (* re-queue for finalization? *) + (* re-queue for finalization? *) ) method sub_one_ctx_obj = m_refCount <- m_refCount - 1 @@ -66,9 +82,9 @@ object (self) method virtual incref : Z3native.ptr -> unit method virtual decref : Z3native.ptr -> unit - (* - Disposes of the underlying native Z3 object. - *) + (* + Disposes of the underlying native Z3 object. + *) method dispose = Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with @@ -92,16 +108,17 @@ object (self) method get_context = m_ctx method get_native_context = m_ctx#get_native - (* - method array_to_native a = +(* + method array_to_native a = let f e = e#get_native_object in (Array.map f a) - method array_length a = + method array_length a = match a with - | Some(x) -> (Array.length x) - | None -> 0 - *) + | Some(x) -> (Array.length x) + | None -> 0 +*) + end class symbol ctx_init obj_init = @@ -110,49 +127,55 @@ object (self) method incref o = () method decref o = () +end - method kind = match m_n_obj with - | Some(x) -> (int2symbol_kind (get_symbol_kind self#get_native_context x)) - | _ -> raise (Exception "Underlying object lost") +class int_symbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init +end - method is_int_symbol = match m_n_obj with - | Some(x) -> self#kind == INT_SYMBOL - | _ -> false +class string_symbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init +end - method is_string_symbol = match m_n_obj with - | Some(x) -> self#kind == STRING_SYMBOL - | _ -> false - - method to_string = match m_n_obj with - | Some(x) -> - ( - match self#kind with - | INT_SYMBOL -> (string_of_int (get_symbol_int self#get_native_context x)) - | STRING_SYMBOL -> (get_symbol_string self#get_native_context x) - ) - | None -> "" - - method create ctx obj = +module Symbol = +struct + let create ctx obj = match obj with | Some(x) -> ( match (int2symbol_kind (get_symbol_kind ctx#get_native x)) with - | INT_SYMBOL -> (new intsymbol ctx obj :> symbol) - | STRING_SYMBOL -> (new stringsymbol ctx obj :> symbol) + | INT_SYMBOL -> (new int_symbol ctx obj :> symbol) + | STRING_SYMBOL -> (new string_symbol ctx obj :> symbol) ) | None -> raise (Exception "Can't create null objects") -end + let kind o = match o#m_n_obj with + | Some(x) -> (int2symbol_kind (get_symbol_kind o#get_native_context x)) + | _ -> raise (Exception "Underlying object lost") -and intsymbol ctx_init obj_init = -object(self) - inherit symbol ctx_init obj_init + let is_int_symbol o = match o#m_n_obj with + | Some(x) -> x#kind == INT_SYMBOL + | _ -> false - method get_int = match m_n_obj with - | Some(x) -> (get_symbol_int m_ctx#get_native x) + let is_string_symbol o = match o#m_n_obj with + | Some(x) -> x#kind == STRING_SYMBOL + | _ -> false + + let get_int o = match o#m_n_obj with + | Some(x) -> (get_symbol_int o#get_native_context x) | None -> 0 -end -and stringsymbol ctx_init obj_init = -object(self) - inherit symbol ctx_init obj_init + let get_string o = match o#m_n_obj with + | Some(x) -> (get_symbol_string o#get_native_context x) + | None -> "" + + let to_string o = match o#m_n_obj with + | Some(x) -> + ( + match (kind o) with + | INT_SYMBOL -> (string_of_int (get_symbol_int o#get_native_context x)) + | STRING_SYMBOL -> (get_symbol_string o#get_native_context x) + ) + | None -> "" end From 18a57267d1cf13d59dabcff027db7c4801ec4012 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 20 Dec 2012 04:12:41 +0000 Subject: [PATCH 137/248] added temporary Makefile for ML annotations. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/api/ml/Makefile diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile new file mode 100644 index 000000000..f97a2dc30 --- /dev/null +++ b/src/api/ml/Makefile @@ -0,0 +1,6 @@ +# This is a temporary support file for emacs annotations. +# It does not compile the Z3 ML API; this will be built +# in the top-level build directory. + +all: + ocamlbuild -cflag -annot z3.cmxa \ No newline at end of file From cfa099007a2c93628ab5fae0acdf32224d1dc483 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 20 Dec 2012 20:51:18 +0000 Subject: [PATCH 138/248] ML build system checks Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 5 +- src/api/ml/z3.ml | 127 +++++++++++++++++++-------------------------- 2 files changed, 55 insertions(+), 77 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 38af3893f..a0f123609 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1439,7 +1439,7 @@ class MLComponent(Component): for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, self.to_src_dir)) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) out.write('z3.cmxa: %s\n' % libfile) out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) @@ -1577,7 +1577,7 @@ class MLExampleComponent(ExampleComponent): for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('ml_example($EXE_EXT): z3.cmxa ') + out.write('ml_example($EXE_EXT): z3.cmxa ml_example.byte') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') @@ -2434,6 +2434,7 @@ def mk_bindings(api_files): _execfile(os.path.join('scripts', 'update_api.py'), g) # HACK cp_z3py_to_build() if is_ml_enabled(): + check_ml() mk_z3consts_ml(api_files) # Extract enumeration types from API files, and add python definitions. diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 31bb7e5fc..4f847bc48 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -10,26 +10,11 @@ module Log = struct let m_is_open = false (* CMW: "open" seems to be an invalid function name*) - let open_ fn = let rv = (open_log fn) in - Printf.printf "ol returned %d\n" rv ; - ((int2lbool rv) == L_TRUE) - let close = close_log - let append s = append_log s + let open_ fn = int2lbool(open_log fn) == L_TRUE + let close = (close_log) + let append s = (append_log s) end - -module Version = -struct - let major = let (x, _, _, _) = get_version in x - let minor = let (_, x, _, _) = get_version in x - let build = let (_, _, x, _) = get_version in x - let revision = let (_, _, _, x) = get_version in x - let to_string = - string_of_int major ^ "." ^ - string_of_int minor ^ "." ^ - string_of_int build ^ "." ^ - string_of_int revision ^ "." -end - + class virtual idisposable = object method virtual dispose : unit @@ -40,7 +25,7 @@ object (self) inherit idisposable val mutable m_n_ctx : Z3native.z3_context = - let cfg = mk_config in + let cfg = mk_config() in let f e = (set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; let v = mk_context_rc cfg in @@ -49,15 +34,14 @@ object (self) val mutable m_refCount : int = 0 - initializer - Gc.finalise (fun self -> self#dispose) self + initializer Gc.finalise (fun self -> self#dispose) self method dispose : unit = if m_refCount == 0 then ( Printf.printf "Disposing %d \n" (Oo.id self) ; (del_context m_n_ctx) ) else ( - (* re-queue for finalization? *) + (* re-queue for finalization? *) ) method sub_one_ctx_obj = m_refCount <- m_refCount - 1 @@ -82,9 +66,9 @@ object (self) method virtual incref : Z3native.ptr -> unit method virtual decref : Z3native.ptr -> unit - (* - Disposes of the underlying native Z3 object. - *) + (* + Disposes of the underlying native Z3 object. + *) method dispose = Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with @@ -108,17 +92,16 @@ object (self) method get_context = m_ctx method get_native_context = m_ctx#get_native -(* - method array_to_native a = + (* + method array_to_native a = let f e = e#get_native_object in (Array.map f a) - method array_length a = + method array_length a = match a with - | Some(x) -> (Array.length x) - | None -> 0 -*) - + | Some(x) -> (Array.length x) + | None -> 0 + *) end class symbol ctx_init obj_init = @@ -127,55 +110,49 @@ object (self) method incref o = () method decref o = () -end -class int_symbol ctx_init obj_init = -object(self) - inherit symbol ctx_init obj_init -end + method kind = match m_n_obj with + | Some(x) -> (int2symbol_kind (get_symbol_kind self#get_native_context x)) + | _ -> raise (Exception "Underlying object lost") -class string_symbol ctx_init obj_init = -object(self) - inherit symbol ctx_init obj_init -end + method is_int_symbol = match m_n_obj with + | Some(x) -> self#kind == INT_SYMBOL + | _ -> false -module Symbol = -struct - let create ctx obj = + method is_string_symbol = match m_n_obj with + | Some(x) -> self#kind == STRING_SYMBOL + | _ -> false + + method to_string = match m_n_obj with + | Some(x) -> + ( + match self#kind with + | INT_SYMBOL -> (string_of_int (get_symbol_int self#get_native_context x)) + | STRING_SYMBOL -> (get_symbol_string self#get_native_context x) + ) + | None -> "" + + method create ctx obj = match obj with | Some(x) -> ( match (int2symbol_kind (get_symbol_kind ctx#get_native x)) with - | INT_SYMBOL -> (new int_symbol ctx obj :> symbol) - | STRING_SYMBOL -> (new string_symbol ctx obj :> symbol) + | INT_SYMBOL -> (new intsymbol ctx obj :> symbol) + | STRING_SYMBOL -> (new stringsymbol ctx obj :> symbol) ) | None -> raise (Exception "Can't create null objects") - let kind o = match o#m_n_obj with - | Some(x) -> (int2symbol_kind (get_symbol_kind o#get_native_context x)) - | _ -> raise (Exception "Underlying object lost") - - let is_int_symbol o = match o#m_n_obj with - | Some(x) -> x#kind == INT_SYMBOL - | _ -> false - - let is_string_symbol o = match o#m_n_obj with - | Some(x) -> x#kind == STRING_SYMBOL - | _ -> false - - let get_int o = match o#m_n_obj with - | Some(x) -> (get_symbol_int o#get_native_context x) - | None -> 0 - - let get_string o = match o#m_n_obj with - | Some(x) -> (get_symbol_string o#get_native_context x) - | None -> "" - - let to_string o = match o#m_n_obj with - | Some(x) -> - ( - match (kind o) with - | INT_SYMBOL -> (string_of_int (get_symbol_int o#get_native_context x)) - | STRING_SYMBOL -> (get_symbol_string o#get_native_context x) - ) - | None -> "" +end + +and intsymbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init + + method get_int = match m_n_obj with + | Some(x) -> (get_symbol_int m_ctx#get_native x) + | None -> 0 +end + +and stringsymbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init end From d8ed9be98e9224b9abfc37d90b1ea7879b35a3f0 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 21 Dec 2012 03:02:12 +0000 Subject: [PATCH 139/248] ML native layer bugfixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- scripts/update_api.py | 165 +++++++++++++++++++++++++----------------- src/api/ml/z3.ml | 120 +++++++++++++++++------------- 3 files changed, 171 insertions(+), 116 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index a0f123609..e44c120cb 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2888,7 +2888,7 @@ def mk_z3consts_ml(api_files): linenum = linenum + 1 efile.write('end\n') if VERBOSE: - print "Generated '%s/enumerations.ml'" % ('%s' % gendir) + print "Generated '%s/z3enums.ml'" % ('%s' % gendir) def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index 25adce2af..d0ef2ec86 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1,3 +1,4 @@ + ############################################ # Copyright (c) 2012 Microsoft Corporation # @@ -1097,6 +1098,45 @@ def is_array_param(p): else: return False +def arrayparams(params): + op = [] + for param in params: + if is_array_param(param): + op.append(param) + return op + + +def ml_unwrap(t): + if t == STRING: + return 'String_val' + elif t == BOOL or t == INT or PRINT_MODE or ERROR_CODE: + return 'Int_val' + elif t == UINT: + return 'Unsigned_int_val' + elif t == INT64: + return 'Long_val' + elif t == UINT64: + return 'Unsigned_long_val' + elif t == DOUBLE: + return 'Double_val' + else: + return 'Data_custom_val' + +def ml_set_wrap(t, d, n): + if t == VOID: + return d + ' = Val_unit;' + elif t == BOOL or t == INT or t == UINT or PRINT_MODE or ERROR_CODE: + return d + ' = Val_int(' + n + ');' + elif t == INT64 or t == UINT64: + return d + ' = Val_long(' + n + ');' + elif t == DOUBLE: + return 'Store_double_val(' + d + ', ' + n + ');' + elif t == STRING: + return d + ' = caml_copy_string((const char*) ' + n + ');' + else: + ts = type2str(t) + return d + ' = caml_alloc_custom(0, sizeof(' + ts + '), 0, 1); memcpy( Data_custom_val(' + d + '), &' + n + ', sizeof(' + ts + '));' + def mk_ml(): global Type2Str if not is_ml_enabled(): @@ -1242,15 +1282,12 @@ def mk_ml(): for name, result, params in _dotnet_decls: ip = inparams(params) op = outparams(params) + ap = arrayparams(params) ret_size = len(op) if result != VOID: ret_size = ret_size + 1 # Setup frame - n_locals = 0 - for p in params: - if is_out_param(p) or (is_in_param(p) and param_type(p) == STRING): - n_locals = n_locals + 1 ml_wrapper.write('CAMLprim value n_%s(' % ml_method_name(name)) first = True i = 0 @@ -1276,46 +1313,50 @@ def mk_ml(): i = i + 1 ml_wrapper.write(');\n') i = 0 - first = True - if result != VOID: - n_locals = n_locals + 1 - if ret_size > 1: - n_locals = n_locals + 1 - if n_locals > 0: - ml_wrapper.write(' CAMLlocal%s(' % (n_locals)) - if ret_size > 1: - if result != VOID: - ml_wrapper.write('result, ') - ml_wrapper.write('result_tuple') - first = False - elif result != VOID: - ml_wrapper.write('result') - first = False + if len(op) + len(ap) == 0: + ml_wrapper.write(' CAMLlocal1(result);\n') + else: + c = 0 for p in params: - if is_out_param(p) or (is_in_param(p) and param_type(p) == STRING): - if first: - first = False - else: - ml_wrapper.write(', ') - ml_wrapper.write('_a%s' % i) + if is_out_param(p) or is_array_param(p): + c = c + 1 + ml_wrapper.write(' CAMLlocal%s(result, res_val' % (c+2)) + for p in params: + if is_out_param(p) or is_array_param(p): + ml_wrapper.write(', _a%s_val' % i) i = i + 1 ml_wrapper.write(');\n') # preprocess arrays, strings, in/out arguments i = 0 for param in params: - if param_kind(param) == OUT_ARRAY: - ml_wrapper.write(' _a%s = (long) malloc(sizeof(%s) * ((long)a%s));\n' % (i, - type2str(param_type(param)), - param_array_capacity_pos(param))) - elif param_kind(param) == IN and param_type(param) == STRING: - ml_wrapper.write(' _a%s = (value) String_val(a%s);\n' % (i, i)) + k = param_kind(param) + if k == OUT_ARRAY: + ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * (_a%s));\n' % ( + type2str(param_type(param)), + i, + type2str(param_type(param)), + type2str(param_type(param)), + param_array_capacity_pos(param))) + elif k == IN_ARRAY or k == INOUT_ARRAY: + t = param_type(param) + ts = type2str(t) + ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) + ml_wrapper.write(' for (unsigned i = 0; i < a%s; i++) _a%s[i] = (%s) %s(Field(a%s, i));\n' % (param_array_capacity_pos(param), i, ts, ml_unwrap(t), i)) + elif k == IN: + t = param_type(param) + ml_wrapper.write(' %s _a%s = (%s) %s(a%s);\n' % (type2str(t), i, type2str(t), ml_unwrap(t), i)) + elif k == OUT: + ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) + elif k == INOUT: + ml_wrapper.write(' %s _a%s = a%s;\n' % (type2str(param_type(param)), i, i)) + i = i + 1 # invoke procedure ml_wrapper.write(' ') if result != VOID: - ml_wrapper.write('result = (value) ') + ml_wrapper.write('%s z3_result = ' % type2str(result)) ml_wrapper.write('%s(' % name) i = 0 first = True @@ -1326,58 +1367,50 @@ def mk_ml(): ml_wrapper.write(', ') k = param_kind(param) if k == OUT or k == INOUT: - ml_wrapper.write('(%s)&_a%s' % (param2str(param), i)) - elif k == INOUT_ARRAY or k == IN_ARRAY: - ml_wrapper.write('(%s*)a%s' % (type2str(param_type(param)), i)) - elif k == OUT_ARRAY: - ml_wrapper.write('(%s*)_a%s' % (type2str(param_type(param)), i)) - elif k == IN and param_type(param) == STRING: - ml_wrapper.write('(Z3_string) _a%s' % i) + ml_wrapper.write('&_a%s' % i) else: - ml_wrapper.write('(%s)a%i' % (param2str(param), i)) + ml_wrapper.write('_a%i' % i) i = i + 1 ml_wrapper.write(');\n') - # return tuples + # convert output params if len(op) > 0: - ml_wrapper.write(' result_tuple = caml_alloc(%s, 0);\n' % ret_size) + if result != VOID: + ml_wrapper.write(' %s\n' % ml_set_wrap(result, "res_val", "z3_result")) + i = 0; + for p in params: + if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: + ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) + ml_wrapper.write(' for (unsigned i = 0; i < _a%s; i++) { value t; %s Store_field(_a%s, i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[i]'), i)) + elif is_out_param(p): + ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) + i = i + 1 + + # return tuples + if len(op) == 0: + ml_wrapper.write(' %s\n' % ml_set_wrap(result, "result", "z3_result")) + else: + ml_wrapper.write(' result = caml_alloc(%s, 0);\n' % ret_size) i = j = 0 if result != VOID: - if result == STRING: - ml_wrapper.write(' Store_field(result_tuple, 0, caml_copy_string(result));\n') - else: - ml_wrapper.write(' Store_field(result_tuple, 0, result);\n') + ml_wrapper.write(' Store_field(result, 0, res_val);\n') j = j + 1 for p in params: - if param_kind(p) == OUT_ARRAY or param_kind(p) == OUT: - ml_wrapper.write(' Store_field(result_tuple, %s, _a%s);\n' % (j, i)) - j = j + 1; - elif is_out_param(p): - if param_type(p) == STRING: - ml_wrapper.write(' Store_field(result_tuple, %s, caml_copy_string((const char *)_a%s));\n' % (j, i)) - else: - ml_wrapper.write(' Store_field(result_tuple, %s, a%s);\n' % (j, i)) + if is_out_param(p): + ml_wrapper.write(' Store_field(result, %s, _a%s_val);\n' % (j, i)) j = j + 1; i = i + 1 # local array cleanup i = 0 for p in params: - if param_kind(p) == OUT_ARRAY: - ml_wrapper.write(' free((long*)_a%s);\n' % i) + k = param_kind(p) + if k == OUT_ARRAY or k == IN_ARRAY or k == INOUT_ARRAY: + ml_wrapper.write(' free(_a%s);\n' % i) i = i + 1 # return - if len(op) > 0: - ml_wrapper.write(' CAMLreturn(result_tuple);\n') - else: - if result == STRING: - ml_wrapper.write(' CAMLreturn(caml_copy_string((const char*) result));\n') - elif result == VOID: - ml_wrapper.write(' CAMLreturn(Val_unit);\n') - elif result != VOID: - ml_wrapper.write(' CAMLreturn(result);\n') - + ml_wrapper.write(' CAMLreturn(result);\n') ml_wrapper.write('}\n\n') if len(ip) > 5: ml_wrapper.write('CAMLprim value n_%s_bytecode(value * argv, int argn) {\n' % ml_method_name(name)) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 4f847bc48..d1ba2b746 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -10,11 +10,25 @@ module Log = struct let m_is_open = false (* CMW: "open" seems to be an invalid function name*) - let open_ fn = int2lbool(open_log fn) == L_TRUE - let close = (close_log) - let append s = (append_log s) + let open_ fn = ((int2lbool (open_log fn)) == L_TRUE) + let close = close_log + let append s = append_log s end - + +module Version = +struct + let major = let (x, _, _, _) = get_version in x + let minor = let (_, x, _, _) = get_version in x + let build = let (_, _, x, _) = get_version in x + let revision = let (_, _, _, x) = get_version in x + let to_string = + let (mj, mn, bld, rev) = get_version in + string_of_int mj ^ "." ^ + string_of_int mn ^ "." ^ + string_of_int bld ^ "." ^ + string_of_int rev ^ "." +end + class virtual idisposable = object method virtual dispose : unit @@ -25,7 +39,7 @@ object (self) inherit idisposable val mutable m_n_ctx : Z3native.z3_context = - let cfg = mk_config() in + let cfg = mk_config in let f e = (set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; let v = mk_context_rc cfg in @@ -34,14 +48,15 @@ object (self) val mutable m_refCount : int = 0 - initializer Gc.finalise (fun self -> self#dispose) self + initializer + Gc.finalise (fun self -> self#dispose) self method dispose : unit = if m_refCount == 0 then ( - Printf.printf "Disposing %d \n" (Oo.id self) ; + Printf.printf "Disposing context %d \n" (Oo.id self) ; (del_context m_n_ctx) ) else ( - (* re-queue for finalization? *) + (* re-queue for finalization? *) ) method sub_one_ctx_obj = m_refCount <- m_refCount - 1 @@ -66,9 +81,9 @@ object (self) method virtual incref : Z3native.ptr -> unit method virtual decref : Z3native.ptr -> unit - (* - Disposes of the underlying native Z3 object. - *) + (* + Disposes of the underlying native Z3 object. + *) method dispose = Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with @@ -92,16 +107,17 @@ object (self) method get_context = m_ctx method get_native_context = m_ctx#get_native - (* - method array_to_native a = +(* + method array_to_native a = let f e = e#get_native_object in (Array.map f a) - method array_length a = + method array_length a = match a with - | Some(x) -> (Array.length x) - | None -> 0 - *) + | Some(x) -> (Array.length x) + | None -> 0 +*) + end class symbol ctx_init obj_init = @@ -110,49 +126,55 @@ object (self) method incref o = () method decref o = () +end - method kind = match m_n_obj with - | Some(x) -> (int2symbol_kind (get_symbol_kind self#get_native_context x)) - | _ -> raise (Exception "Underlying object lost") +class int_symbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init +end - method is_int_symbol = match m_n_obj with - | Some(x) -> self#kind == INT_SYMBOL - | _ -> false +class string_symbol ctx_init obj_init = +object(self) + inherit symbol ctx_init obj_init +end - method is_string_symbol = match m_n_obj with - | Some(x) -> self#kind == STRING_SYMBOL - | _ -> false - - method to_string = match m_n_obj with - | Some(x) -> - ( - match self#kind with - | INT_SYMBOL -> (string_of_int (get_symbol_int self#get_native_context x)) - | STRING_SYMBOL -> (get_symbol_string self#get_native_context x) - ) - | None -> "" - - method create ctx obj = +module Symbol = +struct + let create ctx obj = match obj with | Some(x) -> ( match (int2symbol_kind (get_symbol_kind ctx#get_native x)) with - | INT_SYMBOL -> (new intsymbol ctx obj :> symbol) - | STRING_SYMBOL -> (new stringsymbol ctx obj :> symbol) + | INT_SYMBOL -> (new int_symbol ctx obj :> symbol) + | STRING_SYMBOL -> (new string_symbol ctx obj :> symbol) ) | None -> raise (Exception "Can't create null objects") -end + let kind o = match o#m_n_obj with + | Some(x) -> (int2symbol_kind (get_symbol_kind o#get_native_context x)) + | _ -> raise (Exception "Underlying object lost") -and intsymbol ctx_init obj_init = -object(self) - inherit symbol ctx_init obj_init + let is_int_symbol o = match o#m_n_obj with + | Some(x) -> x#kind == INT_SYMBOL + | _ -> false - method get_int = match m_n_obj with - | Some(x) -> (get_symbol_int m_ctx#get_native x) + let is_string_symbol o = match o#m_n_obj with + | Some(x) -> x#kind == STRING_SYMBOL + | _ -> false + + let get_int o = match o#m_n_obj with + | Some(x) -> (get_symbol_int o#get_native_context x) | None -> 0 -end -and stringsymbol ctx_init obj_init = -object(self) - inherit symbol ctx_init obj_init + let get_string o = match o#m_n_obj with + | Some(x) -> (get_symbol_string o#get_native_context x) + | None -> "" + + let to_string o = match o#m_n_obj with + | Some(x) -> + ( + match (kind o) with + | INT_SYMBOL -> (string_of_int (get_symbol_int o#get_native_context x)) + | STRING_SYMBOL -> (get_symbol_string o#get_native_context x) + ) + | None -> "" end From 7ae90f0b20ef3dc24e0f220f9f30db1ca870dd0c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 21 Dec 2012 07:18:46 +0000 Subject: [PATCH 140/248] More ML API: Fixes in native layer. Added symbols. Prepared code for automatic documentation. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 5 ++ scripts/mk_util.py | 89 +------------------- scripts/update_api.py | 37 ++++++--- src/api/ml/z3.ml | 168 ++++++++++++++++++++++++++------------ 4 files changed, 148 insertions(+), 151 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index c79b3cdaa..7046a92b0 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,6 +4,7 @@ *) open Z3 +open Z3.Context exception ExampleException of string @@ -15,6 +16,10 @@ let _ = Printf.printf "Running Z3 version %s\n" Version.to_string ; let cfg = [("model", "true"); ("proof", "false")] in let ctx = (new context cfg) in + let is = (mk_symbol_int ctx 42) in + let ss = (mk_symbol_string ctx "mySymbol") in + Printf.printf "int symbol: %s\n" (Symbol.to_string (is :> symbol)); + Printf.printf "string symbol: %s\n" (Symbol.to_string (ss :> symbol)); Printf.printf "Disposing...\n"; ctx#dispose (* can do, but we'd rather let it go out of scope *) ; ); diff --git a/scripts/mk_util.py b/scripts/mk_util.py index e44c120cb..5ca0d2299 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2777,99 +2777,12 @@ def mk_z3consts_ml(api_files): efile.write(' | %s \n' % k[3:]) # strip Z3_ efile.write('\n') efile.write('(** Convert %s to int*)\n' % name[3:]) - efile.write('let int_of_%s x : int =\n' % (name[3:])) # strip Z3_ - efile.write(' match x with\n') - for k, i in decls.iteritems(): - efile.write(' | %s -> %d\n' % (k[3:], i)) - efile.write('\n') - efile.write('(** Convert int to %s*)\n' % name[3:]) - efile.write('let %s_of_int x : %s =\n' % (name[3:],name[3:])) # strip Z3_ - efile.write(' match x with\n') - for k, i in decls.iteritems(): - efile.write(' | %d -> %s\n' % (i, k[3:])) - # use Z3.Exception? - efile.write(' | _ -> raise (Failure "undefined enum value")\n\n') - mode = SEARCHING - else: - if words[2] != '': - if len(words[2]) > 1 and words[2][1] == 'x': - idx = int(words[2], 16) - else: - idx = int(words[2]) - decls[words[1]] = idx - idx = idx + 1 - linenum = linenum + 1 - if VERBOSE: - print "Generated '%s/z3enums.ml'" % ('%s' % gendir) - efile = open('%s.mli' % os.path.join(gendir, "z3enums"), 'w') - efile.write('(* Automatically generated file *)\n\n') - efile.write('(** The enumeration types of Z3. *)\n\n') - efile.write('module Z3enums = struct\n') - for api_file in api_files: - api_file_c = ml.find_file(api_file, ml.name) - api_file = os.path.join(api_file_c.src_dir, api_file) - - api = open(api_file, 'r') - - SEARCHING = 0 - FOUND_ENUM = 1 - IN_ENUM = 2 - - mode = SEARCHING - decls = {} - idx = 0 - - linenum = 1 - for line in api: - m1 = blank_pat.match(line) - m2 = comment_pat.match(line) - if m1 or m2: - # skip blank lines and comments - linenum = linenum + 1 - elif mode == SEARCHING: - m = typedef_pat.match(line) - if m: - mode = FOUND_ENUM - m = typedef2_pat.match(line) - if m: - mode = IN_ENUM - decls = {} - idx = 0 - elif mode == FOUND_ENUM: - m = openbrace_pat.match(line) - if m: - mode = IN_ENUM - decls = {} - idx = 0 - else: - assert False, "Invalid %s, line: %s" % (api_file, linenum) - else: - assert mode == IN_ENUM - words = re.split('[^\-a-zA-Z0-9_]+', line) - m = closebrace_pat.match(line) - if m: - name = words[1] - if name not in DeprecatedEnums: - efile.write('(** %s *)\n' % name[3:]) - efile.write('type %s =\n' % name[3:]) # strip Z3_ - for k, i in decls.iteritems(): - efile.write(' | %s \n' % k[3:]) # strip Z3_ - efile.write('\n') - efile.write('(** Convert %s to int*)\n' % name[3:]) - efile.write('val int_of_%s : %s -> int\n' % (name[3:], name[3:])) # strip Z3_ - efile.write('(** Convert int to %s*)\n' % name[3:]) - efile.write('val %s_of_int : int -> %s\n' % (name[3:],name[3:])) # strip Z3_ - efile.write('\n') - efile.write('\n(* %s *)\n' % name) - efile.write('type %s =\n' % name[3:]) # strip Z3_ - for k, i in decls.iteritems(): - efile.write(' | %s \n' % k[3:]) # strip Z3_ - efile.write('\n') efile.write('let %s2int x : int =\n' % (name[3:])) # strip Z3_ efile.write(' match x with\n') for k, i in decls.iteritems(): efile.write(' | %s -> %d\n' % (k[3:], i)) efile.write('\n') + efile.write('(** Convert int to %s*)\n' % name[3:]) efile.write('let int2%s x : %s =\n' % (name[3:],name[3:])) # strip Z3_ efile.write(' match x with\n') for k, i in decls.iteritems(): diff --git a/scripts/update_api.py b/scripts/update_api.py index d0ef2ec86..c8cd05c7e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1106,26 +1106,26 @@ def arrayparams(params): return op -def ml_unwrap(t): +def ml_unwrap(t, ts, s): if t == STRING: - return 'String_val' - elif t == BOOL or t == INT or PRINT_MODE or ERROR_CODE: - return 'Int_val' + return '(' + ts + ') String_val(' + s + ')' + elif t == BOOL or t == INT or t == PRINT_MODE or t == ERROR_CODE: + return '(' + ts + ') Int_val(' + s + ')' elif t == UINT: - return 'Unsigned_int_val' + return '(' + ts + ') Unsigned_int_val(' + s + ')' elif t == INT64: - return 'Long_val' + return '(' + ts + ') Long_val(' + s + ')' elif t == UINT64: - return 'Unsigned_long_val' + return '(' + ts + ') Unsigned_long_val(' + s + ')' elif t == DOUBLE: - return 'Double_val' + return '(' + ts + ') Double_val(' + s + ')' else: - return 'Data_custom_val' + return '* (' + ts + '*) Data_custom_val(' + s + ')' def ml_set_wrap(t, d, n): if t == VOID: return d + ' = Val_unit;' - elif t == BOOL or t == INT or t == UINT or PRINT_MODE or ERROR_CODE: + elif t == BOOL or t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE: return d + ' = Val_int(' + n + ');' elif t == INT64 or t == UINT64: return d + ' = Val_long(' + n + ');' @@ -1135,7 +1135,7 @@ def ml_set_wrap(t, d, n): return d + ' = caml_copy_string((const char*) ' + n + ');' else: ts = type2str(t) - return d + ' = caml_alloc_custom(0, sizeof(' + ts + '), 0, 1); memcpy( Data_custom_val(' + d + '), &' + n + ', sizeof(' + ts + '));' + return d + ' = caml_alloc_custom(&default_custom_ops, sizeof(' + ts + '), 0, 1); memcpy( Data_custom_val(' + d + '), &' + n + ', sizeof(' + ts + '));' def mk_ml(): global Type2Str @@ -1146,7 +1146,9 @@ def mk_ml(): ml_wrapperf = os.path.join(ml_dir, 'z3native.c') ml_native = open(ml_nativef, 'w') ml_native.write('(* Automatically generated file *)\n\n') + ml_native.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') ml_native.write('open Z3enums\n\n') + ml_native.write('(**/**)\n') ml_native.write('type ptr\n') ml_native.write('and z3_symbol = ptr\n') for k, v in Type2Str.iteritems(): @@ -1226,6 +1228,7 @@ def mk_ml(): else: ml_native.write(' res\n') ml_native.write('\n') + ml_native.write('(**/**)\n') # C interface ml_wrapper = open(ml_wrapperf, 'w') @@ -1276,6 +1279,14 @@ def mk_ml(): ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') ml_wrapper.write(' CAMLxparam3(X11,X12,X13); \n') ml_wrapper.write('\n\n') + ml_wrapper.write('static struct custom_operations default_custom_ops = {\n') + ml_wrapper.write(' identifier: "default handling",\n') + ml_wrapper.write(' finalize: custom_finalize_default,\n') + ml_wrapper.write(' compare: custom_compare_default,\n') + ml_wrapper.write(' hash: custom_hash_default,\n') + ml_wrapper.write(' serialize: custom_serialize_default,\n') + ml_wrapper.write(' deserialize: custom_deserialize_default\n') + ml_wrapper.write('};\n\n') ml_wrapper.write('#ifdef __cplusplus\n') ml_wrapper.write('extern "C" {\n') ml_wrapper.write('#endif\n\n') @@ -1342,10 +1353,10 @@ def mk_ml(): t = param_type(param) ts = type2str(t) ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) - ml_wrapper.write(' for (unsigned i = 0; i < a%s; i++) _a%s[i] = (%s) %s(Field(a%s, i));\n' % (param_array_capacity_pos(param), i, ts, ml_unwrap(t), i)) + ml_wrapper.write(' for (unsigned i = 0; i < _a%s; i++) _a%s[i] = %s;\n' % (param_array_capacity_pos(param), i, ml_unwrap(t, ts, 'Field(a' + str(i) + ', i)'))) elif k == IN: t = param_type(param) - ml_wrapper.write(' %s _a%s = (%s) %s(a%s);\n' % (type2str(t), i, type2str(t), ml_unwrap(t), i)) + ml_wrapper.write(' %s _a%s = %s;\n' % (type2str(t), i, ml_unwrap(t, type2str(t), 'a' + str(i)))) elif k == OUT: ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) elif k == INOUT: diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index d1ba2b746..321b17c82 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,33 +1,17 @@ -(* +(** + The Z3 ML/Ocaml Interface. + Copyright (C) 2012 Microsoft Corporation - Author: CM Wintersteiger (cwinter) 2012-12-17 + @author CM Wintersteiger (cwinter) 2012-12-17 *) open Z3enums open Z3native -module Log = -struct - let m_is_open = false - (* CMW: "open" seems to be an invalid function name*) - let open_ fn = ((int2lbool (open_log fn)) == L_TRUE) - let close = close_log - let append s = append_log s -end +(**/**) -module Version = -struct - let major = let (x, _, _, _) = get_version in x - let minor = let (_, x, _, _) = get_version in x - let build = let (_, _, x, _) = get_version in x - let revision = let (_, _, _, x) = get_version in x - let to_string = - let (mj, mn, bld, rev) = get_version in - string_of_int mj ^ "." ^ - string_of_int mn ^ "." ^ - string_of_int bld ^ "." ^ - string_of_int rev ^ "." -end +(* Object definitions. These are internal and should be interacted + with only via the corresponding functions from modules. *) class virtual idisposable = object @@ -61,7 +45,7 @@ object (self) method sub_one_ctx_obj = m_refCount <- m_refCount - 1 method add_one_ctx_obj = m_refCount <- m_refCount + 1 - method get_native = m_n_ctx + method gno = m_n_ctx end class virtual z3object ctx_init obj_init = @@ -91,9 +75,9 @@ object (self) | None -> () ); - method get_native_object = m_n_obj + method gno = m_n_obj - method set_native_object x = + method sno x = (match x with | Some(x) -> self#incref x | None -> () @@ -105,11 +89,11 @@ object (self) m_n_obj <- x method get_context = m_ctx - method get_native_context = m_ctx#get_native + method gnc = m_ctx#gno (* method array_to_native a = - let f e = e#get_native_object in + let f e = e#gno in (Array.map f a) method array_length a = @@ -120,61 +104,145 @@ object (self) end -class symbol ctx_init obj_init = +class symbol ctx obj = object (self) - inherit z3object ctx_init obj_init + inherit z3object ctx obj method incref o = () method decref o = () end -class int_symbol ctx_init obj_init = +class int_symbol ctx = object(self) - inherit symbol ctx_init obj_init + inherit symbol ctx None + method cnstr_obj obj = (self#sno obj) ; self + method cnstr_int i = (self#sno (Some (mk_int_symbol ctx#gno i))) ; self end -class string_symbol ctx_init obj_init = +class string_symbol ctx = object(self) - inherit symbol ctx_init obj_init + inherit symbol ctx None + method cnstr_obj obj = (self#sno obj) ; self + method cnstr_string name = (self#sno (Some (mk_string_symbol ctx#gno name))) ; self end +(**/**) + +(** 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. *) +module Log = +struct + (** Open an interaction log file. + @param filename the name of the file to open. + @return True if opening the log file succeeds, false otherwise. + *) + (* CMW: "open" seems to be a reserved keyword? *) + let open_ filename = ((int2lbool (open_log filename)) == L_TRUE) + + (** Closes the interaction log. *) + let close = close_log + + (** Appends a user-provided string to the interaction log. + @param s the string to append*) + let append s = append_log s +end + +(** Version information. *) +module Version = +struct + (** The major version. *) + let major = let (x, _, _, _) = get_version in x + + (** The minor version. *) + let minor = let (_, x, _, _) = get_version in x + + (** The build version. *) + let build = let (_, _, x, _) = get_version in x + + (** The revision. *) + let revision = let (_, _, _, x) = get_version in x + + (** A string representation of the version information. *) + let to_string = + let (mj, mn, bld, rev) = get_version in + string_of_int mj ^ "." ^ + string_of_int mn ^ "." ^ + string_of_int bld ^ "." ^ + string_of_int rev ^ "." +end + +(** Symbols are used to name several term and type constructors. *) module Symbol = struct +(**/**) let create ctx obj = match obj with | Some(x) -> ( - match (int2symbol_kind (get_symbol_kind ctx#get_native x)) with - | INT_SYMBOL -> (new int_symbol ctx obj :> symbol) - | STRING_SYMBOL -> (new string_symbol ctx obj :> symbol) + match (int2symbol_kind (get_symbol_kind ctx#gno x)) with + | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj obj) :> symbol) + | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj obj) :> symbol) ) | None -> raise (Exception "Can't create null objects") +(**/**) - let kind o = match o#m_n_obj with - | Some(x) -> (int2symbol_kind (get_symbol_kind o#get_native_context x)) + (** The kind of the symbol (int or string) *) + let kind (o : symbol) = match o#gno with + | Some(x) -> (int2symbol_kind (get_symbol_kind o#gnc x)) | _ -> raise (Exception "Underlying object lost") - let is_int_symbol o = match o#m_n_obj with - | Some(x) -> x#kind == INT_SYMBOL + (** Indicates whether the symbol is of Int kind *) + let is_int_symbol (o : symbol) = match o#gno with + | Some(x) -> (kind o) == INT_SYMBOL | _ -> false - let is_string_symbol o = match o#m_n_obj with - | Some(x) -> x#kind == STRING_SYMBOL + (** Indicates whether the symbol is of string kind. *) + let is_string_symbol (o : symbol) = match o#gno with + | Some(x) -> (kind o) == STRING_SYMBOL | _ -> false - let get_int o = match o#m_n_obj with - | Some(x) -> (get_symbol_int o#get_native_context x) + (** The int value of the symbol. *) + let get_int (o : int_symbol) = match o#gno with + | Some(x) -> (get_symbol_int o#gnc x) | None -> 0 - let get_string o = match o#m_n_obj with - | Some(x) -> (get_symbol_string o#get_native_context x) + (** The string value of the symbol. *) + let get_string (o : string_symbol) = match o#gno with + | Some(x) -> (get_symbol_string o#gnc x) | None -> "" - let to_string o = match o#m_n_obj with + (** A string representation of the symbol. *) + let to_string (o : symbol) = match o#gno with | Some(x) -> ( match (kind o) with - | INT_SYMBOL -> (string_of_int (get_symbol_int o#get_native_context x)) - | STRING_SYMBOL -> (get_symbol_string o#get_native_context x) + | INT_SYMBOL -> (string_of_int (get_symbol_int o#gnc x)) + | STRING_SYMBOL -> (get_symbol_string o#gnc x) ) | None -> "" end + +(** The main interaction with Z3 happens via the Context. *) +module Context = +struct + (** + 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. + *) + let mk_symbol_int ctx i = + (new int_symbol ctx)#cnstr_int i + + (** Creates a new symbol using a string. *) + let mk_symbol_string ctx s = + (new string_symbol ctx)#cnstr_string s + + (** + Create an array of symbols. + *) + let mk_symbols ctx names = + let f elem = mk_symbol_string ctx elem in + (Array.map f names) + +end From a2ad7d91bc29b8cec52a2fceed1aa5d655966bf4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 00:51:07 +0000 Subject: [PATCH 141/248] New ML API savepoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/Makefile | 6 +- src/api/ml/z3.ml | 5746 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 5659 insertions(+), 93 deletions(-) diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile index f97a2dc30..4d4a6c08f 100644 --- a/src/api/ml/Makefile +++ b/src/api/ml/Makefile @@ -3,4 +3,8 @@ # in the top-level build directory. all: - ocamlbuild -cflag -annot z3.cmxa \ No newline at end of file + ocamlbuild -cflag -annot z3.cmxa + +doc: *.ml + mkdir -p doc + ocamldoc -html -d doc -I ../../../bld_dbg/api/ml *.ml -hide Z3 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 321b17c82..2100f371e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -6,7 +6,6 @@ *) open Z3enums -open Z3native (**/**) @@ -18,27 +17,28 @@ object method virtual dispose : unit end +(** Context objects *) class context settings = object (self) inherit idisposable val mutable m_n_ctx : Z3native.z3_context = - let cfg = mk_config in - let f e = (set_param_value cfg (fst e) (snd e)) in + let cfg = Z3native.mk_config in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; - let v = mk_context_rc cfg in - del_config(cfg) ; + let v = Z3native.mk_context_rc cfg in + Z3native.del_config(cfg) ; v val mutable m_refCount : int = 0 initializer Gc.finalise (fun self -> self#dispose) self - + method dispose : unit = if m_refCount == 0 then ( Printf.printf "Disposing context %d \n" (Oo.id self) ; - (del_context m_n_ctx) + (Z3native.del_context m_n_ctx) ) else ( (* re-queue for finalization? *) ) @@ -48,6 +48,8 @@ object (self) method gno = m_n_ctx end + +(** Z3 objects *) class virtual z3object ctx_init obj_init = object (self) inherit idisposable @@ -56,14 +58,14 @@ object (self) initializer (match m_n_obj with - | Some (x) -> self#incref x; + | Some (x) -> self#incref m_ctx#gno x; m_ctx#add_one_ctx_obj | None -> () ); Gc.finalise (fun self -> self#dispose) self - method virtual incref : Z3native.ptr -> unit - method virtual decref : Z3native.ptr -> unit + method virtual incref : Z3native.ptr -> Z3native.ptr -> unit + method virtual decref : Z3native.ptr -> Z3native.ptr -> unit (* Disposes of the underlying native Z3 object. @@ -71,61 +73,415 @@ object (self) method dispose = Printf.printf "Disposing z3object %d \n" (Oo.id self) ; (match m_n_obj with - | Some (x) -> self#decref x; m_n_obj <- None; m_ctx#sub_one_ctx_obj + | Some (x) -> self#decref m_ctx#gno x; m_n_obj <- None; m_ctx#sub_one_ctx_obj | None -> () ); - method gno = m_n_obj + method gno = match m_n_obj with + | Some(x) -> x + | None -> raise (Z3native.Exception "Z3 object lost") - method sno x = - (match x with - | Some(x) -> self#incref x - | None -> () - ); + method sno nc o = + self#incref nc o ; (match m_n_obj with - | Some(x) -> self#decref x + | Some(x) -> self#decref nc x | None -> () ); - m_n_obj <- x + m_n_obj <- Some o - method get_context = m_ctx + method gc = m_ctx method gnc = m_ctx#gno - -(* - method array_to_native a = - let f e = e#gno in - (Array.map f a) - - method array_length a = - match a with - | Some(x) -> (Array.length x) - | None -> 0 -*) - end -class symbol ctx obj = + +(** Parameter set objects *) +class params ctx obj = object (self) - inherit z3object ctx obj - - method incref o = () - method decref o = () + inherit z3object ctx obj as super + method incref ctx o = Z3native.params_inc_ref ctx o + method decref ctx o = Z3native.params_dec_ref ctx o end + +(** Symbol objects *) +class symbol ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method incref ctx o = () + method decref ctx o = () +end + +let symbolaton (a : symbol array) = + let f (e : symbol) = e#gno in + Array.map f a + +(** Int symbol objects *) class int_symbol ctx = object(self) - inherit symbol ctx None - method cnstr_obj obj = (self#sno obj) ; self - method cnstr_int i = (self#sno (Some (mk_int_symbol ctx#gno i))) ; self + inherit symbol ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_int i = (self#sno ctx#gno (Z3native.mk_int_symbol ctx#gno i)) ; self end +(** String symbol objects *) class string_symbol ctx = object(self) - inherit symbol ctx None - method cnstr_obj obj = (self#sno obj) ; self - method cnstr_string name = (self#sno (Some (mk_string_symbol ctx#gno name))) ; self + inherit symbol ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_string name = (self#sno ctx#gno (Z3native.mk_string_symbol ctx#gno name)) ; self end +let create_symbol ctx no = + match (int2symbol_kind (Z3native.get_symbol_kind ctx#gno no)) with + | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj no) :> symbol) + | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj no) :> symbol) + +(** AST objects *) +class ast ctx = +object (self) + inherit z3object ctx None as super (* CMW: derive from icomparable? *) + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + + method incref nc o = Z3native.inc_ref nc o + method decref nc o = Z3native.dec_ref nc o +end + +let astaton (a : ast array) = + let f (e : ast) = e#gno in + Array.map f a + +(** Sort objects *) +class sort ctx = +object (self) + inherit ast ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Arithmetic sort objects, i.e., Int or Real. *) +class arith_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Array sorts objects *) +class array_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx#gno (Z3native.mk_array_sort ctx#gno domain#gno range#gno)) ; self +end + +(** Bit-vector sort objects *) +class bitvec_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Boolean sort objects *) +class bool_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Datatype sort objects *) +class datatype_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_sc (name : symbol) constructors = (self#sno ctx#gno (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (astaton constructors)))) ; self +end + +(** Enum sort objects *) +class enum_sort ctx = +object (self) + inherit sort ctx as super + val mutable _constdecls = None + val mutable _testerdecls = None + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_ss (name : symbol) (enum_names : symbol array) = + let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in + _constdecls <- Some a ; + _testerdecls <- Some b ; + (self#sno ctx#gno r) ; + self + + method const_decls = match _constdecls with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing const decls") + + method tester_decls = match _testerdecls with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing tester decls") +end + +(** Int sort objects *) +class int_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Real sort objects *) +class real_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Uninterpreted sort objects *) +class uninterpreted_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_s (s : symbol) = (self #sno ctx#gno (Z3native.mk_uninterpreted_sort ctx#gno s#gno)) ; self +end + +(** Finite domain sort objects *) +class finite_domain_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx#gno (Z3native.mk_finite_domain_sort ctx#gno s#gno sz)) ; self +end + +(** Relation sort objects *) +class relation_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** List sort objects *) +class list_sort ctx = +object (self) + inherit sort ctx as super + val mutable _nildecl = None + val mutable _is_nildecl = None + val mutable _consdecl = None + val mutable _is_consdecl = None + val mutable _headdecl = None + val mutable _taildecl = None + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_ss (name : symbol) (elem_sort : sort) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in + _nildecl <- Some a ; + _is_nildecl <- Some b ; + _consdecl <- Some c ; + _is_consdecl <- Some d ; + _headdecl <- Some e ; + _taildecl <- Some f ; + (self#sno ctx#gno r) ; + self + + method nil_decl = match _nildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing nil decl") + + method is_nil_decl = match _is_nildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing is_nil decls") + + method cons_decl = match _consdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing cons decls") + + method is_cons_decl = match _is_consdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing is_cons decls") + + method head_decl = match _headdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing head decls") + + method tail_decl = match _taildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing tail decls") + +end + +(** Set sort objects *) +class set_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_s (s : sort) = (self#sno ctx#gno s#gno) ; self +end + +(** Tuple sort objects *) +class tuple_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_siss (name : symbol) (num_fields: int) (field_names : symbol array) (field_sorts : sort array) = + let (x,_,_) = (Z3native.mk_tuple_sort ctx#gno name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in + (self#sno ctx#gno x) ; + self +end + +let create_sort ctx obj = + match (int2sort_kind (Z3native.get_sort_kind ctx#gno obj)) with + | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) + | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) + | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) + | DATATYPE_SORT -> (((new datatype_sort ctx)#cnstr_obj obj) :> sort) + | INT_SORT -> (((new int_sort ctx)#cnstr_obj obj) :> sort) + | REAL_SORT -> (((new real_sort ctx)#cnstr_obj obj) :> sort) + | UNINTERPRETED_SORT -> (((new uninterpreted_sort ctx)#cnstr_obj obj) :> sort) + | FINITE_DOMAIN_SORT -> (((new finite_domain_sort ctx)#cnstr_obj obj) :> sort) + | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + +(** Function declaration objects *) +class func_decl ctx = +object (self) + inherit ast ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx#gno (Z3native.mk_func_decl ctx#gno name#gno (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx#gno (Z3native.mk_fresh_func_decl ctx#gno prefix (Array.length domain) (astaton domain) range#gno)) ; self + + method incref nc o = super#incref nc o + method decref nc o = super#decref nc o +end + +class parameter = +object (self) + val mutable m_kind : parameter_kind = PARAMETER_INT; + val mutable m_i : int = 0 + val mutable m_d : float = 0.0 + val mutable m_sym : symbol option = None + val mutable m_srt : sort option = None + val mutable m_ast : ast option = None + val mutable m_fd : func_decl option = None + val mutable m_r : string = "" + + method cnstr_int i = m_kind <- PARAMETER_INT; m_i <- i + method cnstr_double d = m_kind <- PARAMETER_DOUBLE; m_d <- d + method cnstr_symbol sym = m_kind <- PARAMETER_SYMBOL; m_sym <- sym + method cnstr_sort srt = m_kind <- PARAMETER_SORT; m_srt <- srt + method cnstr_ast ast = m_kind <- PARAMETER_AST; m_ast <- ast + method cnstr_func_decl fd = m_kind <- PARAMETER_FUNC_DECL; m_fd <- fd + method cnstr_rational r = m_kind <- PARAMETER_RATIONAL; m_r <- r + + method kind = m_kind + method int = m_i + method double = m_d + method symbol = match m_sym with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing parameter symbol") + method sort = match m_srt with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing parameter sort") + method ast = match m_ast with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing parameter ast") + method func_decl = match m_fd with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing parameter func_decl") + method rational = m_r +end + +(** Expression objects *) +class expr ctx = +object(self) + inherit ast ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +let expraton (a : expr array) = + let f (e : expr) = e#gno in + Array.map f a + +(** Boolean expression objects *) +class bool_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Arithmetic expression objects (int/real) *) +class arith_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Int expression objects *) +class int_expr ctx = +object (self) + inherit arith_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Real expression objects *) +class real_expr ctx = +object (self) + inherit arith_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Bit-vector expression objects *) +class bitvec_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Array expression objects *) +class array_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Datatype expression objects *) +class datatype_expr ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Integer numeral expression objects *) +class int_num ctx = +object (self) + inherit int_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Rational numeral expression objects *) +class rat_num ctx = +object (self) + inherit real_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Bit-vector numeral expression objects *) +class bitvec_num ctx = +object (self) + inherit bitvec_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + +(** Algebraic numeral expression objects *) +class algebraic_num ctx = +object (self) + inherit arith_expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + + +(** Quantifier objects *) +class quantifier ctx = +object (self) + inherit expr ctx as super + method cnstr_obj obj = (self#sno ctx#gno obj) ; self +end + + + (**/**) (** Interaction logging for Z3. @@ -138,34 +494,34 @@ struct @return True if opening the log file succeeds, false otherwise. *) (* CMW: "open" seems to be a reserved keyword? *) - let open_ filename = ((int2lbool (open_log filename)) == L_TRUE) + let open_ filename = ((int2lbool (Z3native.open_log filename)) == L_TRUE) (** Closes the interaction log. *) - let close = close_log + let close = Z3native.close_log (** Appends a user-provided string to the interaction log. @param s the string to append*) - let append s = append_log s + let append s = Z3native.append_log s end (** Version information. *) module Version = struct (** The major version. *) - let major = let (x, _, _, _) = get_version in x + let major = let (x, _, _, _) = Z3native.get_version in x (** The minor version. *) - let minor = let (_, x, _, _) = get_version in x + let minor = let (_, x, _, _) = Z3native.get_version in x (** The build version. *) - let build = let (_, _, x, _) = get_version in x + let build = let (_, _, x, _) = Z3native.get_version in x (** The revision. *) - let revision = let (_, _, _, x) = get_version in x + let revision = let (_, _, _, x) = Z3native.get_version in x (** A string representation of the version information. *) let to_string = - let (mj, mn, bld, rev) = get_version in + let (mj, mn, bld, rev) = Z3native.get_version in string_of_int mj ^ "." ^ string_of_int mn ^ "." ^ string_of_int bld ^ "." ^ @@ -174,75 +530,5281 @@ end (** Symbols are used to name several term and type constructors. *) module Symbol = -struct -(**/**) - let create ctx obj = - match obj with - | Some(x) -> ( - match (int2symbol_kind (get_symbol_kind ctx#gno x)) with - | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj obj) :> symbol) - | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj obj) :> symbol) - ) - | None -> raise (Exception "Can't create null objects") -(**/**) - +struct (** The kind of the symbol (int or string) *) - let kind (o : symbol) = match o#gno with - | Some(x) -> (int2symbol_kind (get_symbol_kind o#gnc x)) - | _ -> raise (Exception "Underlying object lost") + let kind (o : symbol) = (int2symbol_kind (Z3native.get_symbol_kind o#gnc o#gno)) (** Indicates whether the symbol is of Int kind *) - let is_int_symbol (o : symbol) = match o#gno with - | Some(x) -> (kind o) == INT_SYMBOL - | _ -> false + let is_int_symbol (o : symbol) = (kind o) == INT_SYMBOL (** Indicates whether the symbol is of string kind. *) - let is_string_symbol (o : symbol) = match o#gno with - | Some(x) -> (kind o) == STRING_SYMBOL - | _ -> false + let is_string_symbol (o : symbol) = (kind o) == STRING_SYMBOL (** The int value of the symbol. *) - let get_int (o : int_symbol) = match o#gno with - | Some(x) -> (get_symbol_int o#gnc x) - | None -> 0 + let get_int (o : int_symbol) = Z3native.get_symbol_int o#gnc o#gno (** The string value of the symbol. *) - let get_string (o : string_symbol) = match o#gno with - | Some(x) -> (get_symbol_string o#gnc x) - | None -> "" + let get_string (o : string_symbol) = Z3native.get_symbol_string o#gnc o#gno (** A string representation of the symbol. *) - let to_string (o : symbol) = match o#gno with - | Some(x) -> - ( - match (kind o) with - | INT_SYMBOL -> (string_of_int (get_symbol_int o#gnc x)) - | STRING_SYMBOL -> (get_symbol_string o#gnc x) - ) - | None -> "" + let to_string (o : symbol) = + match (kind o) with + | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int o#gnc o#gno)) + | STRING_SYMBOL -> (Z3native.get_symbol_string o#gnc o#gno) end -(** The main interaction with Z3 happens via the Context. *) + +(** + The Sort module implements type information for ASTs. +*) +module Sort = +struct + (** + Comparison operator. + @param a A sort + @param b A sort + @return True if and are from the same context + and represent the same sort; false otherwise. + *) + let ( = ) (a : sort) (b : sort) = (a == b) || + if a#gnc != b#gnc then + false + else + ((int2lbool (Z3native.is_eq_sort a#gnc a#gno b#gno)) == L_TRUE) + + (** + Returns a unique identifier for the sort. + *) + let get_id (x : sort) = Z3native.get_sort_id x#gnc x#gno + + (** + The kind of the sort. + *) + let get_sort_kind (x : sort) = (int2sort_kind (Z3native.get_sort_kind x#gnc x#gno)) + + (** + The name of the sort + *) + let get_name (x : sort) = (create_symbol x#gc (Z3native.get_sort_name x#gnc x#gno)) + + (** + A string representation of the sort. + *) + let to_string (x : sort) = Z3native.sort_to_string x#gnc x#gno +end + +(** Array sorts *) +module ArraySort = +struct + (** The domain of the array sort. *) + let get_domain (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_domain x#gnc x#gno) + + (** The range of the array sort. *) + let get_range (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_range x#gnc x#gno) +end + +(** Bit-vector sorts *) +module BitVectorSort = +struct + (** The size of the bit-vector sort. *) + let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno +end + +(** Finite domain sorts. *) +module FiniteDomainSort = +struct + (** The size of the finite domain sort. *) + let get_size (x : finite_domain_sort) = + let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") +end + +(** Relation sorts. *) +module RelationSort = +struct + (** The arity of the relation sort. *) + let get_arity (x : relation_sort) = Z3native.get_relation_arity x#gnc x#gno + + (** The sorts of the columns of the relation sort. *) + let get_column_sorts (x : relation_sort) = + let n = get_arity x in + let f i = create_sort x#gc (Z3native.get_relation_column x#gnc x#gno i) in + Array.init n f + +end + +(**/**) +let create_expr ctx obj = + if int2ast_kind (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then + (((new quantifier ctx)#cnstr_obj obj) :> expr) + else + let s = Z3native.get_sort ctx#gno obj in + let sk = (int2sort_kind (Z3native.get_sort_kind ctx#gno s)) in + if (int2lbool (Z3native.is_algebraic_number ctx#gno obj) == L_TRUE) then + (((new algebraic_num ctx)#cnstr_obj obj) :> expr) + else + if ((int2lbool (Z3native.is_numeral_ast ctx#gno obj)) == L_TRUE) && + (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + match sk with + | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) + | REAL_SORT -> (((new rat_num ctx)#cnstr_obj obj) :> expr) + | BV_SORT -> (((new bitvec_num ctx)#cnstr_obj obj) :> expr) + | _ -> raise (Z3native.Exception "Unsupported numeral object") + else + match sk with + | BOOL_SORT -> (((new bool_expr ctx)#cnstr_obj obj) :> expr) + | INT_SORT -> (((new int_expr ctx)#cnstr_obj obj) :> expr) + | REAL_SORT -> (((new real_expr ctx)#cnstr_obj obj) :> expr) + | BV_SORT -> (((new bitvec_expr ctx)#cnstr_obj obj) :> expr) + | ARRAY_SORT -> (((new array_expr ctx)#cnstr_obj obj) :> expr) + | DATATYPE_SORT -> (((new datatype_expr ctx)#cnstr_obj obj) :> expr) + | _ -> (new expr ctx)#cnstr_obj obj + +let create_expr_fa (ctx : context) (f : func_decl) (args : expr array) = + let o = Z3native.mk_app ctx#gno f#gno (Array.length args) (astaton args) in + create_expr ctx o + +let create_ast ctx no = + match (int2ast_kind (Z3native.get_ast_kind ctx#gno no)) with + | FUNC_DECL_AST -> (((new func_decl ctx)#cnstr_obj no) :> ast) + | QUANTIFIER_AST -> (((new quantifier ctx)#cnstr_obj no) :> ast) + | SORT_AST -> ((create_sort ctx no) :> ast) + | APP_AST + | NUMERAL_AST + | VAR_AST -> ((create_expr ctx no) :> ast) + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") +(**/**) + +(** Function declarations. *) +module FuncDecl = +struct +(** Parameters of Func_Decls *) + module Parameter = + struct + (** + The kind of the parameter. + *) + let get_kind (x : parameter) = x#kind + + (**The int value of the parameter.*) + let get_int (x : parameter) = + if (x#kind != PARAMETER_INT) then + raise (Z3native.Exception "parameter is not an int") + else + x#int + + (**The double value of the parameter.*) + let get_double (x : parameter) = + if (x#kind != PARAMETER_DOUBLE) then + raise (Z3native.Exception "parameter is not a double") + else + x#double + + (**The Symbol value of the parameter.*) + let get_symbol (x : parameter) = + if (x#kind != PARAMETER_SYMBOL) then + raise (Z3native.Exception "parameter is not a symbol") + else + x#symbol + + (**The Sort value of the parameter.*) + let get_sort (x : parameter) = + if (x#kind != PARAMETER_SORT) then + raise (Z3native.Exception "parameter is not a sort") + else + x#sort + + (**The AST value of the parameter.*) + let get_ast (x : parameter) = + if (x#kind != PARAMETER_AST) then + raise (Z3native.Exception "parameter is not an ast") + else + x#ast + + (**The FunctionDeclaration value of the parameter.*) + let get_ast (x : parameter) = + if (x#kind != PARAMETER_FUNC_DECL) then + raise (Z3native.Exception "parameter is not an function declaration") + else + x#func_decl + + (**The rational string value of the parameter.*) + let get_rational (x : parameter) = + if (x#kind != PARAMETER_RATIONAL) then + raise (Z3native.Exception "parameter is not a ratinoal string") + else + x#rational + end + + (** + Comparison operator. + @param a A func_decl + @param b A func_decl + @return True if and are from the same context + and represent the same func_decl; false otherwise. + *) + let ( = ) (a : func_decl) (b : func_decl) = (a == b) || + if a#gnc == a#gnc then + false + else + ((int2lbool (Z3native.is_eq_func_decl a#gnc a#gno b#gno)) == L_TRUE) + (** + A string representations of the function declaration. + *) + let to_string (x : func_decl) = Z3native.func_decl_to_string x#gnc x#gno + + (** + Returns a unique identifier for the function declaration. + *) + let get_id (x : func_decl) = Z3native.get_func_decl_id x#gnc x#gno + + (** + The arity of the function declaration + *) + let get_arity (x : func_decl) = Z3native.get_arity x#gnc x#gno + + (** + The size of the domain of the function declaration + + *) + let get_domain_size (x : func_decl) = Z3native.get_domain_size x#gnc x#gno + + (** + The domain of the function declaration + *) + let get_domain (x : func_decl) = + let n = (get_domain_size x) in + let f i = create_sort x#gc (Z3native.get_domain x#gnc x#gno i) in + Array.init n f + + (** + The range of the function declaration + *) + let get_range (x : func_decl) = + create_sort x#gc (Z3native.get_range x#gnc x#gno) + + (** + The kind of the function declaration. + *) + let get_decl_kind (x : func_decl) = (int2decl_kind (Z3native.get_decl_kind x#gnc x#gno)) + + (** + The name of the function declaration + *) + let get_name (x : func_decl) = (create_symbol x#gc (Z3native.get_decl_name x#gnc x#gno)) + + (** + The number of parameters of the function declaration + *) + let get_num_parameters (x : func_decl) = (Z3native.get_decl_num_parameters x#gnc x#gno) + + (** + The parameters of the function declaration + *) + let get_parameters (x : func_decl) = + let n = (get_num_parameters x) in + let f i = ( + match (int2parameter_kind (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with + | PARAMETER_INT -> (new parameter)#cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) + | PARAMETER_DOUBLE -> (new parameter)#cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) + | PARAMETER_SYMBOL-> (new parameter)#cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) + | PARAMETER_SORT -> (new parameter)#cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) + | PARAMETER_AST -> (new parameter)#cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) + | PARAMETER_FUNC_DECL -> (new parameter)#cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) + | PARAMETER_RATIONAL -> (new parameter)#cnstr_rational (Z3native.get_decl_rational_parameter x#gnc x#gno i) + ) in + Array.init n f + + (** + Create expression that applies function to arguments. + + *) + let apply (x : func_decl) (args : expr array) = create_expr_fa x#gc x args + +end + +(** Datatype sorts *) +module DatatypeSort = +struct + (** The number of constructors of the datatype sort. *) + let get_num_constructors (x : datatype_sort) = Z3native.get_datatype_sort_num_constructors x#gnc x#gno + + (** The range of the array sort. *) + let get_constructors (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i) in + Array.init n f + + (** The recognizers. *) + let get_recognizers (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_recognizer x#gnc x#gno i) in + Array.init n f + + (** The constructor accessors. *) + let get_accessors (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = ( + let fd = ((new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i)) in + let ds = (Z3native.get_domain_size fd#gnc fd#gno) in + let g j = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor_accessor x#gnc x#gno i j) in + Array.init ds g + ) in + Array.init n f +end + +(** Enumeration sorts. *) +module EnumSort = +struct + (** The function declarations of the constants in the enumeration. *) + let get_const_decls (x : enum_sort) = + let f e = ((new func_decl x#gc)#cnstr_obj e) in + Array.map f x#const_decls + + (** The test predicates for the constants in the enumeration. *) + let get_tester_decls (x : enum_sort) = + let f e = ((new func_decl x#gc)#cnstr_obj e) in + Array.map f x#tester_decls +end + +(** List sorts. *) +module ListSort = +struct + (** The declaration of the nil function of this list sort. *) + let get_nil_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#nil_decl + + (** The declaration of the isNil function of this list sort. *) + let get_is_nil_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#is_nil_decl + + (** The declaration of the cons function of this list sort. *) + let get_cons_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#cons_decl + + (** The declaration of the isCons function of this list sort. *) + let get_is_cons_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#is_cons_decl + + (** The declaration of the head function of this list sort.*) + let get_head_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#head_decl + + (** The declaration of the tail function of this list sort. *) + let get_tail_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#tail_decl + + (** The empty list. *) + let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] +end + +module TupleSort = +struct + (** The constructor function of the tuple.*) + let get_mk_decl (x : tuple_sort) = + (new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_mk_decl x#gnc x#gno) + + (** The number of fields in the tuple. *) + let get_num_fields (x : tuple_sort) = Z3native.get_tuple_sort_num_fields x#gnc x#gno + + (** The field declarations. *) + let get_field_decls (x : tuple_sort) = + let n = get_num_fields x in + let f i = ((new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_field_decl x#gnc x#gno i)) in + Array.init n f +end + +(** The abstract syntax tree (AST) module. *) +module AST = +struct + (** + The AST's hash code. + @return A hash code + *) + let get_hash_code ( x : ast) = Z3native.get_ast_hash x#gnc x#gno + + (** + A unique identifier for the AST (unique among all ASTs). + *) + let get_id ( x : ast) = Z3native.get_ast_id x#gnc x#gno + + (** + The kind of the AST. + *) + let get_ast_kind ( x : ast) = (int2ast_kind (Z3native.get_ast_kind x#gnc x#gno)) + + (** + Indicates whether the AST is an Expr + *) + let is_expr ( x : ast) = + match get_ast_kind ( x : ast) with + | APP_AST + | NUMERAL_AST + | QUANTIFIER_AST + | VAR_AST -> true + | _ -> false + + (** + Indicates whether the AST is a BoundVariable + *) + let is_var ( x : ast) = (get_ast_kind x) == VAR_AST + + (** + Indicates whether the AST is a Quantifier + *) + let is_quantifier ( x : ast) = (get_ast_kind x) == QUANTIFIER_AST + + + (** + Indicates whether the AST is a Sort + *) + let is_sort ( x : ast) = (get_ast_kind x) == SORT_AST + + (** + Indicates whether the AST is a FunctionDeclaration + *) + let is_func_decl ( x : ast) = (get_ast_kind x) == FUNC_DECL_AST + + (** + A string representation of the AST. + *) + let to_string ( x : ast) = Z3native.ast_to_string x#gnc x#gno + + (** + A string representation of the AST in s-expression notation. + *) + let to_sexpr ( x : ast) = Z3native.ast_to_string x#gnc x#gno + + (** + Comparison operator. + @param a An AST + @param b An AST + @return True if and are from the same context + and represent the same sort; false otherwise. + *) + let ( = ) (a : expr) (b : expr) = (a == b) || + if a#gnc == b#gnc then + false + else + ((int2lbool (Z3native.is_eq_ast a#gnc a#gno b#gno)) == L_TRUE) + + (** + Object Comparison. + @param other Another ast + @return Negative if the object should be sorted before , positive if after else zero. + *) + let compare a b = + if (get_id a) < (get_id b) then -1 else + if (get_id a) > (get_id b) then 1 else + 0 + + (** Operator < *) + let ( < ) (a : ast) (b : ast) = (compare a b) + + (** + Translates (copies) the AST to the Context . + @param ctx A context + @return A copy of the AST which is associated with + *) + let translate ( x : ast) to_ctx = + if x#gc == to_ctx then + x + else + (create_ast to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno)) +end + +(** + Parameter sets + + A Params objects represents a configuration in the form of Symbol/value pairs. +*) +module Params = +struct + (** + Adds a parameter setting. + *) + let add_bool (p : params) (name : symbol) (value : bool) = + Z3native.params_set_bool p#gnc p#gno name#gno (lbool2int (if value then L_TRUE else L_FALSE)) + + (** + Adds a parameter setting. + *) + let add_int (p : params) (name : symbol) (value : int) = + Z3native.params_set_uint p#gnc p#gno name#gno value + + (** + Adds a parameter setting. + *) + let add_double (p : params) (name : symbol) (value : float) = + Z3native.params_set_double p#gnc p#gno name#gno value + + (** + Adds a parameter setting. + *) + let add_symbol (p : params) (name : symbol) (value : symbol) = + Z3native.params_set_symbol p#gnc p#gno name#gno value#gno + + (** + Adds a parameter setting. + *) + let add_s_bool (p : params) (name : string) (value : bool) = + add_bool p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_int (p : params) (name : string) (value : int) = + add_int p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_double (p : params) (name : string) (value : float) = + add_double p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_symbol (p : params) (name : string) (value : symbol) = + add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + A string representation of the parameter set. + *) + let to_string (p : params) = Z3native.params_to_string p#gnc p#gno +end + +(** Expressions (terms) *) +module Expr = +struct + (** + Returns a simplified version of the expression. + A set of parameters to configure the simplifier + + *) + let simplify ( x : expr ) ( p : params option ) = match p with + | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) + | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno pp#gno) + + (** + The function declaration of the function that is applied in this expression. + *) + let get_func_decl ( x : expr ) = (new func_decl x#gc)#cnstr_obj (Z3native.get_app_decl x#gnc x#gno) + + (** + Indicates whether the expression is the true or false expression + or something else (Z3_L_UNDEF). + *) + let get_bool_value ( x : expr ) = int2lbool (Z3native.get_bool_value x#gnc x#gno) + + (** + The number of arguments of the expression. + *) + let get_num_args ( x : expr ) = Z3native.get_app_num_args x#gnc x#gno + + (** + The arguments of the expression. + *) + let get_args ( x : expr ) = let n = (get_num_args x) in + let f i = create_expr x#gc (Z3native.get_app_arg x#gnc x#gno i) in + Array.init n f + + (** + Update the arguments of the expression using the arguments + The number of new arguments should coincide with the current number of arguments. + *) + let update ( x : expr ) args = + if (Array.length args <> (get_num_args x)) then + raise (Z3native.Exception "Number of arguments does not match") + else + x#sno x#gnc (Z3native.update_term x#gnc x#gno (Array.length args) (expraton 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]. + + *) + let substitute ( x : expr ) from to_ = + if (Array.length from) <> (Array.length to_) then + raise (Z3native.Exception "Argument sizes do not match") + else + create_expr x#gc (Z3native.substitute x#gnc x#gno (Array.length from) (expraton from) (expraton to_)) + + (** + Substitute every occurrence of from in the expression with to. + + *) + let substitute_one ( x : expr ) from to_ = + substitute ( x : expr ) [| from |] [| 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]. + + *) + let substitute_vars ( x : expr ) to_ = + create_expr x#gc (Z3native.substitute_vars x#gnc x#gno (Array.length to_) (expraton to_)) + + + (** + Translates (copies) the term to the Context . + A context + A copy of the term which is associated with + *) + let translate ( x : expr ) to_ctx = + if x#gc == to_ctx then + x + else + create_expr to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno) + + (** + Returns a string representation of the expression. + *) + let to_string ( x : expr ) = Z3native.ast_to_string x#gnc x#gno + + (** + Indicates whether the term is a numeral + *) + let is_numeral ( x : expr ) = int2lbool (Z3native.is_numeral_ast x#gnc x#gno) == L_TRUE + + (** + Indicates whether the term is well-sorted. + True if the term is well-sorted, false otherwise. + *) + let is_well_sorted ( x : expr ) = int2lbool (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE + + (** + The Sort of the term. + *) + let get_sort ( x : expr ) = create_sort x#gc (Z3native.get_sort x#gnc x#gno) + + (** + Indicates whether the term has Boolean sort. + *) + let is_bool ( x : expr ) = (AST.is_expr x) && + (int2lbool (Z3native.is_eq_sort x#gnc + (Z3native.mk_bool_sort x#gnc) + (Z3native.get_sort x#gnc x#gno))) == L_TRUE + + (** + Indicates whether the term is of integer sort. + *) + let is_int ( x : expr ) = + ((int2lbool (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && + ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) + + (** + Indicates whether the term is of sort real. + *) + let is_real ( x : expr ) = + ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) + + (** + Indicates whether the term is of an array sort. + *) + let is_array ( x : expr ) = + ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + + (** + Indicates whether the term represents a constant. + *) + let is_const ( x : expr ) = (AST.is_expr x) && + (get_num_args x) == 0 && + FuncDecl.get_domain_size(get_func_decl x) == 0 + + (** + Indicates whether the term is an integer numeral. + *) + let is_int_numeral ( x : expr ) = (is_numeral x) && (is_int x) + + (** + Indicates whether the term is a real numeral. + *) + let is_rat_num ( x : expr ) = (is_numeral x) && (is_real x) + + (** + Indicates whether the term is an algebraic number + *) + let is_algebraic_number ( x : expr ) = int2lbool(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE + + (** + Indicates whether the term is the constant true. + *) + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) + + (** + Indicates whether the term is the constant false. + *) + let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) + + (** + Indicates whether the term is an equality predicate. + *) + let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) + + (** + Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). + *) + let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) + + (** + Indicates whether the term is a ternary if-then-else term + *) + let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) + + (** + Indicates whether the term is an n-ary conjunction + *) + let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) + + (** + Indicates whether the term is an n-ary disjunction + *) + let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) + + (** + Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) + *) + let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) + + (** + Indicates whether the term is an exclusive or + *) + let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) + + (** + Indicates whether the term is a negation + *) + let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) + + (** + Indicates whether the term is an implication + *) + let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) + + (** + Indicates whether the term is an arithmetic numeral. + *) + let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ANUM) + + (** + Indicates whether the term is a less-than-or-equal + *) + let is_le ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LE) + + (** + Indicates whether the term is a greater-than-or-equal + *) + let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_GE) + + (** + Indicates whether the term is a less-than + *) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LT) + + (** + Indicates whether the term is a greater-than + *) + let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_GT) + + (** + Indicates whether the term is addition (binary) + *) + let is_add ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ADD) + + (** + Indicates whether the term is subtraction (binary) + *) + let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SUB) + + (** + Indicates whether the term is a unary minus + *) + let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UMINUS) + + (** + Indicates whether the term is multiplication (binary) + *) + let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_MUL) + + (** + Indicates whether the term is division (binary) + *) + let is_div ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DIV) + + (** + Indicates whether the term is integer division (binary) + *) + let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IDIV) + + (** + Indicates whether the term is remainder (binary) + *) + let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_REM) + + (** + Indicates whether the term is modulus (binary) + *) + let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_MOD) + + (** + Indicates whether the term is a coercion of integer to real (unary) + *) + let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TO_REAL) + + (** + Indicates whether the term is a coercion of real to integer (unary) + *) + let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TO_INT) + + (** + Indicates whether the term is a check that tests whether a real is integral (unary) + *) + let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IS_INT) + + (** + 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. + *) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_STORE) + + (** + Indicates whether the term is an array select. + *) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CONST_ARRAY) + + (** + Indicates whether the term is a default array. + For example default(const(v)) = v. The function is unary. + *) + let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AS_ARRAY) + + (** + Indicates whether the term is set union + *) + let is_set_union ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_UNION) + + (** + Indicates whether the term is set intersection + *) + let is_set_intersect ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_INTERSECT) + + (** + Indicates whether the term is set difference + *) + let is_set_difference ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_DIFFERENCE) + + (** + Indicates whether the term is set complement + *) + let is_set_complement ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_COMPLEMENT) + + (** + Indicates whether the term is set subset + *) + let is_set_subset ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_SUBSET) + + (** + Indicates whether the terms is of bit-vector sort. + *) + let is_bv ( x : expr ) = + ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == BV_SORT) + + (** + Indicates whether the term is a bit-vector numeral + *) + let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNUM) + + (** + Indicates whether the term is a one-bit bit-vector with value one + *) + let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BIT1) + + (** + Indicates whether the term is a one-bit bit-vector with value zero + *) + let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BIT0) + + (** + Indicates whether the term is a bit-vector unary minus + *) + let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNEG) + + (** + Indicates whether the term is a bit-vector addition (binary) + *) + let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BADD) + + (** + Indicates whether the term is a bit-vector subtraction (binary) + *) + let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSUB) + + (** + Indicates whether the term is a bit-vector multiplication (binary) + *) + let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BMUL) + + (** + Indicates whether the term is a bit-vector signed division (binary) + *) + let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSDIV) + + (** + Indicates whether the term is a bit-vector unsigned division (binary) + *) + let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUDIV) + + (** + Indicates whether the term is a bit-vector signed remainder (binary) + *) + let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSREM) + + (** + Indicates whether the term is a bit-vector unsigned remainder (binary) + *) + let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUREM) + + (** + Indicates whether the term is a bit-vector signed modulus + *) + let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSMOD) + + (** + Indicates whether the term is a bit-vector signed division by zero + *) + let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSDIV0) + + (** + Indicates whether the term is a bit-vector unsigned division by zero + *) + let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUDIV0) + + (** + Indicates whether the term is a bit-vector signed remainder by zero + *) + let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSREM0) + + (** + Indicates whether the term is a bit-vector unsigned remainder by zero + *) + let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUREM0) + + (** + Indicates whether the term is a bit-vector signed modulus by zero + *) + let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSMOD0) + + (** + Indicates whether the term is an unsigned bit-vector less-than-or-equal + *) + let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ULEQ) + + (** + Indicates whether the term is a signed bit-vector less-than-or-equal + *) + let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SLEQ) + + (** + Indicates whether the term is an unsigned bit-vector greater-than-or-equal + *) + let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UGEQ) + + (** + Indicates whether the term is a signed bit-vector greater-than-or-equal + *) + let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SGEQ) + + (** + Indicates whether the term is an unsigned bit-vector less-than + *) + let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ULT) + + (** + Indicates whether the term is a signed bit-vector less-than + *) + let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SLT) + + (** + Indicates whether the term is an unsigned bit-vector greater-than + *) + let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UGT) + + (** + Indicates whether the term is a signed bit-vector greater-than + *) + let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SGT) + + (** + Indicates whether the term is a bit-wise AND + *) + let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BAND) + + (** + Indicates whether the term is a bit-wise OR + *) + let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BOR) + + (** + Indicates whether the term is a bit-wise NOT + *) + let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNOT) + + (** + Indicates whether the term is a bit-wise XOR + *) + let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BXOR) + + (** + Indicates whether the term is a bit-wise NAND + *) + let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNAND) + + (** + Indicates whether the term is a bit-wise NOR + *) + let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNOR) + + (** + Indicates whether the term is a bit-wise XNOR + *) + let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BXNOR) + + (** + Indicates whether the term is a bit-vector concatenation (binary) + *) + let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CONCAT) + + (** + Indicates whether the term is a bit-vector sign extension + *) + let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SIGN_EXT) + + (** + Indicates whether the term is a bit-vector zero extension + *) + let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ZERO_EXT) + + (** + Indicates whether the term is a bit-vector extraction + *) + let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EXTRACT) + + (** + Indicates whether the term is a bit-vector repetition + *) + let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_REPEAT) + + (** + Indicates whether the term is a bit-vector reduce OR + *) + let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BREDOR) + + (** + Indicates whether the term is a bit-vector reduce AND + *) + let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BREDAND) + + (** + Indicates whether the term is a bit-vector comparison + *) + let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BCOMP) + + (** + Indicates whether the term is a bit-vector shift left + *) + let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSHL) + + (** + Indicates whether the term is a bit-vector logical shift right + *) + let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BLSHR) + + (** + Indicates whether the term is a bit-vector arithmetic shift left + *) + let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BASHR) + + (** + Indicates whether the term is a bit-vector rotate left + *) + let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ROTATE_LEFT) + + (** + Indicates whether the term is a bit-vector rotate right + *) + let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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))) + *) + let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + *) + let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + *) + let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) + + (** + Indicates whether the term is a Proof for the expression 'true'. + *) + let is_proof_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TRUE) + + (** + Indicates whether the term is a proof for a fact asserted by the user. + *) + let is_proof_asserted ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_ASSERTED) + + (** + Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. + *) + let is_proof_goal ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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). + *) + let is_proof_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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'. + *) + let is_proof_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + + *) + let is_proof_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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)) + + *) + let is_proof_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 + + *) + let is_proof_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + + *) + let is_proof_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) + + *) + let is_proof_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + + *) + let is_proof_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 + + *) + let is_proof_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 + + *) + let is_proof_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. + + This proof object has no antecedents. + + Several variables can be eliminated simultaneously. + + *) + let is_proof_der ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DER) + + (** + Indicates whether the term is a proof for quantifier instantiation + + A proof of (or (not (forall (x) (P x))) (P a)) + + *) + let is_proof_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_QUANT_INST) + + (** + Indicates whether the term is a hypthesis marker. + Mark a hypothesis in a natural deduction style proof. + *) + let is_proof_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_lemma ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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') + + *) + let is_proof_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_UNIT_RESOLUTION) + + (** + Indicates whether the term is a proof by iff-true + + T1: p + [iff-true T1]: (iff p true) + + *) + let is_proof_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_IFF_TRUE) + + (** + Indicates whether the term is a proof by iff-false + + T1: (not p) + [iff-false T1]: (iff p false) + + *) + let is_proof_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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). + + *) + let is_proof_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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) + + *) + let is_proof_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_APPLY_DEF) + + (** + Indicates whether the term is a proof iff-oeq + + T1: (iff p q) + [iff~ T1]: (~ p q) + + *) + let is_proof_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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'. + + *) + let is_proof_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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'))) + + *) + let is_proof_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_CNF_STAR) + + (** + Indicates whether the term is a proof for a Skolemization step + + Proof for: + + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + + This proof object has no antecedents. + + *) + let is_proof_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 + + *) + let is_proof_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_proof_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TH_LEMMA) + + (** + Indicates whether the term is of a relation sort. + *) + let is_Relation ( x : expr ) = + ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == 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. + + *) + let is_relation_store ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_STORE) + + (** + Indicates whether the term is an empty relation + *) + let is_empty_relation ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_EMPTY) + + (** + Indicates whether the term is a test for the emptiness of a relation + *) + let is_is_empty_relation ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_IS_EMPTY) + + (** + Indicates whether the term is a relational join + *) + let is_relational_join ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_JOIN) + + (** + Indicates whether the term is the union or convex hull of two relations. + The function takes two arguments. + *) + let is_relation_union ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_UNION) + + (** + Indicates whether the term is the widening of two relations + The function takes two arguments. + *) + let is_relation_widen ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_WIDEN) + + (** + Indicates whether the term is a projection of columns (provided as numbers in the parameters). + The function takes one argument. + *) + let is_relation_project ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_relation_filter ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. + + *) + let is_relation_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_relation_rename ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_RENAME) + + (** + Indicates whether the term is the complement of a relation + *) + let is_relation_complement ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_relation_select ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. + + *) + let is_relation_clone ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_CLONE) + + (** + Indicates whether the term is of an array sort. + *) + let is_finite_domain ( x : expr ) = + ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) + + (** + Indicates whether the term is a less than predicate over a finite domain. + *) + let is_finite_domain_lt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) appears, the higher is its + index. + + *) + let get_index ( x : expr ) = + if not (AST.is_var x) then + raise (Z3native.Exception "Term is not a bound variable.") + else + Z3native.get_index_value x#gnc x#gno +end + +(* Integer Numerals *) +module IntNum = +struct + (** Retrieve the int value. *) + let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno +end + +(** Rational Numerals *) +module RatNum = +struct + + (** The numerator of a rational numeral. *) + let get_numerator ( x : rat_num ) = + (new int_num x#gc)#cnstr_obj (Z3native.get_numerator x#gnc x#gno) + + (** The denominator of a rational numeral. *) + let get_denominator ( x : rat_num ) = + (new int_num x#gc)#cnstr_obj (Z3native.get_denominator x#gnc x#gno) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : rat_num ) (precision : int) = + Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : rat_num ) = Z3native.get_numeral_string x#gnc x#gno +end + +(** Bit-vector numerals *) +module BitVecNum = +struct + (** Retrieve the int value. *) + let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno +end + +(** Algebraic numbers *) +module AlgebraicNum = +struct + (** + 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 + A numeral Expr of sort Real + *) + let to_upper ( x : algebraic_num ) ( precision : int ) = + (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) + + (** + Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + + + A numeral Expr of sort Real + *) + let to_lower ( x : algebraic_num ) precision = + (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : algebraic_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno +end + +(** The main interaction with Z3 happens via the Context module. *) module Context = struct + + (* SYMBOLS *) + (** Creates a new symbol using an integer. Not all integers can be passed to this function. The legal range of unsigned integers is 0 to 2^30-1. *) - let mk_symbol_int ctx i = + let mk_symbol_int ( ctx : context ) i = (new int_symbol ctx)#cnstr_int i - + (** Creates a new symbol using a string. *) - let mk_symbol_string ctx s = + let mk_symbol_string ( ctx : context ) s = (new string_symbol ctx)#cnstr_string s (** Create an array of symbols. *) - let mk_symbols ctx names = - let f elem = mk_symbol_string ctx elem in + let mk_symbols_int ( ctx : context ) names = + let f elem = mk_symbol_int ( ctx : context ) elem in + (Array.map f names) + + (** + Create an array of symbols. + *) + let mk_symbols_string ( ctx : context ) names = + let f elem = mk_symbol_string ( ctx : context ) elem in (Array.map f names) + + (* SORTS *) + + (** + Create a new Boolean sort. + *) + let mk_bool_sort ( ctx : context ) = + (new bool_sort ctx) + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted_sort ( ctx : context ) (s : symbol) = + (new uninterpreted_sort ctx)#cnstr_s s + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted_sort_s ( ctx : context ) (s : string) = + mk_uninterpreted_sort ctx ((mk_symbol_string ( ctx : context ) s) :> symbol) + + (** + Create a new integer sort. + *) + let mk_int_sort ( ctx : context ) = + (new int_sort ctx) + + (** + Create a real sort. + *) + let mk_real_sort ( ctx : context ) = + (new real_sort ctx) + + (** + Create a new bit-vector sort. + *) + let mk_bitvec_sort ( ctx : context ) size = + (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort ctx#gno size) + + (** + Create a new array sort. + *) + let mk_array_sort ( ctx : context ) domain range = + (new array_sort ctx)#cnstr_dr domain range + + (** + Create a new tuple sort. + *) + let mk_tuple_sort ( ctx : context ) name field_names field_sorts = + (new tuple_sort ctx)#cnstr_siss name (Array.length field_names) field_names field_sorts + + (** + Create a new enumeration sort. + *) + let mk_enum_sort ( ctx : context ) name enum_names = + (new enum_sort ctx)#cnstr_ss name enum_names + + (** + Create a new enumeration sort. + *) + let mk_enum_sort_s ( ctx : context ) name enum_names = + (new enum_sort ctx)#cnstr_ss + ((mk_symbol_string ( ctx : context ) name) :> symbol) + (let f e = (e :> symbol) in + (Array.map f (mk_symbols_string ( ctx : context ) enum_names)) + ) + + (** + Create a new list sort. + *) + let mk_list_sort ( ctx : context ) (name : symbol) elem_sort = + (new list_sort ctx)#cnstr_ss name elem_sort + + (** + Create a new list sort. + *) + let mk_list_sort_s ( ctx : context ) (name : string) elem_sort = + mk_list_sort ctx ((mk_symbol_string ctx name) :> symbol) elem_sort + + + (** + Create a new finite domain sort. + *) + let mk_finite_domain_sort ( ctx : context ) ( name : symbol ) size = + (new finite_domain_sort ctx)#cnstr_si name size + + (** + Create a new finite domain sort. + *) + let mk_finite_domain_sort_s ( ctx : context ) ( name : string ) size = + (new finite_domain_sort ctx)#cnstr_si ((mk_symbol_string ctx name) :> symbol) size + +(** + +(* DATATYPES *) +(** + Create a datatype constructor. +*) + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + public Constructor MkConstructor(Symbol name, Symbol recognizer, Symbol[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null) + { + + + + + return new Constructor(this, name, recognizer, fieldNames, sorts, sortRefs); + } + +(** + Create a datatype constructor. +*) + @param name + @param recognizer + @param fieldNames + @param sorts + @param sortRefs + @return + public Constructor MkConstructor(string name, string recognizer, string[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null) + { + + + return new Constructor(this, MkSymbol(name), MkSymbol(recognizer), MkSymbols(fieldNames), sorts, sortRefs); + } + +(** + Create a new datatype sort. +*) + let mk_Datatype_Sort(Symbol name, Constructor[] constructors) + { + + + + + + + CheckContextMatch(name); + CheckContextMatch(constructors); + return new DatatypeSort(this, name, constructors); + } + +(** + Create a new datatype sort. +*) + let mk_Datatype_Sort(string name, Constructor[] constructors) + { + + + + + CheckContextMatch(constructors); + return new DatatypeSort(this, MkSymbol(name), constructors); + } + +(** + Create mutually recursive datatypes. +*) + @param names names of datatype sorts + @param c list of constructors, one list per sort. + let mk_Datatype_Sorts(Symbol[] names, Constructor[][] c) + { + + + + + + + + CheckContextMatch(names); + uint n = (uint)names.Length; + ConstructorList[] cla = new ConstructorList[n]; + IntPtr[] n_constr = new IntPtr[n]; + for (uint i = 0; i < n; i++) + { + Constructor[] constructor = c[i]; + + CheckContextMatch(constructor); + cla[i] = new ConstructorList(this, constructor); + n_constr[i] = cla[i].x#gno; + } + IntPtr[] n_res = new IntPtr[n]; + Z3native.mk_datatypes(nCtx, n, Symbol.ArrayToNative(names), n_res, n_constr); + DatatypeSort[] res = new DatatypeSort[n]; + for (uint i = 0; i < n; i++) + res[i] = new DatatypeSort(this, n_res[i]); + return res; + } + +(** + Create mutually recursive data-types. +*) + @param names + @param c + @return + let mk_Datatype_Sorts(string[] names, Constructor[][] c) + { + + + + + + + + return MkDatatypeSorts(MkSymbols(names), c); + } + + + + +(* FUNCTION DECLARATIONS *) +(** + Creates a new function declaration. +*) + public Func_Decl MkFunc_Decl(Symbol name, Sort[] domain, Sort range) + { + + + + + + CheckContextMatch(name); + CheckContextMatch(domain); + CheckContextMatch(range); + return new Func_Decl(this, name, domain, range); + } + +(** + Creates a new function declaration. +*) + public Func_Decl MkFunc_Decl(Symbol name, Sort domain, Sort range) + { + + + + + + CheckContextMatch(name); + CheckContextMatch(domain); + CheckContextMatch(range); + Sort[] q = new Sort[] { domain }; + return new Func_Decl(this, name, q, range); + } + +(** + Creates a new function declaration. +*) + public Func_Decl MkFunc_Decl(string name, Sort[] domain, Sort range) + { + + + + + CheckContextMatch(domain); + CheckContextMatch(range); + return new Func_Decl(this, MkSymbol(name), domain, range); + } + +(** + Creates a new function declaration. +*) + public Func_Decl MkFunc_Decl(string name, Sort domain, Sort range) + { + + + + + CheckContextMatch(domain); + CheckContextMatch(range); + Sort[] q = new Sort[] { domain }; + return new Func_Decl(this, MkSymbol(name), q, range); + } + +(** + Creates a fresh function declaration with a name prefixed with . +*) + + + let mk_Fresh_Func_Decl(string prefix, Sort[] domain, Sort range) + { + + + + + CheckContextMatch(domain); + CheckContextMatch(range); + return new Func_Decl(this, prefix, domain, range); + } + +(** + Creates a new constant function declaration. +*) + let mk_Const_Decl(Symbol name, Sort range) + { + + + + + CheckContextMatch(name); + CheckContextMatch(range); + return new Func_Decl(this, name, null, range); + } + +(** + Creates a new constant function declaration. +*) + let mk_Const_Decl(string name, Sort range) + { + + + + CheckContextMatch(range); + return new Func_Decl(this, MkSymbol(name), null, range); + } + +(** + Creates a fresh constant function declaration with a name prefixed with . +*) + + + let mk_Fresh_ConstDecl(string prefix, Sort range) + { + + + + CheckContextMatch(range); + return new Func_Decl(this, prefix, null, range); + } + + +(* BOUND VARIABLES *) +(** + Creates a new bound variable. +*) + @param index The de-Bruijn index of the variable + @param ty The sort of the variable + public Expr MkBound(uint index, Sort ty) + { + + + + return Expr.Create(this, Z3native.mk_bound(nCtx, index, ty.x#gno)); + } + + +(* QUANTIFIER PATTERNS *) +(** + Create a quantifier pattern. +*) + public Pattern MkPattern(params 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, Z3native.mk_pattern(nCtx, (uint)terms.Length, termsNative)); + } + + +(* CONSTANTS *) +(** + Creates a new Constant of sort and named . +*) + public Expr MkConst(Symbol name, Sort range) + { + + + + + CheckContextMatch(name); + CheckContextMatch(range); + + return Expr.Create(this, Z3native.mk_const(nCtx, name.x#gno, range.x#gno)); + } + +(** + 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 . +*) + let mk_Fresh_Const(string prefix, Sort range) + { + + + + CheckContextMatch(range); + return Expr.Create(this, Z3native.mk_fresh_const(nCtx, prefix, range.x#gno)); + } + +(** + Creates a fresh constant from the Func_Decl . +*) + @param f A decl of a 0-arity function + public Expr MkConst(Func_Decl f) + { + + + + return MkApp(f); + } + +(** + Create a Boolean constant. +*) + let mk_Bool_Const(Symbol name) + { + + + + return (BoolExpr)MkConst(name, BoolSort); + } + +(** + Create a Boolean constant. +*) + let mk_Bool_Const(string name) + { + + + return (BoolExpr)MkConst(MkSymbol(name), BoolSort); + } + +(** + Creates an integer constant. +*) + let mk_Int_Const(Symbol name) + { + + + + return (IntExpr)MkConst(name, IntSort); + } + +(** + Creates an integer constant. +*) + let mk_Int_Const(string name) + { + + + + return (IntExpr)MkConst(name, IntSort); + } + +(** + Creates a real constant. +*) + let mk_Real_Const(Symbol name) + { + + + + return (RealExpr)MkConst(name, RealSort); + } + +(** + Creates a real constant. +*) + let mk_Real_Const(string name) + { + + + return (RealExpr)MkConst(name, RealSort); + } + +(** + Creates a bit-vector constant. +*) + let mk_B_VConst(Symbol name, uint size) + { + + + + return (BitVecExpr)MkConst(name, MkBitVecSort(size)); + } + +(** + Creates a bit-vector constant. +*) + let mk_B_VConst(string name, uint size) + { + + + return (BitVecExpr)MkConst(name, MkBitVecSort(size)); + } + + +(* TERMS *) +(** + Create a new function application. +*) + public Expr MkApp(Func_Decl f, params Expr[] args) + { + + + + + CheckContextMatch(f); + CheckContextMatch(args); + return Expr.Create(this, f, args); + } + +(* PROPOSITIONAL *) +(** + The true Term. +*) + public BoolExpr MkTrue ( ctx : context ) = + { + + + return new BoolExpr(this, Z3native.mk_true(nCtx)); + } + +(** + The false Term. +*) + public BoolExpr MkFalse ( ctx : context ) = + { + + + return new BoolExpr(this, Z3native.mk_false(nCtx)); + } + +(** + Creates a Boolean value. +*) + public BoolExpr MkBool(bool value) + { + + + return value ? MkTrue ( ctx : context ) = : MkFalse ( ctx : context ) =; + } + +(** + Creates the equality = . +*) + public BoolExpr MkEq(Expr x, Expr y) + { + + + + + CheckContextMatch(x); + CheckContextMatch(y); + return new BoolExpr(this, Z3native.mk_eq(nCtx, x.x#gno, y.x#gno)); + } + +(** + Creates a distinct term. +*) + public BoolExpr MkDistinct(params Expr[] args) + { + + + + + + CheckContextMatch(args); + return new BoolExpr(this, Z3native.mk_distinct(nCtx, (uint)args.Length, AST.ArrayToNative(args))); + } + +(** + Mk an expression representing not(a). +*) + public BoolExpr MkNot(BoolExpr a) + { + + + + CheckContextMatch(a); + return new BoolExpr(this, Z3native.mk_not(nCtx, a.x#gno)); + } + +(** + Create an expression representing an if-then-else: ite(t1, t2, t3). +*) + @param t1 An expression with Boolean sort + @param t2 An expression + @param t3 An expression with the same sort as + let mk_I_TE(BoolExpr t1, Expr t2, Expr t3) + { + + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + CheckContextMatch(t3); + return Expr.Create(this, Z3native.mk_ite(nCtx, t1.x#gno, t2.x#gno, t3.x#gno)); + } + +(** + Create an expression representing t1 iff t2. +*) + public BoolExpr MkIff(BoolExpr t1, BoolExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_iff(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 -> t2. +*) + public BoolExpr MkImplies(BoolExpr t1, BoolExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_implies(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 xor t2. +*) + public BoolExpr MkXor(BoolExpr t1, BoolExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_xor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t[0] and t[1] and .... +*) + public BoolExpr MkAnd(params BoolExpr[] t) + { + + + + + CheckContextMatch(t); + return new BoolExpr(this, Z3native.mk_and(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + +(** + Create an expression representing t[0] or t[1] or .... +*) + public BoolExpr MkOr(params BoolExpr[] t) + { + + + + + CheckContextMatch(t); + return new BoolExpr(this, Z3native.mk_or(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + + +(* ARITHMETIC *) +(** + Create an expression representing t[0] + t[1] + .... +*) + public ArithExpr MkAdd(params ArithExpr[] t) + { + + + + + CheckContextMatch(t); + return (ArithExpr)Expr.Create(this, Z3native.mk_add(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + +(** + Create an expression representing t[0] * t[1] * .... +*) + public ArithExpr MkMul(params ArithExpr[] t) + { + + + + + CheckContextMatch(t); + return (ArithExpr)Expr.Create(this, Z3native.mk_mul(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + +(** + Create an expression representing t[0] - t[1] - .... +*) + public ArithExpr MkSub(params ArithExpr[] t) + { + + + + + CheckContextMatch(t); + return (ArithExpr)Expr.Create(this, Z3native.mk_sub(nCtx, (uint)t.Length, AST.ArrayToNative(t))); + } + +(** + Create an expression representing -t. +*) + let mk_Unary_Minus(ArithExpr t) + { + + + + CheckContextMatch(t); + return (ArithExpr)Expr.Create(this, Z3native.mk_unary_minus(nCtx, t.x#gno)); + } + +(** + Create an expression representing t1 / t2. +*) + public ArithExpr MkDiv(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return (ArithExpr)Expr.Create(this, Z3native.mk_div(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, Z3native.mk_mod(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, Z3native.mk_rem(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 ^ t2. +*) + public ArithExpr MkPower(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return (ArithExpr)Expr.Create(this, Z3native.mk_power(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 < t2 +*) + public BoolExpr MkLt(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_lt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 <= t2 +*) + public BoolExpr MkLe(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_le(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 > t2 +*) + public BoolExpr MkGt(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_gt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an expression representing t1 >= t2 +*) + public BoolExpr MkGe(ArithExpr t1, ArithExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_ge(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, Z3native.mk_int2real(nCtx, t.x#gno)); + } + +(** + 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, Z3native.mk_real2int(nCtx, t.x#gno)); + } + +(** + Creates an expression that checks whether a real number is an integer. +*) + let mk_Is_Integer(RealExpr t) + { + + + + CheckContextMatch(t); + return new BoolExpr(this, Z3native.mk_is_int(nCtx, t.x#gno)); + } + + +(* BIT-VECTORS *) +(** + Bitwise negation. +*) + The argument must have a bit-vector sort. + let mk_B_VNot(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_bvnot(nCtx, t.x#gno)); + } + +(** + Take conjunction of bits in a vector, return vector of length 1. +*) + The argument must have a bit-vector sort. + let mk_B_VRedAND(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_bvredand(nCtx, t.x#gno)); + } + +(** + Take disjunction of bits in a vector, return vector of length 1. +*) + The argument must have a bit-vector sort. + let mk_B_VRedOR(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_bvredor(nCtx, t.x#gno)); + } + +(** + Bitwise conjunction. +*) + The arguments must have a bit-vector sort. + let mk_B_VAND(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvand(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise disjunction. +*) + The arguments must have a bit-vector sort. + let mk_B_VOR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise XOR. +*) + The arguments must have a bit-vector sort. + let mk_B_VXOR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvxor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise NAND. +*) + The arguments must have a bit-vector sort. + let mk_B_VNAND(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvnand(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise NOR. +*) + The arguments must have a bit-vector sort. + let mk_B_VNOR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvnor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bitwise XNOR. +*) + The arguments must have a bit-vector sort. + let mk_B_VXNOR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvxnor(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Standard two's complement unary minus. +*) + The arguments must have a bit-vector sort. + let mk_B_VNeg(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_bvneg(nCtx, t.x#gno)); + } + +(** + Two's complement addition. +*) + The arguments must have the same bit-vector sort. + let mk_B_VAdd(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvadd(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement subtraction. +*) + The arguments must have the same bit-vector sort. + let mk_B_VSub(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvsub(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement multiplication. +*) + The arguments must have the same bit-vector sort. + let mk_B_VMul(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvmul(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VUDiv(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvudiv(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VSDiv(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvsdiv(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VURem(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvurem(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VSRem(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvsrem(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VSMod(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvsmod(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Unsigned less-than +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VULT(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvult(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement signed less-than +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VSLT(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvslt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Unsigned less-than or equal to. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VULE(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvule(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement signed less-than or equal to. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VSLE(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsle(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Unsigned greater than or equal to. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VUGE(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvuge(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement signed greater than or equal to. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VSGE(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsge(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Unsigned greater-than. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VUGT(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvugt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Two's complement signed greater-than. +*) + + The arguments must have the same bit-vector sort. + + let mk_B_VSGT(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsgt(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, Z3native.mk_concat(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Bit-vector extraction. +*) + + Extract the bits down to from a bitvector of + size m to yield a new bitvector of size n, where + n = high - low + 1. + The argument must have a bit-vector sort. + + public BitVecExpr MkExtract(uint high, uint low, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_extract(nCtx, high, low, t.x#gno)); + } + +(** + 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. + + let mk_Sign_Ext(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_sign_ext(nCtx, i, t.x#gno)); + } + +(** + 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. + + let mk_Zero_Ext(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_zero_ext(nCtx, i, t.x#gno)); + } + +(** + Bit-vector repetition. +*) + + The argument must have a bit-vector sort. + + public BitVecExpr MkRepeat(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_repeat(nCtx, i, t.x#gno)); + } + +(** + 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. + + let mk_B_VSHL(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvshl(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VLSHR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvlshr(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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. + + let mk_B_VASHR(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_bvashr(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Rotate Left. +*) + + Rotate bits of \c t to the left \c i times. + The argument must have a bit-vector sort. + + let mk_B_VRotateLeft(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_rotate_left(nCtx, i, t.x#gno)); + } + +(** + Rotate Right. +*) + + Rotate bits of \c t to the right \c i times. + The argument must have a bit-vector sort. + + let mk_B_VRotateRight(uint i, BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_rotate_right(nCtx, i, t.x#gno)); + } + +(** + Rotate Left. +*) + + Rotate bits of to the left times. + The arguments must have the same bit-vector sort. + + let mk_B_VRotateLeft(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_ext_rotate_left(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Rotate Right. +*) + + Rotate bits of to the right times. + The arguments must have the same bit-vector sort. + + let mk_B_VRotateRight(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BitVecExpr(this, Z3native.mk_ext_rotate_right(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create an bit bit-vector from the integer argument . +*) + + NB. This function is essentially treated as uninterpreted. + So you cannot expect Z3 to precisely reflect the semantics of this function + when solving constraints with this function. + + The argument must be of integer sort. + + public BitVecExpr MkInt2BV(uint n, IntExpr t) + { + + + + CheckContextMatch(t); + return new BitVecExpr(this, Z3native.mk_int2bv(nCtx, n, t.x#gno)); + } + +(** + 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. + + let mk_B_V2Int(BitVecExpr t, bool signed) + { + + + + CheckContextMatch(t); + return new IntExpr(this, Z3native.mk_bv2int(nCtx, t.x#gno, (signed) ? 1 : 0)); + } + +(** + Create a predicate that checks that the bit-wise addition does not overflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VAddNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvadd_no_overflow(nCtx, t1.x#gno, t2.x#gno, (isSigned) ? 1 : 0)); + } + +(** + Create a predicate that checks that the bit-wise addition does not underflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VAddNoUnderflow(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvadd_no_underflow(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create a predicate that checks that the bit-wise subtraction does not overflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VSubNoOverflow(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsub_no_overflow(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create a predicate that checks that the bit-wise subtraction does not underflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VSubNoUnderflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsub_no_underflow(nCtx, t1.x#gno, t2.x#gno, (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. + + let mk_B_VSDivNoOverflow(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvsdiv_no_overflow(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create a predicate that checks that the bit-wise negation does not overflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VNegNoOverflow(BitVecExpr t) + { + + + + CheckContextMatch(t); + return new BoolExpr(this, Z3native.mk_bvneg_no_overflow(nCtx, t.x#gno)); + } + +(** + Create a predicate that checks that the bit-wise multiplication does not overflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VMulNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvmul_no_overflow(nCtx, t1.x#gno, t2.x#gno, (isSigned) ? 1 : 0)); + } + +(** + Create a predicate that checks that the bit-wise multiplication does not underflow. +*) + + The arguments must be of bit-vector sort. + + let mk_B_VMulNoUnderflow(BitVecExpr t1, BitVecExpr t2) + { + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + return new BoolExpr(this, Z3native.mk_bvmul_no_underflow(nCtx, t1.x#gno, t2.x#gno)); + } + + +(* ARRAYS *) +(** + Create an array constant. +*) + let mk_Array_Const(Symbol name, Sort domain, Sort range) + { + + + + + + return (ArrayExpr)MkConst(name, MkArraySort(domain, range)); + } + +(** + Create an array constant. +*) + let mk_Array_Const(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, Z3native.mk_select(nCtx, a.x#gno, i.x#gno)); + } + +(** + 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, Z3native.mk_store(nCtx, a.x#gno, i.x#gno, v.x#gno)); + } + +(** + Create a constant array. +*) + + The resulting term is an array, such that a selecton an arbitrary index + produces the value v. + + + + let mk_Const_Array(Sort domain, Expr v) + { + + + + + CheckContextMatch(domain); + CheckContextMatch(v); + return new ArrayExpr(this, Z3native.mk_const_array(nCtx, domain.x#gno, v.x#gno)); + } + +(** + 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(Func_Decl f, params ArrayExpr[] args) + { + + + + + CheckContextMatch(f); + CheckContextMatch(args); + return (ArrayExpr)Expr.Create(this, Z3native.mk_map(nCtx, f.x#gno, 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. + + let mk_Term_Array(ArrayExpr array) + { + + + + CheckContextMatch(array); + return Expr.Create(this, Z3native.mk_array_default(nCtx, array.x#gno)); + } + + +(* SETS *) +(** + Create a set type. +*) + let mk_Set_Sort(Sort ty) + { + + + + CheckContextMatch(ty); + return new SetSort(this, ty); + } + +(** + Create an empty set. +*) + let mk_Empty_Set(Sort domain) + { + + + + CheckContextMatch(domain); + return Expr.Create(this, Z3native.mk_empty_set(nCtx, domain.x#gno)); + } + +(** + Create the full set. +*) + let mk_Full_Set(Sort domain) + { + + + + CheckContextMatch(domain); + return Expr.Create(this, Z3native.mk_full_set(nCtx, domain.x#gno)); + } + +(** + Add an element to the set. +*) + let mk_Set_Add(Expr set, Expr element) + { + + + + + CheckContextMatch(set); + CheckContextMatch(element); + return Expr.Create(this, Z3native.mk_set_add(nCtx, set.x#gno, element.x#gno)); + } + + +(** + Remove an element from a set. +*) + let mk_Set_Del(Expr set, Expr element) + { + + + + + CheckContextMatch(set); + CheckContextMatch(element); + return Expr.Create(this, Z3native.mk_set_del(nCtx, set.x#gno, element.x#gno)); + } + +(** + Take the union of a list of sets. +*) + let mk_Set_Union(params Expr[] args) + { + + + + CheckContextMatch(args); + return Expr.Create(this, Z3native.mk_set_union(nCtx, (uint)args.Length, AST.ArrayToNative(args))); + } + +(** + Take the intersection of a list of sets. +*) + let mk_Set_Intersection(params Expr[] args) + { + + + + + CheckContextMatch(args); + return Expr.Create(this, Z3native.mk_set_intersect(nCtx, (uint)args.Length, AST.ArrayToNative(args))); + } + +(** + Take the difference between two sets. +*) + let mk_Set_Difference(Expr arg1, Expr arg2) + { + + + + + CheckContextMatch(arg1); + CheckContextMatch(arg2); + return Expr.Create(this, Z3native.mk_set_difference(nCtx, arg1.x#gno, arg2.x#gno)); + } + +(** + Take the complement of a set. +*) + let mk_Set_Complement(Expr arg) + { + + + + CheckContextMatch(arg); + return Expr.Create(this, Z3native.mk_set_complement(nCtx, arg.x#gno)); + } + +(** + Check for set membership. +*) + let mk_Set_Membership(Expr elem, Expr set) + { + + + + + CheckContextMatch(elem); + CheckContextMatch(set); + return Expr.Create(this, Z3native.mk_set_member(nCtx, elem.x#gno, set.x#gno)); + } + +(** + Check for subsetness of sets. +*) + let mk_Set_Subset(Expr arg1, Expr arg2) + { + + + + + CheckContextMatch(arg1); + CheckContextMatch(arg2); + return Expr.Create(this, Z3native.mk_set_subset(nCtx, arg1.x#gno, arg2.x#gno)); + } + + +(* NUMERALS *) + +(* GENERAL NUMERALS *) +(** + Create a Term of a given sort. +*) + @param v 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]*. + @param ty 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, Z3native.mk_numeral(nCtx, v, ty.x#gno)); + } + +(** + 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. +*) + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(int v, Sort ty) + { + + + + CheckContextMatch(ty); + return Expr.Create(this, Z3native.mk_int(nCtx, v, ty.x#gno)); + } + +(** + 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. +*) + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(uint v, Sort ty) + { + + + + CheckContextMatch(ty); + return Expr.Create(this, Z3native.mk_unsigned_int(nCtx, v, ty.x#gno)); + } + +(** + 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. +*) + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(long v, Sort ty) + { + + + + CheckContextMatch(ty); + return Expr.Create(this, Z3native.mk_int64(nCtx, v, ty.x#gno)); + } + +(** + 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. +*) + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(ulong v, Sort ty) + { + + + + CheckContextMatch(ty); + return Expr.Create(this, Z3native.mk_unsigned_int64(nCtx, v, ty.x#gno)); + } + + +(* REALS *) +(** + Create a real from a fraction. +*) + @param num numerator of rational. + @param den 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, Z3native.mk_real(nCtx, num, den)); + } + +(** + Create a real numeral. +*) + @param v 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, Z3native.mk_numeral(nCtx, v, RealSort.x#gno)); + } + +(** + Create a real numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(int v) + { + + + return new RatNum(this, Z3native.mk_int(nCtx, v, RealSort.x#gno)); + } + +(** + Create a real numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(uint v) + { + + + return new RatNum(this, Z3native.mk_unsigned_int(nCtx, v, RealSort.x#gno)); + } + +(** + Create a real numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(long v) + { + + + return new RatNum(this, Z3native.mk_int64(nCtx, v, RealSort.x#gno)); + } + +(** + Create a real numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(ulong v) + { + + + return new RatNum(this, Z3native.mk_unsigned_int64(nCtx, v, RealSort.x#gno)); + } + + +(* INTEGERS *) +(** + Create an integer numeral. +*) + @param v A string representing the Term value in decimal notation. + public IntNum MkInt(string v) + { + + + return new IntNum(this, Z3native.mk_numeral(nCtx, v, IntSort.x#gno)); + } + +(** + Create an integer numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(int v) + { + + + return new IntNum(this, Z3native.mk_int(nCtx, v, IntSort.x#gno)); + } + +(** + Create an integer numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(uint v) + { + + + return new IntNum(this, Z3native.mk_unsigned_int(nCtx, v, IntSort.x#gno)); + } + +(** + Create an integer numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(long v) + { + + + return new IntNum(this, Z3native.mk_int64(nCtx, v, IntSort.x#gno)); + } + +(** + Create an integer numeral. +*) + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(ulong v) + { + + + return new IntNum(this, Z3native.mk_unsigned_int64(nCtx, v, IntSort.x#gno)); + } + + +(* BIT-VECTORS *) +(** + Create a bit-vector numeral. +*) + @param v A string representing the value in decimal notation. + @param size the size of the bit-vector + let mk_B_V(string v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + +(** + Create a bit-vector numeral. +*) + @param v value of the numeral. + @param size the size of the bit-vector + let mk_B_V(int v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + +(** + Create a bit-vector numeral. +*) + @param v value of the numeral. + @param size the size of the bit-vector + let mk_B_V(uint v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + +(** + Create a bit-vector numeral. +*) + @param v value of the numeral. + @param size the size of the bit-vector + let mk_B_V(long v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + +(** + Create a bit-vector numeral. +*) + @param v value of the numeral. + @param size the size of the bit-vector + let mk_B_V(ulong v, uint size) + { + + + return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); + } + + + // Numerals + +(* QUANTIFIERS *) +(** + 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. + + @param sorts the sorts of the bound variables. + @param names names of the bound variables + @param body the body of the quantifier. + @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. + @param patterns array containing the patterns created using MkPattern. + @param noPatterns array containing the anti-patterns created using MkPattern. + @param quantifierID optional symbol to track quantifier. + @param skolemID optional symbol to track skolem constants. + public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + + + + + return new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); + } + + +(** + Create a universal Quantifier. +*) + public Quantifier MkForall(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + 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, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + + + + return new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); + } + +(** + Create an existential Quantifier. +*) + public Quantifier MkExists(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + return new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); + } + + +(** + Create a Quantifier. +*) + public Quantifier MkQuantifier(bool universal, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + + + + + 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(bool universal, Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + { + + + + + + + + if (universal) + return MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); + else + return MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); + } + + + + // Expr + +(* OPTIONS *) + +(** + 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 Z3_ast_print_mode PrintMode + { + set { Z3native.set_ast_print_mode(nCtx, (uint)value); } + } + + +(* SMT Files & Strings *) +(** + Convert a benchmark into an SMT-LIB formatted string. +*) + @param name Name of the benchmark. The argument is optional. + @param logic The benchmark logic. + @param status The status string (sat, unsat, or unknown) + @param attributes Other attributes, such as source, difficulty or category. + @param assumptions Auxiliary assumptions. + @param formula 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 Z3native.benchmark_to_smtlib_string(nCtx, name, logic, status, attributes, + (uint)assumptions.Length, AST.ArrayToNative(assumptions), + formula.x#gno); + } + +(** + 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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + { + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_string(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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + { + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_file(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 uint NumSMTLIBFormulas { get { return Z3native.get_smtlib_num_formulas(nCtx)) + +(** + The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public BoolExpr[] SMTLIBFormulas + { + get + { + + + uint n = NumSMTLIBFormulas; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)Expr.Create(this, Z3native.get_smtlib_formula(nCtx, i)); + return res; + } + } + +(** + The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public uint NumSMTLIBAssumptions { get { return Z3native.get_smtlib_num_assumptions(nCtx)) + +(** + The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public BoolExpr[] SMTLIBAssumptions + { + get + { + + + uint n = NumSMTLIBAssumptions; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)Expr.Create(this, Z3native.get_smtlib_assumption(nCtx, i)); + return res; + } + } + +(** + The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public uint NumSMTLIBDecls { get { return Z3native.get_smtlib_num_decls(nCtx)) + +(** + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public Func_Decl[] SMTLIBDecls + { + get + { + + + uint n = NumSMTLIBDecls; + Func_Decl[] res = new Func_Decl[n]; + for (uint i = 0; i < n; i++) + res[i] = new Func_Decl(this, Z3native.get_smtlib_decl(nCtx, i)); + return res; + } + } + +(** + The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public uint NumSMTLIBSorts { get { return Z3native.get_smtlib_num_sorts(nCtx)) + +(** + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. +*) + public Sort[] SMTLIBSorts + { + get + { + + + uint n = NumSMTLIBSorts; + Sort[] res = new Sort[n]; + for (uint i = 0; i < n; i++) + res[i] = Sort.Create(this, Z3native.get_smtlib_sort(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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + { + + + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + return (BoolExpr)Expr.Create(this, Z3native.parse_smtlib2_string(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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + { + + + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + return (BoolExpr)Expr.Create(this, Z3native.parse_smtlib2_file(nCtx, fileName, + AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); + } + + +(* GOALS *) +(** + Creates a new Goal. +*) + + Note that the Context must have been created with proof generation support if + is set to true here. + + @param models Indicates whether model generation should be enabled. + @param unsatCores Indicates whether unsat core generation should be enabled. + @param proofs Indicates whether proof generation should be enabled. + public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) + { + + + return new Goal(this, models, unsatCores, proofs); + } + + +(* PARAMETERSETS *) +(** + Creates a new ParameterSet. +*) + public Params MkParams ( ctx : context ) = + { + + + return new Params(this); + } + + +(* TACTICS *) +(** + The number of supported tactics. +*) + public uint NumTactics + { + get { return Z3native.get_num_tactics(nCtx); } + } + +(** + The names of all supported tactics. +*) + public string[] TacticNames + { + get + { + + + uint n = NumTactics; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_tactic_name(nCtx, i); + return res; + } + } + +(** + Returns a string containing a description of the tactic with the given name. +*) + public string TacticDescription(string name) + { + + + return Z3native.tactic_get_descr(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, params Tactic[] ts) + { + + + + + + + CheckContextMatch(t1); + CheckContextMatch(t2); + CheckContextMatch(ts); + + IntPtr last = IntPtr.Zero; + if (ts != null && ts.Length > 0) + { + last = ts[ts.Length - 1].x#gno; + for (int i = ts.Length - 2; i >= 0; i--) + last = Z3native.tactic_and_then(nCtx, ts[i].x#gno, last); + } + if (last != IntPtr.Zero) + { + last = Z3native.tactic_and_then(nCtx, t2.x#gno, last); + return new Tactic(this, Z3native.tactic_and_then(nCtx, t1.x#gno, last)); + } + else + return new Tactic(this, Z3native.tactic_and_then(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + 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, params 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, Z3native.tactic_or_else(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Create a tactic that applies to a goal for milliseconds. +*) + + If does not terminate within milliseconds, then it fails. + + public Tactic TryFor(Tactic t, uint ms) + { + + + + CheckContextMatch(t); + return new Tactic(this, Z3native.tactic_try_for(nCtx, t.x#gno, 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, Z3native.tactic_when(nCtx, p.x#gno, t.x#gno)); + } + +(** + 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, Z3native.tactic_cond(nCtx, p.x#gno, t1.x#gno, t2.x#gno)); + } + +(** + 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, uint max = uint.MaxValue) + { + + + + CheckContextMatch(t); + return new Tactic(this, Z3native.tactic_repeat(nCtx, t.x#gno, max)); + } + +(** + Create a tactic that just returns the given goal. +*) + public Tactic Skip ( ctx : context ) = + { + + + return new Tactic(this, Z3native.tactic_skip(nCtx)); + } + +(** + Create a tactic always fails. +*) + public Tactic Fail ( ctx : context ) = + { + + + return new Tactic(this, Z3native.tactic_fail(nCtx)); + } + +(** + Create a tactic that fails if the probe evaluates to false. +*) + public Tactic FailIf(Probe p) + { + + + + CheckContextMatch(p); + return new Tactic(this, Z3native.tactic_fail_if(nCtx, p.x#gno)); + } + +(** + 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 ( ctx : context ) = + { + + + return new Tactic(this, Z3native.tactic_fail_if_not_decided(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, Z3native.tactic_using_params(nCtx, t.x#gno, p.x#gno)); + } + +(** + 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(params Tactic[] t) + { + + + + CheckContextMatch(t); + return new Tactic(this, Z3native.tactic_par_or(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, Z3native.tactic_par_and_then(nCtx, t1.x#gno, t2.x#gno)); + } + +(** + Interrupt the execution of a Z3 procedure. +*) + This procedure can be used to interrupt: solvers, simplifiers and tactics. + public void Interrupt ( ctx : context ) = + { + Z3native.interrupt(nCtx); + } + + +(* PROBES *) +(** + The number of supported Probes. +*) + public uint NumProbes + { + get { return Z3native.get_num_probes(nCtx); } + } + +(** + The names of all supported Probes. +*) + public string[] ProbeNames + { + get + { + + + uint n = NumProbes; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_probe_name(nCtx, i); + return res; + } + } + +(** + Returns a string containing a description of the probe with the given name. +*) + public string ProbeDescription(string name) + { + + + return Z3native.probe_get_descr(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, Z3native.probe_const(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, Z3native.probe_lt(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_gt(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_le(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_ge(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_eq(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_and(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_or(nCtx, p1.x#gno, p2.x#gno)); + } + +(** + 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, Z3native.probe_not(nCtx, p.x#gno)); + } + + +(* SOLVERS *) +(** + 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 = null) + { + + + if (logic == null) + return new Solver(this, Z3native.mk_solver(nCtx)); + else + return new Solver(this, Z3native.mk_solver_for_logic(nCtx, logic.x#gno)); + } + +(** + Creates a new (incremental) solver. +*) + + public Solver MkSolver(string logic) + { + + + return MkSolver(MkSymbol(logic)); + } + +(** + Creates a new (incremental) solver. +*) + let mk_Simple_Solver ( ctx : context ) = + { + + + return new Solver(this, Z3native.mk_simple_solver(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, Z3native.mk_solver_from_tactic(nCtx, t.x#gno)); + } + + +(* FIXEDPOINTS *) +(** + Create a Fixedpoint context. +*) + public Fixedpoint MkFixedpoint ( ctx : context ) = + { + + + return new Fixedpoint(this); + } + + + +(* MISCELLANEOUS *) +(** + 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., + . + + @param nativeObject 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., + ). + + @param a The AST to unwrap. + public IntPtr UnwrapAST(AST a) + { + return a.x#gno; + } + +(** + Return a string describing all available parameters to Expr.Simplify. +*) + public string SimplifyHelp ( ctx : context ) = + { + + + return Z3native.simplify_get_help(nCtx); + } + +(** + Retrieves parameter descriptions for simplifier. +*) + public ParamDescrs SimplifyParameterDescriptions + { + get { return new ParamDescrs(this, Z3native.simplify_get_param_descrs(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(bool enabled) + { + Z3native.toggle_warning_messages((enabled) ? 1 : 0); + } + + +(* ERROR HANDLING *) + //(** + //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; + + +(* PARAMETERS *) +(** + 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) + { + Z3native.update_param_value(nCtx, id, value); + } + +(** + Get a configuration parameter. +*) + + Returns null if the parameter value does not exist. + + + public string GetParamValue(string id) + { + IntPtr res = IntPtr.Zero; + int r = Z3native.get_param_value(nCtx, id, out res); + if (r == (int)Z3_lbool.Z3_L_FALSE) + return null; + else + return Marshal.PtrToStringAnsi(res); + } + + + +(* INTERNAL *) + internal IntPtr m_ctx = IntPtr.Zero; + internal Z3native.error_handler m_n_err_handler = null; + internal IntPtr nCtx { get { return m_ctx) + + internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) + { + // Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. + } + + internal void InitContext ( ctx : context ) = + { + PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); // keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); + } +*) end From c28f0e7c8ac61db34bdb96493d3df1913bc2a5d4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 01:45:10 +0000 Subject: [PATCH 142/248] ML API bugfixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 8 ++- scripts/update_api.py | 2 +- src/api/ml/z3.ml | 136 ++++++++++++++++++++------------------ 3 files changed, 80 insertions(+), 66 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 7046a92b0..f414e9d1a 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -18,10 +18,16 @@ let _ = let ctx = (new context cfg) in let is = (mk_symbol_int ctx 42) in let ss = (mk_symbol_string ctx "mySymbol") in + let bs = (mk_bool_sort ctx) in + let ints = (mk_int_sort ctx) in + let rs = (mk_real_sort ctx) in Printf.printf "int symbol: %s\n" (Symbol.to_string (is :> symbol)); Printf.printf "string symbol: %s\n" (Symbol.to_string (ss :> symbol)); + Printf.printf "bool sort: %s\n" (Sort.to_string bs); + Printf.printf "int sort: %s\n" (Sort.to_string ints); + Printf.printf "real sort: %s\n" (Sort.to_string rs); Printf.printf "Disposing...\n"; - ctx#dispose (* can do, but we'd rather let it go out of scope *) ; + Gc.full_major () ); Printf.printf "Exiting.\n"; ;; diff --git a/scripts/update_api.py b/scripts/update_api.py index c8cd05c7e..c3f2abce6 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1280,7 +1280,7 @@ def mk_ml(): ml_wrapper.write(' CAMLxparam3(X11,X12,X13); \n') ml_wrapper.write('\n\n') ml_wrapper.write('static struct custom_operations default_custom_ops = {\n') - ml_wrapper.write(' identifier: "default handling",\n') + ml_wrapper.write(' identifier: (char*) "default handling",\n') ml_wrapper.write(' finalize: custom_finalize_default,\n') ml_wrapper.write(' compare: custom_compare_default,\n') ml_wrapper.write(' hash: custom_hash_default,\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 2100f371e..3a0e9208e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -30,21 +30,25 @@ object (self) Z3native.del_config(cfg) ; v - val mutable m_refCount : int = 0 + val mutable m_obj_cnt : int = 0 initializer - Gc.finalise (fun self -> self#dispose) self + (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) + let f = fun o -> o#dispose in + let v = self in + Gc.finalise f v method dispose : unit = - if m_refCount == 0 then ( - Printf.printf "Disposing context %d \n" (Oo.id self) ; + if m_obj_cnt == 0 then ( + (* Printf.printf "Disposing context %d \n" (Oo.id self) ; *) (Z3native.del_context m_n_ctx) ) else ( + Printf.printf "NOT DISPOSING context %d because it still has %d objects alive\n" (Oo.id self) m_obj_cnt; (* re-queue for finalization? *) ) - method sub_one_ctx_obj = m_refCount <- m_refCount - 1 - method add_one_ctx_obj = m_refCount <- m_refCount + 1 + method add_one_ctx_obj = m_obj_cnt <- m_obj_cnt + 1 + method sub_one_ctx_obj = m_obj_cnt <- m_obj_cnt - 1 method gno = m_n_ctx end @@ -62,18 +66,21 @@ object (self) m_ctx#add_one_ctx_obj | None -> () ); - Gc.finalise (fun self -> self#dispose) self + (* Printf.printf "Installing finalizer on z3object %d \n" (Oo.id self) ; *) + let f = fun o -> o#dispose in + let v = self in + Gc.finalise f v method virtual incref : Z3native.ptr -> Z3native.ptr -> unit method virtual decref : Z3native.ptr -> Z3native.ptr -> unit - (* - Disposes of the underlying native Z3 object. - *) method dispose = - Printf.printf "Disposing z3object %d \n" (Oo.id self) ; + (* Printf.printf "Disposing z3object %d \n" (Oo.id self) ; *) (match m_n_obj with - | Some (x) -> self#decref m_ctx#gno x; m_n_obj <- None; m_ctx#sub_one_ctx_obj + | Some (x) -> + self#decref m_ctx#gno x; + m_ctx#sub_one_ctx_obj ; + m_n_obj <- None; | None -> () ); @@ -81,10 +88,11 @@ object (self) | Some(x) -> x | None -> raise (Z3native.Exception "Z3 object lost") - method sno nc o = - self#incref nc o ; + method sno (ctx : context) o = + m_ctx#add_one_ctx_obj ; + self#incref ctx#gno o ; (match m_n_obj with - | Some(x) -> self#decref nc x + | Some(x) -> self#decref ctx#gno x ; m_ctx#sub_one_ctx_obj | None -> () ); m_n_obj <- Some o @@ -107,7 +115,7 @@ end class symbol ctx = object (self) inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method incref ctx o = () method decref ctx o = () end @@ -120,16 +128,16 @@ let symbolaton (a : symbol array) = class int_symbol ctx = object(self) inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_int i = (self#sno ctx#gno (Z3native.mk_int_symbol ctx#gno i)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_int i = (self#sno ctx (Z3native.mk_int_symbol ctx#gno i)) ; self end (** String symbol objects *) class string_symbol ctx = object(self) inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_string name = (self#sno ctx#gno (Z3native.mk_string_symbol ctx#gno name)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_string name = (self#sno ctx (Z3native.mk_string_symbol ctx#gno name)) ; self end let create_symbol ctx no = @@ -141,7 +149,7 @@ let create_symbol ctx no = class ast ctx = object (self) inherit z3object ctx None as super (* CMW: derive from icomparable? *) - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method incref nc o = Z3native.inc_ref nc o method decref nc o = Z3native.dec_ref nc o @@ -155,44 +163,44 @@ let astaton (a : ast array) = class sort ctx = object (self) inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Arithmetic sort objects, i.e., Int or Real. *) class arith_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Array sorts objects *) class array_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx#gno (Z3native.mk_array_sort ctx#gno domain#gno range#gno)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx (Z3native.mk_array_sort ctx#gno domain#gno range#gno)) ; self end (** Bit-vector sort objects *) class bitvec_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Boolean sort objects *) class bool_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Datatype sort objects *) class datatype_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_sc (name : symbol) constructors = (self#sno ctx#gno (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (astaton constructors)))) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_sc (name : symbol) constructors = (self#sno ctx (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (astaton constructors)))) ; self end (** Enum sort objects *) @@ -201,12 +209,12 @@ object (self) inherit sort ctx as super val mutable _constdecls = None val mutable _testerdecls = None - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (enum_names : symbol array) = let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in _constdecls <- Some a ; _testerdecls <- Some b ; - (self#sno ctx#gno r) ; + (self#sno ctx r) ; self method const_decls = match _constdecls with @@ -222,37 +230,37 @@ end class int_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Real sort objects *) class real_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Uninterpreted sort objects *) class uninterpreted_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_s (s : symbol) = (self #sno ctx#gno (Z3native.mk_uninterpreted_sort ctx#gno s#gno)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_s (s : symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort ctx#gno s#gno)) ; self end (** Finite domain sort objects *) class finite_domain_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx#gno (Z3native.mk_finite_domain_sort ctx#gno s#gno sz)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort ctx#gno s#gno sz)) ; self end (** Relation sort objects *) class relation_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** List sort objects *) @@ -265,7 +273,7 @@ object (self) val mutable _is_consdecl = None val mutable _headdecl = None val mutable _taildecl = None - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (elem_sort : sort) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in _nildecl <- Some a ; @@ -274,7 +282,7 @@ object (self) _is_consdecl <- Some d ; _headdecl <- Some e ; _taildecl <- Some f ; - (self#sno ctx#gno r) ; + (self#sno ctx r) ; self method nil_decl = match _nildecl with @@ -307,18 +315,18 @@ end class set_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_s (s : sort) = (self#sno ctx#gno s#gno) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_s (s : sort) = (self#sno ctx s#gno) ; self end (** Tuple sort objects *) class tuple_sort ctx = object (self) inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_siss (name : symbol) (num_fields: int) (field_names : symbol array) (field_sorts : sort array) = let (x,_,_) = (Z3native.mk_tuple_sort ctx#gno name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in - (self#sno ctx#gno x) ; + (self#sno ctx x) ; self end @@ -339,9 +347,9 @@ let create_sort ctx obj = class func_decl ctx = object (self) inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self - method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx#gno (Z3native.mk_func_decl ctx#gno name#gno (Array.length domain) (astaton domain) range#gno)) ; self - method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx#gno (Z3native.mk_fresh_func_decl ctx#gno prefix (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl ctx#gno name#gno (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl ctx#gno prefix (Array.length domain) (astaton domain) range#gno)) ; self method incref nc o = super#incref nc o method decref nc o = super#decref nc o @@ -388,7 +396,7 @@ end class expr ctx = object(self) inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end let expraton (a : expr array) = @@ -399,77 +407,77 @@ let expraton (a : expr array) = class bool_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Arithmetic expression objects (int/real) *) class arith_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Int expression objects *) class int_expr ctx = object (self) inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Real expression objects *) class real_expr ctx = object (self) inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Bit-vector expression objects *) class bitvec_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Array expression objects *) class array_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Datatype expression objects *) class datatype_expr ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Integer numeral expression objects *) class int_num ctx = object (self) inherit int_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Rational numeral expression objects *) class rat_num ctx = object (self) inherit real_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Bit-vector numeral expression objects *) class bitvec_num ctx = object (self) inherit bitvec_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end (** Algebraic numeral expression objects *) class algebraic_num ctx = object (self) inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end @@ -477,7 +485,7 @@ end class quantifier ctx = object (self) inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx#gno obj) ; self + method cnstr_obj obj = (self#sno ctx obj) ; self end @@ -1112,7 +1120,7 @@ struct if (Array.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - x#sno x#gnc (Z3native.update_term x#gnc x#gno (Array.length args) (expraton args)) + x#sno x#gc (Z3native.update_term x#gnc x#gno (Array.length args) (expraton args)) (** Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. @@ -2483,7 +2491,7 @@ struct Create a new Boolean sort. *) let mk_bool_sort ( ctx : context ) = - (new bool_sort ctx) + (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort ctx#gno) (** Create a new uninterpreted sort. @@ -2501,13 +2509,13 @@ struct Create a new integer sort. *) let mk_int_sort ( ctx : context ) = - (new int_sort ctx) + (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort ctx#gno) (** Create a real sort. *) let mk_real_sort ( ctx : context ) = - (new real_sort ctx) + (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort ctx#gno) (** Create a new bit-vector sort. From 2a6c74bc13e57459effcb46c0bcebc88bb7582b3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 03:57:18 +0000 Subject: [PATCH 143/248] New ML API savepoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 572 ++++++++++++++++++++++++++++++----------------- 1 file changed, 364 insertions(+), 208 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 3a0e9208e..116d7a230 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -33,11 +33,11 @@ object (self) val mutable m_obj_cnt : int = 0 initializer - (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) - let f = fun o -> o#dispose in - let v = self in - Gc.finalise f v - + (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) + let f = fun o -> o#dispose in + let v = self in + Gc.finalise f v + method dispose : unit = if m_obj_cnt == 0 then ( (* Printf.printf "Disposing context %d \n" (Oo.id self) ; *) @@ -110,7 +110,6 @@ object (self) method decref ctx o = Z3native.params_dec_ref ctx o end - (** Symbol objects *) class symbol ctx = object (self) @@ -166,6 +165,10 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end +let sortaton (a : sort array) = + let f (e : sort) = e#gno in + Array.map f a + (** Arithmetic sort objects, i.e., Int or Real. *) class arith_sort ctx = object (self) @@ -195,20 +198,12 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end -(** Datatype sort objects *) -class datatype_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_sc (name : symbol) constructors = (self#sno ctx (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (astaton constructors)))) ; self -end - (** Enum sort objects *) class enum_sort ctx = object (self) inherit sort ctx as super - val mutable _constdecls = None - val mutable _testerdecls = None + val mutable _constdecls : Z3native.ptr array option = None + val mutable _testerdecls : Z3native.ptr array option = None method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (enum_names : symbol array) = let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in @@ -267,12 +262,12 @@ end class list_sort ctx = object (self) inherit sort ctx as super - val mutable _nildecl = None - val mutable _is_nildecl = None - val mutable _consdecl = None - val mutable _is_consdecl = None - val mutable _headdecl = None - val mutable _taildecl = None + val mutable _nildecl : Z3native.ptr option = None + val mutable _is_nildecl : Z3native.ptr option = None + val mutable _consdecl : Z3native.ptr option = None + val mutable _is_consdecl : Z3native.ptr option = None + val mutable _headdecl : Z3native.ptr option = None + val mutable _taildecl : Z3native.ptr option = None method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (elem_sort : sort) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in @@ -291,23 +286,23 @@ object (self) method is_nil_decl = match _is_nildecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_nil decls") + | None -> raise (Z3native.Exception "Missing is_nil decl") method cons_decl = match _consdecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing cons decls") + | None -> raise (Z3native.Exception "Missing cons decl") method is_cons_decl = match _is_consdecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_cons decls") + | None -> raise (Z3native.Exception "Missing is_cons decl") method head_decl = match _headdecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing head decls") + | None -> raise (Z3native.Exception "Missing head decl") method tail_decl = match _taildecl with | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tail decls") + | None -> raise (Z3native.Exception "Missing tail decl") end @@ -330,18 +325,6 @@ object (self) self end -let create_sort ctx obj = - match (int2sort_kind (Z3native.get_sort_kind ctx#gno obj)) with - | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) - | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) - | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) - | DATATYPE_SORT -> (((new datatype_sort ctx)#cnstr_obj obj) :> sort) - | INT_SORT -> (((new int_sort ctx)#cnstr_obj obj) :> sort) - | REAL_SORT -> (((new real_sort ctx)#cnstr_obj obj) :> sort) - | UNINTERPRETED_SORT -> (((new uninterpreted_sort ctx)#cnstr_obj obj) :> sort) - | FINITE_DOMAIN_SORT -> (((new finite_domain_sort ctx)#cnstr_obj obj) :> sort) - | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") (** Function declaration objects *) class func_decl ctx = @@ -392,6 +375,126 @@ object (self) method rational = m_r end + +(** Constructor objects *) +class constructor ctx = +object (self) + inherit z3object ctx None as super + val mutable m_n : int = 0 + val mutable m_tester_decl : func_decl option = None + val mutable m_constructor_decl : func_decl option = None + val mutable m_accessor_decls : func_decl array option = None + method incref ctx o = () + method decref ctx o = () + initializer + let f = fun o -> Z3native.del_constructor o#gnc o#gno in + let v = self in + Gc.finalise f v + + method cnstr_ssssi (name : symbol) (recognizer : symbol) (field_names : symbol array) (sorts : sort array) (sort_refs : int array) = + m_n <- (Array.length field_names) ; + if m_n != (Array.length sorts) then + raise (Z3native.Exception "Number of field names does not match number of sorts") + else + if m_n != (Array.length sort_refs) then + raise (Z3native.Exception "Number of field names does not match number of sort refs") + else + let o = (Z3native.mk_constructor ctx#gno name#gno recognizer#gno m_n (symbolaton field_names) + (sortaton sorts) + sort_refs) in + self#sno ctx o ; + self + + method private init = + match m_tester_decl with + | None -> + let (a, b, c) = (Z3native.query_constructor self#gnc self#gno m_n) in + m_constructor_decl <- Some ((new func_decl ctx)#cnstr_obj a) ; + m_tester_decl <- Some ((new func_decl ctx)#cnstr_obj b) ; + m_accessor_decls <- Some (let f e = ((new func_decl ctx)#cnstr_obj e) in Array.map f c) ; + () + | _ -> () + + method get_n = m_n + + method tester_decl = match m_tester_decl with + | Some(x) -> x + | None -> self#init ; self#tester_decl + + method constructor_decl = match m_constructor_decl with + | Some(x) -> x + | None -> self#init ; self#constructor_decl + + method accessor_decls = match m_accessor_decls with + | Some(x) -> x + | None -> self#init ; self#accessor_decls +end + +let constructoraton (a : constructor array) = + let f (e : constructor) = e#gno in + Array.map f a + +(** Constructor list objects *) +class constructor_list ctx = +object (self) + inherit z3object ctx None + method incref ctx o = () + method decref ctx o = () + initializer + let f = fun o -> Z3native.del_constructor_list o#gnc o#gno in + let v = self in + Gc.finalise f v + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_ca ( c : constructor array ) = + self#sno ctx (Z3native.mk_constructor_list ctx#gno (Array.length c) (constructoraton c)) ; + self +end + +let constructor_listaton (a : constructor_list array) = + let f (e : constructor_list) = e#gno in + Array.map f a + +(** Datatype sort objects *) +class datatype_sort ctx = +object (self) + inherit sort ctx as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_sc (name : symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (constructoraton constructors)))) ; self +end + +let create_sort ctx obj = + match (int2sort_kind (Z3native.get_sort_kind ctx#gno obj)) with + | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) + | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) + | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) + | DATATYPE_SORT -> (((new datatype_sort ctx)#cnstr_obj obj) :> sort) + | INT_SORT -> (((new int_sort ctx)#cnstr_obj obj) :> sort) + | REAL_SORT -> (((new real_sort ctx)#cnstr_obj obj) :> sort) + | UNINTERPRETED_SORT -> (((new uninterpreted_sort ctx)#cnstr_obj obj) :> sort) + | FINITE_DOMAIN_SORT -> (((new finite_domain_sort ctx)#cnstr_obj obj) :> sort) + | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + +(** AST vector objects *) +class ast_vector ctx = +object (self) + inherit z3object ctx None + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref ctx o = Z3native.ast_vector_inc_ref ctx o + method decref ctx o = Z3native.ast_vector_dec_ref ctx o +end + + +(** AST map objects *) +class ast_map ctx = +object (self) + inherit z3object ctx None + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref ctx o = Z3native.ast_map_inc_ref ctx o + method decref ctx o = Z3native.ast_map_dec_ref ctx o +end + + (** Expression objects *) class expr ctx = object(self) @@ -492,7 +595,8 @@ end (**/**) -(** Interaction logging for 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. *) module Log = @@ -512,7 +616,7 @@ struct let append s = Z3native.append_log s end -(** Version information. *) +(** Version information *) module Version = struct (** The major version. *) @@ -536,7 +640,7 @@ struct string_of_int rev ^ "." end -(** Symbols are used to name several term and type constructors. *) +(** Symbols are used to name several term and type constructors *) module Symbol = struct (** The kind of the symbol (int or string) *) @@ -562,9 +666,7 @@ struct end -(** - The Sort module implements type information for ASTs. -*) +(** The Sort module implements type information for ASTs *) module Sort = struct (** @@ -612,13 +714,13 @@ struct end (** Bit-vector sorts *) -module BitVectorSort = +module BitVecSort = struct (** The size of the bit-vector sort. *) let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno end -(** Finite domain sorts. *) +(** Finite domain sorts *) module FiniteDomainSort = struct (** The size of the finite domain sort. *) @@ -628,7 +730,7 @@ struct else raise (Z3native.Exception "Conversion failed.") end -(** Relation sorts. *) +(** Relation sorts *) module RelationSort = struct (** The arity of the relation sort. *) @@ -684,60 +786,60 @@ let create_ast ctx no = | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") (**/**) -(** Function declarations. *) +(** Function declarations *) module FuncDecl = struct -(** Parameters of Func_Decls *) + (** Parameters of Func_Decls *) module Parameter = struct - (** - The kind of the parameter. - *) + (** + The kind of the parameter. + *) let get_kind (x : parameter) = x#kind - (**The int value of the parameter.*) + (**The int value of the parameter.*) let get_int (x : parameter) = if (x#kind != PARAMETER_INT) then raise (Z3native.Exception "parameter is not an int") else x#int - (**The double value of the parameter.*) + (**The double value of the parameter.*) let get_double (x : parameter) = if (x#kind != PARAMETER_DOUBLE) then raise (Z3native.Exception "parameter is not a double") else x#double - (**The Symbol value of the parameter.*) + (**The Symbol value of the parameter.*) let get_symbol (x : parameter) = if (x#kind != PARAMETER_SYMBOL) then raise (Z3native.Exception "parameter is not a symbol") else x#symbol - (**The Sort value of the parameter.*) + (**The Sort value of the parameter.*) let get_sort (x : parameter) = if (x#kind != PARAMETER_SORT) then raise (Z3native.Exception "parameter is not a sort") else x#sort - (**The AST value of the parameter.*) + (**The AST value of the parameter.*) let get_ast (x : parameter) = if (x#kind != PARAMETER_AST) then raise (Z3native.Exception "parameter is not an ast") else x#ast - (**The FunctionDeclaration value of the parameter.*) + (**The FunctionDeclaration value of the parameter.*) let get_ast (x : parameter) = if (x#kind != PARAMETER_FUNC_DECL) then raise (Z3native.Exception "parameter is not an function declaration") else x#func_decl - (**The rational string value of the parameter.*) + (**The rational string value of the parameter.*) let get_rational (x : parameter) = if (x#kind != PARAMETER_RATIONAL) then raise (Z3native.Exception "parameter is not a ratinoal string") @@ -826,7 +928,7 @@ struct (** Create expression that applies function to arguments. - + @param args The arguments *) let apply (x : func_decl) (args : expr array) = create_expr_fa x#gc x args @@ -862,7 +964,7 @@ struct Array.init n f end -(** Enumeration sorts. *) +(** Enumeration sorts *) module EnumSort = struct (** The function declarations of the constants in the enumeration. *) @@ -876,7 +978,7 @@ struct Array.map f x#tester_decls end -(** List sorts. *) +(** List sorts *) module ListSort = struct (** The declaration of the nil function of this list sort. *) @@ -901,6 +1003,7 @@ struct let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] end +(** Tuple sorts *) module TupleSort = struct (** The constructor function of the tuple.*) @@ -917,7 +1020,7 @@ struct Array.init n f end -(** The abstract syntax tree (AST) module. *) +(** The abstract syntax tree (AST) module *) module AST = struct (** @@ -1077,12 +1180,107 @@ struct let to_string (p : params) = Z3native.params_to_string p#gnc p#gno end +(** Vectors of ASTs *) +module ASTVector = +struct + (** The size of the vector *) + let get_size ( x : ast_vector ) = + Z3native.ast_vector_size x#gnc x#gno + + (** + Retrieves the i-th object in the vector. + @param i Index + @return An AST + *) + let get ( x : ast_vector ) ( i : int ) = + create_ast x#gc (Z3native.ast_vector_get x#gnc x#gno i) + + (** Sets the i-th object in the vector. *) + let set ( x : ast_vector ) ( i : int ) ( value : ast ) = + Z3native.ast_vector_set x#gnc x#gno i value#gno + + (** Resize the vector to . + @param newSize The new size of the vector. *) + let resize ( x : ast_vector ) ( new_size : int ) = + Z3native.ast_vector_resize x#gnc x#gno new_size + + (** + Add the AST to the back of the vector. The size + is increased by 1. + @param a An AST + *) + let push ( x : ast_vector ) ( a : ast ) = + Z3native.ast_vector_push x#gnc x#gno a#gno + + (** + Translates all ASTs in the vector to . + @param to_ctx A context + @return A new ASTVector + *) + let translate ( x : ast_vector ) ( to_ctx : context ) = + (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno to_ctx#gno) + + (** Retrieves a string representation of the vector. *) + let to_string ( x : ast_vector ) = + Z3native.ast_vector_to_string x#gnc x#gno +end + +(** Map from AST to AST *) +module ASTMap = +struct + (** Checks whether the map contains the key . + @param k An AST + @return True if is a key in the map, false otherwise. *) + let contains ( m : ast_map ) ( key : ast ) = + (int2lbool (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE + + (** Finds the value associated with the key . + + This function signs an error when is not a key in the map. + + @param k An AST + *) + let find ( m : ast_map ) ( key : ast ) = + create_ast m#gc (Z3native.ast_map_find m#gnc m#gno key#gno) + + (** + Stores or replaces a new key/value pair in the map. + @param k The key AST + @param v The value AST + *) + let insert ( m : ast_map ) ( key : ast ) ( value : ast) = + Z3native.ast_map_insert m#gnc m#gno key#gno value#gno + + (** + Erases the key from the map. + @param k An AST + *) + let erase ( m : ast_map ) ( key : ast ) = + Z3native.ast_map_erase m#gnc m#gno key#gno + + (** Removes all keys from the map. *) + let reset ( m : ast_map ) = + Z3native.ast_map_reset m#gnc m#gno + + (** The size of the map *) + let get_size ( m : ast_map ) = + Z3native.ast_map_size m#gnc m#gno + + (** The keys stored in the map. *) + let get_keys ( m : ast_map ) = + (new ast_vector m#gc)#cnstr_obj (Z3native.ast_map_keys m#gnc m#gno) + + (** Retrieves a string representation of the map.*) + let to_strnig ( m : ast_map ) = + Z3native.ast_map_to_string m#gnc m#gno +end + (** Expressions (terms) *) module Expr = struct (** Returns a simplified version of the expression. - A set of parameters to configure the simplifier + @param p A set of parameters to configure the simplifier *) let simplify ( x : expr ) ( p : params option ) = match p with @@ -1155,8 +1353,8 @@ struct (** Translates (copies) the term to the Context . - A context - A copy of the term which is associated with + @param ctx A context + @return A copy of the term which is associated with *) let translate ( x : expr ) to_ctx = if x#gc == to_ctx then @@ -1176,7 +1374,7 @@ struct (** Indicates whether the term is well-sorted. - True if the term is well-sorted, false otherwise. + @return True if the term is well-sorted, false otherwise. *) let is_well_sorted ( x : expr ) = int2lbool (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE @@ -2372,13 +2570,13 @@ struct Z3native.get_index_value x#gnc x#gno end -(* Integer Numerals *) +(** Integer Numerals *) module IntNum = struct (** Retrieve the int value. *) let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if int2lbool(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -2410,9 +2608,9 @@ module BitVecNum = struct (** Retrieve the int value. *) let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if int2lbool(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") - + if int2lbool(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + (** Returns a string representation of the numeral. *) let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno end @@ -2424,9 +2622,8 @@ struct 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 - A numeral Expr of sort Real + @param precision the precision of the result + @return A numeral Expr of sort Real *) let to_upper ( x : algebraic_num ) ( precision : int ) = (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) @@ -2435,9 +2632,8 @@ struct Return a lower bound for the given real algebraic number. The interval isolating the number is smaller than 1/10^. - - - A numeral Expr of sort Real + @param precision the precision of the result + @return A numeral Expr of sort Real *) let to_lower ( x : algebraic_num ) precision = (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) @@ -2450,8 +2646,24 @@ struct (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno end + +(** Constructors are used for datatype sorts *) +module Constructor = +struct + (** The number of fields of the constructor. *) + let get_num_fields ( x : constructor ) = x#get_n + + (** The function declaration of the constructor. *) + let get_constructor_decl ( x : constructor ) = x#constructor_decl + + (** The function declaration of the tester. *) + let get_tester_decl ( x : constructor ) = x#tester_decl + + (** The function declarations of the accessors *) + let get_accessor_decls ( x : constructor ) = x#accessor_decls +end -(** The main interaction with Z3 happens via the Context module. *) +(** The main interaction with Z3 happens via the Context module *) module Context = struct @@ -2551,151 +2763,95 @@ struct (Array.map f (mk_symbols_string ( ctx : context ) enum_names)) ) - (** - Create a new list sort. - *) + (** + Create a new list sort. + *) let mk_list_sort ( ctx : context ) (name : symbol) elem_sort = - (new list_sort ctx)#cnstr_ss name elem_sort + (new list_sort ctx)#cnstr_ss name elem_sort - (** - Create a new list sort. - *) + (** + Create a new list sort. + *) let mk_list_sort_s ( ctx : context ) (name : string) elem_sort = mk_list_sort ctx ((mk_symbol_string ctx name) :> symbol) elem_sort - (** - Create a new finite domain sort. - *) + (** + Create a new finite domain sort. + *) let mk_finite_domain_sort ( ctx : context ) ( name : symbol ) size = (new finite_domain_sort ctx)#cnstr_si name size - (** - Create a new finite domain sort. - *) + (** + Create a new finite domain sort. + *) let mk_finite_domain_sort_s ( ctx : context ) ( name : string ) size = (new finite_domain_sort ctx)#cnstr_si ((mk_symbol_string ctx name) :> symbol) size -(** - -(* DATATYPES *) -(** - Create a datatype constructor. -*) - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - public Constructor MkConstructor(Symbol name, Symbol recognizer, Symbol[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null) - { + (* DATATYPES *) + (** + Create a datatype constructor. + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + *) + let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs + (** + Create a datatype constructor. + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + *) + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + mk_constructor ctx ((mk_symbol_string ctx name) :> symbol) recognizer field_names sorts sort_refs - return new Constructor(this, name, recognizer, fieldNames, sorts, sortRefs); - } + (** + Create a new datatype sort. + *) + let mk_datatype_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = + (new datatype_sort ctx)#cnstr_sc name constructors + + (** + Create a new datatype sort. + *) + let mk_datatype_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = + mk_datatype_sort ctx ((mk_symbol_string ctx name) :> symbol) constructors + + (** + Create mutually recursive datatypes. + @param names names of datatype sorts + @param c list of constructors, one list per sort. + *) + let mk_datatype_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = + let n = (Array.length names) in + let f e = ( (new constructor_list ctx)#cnstr_ca e ) in + let cla = (Array.map f c) in + let (r, a) = (Z3native.mk_datatypes ctx#gno n (symbolaton names) (constructor_listaton cla)) in + let g e = ( (new datatype_sort ctx)#cnstr_obj e) in + (Array.map g r) + + (** Create mutually recursive data-types. *) + let mk_datatype_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = + mk_datatype_sorts ctx + ( + let f e = ((mk_symbol_string ctx e) :> symbol) in + Array.map f names + ) + c (** - Create a datatype constructor. -*) - @param name - @param recognizer - @param fieldNames - @param sorts - @param sortRefs - @return - public Constructor MkConstructor(string name, string recognizer, string[] fieldNames = null, Sort[] sorts = null, uint[] sortRefs = null) - { - - - return new Constructor(this, MkSymbol(name), MkSymbol(recognizer), MkSymbols(fieldNames), sorts, sortRefs); - } - -(** - Create a new datatype sort. -*) - let mk_Datatype_Sort(Symbol name, Constructor[] constructors) - { - - - - - - - CheckContextMatch(name); - CheckContextMatch(constructors); - return new DatatypeSort(this, name, constructors); - } - -(** - Create a new datatype sort. -*) - let mk_Datatype_Sort(string name, Constructor[] constructors) - { - - - - - CheckContextMatch(constructors); - return new DatatypeSort(this, MkSymbol(name), constructors); - } - -(** - Create mutually recursive datatypes. -*) - @param names names of datatype sorts - @param c list of constructors, one list per sort. - let mk_Datatype_Sorts(Symbol[] names, Constructor[][] c) - { - - - - - - - - CheckContextMatch(names); - uint n = (uint)names.Length; - ConstructorList[] cla = new ConstructorList[n]; - IntPtr[] n_constr = new IntPtr[n]; - for (uint i = 0; i < n; i++) - { - Constructor[] constructor = c[i]; - - CheckContextMatch(constructor); - cla[i] = new ConstructorList(this, constructor); - n_constr[i] = cla[i].x#gno; - } - IntPtr[] n_res = new IntPtr[n]; - Z3native.mk_datatypes(nCtx, n, Symbol.ArrayToNative(names), n_res, n_constr); - DatatypeSort[] res = new DatatypeSort[n]; - for (uint i = 0; i < n; i++) - res[i] = new DatatypeSort(this, n_res[i]); - return res; - } - -(** - Create mutually recursive data-types. -*) - @param names - @param c - @return - let mk_Datatype_Sorts(string[] names, Constructor[][] c) - { - - - - - - - - return MkDatatypeSorts(MkSymbols(names), c); - } - - (* FUNCTION DECLARATIONS *) From 954d92a5135aa8996ef4db5b02756e8d956aca72 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 22 Dec 2012 21:06:13 +0000 Subject: [PATCH 144/248] More new ML API Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 4 +- scripts/update_api.py | 11 +- src/api/ml/Makefile | 2 +- src/api/ml/z3.ml | 1025 +++++++++++++++++++++++++++++++++++------ 4 files changed, 901 insertions(+), 141 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 5ca0d2299..849644a18 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2777,13 +2777,13 @@ def mk_z3consts_ml(api_files): efile.write(' | %s \n' % k[3:]) # strip Z3_ efile.write('\n') efile.write('(** Convert %s to int*)\n' % name[3:]) - efile.write('let %s2int x : int =\n' % (name[3:])) # strip Z3_ + efile.write('let int_of_%s x : int =\n' % (name[3:])) # strip Z3_ efile.write(' match x with\n') for k, i in decls.iteritems(): efile.write(' | %s -> %d\n' % (k[3:], i)) efile.write('\n') efile.write('(** Convert int to %s*)\n' % name[3:]) - efile.write('let int2%s x : %s =\n' % (name[3:],name[3:])) # strip Z3_ + efile.write('let %s_of_int x : %s =\n' % (name[3:],name[3:])) # strip Z3_ efile.write(' match x with\n') for k, i in decls.iteritems(): efile.write(' | %d -> %s\n' % (i, k[3:])) diff --git a/scripts/update_api.py b/scripts/update_api.py index c3f2abce6..27f7dd507 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1154,7 +1154,9 @@ def mk_ml(): for k, v in Type2Str.iteritems(): if is_obj(k): ml_native.write('and %s = ptr\n' % v.lower()) - ml_native.write('\nexception Exception of string\n\n') + ml_native.write('\nexternal is_null : ptr -> bool\n') + ml_native.write(' = "n_is_null"\n\n') + ml_native.write('exception Exception of string\n\n') # ML declarations ml_native.write(' module ML2C = struct\n\n') @@ -1219,9 +1221,9 @@ def mk_ml(): i = i + 1 ml_native.write(') in\n') if len(params) > 0 and param_type(params[0]) == CONTEXT: - ml_native.write(' let err = (int2error_code (ML2C.n_get_error_code a0)) in \n') + ml_native.write(' let err = (error_code_of_int (ML2C.n_get_error_code a0)) in \n') ml_native.write(' if err <> OK then\n') - ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (error_code2int err)))\n') + ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (int_of_error_code err)))\n') ml_native.write(' else\n') if result == VOID and len(op) == 0: ml_native.write(' ()\n') @@ -1290,6 +1292,9 @@ def mk_ml(): ml_wrapper.write('#ifdef __cplusplus\n') ml_wrapper.write('extern "C" {\n') ml_wrapper.write('#endif\n\n') + ml_wrapper.write('CAMLprim value n_is_null(value p) {\n') + ml_wrapper.write(' return Val_bool(Data_custom_val(p) == 0);\n') + ml_wrapper.write('}\n\n') for name, result, params in _dotnet_decls: ip = inparams(params) op = outparams(params) diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile index 4d4a6c08f..ad5442327 100644 --- a/src/api/ml/Makefile +++ b/src/api/ml/Makefile @@ -7,4 +7,4 @@ all: doc: *.ml mkdir -p doc - ocamldoc -html -d doc -I ../../../bld_dbg/api/ml *.ml -hide Z3 + ocamldoc -html -d doc -I ../../../bld_dbg/api/ml -sort *.ml -hide Z3 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 116d7a230..c22ef869b 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -9,9 +9,6 @@ open Z3enums (**/**) -(* Object definitions. These are internal and should be interacted - with only via the corresponding functions from modules. *) - class virtual idisposable = object method virtual dispose : unit @@ -106,8 +103,8 @@ end class params ctx obj = object (self) inherit z3object ctx obj as super - method incref ctx o = Z3native.params_inc_ref ctx o - method decref ctx o = Z3native.params_dec_ref ctx o + method incref nc o = Z3native.params_inc_ref nc o + method decref nc o = Z3native.params_dec_ref nc o end (** Symbol objects *) @@ -115,8 +112,8 @@ class symbol ctx = object (self) inherit z3object ctx None as super method cnstr_obj obj = (self#sno ctx obj) ; self - method incref ctx o = () - method decref ctx o = () + method incref nc o = () + method decref nc o = () end let symbolaton (a : symbol array) = @@ -140,7 +137,7 @@ object(self) end let create_symbol ctx no = - match (int2symbol_kind (Z3native.get_symbol_kind ctx#gno no)) with + match (symbol_kind_of_int (Z3native.get_symbol_kind ctx#gno no)) with | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj no) :> symbol) | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj no) :> symbol) @@ -198,29 +195,6 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end -(** Enum sort objects *) -class enum_sort ctx = -object (self) - inherit sort ctx as super - val mutable _constdecls : Z3native.ptr array option = None - val mutable _testerdecls : Z3native.ptr array option = None - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : symbol) (enum_names : symbol array) = - let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in - _constdecls <- Some a ; - _testerdecls <- Some b ; - (self#sno ctx r) ; - self - - method const_decls = match _constdecls with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing const decls") - - method tester_decls = match _testerdecls with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tester decls") -end - (** Int sort objects *) class int_sort ctx = object (self) @@ -258,54 +232,6 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end -(** List sort objects *) -class list_sort ctx = -object (self) - inherit sort ctx as super - val mutable _nildecl : Z3native.ptr option = None - val mutable _is_nildecl : Z3native.ptr option = None - val mutable _consdecl : Z3native.ptr option = None - val mutable _is_consdecl : Z3native.ptr option = None - val mutable _headdecl : Z3native.ptr option = None - val mutable _taildecl : Z3native.ptr option = None - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : symbol) (elem_sort : sort) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in - _nildecl <- Some a ; - _is_nildecl <- Some b ; - _consdecl <- Some c ; - _is_consdecl <- Some d ; - _headdecl <- Some e ; - _taildecl <- Some f ; - (self#sno ctx r) ; - self - - method nil_decl = match _nildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing nil decl") - - method is_nil_decl = match _is_nildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_nil decl") - - method cons_decl = match _consdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing cons decl") - - method is_cons_decl = match _is_consdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_cons decl") - - method head_decl = match _headdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing head decl") - - method tail_decl = match _taildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tail decl") - -end - (** Set sort objects *) class set_sort ctx = object (self) @@ -376,6 +302,76 @@ object (self) end +(** Enum sort objects *) +class enum_sort ctx = +object (self) + inherit sort ctx as super + val mutable _constdecls : func_decl array option = None + val mutable _testerdecls : func_decl array option = None + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_ss (name : symbol) (enum_names : symbol array) = + let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in + _constdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f a)) ; + _testerdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f b)) ; + (self#sno ctx r) ; + self + + method const_decls = match _constdecls with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing const decls") + + method tester_decls = match _testerdecls with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing tester decls") +end + +(** List sort objects *) +class list_sort ctx = +object (self) + inherit sort ctx as super + val mutable _nildecl : func_decl option = None + val mutable _is_nildecl : func_decl option = None + val mutable _consdecl : func_decl option = None + val mutable _is_consdecl : func_decl option = None + val mutable _headdecl : func_decl option = None + val mutable _taildecl : func_decl option = None + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_ss (name : symbol) (elem_sort : sort) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in + _nildecl <- Some ((new func_decl ctx)#cnstr_obj a) ; + _is_nildecl <- Some ((new func_decl ctx)#cnstr_obj b) ; + _consdecl <- Some ((new func_decl ctx)#cnstr_obj c) ; + _is_consdecl <- Some ((new func_decl ctx)#cnstr_obj d) ; + _headdecl <- Some ((new func_decl ctx)#cnstr_obj e) ; + _taildecl <- Some ((new func_decl ctx)#cnstr_obj f) ; + (self#sno ctx r) ; + self + + method nil_decl = match _nildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing nil decl") + + method is_nil_decl = match _is_nildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing is_nil decl") + + method cons_decl = match _consdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing cons decl") + + method is_cons_decl = match _is_consdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing is_cons decl") + + method head_decl = match _headdecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing head decl") + + method tail_decl = match _taildecl with + | Some(x) -> x + | None -> raise (Z3native.Exception "Missing tail decl") +end + (** Constructor objects *) class constructor ctx = object (self) @@ -384,8 +380,8 @@ object (self) val mutable m_tester_decl : func_decl option = None val mutable m_constructor_decl : func_decl option = None val mutable m_accessor_decls : func_decl array option = None - method incref ctx o = () - method decref ctx o = () + method incref nc o = () + method decref nc o = () initializer let f = fun o -> Z3native.del_constructor o#gnc o#gno in let v = self in @@ -438,8 +434,8 @@ let constructoraton (a : constructor array) = class constructor_list ctx = object (self) inherit z3object ctx None - method incref ctx o = () - method decref ctx o = () + method incref nc o = () + method decref nc o = () initializer let f = fun o -> Z3native.del_constructor_list o#gnc o#gno in let v = self in @@ -463,7 +459,7 @@ object (self) end let create_sort ctx obj = - match (int2sort_kind (Z3native.get_sort_kind ctx#gno obj)) with + match (sort_kind_of_int (Z3native.get_sort_kind ctx#gno obj)) with | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) @@ -480,8 +476,8 @@ class ast_vector ctx = object (self) inherit z3object ctx None method cnstr_obj obj = (self#sno ctx obj) ; self - method incref ctx o = Z3native.ast_vector_inc_ref ctx o - method decref ctx o = Z3native.ast_vector_dec_ref ctx o + method incref nc o = Z3native.ast_vector_inc_ref nc o + method decref nc o = Z3native.ast_vector_dec_ref nc o end @@ -490,8 +486,8 @@ class ast_map ctx = object (self) inherit z3object ctx None method cnstr_obj obj = (self#sno ctx obj) ; self - method incref ctx o = Z3native.ast_map_inc_ref ctx o - method decref ctx o = Z3native.ast_map_dec_ref ctx o + method incref nc o = Z3native.ast_map_inc_ref nc o + method decref nc o = Z3native.ast_map_dec_ref nc o end @@ -583,7 +579,6 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end - (** Quantifier objects *) class quantifier ctx = object (self) @@ -591,10 +586,127 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end +(** Parameter description objects *) +class param_descrs ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.param_descrs_inc_ref nc o + method decref nc o = Z3native.param_descrs_dec_ref nc o +end +(** Goal objects *) +class goal ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.goal_inc_ref nc o + method decref nc o = Z3native.goal_dec_ref nc o +end + +(** Tactic objects *) +class tactic ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.tactic_inc_ref nc o + method decref nc o = Z3native.tactic_dec_ref nc o +end + +(** Function interpretation entry objects *) +class func_entry ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.func_entry_inc_ref nc o + method decref nc o = Z3native.func_entry_dec_ref nc o +end + +(** Function interpretation objects *) +class func_interp ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.func_interp_inc_ref nc o + method decref nc o = Z3native.func_interp_dec_ref nc o +end + +(** Model objects *) +class model ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.model_inc_ref nc o + method decref nc o = Z3native.model_dec_ref nc o +end + +(** Tactic application result objects *) +class apply_result ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.apply_result_inc_ref nc o + method decref nc o = Z3native.apply_result_dec_ref nc o +end + +(** Probe objects *) +class probe ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.probe_inc_ref nc o + method decref nc o = Z3native.probe_dec_ref nc o +end + +(** Statistical value objects *) +class statistics_entry = +object (self) + val mutable m_key : string = "" + val mutable m_is_int = false + val mutable m_is_float = false + val mutable m_int = 0 + val mutable m_float = 0.0 + + method cnstr_si k v = + m_key <- k; + m_is_int <- true; + m_int <- v; + self + + method cnstr_sd k v = + m_key <- k; + m_is_float <- true; + m_float <- v; + self + + method key = m_key + method int = m_int + method float = m_float + method is_int = m_is_int + method is_float = m_is_float +end + +(** Statistics objects *) +class statistics ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.stats_inc_ref nc o + method decref nc o = Z3native.stats_dec_ref nc o +end + +(** Solver objects *) +class solver ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.solver_inc_ref nc o + method decref nc o = Z3native.solver_dec_ref nc o +end (**/**) + (** Interaction logging for Z3 Note that this is a global, static log and if multiple Context @@ -606,7 +718,7 @@ struct @return True if opening the log file succeeds, false otherwise. *) (* CMW: "open" seems to be a reserved keyword? *) - let open_ filename = ((int2lbool (Z3native.open_log filename)) == L_TRUE) + let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) (** Closes the interaction log. *) let close = Z3native.close_log @@ -644,7 +756,7 @@ end module Symbol = struct (** The kind of the symbol (int or string) *) - let kind (o : symbol) = (int2symbol_kind (Z3native.get_symbol_kind o#gnc o#gno)) + let kind (o : symbol) = (symbol_kind_of_int (Z3native.get_symbol_kind o#gnc o#gno)) (** Indicates whether the symbol is of Int kind *) let is_int_symbol (o : symbol) = (kind o) == INT_SYMBOL @@ -680,7 +792,7 @@ struct if a#gnc != b#gnc then false else - ((int2lbool (Z3native.is_eq_sort a#gnc a#gno b#gno)) == L_TRUE) + ((lbool_of_int (Z3native.is_eq_sort a#gnc a#gno b#gno)) == L_TRUE) (** Returns a unique identifier for the sort. @@ -690,7 +802,7 @@ struct (** The kind of the sort. *) - let get_sort_kind (x : sort) = (int2sort_kind (Z3native.get_sort_kind x#gnc x#gno)) + let get_sort_kind (x : sort) = (sort_kind_of_int (Z3native.get_sort_kind x#gnc x#gno)) (** The name of the sort @@ -726,7 +838,7 @@ struct (** The size of the finite domain sort. *) let get_size (x : finite_domain_sort) = let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in - if int2lbool(r) == L_TRUE then v + if lbool_of_int(r) == L_TRUE then v else raise (Z3native.Exception "Conversion failed.") end @@ -746,15 +858,15 @@ end (**/**) let create_expr ctx obj = - if int2ast_kind (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then + if ast_kind_of_int (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then (((new quantifier ctx)#cnstr_obj obj) :> expr) else let s = Z3native.get_sort ctx#gno obj in - let sk = (int2sort_kind (Z3native.get_sort_kind ctx#gno s)) in - if (int2lbool (Z3native.is_algebraic_number ctx#gno obj) == L_TRUE) then + let sk = (sort_kind_of_int (Z3native.get_sort_kind ctx#gno s)) in + if (lbool_of_int (Z3native.is_algebraic_number ctx#gno obj) == L_TRUE) then (((new algebraic_num ctx)#cnstr_obj obj) :> expr) else - if ((int2lbool (Z3native.is_numeral_ast ctx#gno obj)) == L_TRUE) && + if ((lbool_of_int (Z3native.is_numeral_ast ctx#gno obj)) == L_TRUE) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) @@ -776,7 +888,7 @@ let create_expr_fa (ctx : context) (f : func_decl) (args : expr array) = create_expr ctx o let create_ast ctx no = - match (int2ast_kind (Z3native.get_ast_kind ctx#gno no)) with + match (ast_kind_of_int (Z3native.get_ast_kind ctx#gno no)) with | FUNC_DECL_AST -> (((new func_decl ctx)#cnstr_obj no) :> ast) | QUANTIFIER_AST -> (((new quantifier ctx)#cnstr_obj no) :> ast) | SORT_AST -> ((create_sort ctx no) :> ast) @@ -858,7 +970,7 @@ struct if a#gnc == a#gnc then false else - ((int2lbool (Z3native.is_eq_func_decl a#gnc a#gno b#gno)) == L_TRUE) + ((lbool_of_int (Z3native.is_eq_func_decl a#gnc a#gno b#gno)) == L_TRUE) (** A string representations of the function declaration. *) @@ -897,7 +1009,7 @@ struct (** The kind of the function declaration. *) - let get_decl_kind (x : func_decl) = (int2decl_kind (Z3native.get_decl_kind x#gnc x#gno)) + let get_decl_kind (x : func_decl) = (decl_kind_of_int (Z3native.get_decl_kind x#gnc x#gno)) (** The name of the function declaration @@ -915,7 +1027,7 @@ struct let get_parameters (x : func_decl) = let n = (get_num_parameters x) in let f i = ( - match (int2parameter_kind (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with + match (parameter_kind_of_int (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with | PARAMETER_INT -> (new parameter)#cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) | PARAMETER_DOUBLE -> (new parameter)#cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) | PARAMETER_SYMBOL-> (new parameter)#cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) @@ -968,36 +1080,32 @@ end module EnumSort = struct (** The function declarations of the constants in the enumeration. *) - let get_const_decls (x : enum_sort) = - let f e = ((new func_decl x#gc)#cnstr_obj e) in - Array.map f x#const_decls + let get_const_decls (x : enum_sort) = x#const_decls (** The test predicates for the constants in the enumeration. *) - let get_tester_decls (x : enum_sort) = - let f e = ((new func_decl x#gc)#cnstr_obj e) in - Array.map f x#tester_decls + let get_tester_decls (x : enum_sort) = x#tester_decls end (** List sorts *) module ListSort = struct (** The declaration of the nil function of this list sort. *) - let get_nil_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#nil_decl + let get_nil_decl (x : list_sort) = x#nil_decl (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#is_nil_decl + let get_is_nil_decl (x : list_sort) = x#is_nil_decl (** The declaration of the cons function of this list sort. *) - let get_cons_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#cons_decl + let get_cons_decl (x : list_sort) = x#cons_decl (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#is_cons_decl + let get_is_cons_decl (x : list_sort) = x#is_cons_decl (** The declaration of the head function of this list sort.*) - let get_head_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#head_decl + let get_head_decl (x : list_sort) = x#head_decl (** The declaration of the tail function of this list sort. *) - let get_tail_decl (x : list_sort) = (new func_decl x#gc)#cnstr_obj x#tail_decl + let get_tail_decl (x : list_sort) = x#tail_decl (** The empty list. *) let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] @@ -1037,7 +1145,7 @@ struct (** The kind of the AST. *) - let get_ast_kind ( x : ast) = (int2ast_kind (Z3native.get_ast_kind x#gnc x#gno)) + let get_ast_kind ( x : ast) = (ast_kind_of_int (Z3native.get_ast_kind x#gnc x#gno)) (** Indicates whether the AST is an Expr @@ -1092,7 +1200,7 @@ struct if a#gnc == b#gnc then false else - ((int2lbool (Z3native.is_eq_ast a#gnc a#gno b#gno)) == L_TRUE) + ((lbool_of_int (Z3native.is_eq_ast a#gnc a#gno b#gno)) == L_TRUE) (** Object Comparison. @@ -1130,7 +1238,7 @@ struct Adds a parameter setting. *) let add_bool (p : params) (name : symbol) (value : bool) = - Z3native.params_set_bool p#gnc p#gno name#gno (lbool2int (if value then L_TRUE else L_FALSE)) + Z3native.params_set_bool p#gnc p#gno name#gno (int_of_lbool (if value then L_TRUE else L_FALSE)) (** Adds a parameter setting. @@ -1232,7 +1340,7 @@ struct @param k An AST @return True if is a key in the map, false otherwise. *) let contains ( m : ast_map ) ( key : ast ) = - (int2lbool (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE + (lbool_of_int (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE (** Finds the value associated with the key . @@ -1296,7 +1404,7 @@ struct Indicates whether the expression is the true or false expression or something else (Z3_L_UNDEF). *) - let get_bool_value ( x : expr ) = int2lbool (Z3native.get_bool_value x#gnc x#gno) + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value x#gnc x#gno) (** The number of arguments of the expression. @@ -1370,13 +1478,13 @@ struct (** Indicates whether the term is a numeral *) - let is_numeral ( x : expr ) = int2lbool (Z3native.is_numeral_ast x#gnc x#gno) == L_TRUE + let is_numeral ( x : expr ) = lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno) == L_TRUE (** Indicates whether the term is well-sorted. @return True if the term is well-sorted, false otherwise. *) - let is_well_sorted ( x : expr ) = int2lbool (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE + let is_well_sorted ( x : expr ) = lbool_of_int (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE (** The Sort of the term. @@ -1387,7 +1495,7 @@ struct Indicates whether the term has Boolean sort. *) let is_bool ( x : expr ) = (AST.is_expr x) && - (int2lbool (Z3native.is_eq_sort x#gnc + (lbool_of_int (Z3native.is_eq_sort x#gnc (Z3native.mk_bool_sort x#gnc) (Z3native.get_sort x#gnc x#gno))) == L_TRUE @@ -1395,21 +1503,21 @@ struct Indicates whether the term is of integer sort. *) let is_int ( x : expr ) = - ((int2lbool (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && - ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) + ((lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) (** Indicates whether the term is of sort real. *) let is_real ( x : expr ) = - ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) (** Indicates whether the term is of an array sort. *) let is_array ( x : expr ) = - ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) (** Indicates whether the term represents a constant. @@ -1431,7 +1539,7 @@ struct (** Indicates whether the term is an algebraic number *) - let is_algebraic_number ( x : expr ) = int2lbool(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE + let is_algebraic_number ( x : expr ) = lbool_of_int(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE (** Indicates whether the term is the constant true. @@ -1634,7 +1742,7 @@ struct Indicates whether the terms is of bit-vector sort. *) let is_bv ( x : expr ) = - ((int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == BV_SORT) + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == BV_SORT) (** Indicates whether the term is a bit-vector numeral @@ -2422,8 +2530,8 @@ struct Indicates whether the term is of a relation sort. *) let is_Relation ( x : expr ) = - ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT) + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT) (** Indicates whether the term is an relation store @@ -2536,8 +2644,8 @@ struct Indicates whether the term is of an array sort. *) let is_finite_domain ( x : expr ) = - ((int2lbool (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (int2sort_kind (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) (** Indicates whether the term is a less than predicate over a finite domain. @@ -2575,7 +2683,7 @@ module IntNum = struct (** Retrieve the int value. *) let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if int2lbool(r) == L_TRUE then v + if lbool_of_int(r) == L_TRUE then v else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) @@ -2608,7 +2716,7 @@ module BitVecNum = struct (** Retrieve the int value. *) let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if int2lbool(r) == L_TRUE then v + if lbool_of_int(r) == L_TRUE then v else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) @@ -2662,7 +2770,654 @@ struct (** The function declarations of the accessors *) let get_accessor_decls ( x : constructor ) = x#accessor_decls end + + +(** ParamDescrs describe sets of parameters.*) +module ParamDescrs = +struct + + (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno + + (** Retrieve kind of parameter. *) + let get_kind ( x : param_descrs ) ( name : symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) + + (** Retrieve all names of parameters. *) + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size x#gnc x#gno in + let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in + Array.init n f + + (** The size of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno + + (** Retrieves a string representation of the ParamDescrs. *) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno + +end + +(** Goals + + A goal (aka problem). A goal is essentially a + of formulas, that can be solved and/or transformed using + tactics and solvers. *) +module Goal = +struct + + (** 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. + *) + let get_precision ( x : goal ) = + goal_prec_of_int (Z3native.goal_precision x#gnc x#gno) + + (** Indicates whether the goal is precise. *) + let is_precise ( x : goal ) = + (get_precision x) == GOAL_PRECISE + + (** Indicates whether the goal is an under-approximation. *) + let is_underapproximation ( x : goal ) = + (get_precision x) == GOAL_UNDER + + (** Indicates whether the goal is an over-approximation. *) + let is_overapproximation ( x : goal ) = + (get_precision x) == GOAL_OVER + + (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) + let is_garbage ( x : goal ) = + (get_precision x) == GOAL_UNDER_OVER + + (** Adds the constraints to the given goal. *) + (* CMW: assert seems to be a keyword. *) + let assert_ ( x : goal ) ( constraints : bool_expr array ) = + let f e = Z3native.goal_assert x#gnc x#gno e#gno in + Array.map f constraints + + (** Indicates whether the goal contains `false'. *) + let is_inconsistent ( x : goal ) = + (lbool_of_int (Z3native.goal_inconsistent x#gnc x#gno)) == L_TRUE + + (** The depth of the goal. + This tracks how many transformations were applied to it. *) + let get_depth ( x : goal ) = Z3native.goal_depth x#gnc x#gno + + (** Erases all formulas from the given goal. *) + let reset ( x : goal ) = Z3native.goal_reset x#gnc x#gno + + (** The number of formulas in the goal. *) + let get_size ( x : goal ) = Z3native.goal_size x#gnc x#gno + + (** The formulas in the goal. *) + let get_formulas ( x : goal ) = + let n = get_size x in + let f i = (new bool_expr x#gc)#cnstr_obj (Z3native.goal_formula x#gnc x#gno i) in + Array.init n f + + (** The number of formulas, subformulas and terms in the goal. *) + let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs x#gnc x#gno + + (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) + let is_decided_sat ( x : goal ) = + (lbool_of_int (Z3native.goal_is_decided_sat x#gnc x#gno)) == L_TRUE + + (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) + let is_decided_unsat ( x : goal ) = + (lbool_of_int (Z3native.goal_is_decided_unsat x#gnc x#gno)) == L_TRUE + + (** Translates (copies) the Goal to the target Context . *) + let translate ( x : goal ) ( to_ctx : context ) = + (new goal to_ctx)#cnstr_obj (Z3native.goal_translate x#gnc x#gno to_ctx#gno) + + (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) + let simplify ( x : goal ) ( p : params option ) = + let tn = Z3native.mk_tactic x#gnc "simplify" in + Z3native.tactic_inc_ref x#gnc tn ; + let arn = match p with + | None -> Z3native.tactic_apply x#gnc tn x#gno + | Some(pn) -> Z3native.tactic_apply_ex x#gnc tn x#gno pn#gno + in + Z3native.apply_result_inc_ref x#gnc arn ; + let sg = Z3native.apply_result_get_num_subgoals x#gnc arn in + let res = if sg == 0 then + raise (Z3native.Exception "No subgoals") + else + Z3native.apply_result_get_subgoal x#gnc arn 0 in + Z3native.apply_result_dec_ref x#gnc arn ; + Z3native.tactic_dec_ref x#gnc tn ; + (new goal x#gc)#cnstr_obj res + + (** A string representation of the Goal. *) + let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno +end + + +(** Tactics + + Tactics are the basic building block for creating custom solvers for specific problem domains. + The complete list of tactics may be obtained using Context.get_num_tactics + and Context.get_tactic_names. + It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. +*) +module Tactic = +struct + (** A string containing a description of parameters accepted by the tactic. *) + let get_help ( x : tactic ) = Z3native.tactic_get_help x#gnc x#gno + + + (** Retrieves parameter descriptions for Tactics. *) + let get_param_descrs ( x : tactic ) = + (new param_descrs x#gc)#cnstr_obj (Z3native.tactic_get_param_descrs x#gnc x#gno) + + (** Apply the tactic to the goal. *) + let apply ( x : tactic ) ( g : goal ) ( p : params option ) = + match p with + | None -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply x#gnc x#gno g#gno) + | Some (pn) -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno) + + (** Creates a solver that is implemented using the given tactic. + *) + let get_solver ( x : tactic ) = + (new solver x#gc)#cnstr_obj (Z3native.mk_solver_from_tactic x#gnc x#gno) + +end + + +(** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. +*) +module FuncInterp = +struct + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. + *) + module FuncEntry = + struct + (** + Return the (symbolic) value of this entry. + *) + let get_value ( x : func_entry ) = + create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + + (** + The number of arguments of the entry. + *) + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + + (** + The arguments of the function entry. + *) + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the function entry. + *) + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]]") + end + + (** + The number of entries in the function interpretation. + *) + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + + (** + The entries in the function interpretation + *) + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + Array.init n f + + (** + The (symbolic) `else' value of the function interpretation. + *) + let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + + (** + The arity of the function interpretation + *) + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + + (** + A string representation of the function interpretation. + *) + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (Array.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") +end + +(** Models. + + A Model contains interpretations (assignments) of constants and functions. *) +module Model = +struct + (** Retrieves the interpretation (the assignment) of in the model. + A function declaration of zero arity + An expression if the function has an interpretation in the model, null otherwise. *) + let get_const_interp ( x : model ) ( f : func_decl ) = + if (FuncDecl.get_arity f) != 0 || + (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then + raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") + else + let np = Z3native.model_get_const_interp x#gnc x#gno f#gno in + if (Z3native.is_null np) then + None + else + Some (create_expr x#gc np) + + (** Retrieves the interpretation (the assignment) of in the model. + A Constant + An expression if the constant has an interpretation in the model, null otherwise. + *) + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + + + (** Retrieves the interpretation (the assignment) of a non-constant in the model. + A function declaration of non-zero arity + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + let rec get_func_interp ( x : model ) ( f : func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_range f#gnc f#gno))) in + if (FuncDecl.get_arity f) == 0 then + let n = Z3native.model_get_const_interp x#gnc x#gno f#gno in + if (Z3native.is_null n) then + None + else + match sk with + | ARRAY_SORT -> + if (lbool_of_int (Z3native.is_as_array x#gnc n)) == L_FALSE then + raise (Z3native.Exception "Argument was not an array constant") + else + let fd = Z3native.get_as_array_func_decl x#gnc n in + get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) + | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); + else + let n = (Z3native.model_get_func_interp x#gnc x#gno f#gno) in + if (Z3native.is_null n) then None else Some ((new func_interp x#gc)#cnstr_obj n) + + (** The number of constants that have an interpretation in the model. *) + let get_num_consts ( x : model ) = Z3native.model_get_num_consts x#gnc x#gno + + (** The function declarations of the constants in the model. *) + let get_const_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in + Array.init n f + + + (** The number of function interpretations in the model. *) + let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs x#gnc x#gno + + (** The function declarations of the function interpretations in the model. *) + let get_func_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in + Array.init n f + + (** All symbols that have an interpretation in the model. *) + let get_decls ( x : model ) = + let n_funcs = (get_num_funcs x) in + let n_consts = (get_num_consts x ) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in + let g i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in + Array.append (Array.init n_funcs f) (Array.init n_consts g) + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) + exception ModelEvaluationFailedException of string + + (** + 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. + + The evaluation of in the model. + *) + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno (int_of_lbool (if completion then L_TRUE else L_FALSE))) in + if (lbool_of_int r) == L_FALSE then + raise (ModelEvaluationFailedException "evaluation failed") + else + create_expr x#gc v + + (** Alias for eval. *) + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + eval x t completion + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts x#gnc x#gno + + (** 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. + + + + *) + let get_sorts ( x : model ) = + let n = (get_num_sorts x) in + let f i = (create_sort x#gc (Z3native.model_get_sort x#gnc x#gno i)) in + Array.init n f + + + (** The finite set of distinct values that represent the interpretation for sort . + + An uninterpreted sort + An array of expressions, where each is an element of the universe of + *) + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in + let n = (ASTVector.get_size n_univ) in + let f i = (ASTVector.get n_univ i) in + Array.init n f + + (** Conversion of models to strings. + A string representation of the model. + *) + let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno +end + +(** Tactic application results + + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) +module ApplyResult = +struct + (** The number of Subgoals. *) + let get_num_subgoals ( x : apply_result ) = + Z3native.apply_result_get_num_subgoals x#gnc x#gno + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoals ( x : apply_result ) = + let n = (get_num_subgoals x) in + let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in + Array.init n f + + (** 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 + *) + let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = + (new model x#gc)#cnstr_obj (Z3native.apply_result_convert_model x#gnc x#gno i m#gno) + + (** A string representation of the ApplyResult. *) + let to_string ( x : apply_result) = Z3native.apply_result_to_string x#gnc x#gno +end + +(** Objects that track statistical information about solvers. *) +module Statistics = +struct + + (** + Statistical data is organized into pairs of [Key, Entry], where every + Entry is either a DoubleEntry or a UIntEntry + *) + module Entry = + struct + (** The key of the entry. *) + let get_key (x : statistics_entry) = x#key + + (** The int-value of the entry. *) + let get_int (x : statistics_entry) = x#int + + (** The float-value of the entry. *) + let get_float (x : statistics_entry) = x#float + + (** True if the entry is uint-valued. *) + let is_int (x : statistics_entry) = x#is_int + + (** True if the entry is double-valued. *) + let is_float (x : statistics_entry) = x#is_float + + (** The string representation of the the entry's value. *) + let to_string_value (x : statistics_entry) = + if (is_int x) then + string_of_int (get_int x) + else if (is_float x) then + string_of_float (get_float x) + else + raise (Z3native.Exception "Unknown statistical entry type") + + (** The string representation of the entry (key and value) *) + let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) + end + + (** A string representation of the statistical data. *) + let to_string ( x : statistics ) = Z3native.stats_to_string x#gnc x#gno + + (** The number of statistical data. *) + let get_size ( x : statistics ) = Z3native.stats_size x#gnc x#gno + + (** The data entries. *) + let get_entries ( x : statistics ) = + let n = (get_size x ) in + let f i = ( + let k = Z3native.stats_get_key x#gnc x#gno i in + if (lbool_of_int (Z3native.stats_is_uint x#gnc x#gno i)) == L_TRUE then + ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) + else + ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) + ) in + Array.init n f + + (** + The statistical counters. + *) + let get_keys ( x : statistics ) = + let n = (get_size x) in + let f i = (Z3native.stats_get_key x#gnc x#gno i) in + Array.init n f + + (** + The value of a particular statistical counter. + *) + let get ( x : statistics ) ( key : string ) = + let f p c = (if (Entry.get_key c) = key then (Some c) else p) in + Array.fold_left f None (get_entries x) + +end + +(** Solvers *) +module Solver = +struct + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + + (** + A string that describes all available solver parameters. + *) + let get_help ( x : solver ) = Z3native.solver_get_help x#gnc x#gno + + (** + Sets the solver parameters. + *) + let set_parameters ( x : solver ) ( value : params )= + Z3native.solver_set_params x#gnc x#gno value#gno + + (** + Retrieves parameter descriptions for solver. + *) + let get_param_descrs ( x : solver ) = + (new param_descrs x#gc)#cnstr_obj (Z3native.solver_get_param_descrs x#gnc x#gno) + + (** + The current number of backtracking points (scopes). + + + *) + let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes x#gnc x#gno + + (** + Creates a backtracking point. + + *) + let push ( x : solver ) = Z3native.solver_push x#gnc x#gno + + (** + Backtracks backtracking points. + Note that an exception is thrown if is not smaller than NumScopes + + *) + let pop ( x : solver ) ( n : int ) = Z3native.solver_pop x#gnc x#gno n + + (** + Resets the Solver. + This removes all assertions from the solver. + *) + let reset ( x : solver ) = Z3native.solver_reset x#gnc x#gno + + (** + Assert a constraint (or multiple) into the solver. + *) + let assert_ ( x : solver ) ( constraints : bool_expr array ) = + let f e = (Z3native.solver_assert x#gnc x#gno e#gno) in + Array.map f constraints + + (** + The number of assertions in the solver. + *) + let get_num_assertions ( x : solver ) = + let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in + (ASTVector.get_size a) + + + (** + The set of asserted formulas. + *) + let get_assertions ( x : solver ) = + let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in + let n = (ASTVector.get_size a) in + let f i = ((new bool_expr x#gc)#cnstr_obj (ASTVector.get a i)#gno) in + Array.init n f + + (** + Checks whether the assertions in the solver are consistent or not. + + + + + + *) + let check ( x : solver ) ( assumptions : bool_expr array option) = + let r = + match assumptions with + | None -> lbool_of_int (Z3native.solver_check x#gnc x#gno) + | Some (ass) -> lbool_of_int (Z3native.solver_check_assumptions x#gnc x#gno (Array.length ass) (astaton ass)) + in + match r with + | L_TRUE -> SATISFIABLE + | L_FALSE -> UNSATISFIABLE + | _ -> UNKNOWN + + (** + The model of the last Check. + + The result is None if Check was not invoked before, + if its results was not SATISFIABLE, or if model production is not enabled. + + *) + let get_model ( x : solver ) = + let q = Z3native.solver_get_model x#gnc x#gno in + if (Z3native.is_null q) then + None + else + Some ((new model x#gc)#cnstr_obj q) + + (** + 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. + + *) + let get_proof ( x : solver ) = + let q = Z3native.solver_get_proof x#gnc x#gno in + if (Z3native.is_null q) then + None + else + Some (create_expr x#gc q) + + (** + 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. + + *) + let get_unsat_core ( x : solver ) = + let cn = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_unsat_core x#gnc x#gno) in + let n = (ASTVector.get_size cn) in + let f i = (ASTVector.get cn i) in + Array.init n f + + (** + A brief justification of why the last call to Check returned UNKNOWN. + *) + let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown x#gnc x#gno + + + (** + Solver statistics. + *) + let get_statistics ( x : solver ) = + (new statistics x#gc)#cnstr_obj (Z3native.solver_get_statistics x#gnc x#gno) + + (** + A string representation of the solver. + *) + let to_string ( x : solver ) = Z3native.solver_to_string x#gnc x#gno +end + +(** Probes + + 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. +*) +module Probe = +struct + (** + Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. + *) + let apply ( x : probe ) (g : goal) = + Z3native.probe_apply x#gnc x#gno g#gno +end + + (** The main interaction with Z3 happens via the Context module *) module Context = struct From f1ecf3ae0bec626e0bc9861ed94beb146f288424 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sun, 23 Dec 2012 02:20:24 +0000 Subject: [PATCH 145/248] New ML API savepoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 6488 +++++++++++++++++++--------------------------- 1 file changed, 2629 insertions(+), 3859 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c22ef869b..5f67e11e2 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -586,6 +586,13 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end +(** Quantifier pattern objects *) +class pattern ctx = +object (self) + inherit ast ctx as super + method cnstr_obj obj = (self#sno ctx obj) ; self +end + (** Parameter description objects *) class param_descrs ctx = object (self) @@ -775,6 +782,33 @@ struct match (kind o) with | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int o#gnc o#gno)) | STRING_SYMBOL -> (Z3native.get_symbol_string o#gnc o#gno) + + (** + 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. + *) + let mk_int ( ctx : context ) i = + (new int_symbol ctx)#cnstr_int i + + (** Creates a new symbol using a string. *) + let mk_string ( ctx : context ) s = + (new string_symbol ctx)#cnstr_string s + + (** + Create an array of symbols. + *) + let mk_ints ( ctx : context ) ( names : int array ) = + let f elem = mk_int ( ctx : context ) elem in + (Array.map f names) + + (** + Create an array of symbols. + *) + let mk_strings ( ctx : context ) ( names : string array ) = + let f elem = mk_string ( ctx : context ) elem in + (Array.map f names) end @@ -813,49 +847,26 @@ struct A string representation of the sort. *) let to_string (x : sort) = Z3native.sort_to_string x#gnc x#gno + + (** + Create a new Boolean sort. + *) + let mk_bool ( ctx : context ) = + (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort ctx#gno) + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted ( ctx : context ) (s : symbol) = + (new uninterpreted_sort ctx)#cnstr_s s + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted_s ( ctx : context ) (s : string) = + mk_uninterpreted ctx ((Symbol.mk_string ( ctx : context ) s) :> symbol) end -(** Array sorts *) -module ArraySort = -struct - (** The domain of the array sort. *) - let get_domain (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_domain x#gnc x#gno) - - (** The range of the array sort. *) - let get_range (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_range x#gnc x#gno) -end - -(** Bit-vector sorts *) -module BitVecSort = -struct - (** The size of the bit-vector sort. *) - let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno -end - -(** Finite domain sorts *) -module FiniteDomainSort = -struct - (** The size of the finite domain sort. *) - let get_size (x : finite_domain_sort) = - let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") -end - -(** Relation sorts *) -module RelationSort = -struct - (** The arity of the relation sort. *) - let get_arity (x : relation_sort) = Z3native.get_relation_arity x#gnc x#gno - - (** The sorts of the columns of the relation sort. *) - let get_column_sorts (x : relation_sort) = - let n = get_arity x in - let f i = create_sort x#gc (Z3native.get_relation_column x#gnc x#gno i) in - Array.init n f - -end - (**/**) let create_expr ctx obj = if ast_kind_of_int (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then @@ -957,6 +968,48 @@ struct raise (Z3native.Exception "parameter is not a ratinoal string") else x#rational + + (** + Creates a new function declaration. + *) + let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr name domain range + + (** + Creates a new function declaration. + *) + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = + mk_func_decl ctx ((Symbol.mk_string ctx name) :> symbol) domain range + + (** + Creates a fresh function declaration with a name prefixed with . + + + *) + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort) = + (new func_decl ctx)#cnstr_pdr prefix domain range + + (** + Creates a new constant function declaration. + *) + let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr name [||] range + + + (** + Creates a new constant function declaration. + *) + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr ((Symbol.mk_string ctx name) :> symbol) [||] range + + (** + Creates a fresh constant function declaration with a name prefixed with . + + + *) + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = + (new func_decl ctx)#cnstr_pdr prefix [||] range + end (** @@ -1046,91 +1099,103 @@ struct end -(** Datatype sorts *) -module DatatypeSort = -struct - (** The number of constructors of the datatype sort. *) - let get_num_constructors (x : datatype_sort) = Z3native.get_datatype_sort_num_constructors x#gnc x#gno - - (** The range of the array sort. *) - let get_constructors (x : datatype_sort) = - let n = (get_num_constructors x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i) in - Array.init n f - - (** The recognizers. *) - let get_recognizers (x : datatype_sort) = - let n = (get_num_constructors x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_recognizer x#gnc x#gno i) in - Array.init n f - - (** The constructor accessors. *) - let get_accessors (x : datatype_sort) = - let n = (get_num_constructors x) in - let f i = ( - let fd = ((new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i)) in - let ds = (Z3native.get_domain_size fd#gnc fd#gno) in - let g j = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor_accessor x#gnc x#gno i j) in - Array.init ds g - ) in - Array.init n f -end - -(** Enumeration sorts *) -module EnumSort = -struct - (** The function declarations of the constants in the enumeration. *) - let get_const_decls (x : enum_sort) = x#const_decls - - (** The test predicates for the constants in the enumeration. *) - let get_tester_decls (x : enum_sort) = x#tester_decls -end - -(** List sorts *) -module ListSort = -struct - (** The declaration of the nil function of this list sort. *) - let get_nil_decl (x : list_sort) = x#nil_decl - - (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl (x : list_sort) = x#is_nil_decl - - (** The declaration of the cons function of this list sort. *) - let get_cons_decl (x : list_sort) = x#cons_decl - - (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl (x : list_sort) = x#is_cons_decl - - (** The declaration of the head function of this list sort.*) - let get_head_decl (x : list_sort) = x#head_decl - - (** The declaration of the tail function of this list sort. *) - let get_tail_decl (x : list_sort) = x#tail_decl - - (** The empty list. *) - let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] -end - -(** Tuple sorts *) -module TupleSort = -struct - (** The constructor function of the tuple.*) - let get_mk_decl (x : tuple_sort) = - (new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_mk_decl x#gnc x#gno) - - (** The number of fields in the tuple. *) - let get_num_fields (x : tuple_sort) = Z3native.get_tuple_sort_num_fields x#gnc x#gno - - (** The field declarations. *) - let get_field_decls (x : tuple_sort) = - let n = get_num_fields x in - let f i = ((new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_field_decl x#gnc x#gno i)) in - Array.init n f -end - (** The abstract syntax tree (AST) module *) module AST = struct + (** Vectors of ASTs *) + module ASTVector = + struct + (** The size of the vector *) + let get_size ( x : ast_vector ) = + Z3native.ast_vector_size x#gnc x#gno + + (** + Retrieves the i-th object in the vector. + @param i Index + @return An AST + *) + let get ( x : ast_vector ) ( i : int ) = + create_ast x#gc (Z3native.ast_vector_get x#gnc x#gno i) + + (** Sets the i-th object in the vector. *) + let set ( x : ast_vector ) ( i : int ) ( value : ast ) = + Z3native.ast_vector_set x#gnc x#gno i value#gno + + (** Resize the vector to . + @param newSize The new size of the vector. *) + let resize ( x : ast_vector ) ( new_size : int ) = + Z3native.ast_vector_resize x#gnc x#gno new_size + + (** + Add the AST to the back of the vector. The size + is increased by 1. + @param a An AST + *) + let push ( x : ast_vector ) ( a : ast ) = + Z3native.ast_vector_push x#gnc x#gno a#gno + + (** + Translates all ASTs in the vector to . + @param to_ctx A context + @return A new ASTVector + *) + let translate ( x : ast_vector ) ( to_ctx : context ) = + (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno to_ctx#gno) + + (** Retrieves a string representation of the vector. *) + let to_string ( x : ast_vector ) = + Z3native.ast_vector_to_string x#gnc x#gno + end + + (** Map from AST to AST *) + module ASTMap = + struct + (** Checks whether the map contains the key . + @param k An AST + @return True if is a key in the map, false otherwise. *) + let contains ( m : ast_map ) ( key : ast ) = + (lbool_of_int (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE + + (** Finds the value associated with the key . + + This function signs an error when is not a key in the map. + @param k An AST + *) + let find ( m : ast_map ) ( key : ast ) = + create_ast m#gc (Z3native.ast_map_find m#gnc m#gno key#gno) + + (** + Stores or replaces a new key/value pair in the map. + @param k The key AST + @param v The value AST + *) + let insert ( m : ast_map ) ( key : ast ) ( value : ast) = + Z3native.ast_map_insert m#gnc m#gno key#gno value#gno + + (** + Erases the key from the map. + @param k An AST + *) + let erase ( m : ast_map ) ( key : ast ) = + Z3native.ast_map_erase m#gnc m#gno key#gno + + (** Removes all keys from the map. *) + let reset ( m : ast_map ) = + Z3native.ast_map_reset m#gnc m#gno + + (** The size of the map *) + let get_size ( m : ast_map ) = + Z3native.ast_map_size m#gnc m#gno + + (** The keys stored in the map. *) + let get_keys ( m : ast_map ) = + (new ast_vector m#gc)#cnstr_obj (Z3native.ast_map_keys m#gnc m#gno) + + (** Retrieves a string representation of the map.*) + let to_strnig ( m : ast_map ) = + Z3native.ast_map_to_string m#gnc m#gno + end + (** The AST's hash code. @return A hash code @@ -1159,7 +1224,7 @@ struct | _ -> false (** - Indicates whether the AST is a BoundVariable + Indicates whether the AST is a bound variable *) let is_var ( x : ast) = (get_ast_kind x) == VAR_AST @@ -1227,163 +1292,7 @@ struct (create_ast to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno)) end -(** - Parameter sets - - A Params objects represents a configuration in the form of Symbol/value pairs. -*) -module Params = -struct - (** - Adds a parameter setting. - *) - let add_bool (p : params) (name : symbol) (value : bool) = - Z3native.params_set_bool p#gnc p#gno name#gno (int_of_lbool (if value then L_TRUE else L_FALSE)) - - (** - Adds a parameter setting. - *) - let add_int (p : params) (name : symbol) (value : int) = - Z3native.params_set_uint p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_double (p : params) (name : symbol) (value : float) = - Z3native.params_set_double p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_symbol (p : params) (name : symbol) (value : symbol) = - Z3native.params_set_symbol p#gnc p#gno name#gno value#gno - - (** - Adds a parameter setting. - *) - let add_s_bool (p : params) (name : string) (value : bool) = - add_bool p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_int (p : params) (name : string) (value : int) = - add_int p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_double (p : params) (name : string) (value : float) = - add_double p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_symbol (p : params) (name : string) (value : symbol) = - add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - A string representation of the parameter set. - *) - let to_string (p : params) = Z3native.params_to_string p#gnc p#gno -end - -(** Vectors of ASTs *) -module ASTVector = -struct - (** The size of the vector *) - let get_size ( x : ast_vector ) = - Z3native.ast_vector_size x#gnc x#gno - - (** - Retrieves the i-th object in the vector. - @param i Index - @return An AST - *) - let get ( x : ast_vector ) ( i : int ) = - create_ast x#gc (Z3native.ast_vector_get x#gnc x#gno i) - - (** Sets the i-th object in the vector. *) - let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set x#gnc x#gno i value#gno - - (** Resize the vector to . - @param newSize The new size of the vector. *) - let resize ( x : ast_vector ) ( new_size : int ) = - Z3native.ast_vector_resize x#gnc x#gno new_size - - (** - Add the AST to the back of the vector. The size - is increased by 1. - @param a An AST - *) - let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push x#gnc x#gno a#gno - - (** - Translates all ASTs in the vector to . - @param to_ctx A context - @return A new ASTVector - *) - let translate ( x : ast_vector ) ( to_ctx : context ) = - (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno to_ctx#gno) - - (** Retrieves a string representation of the vector. *) - let to_string ( x : ast_vector ) = - Z3native.ast_vector_to_string x#gnc x#gno -end - -(** Map from AST to AST *) -module ASTMap = -struct - (** Checks whether the map contains the key . - @param k An AST - @return True if is a key in the map, false otherwise. *) - let contains ( m : ast_map ) ( key : ast ) = - (lbool_of_int (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE - - (** Finds the value associated with the key . - - This function signs an error when is not a key in the map. - - @param k An AST - *) - let find ( m : ast_map ) ( key : ast ) = - create_ast m#gc (Z3native.ast_map_find m#gnc m#gno key#gno) - - (** - Stores or replaces a new key/value pair in the map. - @param k The key AST - @param v The value AST - *) - let insert ( m : ast_map ) ( key : ast ) ( value : ast) = - Z3native.ast_map_insert m#gnc m#gno key#gno value#gno - - (** - Erases the key from the map. - @param k An AST - *) - let erase ( m : ast_map ) ( key : ast ) = - Z3native.ast_map_erase m#gnc m#gno key#gno - - (** Removes all keys from the map. *) - let reset ( m : ast_map ) = - Z3native.ast_map_reset m#gnc m#gno - - (** The size of the map *) - let get_size ( m : ast_map ) = - Z3native.ast_map_size m#gnc m#gno - - (** The keys stored in the map. *) - let get_keys ( m : ast_map ) = - (new ast_vector m#gc)#cnstr_obj (Z3native.ast_map_keys m#gnc m#gno) - - (** Retrieves a string representation of the map.*) - let to_strnig ( m : ast_map ) = - Z3native.ast_map_to_string m#gnc m#gno -end - -(** Expressions (terms) *) +(** General expressions (terms), including Boolean logic *) module Expr = struct (** @@ -1402,7 +1311,7 @@ struct (** Indicates whether the expression is the true or false expression - or something else (Z3_L_UNDEF). + or something else (L_UNDEF). *) let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value x#gnc x#gno) @@ -1434,7 +1343,6 @@ struct 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]. - *) let substitute ( x : expr ) from to_ = if (Array.length from) <> (Array.length to_) then @@ -1453,7 +1361,6 @@ struct 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]. - *) let substitute_vars ( x : expr ) to_ = create_expr x#gc (Z3native.substitute_vars x#gnc x#gno (Array.length to_) (expraton to_)) @@ -1496,28 +1403,8 @@ struct *) let is_bool ( x : expr ) = (AST.is_expr x) && (lbool_of_int (Z3native.is_eq_sort x#gnc - (Z3native.mk_bool_sort x#gnc) - (Z3native.get_sort x#gnc x#gno))) == L_TRUE - - (** - Indicates whether the term is of integer sort. - *) - let is_int ( x : expr ) = - ((lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) - - (** - Indicates whether the term is of sort real. - *) - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) - - (** - Indicates whether the term is of an array sort. - *) - let is_array ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + (Z3native.mk_bool_sort x#gnc) + (Z3native.get_sort x#gnc x#gno))) == L_TRUE (** Indicates whether the term represents a constant. @@ -1526,21 +1413,6 @@ struct (get_num_args x) == 0 && FuncDecl.get_domain_size(get_func_decl x) == 0 - (** - Indicates whether the term is an integer numeral. - *) - let is_int_numeral ( x : expr ) = (is_numeral x) && (is_int x) - - (** - Indicates whether the term is a real numeral. - *) - let is_rat_num ( x : expr ) = (is_numeral x) && (is_real x) - - (** - Indicates whether the term is an algebraic number - *) - let is_algebraic_number ( x : expr ) = lbool_of_int(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE - (** Indicates whether the term is the constant true. *) @@ -1597,146 +1469,1189 @@ struct let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) (** - Indicates whether the term is an arithmetic numeral. + 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. *) - let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ANUM) + let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) (** - Indicates whether the term is a less-than-or-equal + 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. + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) *) - let is_le ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LE) (** - Indicates whether the term is a greater-than-or-equal + 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. *) - let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_GE) + let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) (** - Indicates whether the term is a less-than + Creates a new Constant of sort and named . *) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LT) + let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = + create_expr ctx (Z3native.mk_const ctx#gno name#gno range#gno) + (** - Indicates whether the term is a greater-than + Creates a new Constant of sort and named . *) - let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_GT) + let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = + mk_const ctx ((Symbol.mk_string ctx name) :> symbol) range + (** - Indicates whether the term is addition (binary) + Creates a constant from the func_decl . + @param f An expression of a 0-arity function *) - let is_add ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ADD) + let mk_const_f ( ctx : context ) ( f : func_decl ) = + create_expr_fa ctx f [||] (** - Indicates whether the term is subtraction (binary) + Creates a fresh constant of sort and a + name prefixed with . *) - let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SUB) + let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort) = + create_expr ctx (Z3native.mk_fresh_const ctx#gno prefix range#gno) (** - Indicates whether the term is a unary minus - *) - let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UMINUS) + Create a Boolean constant. + *) + let mk_bool_const ( ctx : context ) ( name : symbol ) = + ((mk_const ctx name (Sort.mk_bool ctx)) :> bool_expr) + + (** + Create a Boolean constant. + *) + let mk_bool_const_s ( ctx : context ) ( name : string ) = + mk_bool_const ctx ((Symbol.mk_string ctx name) :> symbol) (** - Indicates whether the term is multiplication (binary) + Create a new function application. *) - let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_MUL) + let mk_app ( ctx : context ) ( f : func_decl ) ( args : expr array ) = + create_expr_fa ctx f args (** - Indicates whether the term is division (binary) - *) - let is_div ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DIV) + The true Term. + *) + let mk_true ( ctx : context ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_true ctx#gno) (** - Indicates whether the term is integer division (binary) - *) - let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IDIV) + The false Term. + *) + let mk_false ( ctx : context ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_false ctx#gno) (** - Indicates whether the term is remainder (binary) - *) - let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_REM) + Creates a Boolean value. + *) + let mk_bool ( ctx : context ) ( value : bool) = + if value then mk_true ctx else mk_false ctx (** - Indicates whether the term is modulus (binary) + Creates the equality = . *) - let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_MOD) + let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_eq ctx#gno x#gno y#gno) (** - Indicates whether the term is a coercion of integer to real (unary) + Creates a distinct term. *) - let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TO_REAL) + let mk_distinct ( ctx : context ) ( args : expr array ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_distinct ctx#gno (Array.length args) (astaton args)) + + (** + Mk an expression representing not(a). + *) + let mk_not ( ctx : context ) ( a : bool_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_not ctx#gno a#gno) + + (** + Create an expression representing an if-then-else: ite(t1, t2, t3). + @param t1 An expression with Boolean sort + @param t2 An expression + @param t3 An expression with the same sort as + *) + let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = + create_expr ctx (Z3native.mk_ite ctx#gno t1#gno t2#gno t3#gno) + + (** + Create an expression representing t1 iff t2. + *) + let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_iff ctx#gno t1#gno t2#gno) (** - Indicates whether the term is a coercion of real to integer (unary) + Create an expression representing t1 -> t2. *) - let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TO_INT) + let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_implies ctx#gno t1#gno t2#gno) (** - Indicates whether the term is a check that tests whether a real is integral (unary) + Create an expression representing t1 xor t2. *) - let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IS_INT) + let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_xor ctx#gno t1#gno t2#gno) + + (** + Create an expression representing the AND of args + *) + let mk_and ( ctx : context ) ( args : bool_expr array ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_and ctx#gno (Array.length args) (astaton args)) + + (** + Create an expression representing the OR of args + *) + let mk_or ( ctx : context ) ( args : bool_expr array ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_or ctx#gno (Array.length args) (astaton args)) +end + +(** Functions to manipulate Array expressions *) +module Arrays = +struct + (** + Create a new array sort. + *) + let mk_sort ( ctx : context ) domain range = + (new array_sort ctx)#cnstr_dr domain range (** 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. + Array store takes at least 3 arguments. *) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_STORE) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) (** Indicates whether the term is an array select. *) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SELECT) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + For example, select(const(v),i) = v holds for every v and i. The function is unary. *) - let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CONST_ARRAY) + let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) (** Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. + For example default(const(v)) = v. The function is unary. *) - let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ARRAY_DEFAULT) + let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + It satisfies map[f](a1,..,a_n)[i] = f(a1[i],...,a_n[i]) for every i. *) - let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ARRAY_MAP) + let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + function passed as parameter. *) - let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AS_ARRAY) + let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + (** + Indicates whether the term is of an array sort. + *) + let is_array ( x : expr ) = + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + + (** The domain of the array sort. *) + let get_domain (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_domain x#gnc x#gno) + + (** The range of the array sort. *) + let get_range (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_range x#gnc x#gno) + + + (** + Create an array constant. + *) + let mk_const ( ctx : context ) ( name : symbol ) ( domain : sort ) ( range : sort ) = + ((Expr.mk_const ctx name ((mk_sort ctx domain range) :> sort)) :> array_expr) + + (** + Create an array constant. + *) + let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = + mk_const ctx ((Symbol.mk_string ctx name) :> symbol) 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. + + + *) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = + ((create_expr ctx (Z3native.mk_select ctx#gno a#gno i#gno)) :> array_expr) + + (** + 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). + + + *) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr) = + (new array_expr ctx)#cnstr_obj (Z3native.mk_store ctx#gno a#gno i#gno v#gno) + + (** + Create a constant array. + + The resulting term is an array, such that a selecton an arbitrary index + produces the value v. + + + *) + let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = + (new array_expr ctx)#cnstr_obj (Z3native.mk_const_array ctx#gno domain#gno v#gno) + + (** + 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]. + + + + *) + let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = + ((create_expr ctx (Z3native.mk_map ctx#gno f#gno (Array.length args) (astaton args))) :> array_expr) + + (** + Access the array default value. + + Produces the default range value, for arrays that can be represented as + finite maps with a default range value. + *) + let mk_term_array ( ctx : context ) ( arg : array_expr ) = + ((create_expr ctx (Z3native.mk_array_default ctx#gno arg#gno)) :> array_expr) +end + +(** Functions to manipulate Set expressions *) +module Sets = +struct (** Indicates whether the term is set union *) - let is_set_union ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_UNION) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) (** Indicates whether the term is set intersection *) - let is_set_intersect ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_INTERSECT) + let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) (** Indicates whether the term is set difference *) - let is_set_difference ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_DIFFERENCE) + let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) (** Indicates whether the term is set complement *) - let is_set_complement ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_COMPLEMENT) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) (** Indicates whether the term is set subset *) - let is_set_subset ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SET_SUBSET) + let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + +(** + Create a set type. +*) +let mk_sort ( ctx : context ) ( ty : sort) = + (new set_sort ctx)#cnstr_s ty + +(** + Create an empty set. +*) +let mk_empty ( ctx : context ) ( domain : sort ) = + (create_expr ctx (Z3native.mk_empty_set ctx#gno domain#gno)) + + (** + Create the full set. + *) +let mk_full ( ctx : context ) ( domain : sort ) = + create_expr ctx (Z3native.mk_full_set ctx#gno domain#gno) + +(** + Add an element to the set. +*) +let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = + create_expr ctx (Z3native.mk_set_add ctx#gno set#gno element#gno) + + (** + Remove an element from a set. + *) +let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = + create_expr ctx (Z3native.mk_set_del ctx#gno set#gno element#gno) + + (** + Take the union of a list of sets. + *) +let mk_union ( ctx : context ) ( args : expr array ) = + create_expr ctx (Z3native.mk_set_union ctx#gno (Array.length args) (astaton args)) + +(** + Take the intersection of a list of sets. +*) +let mk_intersection ( ctx : context ) ( args : expr array ) = + create_expr ctx (Z3native.mk_set_intersect ctx#gno (Array.length args) (astaton args)) + +(** + Take the difference between two sets. +*) +let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = + create_expr ctx (Z3native.mk_set_difference ctx#gno arg1#gno arg2#gno) + +(** + Take the complement of a set. +*) +let mk_complement ( ctx : context ) ( arg : expr ) = + create_expr ctx (Z3native.mk_set_complement ctx#gno arg#gno) + +(** + Check for set membership. +*) +let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = + create_expr ctx (Z3native.mk_set_member ctx#gno elem#gno set#gno) + + (** + Check for subsetness of sets. + *) +let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = + create_expr ctx (Z3native.mk_set_subset ctx#gno arg1#gno arg2#gno) + +end + +(** Functions to manipulate Finite Domain expressions *) +module FiniteDomains = +struct + (** + Create a new finite domain sort. + *) + let mk_sort ( ctx : context ) ( name : symbol ) size = + (new finite_domain_sort ctx)#cnstr_si name size + + (** + Create a new finite domain sort. + *) + let mk_sort_s ( ctx : context ) ( name : string ) size = + (new finite_domain_sort ctx)#cnstr_si ((Symbol.mk_string ctx name) :> symbol) size + + + (** + Indicates whether the term is of an array sort. + *) + let is_finite_domain ( x : expr ) = + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) + + (** + Indicates whether the term is a less than predicate over a finite domain. + *) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + + (** The size of the finite domain sort. *) + let get_size (x : finite_domain_sort) = + let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in + if lbool_of_int(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") +end + +(** Functions to manipulate Relation expressions *) +module Relations = +struct + (** + Indicates whether the term is of a relation sort. + *) + let is_relation ( x : expr ) = + ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == 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. + *) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + + (** + Indicates whether the term is an empty relation + *) + let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + + (** + Indicates whether the term is a test for the emptiness of a relation + *) + let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + + (** + Indicates whether the term is a relational join + *) + let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + + (** + Indicates whether the term is the union or convex hull of two relations. + The function takes two arguments. + *) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + + (** + Indicates whether the term is the widening of two relations + The function takes two arguments. + *) + let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + + (** + Indicates whether the term is a projection of columns (provided as numbers in the parameters). + The function takes one argument. + *) + let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + *) + let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. + *) + let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + *) + let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + + (** + Indicates whether the term is the complement of a relation + *) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + *) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + *) + let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + + (** The arity of the relation sort. *) + let get_arity (x : relation_sort) = Z3native.get_relation_arity x#gnc x#gno + + (** The sorts of the columns of the relation sort. *) + let get_column_sorts (x : relation_sort) = + let n = get_arity x in + let f i = create_sort x#gc (Z3native.get_relation_column x#gnc x#gno i) in + Array.init n f + +end + +(** Quantifier expressions *) +module Quantifiers = +struct + (** + 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 : expr ) appears, the higher is its + index. + *) + let get_index ( x : expr ) = + if not (AST.is_var x) then + raise (Z3native.Exception "Term is not a bound variable.") + else + Z3native.get_index_value x#gnc x#gno + + (** Quantifier patterns + + 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. + *) + module Pattern = + struct + (** + The number of terms in the pattern. + *) + let get_num_terms ( x : pattern ) = + Z3native.get_pattern_num_terms x#gnc x#gno + + (** + The terms in the pattern. + *) + let get_terms ( x : pattern ) = + let n = (get_num_terms x) in + let f i = (create_expr x#gc (Z3native.get_pattern x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the pattern. + *) + let to_string ( x : pattern ) = Z3native.pattern_to_string x#gnc x#gno + end + + (** + Indicates whether the quantifier is universal. + *) + let is_universal ( x : quantifier ) = + lbool_of_int (Z3native.is_quantifier_forall x#gnc x#gno) == L_TRUE + + (** + Indicates whether the quantifier is existential. + *) + let is_existential ( x : quantifier ) = not (is_universal x) + + (** + The weight of the quantifier. + *) + let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight x#gnc x#gno + + (** + The number of patterns. + *) + let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns x#gnc x#gno + + (** + The patterns. + *) + let get_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_pattern_ast x#gnc x#gno i)) in + Array.init n f + + (** + The number of no-patterns. + *) + let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns x#gnc x#gno + + (** + The no-patterns. + *) + let get_no_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_no_pattern_ast x#gnc x#gno i)) in + Array.init n f + + (** + The number of bound variables. + *) + let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound x#gnc x#gno + + (** + The symbols for the bound variables. + *) + let get_bound_variable_names ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (create_symbol x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in + Array.init n f + + (** + The sorts of the bound variables. + *) + let get_bound_variable_sorts ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (create_sort x#gc (Z3native.get_quantifier_bound_sort x#gnc x#gno i)) in + Array.init n f + + (** + The body of the quantifier. + *) + let get_body ( x : quantifier ) = + (new bool_expr x#gc)#cnstr_obj (Z3native.get_quantifier_body x#gnc x#gno) + + (** + Creates a new bound variable. + @param index The de-Bruijn index of the variable + @param ty The sort of the variable + *) + let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = + create_expr ctx (Z3native.mk_bound ctx#gno index ty#gno) + + (** + Create a quantifier pattern. + *) + let mk_pattern ( ctx : context ) ( terms : expr array ) = + if (Array.length terms) == 0 then + raise (Z3native.Exception "Cannot create a pattern from zero terms") + else + (new pattern ctx)#cnstr_obj (Z3native.mk_pattern ctx#gno (Array.length terms) (astaton terms)) +end + +(** Functions to manipulate Datatype expressions *) +module Datatypes = +struct + (** Constructors *) + module Constructor = + struct + (** The number of fields of the constructor. *) + let get_num_fields ( x : constructor ) = x#get_n + + (** The function declaration of the constructor. *) + let get_constructor_decl ( x : constructor ) = x#constructor_decl + + (** The function declaration of the tester. *) + let get_tester_decl ( x : constructor ) = x#tester_decl + + (** The function declarations of the accessors *) + let get_accessor_decls ( x : constructor ) = x#accessor_decls + end + + (* DATATYPES *) + (** + Create a datatype constructor. + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + *) + let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs + + + (** + Create a datatype constructor. + @param name constructor name + @param recognizer name of recognizer function. + @param fieldNames names of the constructor fields. + @param sorts field sorts, 0 if the field sort refers to a recursive sort. + @param sortRefs reference to datatype sort that is an argument to the constructor; + if the corresponding sort reference is 0, then the value in sort_refs should be an index + referring to one of the recursive datatypes that is declared. + *) + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + mk_constructor ctx ((Symbol.mk_string ctx name) :> symbol) recognizer field_names sorts sort_refs + + + (** + Create a new datatype sort. + *) + let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = + (new datatype_sort ctx)#cnstr_sc name constructors + + (** + Create a new datatype sort. + *) + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = + mk_sort ctx ((Symbol.mk_string ctx name) :> symbol) constructors + + (** + Create mutually recursive datatypes. + @param names names of datatype sorts + @param c list of constructors, one list per sort. + *) + let mk_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = + let n = (Array.length names) in + let f e = ( (new constructor_list ctx)#cnstr_ca e ) in + let cla = (Array.map f c) in + let (r, a) = (Z3native.mk_datatypes ctx#gno n (symbolaton names) (constructor_listaton cla)) in + let g e = ( (new datatype_sort ctx)#cnstr_obj e) in + (Array.map g r) + + (** Create mutually recursive data-types. *) + let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = + mk_sorts ctx + ( + let f e = ((Symbol.mk_string ctx e) :> symbol) in + Array.map f names + ) + c + + (** The number of constructors of the datatype sort. *) + let get_num_constructors (x : datatype_sort) = Z3native.get_datatype_sort_num_constructors x#gnc x#gno + + (** The range of the array sort. *) + let get_constructors (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i) in + Array.init n f + + (** The recognizers. *) + let get_recognizers (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_recognizer x#gnc x#gno i) in + Array.init n f + + (** The constructor accessors. *) + let get_accessors (x : datatype_sort) = + let n = (get_num_constructors x) in + let f i = ( + let fd = ((new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i)) in + let ds = (Z3native.get_domain_size fd#gnc fd#gno) in + let g j = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor_accessor x#gnc x#gno i j) in + Array.init ds g + ) in + Array.init n f +end + +(** Functions to manipulate Enumeration expressions *) +module Enumerations = +struct + (** + Create a new enumeration sort. + *) + let mk_sort ( ctx : context ) name enum_names = + (new enum_sort ctx)#cnstr_ss name enum_names + + (** + Create a new enumeration sort. + *) + let mk_sort_s ( ctx : context ) name enum_names = + (new enum_sort ctx)#cnstr_ss + ((Symbol.mk_string ( ctx : context ) name) :> symbol) + (let f e = (e :> symbol) in + (Array.map f (Symbol.mk_strings ( ctx : context ) enum_names)) + ) + + (** The function declarations of the constants in the enumeration. *) + let get_const_decls (x : enum_sort) = x#const_decls + + (** The test predicates for the constants in the enumeration. *) + let get_tester_decls (x : enum_sort) = x#tester_decls +end + +(** Functions to manipulate List expressions *) +module Lists = +struct + (** + Create a new list sort. + *) + let mk_sort ( ctx : context ) (name : symbol) elem_sort = + (new list_sort ctx)#cnstr_ss name elem_sort + + (** + Create a new list sort. + *) + let mk_list_s ( ctx : context ) (name : string) elem_sort = + mk_sort ctx ((Symbol.mk_string ctx name) :> symbol) elem_sort + + + (** The declaration of the nil function of this list sort. *) + let get_nil_decl (x : list_sort) = x#nil_decl + + (** The declaration of the isNil function of this list sort. *) + let get_is_nil_decl (x : list_sort) = x#is_nil_decl + + (** The declaration of the cons function of this list sort. *) + let get_cons_decl (x : list_sort) = x#cons_decl + + (** The declaration of the isCons function of this list sort. *) + let get_is_cons_decl (x : list_sort) = x#is_cons_decl + + (** The declaration of the head function of this list sort. *) + let get_head_decl (x : list_sort) = x#head_decl + + (** The declaration of the tail function of this list sort. *) + let get_tail_decl (x : list_sort) = x#tail_decl + + (** The empty list. *) + let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] +end + +(** Functions to manipulate Tuple expressions *) +module Tuples = +struct + (** + Create a new tuple sort. + *) + let mk_sort ( ctx : context ) name field_names field_sorts = + (new tuple_sort ctx)#cnstr_siss name (Array.length field_names) field_names field_sorts + + (** The constructor function of the tuple. *) + let get_mk_decl (x : tuple_sort) = + (new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_mk_decl x#gnc x#gno) + + (** The number of fields in the tuple. *) + let get_num_fields (x : tuple_sort) = Z3native.get_tuple_sort_num_fields x#gnc x#gno + + (** The field declarations. *) + let get_field_decls (x : tuple_sort) = + let n = get_num_fields x in + let f i = ((new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_field_decl x#gnc x#gno i)) in + Array.init n f +end + +(** Functions to manipulate arithmetic expressions *) +module Arithmetic = +struct + (** + Create a new integer sort. + *) + let mk_int_sort ( ctx : context ) = + (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort ctx#gno) + + (** + Create a real sort. + *) + let mk_real_sort ( ctx : context ) = + (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort ctx#gno) + + (** + Indicates whether the term is of integer sort. + *) + let is_int ( x : expr ) = + ((lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) + + (** + Indicates whether the term is an arithmetic numeral. + *) + let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + + (** + Indicates whether the term is a less-than-or-equal + *) + let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + + (** + Indicates whether the term is a greater-than-or-equal + *) + let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + + (** + Indicates whether the term is a less-than + *) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + + (** + Indicates whether the term is a greater-than + *) + let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + + (** + Indicates whether the term is addition (binary) + *) + let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + + (** + Indicates whether the term is subtraction (binary) + *) + let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + + (** + Indicates whether the term is a unary minus + *) + let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + + (** + Indicates whether the term is multiplication (binary) + *) + let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + + (** + Indicates whether the term is division (binary) + *) + let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + + (** + Indicates whether the term is integer division (binary) + *) + let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + + (** + Indicates whether the term is remainder (binary) + *) + let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + + (** + Indicates whether the term is modulus (binary) + *) + let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + + (** + Indicates whether the term is a coercion of integer to real (unary) + *) + let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + + (** + Indicates whether the term is a coercion of real to integer (unary) + *) + let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + + (** + Indicates whether the term is a check that tests whether a real is integral (unary) + *) + let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + + (** + Indicates whether the term is of sort real. + *) + let is_real ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) + + (** + Indicates whether the term is an integer numeral. + *) + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) + + (** + Indicates whether the term is a real numeral. + *) + let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) + + (** + Indicates whether the term is an algebraic number + *) + let is_algebraic_number ( x : expr ) = lbool_of_int(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE + + (** Retrieve the int value. *) + let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if lbool_of_int(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno + + (** The numerator of a rational numeral. *) + let get_numerator ( x : rat_num ) = + (new int_num x#gc)#cnstr_obj (Z3native.get_numerator x#gnc x#gno) + + (** The denominator of a rational numeral. *) + let get_denominator ( x : rat_num ) = + (new int_num x#gc)#cnstr_obj (Z3native.get_denominator x#gnc x#gno) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : rat_num ) (precision : int) = + Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : rat_num ) = Z3native.get_numeral_string x#gnc x#gno + + (** + Creates an integer constant. + *) + let mk_int_const ( ctx : context ) ( name : symbol ) = + ((Expr.mk_const ctx name (mk_int_sort ctx)) :> int_expr) + + (** + Creates an integer constant. + *) + let mk_int_const_s ( ctx : context ) ( name : string ) = + mk_int_const ctx ((Symbol.mk_string ctx name) :> symbol) + + (** + Creates a real constant. + *) + let mk_real_const ( ctx : context ) ( name : symbol ) = + ((Expr.mk_const ctx name (mk_real_sort ctx)) :> real_expr) + + (** + Creates a real constant. + *) + let mk_real_const_s ( ctx : context ) ( name : string ) = + mk_real_const ctx ((Symbol.mk_string ctx name) :> symbol) + + (** + Create an expression representing t[0] + t[1] + .... + *) + let mk_add ( ctx : context ) ( t : arith_expr array ) = + (create_expr ctx (Z3native.mk_add ctx#gno (Array.length t) (astaton t)) :> arith_expr) + + (** + Create an expression representing t[0] * t[1] * .... + *) + let mk_mul ( ctx : context ) ( t : arith_expr array ) = + (create_expr ctx (Z3native.mk_mul ctx#gno (Array.length t) (astaton t)) :> arith_expr) + + (** + Create an expression representing t[0] - t[1] - .... + *) + let mk_sub ( ctx : context ) ( t : arith_expr array ) = + (create_expr ctx (Z3native.mk_sub ctx#gno (Array.length t) (astaton t)) :> arith_expr) + + (** + Create an expression representing -t. + *) + let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = + (create_expr ctx (Z3native.mk_unary_minus ctx#gno t#gno) :> arith_expr) + + (** + Create an expression representing t1 / t2. + *) + let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + (create_expr ctx (Z3native.mk_div ctx#gno t1#gno t2#gno) :> arith_expr) + + (** + Create an expression representing t1 mod t2. + The arguments must have int type. + *) + let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new int_expr ctx)#cnstr_obj (Z3native.mk_mod ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 rem t2. + The arguments must have int type. + *) + let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new int_expr ctx)#cnstr_obj (Z3native.mk_rem ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 ^ t2. + *) + let mk_Power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (create_expr ctx (Z3native.mk_power ctx#gno t1#gno t2#gno) :> arith_expr) + + (** + Create an expression representing t1 < t2 + *) + let mk_lt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_lt ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 <= t2 + *) + let mk_le ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_le ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 > t2 + *) + let mk_gt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_gt ctx#gno t1#gno t2#gno) + + (** + Create an expression representing t1 >= t2 + *) + let mk_ge ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_ge ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_int2real ( ctx : context ) ( t : int_expr ) = + (new real_expr ctx)#cnstr_obj (Z3native.mk_int2real ctx#gno t#gno) + + (** + 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. + *) + let mk_real2int ( ctx : context ) ( t : real_expr ) = + (new int_expr ctx)#cnstr_obj (Z3native.mk_real2int ctx#gno t#gno) + + (** + Creates an expression that checks whether a real number is an integer. + *) + let mk_is_integer ( ctx : context ) ( t : real_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_is_int ctx#gno t#gno) + + (** + Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + @param precision the precision of the result + @return A numeral Expr of sort Real + *) + let to_upper ( x : algebraic_num ) ( precision : int ) = + (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) + + (** + Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + @param precision the precision of the result + @return A numeral Expr of sort Real + *) + let to_lower ( x : algebraic_num ) precision = + (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : algebraic_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno +end + + +(** Functions to manipulate bit-vector expressions *) +module BitVectors = +struct + (** + Create a new bit-vector sort. + *) + let mk_sort ( ctx : context ) size = + (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort ctx#gno size) (** Indicates whether the terms is of bit-vector sort. @@ -1747,300 +2662,750 @@ struct (** Indicates whether the term is a bit-vector numeral *) - let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNUM) + let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) (** Indicates whether the term is a one-bit bit-vector with value one *) - let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BIT1) + let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) (** Indicates whether the term is a one-bit bit-vector with value zero *) - let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BIT0) + let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) (** Indicates whether the term is a bit-vector unary minus *) - let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNEG) + let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) (** Indicates whether the term is a bit-vector addition (binary) *) - let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BADD) + let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) (** Indicates whether the term is a bit-vector subtraction (binary) *) - let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSUB) + let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) (** Indicates whether the term is a bit-vector multiplication (binary) *) - let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BMUL) + let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) (** Indicates whether the term is a bit-vector signed division (binary) *) - let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSDIV) + let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) (** Indicates whether the term is a bit-vector unsigned division (binary) *) - let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUDIV) + let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) (** Indicates whether the term is a bit-vector signed remainder (binary) *) - let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSREM) + let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUREM) + let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) (** Indicates whether the term is a bit-vector signed modulus *) - let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSMOD) + let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) (** Indicates whether the term is a bit-vector signed division by zero *) - let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSDIV0) + let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) (** Indicates whether the term is a bit-vector unsigned division by zero *) - let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUDIV0) + let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) (** Indicates whether the term is a bit-vector signed remainder by zero *) - let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSREM0) + let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BUREM0) + let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) (** Indicates whether the term is a bit-vector signed modulus by zero *) - let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSMOD0) + let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ULEQ) + let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SLEQ) + let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UGEQ) + let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SGEQ) + let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) (** Indicates whether the term is an unsigned bit-vector less-than *) - let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ULT) + let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) (** Indicates whether the term is a signed bit-vector less-than *) - let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SLT) + let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) (** Indicates whether the term is an unsigned bit-vector greater-than *) - let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_UGT) + let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) (** Indicates whether the term is a signed bit-vector greater-than *) - let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SGT) + let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) (** Indicates whether the term is a bit-wise AND *) - let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BAND) + let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) (** Indicates whether the term is a bit-wise OR *) - let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BOR) + let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) (** Indicates whether the term is a bit-wise NOT *) - let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNOT) + let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) (** Indicates whether the term is a bit-wise XOR *) - let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BXOR) + let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) (** Indicates whether the term is a bit-wise NAND *) - let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNAND) + let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) (** Indicates whether the term is a bit-wise NOR *) - let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BNOR) + let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) (** Indicates whether the term is a bit-wise XNOR *) - let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BXNOR) + let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) (** Indicates whether the term is a bit-vector concatenation (binary) *) - let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CONCAT) + let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) (** Indicates whether the term is a bit-vector sign extension *) - let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_SIGN_EXT) + let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) (** Indicates whether the term is a bit-vector zero extension *) - let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ZERO_EXT) + let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) (** Indicates whether the term is a bit-vector extraction *) - let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EXTRACT) + let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) (** Indicates whether the term is a bit-vector repetition *) - let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_REPEAT) + let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) (** Indicates whether the term is a bit-vector reduce OR *) - let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BREDOR) + let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) (** Indicates whether the term is a bit-vector reduce AND *) - let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BREDAND) + let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) (** Indicates whether the term is a bit-vector comparison *) - let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BCOMP) + let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) (** Indicates whether the term is a bit-vector shift left *) - let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BSHL) + let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) (** Indicates whether the term is a bit-vector logical shift right *) - let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) (** Indicates whether the term is a bit-vector arithmetic shift left *) - let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BASHR) + let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) (** Indicates whether the term is a bit-vector rotate left *) - let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) (** Indicates whether the term is a bit-vector rotate right *) - let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + Similar to Z3_OP_ROTATE_LEFT, but it is a binary operator instead of a parametric one. *) - let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + Similar to Z3_OP_ROTATE_RIGHT, but it is a binary operator instead of a parametric one. *) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + rudimentary simplification rules are applied to this function. *) - let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_INT2BV) + let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. + rudimentary simplification rules are applied to this function. *) - let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_BV2INT) + let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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))) + equivalence (carry l1 l2 l3) <=> (or (and l1 l2) (and l1 l3) (and l2 l3))) *) - let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_CARRY) + let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) + The meaning is given by the equivalence (xor3 l1 l2 l3) <=> (xor (xor l1 l2) l3) *) - let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR3) + let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + + (** The size of a bit-vector sort. *) + let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno + + (** Retrieve the int value. *) + let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if lbool_of_int(r) == L_TRUE then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno (** - 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. + Creates a bit-vector constant. *) - let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) + let mk_const ( ctx : context ) ( name : symbol ) ( size : int ) = + ((Expr.mk_const ctx name (mk_sort ctx size)) :> bitvec_expr) (** - 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. - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) + Creates a bit-vector constant. *) + let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = + mk_const ctx ((Symbol.mk_string ctx name) :> symbol) size (** - 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. + Bitwise negation. + The argument must have a bit-vector sort. *) - let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) + let mk_not ( ctx : context ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnot ctx#gno t#gno) + (** + Take conjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. + *) + let mk_redand ( ctx : context ) ( t : bitvec_expr) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredand ctx#gno t#gno) + + (** + Take disjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. + *) + let mk_redor ( ctx : context ) ( t : bitvec_expr) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredor ctx#gno t#gno) + + (** + Bitwise conjunction. + The arguments must have a bit-vector sort. + *) + let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvand ctx#gno t1#gno t2#gno) + + (** + Bitwise disjunction. + The arguments must have a bit-vector sort. + *) + let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvor ctx#gno t1#gno t2#gno) + + (** + Bitwise XOR. + The arguments must have a bit-vector sort. + *) + let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxor ctx#gno t1#gno t2#gno) + + (** + Bitwise NAND. + The arguments must have a bit-vector sort. + *) + let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnand ctx#gno t1#gno t2#gno) + + (** + Bitwise NOR. + The arguments must have a bit-vector sort. + *) + let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnor ctx#gno t1#gno t2#gno) + + (** + Bitwise XNOR. + The arguments must have a bit-vector sort. + *) + let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxnor ctx#gno t1#gno t2#gno) + + (** + Standard two's complement unary minus. + The arguments must have a bit-vector sort. + *) + let mk_neg ( ctx : context ) ( t : bitvec_expr) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvneg ctx#gno t#gno) + + (** + Two's complement addition. + The arguments must have the same bit-vector sort. + *) + let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvadd ctx#gno t1#gno t2#gno) + + (** + Two's complement subtraction. + The arguments must have the same bit-vector sort. + *) + let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsub ctx#gno t1#gno t2#gno) + + (** + Two's complement multiplication. + The arguments must have the same bit-vector sort. + *) + let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvmul ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvudiv ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvurem ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsrem ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsmod ctx#gno t1#gno t2#gno) + + (** + Unsigned less-than + + The arguments must have the same bit-vector sort. + *) + let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvult ctx#gno t1#gno t2#gno) + + (** + Two's complement signed less-than + + The arguments must have the same bit-vector sort. + *) + let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvslt ctx#gno t1#gno t2#gno) + + (** + Unsigned less-than or equal to. + + The arguments must have the same bit-vector sort. + *) + let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvule ctx#gno t1#gno t2#gno) + + (** + Two's complement signed less-than or equal to. + + The arguments must have the same bit-vector sort. + *) + let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsle ctx#gno t1#gno t2#gno) + + (** + Unsigned greater than or equal to. + + The arguments must have the same bit-vector sort. + *) + let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvuge ctx#gno t1#gno t2#gno) + + (** + Two's complement signed greater than or equal to. + + The arguments must have the same bit-vector sort. + *) + let mk_SGE ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsge ctx#gno t1#gno t2#gno) + + (** + Unsigned greater-than. + + The arguments must have the same bit-vector sort. + *) + let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvugt ctx#gno t1#gno t2#gno) + + (** + Two's complement signed greater-than. + + The arguments must have the same bit-vector sort. + *) + let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsgt ctx#gno t1#gno t2#gno) + + (** + 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). + *) + let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_concat ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_extract ctx#gno high low t#gno) + + (** + 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. + *) + let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_sign_ext ctx#gno i t#gno) + + (** + 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. + *) + let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_zero_ext ctx#gno i t#gno) + + (** + Bit-vector repetition. + + The argument must have a bit-vector sort. + *) + let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_repeat ctx#gno i t#gno) + + (** + 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. + *) + let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvshl ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvlshr ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvashr ctx#gno t1#gno t2#gno) + + (** + Rotate Left. + + Rotate bits of \c t to the left \c i times. + The argument must have a bit-vector sort. + *) + let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_left ctx#gno i t#gno) + + (** + Rotate Right. + + Rotate bits of \c t to the right \c i times. + The argument must have a bit-vector sort. + *) + let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_right ctx#gno i t#gno) + + (** + Rotate Left. + + Rotate bits of to the left times. + The arguments must have the same bit-vector sort. + *) + let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_left ctx#gno t1#gno t2#gno) + + (** + Rotate Right. + + + Rotate bits of to the right times. + The arguments must have the same bit-vector sort. + *) + let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_right ctx#gno t1#gno t2#gno) + + (** + 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. + *) + let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_int2bv ctx#gno n t#gno) + + (** + 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. + *) + let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = + (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int ctx#gno t#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + + (** + Create a predicate that checks that the bit-wise addition does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + + (** + Create a predicate that checks that the bit-wise addition does not underflow. + + The arguments must be of bit-vector sort. + *) + let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_underflow ctx#gno t1#gno t2#gno) + + (** + Create a predicate that checks that the bit-wise subtraction does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_overflow ctx#gno t1#gno t2#gno) + + (** + Create a predicate that checks that the bit-wise subtraction does not underflow. + + The arguments must be of bit-vector sort. + *) + let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + + (** + Create a predicate that checks that the bit-wise signed division does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv_no_overflow ctx#gno t1#gno t2#gno) + + (** + Create a predicate that checks that the bit-wise negation does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvneg_no_overflow ctx#gno t#gno) + + (** + Create a predicate that checks that the bit-wise multiplication does not overflow. + + The arguments must be of bit-vector sort. + *) + let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + + (** + Create a predicate that checks that the bit-wise multiplication does not underflow. + + The arguments must be of bit-vector sort. + *) + let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow ctx#gno t1#gno t2#gno) + +end + +(** Functions to manipulate Proof objects *) +module Proofs = +struct (** Indicates whether the term is a Proof for the expression 'true'. *) - let is_proof_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TRUE) + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) (** Indicates whether the term is a proof for a fact asserted by the user. *) - let is_proof_asserted ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_ASSERTED) + let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - let is_proof_goal ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_GOAL) + let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) (** Indicates whether the term is proof via modus ponens @@ -2049,18 +3414,18 @@ struct T1: p T2: (implies p q) [mp T1 T2]: q - The second antecedents may also be a proof for (iff p q). + The second antecedents may also be a proof for (iff p q). *) - let is_proof_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_MODUS_PONENS) + let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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'. + That is, R is either '~', '=' or 'iff'. *) - let is_proof_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_REFLEXIVITY) + let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) (** Indicates whether the term is proof by symmetricity of a relation @@ -2069,9 +3434,8 @@ struct T1: (R t s) [symmetry T1]: (R s t) T1 is the antecedent of this proof object. - *) - let is_proof_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_SYMMETRY) + let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) (** Indicates whether the term is a proof by transitivity of a relation @@ -2081,9 +3445,8 @@ struct T1: (R t s) T2: (R s u) [trans T1 T2]: (R t u) - *) - let is_proof_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TRANSITIVITY) + let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) (** Indicates whether the term is a proof by condensed transitivity of a relation @@ -2102,9 +3465,8 @@ struct 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. - *) - let is_proof_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) (** @@ -2116,9 +3478,8 @@ struct [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. - *) - let is_proof_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_MONOTONICITY) + let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) (** Indicates whether the term is a quant-intro proof @@ -2126,9 +3487,8 @@ struct 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)) - *) - let is_proof_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_QUANT_INTRO) + let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) (** Indicates whether the term is a distributivity proof object. @@ -2144,9 +3504,8 @@ struct This proof object has no antecedents. Remark. This rule is used by the CNF conversion pass and instantiated by f = or, and g = and. - *) - let is_proof_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) (** Indicates whether the term is a proof by elimination of AND @@ -2154,9 +3513,8 @@ struct 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 - *) - let is_proof_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_AND_ELIM) + let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) (** Indicates whether the term is a proof by eliminiation of not-or @@ -2164,9 +3522,8 @@ struct 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) - *) - let is_proof_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) (** Indicates whether the term is a proof by rewriting @@ -2183,9 +3540,8 @@ struct (= (+ ( x : expr ) 0) x) (= (+ ( x : expr ) 1 2) (+ 3 x)) (iff (or ( x : expr ) false) x) - *) - let is_proof_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_REWRITE) + let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) (** Indicates whether the term is a proof by rewriting @@ -2199,17 +3555,15 @@ struct - 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) - *) - let is_proof_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_REWRITE_STAR) + let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) - let is_proof_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) (** Indicates whether the term is a proof for pulling quantifiers out. @@ -2217,9 +3571,8 @@ struct 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 - *) - let is_proof_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) (** Indicates whether the term is a proof for pushing quantifiers in. @@ -2230,9 +3583,9 @@ struct ... (forall (x_1 ... x_m) p_n[x_1 ... x_m]))) This proof object has no antecedents - *) - let is_proof_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_PUSH_QUANT) + + let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) (** Indicates whether the term is a proof for elimination of unused variables. @@ -2242,9 +3595,9 @@ struct It is used to justify the elimination of unused variables. This proof object has no antecedents. - *) - let is_proof_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + + let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) (** Indicates whether the term is a proof for destructive equality resolution @@ -2256,23 +3609,22 @@ struct This proof object has no antecedents. Several variables can be eliminated simultaneously. - *) - let is_proof_der ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DER) + + let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) (** Indicates whether the term is a proof for quantifier instantiation A proof of (or (not (forall (x) (P x))) (P a)) - *) - let is_proof_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_QUANT_INST) + let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) (** Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. + Mark a hypothesis in a natural deduction style proof. *) - let is_proof_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_HYPOTHESIS) + let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) (** Indicates whether the term is a proof by lemma @@ -2283,9 +3635,8 @@ struct 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. - *) - let is_proof_lemma ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_LEMMA) + let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) (** Indicates whether the term is a proof by unit resolution @@ -2295,27 +3646,24 @@ struct ... T(n+1): (not l_n) [unit-resolution T1 ... T(n+1)]: (or l_1' ... l_m') - *) - let is_proof_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) (** Indicates whether the term is a proof by iff-true T1: p [iff-true T1]: (iff p true) - *) - let is_proof_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) (** Indicates whether the term is a proof by iff-false T1: (not p) [iff-false T1]: (iff p false) - *) - let is_proof_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_IFF_FALSE) + let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) (** Indicates whether the term is a proof by commutativity @@ -2326,9 +3674,8 @@ struct This proof object has no antecedents. Remark: if f is bool, then = is iff. - *) - let is_proof_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) (** Indicates whether the term is a proof for Tseitin-like axioms @@ -2362,9 +3709,8 @@ struct You can recover the propositional tautologies by unfolding the Boolean connectives in the axioms a small bounded number of steps (=3). - *) - let is_proof_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) (** Indicates whether the term is a proof for introduction of a name @@ -2385,9 +3731,8 @@ struct Otherwise: [def-intro]: (= n e) - *) - let is_proof_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_DEF_INTRO) + let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) (** Indicates whether the term is a proof for application of a definition @@ -2395,18 +3740,16 @@ struct [apply-def T1]: F ~ n F is 'equivalent' to n, given that T1 is a proof that n is a name for F. - *) - let is_proof_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_APPLY_DEF) + let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) (** Indicates whether the term is a proof iff-oeq T1: (iff p q) [iff~ T1]: (~ p q) - *) - let is_proof_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_IFF_OEQ) + let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) (** Indicates whether the term is a proof for a positive NNF step @@ -2432,9 +3775,8 @@ struct for NNF_POS are 'implies', 'iff', 'xor', 'ite'. NNF_NEG furthermore handles the case where negation is pushed over Boolean connectives 'and' and 'or'. - *) - let is_proof_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) (** Indicates whether the term is a proof for a negative NNF step @@ -2457,9 +3799,8 @@ struct 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'))) - *) - let is_proof_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) (** Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form. @@ -2469,9 +3810,8 @@ struct 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. - *) - let is_proof_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_NNF_STAR) + let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) (** Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form. @@ -2479,9 +3819,8 @@ struct 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. - *) - let is_proof_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_CNF_STAR) + let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) (** Indicates whether the term is a proof for a Skolemization step @@ -2492,9 +3831,8 @@ struct [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) This proof object has no antecedents. - *) - let is_proof_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_SKOLEMIZE) + let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) (** Indicates whether the term is a proof by modus ponens for equi-satisfiability. @@ -2503,9 +3841,8 @@ struct T1: p T2: (~ p q) [mp~ T1 T2]: q - *) - let is_proof_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) (** Indicates whether the term is a proof for theory lemma @@ -2520,259 +3857,74 @@ struct - 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))) + (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. - *) - let is_proof_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_PR_TH_LEMMA) - - (** - Indicates whether the term is of a relation sort. - *) - let is_Relation ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == 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. - - *) - let is_relation_store ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_STORE) - - (** - Indicates whether the term is an empty relation - *) - let is_empty_relation ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_EMPTY) - - (** - Indicates whether the term is a test for the emptiness of a relation - *) - let is_is_empty_relation ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_IS_EMPTY) - - (** - Indicates whether the term is a relational join - *) - let is_relational_join ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_JOIN) - - (** - Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. - *) - let is_relation_union ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_UNION) - - (** - Indicates whether the term is the widening of two relations - The function takes two arguments. - *) - let is_relation_widen ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_WIDEN) - - (** - Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. - *) - let is_relation_project ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - - *) - let is_relation_filter ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. - - *) - let is_relation_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - - *) - let is_relation_rename ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_RENAME) - - (** - Indicates whether the term is the complement of a relation - *) - let is_relation_complement ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - - *) - let is_relation_select ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - - *) - let is_relation_clone ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_RA_CLONE) - - (** - Indicates whether the term is of an array sort. - *) - let is_finite_domain ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) - - (** - Indicates whether the term is a less than predicate over a finite domain. - *) - let is_finite_domain_lt ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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 : expr ) appears, the higher is its - index. - - *) - let get_index ( x : expr ) = - if not (AST.is_var x) then - raise (Z3native.Exception "Term is not a bound variable.") - else - Z3native.get_index_value x#gnc x#gno + let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end -(** Integer Numerals *) -module IntNum = -struct - (** Retrieve the int value. *) - let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") +(** + Parameter sets (of Solvers, Tactics, ...) - (** Returns a string representation of the numeral. *) - let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno -end - -(** Rational Numerals *) -module RatNum = -struct - - (** The numerator of a rational numeral. *) - let get_numerator ( x : rat_num ) = - (new int_num x#gc)#cnstr_obj (Z3native.get_numerator x#gnc x#gno) - - (** The denominator of a rational numeral. *) - let get_denominator ( x : rat_num ) = - (new int_num x#gc)#cnstr_obj (Z3native.get_denominator x#gnc x#gno) - - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) - let to_decimal_string ( x : rat_num ) (precision : int) = - Z3native.get_numeral_decimal_string x#gnc x#gno precision - - (** Returns a string representation of the numeral. *) - let to_string ( x : rat_num ) = Z3native.get_numeral_string x#gnc x#gno -end - -(** Bit-vector numerals *) -module BitVecNum = -struct - (** Retrieve the int value. *) - let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") - - (** Returns a string representation of the numeral. *) - let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno -end - -(** Algebraic numbers *) -module AlgebraicNum = + A Params objects represents a configuration in the form of symbol/value pairs. +*) +module Params = struct (** - Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real + Adds a parameter setting. *) - let to_upper ( x : algebraic_num ) ( precision : int ) = - (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) - - (** - Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) - let to_lower ( x : algebraic_num ) precision = - (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) + let add_bool (p : params) (name : symbol) (value : bool) = + Z3native.params_set_bool p#gnc p#gno name#gno (int_of_lbool (if value then L_TRUE else L_FALSE)) - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) - let to_decimal_string ( x : algebraic_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string x#gnc x#gno precision + (** + Adds a parameter setting. + *) + let add_int (p : params) (name : symbol) (value : int) = + Z3native.params_set_uint p#gnc p#gno name#gno value - (** Returns a string representation of the numeral. *) - let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno + (** + Adds a parameter setting. + *) + let add_double (p : params) (name : symbol) (value : float) = + Z3native.params_set_double p#gnc p#gno name#gno value + + (** + Adds a parameter setting. + *) + let add_symbol (p : params) (name : symbol) (value : symbol) = + Z3native.params_set_symbol p#gnc p#gno name#gno value#gno + + (** + Adds a parameter setting. + *) + let add_s_bool (p : params) (name : string) (value : bool) = + add_bool p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_int (p : params) (name : string) (value : int) = + add_int p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_double (p : params) (name : string) (value : float) = + add_double p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + Adds a parameter setting. + *) + let add_s_symbol (p : params) (name : string) (value : symbol) = + add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + + (** + A string representation of the parameter set. + *) + let to_string (p : params) = Z3native.params_to_string p#gnc p#gno end -(** Constructors are used for datatype sorts *) -module Constructor = -struct - (** The number of fields of the constructor. *) - let get_num_fields ( x : constructor ) = x#get_n - - (** The function declaration of the constructor. *) - let get_constructor_decl ( x : constructor ) = x#constructor_decl - - (** The function declaration of the tester. *) - let get_tester_decl ( x : constructor ) = x#tester_decl - - (** The function declarations of the accessors *) - let get_accessor_decls ( x : constructor ) = x#accessor_decls -end - - -(** ParamDescrs describe sets of parameters.*) +(** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) module ParamDescrs = struct @@ -2917,102 +4069,100 @@ struct | None -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply x#gnc x#gno g#gno) | Some (pn) -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno) - (** Creates a solver that is implemented using the given tactic. + (** creates a solver that is implemented using the given tactic. *) let get_solver ( x : tactic ) = (new solver x#gc)#cnstr_obj (Z3native.mk_solver_from_tactic x#gnc x#gno) end - -(** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. -*) -module FuncInterp = -struct - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. - *) - module FuncEntry = - struct - (** - Return the (symbolic) value of this entry. - *) - let get_value ( x : func_entry ) = - create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) - - (** - The number of arguments of the entry. - *) - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno - - (** - The arguments of the function entry. - *) - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in - Array.init n f - - (** - A string representation of the function entry. - *) - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]]") - end - - (** - The number of entries in the function interpretation. - *) - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno - - (** - The entries in the function interpretation - *) - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in - Array.init n f - - (** - The (symbolic) `else' value of the function interpretation. - *) - let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) - - (** - The arity of the function interpretation - *) - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno - - (** - A string representation of the function interpretation. - *) - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (Array.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") -end - -(** Models. +(** Models A Model contains interpretations (assignments) of constants and functions. *) module Model = struct - + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. + *) + module FuncInterp = + struct + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. + *) + module FuncEntry = + struct + (** + Return the (symbolic) value of this entry. + *) + let get_value ( x : func_entry ) = + create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + + (** + The number of arguments of the entry. + *) + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + + (** + The arguments of the function entry. + *) + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the function entry. + *) + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]]") + end + + (** + The number of entries in the function interpretation. + *) + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + + (** + The entries in the function interpretation + *) + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + Array.init n f + + (** + The (symbolic) `else' value of the function interpretation. + *) + let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + + (** + The arity of the function interpretation + *) + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + + (** + A string representation of the function interpretation. + *) + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (Array.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + end + (** Retrieves the interpretation (the assignment) of in the model. A function declaration of zero arity An expression if the function has an interpretation in the model, null otherwise. *) @@ -3093,7 +4243,7 @@ struct 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 @@ -3120,7 +4270,6 @@ struct 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. - *) @@ -3137,8 +4286,8 @@ struct *) let sort_universe ( x : model ) ( s : sort ) = let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in - let n = (ASTVector.get_size n_univ) in - let f i = (ASTVector.get n_univ i) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in Array.init n f (** Conversion of models to strings. @@ -3174,84 +4323,85 @@ struct let to_string ( x : apply_result) = Z3native.apply_result_to_string x#gnc x#gno end -(** Objects that track statistical information about solvers. *) -module Statistics = -struct - - (** - Statistical data is organized into pairs of [Key, Entry], where every - Entry is either a DoubleEntry or a UIntEntry - *) - module Entry = - struct - (** The key of the entry. *) - let get_key (x : statistics_entry) = x#key - - (** The int-value of the entry. *) - let get_int (x : statistics_entry) = x#int - - (** The float-value of the entry. *) - let get_float (x : statistics_entry) = x#float - - (** True if the entry is uint-valued. *) - let is_int (x : statistics_entry) = x#is_int - - (** True if the entry is double-valued. *) - let is_float (x : statistics_entry) = x#is_float - - (** The string representation of the the entry's value. *) - let to_string_value (x : statistics_entry) = - if (is_int x) then - string_of_int (get_int x) - else if (is_float x) then - string_of_float (get_float x) - else - raise (Z3native.Exception "Unknown statistical entry type") - - (** The string representation of the entry (key and value) *) - let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) - end - - (** A string representation of the statistical data. *) - let to_string ( x : statistics ) = Z3native.stats_to_string x#gnc x#gno - - (** The number of statistical data. *) - let get_size ( x : statistics ) = Z3native.stats_size x#gnc x#gno - - (** The data entries. *) - let get_entries ( x : statistics ) = - let n = (get_size x ) in - let f i = ( - let k = Z3native.stats_get_key x#gnc x#gno i in - if (lbool_of_int (Z3native.stats_is_uint x#gnc x#gno i)) == L_TRUE then - ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) - else - ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) - ) in - Array.init n f - - (** - The statistical counters. - *) - let get_keys ( x : statistics ) = - let n = (get_size x) in - let f i = (Z3native.stats_get_key x#gnc x#gno i) in - Array.init n f - - (** - The value of a particular statistical counter. - *) - let get ( x : statistics ) ( key : string ) = - let f p c = (if (Entry.get_key c) = key then (Some c) else p) in - Array.fold_left f None (get_entries x) - -end - (** Solvers *) module Solver = struct type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + (** Objects that track statistical information about solvers. *) + module Statistics = + struct + + (** + Statistical data is organized into pairs of [Key, Entry], where every + Entry is either a DoubleEntry or a UIntEntry + *) + module Entry = + struct + (** The key of the entry. *) + let get_key (x : statistics_entry) = x#key + + (** The int-value of the entry. *) + let get_int (x : statistics_entry) = x#int + + (** The float-value of the entry. *) + let get_float (x : statistics_entry) = x#float + + (** True if the entry is uint-valued. *) + let is_int (x : statistics_entry) = x#is_int + + (** True if the entry is double-valued. *) + let is_float (x : statistics_entry) = x#is_float + + (** The string representation of the the entry's value. *) + let to_string_value (x : statistics_entry) = + if (is_int x) then + string_of_int (get_int x) + else if (is_float x) then + string_of_float (get_float x) + else + raise (Z3native.Exception "Unknown statistical entry type") + + (** The string representation of the entry (key and value) *) + let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) + end + + (** A string representation of the statistical data. *) + let to_string ( x : statistics ) = Z3native.stats_to_string x#gnc x#gno + + (** The number of statistical data. *) + let get_size ( x : statistics ) = Z3native.stats_size x#gnc x#gno + + (** The data entries. *) + let get_entries ( x : statistics ) = + let n = (get_size x ) in + let f i = ( + let k = Z3native.stats_get_key x#gnc x#gno i in + if (lbool_of_int (Z3native.stats_is_uint x#gnc x#gno i)) == L_TRUE then + ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) + else + ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) + ) in + Array.init n f + + (** + The statistical counters. + *) + let get_keys ( x : statistics ) = + let n = (get_size x) in + let f i = (Z3native.stats_get_key x#gnc x#gno i) in + Array.init n f + + (** + The value of a particular statistical counter. + *) + let get ( x : statistics ) ( key : string ) = + let f p c = (if (Entry.get_key c) = key then (Some c) else p) in + Array.fold_left f None (get_entries x) + + end + + (** A string that describes all available solver parameters. *) @@ -3284,14 +4434,14 @@ struct (** Backtracks backtracking points. - Note that an exception is thrown if is not smaller than NumScopes + Note that an exception is thrown if is not smaller than NumScopes *) let pop ( x : solver ) ( n : int ) = Z3native.solver_pop x#gnc x#gno n (** Resets the Solver. - This removes all assertions from the solver. + This removes all assertions from the solver. *) let reset ( x : solver ) = Z3native.solver_reset x#gnc x#gno @@ -3307,7 +4457,7 @@ struct *) let get_num_assertions ( x : solver ) = let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in - (ASTVector.get_size a) + (AST.ASTVector.get_size a) (** @@ -3315,8 +4465,8 @@ struct *) let get_assertions ( x : solver ) = let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in - let n = (ASTVector.get_size a) in - let f i = ((new bool_expr x#gc)#cnstr_obj (ASTVector.get a i)#gno) in + let n = (AST.ASTVector.get_size a) in + let f i = ((new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get a i)#gno) in Array.init n f (** @@ -3325,7 +4475,6 @@ struct - *) let check ( x : solver ) ( assumptions : bool_expr array option) = let r = @@ -3343,7 +4492,6 @@ struct The result is None if Check was not invoked before, if its results was not SATISFIABLE, or if model production is not enabled. - *) let get_model ( x : solver ) = let q = Z3native.solver_get_model x#gnc x#gno in @@ -3357,7 +4505,6 @@ struct The result is null if Check was not invoked before, if its results was not UNSATISFIABLE, or if proof production is disabled. - *) let get_proof ( x : solver ) = let q = Z3native.solver_get_proof x#gnc x#gno in @@ -3372,12 +4519,11 @@ struct 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. - *) let get_unsat_core ( x : solver ) = let cn = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_unsat_core x#gnc x#gno) in - let n = (ASTVector.get_size cn) in - let f i = (ASTVector.get cn i) in + let n = (AST.ASTVector.get_size cn) in + let f i = (AST.ASTVector.get cn i) in Array.init n f (** @@ -3418,3312 +4564,936 @@ struct end -(** The main interaction with Z3 happens via the Context module *) -module Context = -struct +(* STUFF FROM THE CONTEXT *) - (* SYMBOLS *) - - (** - Creates a new symbol using an integer. - - Not all integers can be passed to this function. - The legal range of unsigned integers is 0 to 2^30-1. - *) - let mk_symbol_int ( ctx : context ) i = - (new int_symbol ctx)#cnstr_int i - - (** Creates a new symbol using a string. *) - let mk_symbol_string ( ctx : context ) s = - (new string_symbol ctx)#cnstr_string s - - (** - Create an array of symbols. - *) - let mk_symbols_int ( ctx : context ) names = - let f elem = mk_symbol_int ( ctx : context ) elem in - (Array.map f names) - - (** - Create an array of symbols. - *) - let mk_symbols_string ( ctx : context ) names = - let f elem = mk_symbol_string ( ctx : context ) elem in - (Array.map f names) - - - (* SORTS *) - - (** - Create a new Boolean sort. - *) - let mk_bool_sort ( ctx : context ) = - (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort ctx#gno) - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted_sort ( ctx : context ) (s : symbol) = - (new uninterpreted_sort ctx)#cnstr_s s - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted_sort_s ( ctx : context ) (s : string) = - mk_uninterpreted_sort ctx ((mk_symbol_string ( ctx : context ) s) :> symbol) - - (** - Create a new integer sort. - *) - let mk_int_sort ( ctx : context ) = - (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort ctx#gno) - - (** - Create a real sort. - *) - let mk_real_sort ( ctx : context ) = - (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort ctx#gno) - - (** - Create a new bit-vector sort. - *) - let mk_bitvec_sort ( ctx : context ) size = - (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort ctx#gno size) - - (** - Create a new array sort. - *) - let mk_array_sort ( ctx : context ) domain range = - (new array_sort ctx)#cnstr_dr domain range - - (** - Create a new tuple sort. - *) - let mk_tuple_sort ( ctx : context ) name field_names field_sorts = - (new tuple_sort ctx)#cnstr_siss name (Array.length field_names) field_names field_sorts - - (** - Create a new enumeration sort. - *) - let mk_enum_sort ( ctx : context ) name enum_names = - (new enum_sort ctx)#cnstr_ss name enum_names - - (** - Create a new enumeration sort. - *) - let mk_enum_sort_s ( ctx : context ) name enum_names = - (new enum_sort ctx)#cnstr_ss - ((mk_symbol_string ( ctx : context ) name) :> symbol) - (let f e = (e :> symbol) in - (Array.map f (mk_symbols_string ( ctx : context ) enum_names)) - ) - - (** - Create a new list sort. - *) - let mk_list_sort ( ctx : context ) (name : symbol) elem_sort = - (new list_sort ctx)#cnstr_ss name elem_sort - - (** - Create a new list sort. - *) - let mk_list_sort_s ( ctx : context ) (name : string) elem_sort = - mk_list_sort ctx ((mk_symbol_string ctx name) :> symbol) elem_sort - - - (** - Create a new finite domain sort. - *) - let mk_finite_domain_sort ( ctx : context ) ( name : symbol ) size = - (new finite_domain_sort ctx)#cnstr_si name size - - (** - Create a new finite domain sort. - *) - let mk_finite_domain_sort_s ( ctx : context ) ( name : string ) size = - (new finite_domain_sort ctx)#cnstr_si ((mk_symbol_string ctx name) :> symbol) size - - (* DATATYPES *) - (** - Create a datatype constructor. - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - *) - let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = - (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs - - - (** - Create a datatype constructor. - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = - mk_constructor ctx ((mk_symbol_string ctx name) :> symbol) recognizer field_names sorts sort_refs - - - (** - Create a new datatype sort. - *) - let mk_datatype_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = - (new datatype_sort ctx)#cnstr_sc name constructors - - (** - Create a new datatype sort. - *) - let mk_datatype_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = - mk_datatype_sort ctx ((mk_symbol_string ctx name) :> symbol) constructors - - (** - Create mutually recursive datatypes. - @param names names of datatype sorts - @param c list of constructors, one list per sort. - *) - let mk_datatype_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = - let n = (Array.length names) in - let f e = ( (new constructor_list ctx)#cnstr_ca e ) in - let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes ctx#gno n (symbolaton names) (constructor_listaton cla)) in - let g e = ( (new datatype_sort ctx)#cnstr_obj e) in - (Array.map g r) - - (** Create mutually recursive data-types. *) - let mk_datatype_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = - mk_datatype_sorts ctx - ( - let f e = ((mk_symbol_string ctx e) :> symbol) in - Array.map f names - ) - c - -(** - - -(* FUNCTION DECLARATIONS *) -(** - Creates a new function declaration. -*) - public Func_Decl MkFunc_Decl(Symbol name, Sort[] domain, Sort range) - { - - - - - - CheckContextMatch(name); - CheckContextMatch(domain); - CheckContextMatch(range); - return new Func_Decl(this, name, domain, range); - } - -(** - Creates a new function declaration. -*) - public Func_Decl MkFunc_Decl(Symbol name, Sort domain, Sort range) - { - - - - - - CheckContextMatch(name); - CheckContextMatch(domain); - CheckContextMatch(range); - Sort[] q = new Sort[] { domain }; - return new Func_Decl(this, name, q, range); - } - -(** - Creates a new function declaration. -*) - public Func_Decl MkFunc_Decl(string name, Sort[] domain, Sort range) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(range); - return new Func_Decl(this, MkSymbol(name), domain, range); - } - -(** - Creates a new function declaration. -*) - public Func_Decl MkFunc_Decl(string name, Sort domain, Sort range) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(range); - Sort[] q = new Sort[] { domain }; - return new Func_Decl(this, MkSymbol(name), q, range); - } - -(** - Creates a fresh function declaration with a name prefixed with . -*) - - - let mk_Fresh_Func_Decl(string prefix, Sort[] domain, Sort range) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(range); - return new Func_Decl(this, prefix, domain, range); - } - -(** - Creates a new constant function declaration. -*) - let mk_Const_Decl(Symbol name, Sort range) - { - - - - - CheckContextMatch(name); - CheckContextMatch(range); - return new Func_Decl(this, name, null, range); - } - -(** - Creates a new constant function declaration. -*) - let mk_Const_Decl(string name, Sort range) - { - - - - CheckContextMatch(range); - return new Func_Decl(this, MkSymbol(name), null, range); - } - -(** - Creates a fresh constant function declaration with a name prefixed with . -*) - - - let mk_Fresh_ConstDecl(string prefix, Sort range) - { - - - - CheckContextMatch(range); - return new Func_Decl(this, prefix, null, range); - } - - -(* BOUND VARIABLES *) -(** - Creates a new bound variable. -*) - @param index The de-Bruijn index of the variable - @param ty The sort of the variable - public Expr MkBound(uint index, Sort ty) - { - - - - return Expr.Create(this, Z3native.mk_bound(nCtx, index, ty.x#gno)); - } - - -(* QUANTIFIER PATTERNS *) -(** - Create a quantifier pattern. -*) - public Pattern MkPattern(params 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, Z3native.mk_pattern(nCtx, (uint)terms.Length, termsNative)); - } - - -(* CONSTANTS *) -(** - Creates a new Constant of sort and named . -*) - public Expr MkConst(Symbol name, Sort range) - { - - - - - CheckContextMatch(name); - CheckContextMatch(range); - - return Expr.Create(this, Z3native.mk_const(nCtx, name.x#gno, range.x#gno)); - } - -(** - 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 . -*) - let mk_Fresh_Const(string prefix, Sort range) - { - - - - CheckContextMatch(range); - return Expr.Create(this, Z3native.mk_fresh_const(nCtx, prefix, range.x#gno)); - } - -(** - Creates a fresh constant from the Func_Decl . -*) - @param f A decl of a 0-arity function - public Expr MkConst(Func_Decl f) - { - - - - return MkApp(f); - } - -(** - Create a Boolean constant. -*) - let mk_Bool_Const(Symbol name) - { - - - - return (BoolExpr)MkConst(name, BoolSort); - } - -(** - Create a Boolean constant. -*) - let mk_Bool_Const(string name) - { - - - return (BoolExpr)MkConst(MkSymbol(name), BoolSort); - } - -(** - Creates an integer constant. -*) - let mk_Int_Const(Symbol name) - { - - - - return (IntExpr)MkConst(name, IntSort); - } - -(** - Creates an integer constant. -*) - let mk_Int_Const(string name) - { - - - - return (IntExpr)MkConst(name, IntSort); - } - -(** - Creates a real constant. -*) - let mk_Real_Const(Symbol name) - { - - - - return (RealExpr)MkConst(name, RealSort); - } - -(** - Creates a real constant. -*) - let mk_Real_Const(string name) - { - - - return (RealExpr)MkConst(name, RealSort); - } - -(** - Creates a bit-vector constant. -*) - let mk_B_VConst(Symbol name, uint size) - { - - - - return (BitVecExpr)MkConst(name, MkBitVecSort(size)); - } - -(** - Creates a bit-vector constant. -*) - let mk_B_VConst(string name, uint size) - { - - - return (BitVecExpr)MkConst(name, MkBitVecSort(size)); - } - - -(* TERMS *) -(** - Create a new function application. -*) - public Expr MkApp(Func_Decl f, params Expr[] args) - { - - - - - CheckContextMatch(f); - CheckContextMatch(args); - return Expr.Create(this, f, args); - } - -(* PROPOSITIONAL *) -(** - The true Term. -*) - public BoolExpr MkTrue ( ctx : context ) = - { - - - return new BoolExpr(this, Z3native.mk_true(nCtx)); - } - -(** - The false Term. -*) - public BoolExpr MkFalse ( ctx : context ) = - { - - - return new BoolExpr(this, Z3native.mk_false(nCtx)); - } - -(** - Creates a Boolean value. -*) - public BoolExpr MkBool(bool value) - { - - - return value ? MkTrue ( ctx : context ) = : MkFalse ( ctx : context ) =; - } - -(** - Creates the equality = . -*) - public BoolExpr MkEq(Expr x, Expr y) - { - - - - - CheckContextMatch(x); - CheckContextMatch(y); - return new BoolExpr(this, Z3native.mk_eq(nCtx, x.x#gno, y.x#gno)); - } - -(** - Creates a distinct term. -*) - public BoolExpr MkDistinct(params Expr[] args) - { - - - - - - CheckContextMatch(args); - return new BoolExpr(this, Z3native.mk_distinct(nCtx, (uint)args.Length, AST.ArrayToNative(args))); - } - -(** - Mk an expression representing not(a). -*) - public BoolExpr MkNot(BoolExpr a) - { - - - - CheckContextMatch(a); - return new BoolExpr(this, Z3native.mk_not(nCtx, a.x#gno)); - } - -(** - Create an expression representing an if-then-else: ite(t1, t2, t3). -*) - @param t1 An expression with Boolean sort - @param t2 An expression - @param t3 An expression with the same sort as - let mk_I_TE(BoolExpr t1, Expr t2, Expr t3) - { - - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - CheckContextMatch(t3); - return Expr.Create(this, Z3native.mk_ite(nCtx, t1.x#gno, t2.x#gno, t3.x#gno)); - } - -(** - Create an expression representing t1 iff t2. -*) - public BoolExpr MkIff(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_iff(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 -> t2. -*) - public BoolExpr MkImplies(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_implies(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 xor t2. -*) - public BoolExpr MkXor(BoolExpr t1, BoolExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_xor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t[0] and t[1] and .... -*) - public BoolExpr MkAnd(params BoolExpr[] t) - { - - - - - CheckContextMatch(t); - return new BoolExpr(this, Z3native.mk_and(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - -(** - Create an expression representing t[0] or t[1] or .... -*) - public BoolExpr MkOr(params BoolExpr[] t) - { - - - - - CheckContextMatch(t); - return new BoolExpr(this, Z3native.mk_or(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - - -(* ARITHMETIC *) -(** - Create an expression representing t[0] + t[1] + .... -*) - public ArithExpr MkAdd(params ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Z3native.mk_add(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - -(** - Create an expression representing t[0] * t[1] * .... -*) - public ArithExpr MkMul(params ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Z3native.mk_mul(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - -(** - Create an expression representing t[0] - t[1] - .... -*) - public ArithExpr MkSub(params ArithExpr[] t) - { - - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Z3native.mk_sub(nCtx, (uint)t.Length, AST.ArrayToNative(t))); - } - -(** - Create an expression representing -t. -*) - let mk_Unary_Minus(ArithExpr t) - { - - - - CheckContextMatch(t); - return (ArithExpr)Expr.Create(this, Z3native.mk_unary_minus(nCtx, t.x#gno)); - } - -(** - Create an expression representing t1 / t2. -*) - public ArithExpr MkDiv(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return (ArithExpr)Expr.Create(this, Z3native.mk_div(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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, Z3native.mk_mod(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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, Z3native.mk_rem(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 ^ t2. -*) - public ArithExpr MkPower(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return (ArithExpr)Expr.Create(this, Z3native.mk_power(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 < t2 -*) - public BoolExpr MkLt(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_lt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 <= t2 -*) - public BoolExpr MkLe(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_le(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 > t2 -*) - public BoolExpr MkGt(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_gt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an expression representing t1 >= t2 -*) - public BoolExpr MkGe(ArithExpr t1, ArithExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_ge(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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, Z3native.mk_int2real(nCtx, t.x#gno)); - } - -(** - 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, Z3native.mk_real2int(nCtx, t.x#gno)); - } - -(** - Creates an expression that checks whether a real number is an integer. -*) - let mk_Is_Integer(RealExpr t) - { - - - - CheckContextMatch(t); - return new BoolExpr(this, Z3native.mk_is_int(nCtx, t.x#gno)); - } - - -(* BIT-VECTORS *) -(** - Bitwise negation. -*) - The argument must have a bit-vector sort. - let mk_B_VNot(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_bvnot(nCtx, t.x#gno)); - } - -(** - Take conjunction of bits in a vector, return vector of length 1. -*) - The argument must have a bit-vector sort. - let mk_B_VRedAND(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_bvredand(nCtx, t.x#gno)); - } - -(** - Take disjunction of bits in a vector, return vector of length 1. -*) - The argument must have a bit-vector sort. - let mk_B_VRedOR(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_bvredor(nCtx, t.x#gno)); - } - -(** - Bitwise conjunction. -*) - The arguments must have a bit-vector sort. - let mk_B_VAND(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvand(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise disjunction. -*) - The arguments must have a bit-vector sort. - let mk_B_VOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise XOR. -*) - The arguments must have a bit-vector sort. - let mk_B_VXOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvxor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise NAND. -*) - The arguments must have a bit-vector sort. - let mk_B_VNAND(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvnand(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise NOR. -*) - The arguments must have a bit-vector sort. - let mk_B_VNOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvnor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bitwise XNOR. -*) - The arguments must have a bit-vector sort. - let mk_B_VXNOR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvxnor(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Standard two's complement unary minus. -*) - The arguments must have a bit-vector sort. - let mk_B_VNeg(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_bvneg(nCtx, t.x#gno)); - } - -(** - Two's complement addition. -*) - The arguments must have the same bit-vector sort. - let mk_B_VAdd(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvadd(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement subtraction. -*) - The arguments must have the same bit-vector sort. - let mk_B_VSub(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvsub(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement multiplication. -*) - The arguments must have the same bit-vector sort. - let mk_B_VMul(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvmul(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VUDiv(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvudiv(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VSDiv(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvsdiv(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VURem(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvurem(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VSRem(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvsrem(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VSMod(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvsmod(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Unsigned less-than -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VULT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvult(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement signed less-than -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VSLT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvslt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Unsigned less-than or equal to. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VULE(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvule(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement signed less-than or equal to. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VSLE(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsle(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Unsigned greater than or equal to. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VUGE(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvuge(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement signed greater than or equal to. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VSGE(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsge(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Unsigned greater-than. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VUGT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvugt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Two's complement signed greater-than. -*) - - The arguments must have the same bit-vector sort. - - let mk_B_VSGT(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsgt(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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, Z3native.mk_concat(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Bit-vector extraction. -*) - - Extract the bits down to from a bitvector of - size m to yield a new bitvector of size n, where - n = high - low + 1. - The argument must have a bit-vector sort. - - public BitVecExpr MkExtract(uint high, uint low, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_extract(nCtx, high, low, t.x#gno)); - } - -(** - 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. - - let mk_Sign_Ext(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_sign_ext(nCtx, i, t.x#gno)); - } - -(** - 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. - - let mk_Zero_Ext(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_zero_ext(nCtx, i, t.x#gno)); - } - -(** - Bit-vector repetition. -*) - - The argument must have a bit-vector sort. - - public BitVecExpr MkRepeat(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_repeat(nCtx, i, t.x#gno)); - } - -(** - 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. - - let mk_B_VSHL(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvshl(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VLSHR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvlshr(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - 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. - - let mk_B_VASHR(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_bvashr(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Rotate Left. -*) - - Rotate bits of \c t to the left \c i times. - The argument must have a bit-vector sort. - - let mk_B_VRotateLeft(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_rotate_left(nCtx, i, t.x#gno)); - } - -(** - Rotate Right. -*) - - Rotate bits of \c t to the right \c i times. - The argument must have a bit-vector sort. - - let mk_B_VRotateRight(uint i, BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_rotate_right(nCtx, i, t.x#gno)); - } - -(** - Rotate Left. -*) - - Rotate bits of to the left times. - The arguments must have the same bit-vector sort. - - let mk_B_VRotateLeft(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_ext_rotate_left(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Rotate Right. -*) - - Rotate bits of to the right times. - The arguments must have the same bit-vector sort. - - let mk_B_VRotateRight(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BitVecExpr(this, Z3native.mk_ext_rotate_right(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create an bit bit-vector from the integer argument . -*) - - NB. This function is essentially treated as uninterpreted. - So you cannot expect Z3 to precisely reflect the semantics of this function - when solving constraints with this function. - - The argument must be of integer sort. - - public BitVecExpr MkInt2BV(uint n, IntExpr t) - { - - - - CheckContextMatch(t); - return new BitVecExpr(this, Z3native.mk_int2bv(nCtx, n, t.x#gno)); - } - -(** - 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. - - let mk_B_V2Int(BitVecExpr t, bool signed) - { - - - - CheckContextMatch(t); - return new IntExpr(this, Z3native.mk_bv2int(nCtx, t.x#gno, (signed) ? 1 : 0)); - } - -(** - Create a predicate that checks that the bit-wise addition does not overflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VAddNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvadd_no_overflow(nCtx, t1.x#gno, t2.x#gno, (isSigned) ? 1 : 0)); - } - -(** - Create a predicate that checks that the bit-wise addition does not underflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VAddNoUnderflow(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvadd_no_underflow(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create a predicate that checks that the bit-wise subtraction does not overflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VSubNoOverflow(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsub_no_overflow(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create a predicate that checks that the bit-wise subtraction does not underflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VSubNoUnderflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsub_no_underflow(nCtx, t1.x#gno, t2.x#gno, (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. - - let mk_B_VSDivNoOverflow(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvsdiv_no_overflow(nCtx, t1.x#gno, t2.x#gno)); - } - -(** - Create a predicate that checks that the bit-wise negation does not overflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VNegNoOverflow(BitVecExpr t) - { - - - - CheckContextMatch(t); - return new BoolExpr(this, Z3native.mk_bvneg_no_overflow(nCtx, t.x#gno)); - } - -(** - Create a predicate that checks that the bit-wise multiplication does not overflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VMulNoOverflow(BitVecExpr t1, BitVecExpr t2, bool isSigned) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvmul_no_overflow(nCtx, t1.x#gno, t2.x#gno, (isSigned) ? 1 : 0)); - } - -(** - Create a predicate that checks that the bit-wise multiplication does not underflow. -*) - - The arguments must be of bit-vector sort. - - let mk_B_VMulNoUnderflow(BitVecExpr t1, BitVecExpr t2) - { - - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new BoolExpr(this, Z3native.mk_bvmul_no_underflow(nCtx, t1.x#gno, t2.x#gno)); - } - - -(* ARRAYS *) -(** - Create an array constant. -*) - let mk_Array_Const(Symbol name, Sort domain, Sort range) - { - - - - - - return (ArrayExpr)MkConst(name, MkArraySort(domain, range)); - } - -(** - Create an array constant. -*) - let mk_Array_Const(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, Z3native.mk_select(nCtx, a.x#gno, i.x#gno)); - } - -(** - 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, Z3native.mk_store(nCtx, a.x#gno, i.x#gno, v.x#gno)); - } - -(** - Create a constant array. -*) - - The resulting term is an array, such that a selecton an arbitrary index - produces the value v. - - - - let mk_Const_Array(Sort domain, Expr v) - { - - - - - CheckContextMatch(domain); - CheckContextMatch(v); - return new ArrayExpr(this, Z3native.mk_const_array(nCtx, domain.x#gno, v.x#gno)); - } - -(** - 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(Func_Decl f, params ArrayExpr[] args) - { - - - - - CheckContextMatch(f); - CheckContextMatch(args); - return (ArrayExpr)Expr.Create(this, Z3native.mk_map(nCtx, f.x#gno, 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. - - let mk_Term_Array(ArrayExpr array) - { - - - - CheckContextMatch(array); - return Expr.Create(this, Z3native.mk_array_default(nCtx, array.x#gno)); - } - - -(* SETS *) -(** - Create a set type. -*) - let mk_Set_Sort(Sort ty) - { - - - - CheckContextMatch(ty); - return new SetSort(this, ty); - } - -(** - Create an empty set. -*) - let mk_Empty_Set(Sort domain) - { - - - - CheckContextMatch(domain); - return Expr.Create(this, Z3native.mk_empty_set(nCtx, domain.x#gno)); - } - -(** - Create the full set. -*) - let mk_Full_Set(Sort domain) - { - - - - CheckContextMatch(domain); - return Expr.Create(this, Z3native.mk_full_set(nCtx, domain.x#gno)); - } - -(** - Add an element to the set. -*) - let mk_Set_Add(Expr set, Expr element) - { - - - - - CheckContextMatch(set); - CheckContextMatch(element); - return Expr.Create(this, Z3native.mk_set_add(nCtx, set.x#gno, element.x#gno)); - } - - -(** - Remove an element from a set. -*) - let mk_Set_Del(Expr set, Expr element) - { - - - - - CheckContextMatch(set); - CheckContextMatch(element); - return Expr.Create(this, Z3native.mk_set_del(nCtx, set.x#gno, element.x#gno)); - } - -(** - Take the union of a list of sets. -*) - let mk_Set_Union(params Expr[] args) - { - - - - CheckContextMatch(args); - return Expr.Create(this, Z3native.mk_set_union(nCtx, (uint)args.Length, AST.ArrayToNative(args))); - } - -(** - Take the intersection of a list of sets. -*) - let mk_Set_Intersection(params Expr[] args) - { - - - - - CheckContextMatch(args); - return Expr.Create(this, Z3native.mk_set_intersect(nCtx, (uint)args.Length, AST.ArrayToNative(args))); - } - -(** - Take the difference between two sets. -*) - let mk_Set_Difference(Expr arg1, Expr arg2) - { - - - - - CheckContextMatch(arg1); - CheckContextMatch(arg2); - return Expr.Create(this, Z3native.mk_set_difference(nCtx, arg1.x#gno, arg2.x#gno)); - } - -(** - Take the complement of a set. -*) - let mk_Set_Complement(Expr arg) - { - - - - CheckContextMatch(arg); - return Expr.Create(this, Z3native.mk_set_complement(nCtx, arg.x#gno)); - } - -(** - Check for set membership. -*) - let mk_Set_Membership(Expr elem, Expr set) - { - - - - - CheckContextMatch(elem); - CheckContextMatch(set); - return Expr.Create(this, Z3native.mk_set_member(nCtx, elem.x#gno, set.x#gno)); - } - -(** - Check for subsetness of sets. -*) - let mk_Set_Subset(Expr arg1, Expr arg2) - { - - - - - CheckContextMatch(arg1); - CheckContextMatch(arg2); - return Expr.Create(this, Z3native.mk_set_subset(nCtx, arg1.x#gno, arg2.x#gno)); - } - +(** (* NUMERALS *) (* GENERAL NUMERALS *) (** - Create a Term of a given sort. + Create a Term of a given sort. *) - @param v 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]*. - @param ty 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) - { + @param v 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]*. + @param ty 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, Z3native.mk_numeral(nCtx, v, ty.x#gno)); - } + create_expr ctx (Z3native.mk_numeral ctx#gno v, ty#gno) (** - 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. + 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. *) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(int v, Sort ty) - { + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(int v, Sort ty) - - - CheckContextMatch(ty); - return Expr.Create(this, Z3native.mk_int(nCtx, v, ty.x#gno)); - } + create_expr ctx (Z3native.mk_int ctx#gno v, ty#gno) (** - 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. + 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. *) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(uint v, Sort ty) - { + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(uint v, Sort ty) - - - CheckContextMatch(ty); - return Expr.Create(this, Z3native.mk_unsigned_int(nCtx, v, ty.x#gno)); - } + create_expr ctx (Z3native.mk_unsigned_int ctx#gno v, ty#gno) (** - 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. + 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. *) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(long v, Sort ty) - { + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(long v, Sort ty) - - - CheckContextMatch(ty); - return Expr.Create(this, Z3native.mk_int64(nCtx, v, ty.x#gno)); - } + create_expr ctx (Z3native.mk_int64 ctx#gno v, ty#gno) (** - 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. + 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. *) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(ulong v, Sort ty) - { + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + public Expr MkNumeral(ulong v, Sort ty) - - - CheckContextMatch(ty); - return Expr.Create(this, Z3native.mk_unsigned_int64(nCtx, v, ty.x#gno)); - } - + create_expr ctx (Z3native.mk_unsigned_int64 ctx#gno v, ty#gno) (* REALS *) (** - Create a real from a fraction. + Create a real from a fraction. *) - @param num numerator of rational. - @param den 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"); + @param num numerator of rational. + @param den 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, Z3native.mk_real(nCtx, num, den)); - } + new RatNum(this, Z3native.mk_real ctx#gno num, den) (** - Create a real numeral. + Create a real numeral. *) - @param v A string representing the Term value in decimal notation. - @return A Term with value and sort Real - public RatNum MkReal(string v) - { + @param v 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, Z3native.mk_numeral(nCtx, v, RealSort.x#gno)); - } + new RatNum(this, Z3native.mk_numeral ctx#gno v, RealSort#gno) (** - Create a real numeral. + Create a real numeral. *) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(int v) - { + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(int v) - - return new RatNum(this, Z3native.mk_int(nCtx, v, RealSort.x#gno)); - } + new RatNum(this, Z3native.mk_int ctx#gno v, RealSort#gno) (** - Create a real numeral. + Create a real numeral. *) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(uint v) - { + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(uint v) - - return new RatNum(this, Z3native.mk_unsigned_int(nCtx, v, RealSort.x#gno)); - } + new RatNum(this, Z3native.mk_unsigned_int ctx#gno v, RealSort#gno) (** - Create a real numeral. + Create a real numeral. *) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(long v) - { + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(long v) - - return new RatNum(this, Z3native.mk_int64(nCtx, v, RealSort.x#gno)); - } + new RatNum(this, Z3native.mk_int64 ctx#gno v, RealSort#gno) (** - Create a real numeral. + Create a real numeral. *) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(ulong v) - { + @param v value of the numeral. + @return A Term with value and sort Real + public RatNum MkReal(ulong v) - - return new RatNum(this, Z3native.mk_unsigned_int64(nCtx, v, RealSort.x#gno)); - } - + new RatNum(this, Z3native.mk_unsigned_int64 ctx#gno v, RealSort#gno) (* INTEGERS *) (** - Create an integer numeral. + Create an integer numeral. *) - @param v A string representing the Term value in decimal notation. - public IntNum MkInt(string v) - { + @param v A string representing the Term value in decimal notation. + public IntNum MkInt(string v) - - return new IntNum(this, Z3native.mk_numeral(nCtx, v, IntSort.x#gno)); - } + new IntNum(this, Z3native.mk_numeral ctx#gno v, IntSort#gno) (** - Create an integer numeral. + Create an integer numeral. *) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(int v) - { + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(int v) - - return new IntNum(this, Z3native.mk_int(nCtx, v, IntSort.x#gno)); - } + new IntNum(this, Z3native.mk_int ctx#gno v, IntSort#gno) (** - Create an integer numeral. + Create an integer numeral. *) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(uint v) - { + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(uint v) - - return new IntNum(this, Z3native.mk_unsigned_int(nCtx, v, IntSort.x#gno)); - } + new IntNum(this, Z3native.mk_unsigned_int ctx#gno v, IntSort#gno) (** - Create an integer numeral. + Create an integer numeral. *) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(long v) - { + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(long v) - - return new IntNum(this, Z3native.mk_int64(nCtx, v, IntSort.x#gno)); - } + new IntNum(this, Z3native.mk_int64 ctx#gno v, IntSort#gno) (** - Create an integer numeral. + Create an integer numeral. *) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(ulong v) - { + @param v value of the numeral. + @return A Term with value and sort Integer + public IntNum MkInt(ulong v) - - return new IntNum(this, Z3native.mk_unsigned_int64(nCtx, v, IntSort.x#gno)); - } - + new IntNum(this, Z3native.mk_unsigned_int64 ctx#gno v, IntSort#gno) (* BIT-VECTORS *) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v A string representing the value in decimal notation. - @param size the size of the bit-vector - let mk_B_V(string v, uint size) - { + @param v A string representing the value in decimal notation. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) string v, uint size) - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } + (BitVecNum)MkNumeral(v, MkBitVecSort(size) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_B_V(int v, uint size) - { + @param v value of the numeral. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) int v, uint size) - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } + (BitVecNum)MkNumeral(v, MkBitVecSort(size) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_B_V(uint v, uint size) - { + @param v value of the numeral. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) uint v, uint size) - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } + (BitVecNum)MkNumeral(v, MkBitVecSort(size) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_B_V(long v, uint size) - { + @param v value of the numeral. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) long v, uint size) - - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } + (BitVecNum)MkNumeral(v, MkBitVecSort(size) (** - Create a bit-vector numeral. + Create a bit-vector numeral. *) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_B_V(ulong v, uint size) - { + @param v value of the numeral. + @param size the size of the bit-vector + let mk_bv_ ( ctx : context ) ulong v, uint size) + (BitVecNum)MkNumeral(v, MkBitVecSort(size) - return (BitVecNum)MkNumeral(v, MkBitVecSort(size)); - } - - - // Numerals + // Numerals (* QUANTIFIERS *) (** - Create a universal Quantifier. + 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. *) - - 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. - - @param sorts the sorts of the bound variables. - @param names names of the bound variables - @param body the body of the quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param patterns array containing the patterns created using MkPattern. - @param noPatterns array containing the anti-patterns created using MkPattern. - @param quantifierID optional symbol to track quantifier. - @param skolemID optional symbol to track skolem constants. - public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { - - - - - - - - - - - - return new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + @param sorts the sorts of the bound variables. + @param names names of the bound variables + @param body the body of the quantifier. + @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. + @param patterns array containing the patterns created using MkPattern. + @param noPatterns array containing the anti-patterns created using MkPattern. + @param quantifierID optional symbol to track quantifier. + @param skolemID optional symbol to track skolem constants. + public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create a universal Quantifier. + Create a universal Quantifier. *) - public Quantifier MkForall(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { + public Quantifier MkForall(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - - - - - - return new Quantifier(this, true, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + new Quantifier(this, true, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create an existential Quantifier. + Create an existential Quantifier. *) - - public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { + + public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - - - - - - - - - return new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create an existential Quantifier. + Create an existential Quantifier. *) - public Quantifier MkExists(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { - - - - - - - return new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + public Quantifier MkExists(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create a Quantifier. + Create a Quantifier. *) - public Quantifier MkQuantifier(bool universal, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { - - - - - - - - - - - - if (universal) - return MkForall(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - return MkExists(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - } + public Quantifier MkQuantifier(bool universal, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + if (universal) + MkForall(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); + else + MkExists(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); (** - Create a Quantifier. + Create a Quantifier. *) - public Quantifier MkQuantifier(bool universal, Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - { + public Quantifier MkQuantifier(bool universal, Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) + if (universal) + MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); + else + MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - - - - - - if (universal) - return MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - return MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - } - - - - // Expr + // Expr (* OPTIONS *) (** - Selects the format used for pretty-printing expressions. + 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. *) - - 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 Z3_ast_print_mode PrintMode - { - set { Z3native.set_ast_print_mode(nCtx, (uint)value); } - } - + + + + + public Z3_ast_print_mode PrintMode + + set { Z3native.set_ast_print_mode ctx#gno (uint)value); } (* SMT Files & Strings *) (** - Convert a benchmark into an SMT-LIB formatted string. + Convert a benchmark into an SMT-LIB formatted string. *) - @param name Name of the benchmark. The argument is optional. - @param logic The benchmark logic. - @param status The status string (sat, unsat, or unknown) - @param attributes Other attributes, such as source, difficulty or category. - @param assumptions Auxiliary assumptions. - @param formula 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) - { + @param name Name of the benchmark. The argument is optional. + @param logic The benchmark logic. + @param status The status string (sat, unsat, or unknown) + @param attributes Other attributes, such as source, difficulty or category. + @param assumptions Auxiliary assumptions. + @param formula 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 Z3native.benchmark_to_smtlib_string(nCtx, name, logic, status, attributes, - (uint)assumptions.Length, AST.ArrayToNative(assumptions), - formula.x#gno); - } + Z3native.benchmark_to_smtlib_string ctx#gno name, logic, status, attributes, + (uint)assumptions.Length, AST.ArrayToNative(assumptions), + formula#gno); (** - Parse the given string using the SMT-LIB parser. + 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. *) - - 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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - { - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_string(nCtx, str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)); - } + public void ParseSMTLIBString(string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_string ctx#gno 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. + Parse the given file using the SMT-LIB parser. *) - - public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - { - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_file(nCtx, fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)); - } + + public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_file ctx#gno 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. + The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBFormulas { get { return Z3native.get_smtlib_num_formulas(nCtx)) + public uint NumSMTLIBFormulas { get {Z3native.get_smtlib_num_formulas ctx#gno)) (** - The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public BoolExpr[] SMTLIBFormulas - { - get - { + let[] SMTLIBFormulas + get + + uint n = NumSMTLIBFormulas; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_formula ctx#gno i) + res; - uint n = NumSMTLIBFormulas; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)Expr.Create(this, Z3native.get_smtlib_formula(nCtx, i)); - return res; - } - } (** - The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBAssumptions { get { return Z3native.get_smtlib_num_assumptions(nCtx)) + public uint NumSMTLIBAssumptions { get {Z3native.get_smtlib_num_assumptions ctx#gno)) (** - The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public BoolExpr[] SMTLIBAssumptions - { - get - { + let[] SMTLIBAssumptions + get + + uint n = NumSMTLIBAssumptions; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i) + res; - uint n = NumSMTLIBAssumptions; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)Expr.Create(this, Z3native.get_smtlib_assumption(nCtx, i)); - return res; - } - } (** - The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBDecls { get { return Z3native.get_smtlib_num_decls(nCtx)) + public uint NumSMTLIBDecls { get {Z3native.get_smtlib_num_decls ctx#gno)) (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public Func_Decl[] SMTLIBDecls - { - get - { + public Func_Decl[] SMTLIBDecls + get + + uint n = NumSMTLIBDecls; + Func_Decl[] res = new Func_Decl[n]; + for (uint i = 0; i < n; i++) + res[i] = new Func_Decl(this, Z3native.get_smtlib_decl ctx#gno i) + res; - uint n = NumSMTLIBDecls; - Func_Decl[] res = new Func_Decl[n]; - for (uint i = 0; i < n; i++) - res[i] = new Func_Decl(this, Z3native.get_smtlib_decl(nCtx, i)); - return res; - } - } (** - The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBSorts { get { return Z3native.get_smtlib_num_sorts(nCtx)) + public uint NumSMTLIBSorts { get {Z3native.get_smtlib_num_sorts ctx#gno)) (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public Sort[] SMTLIBSorts - { - get - { + public Sort[] SMTLIBSorts + get + + uint n = NumSMTLIBSorts; + Sort[] res = new Sort[n]; + for (uint i = 0; i < n; i++) + res[i] = Sort.Create(this, Z3native.get_smtlib_sort ctx#gno i) + res; - uint n = NumSMTLIBSorts; - Sort[] res = new Sort[n]; - for (uint i = 0; i < n; i++) - res[i] = Sort.Create(this, Z3native.get_smtlib_sort(nCtx, i)); - return res; - } - } (** - Parse the given string using the SMT-LIB2 parser. + 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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - { + + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. + let ParseSMTLIB2String ( ctx : context ) string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - return (BoolExpr)Expr.Create(this, Z3native.parse_smtlib2_string(nCtx, str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); - } + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_string ctx#gno 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. + Parse the given file using the SMT-LIB2 parser. *) - - public BoolExpr ParseSMTLIB2File(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - { + + let ParseSMTLIB2File ( ctx : context ) string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - return (BoolExpr)Expr.Create(this, Z3native.parse_smtlib2_file(nCtx, fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls))); - } - + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_file ctx#gno fileName, + AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) (* GOALS *) (** - Creates a new Goal. + Creates a new Goal. + + Note that the Context must have been created with proof generation support if + is set to true here. *) - - Note that the Context must have been created with proof generation support if - is set to true here. - - @param models Indicates whether model generation should be enabled. - @param unsatCores Indicates whether unsat core generation should be enabled. - @param proofs Indicates whether proof generation should be enabled. - public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) - { + @param models Indicates whether model generation should be enabled. + @param unsatCores Indicates whether unsat core generation should be enabled. + @param proofs Indicates whether proof generation should be enabled. + public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) - - return new Goal(this, models, unsatCores, proofs); - } - + new Goal(this, models, unsatCores, proofs); (* PARAMETERSETS *) (** - Creates a new ParameterSet. + Creates a new ParameterSet. *) - public Params MkParams ( ctx : context ) = - { + public Params MkParams ( ctx : context ) = - - return new Params(this); - } - + new Params(this); (* TACTICS *) (** - The number of supported tactics. + The number of supported tactics. *) - public uint NumTactics - { - get { return Z3native.get_num_tactics(nCtx); } - } + public uint NumTactics + + get {Z3native.get_num_tactics ctx#gno); } (** - The names of all supported tactics. + The names of all supported tactics. *) - public string[] TacticNames - { - get - { + public string[] TacticNames + get + + uint n = NumTactics; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_tactic_name ctx#gno i); + res; - uint n = NumTactics; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_tactic_name(nCtx, i); - return res; - } - } (** - Returns a string containing a description of the tactic with the given name. + Returns a string containing a description of the tactic with the given name. *) - public string TacticDescription(string name) - { + public string TacticDescription(string name) - - return Z3native.tactic_get_descr(nCtx, name); - } + Z3native.tactic_get_descr ctx#gno name); (** - Creates a new Tactic. + Creates a new Tactic. *) - public Tactic MkTactic(string name) - { + public Tactic MkTactic(string name) - - return new Tactic(this, name); - } + new Tactic(this, name); (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . + Create a tactic that applies to a Goal and + then to every subgoal produced by . *) - public Tactic AndThen(Tactic t1, Tactic t2, params Tactic[] ts) - { + public Tactic AndThen(Tactic t1, Tactic t2, params Tactic[] ts) + IntPtr last = IntPtr.Zero; + if (ts != null && ts.Length > 0) + last = ts[ts.Length - 1]#gno; + for (int i = ts.Length - 2; i >= 0; i--) + last = Z3native.tactic_and_then ctx#gno ts[i]#gno last); + if (last != IntPtr.Zero) + last = Z3native.tactic_and_then ctx#gno t2#gno last); + new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno last) - - CheckContextMatch(t1); - CheckContextMatch(t2); - CheckContextMatch(ts); - - IntPtr last = IntPtr.Zero; - if (ts != null && ts.Length > 0) - { - last = ts[ts.Length - 1].x#gno; - for (int i = ts.Length - 2; i >= 0; i--) - last = Z3native.tactic_and_then(nCtx, ts[i].x#gno, last); - } - if (last != IntPtr.Zero) - { - last = Z3native.tactic_and_then(nCtx, t2.x#gno, last); - return new Tactic(this, Z3native.tactic_and_then(nCtx, t1.x#gno, last)); - } - else - return new Tactic(this, Z3native.tactic_and_then(nCtx, t1.x#gno, t2.x#gno)); - } + else + new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno t2#gno) (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . + Create a tactic that applies to a Goal and + then to every subgoal produced by . + + Shorthand for AndThen. *) - - Shorthand for AndThen. - - public Tactic Then(Tactic t1, Tactic t2, params Tactic[] ts) - { + public Tactic Then(Tactic t1, Tactic t2, params Tactic[] ts) - - - - - return AndThen(t1, t2, ts); - } + 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. + 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) - { + public Tactic OrElse(Tactic t1, Tactic t2) - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Z3native.tactic_or_else(nCtx, t1.x#gno, t2.x#gno)); - } + new Tactic(this, Z3native.tactic_or_else ctx#gno t1#gno t2#gno) (** - Create a tactic that applies to a goal for milliseconds. + Create a tactic that applies to a goal for milliseconds. + + If does not terminate within milliseconds, then it fails. *) - - If does not terminate within milliseconds, then it fails. - - public Tactic TryFor(Tactic t, uint ms) - { + public Tactic TryFor(Tactic t, uint ms) - - - CheckContextMatch(t); - return new Tactic(this, Z3native.tactic_try_for(nCtx, t.x#gno, ms)); - } + new Tactic(this, Z3native.tactic_try_for ctx#gno t#gno ms) (** - Create a tactic that applies to a given goal if the probe - evaluates to true. + 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. *) - - If evaluates to false, then the new tactic behaves like the skip tactic. - - public Tactic When(Probe p, Tactic t) - { + public Tactic When(Probe p, Tactic t) - - - - CheckContextMatch(t); - CheckContextMatch(p); - return new Tactic(this, Z3native.tactic_when(nCtx, p.x#gno, t.x#gno)); - } + new Tactic(this, Z3native.tactic_when ctx#gno p#gno t#gno) (** - Create a tactic that applies to a given goal if the probe - evaluates to true and otherwise. + 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) - { + public Tactic Cond(Probe p, Tactic t1, Tactic t2) - - - - - CheckContextMatch(p); - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Z3native.tactic_cond(nCtx, p.x#gno, t1.x#gno, t2.x#gno)); - } + new Tactic(this, Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) (** - Create a tactic that keeps applying until the goal is not - modified anymore or the maximum number of iterations is reached. + 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, uint max = uint.MaxValue) - { + public Tactic Repeat(Tactic t, uint max = uint.MaxValue) - - - CheckContextMatch(t); - return new Tactic(this, Z3native.tactic_repeat(nCtx, t.x#gno, max)); - } + new Tactic(this, Z3native.tactic_repeat ctx#gno t#gno max) (** - Create a tactic that just returns the given goal. + Create a tactic that just returns the given goal. *) - public Tactic Skip ( ctx : context ) = - { + public Tactic Skip ( ctx : context ) = - - return new Tactic(this, Z3native.tactic_skip(nCtx)); - } + new Tactic(this, Z3native.tactic_skip ctx#gno) (** - Create a tactic always fails. + Create a tactic always fails. *) - public Tactic Fail ( ctx : context ) = - { + public Tactic Fail ( ctx : context ) = - - return new Tactic(this, Z3native.tactic_fail(nCtx)); - } + new Tactic(this, Z3native.tactic_fail ctx#gno) (** - Create a tactic that fails if the probe evaluates to false. + Create a tactic that fails if the probe evaluates to false. *) - public Tactic FailIf(Probe p) - { + public Tactic FailIf(Probe p) - - - CheckContextMatch(p); - return new Tactic(this, Z3native.tactic_fail_if(nCtx, p.x#gno)); - } + new Tactic(this, Z3native.tactic_fail_if ctx#gno p#gno) (** - Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). + 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 ( ctx : context ) = - { + public Tactic FailIfNotDecided ( ctx : context ) = - - return new Tactic(this, Z3native.tactic_fail_if_not_decided(nCtx)); - } + new Tactic(this, Z3native.tactic_fail_if_not_decided ctx#gno) (** - Create a tactic that applies using the given set of parameters . + Create a tactic that applies using the given set of parameters . *) - public Tactic UsingParams(Tactic t, Params p) - { + public Tactic UsingParams(Tactic t, Params p) - - - - CheckContextMatch(t); - CheckContextMatch(p); - return new Tactic(this, Z3native.tactic_using_params(nCtx, t.x#gno, p.x#gno)); - } + new Tactic(this, Z3native.tactic_using_params ctx#gno t#gno p#gno) (** - Create a tactic that applies using the given set of parameters . -*) - Alias for UsingParams - public Tactic With(Tactic t, Params p) - { + 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); - } + UsingParams(t, p); (** - Create a tactic that applies the given tactics in parallel. + Create a tactic that applies the given tactics in parallel. *) - public Tactic ParOr(params Tactic[] t) - { + public Tactic ParOr(params Tactic[] t) - - - CheckContextMatch(t); - return new Tactic(this, Z3native.tactic_par_or(nCtx, Tactic.ArrayLength(t), Tactic.ArrayToNative(t))); - } + new Tactic(this, Z3native.tactic_par_or ctx#gno 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. + 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) - { + public Tactic ParAndThen(Tactic t1, Tactic t2) - - - - CheckContextMatch(t1); - CheckContextMatch(t2); - return new Tactic(this, Z3native.tactic_par_and_then(nCtx, t1.x#gno, t2.x#gno)); - } + new Tactic(this, Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) (** - Interrupt the execution of a Z3 procedure. + Interrupt the execution of a Z3 procedure. *) - This procedure can be used to interrupt: solvers, simplifiers and tactics. - public void Interrupt ( ctx : context ) = - { - Z3native.interrupt(nCtx); - } - + This procedure can be used to interrupt: solvers, simplifiers and tactics. + public void Interrupt ( ctx : context ) = + + Z3native.interrupt ctx#gno); (* PROBES *) (** - The number of supported Probes. + The number of supported Probes. *) - public uint NumProbes - { - get { return Z3native.get_num_probes(nCtx); } - } + public uint NumProbes + + get {Z3native.get_num_probes ctx#gno); } (** - The names of all supported Probes. + The names of all supported Probes. *) - public string[] ProbeNames - { - get - { + public string[] ProbeNames + get + + uint n = NumProbes; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_probe_name ctx#gno i); + res; - uint n = NumProbes; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_probe_name(nCtx, i); - return res; - } - } (** - Returns a string containing a description of the probe with the given name. + Returns a string containing a description of the probe with the given name. *) - public string ProbeDescription(string name) - { + public string ProbeDescription(string name) - - return Z3native.probe_get_descr(nCtx, name); - } + Z3native.probe_get_descr ctx#gno name); (** - Creates a new Probe. + Creates a new Probe. *) - public Probe MkProbe(string name) - { + public Probe MkProbe(string name) - - return new Probe(this, name); - } + new Probe(this, name); (** - Create a probe that always evaluates to . + Create a probe that always evaluates to . *) - public Probe Const(double val) - { + public Probe Const(double val) - - return new Probe(this, Z3native.probe_const(nCtx, val)); - } + new Probe(this, Z3native.probe_const ctx#gno val) (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by + 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) - { + public Probe Lt(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_lt(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_lt ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by + 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) - { + public Probe Gt(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_gt(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_gt ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by + 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) - { + public Probe Le(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_le(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_le ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by + 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) - { + public Probe Ge(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_ge(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_ge ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by + 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) - { + public Probe Eq(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_eq(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_eq ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". + Create a probe that evaluates to "true" when the value + and evaluate to "true". *) - public Probe And(Probe p1, Probe p2) - { + public Probe And(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_and(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_and ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". + Create a probe that evaluates to "true" when the value + or evaluate to "true". *) - public Probe Or(Probe p1, Probe p2) - { + public Probe Or(Probe p1, Probe p2) - - - - CheckContextMatch(p1); - CheckContextMatch(p2); - return new Probe(this, Z3native.probe_or(nCtx, p1.x#gno, p2.x#gno)); - } + new Probe(this, Z3native.probe_or ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". + Create a probe that evaluates to "true" when the value + does not evaluate to "true". *) - public Probe Not(Probe p) - { + public Probe Not(Probe p) - - - CheckContextMatch(p); - return new Probe(this, Z3native.probe_not(nCtx, p.x#gno)); - } - + new Probe(this, Z3native.probe_not ctx#gno p#gno) (* SOLVERS *) (** - 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 = null) - { + 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 = null) - - if (logic == null) - return new Solver(this, Z3native.mk_solver(nCtx)); - else - return new Solver(this, Z3native.mk_solver_for_logic(nCtx, logic.x#gno)); - } + if (logic == null) + new Solver(this, Z3native.mk_solver ctx#gno) + else + new Solver(this, Z3native.mk_solver_for_logic ctx#gno logic#gno) (** - Creates a new (incremental) solver. + Creates a new (incremental) solver. *) - - public Solver MkSolver(string logic) - { + + public Solver MkSolver(string logic) - - return MkSolver(MkSymbol(logic)); - } + MkSolver(MkSymbol(logic) (** - Creates a new (incremental) solver. + Creates a new (incremental) solver. *) - let mk_Simple_Solver ( ctx : context ) = - { + let mk_Simple_Solver ( ctx : context ) ctx : context ) = - - return new Solver(this, Z3native.mk_simple_solver(nCtx)); - } + new Solver(this, Z3native.mk_simple_solver ctx#gno) (** - Creates a solver that is implemented using the given tactic. + 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. *) - - The solver supports the commands Push and Pop, but it - will always solve each check from scratch. - - public Solver MkSolver(Tactic t) - { + public Solver MkSolver(Tactic t) - - - return new Solver(this, Z3native.mk_solver_from_tactic(nCtx, t.x#gno)); - } - + new Solver(this, Z3native.mk_solver_from_tactic ctx#gno t#gno) (* FIXEDPOINTS *) (** - Create a Fixedpoint context. + Create a Fixedpoint context. *) - public Fixedpoint MkFixedpoint ( ctx : context ) = - { - - - return new Fixedpoint(this); - } - + public Fixedpoint MkFixedpoint ( ctx : context ) = + new Fixedpoint(this); (* MISCELLANEOUS *) (** - Wraps an AST. + 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., - . - - @param nativeObject The native pointer to wrap. - public AST WrapAST(IntPtr nativeObject) - { + 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., + . + + @param nativeObject The native pointer to wrap. + public AST WrapAST(IntPtr nativeObject) - return AST.Create(this, nativeObject); - } + AST.Create(this, nativeObject); (** - Unwraps an AST. + 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., - ). - - @param a The AST to unwrap. - public IntPtr UnwrapAST(AST a) - { - return a.x#gno; - } + 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., + ). + + @param a The AST to unwrap. + public IntPtr UnwrapAST(AST a) + + a#gno; (** - Return a string describing all available parameters to Expr.Simplify. + a string describing all available parameters to Expr.Simplify. *) - public string SimplifyHelp ( ctx : context ) = - { + public string SimplifyHelp ( ctx : context ) = - - return Z3native.simplify_get_help(nCtx); - } + Z3native.simplify_get_help ctx#gno); (** - Retrieves parameter descriptions for simplifier. + Retrieves parameter descriptions for simplifier. *) - public ParamDescrs SimplifyParameterDescriptions - { - get { return new ParamDescrs(this, Z3native.simplify_get_param_descrs(nCtx)); } - } + public ParamDescrs SimplifyParameterDescriptions + + get {new ParamDescrs(this, Z3native.simplify_get_param_descrs ctx#gno)); } (** - Enable/disable printing of warning messages to the console. + 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(bool enabled) - { - Z3native.toggle_warning_messages((enabled) ? 1 : 0); - } - + Note that this function is static and effects the behaviour of + all contexts globally. + public static void ToggleWarningMessages(bool enabled) + + Z3native.toggle_warning_messages((enabled) ? 1 : 0); (* ERROR HANDLING *) - //(** - //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); +(** + 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; - +(** + The OnError event. +*) + public event ErrorHandler OnError = null; (* PARAMETERS *) (** - Update a mutable configuration parameter. + 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. *) - - 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) - { - Z3native.update_param_value(nCtx, id, value); - } + + public void UpdateParamValue(string id, string value) + + Z3native.update_param_value ctx#gno id, value); (** - Get a configuration parameter. + Get a configuration parameter. + + Returns null if the parameter value does not exist. + *) - - Returns null if the parameter value does not exist. - - - public string GetParamValue(string id) - { - IntPtr res = IntPtr.Zero; - int r = Z3native.get_param_value(nCtx, id, out res); - if (r == (int)Z3_lbool.Z3_L_FALSE) - return null; - else - return Marshal.PtrToStringAnsi(res); - } + public string GetParamValue(string id) - + IntPtr res = IntPtr.Zero; + int r = Z3native.get_param_value ctx#gno id, out res); + if (r == (int)Z3_lbool.L_FALSE) + null; + else + Marshal.PtrToStringAnsi(res); (* INTERNAL *) - internal IntPtr m_ctx = IntPtr.Zero; - internal Z3native.error_handler m_n_err_handler = null; - internal IntPtr nCtx { get { return m_ctx) + internal IntPtr m_ctx = IntPtr.Zero; + internal Z3native.error_handler m_n_err_handler = null; + internal IntPtr nCtx { get {m_ctx) - internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) - { - // Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. - } + internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) + + Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. + + internal void InitContext ( ctx : context ) = + + PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); - internal void InitContext ( ctx : context ) = - { - PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); // keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); - } *) -end + From 49a4e77a6df433ea91cc23bfc77063335459841e Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sun, 23 Dec 2012 04:00:34 +0000 Subject: [PATCH 146/248] More new ML API. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 8 +- scripts/update_api.py | 13 +- src/api/ml/z3.ml | 1644 ++++++++++++++++++------------------- 3 files changed, 807 insertions(+), 858 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index f414e9d1a..dde9f944a 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,7 +4,7 @@ *) open Z3 -open Z3.Context +open Z3.Arithmetic exception ExampleException of string @@ -16,9 +16,9 @@ let _ = Printf.printf "Running Z3 version %s\n" Version.to_string ; let cfg = [("model", "true"); ("proof", "false")] in let ctx = (new context cfg) in - let is = (mk_symbol_int ctx 42) in - let ss = (mk_symbol_string ctx "mySymbol") in - let bs = (mk_bool_sort ctx) in + let is = (Symbol.mk_int ctx 42) in + let ss = (Symbol.mk_string ctx "mySymbol") in + let bs = (Sort.mk_bool ctx) in let ints = (mk_int_sort ctx) in let rs = (mk_real_sort ctx) in Printf.printf "int symbol: %s\n" (Symbol.to_string (is :> symbol)); diff --git a/scripts/update_api.py b/scripts/update_api.py index 27f7dd507..acaa9478e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1154,8 +1154,11 @@ def mk_ml(): for k, v in Type2Str.iteritems(): if is_obj(k): ml_native.write('and %s = ptr\n' % v.lower()) - ml_native.write('\nexternal is_null : ptr -> bool\n') + ml_native.write('\n') + ml_native.write('external is_null : ptr -> bool\n') ml_native.write(' = "n_is_null"\n\n') + ml_native.write('external mk_null : unit -> ptr\n') + ml_native.write(' = "n_mk_null"\n\n') ml_native.write('exception Exception of string\n\n') # ML declarations @@ -1295,6 +1298,14 @@ def mk_ml(): ml_wrapper.write('CAMLprim value n_is_null(value p) {\n') ml_wrapper.write(' return Val_bool(Data_custom_val(p) == 0);\n') ml_wrapper.write('}\n\n') + ml_wrapper.write('CAMLprim value n_mk_null( void ) {\n') + ml_wrapper.write(' CAMLparam0();\n') + ml_wrapper.write(' CAMLlocal1(result);\n') + ml_wrapper.write(' void * z3_result = 0;\n') + ml_wrapper.write(' result = caml_alloc_custom(&default_custom_ops, sizeof(void*), 0, 1);\n') + ml_wrapper.write(' memcpy( Data_custom_val(result), &z3_result, sizeof(void*));\n') + ml_wrapper.write(' CAMLreturn (result);\n') + ml_wrapper.write('}\n\n') for name, result, params in _dotnet_decls: ip = inparams(params) op = outparams(params) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 5f67e11e2..f6454b797 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -593,6 +593,10 @@ object (self) method cnstr_obj obj = (self#sno ctx obj) ; self end +let patternaton (a : pattern array) = + let f (e : pattern) = e#gno in + Array.map f a + (** Parameter description objects *) class param_descrs ctx = object (self) @@ -1607,6 +1611,306 @@ struct *) let mk_or ( ctx : context ) ( args : bool_expr array ) = (new bool_expr ctx)#cnstr_obj (Z3native.mk_or ctx#gno (Array.length args) (astaton args)) + + (** + Create a numeral of a given sort. + @param v 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]*. + @param ty 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 + *) + let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = + create_expr ctx (Z3native.mk_numeral ctx#gno v ty#gno) + + (** + Create a numeral 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. + @param v Value of the numeral + @param ty Sort of the numeral + @return A Term with value and type + *) + let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = + create_expr ctx (Z3native.mk_int ctx#gno v ty#gno) +end + +(** Quantifier expressions *) +module Quantifiers = +struct + (** + 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 : expr ) appears, the higher is its + index. + *) + let get_index ( x : expr ) = + if not (AST.is_var x) then + raise (Z3native.Exception "Term is not a bound variable.") + else + Z3native.get_index_value x#gnc x#gno + + (** Quantifier patterns + + 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. + *) + module Pattern = + struct + (** + The number of terms in the pattern. + *) + let get_num_terms ( x : pattern ) = + Z3native.get_pattern_num_terms x#gnc x#gno + + (** + The terms in the pattern. + *) + let get_terms ( x : pattern ) = + let n = (get_num_terms x) in + let f i = (create_expr x#gc (Z3native.get_pattern x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the pattern. + *) + let to_string ( x : pattern ) = Z3native.pattern_to_string x#gnc x#gno + end + + (** + Indicates whether the quantifier is universal. + *) + let is_universal ( x : quantifier ) = + lbool_of_int (Z3native.is_quantifier_forall x#gnc x#gno) == L_TRUE + + (** + Indicates whether the quantifier is existential. + *) + let is_existential ( x : quantifier ) = not (is_universal x) + + (** + The weight of the quantifier. + *) + let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight x#gnc x#gno + + (** + The number of patterns. + *) + let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns x#gnc x#gno + + (** + The patterns. + *) + let get_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_pattern_ast x#gnc x#gno i)) in + Array.init n f + + (** + The number of no-patterns. + *) + let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns x#gnc x#gno + + (** + The no-patterns. + *) + let get_no_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_no_pattern_ast x#gnc x#gno i)) in + Array.init n f + + (** + The number of bound variables. + *) + let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound x#gnc x#gno + + (** + The symbols for the bound variables. + *) + let get_bound_variable_names ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (create_symbol x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in + Array.init n f + + (** + The sorts of the bound variables. + *) + let get_bound_variable_sorts ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (create_sort x#gc (Z3native.get_quantifier_bound_sort x#gnc x#gno i)) in + Array.init n f + + (** + The body of the quantifier. + *) + let get_body ( x : quantifier ) = + (new bool_expr x#gc)#cnstr_obj (Z3native.get_quantifier_body x#gnc x#gno) + + (** + Creates a new bound variable. + @param index The de-Bruijn index of the variable + @param ty The sort of the variable + *) + let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = + create_expr ctx (Z3native.mk_bound ctx#gno index ty#gno) + + (** + Create a quantifier pattern. + *) + let mk_pattern ( ctx : context ) ( terms : expr array ) = + if (Array.length terms) == 0 then + raise (Z3native.Exception "Cannot create a pattern from zero terms") + else + (new pattern ctx)#cnstr_obj (Z3native.mk_pattern ctx#gno (Array.length terms) (astaton terms)) + + (** + 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. + + @param sorts the sorts of the bound variables. + @param names names of the bound variables + @param body the body of the quantifier. + @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. + @param patterns array containing the patterns created using MkPattern. + @param noPatterns array containing the anti-patterns created using MkPattern. + @param quantifierID optional symbol to track quantifier. + @param skolemID optional symbol to track skolem constants. + *) + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (Array.length sorts) != (Array.length names) then + raise (Z3native.Exception "Number of sorts does not match number of names") + else if (nopatterns == None && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno (int_of_lbool L_TRUE) + (match weight with | None -> 1 | Some(x) -> x) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length sorts) (astaton sorts) + (astaton names) + body#gno) + else + let null = Z3native.mk_null() in + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno (int_of_lbool L_TRUE) + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> x#gno) + (match skolem_id with | None -> null | Some(x) -> x#gno) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) + (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length sorts) (astaton sorts) + (astaton names) + body#gno) + + (** + Create a universal Quantifier. + *) + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (nopatterns == None && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno (int_of_lbool L_TRUE) + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (expraton bound_constants) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + body#gno) + else + let null = Z3native.mk_null() in + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno (int_of_lbool L_TRUE) + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> x#gno) + (match skolem_id with | None -> null | Some(x) -> x#gno) + (Array.length bound_constants) (expraton bound_constants) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) + (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + body#gno) + (** + Create an existential Quantifier. + + *) + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (Array.length sorts) != (Array.length names) then + raise (Z3native.Exception "Number of sorts does not match number of names") + else if (nopatterns == None && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno (int_of_lbool L_FALSE) + (match weight with | None -> 1 | Some(x) -> x) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length sorts) (astaton sorts) + (astaton names) + body#gno) + else + let null = Z3native.mk_null() in + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno (int_of_lbool L_FALSE) + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> x#gno) + (match skolem_id with | None -> null | Some(x) -> x#gno) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) + (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length sorts) (astaton sorts) + (astaton names) + body#gno) + + (** + Create an existential Quantifier. + *) + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (nopatterns == None && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno (int_of_lbool L_FALSE) + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (expraton bound_constants) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + body#gno) + else + let null = Z3native.mk_null() in + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno (int_of_lbool L_FALSE) + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> x#gno) + (match skolem_id with | None -> null | Some(x) -> x#gno) + (Array.length bound_constants) (expraton bound_constants) + (match patterns with | None -> 0 | Some(x) -> (Array.length x)) + (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) + (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + body#gno) + + (** + Create a Quantifier. + *) + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (universal) then + (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) + else + (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) + + + (** + Create a Quantifier. + *) + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if (universal) then + mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id + else + mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id end (** Functions to manipulate Array expressions *) @@ -1777,71 +2081,71 @@ struct *) let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) -(** - Create a set type. -*) -let mk_sort ( ctx : context ) ( ty : sort) = - (new set_sort ctx)#cnstr_s ty + (** + Create a set type. + *) + let mk_sort ( ctx : context ) ( ty : sort) = + (new set_sort ctx)#cnstr_s ty -(** - Create an empty set. -*) -let mk_empty ( ctx : context ) ( domain : sort ) = - (create_expr ctx (Z3native.mk_empty_set ctx#gno domain#gno)) - - (** - Create the full set. - *) -let mk_full ( ctx : context ) ( domain : sort ) = - create_expr ctx (Z3native.mk_full_set ctx#gno domain#gno) + (** + Create an empty set. + *) + let mk_empty ( ctx : context ) ( domain : sort ) = + (create_expr ctx (Z3native.mk_empty_set ctx#gno domain#gno)) + + (** + Create the full set. + *) + let mk_full ( ctx : context ) ( domain : sort ) = + create_expr ctx (Z3native.mk_full_set ctx#gno domain#gno) -(** - Add an element to the set. -*) -let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_add ctx#gno set#gno element#gno) - - (** - Remove an element from a set. - *) -let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_del ctx#gno set#gno element#gno) - - (** - Take the union of a list of sets. - *) -let mk_union ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_union ctx#gno (Array.length args) (astaton args)) - -(** - Take the intersection of a list of sets. -*) -let mk_intersection ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_intersect ctx#gno (Array.length args) (astaton args)) + (** + Add an element to the set. + *) + let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = + create_expr ctx (Z3native.mk_set_add ctx#gno set#gno element#gno) + + (** + Remove an element from a set. + *) + let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = + create_expr ctx (Z3native.mk_set_del ctx#gno set#gno element#gno) + + (** + Take the union of a list of sets. + *) + let mk_union ( ctx : context ) ( args : expr array ) = + create_expr ctx (Z3native.mk_set_union ctx#gno (Array.length args) (astaton args)) + + (** + Take the intersection of a list of sets. + *) + let mk_intersection ( ctx : context ) ( args : expr array ) = + create_expr ctx (Z3native.mk_set_intersect ctx#gno (Array.length args) (astaton args)) -(** - Take the difference between two sets. -*) -let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_difference ctx#gno arg1#gno arg2#gno) + (** + Take the difference between two sets. + *) + let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = + create_expr ctx (Z3native.mk_set_difference ctx#gno arg1#gno arg2#gno) -(** - Take the complement of a set. -*) -let mk_complement ( ctx : context ) ( arg : expr ) = - create_expr ctx (Z3native.mk_set_complement ctx#gno arg#gno) + (** + Take the complement of a set. + *) + let mk_complement ( ctx : context ) ( arg : expr ) = + create_expr ctx (Z3native.mk_set_complement ctx#gno arg#gno) -(** - Check for set membership. -*) -let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - create_expr ctx (Z3native.mk_set_member ctx#gno elem#gno set#gno) + (** + Check for set membership. + *) + let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = + create_expr ctx (Z3native.mk_set_member ctx#gno elem#gno set#gno) - (** - Check for subsetness of sets. - *) -let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_subset ctx#gno arg1#gno arg2#gno) + (** + Check for subsetness of sets. + *) + let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = + create_expr ctx (Z3native.mk_set_subset ctx#gno arg1#gno arg2#gno) end @@ -2001,148 +2305,6 @@ struct Array.init n f end - -(** Quantifier expressions *) -module Quantifiers = -struct - (** - 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 : expr ) appears, the higher is its - index. - *) - let get_index ( x : expr ) = - if not (AST.is_var x) then - raise (Z3native.Exception "Term is not a bound variable.") - else - Z3native.get_index_value x#gnc x#gno - - (** Quantifier patterns - - 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. - *) - module Pattern = - struct - (** - The number of terms in the pattern. - *) - let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms x#gnc x#gno - - (** - The terms in the pattern. - *) - let get_terms ( x : pattern ) = - let n = (get_num_terms x) in - let f i = (create_expr x#gc (Z3native.get_pattern x#gnc x#gno i)) in - Array.init n f - - (** - A string representation of the pattern. - *) - let to_string ( x : pattern ) = Z3native.pattern_to_string x#gnc x#gno - end - - (** - Indicates whether the quantifier is universal. - *) - let is_universal ( x : quantifier ) = - lbool_of_int (Z3native.is_quantifier_forall x#gnc x#gno) == L_TRUE - - (** - Indicates whether the quantifier is existential. - *) - let is_existential ( x : quantifier ) = not (is_universal x) - - (** - The weight of the quantifier. - *) - let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight x#gnc x#gno - - (** - The number of patterns. - *) - let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns x#gnc x#gno - - (** - The patterns. - *) - let get_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_pattern_ast x#gnc x#gno i)) in - Array.init n f - - (** - The number of no-patterns. - *) - let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns x#gnc x#gno - - (** - The no-patterns. - *) - let get_no_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_no_pattern_ast x#gnc x#gno i)) in - Array.init n f - - (** - The number of bound variables. - *) - let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound x#gnc x#gno - - (** - The symbols for the bound variables. - *) - let get_bound_variable_names ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (create_symbol x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in - Array.init n f - - (** - The sorts of the bound variables. - *) - let get_bound_variable_sorts ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (create_sort x#gc (Z3native.get_quantifier_bound_sort x#gnc x#gno i)) in - Array.init n f - - (** - The body of the quantifier. - *) - let get_body ( x : quantifier ) = - (new bool_expr x#gc)#cnstr_obj (Z3native.get_quantifier_body x#gnc x#gno) - - (** - Creates a new bound variable. - @param index The de-Bruijn index of the variable - @param ty The sort of the variable - *) - let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_bound ctx#gno index ty#gno) - - (** - Create a quantifier pattern. - *) - let mk_pattern ( ctx : context ) ( terms : expr array ) = - if (Array.length terms) == 0 then - raise (Z3native.Exception "Cannot create a pattern from zero terms") - else - (new pattern ctx)#cnstr_obj (Z3native.mk_pattern ctx#gno (Array.length terms) (astaton terms)) -end (** Functions to manipulate Datatype expressions *) module Datatypes = @@ -2638,7 +2800,54 @@ struct The result has at most decimal places.*) let to_decimal_string ( x : algebraic_num ) ( precision : int ) = Z3native.get_numeral_decimal_string x#gnc x#gno precision + + (** + Create a real from a fraction. + + @param num numerator of rational. + @param den denominator of rational. + @return A Term with value / and sort Real + + *) + let mk_real_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = + if (den == 0) then + raise (Z3native.Exception "Denominator is zero") + else + (new rat_num ctx)#cnstr_obj (Z3native.mk_real ctx#gno num den) + + (** + Create a real numeral. + @param v A string representing the Term value in decimal notation. + @return A Term with value and sort Real + *) + let mk_real_numeral_s ( ctx : context ) ( v : string ) = + (new rat_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_real_sort ctx)#gno) + + (** + Create a real numeral. + + @param v value of the numeral. + @return A Term with value and sort Real + *) + let mk_real_numeral_i ( ctx : context ) ( v : int ) = + (new rat_num ctx)#cnstr_obj (Z3native.mk_int ctx#gno v (mk_real_sort ctx)#gno) + + (** + Create an integer numeral. + @param v A string representing the Term value in decimal notation. + *) + let mk_int_numeral_s ( ctx : context ) ( v : string ) = + (new int_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_int_sort ctx)#gno) + + (** + Create an integer numeral. + @param v value of the numeral. + @return A Term with value and sort Integer + *) + let mk_int_numeral_i ( ctx : context ) ( v : int ) = + (new int_num ctx)#cnstr_obj (Z3native.mk_int ctx#gno v (mk_int_sort ctx)#gno) + (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno end @@ -3386,10 +3595,18 @@ struct *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow ctx#gno t1#gno t2#gno) - + + (** + Create a bit-vector numeral. + + @param v A string representing the value in decimal notation. + @param size the size of the bit-vector + *) + let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = + (new bitvec_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_sort ctx size)#gno) end -(** Functions to manipulate Proof objects *) +(** Functions to manipulate proof expressions *) module Proofs = struct (** @@ -4567,933 +4784,654 @@ end (* STUFF FROM THE CONTEXT *) (** - -(* NUMERALS *) - -(* GENERAL NUMERALS *) -(** - Create a Term of a given sort. -*) - @param v 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]*. - @param ty 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) - - create_expr ctx (Z3native.mk_numeral ctx#gno v, ty#gno) - -(** - 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. -*) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(int v, Sort ty) - - create_expr ctx (Z3native.mk_int ctx#gno v, ty#gno) - -(** - 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. -*) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(uint v, Sort ty) - - create_expr ctx (Z3native.mk_unsigned_int ctx#gno v, ty#gno) - -(** - 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. -*) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(long v, Sort ty) - - create_expr ctx (Z3native.mk_int64 ctx#gno v, ty#gno) - -(** - 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. -*) - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - public Expr MkNumeral(ulong v, Sort ty) - - create_expr ctx (Z3native.mk_unsigned_int64 ctx#gno v, ty#gno) - -(* REALS *) -(** - Create a real from a fraction. -*) - @param num numerator of rational. - @param den 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"); - - new RatNum(this, Z3native.mk_real ctx#gno num, den) - -(** - Create a real numeral. -*) - @param v A string representing the Term value in decimal notation. - @return A Term with value and sort Real - public RatNum MkReal(string v) - - new RatNum(this, Z3native.mk_numeral ctx#gno v, RealSort#gno) - -(** - Create a real numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(int v) - - new RatNum(this, Z3native.mk_int ctx#gno v, RealSort#gno) - -(** - Create a real numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(uint v) - - new RatNum(this, Z3native.mk_unsigned_int ctx#gno v, RealSort#gno) - -(** - Create a real numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(long v) - - new RatNum(this, Z3native.mk_int64 ctx#gno v, RealSort#gno) - -(** - Create a real numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Real - public RatNum MkReal(ulong v) - - new RatNum(this, Z3native.mk_unsigned_int64 ctx#gno v, RealSort#gno) - -(* INTEGERS *) -(** - Create an integer numeral. -*) - @param v A string representing the Term value in decimal notation. - public IntNum MkInt(string v) - - new IntNum(this, Z3native.mk_numeral ctx#gno v, IntSort#gno) - -(** - Create an integer numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(int v) - - new IntNum(this, Z3native.mk_int ctx#gno v, IntSort#gno) - -(** - Create an integer numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(uint v) - - new IntNum(this, Z3native.mk_unsigned_int ctx#gno v, IntSort#gno) - -(** - Create an integer numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(long v) - - new IntNum(this, Z3native.mk_int64 ctx#gno v, IntSort#gno) - -(** - Create an integer numeral. -*) - @param v value of the numeral. - @return A Term with value and sort Integer - public IntNum MkInt(ulong v) - - new IntNum(this, Z3native.mk_unsigned_int64 ctx#gno v, IntSort#gno) - -(* BIT-VECTORS *) -(** - Create a bit-vector numeral. -*) - @param v A string representing the value in decimal notation. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) string v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - -(** - Create a bit-vector numeral. -*) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) int v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - -(** - Create a bit-vector numeral. -*) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) uint v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - -(** - Create a bit-vector numeral. -*) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) long v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - -(** - Create a bit-vector numeral. -*) - @param v value of the numeral. - @param size the size of the bit-vector - let mk_bv_ ( ctx : context ) ulong v, uint size) - - (BitVecNum)MkNumeral(v, MkBitVecSort(size) - - // Numerals - -(* QUANTIFIERS *) -(** - 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. -*) - @param sorts the sorts of the bound variables. - @param names names of the bound variables - @param body the body of the quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param patterns array containing the patterns created using MkPattern. - @param noPatterns array containing the anti-patterns created using MkPattern. - @param quantifierID optional symbol to track quantifier. - @param skolemID optional symbol to track skolem constants. - public Quantifier MkForall(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - new Quantifier(this, true, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create a universal Quantifier. -*) - public Quantifier MkForall(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - new Quantifier(this, true, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create an existential Quantifier. -*) - - public Quantifier MkExists(Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - new Quantifier(this, false, sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create an existential Quantifier. -*) - public Quantifier MkExists(Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - new Quantifier(this, false, boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create a Quantifier. -*) - public Quantifier MkQuantifier(bool universal, Sort[] sorts, Symbol[] names, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - if (universal) - MkForall(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - MkExists(sorts, names, body, weight, patterns, noPatterns, quantifierID, skolemID); - -(** - Create a Quantifier. -*) - public Quantifier MkQuantifier(bool universal, Expr[] boundConstants, Expr body, uint weight = 1, Pattern[] patterns = null, Expr[] noPatterns = null, Symbol quantifierID = null, Symbol skolemID = null) - - if (universal) - MkForall(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - else - MkExists(boundConstants, body, weight, patterns, noPatterns, quantifierID, skolemID); - - // Expr - (* OPTIONS *) (** - 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. + 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 Z3_ast_print_mode PrintMode + + + + + public Z3_ast_print_mode PrintMode - set { Z3native.set_ast_print_mode ctx#gno (uint)value); } + set { Z3native.set_ast_print_mode ctx#gno (uint)value); } (* SMT Files & Strings *) (** - Convert a benchmark into an SMT-LIB formatted string. + Convert a benchmark into an SMT-LIB formatted string. *) - @param name Name of the benchmark. The argument is optional. - @param logic The benchmark logic. - @param status The status string (sat, unsat, or unknown) - @param attributes Other attributes, such as source, difficulty or category. - @param assumptions Auxiliary assumptions. - @param formula 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) + @param name Name of the benchmark. The argument is optional. + @param logic The benchmark logic. + @param status The status string (sat, unsat, or unknown) + @param attributes Other attributes, such as source, difficulty or category. + @param assumptions Auxiliary assumptions. + @param formula 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) - Z3native.benchmark_to_smtlib_string ctx#gno name, logic, status, attributes, - (uint)assumptions.Length, AST.ArrayToNative(assumptions), - formula#gno); + Z3native.benchmark_to_smtlib_string ctx#gno name, logic, status, attributes, + (uint)assumptions.Length, AST.ArrayToNative(assumptions), + formula#gno); (** - 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. + 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 = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + public void ParseSMTLIBString(string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_string ctx#gno str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls) + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_string ctx#gno 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. + Parse the given file using the SMT-LIB parser. *) - - public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_file ctx#gno fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls) + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + Z3native.parse_smtlib_file ctx#gno 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. + The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBFormulas { get {Z3native.get_smtlib_num_formulas ctx#gno)) + public uint NumSMTLIBFormulas { get {Z3native.get_smtlib_num_formulas ctx#gno)) (** - The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let[] SMTLIBFormulas + let[] SMTLIBFormulas - get + get - uint n = NumSMTLIBFormulas; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_formula ctx#gno i) - res; + uint n = NumSMTLIBFormulas; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_formula ctx#gno i) + res; (** - The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBAssumptions { get {Z3native.get_smtlib_num_assumptions ctx#gno)) + public uint NumSMTLIBAssumptions { get {Z3native.get_smtlib_num_assumptions ctx#gno)) (** - The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let[] SMTLIBAssumptions + let[] SMTLIBAssumptions - get + get - uint n = NumSMTLIBAssumptions; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i) - res; + uint n = NumSMTLIBAssumptions; + BoolExpr[] res = new BoolExpr[n]; + for (uint i = 0; i < n; i++) + res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i) + res; (** - The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBDecls { get {Z3native.get_smtlib_num_decls ctx#gno)) + public uint NumSMTLIBDecls { get {Z3native.get_smtlib_num_decls ctx#gno)) (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public Func_Decl[] SMTLIBDecls + public Func_Decl[] SMTLIBDecls - get + get - uint n = NumSMTLIBDecls; - Func_Decl[] res = new Func_Decl[n]; - for (uint i = 0; i < n; i++) - res[i] = new Func_Decl(this, Z3native.get_smtlib_decl ctx#gno i) - res; + uint n = NumSMTLIBDecls; + Func_Decl[] res = new Func_Decl[n]; + for (uint i = 0; i < n; i++) + res[i] = new Func_Decl(this, Z3native.get_smtlib_decl ctx#gno i) + res; (** - The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public uint NumSMTLIBSorts { get {Z3native.get_smtlib_num_sorts ctx#gno)) + public uint NumSMTLIBSorts { get {Z3native.get_smtlib_num_sorts ctx#gno)) (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - public Sort[] SMTLIBSorts + public Sort[] SMTLIBSorts - get + get - uint n = NumSMTLIBSorts; - Sort[] res = new Sort[n]; - for (uint i = 0; i < n; i++) - res[i] = Sort.Create(this, Z3native.get_smtlib_sort ctx#gno i) - res; + uint n = NumSMTLIBSorts; + Sort[] res = new Sort[n]; + for (uint i = 0; i < n; i++) + res[i] = Sort.Create(this, Z3native.get_smtlib_sort ctx#gno i) + res; (** - Parse the given string using the SMT-LIB2 parser. + 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. - let ParseSMTLIB2String ( ctx : context ) string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. + let ParseSMTLIB2String ( ctx : context ) string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_string ctx#gno str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_string ctx#gno 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. + Parse the given file using the SMT-LIB2 parser. *) - - let ParseSMTLIB2File ( ctx : context ) string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + + let ParseSMTLIB2File ( ctx : context ) string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_file ctx#gno fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) + uint csn = Symbol.ArrayLength(sortNames); + uint cs = Sort.ArrayLength(sorts); + uint cdn = Symbol.ArrayLength(declNames); + uint cd = AST.ArrayLength(decls); + if (csn != cs || cdn != cd) + throw new Z3Exception("Argument size mismatch"); + (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_file ctx#gno fileName, + AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), + AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) (* GOALS *) (** - Creates a new Goal. - - Note that the Context must have been created with proof generation support if - is set to true here. + Creates a new Goal. + + Note that the Context must have been created with proof generation support if + is set to true here. *) - @param models Indicates whether model generation should be enabled. - @param unsatCores Indicates whether unsat core generation should be enabled. - @param proofs Indicates whether proof generation should be enabled. - public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) + @param models Indicates whether model generation should be enabled. + @param unsatCores Indicates whether unsat core generation should be enabled. + @param proofs Indicates whether proof generation should be enabled. + public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) - new Goal(this, models, unsatCores, proofs); + new Goal(this, models, unsatCores, proofs); (* PARAMETERSETS *) (** - Creates a new ParameterSet. + Creates a new ParameterSet. *) - public Params MkParams ( ctx : context ) = + public Params MkParams ( ctx : context ) = - new Params(this); + new Params(this); (* TACTICS *) (** - The number of supported tactics. + The number of supported tactics. *) - public uint NumTactics + public uint NumTactics - get {Z3native.get_num_tactics ctx#gno); } + get {Z3native.get_num_tactics ctx#gno); } (** - The names of all supported tactics. + The names of all supported tactics. *) - public string[] TacticNames + public string[] TacticNames - get + get - uint n = NumTactics; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_tactic_name ctx#gno i); - res; + uint n = NumTactics; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_tactic_name ctx#gno i); + res; (** - Returns a string containing a description of the tactic with the given name. + Returns a string containing a description of the tactic with the given name. *) - public string TacticDescription(string name) + public string TacticDescription(string name) - Z3native.tactic_get_descr ctx#gno name); + Z3native.tactic_get_descr ctx#gno name); (** - Creates a new Tactic. + Creates a new Tactic. *) - public Tactic MkTactic(string name) + public Tactic MkTactic(string name) - new Tactic(this, name); + new Tactic(this, name); (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . + Create a tactic that applies to a Goal and + then to every subgoal produced by . *) - public Tactic AndThen(Tactic t1, Tactic t2, params Tactic[] ts) + public Tactic AndThen(Tactic t1, Tactic t2, params Tactic[] ts) - IntPtr last = IntPtr.Zero; - if (ts != null && ts.Length > 0) + IntPtr last = IntPtr.Zero; + if (ts != null && ts.Length > 0) - last = ts[ts.Length - 1]#gno; - for (int i = ts.Length - 2; i >= 0; i--) - last = Z3native.tactic_and_then ctx#gno ts[i]#gno last); + last = ts[ts.Length - 1]#gno; + for (int i = ts.Length - 2; i >= 0; i--) + last = Z3native.tactic_and_then ctx#gno ts[i]#gno last); - if (last != IntPtr.Zero) + if (last != IntPtr.Zero) - last = Z3native.tactic_and_then ctx#gno t2#gno last); - new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno last) + last = Z3native.tactic_and_then ctx#gno t2#gno last); + new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno last) - else - new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno t2#gno) + else + new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno t2#gno) (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . - - Shorthand for AndThen. + 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, params Tactic[] ts) + public Tactic Then(Tactic t1, Tactic t2, params Tactic[] ts) - AndThen(t1, t2, ts); + 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. + 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) + public Tactic OrElse(Tactic t1, Tactic t2) - new Tactic(this, Z3native.tactic_or_else ctx#gno t1#gno t2#gno) + new Tactic(this, Z3native.tactic_or_else ctx#gno t1#gno t2#gno) (** - Create a tactic that applies to a goal for milliseconds. - - If does not terminate within milliseconds, then it fails. + Create a tactic that applies to a goal for milliseconds. + + If does not terminate within milliseconds, then it fails. *) - public Tactic TryFor(Tactic t, uint ms) + public Tactic TryFor(Tactic t, uint ms) - new Tactic(this, Z3native.tactic_try_for ctx#gno t#gno ms) + new Tactic(this, Z3native.tactic_try_for ctx#gno t#gno 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. + 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) + public Tactic When(Probe p, Tactic t) - new Tactic(this, Z3native.tactic_when ctx#gno p#gno t#gno) + new Tactic(this, Z3native.tactic_when ctx#gno p#gno t#gno) (** - Create a tactic that applies to a given goal if the probe - evaluates to true and otherwise. + 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) + public Tactic Cond(Probe p, Tactic t1, Tactic t2) - new Tactic(this, Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) + new Tactic(this, Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) (** - Create a tactic that keeps applying until the goal is not - modified anymore or the maximum number of iterations is reached. + 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, uint max = uint.MaxValue) + public Tactic Repeat(Tactic t, uint max = uint.MaxValue) - new Tactic(this, Z3native.tactic_repeat ctx#gno t#gno max) + new Tactic(this, Z3native.tactic_repeat ctx#gno t#gno max) (** - Create a tactic that just returns the given goal. + Create a tactic that just returns the given goal. *) - public Tactic Skip ( ctx : context ) = + public Tactic Skip ( ctx : context ) = - new Tactic(this, Z3native.tactic_skip ctx#gno) + new Tactic(this, Z3native.tactic_skip ctx#gno) (** - Create a tactic always fails. + Create a tactic always fails. *) - public Tactic Fail ( ctx : context ) = + public Tactic Fail ( ctx : context ) = - new Tactic(this, Z3native.tactic_fail ctx#gno) + new Tactic(this, Z3native.tactic_fail ctx#gno) (** - Create a tactic that fails if the probe evaluates to false. + Create a tactic that fails if the probe evaluates to false. *) - public Tactic FailIf(Probe p) + public Tactic FailIf(Probe p) - new Tactic(this, Z3native.tactic_fail_if ctx#gno p#gno) + new Tactic(this, Z3native.tactic_fail_if ctx#gno p#gno) (** - Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). + 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 ( ctx : context ) = + public Tactic FailIfNotDecided ( ctx : context ) = - new Tactic(this, Z3native.tactic_fail_if_not_decided ctx#gno) + new Tactic(this, Z3native.tactic_fail_if_not_decided ctx#gno) (** - Create a tactic that applies using the given set of parameters . + Create a tactic that applies using the given set of parameters . *) - public Tactic UsingParams(Tactic t, Params p) + public Tactic UsingParams(Tactic t, Params p) - new Tactic(this, Z3native.tactic_using_params ctx#gno t#gno p#gno) + new Tactic(this, Z3native.tactic_using_params ctx#gno t#gno p#gno) (** - Create a tactic that applies using the given set of parameters . - Alias for UsingParams*) - public Tactic With(Tactic t, Params p) + Create a tactic that applies using the given set of parameters . + Alias for UsingParams*) + public Tactic With(Tactic t, Params p) - UsingParams(t, p); + UsingParams(t, p); (** - Create a tactic that applies the given tactics in parallel. + Create a tactic that applies the given tactics in parallel. *) - public Tactic ParOr(params Tactic[] t) + public Tactic ParOr(params Tactic[] t) - new Tactic(this, Z3native.tactic_par_or ctx#gno Tactic.ArrayLength(t), Tactic.ArrayToNative(t)) + new Tactic(this, Z3native.tactic_par_or ctx#gno 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. + 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) + public Tactic ParAndThen(Tactic t1, Tactic t2) - new Tactic(this, Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) + new Tactic(this, Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) (** - Interrupt the execution of a Z3 procedure. + Interrupt the execution of a Z3 procedure. *) - This procedure can be used to interrupt: solvers, simplifiers and tactics. - public void Interrupt ( ctx : context ) = + This procedure can be used to interrupt: solvers, simplifiers and tactics. + public void Interrupt ( ctx : context ) = - Z3native.interrupt ctx#gno); + Z3native.interrupt ctx#gno); (* PROBES *) (** - The number of supported Probes. + The number of supported Probes. *) - public uint NumProbes + public uint NumProbes - get {Z3native.get_num_probes ctx#gno); } + get {Z3native.get_num_probes ctx#gno); } (** - The names of all supported Probes. + The names of all supported Probes. *) - public string[] ProbeNames + public string[] ProbeNames - get + get - uint n = NumProbes; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_probe_name ctx#gno i); - res; + uint n = NumProbes; + string[] res = new string[n]; + for (uint i = 0; i < n; i++) + res[i] = Z3native.get_probe_name ctx#gno i); + res; (** - Returns a string containing a description of the probe with the given name. + Returns a string containing a description of the probe with the given name. *) - public string ProbeDescription(string name) + public string ProbeDescription(string name) - Z3native.probe_get_descr ctx#gno name); + Z3native.probe_get_descr ctx#gno name); (** - Creates a new Probe. + Creates a new Probe. *) - public Probe MkProbe(string name) + public Probe MkProbe(string name) - new Probe(this, name); + new Probe(this, name); (** - Create a probe that always evaluates to . + Create a probe that always evaluates to . *) - public Probe Const(double val) + public Probe Const(double val) - new Probe(this, Z3native.probe_const ctx#gno val) + new Probe(this, Z3native.probe_const ctx#gno val) (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by + 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) + public Probe Lt(Probe p1, Probe p2) - new Probe(this, Z3native.probe_lt ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_lt ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by + 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) + public Probe Gt(Probe p1, Probe p2) - new Probe(this, Z3native.probe_gt ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_gt ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by + 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) + public Probe Le(Probe p1, Probe p2) - new Probe(this, Z3native.probe_le ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_le ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by + 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) + public Probe Ge(Probe p1, Probe p2) - new Probe(this, Z3native.probe_ge ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_ge ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by + 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) + public Probe Eq(Probe p1, Probe p2) - new Probe(this, Z3native.probe_eq ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_eq ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". + Create a probe that evaluates to "true" when the value + and evaluate to "true". *) - public Probe And(Probe p1, Probe p2) + public Probe And(Probe p1, Probe p2) - new Probe(this, Z3native.probe_and ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_and ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". + Create a probe that evaluates to "true" when the value + or evaluate to "true". *) - public Probe Or(Probe p1, Probe p2) + public Probe Or(Probe p1, Probe p2) - new Probe(this, Z3native.probe_or ctx#gno p1#gno p2#gno) + new Probe(this, Z3native.probe_or ctx#gno p1#gno p2#gno) (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". + Create a probe that evaluates to "true" when the value + does not evaluate to "true". *) - public Probe Not(Probe p) + public Probe Not(Probe p) - new Probe(this, Z3native.probe_not ctx#gno p#gno) + new Probe(this, Z3native.probe_not ctx#gno p#gno) (* SOLVERS *) (** - 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. + 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 = null) + public Solver MkSolver(Symbol logic = null) - if (logic == null) - new Solver(this, Z3native.mk_solver ctx#gno) - else - new Solver(this, Z3native.mk_solver_for_logic ctx#gno logic#gno) + if (logic == null) + new Solver(this, Z3native.mk_solver ctx#gno) + else + new Solver(this, Z3native.mk_solver_for_logic ctx#gno logic#gno) (** - Creates a new (incremental) solver. + Creates a new (incremental) solver. *) - - public Solver MkSolver(string logic) + + public Solver MkSolver(string logic) - MkSolver(MkSymbol(logic) + MkSolver(MkSymbol(logic) (** - Creates a new (incremental) solver. + Creates a new (incremental) solver. *) - let mk_Simple_Solver ( ctx : context ) ctx : context ) = + let mk_Simple_Solver( ctx : context ) ctx : context ) = - new Solver(this, Z3native.mk_simple_solver ctx#gno) + new Solver(this, Z3native.mk_simple_solver ctx#gno) (** - 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. + 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) + public Solver MkSolver(Tactic t) - new Solver(this, Z3native.mk_solver_from_tactic ctx#gno t#gno) + new Solver(this, Z3native.mk_solver_from_tactic ctx#gno t#gno) (* FIXEDPOINTS *) (** - Create a Fixedpoint context. + Create a Fixedpoint context. *) - public Fixedpoint MkFixedpoint ( ctx : context ) = + public Fixedpoint MkFixedpoint ( ctx : context ) = - new Fixedpoint(this); + new Fixedpoint(this); (* MISCELLANEOUS *) (** - Wraps an AST. + 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., - . - - @param nativeObject The native pointer to wrap. - public AST WrapAST(IntPtr nativeObject) + 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., + . + + @param nativeObject The native pointer to wrap. + public AST WrapAST(IntPtr nativeObject) - AST.Create(this, nativeObject); + AST.Create(this, nativeObject); (** - Unwraps an AST. + 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., - ). - - @param a The AST to unwrap. - public IntPtr UnwrapAST(AST a) + 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., + ). + + @param a The AST to unwrap. + public IntPtr UnwrapAST(AST a) - a#gno; + a#gno; (** - a string describing all available parameters to Expr.Simplify. + a string describing all available parameters to Expr.Simplify. *) - public string SimplifyHelp ( ctx : context ) = + public string SimplifyHelp ( ctx : context ) = - Z3native.simplify_get_help ctx#gno); + Z3native.simplify_get_help ctx#gno); (** - Retrieves parameter descriptions for simplifier. + Retrieves parameter descriptions for simplifier. *) - public ParamDescrs SimplifyParameterDescriptions + public ParamDescrs SimplifyParameterDescriptions - get {new ParamDescrs(this, Z3native.simplify_get_param_descrs ctx#gno)); } + get {new ParamDescrs(this, Z3native.simplify_get_param_descrs ctx#gno)); } (** - Enable/disable printing of warning messages to the console. + 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(bool enabled) + Note that this function is static and effects the behaviour of + all contexts globally. + public static void ToggleWarningMessages(bool enabled) - Z3native.toggle_warning_messages((enabled) ? 1 : 0); + Z3native.toggle_warning_messages((enabled) ? 1 : 0); (* ERROR HANDLING *) (** - 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. + 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); + public delegate void ErrorHandler(Context ctx, Z3_error_code errorCode, string errorString); (** - The OnError event. + The OnError event. *) - public event ErrorHandler OnError = null; + public event ErrorHandler OnError = null; (* PARAMETERS *) (** - 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. + 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) + + public void UpdateParamValue(string id, string value) - Z3native.update_param_value ctx#gno id, value); + Z3native.update_param_value ctx#gno id, value); (** - Get a configuration parameter. - - Returns null if the parameter value does not exist. - + Get a configuration parameter. + + Returns null if the parameter value does not exist. + *) - public string GetParamValue(string id) + public string GetParamValue(string id) - IntPtr res = IntPtr.Zero; - int r = Z3native.get_param_value ctx#gno id, out res); - if (r == (int)Z3_lbool.L_FALSE) - null; - else - Marshal.PtrToStringAnsi(res); + IntPtr res = IntPtr.Zero; + int r = Z3native.get_param_value ctx#gno id, out res); + if (r == (int)Z3_lbool.L_FALSE) + null; + else + Marshal.PtrToStringAnsi(res); (* INTERNAL *) - internal IntPtr m_ctx = IntPtr.Zero; - internal Z3native.error_handler m_n_err_handler = null; - internal IntPtr nCtx { get {m_ctx) + internal IntPtr m_ctx = IntPtr.Zero; + internal Z3native.error_handler m_n_err_handler = null; + internal IntPtr nCtx { get {m_ctx) - internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) + internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) - Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. + Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. - internal void InitContext ( ctx : context ) = + internal void InitContext ( ctx : context ) = - PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); + PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); *) - From 77679dc1f508833b3acc034b24a750ae0c2db956 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 24 Dec 2012 02:47:41 +0000 Subject: [PATCH 147/248] More new ML API; Status: everything is there except for error handling. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 1498 +++++++++++++++++++++++++--------------------- 1 file changed, 809 insertions(+), 689 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index f6454b797..088bfbd6f 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,33 +7,52 @@ open Z3enums -(**/**) +(** Context objects. -class virtual idisposable = -object - method virtual dispose : unit -end +Most interactions with Z3 are interpreted in some context; most users will only +require one such object, but power users may require more than one. To start using +Z3, do -(** Context objects *) + + let ctx = (new context [||]) in + (...) + + +where [||] is a (possibly empty) list of pairs of strings, which can +be used to set options on the context, e.g., like so: + + + let cfg = [("model", "true"); ("...", "...")] in + let ctx = (new context cfg) in + (...) + + +*) class context settings = +(**/**) object (self) - inherit idisposable - val mutable m_n_ctx : Z3native.z3_context = let cfg = Z3native.mk_config in let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; let v = Z3native.mk_context_rc cfg in Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; v +(* CMW: Install error handler here! + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); +*) + val mutable m_obj_cnt : int = 0 initializer (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) let f = fun o -> o#dispose in let v = self in - Gc.finalise f v + Gc.finalise f v; method dispose : unit = if m_obj_cnt == 0 then ( @@ -47,13 +66,14 @@ object (self) method add_one_ctx_obj = m_obj_cnt <- m_obj_cnt + 1 method sub_one_ctx_obj = m_obj_cnt <- m_obj_cnt - 1 method gno = m_n_ctx +(**/**) end +(**/**) (** Z3 objects *) class virtual z3object ctx_init obj_init = object (self) - inherit idisposable val mutable m_ctx : context = ctx_init val mutable m_n_obj : Z3native.ptr option = obj_init @@ -100,9 +120,10 @@ end (** Parameter set objects *) -class params ctx obj = +class params ctx = object (self) - inherit z3object ctx obj as super + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self method incref nc o = Z3native.params_inc_ref nc o method decref nc o = Z3native.params_dec_ref nc o end @@ -264,6 +285,10 @@ object (self) method decref nc o = super#decref nc o end +let func_declaton (a : func_decl array) = + let f (e : func_decl) = e#gno in + Array.map f a + class parameter = object (self) val mutable m_kind : parameter_kind = PARAMETER_INT; @@ -624,6 +649,10 @@ object (self) method decref nc o = Z3native.tactic_dec_ref nc o end +let tacticaton (a : tactic array) = + let f (e : tactic) = e#gno in + Array.map f a + (** Function interpretation entry objects *) class func_entry ctx = object (self) @@ -715,6 +744,15 @@ object (self) method decref nc o = Z3native.solver_dec_ref nc o end +(** Fixedpoint objects *) +class fixedpoint ctx = +object (self) + inherit z3object ctx None as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method incref nc o = Z3native.fixedpoint_inc_ref nc o + method decref nc o = Z3native.fixedpoint_dec_ref nc o +end + (**/**) @@ -1294,6 +1332,33 @@ struct x else (create_ast to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno)) + +(** + 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., + . + + @param nativeObject The native pointer to wrap. +*) + let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = + create_ast ctx ptr + +(** + 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., + ). + + @param a The AST to unwrap. +*) + let unwrap_ast ( a : ast ) = a#gno end (** General expressions (terms), including Boolean logic *) @@ -1308,6 +1373,18 @@ struct | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno pp#gno) +(** + a string describing all available parameters to Expr.Simplify. +*) + let get_simplify_help ( ctx : context ) = + Z3native.simplify_get_help ctx#gno + +(** + Retrieves parameter descriptions for simplifier. +*) + let get_simplify_parameter_descrs ( ctx : context ) = + (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs ctx#gno) + (** The function declaration of the function that is applied in this expression. *) @@ -4087,6 +4164,30 @@ end *) module Params = struct +(** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) +module ParamDescrs = +struct + + (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno + + (** Retrieve kind of parameter. *) + let get_kind ( x : param_descrs ) ( name : symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) + + (** Retrieve all names of parameters. *) + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size x#gnc x#gno in + let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in + Array.init n f + + (** The size of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno + + (** Retrieves a string representation of the ParamDescrs. *) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno +end + (** Adds a parameter setting. *) @@ -4135,37 +4236,18 @@ struct let add_s_symbol (p : params) (name : string) (value : symbol) = add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value + (** + Creates a new parameter set + *) + let mk_params ( ctx : context ) = + (new params ctx)#cnstr_obj (Z3native.mk_params ctx#gno) + (** A string representation of the parameter set. *) let to_string (p : params) = Z3native.params_to_string p#gnc p#gno end -(** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) -module ParamDescrs = -struct - - (** Validate a set of parameters. *) - let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno - - (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) - - (** Retrieve all names of parameters. *) - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size x#gnc x#gno in - let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in - Array.init n f - - (** The size of the ParamDescrs. *) - let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno - - (** Retrieves a string representation of the ParamDescrs. *) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno - -end - (** Goals A goal (aka problem). A goal is essentially a @@ -4258,6 +4340,22 @@ struct Z3native.tactic_dec_ref x#gnc tn ; (new goal x#gc)#cnstr_obj res + + (** + Creates a new Goal. + + Note that the Context must have been created with proof generation support if + is set to true here. + @param models Indicates whether model generation should be enabled. + @param unsat_cores Indicates whether unsat core generation should be enabled. + @param proofs Indicates whether proof generation should be enabled. + *) + let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = + (new goal ctx)#cnstr_obj (Z3native.mk_goal ctx#gno + (int_of_lbool (if models then L_TRUE else L_FALSE)) + (int_of_lbool (if unsat_cores then L_TRUE else L_FALSE)) + (int_of_lbool (if proofs then L_TRUE else L_FALSE))) + (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno end @@ -4272,6 +4370,33 @@ end *) module Tactic = struct +(** Tactic application results + + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) +module ApplyResult = +struct + (** The number of Subgoals. *) + let get_num_subgoals ( x : apply_result ) = + Z3native.apply_result_get_num_subgoals x#gnc x#gno + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoals ( x : apply_result ) = + let n = (get_num_subgoals x) in + let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in + Array.init n f + + (** 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 + *) + let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = + (new model x#gc)#cnstr_obj (Z3native.apply_result_convert_model x#gnc x#gno i m#gno) + + (** A string representation of the ApplyResult. *) + let to_string ( x : apply_result ) = Z3native.apply_result_to_string x#gnc x#gno +end + (** A string containing a description of parameters accepted by the tactic. *) let get_help ( x : tactic ) = Z3native.tactic_get_help x#gnc x#gno @@ -4291,6 +4416,147 @@ struct let get_solver ( x : tactic ) = (new solver x#gc)#cnstr_obj (Z3native.mk_solver_from_tactic x#gnc x#gno) + (** + The number of supported tactics. + *) + let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics ctx#gno + + (** + The names of all supported tactics. + *) + let get_tactic_names ( ctx : context ) = + let n = (get_num_tactics ctx ) in + let f i = (Z3native.get_tactic_name ctx#gno i) in + Array.init n f + + + (** + Returns a string containing a description of the tactic with the given name. + *) + let get_tactic_description ( ctx : context ) ( name : string ) = + Z3native.tactic_get_descr ctx#gno name + + (** + Creates a new Tactic. + *) + let mk_tactic ( ctx : context ) ( name : string ) = + (new tactic ctx)#cnstr_obj (Z3native.mk_tactic ctx#gno name) + + (** + Create a tactic that applies to a Goal and + then to every subgoal produced by . + *) + let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array option ) = + match + match ts with + | None -> None + | Some(rts) -> ( + let f p c = (match p with + | None -> (Some c#gno) + | Some(x) -> (Some (Z3native.tactic_and_then ctx#gno c#gno x))) in + Array.fold_left f None rts) + with + | None -> (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then ctx#gno t1#gno t2#gno) + | Some(x) -> + let o = (Z3native.tactic_and_then ctx#gno t2#gno x) in + (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then ctx#gno t1#gno o) + + (** + Create a tactic that first applies to a Goal and + if it fails then returns the result of applied to the Goal. + *) + let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_or_else ctx#gno t1#gno t2#gno) + + (** + Create a tactic that applies to a goal for milliseconds. + + If does not terminate within milliseconds, then it fails. + *) + let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_try_for ctx#gno t#gno 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. + *) + (* CMW: when is a keyword *) + let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_when ctx#gno p#gno t#gno) + + (** + Create a tactic that applies to a given goal if the probe + evaluates to true and otherwise. + *) + let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) + + (** + Create a tactic that keeps applying until the goal is not + modified anymore or the maximum number of iterations is reached. + *) + let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_repeat ctx#gno t#gno max) + + (** + Create a tactic that just returns the given goal. + *) + let skip ( ctx : context ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_skip ctx#gno) + + (** + Create a tactic always fails. + *) + let fail ( ctx : context ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail ctx#gno) + + (** + Create a tactic that fails if the probe evaluates to false. + *) + let fail_if ( ctx : context ) ( p : probe ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if ctx#gno p#gno) + + (** + Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) + or trivially unsatisfiable (i.e., contains `false'). + *) + let fail_if_not_decided ( ctx : context ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if_not_decided ctx#gno) + + (** + Create a tactic that applies using the given set of parameters . + *) + let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_using_params ctx#gno t#gno p#gno) + + (** + Create a tactic that applies using the given set of parameters . + Alias for UsingParams*) + (* CMW: with is a keyword *) + let with_ ( ctx : context ) ( t : tactic ) ( p : params ) = + using_params ctx t p + + (** + Create a tactic that applies the given tactics in parallel. + *) + let par_or ( ctx : context ) ( t : tactic array ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_par_or ctx#gno (Array.length t) (tacticaton t)) + + (** + Create a tactic that applies to a given goal and then + to every subgoal produced by . The subgoals are processed in parallel. + *) + let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) + + (** + Interrupt the execution of a Z3 procedure. + This procedure can be used to interrupt: solvers, simplifiers and tactics. + *) + let interrupt ( ctx : context ) = + Z3native.interrupt ctx#gno end (** Models @@ -4337,7 +4603,7 @@ struct let to_string ( x : func_entry ) = let a = (get_args x) in let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]]") + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") end (** @@ -4513,33 +4779,6 @@ struct let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno end -(** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) -module ApplyResult = -struct - (** The number of Subgoals. *) - let get_num_subgoals ( x : apply_result ) = - Z3native.apply_result_get_num_subgoals x#gnc x#gno - - (** Retrieves the subgoals from the apply_result. *) - let get_subgoals ( x : apply_result ) = - let n = (get_num_subgoals x) in - let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in - Array.init n f - - (** 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 - *) - let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = - (new model x#gc)#cnstr_obj (Z3native.apply_result_convert_model x#gnc x#gno i m#gno) - - (** A string representation of the ApplyResult. *) - let to_string ( x : apply_result) = Z3native.apply_result_to_string x#gnc x#gno -end - (** Solvers *) module Solver = struct @@ -4615,10 +4854,8 @@ struct let get ( x : statistics ) ( key : string ) = let f p c = (if (Entry.get_key c) = key then (Some c) else p) in Array.fold_left f None (get_entries x) - end - (** A string that describes all available solver parameters. *) @@ -4755,12 +4992,222 @@ struct let get_statistics ( x : solver ) = (new statistics x#gc)#cnstr_obj (Z3native.solver_get_statistics x#gnc x#gno) + (** + 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. + *) + let mk_solver ( ctx : context ) ( logic : symbol option) = + match logic with + | None -> (new solver ctx)#cnstr_obj (Z3native.mk_solver ctx#gno) + | Some (x) -> (new solver ctx)#cnstr_obj (Z3native.mk_solver_for_logic ctx#gno x#gno) + + (** + Creates a new (incremental) solver. + + *) + let mk_solver_s ( ctx : context ) ( logic : string ) = + mk_solver ctx (Some ((Symbol.mk_string ctx logic) :> symbol)) + + (** + Creates a new (incremental) solver. + *) + let mk_simple_solver ( ctx : context ) = + (new solver ctx)#cnstr_obj (Z3native.mk_simple_solver ctx#gno) + + (** + 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. + *) + let mk_solver_t ( ctx : context ) ( t : tactic ) = + (new solver ctx)#cnstr_obj (Z3native.mk_solver_from_tactic ctx#gno t#gno) + (** A string representation of the solver. *) let to_string ( x : solver ) = Z3native.solver_to_string x#gnc x#gno end +(** Fixedpoint solving *) +module Fixedpoints = +struct + (** + A string that describes all available fixedpoint solver parameters. + *) + let get_help ( x : fixedpoint ) = + Z3native.fixedpoint_get_help x#gnc x#gno + + (** + Sets the fixedpoint solver parameters. + *) + let set_params ( x : fixedpoint ) ( p : params )= + Z3native.fixedpoint_set_params x#gnc x#gno p#gno + + (** + Retrieves parameter descriptions for Fixedpoint solver. + *) + let get_param_descrs ( x : fixedpoint ) = + (new param_descrs x#gc)#cnstr_obj (Z3native.fixedpoint_get_param_descrs x#gnc x#gno) + + (** + Assert a constraints into the fixedpoint solver. + *) + let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = + let f e = (Z3native.fixedpoint_assert x#gnc x#gno e#gno) in + Array.map f constraints + + (** + Register predicate as recursive relation. + *) + let register_relation ( x : fixedpoint ) ( f : func_decl ) = + Z3native.fixedpoint_register_relation x#gnc x#gno f#gno + + (** + Add rule into the fixedpoint solver. + *) + let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = + match name with + | None -> Z3native.fixedpoint_add_rule x#gnc x#gno rule#gno (Z3native.mk_null()) + | Some(y) -> Z3native.fixedpoint_add_rule x#gnc x#gno rule#gno y#gno + + (** + Add table fact to the fixedpoint solver. + *) + let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = + Z3native.fixedpoint_add_fact x#gnc x#gno pred#gno (Array.length args) 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. + *) + let query ( x : fixedpoint ) ( query : bool_expr ) = + match (lbool_of_int (Z3native.fixedpoint_query x#gnc x#gno query#gno)) with + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.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. + *) + let query_r ( x : fixedpoint ) ( relations : func_decl array ) = + match (lbool_of_int (Z3native.fixedpoint_query_relations x#gnc x#gno (Array.length relations) (func_declaton relations))) with + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN + + (** + Creates a backtracking point. + + *) + let push ( x : fixedpoint ) = + Z3native.fixedpoint_push x#gnc x#gno + + (** + Backtrack one backtracking point. + + Note that an exception is thrown if Pop is called without a corresponding Push + + *) + let pop ( x : fixedpoint ) = + Z3native.fixedpoint_pop x#gnc x#gno + + (** + Update named rule into in the fixedpoint solver. + *) + let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = + Z3native.fixedpoint_update_rule x#gnc x#gno rule#gno name#gno + + (** + Retrieve satisfying instance or instances of solver, + or definitions for the recursive predicates that show unsatisfiability. + *) + let get_answer ( x : fixedpoint ) = + let q = (Z3native.fixedpoint_get_answer x#gnc x#gno) in + if (Z3native.is_null q) then + None + else + Some (create_expr x#gc q) + + (** + Retrieve explanation why fixedpoint engine returned status Unknown. + *) + let get_reason_unknown ( x : fixedpoint ) = + Z3native.fixedpoint_get_reason_unknown x#gnc x#gno + + (** + Retrieve the number of levels explored for a given predicate. + *) + let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = + Z3native.fixedpoint_get_num_levels x#gnc x#gno predicate#gno + + (** + Retrieve the cover of a predicate. + *) + let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = + let q = (Z3native.fixedpoint_get_cover_delta x#gnc x#gno level predicate#gno) in + if (Z3native.is_null q) then + None + else + Some (create_expr x#gc q) + + (** + Add property about the predicate. + The property is added at level. + *) + let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = + Z3native.fixedpoint_add_cover x#gnc x#gno level predicate#gno, property#gno + + (** + Retrieve internal string representation of fixedpoint object. + *) + let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string x#gnc x#gno 0 [||] + + (** + Instrument the Datalog engine on which table representation to use for recursive predicate. + *) + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = + Z3native.fixedpoint_set_predicate_representation x#gnc x#gno f#gno (Array.length kinds) (symbolaton kinds) + + (** + Convert benchmark given as set of axioms, rules and queries to a string. + *) + let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = + Z3native.fixedpoint_to_string x#gnc x#gno (Array.length queries) (astaton queries) + + (** + Retrieve set of rules added to fixedpoint context. + *) + let get_rules ( x : fixedpoint ) = + let v = ((new ast_vector x#gc)#cnstr_obj (Z3native.fixedpoint_get_rules x#gnc x#gno)) in + let n = (AST.ASTVector.get_size v) in + let f i = (new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get v i)#gno in + Array.init n f + + (** + Retrieve set of assertions added to fixedpoint context. + *) + let get_assertions ( x : fixedpoint ) = + let v = ((new ast_vector x#gc)#cnstr_obj (Z3native.fixedpoint_get_assertions x#gnc x#gno)) in + let n = (AST.ASTVector.get_size v) in + let f i = (new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get v i)#gno in + Array.init n f + + (** + Create a Fixedpoint context. + *) + let mk_fixedpoint ( ctx : context ) = + (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint ctx#gno) +end + (** Probes Probes are used to inspect a goal (aka problem) and collect information that may be used to decide @@ -4778,660 +5225,333 @@ struct *) let apply ( x : probe ) (g : goal) = Z3native.probe_apply x#gnc x#gno g#gno + + (** + The number of supported Probes. + *) + let get_num_probes ( ctx : context ) = + Z3native.get_num_probes ctx#gno + + (** + The names of all supported Probes. + *) + let get_probe_names ( ctx : context ) = + let n = (get_num_probes ctx) in + let f i = (Z3native.get_probe_name ctx#gno i) in + Array.init n f + + (** + Returns a string containing a description of the probe with the given name. + *) + let get_probe_description ( ctx : context ) ( name : string ) = + Z3native.probe_get_descr ctx#gno name + + (** + Creates a new Probe. + *) + let mk_probe ( ctx : context ) ( name : string ) = + (new probe ctx)#cnstr_obj (Z3native.mk_probe ctx#gno name) + + (** + Create a probe that always evaluates to . + *) + let const ( ctx : context ) ( v : float ) = + (new probe ctx)#cnstr_obj (Z3native.probe_const ctx#gno v) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than the value returned by + *) + let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_lt ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than the value returned by + *) + let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_gt ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than or equal the value returned by + *) + let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_le ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than or equal the value returned by + *) + let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_ge ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is equal to the value returned by + *) + let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_eq ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + and evaluate to "true". + *) + (* CMW: and is a keyword *) + let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_and ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + or evaluate to "true". + *) + (* CMW: or is a keyword *) + let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_or ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + does not evaluate to "true". + *) + (* CMW: is not a keyword? *) + let not_ ( ctx : context ) ( p : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_not ctx#gno p#gno) end - -(* STUFF FROM THE CONTEXT *) - -(** -(* OPTIONS *) +(** Global and context options + + Note: This module contains functions that set parameters/options for context + objects as well as functions that set options that are used globally, across + contexts.*) +module Options = +struct (** - 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. + 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 Z3_ast_print_mode PrintMode + let update_param_value ( ctx : context ) ( id : string) ( value : string )= + Z3native.update_param_value ctx#gno id value - set { Z3native.set_ast_print_mode ctx#gno (uint)value); } - -(* SMT Files & Strings *) (** - Convert a benchmark into an SMT-LIB formatted string. + Get a configuration parameter. + + Returns None if the parameter value does not exist. + *) - @param name Name of the benchmark. The argument is optional. - @param logic The benchmark logic. - @param status The status string (sat, unsat, or unknown) - @param attributes Other attributes, such as source, difficulty or category. - @param assumptions Auxiliary assumptions. - @param formula 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) + let get_param_value ( ctx : context ) ( id : string ) = + let (r, v) = (Z3native.get_param_value ctx#gno id) in + if ((lbool_of_int r) == L_FALSE) then + None + else + Some v - Z3native.benchmark_to_smtlib_string ctx#gno name, logic, status, attributes, - (uint)assumptions.Length, AST.ArrayToNative(assumptions), - formula#gno); + (** + 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + + + + + *) + let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = + Z3native.set_ast_print_mode ctx#gno (int_of_ast_print_mode value) (** - 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. + Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) - public void ParseSMTLIBString(string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) + let toggle_warning_messages ( enabled: bool ) = + Z3native.toggle_warning_messages (int_of_lbool (if enabled then L_TRUE else L_FALSE)) +end - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_string ctx#gno str, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls) +(** Functions for handling SMT and SMT2 expressions and files *) +module SMT = +struct + (** + Convert a benchmark into an SMT-LIB formatted string. -(** - Parse the given file using the SMT-LIB parser. -*) - - public void ParseSMTLIBFile(string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - Z3native.parse_smtlib_file ctx#gno 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 uint NumSMTLIBFormulas { get {Z3native.get_smtlib_num_formulas ctx#gno)) - -(** - The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - let[] SMTLIBFormulas - - get - - uint n = NumSMTLIBFormulas; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_formula ctx#gno i) - res; - - -(** - The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public uint NumSMTLIBAssumptions { get {Z3native.get_smtlib_num_assumptions ctx#gno)) - -(** - The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - let[] SMTLIBAssumptions - - get - - uint n = NumSMTLIBAssumptions; - BoolExpr[] res = new BoolExpr[n]; - for (uint i = 0; i < n; i++) - res[i] = (BoolExpr)create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i) - res; - - -(** - The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public uint NumSMTLIBDecls { get {Z3native.get_smtlib_num_decls ctx#gno)) - -(** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public Func_Decl[] SMTLIBDecls - - get - - uint n = NumSMTLIBDecls; - Func_Decl[] res = new Func_Decl[n]; - for (uint i = 0; i < n; i++) - res[i] = new Func_Decl(this, Z3native.get_smtlib_decl ctx#gno i) - res; - - -(** - The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public uint NumSMTLIBSorts { get {Z3native.get_smtlib_num_sorts ctx#gno)) - -(** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. -*) - public Sort[] SMTLIBSorts - - get - - uint n = NumSMTLIBSorts; - Sort[] res = new Sort[n]; - for (uint i = 0; i < n; i++) - res[i] = Sort.Create(this, Z3native.get_smtlib_sort ctx#gno i) - 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. - let ParseSMTLIB2String ( ctx : context ) string str, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_string ctx#gno 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. -*) - - let ParseSMTLIB2File ( ctx : context ) string fileName, Symbol[] sortNames = null, Sort[] sorts = null, Symbol[] declNames = null, Func_Decl[] decls = null) - - uint csn = Symbol.ArrayLength(sortNames); - uint cs = Sort.ArrayLength(sorts); - uint cdn = Symbol.ArrayLength(declNames); - uint cd = AST.ArrayLength(decls); - if (csn != cs || cdn != cd) - throw new Z3Exception("Argument size mismatch"); - (BoolExpr)create_expr ctx (Z3native.parse_smtlib2_file ctx#gno fileName, - AST.ArrayLength(sorts), Symbol.ArrayToNative(sortNames), AST.ArrayToNative(sorts), - AST.ArrayLength(decls), Symbol.ArrayToNative(declNames), AST.ArrayToNative(decls)) - -(* GOALS *) -(** - Creates a new Goal. - - Note that the Context must have been created with proof generation support if - is set to true here. -*) - @param models Indicates whether model generation should be enabled. - @param unsatCores Indicates whether unsat core generation should be enabled. - @param proofs Indicates whether proof generation should be enabled. - public Goal MkGoal(bool models = true, bool unsatCores = false, bool proofs = false) - - new Goal(this, models, unsatCores, proofs); - -(* PARAMETERSETS *) -(** - Creates a new ParameterSet. -*) - public Params MkParams ( ctx : context ) = - - new Params(this); - -(* TACTICS *) -(** - The number of supported tactics. -*) - public uint NumTactics - - get {Z3native.get_num_tactics ctx#gno); } - -(** - The names of all supported tactics. -*) - public string[] TacticNames - - get - - uint n = NumTactics; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_tactic_name ctx#gno i); - res; - - -(** - Returns a string containing a description of the tactic with the given name. -*) - public string TacticDescription(string name) - - Z3native.tactic_get_descr ctx#gno name); - -(** - Creates a new Tactic. -*) - public Tactic MkTactic(string name) - - 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, params Tactic[] ts) - - IntPtr last = IntPtr.Zero; - if (ts != null && ts.Length > 0) - - last = ts[ts.Length - 1]#gno; - for (int i = ts.Length - 2; i >= 0; i--) - last = Z3native.tactic_and_then ctx#gno ts[i]#gno last); - - if (last != IntPtr.Zero) - - last = Z3native.tactic_and_then ctx#gno t2#gno last); - new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno last) + @param name Name of the benchmark. The argument is optional. + @param logic The benchmark logic. + @param status The status string (sat, unsat, or unknown) + @param attributes Other attributes, such as source, difficulty or category. + @param assumptions Auxiliary assumptions. + @param formula Formula to be checked for consistency in conjunction with assumptions. + @return A string representation of the benchmark. + *) + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = + Z3native.benchmark_to_smtlib_string ctx#gno name logic status attributes + (Array.length assumptions) (astaton assumptions) + formula#gno + (** + 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. + *) + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = + let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in + let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in + let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in + let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") else - new Tactic(this, Z3native.tactic_and_then ctx#gno t1#gno t2#gno) - -(** - 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, params Tactic[] ts) - - 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) - - new Tactic(this, Z3native.tactic_or_else ctx#gno t1#gno t2#gno) - -(** - Create a tactic that applies to a goal for milliseconds. - - If does not terminate within milliseconds, then it fails. -*) - public Tactic TryFor(Tactic t, uint ms) - - new Tactic(this, Z3native.tactic_try_for ctx#gno t#gno 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) - - new Tactic(this, Z3native.tactic_when ctx#gno p#gno t#gno) - -(** - 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) - - new Tactic(this, Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) - -(** - 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, uint max = uint.MaxValue) - - new Tactic(this, Z3native.tactic_repeat ctx#gno t#gno max) - -(** - Create a tactic that just returns the given goal. -*) - public Tactic Skip ( ctx : context ) = - - new Tactic(this, Z3native.tactic_skip ctx#gno) - -(** - Create a tactic always fails. -*) - public Tactic Fail ( ctx : context ) = - - new Tactic(this, Z3native.tactic_fail ctx#gno) - -(** - Create a tactic that fails if the probe evaluates to false. -*) - public Tactic FailIf(Probe p) - - new Tactic(this, Z3native.tactic_fail_if ctx#gno p#gno) - -(** - 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 ( ctx : context ) = - - new Tactic(this, Z3native.tactic_fail_if_not_decided ctx#gno) - -(** - Create a tactic that applies using the given set of parameters . -*) - public Tactic UsingParams(Tactic t, Params p) - - new Tactic(this, Z3native.tactic_using_params ctx#gno t#gno p#gno) - -(** - Create a tactic that applies using the given set of parameters . - Alias for UsingParams*) - public Tactic With(Tactic t, Params p) - - UsingParams(t, p); - -(** - Create a tactic that applies the given tactics in parallel. -*) - public Tactic ParOr(params Tactic[] t) - - new Tactic(this, Z3native.tactic_par_or ctx#gno 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) - - new Tactic(this, Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) - -(** - Interrupt the execution of a Z3 procedure. -*) - This procedure can be used to interrupt: solvers, simplifiers and tactics. - public void Interrupt ( ctx : context ) = - - Z3native.interrupt ctx#gno); - -(* PROBES *) -(** - The number of supported Probes. -*) - public uint NumProbes - - get {Z3native.get_num_probes ctx#gno); } - -(** - The names of all supported Probes. -*) - public string[] ProbeNames - - get - - uint n = NumProbes; - string[] res = new string[n]; - for (uint i = 0; i < n; i++) - res[i] = Z3native.get_probe_name ctx#gno i); - res; - - -(** - Returns a string containing a description of the probe with the given name. -*) - public string ProbeDescription(string name) - - Z3native.probe_get_descr ctx#gno name); - -(** - Creates a new Probe. -*) - public Probe MkProbe(string name) - - new Probe(this, name); - -(** - Create a probe that always evaluates to . -*) - public Probe Const(double val) - - new Probe(this, Z3native.probe_const ctx#gno 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) - - new Probe(this, Z3native.probe_lt ctx#gno p1#gno p2#gno) - -(** - 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) - - new Probe(this, Z3native.probe_gt ctx#gno p1#gno p2#gno) - -(** - 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) - - new Probe(this, Z3native.probe_le ctx#gno p1#gno p2#gno) - -(** - 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) - - new Probe(this, Z3native.probe_ge ctx#gno p1#gno p2#gno) - -(** - 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) - - new Probe(this, Z3native.probe_eq ctx#gno p1#gno p2#gno) - -(** - Create a probe that evaluates to "true" when the value - and evaluate to "true". -*) - public Probe And(Probe p1, Probe p2) - - new Probe(this, Z3native.probe_and ctx#gno p1#gno p2#gno) - -(** - Create a probe that evaluates to "true" when the value - or evaluate to "true". -*) - public Probe Or(Probe p1, Probe p2) - - new Probe(this, Z3native.probe_or ctx#gno p1#gno p2#gno) - -(** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". -*) - public Probe Not(Probe p) - - new Probe(this, Z3native.probe_not ctx#gno p#gno) - -(* SOLVERS *) -(** - 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 = null) - - if (logic == null) - new Solver(this, Z3native.mk_solver ctx#gno) + Z3native.parse_smtlib_string ctx#gno str + cs + (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match sorts with | None -> [||] | Some(x) -> (astaton x)) + cd + (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + + (** + Parse the given file using the SMT-LIB parser. + + *) + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array option) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = + let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in + let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in + let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in + let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") else - new Solver(this, Z3native.mk_solver_for_logic ctx#gno logic#gno) + Z3native.parse_smtlib_file ctx#gno file_name + cs + (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match sorts with | None -> [||] | Some(x) -> (astaton x)) + cd + (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (** + The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas ctx#gno -(** - Creates a new (incremental) solver. -*) - - public Solver MkSolver(string logic) + (** + The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_smtlib_formulas ( ctx : context ) = + let n = (get_num_smtlib_formulas ctx ) in + let f i = ((create_expr ctx (Z3native.get_smtlib_formula ctx#gno i)) :> bool_expr) in + Array.init n f - MkSolver(MkSymbol(logic) -(** - Creates a new (incremental) solver. -*) - let mk_Simple_Solver( ctx : context ) ctx : context ) = + (** + The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions ctx#gno - new Solver(this, Z3native.mk_simple_solver ctx#gno) + (** + The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_smtlib_assumptions ( ctx : context ) = + let n = (get_num_smtlib_assumptions ctx ) in + let f i = ((create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i)) :> bool_expr ) in + Array.init n f -(** - 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) + (** + The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls ctx#gno - new Solver(this, Z3native.mk_solver_from_tactic ctx#gno t#gno) + (** + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_smtlib_decls ( ctx : context ) = + let n = (get_num_smtlib_decls ctx) in + let f i = (new func_decl ctx)#cnstr_obj (Z3native.get_smtlib_decl ctx#gno i) in + Array.init n f -(* FIXEDPOINTS *) -(** - Create a Fixedpoint context. -*) - public Fixedpoint MkFixedpoint ( ctx : context ) = + (** + The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts ctx#gno - new Fixedpoint(this); + (** + The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. + *) + let get_smtlib_sorts ( ctx : context ) = + let n = (get_num_smtlib_sorts ctx) in + let f i = (create_sort ctx (Z3native.get_smtlib_sort ctx#gno i)) in + Array.init n f -(* MISCELLANEOUS *) -(** - 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., - . - - @param nativeObject The native pointer to wrap. - public AST WrapAST(IntPtr nativeObject) + (** + Parse the given string using the SMT-LIB2 parser. - 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., - ). - - @param a The AST to unwrap. - public IntPtr UnwrapAST(AST a) - - a#gno; - -(** - a string describing all available parameters to Expr.Simplify. -*) - public string SimplifyHelp ( ctx : context ) = - - Z3native.simplify_get_help ctx#gno); - -(** - Retrieves parameter descriptions for simplifier. -*) - public ParamDescrs SimplifyParameterDescriptions - - get {new ParamDescrs(this, Z3native.simplify_get_param_descrs ctx#gno)); } - -(** - 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(bool enabled) - - Z3native.toggle_warning_messages((enabled) ? 1 : 0); - -(* ERROR HANDLING *) -(** - 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; - -(* PARAMETERS *) -(** - 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) - - Z3native.update_param_value ctx#gno id, value); - -(** - Get a configuration parameter. - - Returns null if the parameter value does not exist. - -*) - public string GetParamValue(string id) - - IntPtr res = IntPtr.Zero; - int r = Z3native.get_param_value ctx#gno id, out res); - if (r == (int)Z3_lbool.L_FALSE) - null; + + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. + *) + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = + let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in + let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in + let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in + let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") else - Marshal.PtrToStringAnsi(res); + Z3native.parse_smtlib2_string ctx#gno str + cs + (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match sorts with | None -> [||] | Some(x) -> (astaton x)) + cd + (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match decls with | None -> [||] | Some(x) -> (func_declaton x)) -(* INTERNAL *) - internal IntPtr m_ctx = IntPtr.Zero; - internal Z3native.error_handler m_n_err_handler = null; - internal IntPtr nCtx { get {m_ctx) + (** + Parse the given file using the SMT-LIB2 parser. + + *) + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = + let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in + let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in + let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in + let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Z3native.parse_smtlib2_string ctx#gno file_name + cs + (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match sorts with | None -> [||] | Some(x) -> (astaton x)) + cd + (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) + (match decls with | None -> [||] | Some(x) -> (func_declaton x)) +end - internal void NativeErrorHandler(IntPtr ctx, Z3_error_code errorCode) +(* - Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. +(** + 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, error_code errorCode, string errorString); - internal void InitContext ( ctx : context ) = + internal Z3native.error_handler m_n_err_handler = null; - PrintMode = Z3_ast_print_mode.Z3_PRINT_SMTLIB2_COMPLIANT; - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); + internal void NativeErrorHandler(IntPtr ctx, error_code errorCode) + + Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. *) From c2ff90720e6a7c08e096c096cdcc4cd7feb4b5b3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 24 Dec 2012 03:00:39 +0000 Subject: [PATCH 148/248] ML API: mk_context added. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 4 +- src/api/ml/z3.ml | 687 +++++++++++++++++++------------------- 2 files changed, 349 insertions(+), 342 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index dde9f944a..32c9458f5 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -14,8 +14,8 @@ let _ = else ( Printf.printf "Running Z3 version %s\n" Version.to_string ; - let cfg = [("model", "true"); ("proof", "false")] in - let ctx = (new context cfg) in + let cfg = (Some [("model", "true"); ("proof", "false")]) in + let ctx = (mk_context cfg) in let is = (Symbol.mk_int ctx 42) in let ss = (Symbol.mk_string ctx "mySymbol") in let bs = (Sort.mk_bool ctx) in diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 088bfbd6f..fee6f9fe0 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,29 +7,9 @@ open Z3enums -(** Context objects. - -Most interactions with Z3 are interpreted in some context; most users will only -require one such object, but power users may require more than one. To start using -Z3, do - - - let ctx = (new context [||]) in - (...) - - -where [||] is a (possibly empty) list of pairs of strings, which can -be used to set options on the context, e.g., like so: - - - let cfg = [("model", "true"); ("...", "...")] in - let ctx = (new context cfg) in - (...) - - -*) -class context settings = (**/**) + +class context settings = object (self) val mutable m_n_ctx : Z3native.z3_context = let cfg = Z3native.mk_config in @@ -66,11 +46,37 @@ object (self) method add_one_ctx_obj = m_obj_cnt <- m_obj_cnt + 1 method sub_one_ctx_obj = m_obj_cnt <- m_obj_cnt - 1 method gno = m_n_ctx -(**/**) end (**/**) +(** Create a context object. + +Most interactions with Z3 are interpreted in some context; many users will only +require one such object, but power users may require more than one. To start using +Z3, do + + + let ctx = (mk_context None) in + (...) + + +where a list of pairs of strings may be passed to set options on +the context, e.g., like so: + + + let cfg = (Some [("model", "true"); ("...", "...")]) in + let ctx = (mk_context cfg) in + (...) + +*) +let mk_context ( cfg : ( string * string ) list option ) = + match cfg with + | None -> new context [] + | Some(x) -> new context x + +(**/**) + (** Z3 objects *) class virtual z3object ctx_init obj_init = object (self) @@ -4559,224 +4565,114 @@ end Z3native.interrupt ctx#gno end -(** Models +(** Probes - A Model contains interpretations (assignments) of constants and functions. *) -module Model = + 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. +*) +module Probe = struct - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. - *) - module FuncInterp = - struct - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. - *) - module FuncEntry = - struct - (** - Return the (symbolic) value of this entry. - *) - let get_value ( x : func_entry ) = - create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) - - (** - The number of arguments of the entry. - *) - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno - - (** - The arguments of the function entry. - *) - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in - Array.init n f - - (** - A string representation of the function entry. - *) - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") - end - - (** - The number of entries in the function interpretation. - *) - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno - - (** - The entries in the function interpretation - *) - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in - Array.init n f - - (** - The (symbolic) `else' value of the function interpretation. - *) - let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) - - (** - The arity of the function interpretation - *) - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno - - (** - A string representation of the function interpretation. - *) - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (Array.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") - end - - (** Retrieves the interpretation (the assignment) of in the model. - A function declaration of zero arity - An expression if the function has an interpretation in the model, null otherwise. *) - let get_const_interp ( x : model ) ( f : func_decl ) = - if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then - raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") - else - let np = Z3native.model_get_const_interp x#gnc x#gno f#gno in - if (Z3native.is_null np) then - None - else - Some (create_expr x#gc np) - - (** Retrieves the interpretation (the assignment) of in the model. - A Constant - An expression if the constant has an interpretation in the model, null otherwise. - *) - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - - - (** Retrieves the interpretation (the assignment) of a non-constant in the model. - A function declaration of non-zero arity - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_range f#gnc f#gno))) in - if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp x#gnc x#gno f#gno in - if (Z3native.is_null n) then - None - else - match sk with - | ARRAY_SORT -> - if (lbool_of_int (Z3native.is_as_array x#gnc n)) == L_FALSE then - raise (Z3native.Exception "Argument was not an array constant") - else - let fd = Z3native.get_as_array_func_decl x#gnc n in - get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) - | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); - else - let n = (Z3native.model_get_func_interp x#gnc x#gno f#gno) in - if (Z3native.is_null n) then None else Some ((new func_interp x#gc)#cnstr_obj n) - - (** The number of constants that have an interpretation in the model. *) - let get_num_consts ( x : model ) = Z3native.model_get_num_consts x#gnc x#gno - - (** The function declarations of the constants in the model. *) - let get_const_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in - Array.init n f - - - (** The number of function interpretations in the model. *) - let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs x#gnc x#gno - - (** The function declarations of the function interpretations in the model. *) - let get_func_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in - Array.init n f - - (** All symbols that have an interpretation in the model. *) - let get_decls ( x : model ) = - let n_funcs = (get_num_funcs x) in - let n_consts = (get_num_consts x ) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in - let g i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in - Array.append (Array.init n_funcs f) (Array.init n_consts g) - - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) - exception ModelEvaluationFailedException of string - (** - 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. - - The evaluation of in the model. + Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno (int_of_lbool (if completion then L_TRUE else L_FALSE))) in - if (lbool_of_int r) == L_FALSE then - raise (ModelEvaluationFailedException "evaluation failed") - else - create_expr x#gc v + let apply ( x : probe ) (g : goal) = + Z3native.probe_apply x#gnc x#gno g#gno - (** Alias for eval. *) - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = - eval x t completion - - (** The number of uninterpreted sorts that the model has an interpretation for. *) - let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts x#gnc x#gno - - (** 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. - - + (** + The number of supported Probes. *) - let get_sorts ( x : model ) = - let n = (get_num_sorts x) in - let f i = (create_sort x#gc (Z3native.model_get_sort x#gnc x#gno i)) in + let get_num_probes ( ctx : context ) = + Z3native.get_num_probes ctx#gno + + (** + The names of all supported Probes. + *) + let get_probe_names ( ctx : context ) = + let n = (get_num_probes ctx) in + let f i = (Z3native.get_probe_name ctx#gno i) in Array.init n f + (** + Returns a string containing a description of the probe with the given name. + *) + let get_probe_description ( ctx : context ) ( name : string ) = + Z3native.probe_get_descr ctx#gno name - (** The finite set of distinct values that represent the interpretation for sort . - - An uninterpreted sort - An array of expressions, where each is an element of the universe of + (** + Creates a new Probe. + *) + let mk_probe ( ctx : context ) ( name : string ) = + (new probe ctx)#cnstr_obj (Z3native.mk_probe ctx#gno name) + + (** + Create a probe that always evaluates to . *) - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in - Array.init n f - - (** Conversion of models to strings. - A string representation of the model. + let const ( ctx : context ) ( v : float ) = + (new probe ctx)#cnstr_obj (Z3native.probe_const ctx#gno v) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than the value returned by *) - let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno + let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_lt ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than the value returned by + *) + let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_gt ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than or equal the value returned by + *) + let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_le ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than or equal the value returned by + *) + let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_ge ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value returned by + is equal to the value returned by + *) + let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_eq ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + and evaluate to "true". + *) + (* CMW: and is a keyword *) + let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_and ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + or evaluate to "true". + *) + (* CMW: or is a keyword *) + let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_or ctx#gno p1#gno p2#gno) + + (** + Create a probe that evaluates to "true" when the value + does not evaluate to "true". + *) + (* CMW: is not a keyword? *) + let not_ ( ctx : context ) ( p : probe ) = + (new probe ctx)#cnstr_obj (Z3native.probe_not ctx#gno p#gno) end (** Solvers *) @@ -5032,6 +4928,227 @@ struct let to_string ( x : solver ) = Z3native.solver_to_string x#gnc x#gno end + +(** Models + + A Model contains interpretations (assignments) of constants and functions. *) +module Model = +struct + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. + *) + module FuncInterp = + struct + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. + *) + module FuncEntry = + struct + (** + Return the (symbolic) value of this entry. + *) + let get_value ( x : func_entry ) = + create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + + (** + The number of arguments of the entry. + *) + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + + (** + The arguments of the function entry. + *) + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the function entry. + *) + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") + end + + (** + The number of entries in the function interpretation. + *) + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + + (** + The entries in the function interpretation + *) + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + Array.init n f + + (** + The (symbolic) `else' value of the function interpretation. + *) + let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + + (** + The arity of the function interpretation + *) + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + + (** + A string representation of the function interpretation. + *) + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (Array.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + end + + (** Retrieves the interpretation (the assignment) of in the model. + A function declaration of zero arity + An expression if the function has an interpretation in the model, null otherwise. *) + let get_const_interp ( x : model ) ( f : func_decl ) = + if (FuncDecl.get_arity f) != 0 || + (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then + raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") + else + let np = Z3native.model_get_const_interp x#gnc x#gno f#gno in + if (Z3native.is_null np) then + None + else + Some (create_expr x#gc np) + + (** Retrieves the interpretation (the assignment) of in the model. + A Constant + An expression if the constant has an interpretation in the model, null otherwise. + *) + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + + + (** Retrieves the interpretation (the assignment) of a non-constant in the model. + A function declaration of non-zero arity + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + let rec get_func_interp ( x : model ) ( f : func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_range f#gnc f#gno))) in + if (FuncDecl.get_arity f) == 0 then + let n = Z3native.model_get_const_interp x#gnc x#gno f#gno in + if (Z3native.is_null n) then + None + else + match sk with + | ARRAY_SORT -> + if (lbool_of_int (Z3native.is_as_array x#gnc n)) == L_FALSE then + raise (Z3native.Exception "Argument was not an array constant") + else + let fd = Z3native.get_as_array_func_decl x#gnc n in + get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) + | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); + else + let n = (Z3native.model_get_func_interp x#gnc x#gno f#gno) in + if (Z3native.is_null n) then None else Some ((new func_interp x#gc)#cnstr_obj n) + + (** The number of constants that have an interpretation in the model. *) + let get_num_consts ( x : model ) = Z3native.model_get_num_consts x#gnc x#gno + + (** The function declarations of the constants in the model. *) + let get_const_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in + Array.init n f + + + (** The number of function interpretations in the model. *) + let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs x#gnc x#gno + + (** The function declarations of the function interpretations in the model. *) + let get_func_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in + Array.init n f + + (** All symbols that have an interpretation in the model. *) + let get_decls ( x : model ) = + let n_funcs = (get_num_funcs x) in + let n_consts = (get_num_consts x ) in + let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in + let g i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in + Array.append (Array.init n_funcs f) (Array.init n_consts g) + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) + exception ModelEvaluationFailedException of string + + (** + 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. + + The evaluation of in the model. + *) + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno (int_of_lbool (if completion then L_TRUE else L_FALSE))) in + if (lbool_of_int r) == L_FALSE then + raise (ModelEvaluationFailedException "evaluation failed") + else + create_expr x#gc v + + (** Alias for eval. *) + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + eval x t completion + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts x#gnc x#gno + + (** 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. + + + *) + let get_sorts ( x : model ) = + let n = (get_num_sorts x) in + let f i = (create_sort x#gc (Z3native.model_get_sort x#gnc x#gno i)) in + Array.init n f + + + (** The finite set of distinct values that represent the interpretation for sort . + + An uninterpreted sort + An array of expressions, where each is an element of the universe of + *) + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in + Array.init n f + + (** Conversion of models to strings. + A string representation of the model. + *) + let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno +end + (** Fixedpoint solving *) module Fixedpoints = struct @@ -5208,116 +5325,6 @@ struct (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint ctx#gno) end -(** Probes - - 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. -*) -module Probe = -struct - (** - Execute the probe over the goal. - A probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. - *) - let apply ( x : probe ) (g : goal) = - Z3native.probe_apply x#gnc x#gno g#gno - - (** - The number of supported Probes. - *) - let get_num_probes ( ctx : context ) = - Z3native.get_num_probes ctx#gno - - (** - The names of all supported Probes. - *) - let get_probe_names ( ctx : context ) = - let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name ctx#gno i) in - Array.init n f - - (** - Returns a string containing a description of the probe with the given name. - *) - let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr ctx#gno name - - (** - Creates a new Probe. - *) - let mk_probe ( ctx : context ) ( name : string ) = - (new probe ctx)#cnstr_obj (Z3native.mk_probe ctx#gno name) - - (** - Create a probe that always evaluates to . - *) - let const ( ctx : context ) ( v : float ) = - (new probe ctx)#cnstr_obj (Z3native.probe_const ctx#gno v) - - (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by - *) - let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_lt ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by - *) - let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_gt ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by - *) - let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_le ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by - *) - let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_ge ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by - *) - let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_eq ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". - *) - (* CMW: and is a keyword *) - let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_and ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". - *) - (* CMW: or is a keyword *) - let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_or ctx#gno p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". - *) - (* CMW: is not a keyword? *) - let not_ ( ctx : context ) ( p : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_not ctx#gno p#gno) -end - (** Global and context options Note: This module contains functions that set parameters/options for context From 25498345e54f30d7f7b3095b41e3707eeb3217b2 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 24 Dec 2012 15:16:16 +0000 Subject: [PATCH 149/248] New ML API bugfixes and first example. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 122 ++++++++++++++++++++++++++++++++++++++ scripts/update_api.py | 10 +++- src/api/ml/z3.ml | 112 +++++++++++++++++----------------- 3 files changed, 186 insertions(+), 58 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 32c9458f5..945c9a494 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -4,10 +4,131 @@ *) open Z3 +open Z3.Symbol +open Z3.Sort +open Z3.Expr +open Z3.FuncDecl +open Z3.Goal +open Z3.Tactic +open Z3.Probe +open Z3.Solver open Z3.Arithmetic exception ExampleException of string + +(** + Some basic tests. +*) +let basic_tests ( ctx : context ) = + Printf.printf "BasicTests\n" ; + let qi = (mk_int ctx 1) in + let fname = ((mk_string ctx "f") :> symbol) in + let x = ((mk_string ctx "x") :> symbol) in + let y = ((mk_string ctx "y") :> symbol) in + let bs = (Sort.mk_bool ctx) in + let domain = [| bs; bs |] in + let f = (FuncDecl.mk_func_decl ctx fname domain bs) in + let fapp = (mk_app ctx f + [| (mk_const ctx x bs); (mk_const ctx y bs) |]) in + let fargs2 = [| (mk_fresh_const ctx "cp" bs) |] in + let domain2 = [| bs |] in + let fapp2 = (mk_app ctx (mk_fresh_func_decl ctx "fp" domain2 bs) fargs2) in + let trivial_eq = (mk_eq ctx fapp fapp) in + let nontrivial_eq = (mk_eq ctx fapp fapp2) in + let g = (mk_goal ctx true false false) in + (Goal.assert_ g [| trivial_eq |]) ; + (Goal.assert_ g [| nontrivial_eq |]) ; + Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; + let solver = (mk_solver ctx None) in + (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; + if (check solver None) != SATISFIABLE then + raise (ExampleException "") + else + Printf.printf "Test passed.\n" ; + () + +(* + ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g); + if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat)) + throw new TestFailedException(); + + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) + throw new TestFailedException(); + + g.Assert(ctx.MkEq(ctx.MkNumeral(1, ctx.MkBitVecSort(32)), + ctx.MkNumeral(2, ctx.MkBitVecSort(32)))); + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) + throw new TestFailedException(); + + + Goal g2 = ctx.MkGoal(true, true); + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) + throw new TestFailedException(); + + g2 = ctx.MkGoal(true, true); + g2.Assert(ctx.MkFalse()); + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) + throw new TestFailedException(); + + Goal g3 = ctx.MkGoal(true, true); + Expr xc = ctx.MkConst(ctx.MkSymbol("x"), ctx.IntSort); + Expr yc = ctx.MkConst(ctx.MkSymbol("y"), ctx.IntSort); + g3.Assert(ctx.MkEq(xc, ctx.MkNumeral(1, ctx.IntSort))); + g3.Assert(ctx.MkEq(yc, ctx.MkNumeral(2, ctx.IntSort))); + BoolExpr constr = ctx.MkEq(xc, yc); + g3.Assert(constr); + ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g3); + if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) + throw new TestFailedException(); + + ModelConverterTest(ctx); + + // Real num/den test. + RatNum rn = ctx.MkReal(42, 43); + Expr inum = rn.Numerator; + Expr iden = rn.Denominator; + Console.WriteLine("Numerator: " + inum + " Denominator: " + iden); + if (inum.ToString() != "42" || iden.ToString() != "43") + throw new TestFailedException(); + + if (rn.ToDecimalString(3) != "0.976?") + throw new TestFailedException(); + + BigIntCheck(ctx, ctx.MkReal("-1231231232/234234333")); + BigIntCheck(ctx, ctx.MkReal("-123123234234234234231232/234234333")); + BigIntCheck(ctx, ctx.MkReal("-234234333")); + BigIntCheck(ctx, ctx.MkReal("234234333/2")); + + + string bn = "1234567890987654321"; + + if (ctx.MkInt(bn).BigInteger.ToString() != bn) + throw new TestFailedException(); + + if (ctx.MkBV(bn, 128).BigInteger.ToString() != bn) + throw new TestFailedException(); + + if (ctx.MkBV(bn, 32).BigInteger.ToString() == bn) + throw new TestFailedException(); + + // Error handling test. + try + { + IntExpr i = ctx.MkInt("1/2"); + throw new TestFailedException(); // unreachable + } + catch (Z3Exception) + { + } + } +*) + + let _ = if not (Log.open_ "z3.log") then raise (ExampleException "Log couldn't be opened.") @@ -27,6 +148,7 @@ let _ = Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); Printf.printf "Disposing...\n"; + basic_tests ctx ; Gc.full_major () ); Printf.printf "Exiting.\n"; diff --git a/scripts/update_api.py b/scripts/update_api.py index acaa9478e..5d95a12f8 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -159,7 +159,7 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I # Mapping to ML types Type2ML = { VOID : 'unit', VOID_PTR : 'VOIDP', INT : 'int', UINT : 'int', INT64 : 'int', UINT64 : 'int', DOUBLE : 'float', STRING : 'string', STRING_PTR : 'char**', - BOOL : 'int', SYMBOL : 'z3_symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } + BOOL : 'bool', SYMBOL : 'z3_symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } next_type_id = FIRST_OBJ_ID @@ -1109,7 +1109,9 @@ def arrayparams(params): def ml_unwrap(t, ts, s): if t == STRING: return '(' + ts + ') String_val(' + s + ')' - elif t == BOOL or t == INT or t == PRINT_MODE or t == ERROR_CODE: + elif t == BOOL: + return '(' + ts + ') Bool_val(' + s + ')' + elif t == INT or t == PRINT_MODE or t == ERROR_CODE: return '(' + ts + ') Int_val(' + s + ')' elif t == UINT: return '(' + ts + ') Unsigned_int_val(' + s + ')' @@ -1125,7 +1127,9 @@ def ml_unwrap(t, ts, s): def ml_set_wrap(t, d, n): if t == VOID: return d + ' = Val_unit;' - elif t == BOOL or t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE: + elif t == BOOL: + return d + ' = Val_bool(' + n + ');' + elif t == INT or t == UINT or t == PRINT_MODE or t == ERROR_CODE: return d + ' = Val_int(' + n + ');' elif t == INT64 or t == UINT64: return d + ' = Val_long(' + n + ');' diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index fee6f9fe0..b4d58711c 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -874,7 +874,7 @@ struct if a#gnc != b#gnc then false else - ((lbool_of_int (Z3native.is_eq_sort a#gnc a#gno b#gno)) == L_TRUE) + (Z3native.is_eq_sort a#gnc a#gno b#gno) (** Returns a unique identifier for the sort. @@ -922,10 +922,10 @@ let create_expr ctx obj = else let s = Z3native.get_sort ctx#gno obj in let sk = (sort_kind_of_int (Z3native.get_sort_kind ctx#gno s)) in - if (lbool_of_int (Z3native.is_algebraic_number ctx#gno obj) == L_TRUE) then + if (Z3native.is_algebraic_number ctx#gno obj) then (((new algebraic_num ctx)#cnstr_obj obj) :> expr) else - if ((lbool_of_int (Z3native.is_numeral_ast ctx#gno obj)) == L_TRUE) && + if (Z3native.is_numeral_ast ctx#gno obj) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) @@ -1016,6 +1016,7 @@ struct raise (Z3native.Exception "parameter is not a ratinoal string") else x#rational + end (** Creates a new function declaration. @@ -1058,7 +1059,6 @@ struct let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = (new func_decl ctx)#cnstr_pdr prefix [||] range - end (** Comparison operator. @@ -1071,7 +1071,7 @@ struct if a#gnc == a#gnc then false else - ((lbool_of_int (Z3native.is_eq_func_decl a#gnc a#gno b#gno)) == L_TRUE) + (Z3native.is_eq_func_decl a#gnc a#gno b#gno) (** A string representations of the function declaration. *) @@ -1202,7 +1202,7 @@ struct @param k An AST @return True if is a key in the map, false otherwise. *) let contains ( m : ast_map ) ( key : ast ) = - (lbool_of_int (Z3native.ast_map_contains m#gnc m#gno key#gno)) == L_TRUE + (Z3native.ast_map_contains m#gnc m#gno key#gno) (** Finds the value associated with the key . @@ -1313,7 +1313,7 @@ struct if a#gnc == b#gnc then false else - ((lbool_of_int (Z3native.is_eq_ast a#gnc a#gno b#gno)) == L_TRUE) + (Z3native.is_eq_ast a#gnc a#gno b#gno) (** Object Comparison. @@ -1472,13 +1472,13 @@ struct (** Indicates whether the term is a numeral *) - let is_numeral ( x : expr ) = lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno) == L_TRUE + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast x#gnc x#gno) (** Indicates whether the term is well-sorted. @return True if the term is well-sorted, false otherwise. *) - let is_well_sorted ( x : expr ) = lbool_of_int (Z3native.is_well_sorted x#gnc x#gno) == L_TRUE + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted x#gnc x#gno (** The Sort of the term. @@ -1489,9 +1489,9 @@ struct Indicates whether the term has Boolean sort. *) let is_bool ( x : expr ) = (AST.is_expr x) && - (lbool_of_int (Z3native.is_eq_sort x#gnc - (Z3native.mk_bool_sort x#gnc) - (Z3native.get_sort x#gnc x#gno))) == L_TRUE + (Z3native.is_eq_sort x#gnc + (Z3native.mk_bool_sort x#gnc) + (Z3native.get_sort x#gnc x#gno)) (** Indicates whether the term represents a constant. @@ -1774,7 +1774,7 @@ struct Indicates whether the quantifier is universal. *) let is_universal ( x : quantifier ) = - lbool_of_int (Z3native.is_quantifier_forall x#gnc x#gno) == L_TRUE + Z3native.is_quantifier_forall x#gnc x#gno (** Indicates whether the quantifier is existential. @@ -1879,7 +1879,7 @@ struct if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno (int_of_lbool L_TRUE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno true (match weight with | None -> 1 | Some(x) -> x) (match patterns with | None -> 0 | Some(x) -> (Array.length x)) (match patterns with | None -> [||] | Some(x) -> (patternaton x)) @@ -1888,7 +1888,7 @@ struct body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno (int_of_lbool L_TRUE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) @@ -1905,7 +1905,7 @@ struct *) let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno (int_of_lbool L_TRUE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno true (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expraton bound_constants) (match patterns with | None -> 0 | Some(x) -> (Array.length x)) @@ -1913,7 +1913,7 @@ struct body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno (int_of_lbool L_TRUE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) @@ -1931,7 +1931,7 @@ struct if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno (int_of_lbool L_FALSE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno false (match weight with | None -> 1 | Some(x) -> x) (match patterns with | None -> 0 | Some(x) -> (Array.length x)) (match patterns with | None -> [||] | Some(x) -> (patternaton x)) @@ -1940,7 +1940,7 @@ struct body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno (int_of_lbool L_FALSE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) @@ -1957,7 +1957,7 @@ struct *) let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno (int_of_lbool L_FALSE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno false (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expraton bound_constants) (match patterns with | None -> 0 | Some(x) -> (Array.length x)) @@ -1965,7 +1965,7 @@ struct body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno (int_of_lbool L_FALSE) + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) @@ -2046,7 +2046,7 @@ struct Indicates whether the term is of an array sort. *) let is_array ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (Z3native.is_app x#gnc x#gno) && ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) (** The domain of the array sort. *) @@ -2252,7 +2252,7 @@ struct Indicates whether the term is of an array sort. *) let is_finite_domain ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && + (Z3native.is_app x#gnc x#gno) && (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) (** @@ -2263,7 +2263,7 @@ struct (** The size of the finite domain sort. *) let get_size (x : finite_domain_sort) = let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v + if r then v else raise (Z3native.Exception "Conversion failed.") end @@ -2274,8 +2274,8 @@ struct Indicates whether the term is of a relation sort. *) let is_relation ( x : expr ) = - ((lbool_of_int (Z3native.is_app x#gnc x#gno)) == L_TRUE) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT) + ((Z3native.is_app x#gnc x#gno) && + (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT)) (** Indicates whether the term is an relation store @@ -2604,7 +2604,7 @@ struct Indicates whether the term is of integer sort. *) let is_int ( x : expr ) = - ((lbool_of_int (Z3native.is_numeral_ast x#gnc x#gno)) == L_TRUE) && + (Z3native.is_numeral_ast x#gnc x#gno) && ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) (** @@ -2706,12 +2706,13 @@ struct (** Indicates whether the term is an algebraic number *) - let is_algebraic_number ( x : expr ) = lbool_of_int(Z3native.is_algebraic_number x#gnc x#gno) == L_TRUE + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number x#gnc x#gno (** Retrieve the int value. *) - let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") + let get_int ( x : int_num ) = + let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if r then v + else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -3219,9 +3220,10 @@ struct let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno (** Retrieve the int value. *) - let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if lbool_of_int(r) == L_TRUE then v - else raise (Z3native.Exception "Conversion failed.") + let get_int ( x : bitvec_num ) = + let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + if r then v + else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -3613,7 +3615,7 @@ struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int ctx#gno t#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int ctx#gno t#gno signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3621,7 +3623,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow ctx#gno t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3645,7 +3647,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow ctx#gno t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3669,7 +3671,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow ctx#gno t1#gno t2#gno (int_of_lbool (if (signed) then L_TRUE else L_FALSE))) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow ctx#gno t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -4198,7 +4200,7 @@ end Adds a parameter setting. *) let add_bool (p : params) (name : symbol) (value : bool) = - Z3native.params_set_bool p#gnc p#gno name#gno (int_of_lbool (if value then L_TRUE else L_FALSE)) + Z3native.params_set_bool p#gnc p#gno name#gno value (** Adds a parameter setting. @@ -4291,11 +4293,12 @@ struct (* CMW: assert seems to be a keyword. *) let assert_ ( x : goal ) ( constraints : bool_expr array ) = let f e = Z3native.goal_assert x#gnc x#gno e#gno in - Array.map f constraints + ignore (Array.map f constraints) ; + () (** Indicates whether the goal contains `false'. *) let is_inconsistent ( x : goal ) = - (lbool_of_int (Z3native.goal_inconsistent x#gnc x#gno)) == L_TRUE + Z3native.goal_inconsistent x#gnc x#gno (** The depth of the goal. This tracks how many transformations were applied to it. *) @@ -4318,11 +4321,11 @@ struct (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) let is_decided_sat ( x : goal ) = - (lbool_of_int (Z3native.goal_is_decided_sat x#gnc x#gno)) == L_TRUE + Z3native.goal_is_decided_sat x#gnc x#gno (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) let is_decided_unsat ( x : goal ) = - (lbool_of_int (Z3native.goal_is_decided_unsat x#gnc x#gno)) == L_TRUE + Z3native.goal_is_decided_unsat x#gnc x#gno (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = @@ -4357,10 +4360,7 @@ struct @param proofs Indicates whether proof generation should be enabled. *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - (new goal ctx)#cnstr_obj (Z3native.mk_goal ctx#gno - (int_of_lbool (if models then L_TRUE else L_FALSE)) - (int_of_lbool (if unsat_cores then L_TRUE else L_FALSE)) - (int_of_lbool (if proofs then L_TRUE else L_FALSE))) + (new goal ctx)#cnstr_obj (Z3native.mk_goal ctx#gno models unsat_cores proofs) (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno @@ -4729,7 +4729,7 @@ struct let n = (get_size x ) in let f i = ( let k = Z3native.stats_get_key x#gnc x#gno i in - if (lbool_of_int (Z3native.stats_is_uint x#gnc x#gno i)) == L_TRUE then + if (Z3native.stats_is_uint x#gnc x#gno i) then ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) else ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) @@ -4800,7 +4800,8 @@ struct *) let assert_ ( x : solver ) ( constraints : bool_expr array ) = let f e = (Z3native.solver_assert x#gnc x#gno e#gno) in - Array.map f constraints + ignore (Array.map f constraints) ; + () (** The number of assertions in the solver. @@ -5049,7 +5050,7 @@ struct else match sk with | ARRAY_SORT -> - if (lbool_of_int (Z3native.is_as_array x#gnc n)) == L_FALSE then + if not (Z3native.is_as_array x#gnc n) then raise (Z3native.Exception "Argument was not an array constant") else let fd = Z3native.get_as_array_func_decl x#gnc n in @@ -5105,8 +5106,8 @@ struct The evaluation of in the model. *) let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno (int_of_lbool (if completion then L_TRUE else L_FALSE))) in - if (lbool_of_int r) == L_FALSE then + let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno completion) in + if not r then raise (ModelEvaluationFailedException "evaluation failed") else create_expr x#gc v @@ -5175,7 +5176,8 @@ struct *) let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = let f e = (Z3native.fixedpoint_assert x#gnc x#gno e#gno) in - Array.map f constraints + ignore (Array.map f constraints) ; + () (** Register predicate as recursive relation. @@ -5353,7 +5355,7 @@ struct *) let get_param_value ( ctx : context ) ( id : string ) = let (r, v) = (Z3native.get_param_value ctx#gno id) in - if ((lbool_of_int r) == L_FALSE) then + if not r then None else Some v @@ -5383,7 +5385,7 @@ struct all contexts globally. *) let toggle_warning_messages ( enabled: bool ) = - Z3native.toggle_warning_messages (int_of_lbool (if enabled then L_TRUE else L_FALSE)) + Z3native.toggle_warning_messages enabled end (** Functions for handling SMT and SMT2 expressions and files *) From c03d5277bc179a561083151549177f33fe087823 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 26 Dec 2012 16:54:45 +0000 Subject: [PATCH 150/248] more ML Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 58 +++++++++++++++++++++------------------ src/api/ml/z3.ml | 4 +++ 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 945c9a494..7fcd2e9f7 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -10,11 +10,12 @@ open Z3.Expr open Z3.FuncDecl open Z3.Goal open Z3.Tactic +open Z3.Tactic.ApplyResult open Z3.Probe open Z3.Solver open Z3.Arithmetic -exception ExampleException of string +exception TestFailedException of string (** @@ -43,32 +44,37 @@ let basic_tests ( ctx : context ) = let solver = (mk_solver ctx None) in (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; if (check solver None) != SATISFIABLE then - raise (ExampleException "") + raise (TestFailedException "") else Printf.printf "Test passed.\n" ; - () - -(* - ApplyResult ar = ApplyTactic(ctx, ctx.MkTactic("simplify"), g); - if (ar.NumSubgoals == 1 && (ar.Subgoals[0].IsDecidedSat || ar.Subgoals[0].IsDecidedUnsat)) - throw new TestFailedException(); - - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) - throw new TestFailedException(); - - g.Assert(ctx.MkEq(ctx.MkNumeral(1, ctx.MkBitVecSort(32)), - ctx.MkNumeral(2, ctx.MkBitVecSort(32)))); - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) - throw new TestFailedException(); - - - Goal g2 = ctx.MkGoal(true, true); - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedSat) - throw new TestFailedException(); - + () ; + let ar = (Tactic.apply (mk_tactic ctx "simplify") g None) in + if ((get_num_subgoals ar) == 1 && + ((is_decided_sat (get_subgoal ar 0)) || + (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_sat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + (Goal.assert_ g [| (mk_eq ctx (mk_numeral_int ctx 1 (BitVectors.mk_sort ctx 32)) + (mk_numeral_int ctx 2 (BitVectors.mk_sort ctx 32))) |] ) + ; + let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + let g2 = (mk_goal ctx true true false) in + let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_sat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + () +(* g2 = ctx.MkGoal(true, true); g2.Assert(ctx.MkFalse()); ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); @@ -131,7 +137,7 @@ let basic_tests ( ctx : context ) = let _ = if not (Log.open_ "z3.log") then - raise (ExampleException "Log couldn't be opened.") + raise (TestFailedException "Log couldn't be opened.") else ( Printf.printf "Running Z3 version %s\n" Version.to_string ; diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index b4d58711c..8806a70ee 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -4391,6 +4391,10 @@ struct let n = (get_num_subgoals x) in let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in Array.init n f + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoal ( x : apply_result ) ( i : int ) = + (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) (** Convert a model for the subgoal into a model for the original goal g, that the ApplyResult was obtained from. From e2f6b10e3200bef881e0e3dcd2d84c8ab5570d37 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 27 Dec 2012 15:51:42 +0000 Subject: [PATCH 151/248] ML API bugfixes More ML examples Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 165 ++++++++++++++++++++++++++------------ src/api/ml/z3.ml | 5 ++ 2 files changed, 119 insertions(+), 51 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 7fcd2e9f7..0e8122ae0 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -17,6 +17,50 @@ open Z3.Arithmetic exception TestFailedException of string +(** + Model Converter test +*) +let model_converter_test ( ctx : context ) = + Printf.printf "ModelConverterTest\n"; + let xr = ((mk_const ctx ((Symbol.mk_string ctx "x") :> symbol) (mk_real_sort ctx )) :> arith_expr) in + let yr = ((mk_const ctx ((Symbol.mk_string ctx "y") :> symbol) (mk_real_sort ctx )) :> arith_expr) in + let g4 = (mk_goal ctx true false false ) in + (Goal.assert_ g4 [| (mk_gt ctx xr (mk_real_numeral_nd ctx 10 1)) |]) ; + (Goal.assert_ g4 [| (mk_eq ctx yr (mk_add ctx [| xr; (mk_real_numeral_nd ctx 1 1) |] )) |] ) ; + (Goal.assert_ g4 [| (mk_gt ctx yr (mk_real_numeral_nd ctx 1 1)) |]) ; + ( + let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in + if ((get_num_subgoals ar) == 1 && + ((is_decided_sat (get_subgoal ar 0)) || + (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") None) g4 None) in + if ((get_num_subgoals ar) == 1 && + ((is_decided_sat (get_subgoal ar 0)) || + (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ; + let solver = (mk_solver ctx None) in + let f e = (Solver.assert_ solver [| e |]) in + ignore (Array.map f (get_formulas (get_subgoal ar 0))) ; + let q = (check solver None) in + if q != SATISFIABLE then + raise (TestFailedException "") + else + let m = (get_model solver) in + match m with + | None -> raise (TestFailedException "") + | Some (m) -> + Printf.printf "Solver says: %s\n" (string_of_status q) ; + Printf.printf "Model: \n%s\n" (Model.to_string m) ; + Printf.printf "Converted Model: \n%s\n" (Model.to_string (convert_model ar 0 m)) + ) (** Some basic tests. @@ -41,59 +85,78 @@ let basic_tests ( ctx : context ) = (Goal.assert_ g [| trivial_eq |]) ; (Goal.assert_ g [| nontrivial_eq |]) ; Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; - let solver = (mk_solver ctx None) in - (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; - if (check solver None) != SATISFIABLE then - raise (TestFailedException "") - else - Printf.printf "Test passed.\n" ; - () ; - let ar = (Tactic.apply (mk_tactic ctx "simplify") g None) in - if ((get_num_subgoals ar) == 1 && - ((is_decided_sat (get_subgoal ar 0)) || - (is_decided_unsat (get_subgoal ar 0)))) then + ( + let solver = (mk_solver ctx None) in + (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; + if (check solver None) != SATISFIABLE then raise (TestFailedException "") else - let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_sat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - (Goal.assert_ g [| (mk_eq ctx (mk_numeral_int ctx 1 (BitVectors.mk_sort ctx 32)) - (mk_numeral_int ctx 2 (BitVectors.mk_sort ctx 32))) |] ) - ; - let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_unsat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - let g2 = (mk_goal ctx true true false) in - let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in - if ((get_num_subgoals ar) == 1 && - (not (is_decided_sat (get_subgoal ar 0)))) then - raise (TestFailedException "") - else - () -(* - g2 = ctx.MkGoal(true, true); - g2.Assert(ctx.MkFalse()); - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g2); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) - throw new TestFailedException(); - - Goal g3 = ctx.MkGoal(true, true); - Expr xc = ctx.MkConst(ctx.MkSymbol("x"), ctx.IntSort); - Expr yc = ctx.MkConst(ctx.MkSymbol("y"), ctx.IntSort); - g3.Assert(ctx.MkEq(xc, ctx.MkNumeral(1, ctx.IntSort))); - g3.Assert(ctx.MkEq(yc, ctx.MkNumeral(2, ctx.IntSort))); - BoolExpr constr = ctx.MkEq(xc, yc); - g3.Assert(constr); - ar = ApplyTactic(ctx, ctx.MkTactic("smt"), g3); - if (ar.NumSubgoals != 1 || !ar.Subgoals[0].IsDecidedUnsat) - throw new TestFailedException(); - - ModelConverterTest(ctx); - + Printf.printf "Test passed.\n" + ); + ( + let ar = (Tactic.apply (mk_tactic ctx "simplify") g None) in + if ((get_num_subgoals ar) == 1 && + ((is_decided_sat (get_subgoal ar 0)) || + (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_sat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + (Goal.assert_ g [| (mk_eq ctx (mk_numeral_int ctx 1 (BitVectors.mk_sort ctx 32)) + (mk_numeral_int ctx 2 (BitVectors.mk_sort ctx 32))) |] ) + ; + ( + let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let g2 = (mk_goal ctx true true false) in + let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_sat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let g2 = (mk_goal ctx true true false) in + (Goal.assert_ g2 [| (mk_false ctx) |]) ; + let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); + ( + let g3 = (mk_goal ctx true true false) in + let xc = (mk_const ctx ((Symbol.mk_string ctx "x") :> symbol) (mk_int_sort ctx)) in + let yc = (mk_const ctx ((Symbol.mk_string ctx "y") :> symbol) (mk_int_sort ctx)) in + (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (mk_int_sort ctx))) |]) ; + (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (mk_int_sort ctx))) |]) ; + let constr = (mk_eq ctx xc yc) in + (Goal.assert_ g3 [| constr |] ) ; + let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in + if ((get_num_subgoals ar) == 1 && + (not (is_decided_unsat (get_subgoal ar 0)))) then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ) ; + model_converter_test ctx +(* // Real num/den test. RatNum rn = ctx.MkReal(42, 43); Expr inum = rn.Numerator; diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 8806a70ee..c0711b4eb 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -4684,6 +4684,11 @@ module Solver = struct type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + let string_of_status ( s : status) = match s with + | UNSATISFIABLE -> "unsatisfiable" + | SATISFIABLE -> "satisfiable" + | _ -> "unknown" + (** Objects that track statistical information about solvers. *) module Statistics = struct From 7eb95bf6c20943f9324e52b1671d11ebfb6537b5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 7 Jan 2013 15:32:25 +0000 Subject: [PATCH 152/248] ML API: made native layer ANSI-C compliant to avoid compilation issues. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 5 +++- scripts/update_api.py | 55 ++++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 849644a18..020653272 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1440,7 +1440,10 @@ class MLComponent(Component): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) + if WINDOWS: + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) + else: + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) out.write('z3.cmxa: %s\n' % libfile) out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) out.write('z3.cma: %s\n' % libfile) diff --git a/scripts/update_api.py b/scripts/update_api.py index 5d95a12f8..1986f4a7e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1262,39 +1262,39 @@ def mk_ml(): ml_wrapper.write('#include \n\n') ml_wrapper.write('#define CAMLlocal6(X1,X2,X3,X4,X5,X6) \\\n') ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal1(X6); \n') + ml_wrapper.write(' CAMLlocal1(X6) \n') ml_wrapper.write('#define CAMLlocal7(X1,X2,X3,X4,X5,X6,X7) \\\n') ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal2(X6,X7); \n') + ml_wrapper.write(' CAMLlocal2(X6,X7) \n') ml_wrapper.write('#define CAMLlocal8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') ml_wrapper.write(' CAMLlocal5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLlocal3(X6,X7,X8); \n') + ml_wrapper.write(' CAMLlocal3(X6,X7,X8) \n') ml_wrapper.write('\n') ml_wrapper.write('#define CAMLparam7(X1,X2,X3,X4,X5,X6,X7) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam2(X6,X7); \n') + ml_wrapper.write(' CAMLxparam2(X6,X7) \n') ml_wrapper.write('#define CAMLparam8(X1,X2,X3,X4,X5,X6,X7,X8) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam3(X6,X7,X8); \n') + ml_wrapper.write(' CAMLxparam3(X6,X7,X8) \n') ml_wrapper.write('#define CAMLparam9(X1,X2,X3,X4,X5,X6,X7,X8,X9) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') - ml_wrapper.write(' CAMLxparam4(X6,X7,X8,X9); \n') + ml_wrapper.write(' CAMLxparam4(X6,X7,X8,X9) \n') ml_wrapper.write('#define CAMLparam12(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') - ml_wrapper.write(' CAMLxparam2(X11,X12); \n') + ml_wrapper.write(' CAMLxparam2(X11,X12) \n') ml_wrapper.write('#define CAMLparam13(X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13) \\\n') ml_wrapper.write(' CAMLparam5(X1,X2,X3,X4,X5); \\\n') ml_wrapper.write(' CAMLxparam5(X6,X7,X8,X9,X10); \\\n') - ml_wrapper.write(' CAMLxparam3(X11,X12,X13); \n') + ml_wrapper.write(' CAMLxparam3(X11,X12,X13) \n') ml_wrapper.write('\n\n') ml_wrapper.write('static struct custom_operations default_custom_ops = {\n') - ml_wrapper.write(' identifier: (char*) "default handling",\n') - ml_wrapper.write(' finalize: custom_finalize_default,\n') - ml_wrapper.write(' compare: custom_compare_default,\n') - ml_wrapper.write(' hash: custom_hash_default,\n') - ml_wrapper.write(' serialize: custom_serialize_default,\n') - ml_wrapper.write(' deserialize: custom_deserialize_default\n') + ml_wrapper.write(' (char*) "default handling",\n') + ml_wrapper.write(' custom_finalize_default,\n') + ml_wrapper.write(' custom_compare_default,\n') + ml_wrapper.write(' custom_hash_default,\n') + ml_wrapper.write(' custom_serialize_default,\n') + ml_wrapper.write(' custom_deserialize_default\n') ml_wrapper.write('};\n\n') ml_wrapper.write('#ifdef __cplusplus\n') ml_wrapper.write('extern "C" {\n') @@ -1358,7 +1358,10 @@ def mk_ml(): i = i + 1 ml_wrapper.write(');\n') - # preprocess arrays, strings, in/out arguments + if len(ap) != 0: + ml_wrapper.write(' unsigned _i;\n') + + # declare locals, preprocess arrays, strings, in/out arguments i = 0 for param in params: k = param_kind(param) @@ -1372,22 +1375,32 @@ def mk_ml(): elif k == IN_ARRAY or k == INOUT_ARRAY: t = param_type(param) ts = type2str(t) - ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) - ml_wrapper.write(' for (unsigned i = 0; i < _a%s; i++) _a%s[i] = %s;\n' % (param_array_capacity_pos(param), i, ml_unwrap(t, ts, 'Field(a' + str(i) + ', i)'))) + ml_wrapper.write(' %s * _a%s = (%s*) malloc(sizeof(%s) * _a%s);\n' % (ts, i, ts, ts, param_array_capacity_pos(param))) elif k == IN: t = param_type(param) ml_wrapper.write(' %s _a%s = %s;\n' % (type2str(t), i, ml_unwrap(t, type2str(t), 'a' + str(i)))) elif k == OUT: ml_wrapper.write(' %s _a%s;\n' % (type2str(param_type(param)), i)) elif k == INOUT: - ml_wrapper.write(' %s _a%s = a%s;\n' % (type2str(param_type(param)), i, i)) - + ml_wrapper.write(' %s _a%s = a%s;\n' % (type2str(param_type(param)), i, i)) + i = i + 1 + + if result != VOID: + ml_wrapper.write(' %s z3_result;\n' % type2str(result)) + + i = 0 + for param in params: + k = param_kind(param) + if k == IN_ARRAY or k == INOUT_ARRAY: + t = param_type(param) + ts = type2str(t) + ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { _a%s[_i] = %s; }\n' % (param_array_capacity_pos(param), i, ml_unwrap(t, ts, 'Field(a' + str(i) + ', _i)'))) i = i + 1 # invoke procedure ml_wrapper.write(' ') if result != VOID: - ml_wrapper.write('%s z3_result = ' % type2str(result)) + ml_wrapper.write('z3_result = ') ml_wrapper.write('%s(' % name) i = 0 first = True @@ -1412,7 +1425,7 @@ def mk_ml(): for p in params: if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) - ml_wrapper.write(' for (unsigned i = 0; i < _a%s; i++) { value t; %s Store_field(_a%s, i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[i]'), i)) + ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) elif is_out_param(p): ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) i = i + 1 From 3e8c1e3a29494a6b893f5015ba2dccce9477a2d5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 7 Jan 2013 18:56:19 +0000 Subject: [PATCH 153/248] ML API: bugfix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 020653272..9bb0e0efe 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1440,7 +1440,7 @@ class MLComponent(Component): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) - if WINDOWS: + if IS_WINDOWS: out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) else: out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) From 4a606dbe600d09fb8b9db059583a865edea4b5be Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 7 Jan 2013 22:44:55 +0000 Subject: [PATCH 154/248] ML API: bugfix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 9bb0e0efe..9dcf43813 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1439,7 +1439,7 @@ class MLComponent(Component): for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I%s -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) + out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I"%s" -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) if IS_WINDOWS: out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) else: From 49dd2e4a07a48ce106c86cb0b6fefee804bc47ee Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 8 Jan 2013 20:56:49 +0000 Subject: [PATCH 155/248] ML API: build system changes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 48 +++++++++++++++++++++++++++++++++++----------- src/api/ml/README | 2 +- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 9dcf43813..4c39ff13b 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1342,6 +1342,7 @@ class MLComponent(Component): def mk_makefile(self, out): if is_ml_enabled(): +<<<<<<< HEAD CP_CMD = "cp" if IS_WINDOWS: CP_CMD = "copy" @@ -1436,18 +1437,31 @@ class MLComponent(Component): mk_dir(bld_dir) libfile = '%s$(SO_EXT)' % self.lib_name out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'z3native.c'))) +======= + src_dir = self.to_src_dir + sub_dir = os.path.join('api', 'ml') + mk_dir(os.path.join(BUILD_DIR, sub_dir)) + for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): + shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) + for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): + shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) + out.write('z3.cmxa:') + for mlfile in get_ml_files(self.src_dir): + out.write(' %s' % os.path.join(src_dir, mlfile)) + out.write('\n') + out.write('\tpushd %s && %s ' % (sub_dir, OCAMLOPT)) + if DEBUG_MODE: + out.write('-g ') + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cmxa -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) + out.write('z3.cma:') +>>>>>>> ML API: build system changes for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\t$(CXX) $(CXXFLAGS) $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT) -I"%s" -I%s %s/z3native.c\n' % (get_component(API_COMPONENT).to_src_dir, OCAML_LIB, self.to_src_dir)) - if IS_WINDOWS: - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(LIB_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) - else: - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)%s $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' % (libfile, os.path.join('api', 'ml', 'z3native'))) - out.write('z3.cmxa: %s\n' % libfile) - out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3.cmxa z3native$(OBJ_EXT) && cd -\n' % (self.to_src_dir,BUILD_DIR)) - out.write('z3.cma: %s\n' % libfile) - out.write('\tcd %s && ocamlbuild -cflags \'-g\' -lflags -custom,-cclib,-L../..,-cclib,-lz3,-cclib,-lz3ml,-linkall -build-dir ../../../%s/api/ml z3native$(OBJ_EXT) z3.cma && cd -\n' % (self.to_src_dir,BUILD_DIR)) + out.write('\tpushd %s && %s ' % (sub_dir, OCAMLC)) + if DEBUG_MODE: + out.write('-g ') + out.write('-custom -ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cma -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) out.write('ml: z3.cmxa z3.cma\n') out.write('\n') @@ -1576,7 +1590,10 @@ class MLExampleComponent(ExampleComponent): for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') - out.write('\tocamlc -g -o ml_example.byte -I . z3.cma -I api/ml') + out.write('\t%s ' % OCAMLC) + if DEBUG_MODE: + out.write('-g ') + out.write('-custom -o ml_example.byte -I . z3.cma -I api/ml') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') @@ -1584,7 +1601,10 @@ class MLExampleComponent(ExampleComponent): for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') - out.write('\tocamlopt -g -o ml_example -I . z3.cmxa -I api/ml') + out.write('\t%s ' % OCAMLOPT) + if DEBUG_MODE: + out.write('-g ') + out.write('-o ml_example($EXE_EXT) -I . z3.cmxa -I api/ml') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') @@ -1862,9 +1882,15 @@ def mk_config(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) if is_ml_enabled(): +<<<<<<< HEAD print('Ocaml Compiler: %s' % OCAMLC) print('Ocaml Native: %s' % OCAMLOPT) print('Ocaml Library: %s' % OCAML_LIB) +======= + print('OCaml Compiler: %s' % OCAMLC) + print('OCaml Native: %s' % OCAMLOPT) + print('OCaml Library: %s' % OCAML_LIB) +>>>>>>> ML API: build system changes def mk_install(out): out.write('install: ') diff --git a/src/api/ml/README b/src/api/ml/README index 36f903925..beee7d864 100644 --- a/src/api/ml/README +++ b/src/api/ml/README @@ -5,4 +5,4 @@ We are currently working on a brand new ML API. On Windows, there are no less than four different ports of OCaml. The Z3 build system assumes that either the win32 or the win64 port is installed. This means that OCaml will use `cl' as the underlying C compiler and not the cygwin or -mingw compilers. +mingw compilers. \ No newline at end of file From 09292437db25600e12a590ea6151784005843f3c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 8 Jan 2013 21:02:44 +0000 Subject: [PATCH 156/248] ML API: build system fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 4c39ff13b..503c3dadd 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -357,6 +357,7 @@ def check_ml(): rmf('hello.cmo') rmf('hello.cmx') rmf('a.out') + t.__del__() find_ml_lib() find_ocaml_find() From f94fa8544476845742078bad95b1627cdec6f0bb Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 8 Jan 2013 21:22:45 +0000 Subject: [PATCH 157/248] ML API: build system fix --- scripts/mk_util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 503c3dadd..4c39ff13b 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -357,7 +357,6 @@ def check_ml(): rmf('hello.cmo') rmf('hello.cmx') rmf('a.out') - t.__del__() find_ml_lib() find_ocaml_find() From f0e61ee52342dccf32039b44186afb4c77ac71f3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 10 Jan 2013 17:25:55 +0000 Subject: [PATCH 158/248] ML API: build system fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 128 ++++++--------------------------------------- 1 file changed, 15 insertions(+), 113 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 4c39ff13b..c7b48b891 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1342,102 +1342,6 @@ class MLComponent(Component): def mk_makefile(self, out): if is_ml_enabled(): -<<<<<<< HEAD - CP_CMD = "cp" - if IS_WINDOWS: - CP_CMD = "copy" - src_dir = self.to_src_dir - sub_dir = os.path.join('api', 'ml') - mk_dir(os.path.join(BUILD_DIR, sub_dir)) - api_src = get_component(API_COMPONENT).to_src_dir - for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): - out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) - str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) - out.write(str) - for f in filter(lambda f: f.endswith('.mli'), os.listdir(self.src_dir)): - out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) - str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) - out.write(str) - for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): - out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) - str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) - out.write(str) - modules = ["z3enums", "z3native", "z3"] # dependencies in this order! - mls = '' - mlis = '' - cmis = '' - archives = '' - - for m in modules: - fn = os.path.join(self.src_dir, ('%s.mli' % m)) - if not os.path.exists(fn): - out.write('%s.mli: %s.ml%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),mlis)) - out.write('\t%s -I %s -i -c %s.ml > %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir, m),os.path.join(sub_dir, m))) - out.write('%s.cmi: %s.mli%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m), cmis)) - out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) - out.write('%s.cma: %s.ml %s.cmi%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),os.path.join(sub_dir,m), archives)) - out.write('\t%s -a -o %s.ml -o %s.cma\n' % (OCAMLC,os.path.join(sub_dir,m), os.path.join(sub_dir,m))) - mlis = mlis + ' ' + os.path.join(sub_dir, m) + '.mli' - cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - archives = archives + ' ' + os.path.join(sub_dir,m) + '.cma' - mls = mls + ' ' + os.path.join(sub_dir, m) + '.ml' - - out.write('%s: %s %s\n' % - (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'), - os.path.join(sub_dir, 'z3native_stubs.c'), - get_component(Z3_DLL_COMPONENT).dll_name+'$(SO_EXT)')); - out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s $(CXX_OUT_FLAG)%s$(OBJ_EXT)\n' % - (OCAML_LIB, api_src, os.path.join(sub_dir, 'z3native_stubs.c'), os.path.join(sub_dir, 'z3native_stubs'))) - - out.write('%s: %s %s %s$(SO_EXT)' % ( - os.path.join(sub_dir, "z3ml.cmxa"), - cmis, - archives, - get_component(Z3_DLL_COMPONENT).dll_name)) - out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) - out.write('\tocamlmklib -o %s -I %s -ldopt \"-L. -lz3\" ' % (os.path.join(sub_dir, 'z3ml'), sub_dir)) - for m in modules: - out.write(' %s' % (os.path.join(sub_dir, m+'.ml'))) - out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) - out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3ml.cmxa'))) - self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) - if OCAMLFIND != '': - out.write('\nocamlfind_install: %s %s %s\n' % ( - get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)', - os.path.join(sub_dir, 'z3ml.cmxa'), - os.path.join(sub_dir, 'META'))) - out.write('\t%s remove Z3\n' % (OCAMLFIND)) - out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) - for m in modules: - out.write(' %s.cma' % (os.path.join(sub_dir, m))) - out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - out.write(' %s.cmi' % (os.path.join(sub_dir, m))) - out.write(' %s.cmo' % (os.path.join(sub_dir, m))) - out.write(' %s.ml' % (os.path.join(sub_dir, m))) - out.write(' %s.mli' % (os.path.join(sub_dir, m))) - out.write(' %s$(OBJ_EXT)' % (os.path.join(sub_dir, m))) - out.write(' %s' % ((os.path.join(sub_dir, 'z3ml$(LIB_EXT)')))) - out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cma')))) - out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cmxa')))) - out.write(' %s' % ((os.path.join(sub_dir, 'libz3ml$(LIB_EXT)')))) - out.write(' %s' % ((os.path.join(sub_dir, 'dllz3ml')))) - if IS_WINDOWS: - out.write('.dll') - else: - out.write('.so') # .so also on OSX! - out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)') - if IS_WINDOWS: - out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(LIB_EXT)') - out.write('\n\n') - deffile = open('%s.mllib' % os.path.join(self.src_dir, "z3"), 'w') - for mlfile in get_ml_files(self.src_dir): - deffile.write('%s\n' % (string.upper(mlfile[0]) + mlfile[1:-3])) - deffile.close() - bld_dir = os.path.join(BUILD_DIR, 'api', 'ml') - mk_dir(bld_dir) - libfile = '%s$(SO_EXT)' % self.lib_name - out.write('%s: libz3$(SO_EXT) %s' % (libfile, os.path.join(self.to_src_dir, 'z3native.c'))) -======= src_dir = self.to_src_dir sub_dir = os.path.join('api', 'ml') mk_dir(os.path.join(BUILD_DIR, sub_dir)) @@ -1445,24 +1349,28 @@ class MLComponent(Component): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) - out.write('z3.cmxa:') + out.write('libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CXX) $(CXXFLAGS) -I %s api/ml/z3native.c $(CXX_OUTFLAG) api/ml/z3native$(OBJ_EXT)\n' % get_component(API_COMPONENT).to_src_dir) + out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG) libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') + out.write('api/ml/z3.cmxa: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(src_dir, mlfile)) out.write('\n') - out.write('\tpushd %s && %s ' % (sub_dir, OCAMLOPT)) + out.write('\tcd %s && %s ' % (sub_dir, OCAMLOPT)) if DEBUG_MODE: out.write('-g ') out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cmxa -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) out.write('z3.cma:') ->>>>>>> ML API: build system changes + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" z3enums.ml z3native.ml z3.ml -a -o z3.cmxa -linkall && cd ../..\n' % get_component(API_COMPONENT).to_src_dir) + out.write('api/ml/z3.cma: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\tpushd %s && %s ' % (sub_dir, OCAMLC)) + out.write('\tcd %s && %s ' % (sub_dir, OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-custom -ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cma -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) - out.write('ml: z3.cmxa z3.cma\n') + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" z3enums.ml z3native.ml z3.ml -a -o z3.cma -linkall && cd ../..\n' % get_component(API_COMPONENT).to_src_dir) + out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') out.write('\n') def main_component(self): @@ -1586,29 +1494,29 @@ class MLExampleComponent(ExampleComponent): def mk_makefile(self, out): if ML_ENABLED: - out.write('ml_example.byte: z3.cma ') + out.write('ml_example.byte: api/ml/z3.cma ') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') out.write('\t%s ' % OCAMLC) if DEBUG_MODE: out.write('-g ') - out.write('-custom -o ml_example.byte -I . z3.cma -I api/ml') + out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" z3.cma') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('ml_example($EXE_EXT): z3.cmxa ml_example.byte') + out.write('ml_example$(EXE_EXT): api/ml/z3.cmxa ml_example.byte') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') out.write('\t%s ' % OCAMLOPT) if DEBUG_MODE: out.write('-g ') - out.write('-o ml_example($EXE_EXT) -I . z3.cmxa -I api/ml') + out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" z3.cmxa') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('_ex_%s: ml_example.byte ml_example($EXE_EXT)\n\n' % self.name) + out.write('_ex_%s: ml_example.byte ml_example$(EXE_EXT)\n\n' % self.name) class PythonExampleComponent(ExampleComponent): def __init__(self, name, path): @@ -1882,15 +1790,9 @@ def mk_config(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) if is_ml_enabled(): -<<<<<<< HEAD print('Ocaml Compiler: %s' % OCAMLC) print('Ocaml Native: %s' % OCAMLOPT) print('Ocaml Library: %s' % OCAML_LIB) -======= - print('OCaml Compiler: %s' % OCAMLC) - print('OCaml Native: %s' % OCAMLOPT) - print('OCaml Library: %s' % OCAML_LIB) ->>>>>>> ML API: build system changes def mk_install(out): out.write('install: ') From e57dbbb56dcdc951e3c8460f4882f1a7d46e7e48 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 10 Jan 2013 18:39:43 +0000 Subject: [PATCH 159/248] ML API: build system fixes --- scripts/mk_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index c7b48b891..befd78be6 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1350,8 +1350,8 @@ class MLComponent(Component): for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) out.write('libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s api/ml/z3native.c $(CXX_OUTFLAG) api/ml/z3native$(OBJ_EXT)\n' % get_component(API_COMPONENT).to_src_dir) - out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG) libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') + out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s api/ml/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, get_component(API_COMPONENT).to_src_dir)) + out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') out.write('api/ml/z3.cmxa: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(src_dir, mlfile)) From 1e2b546b037ce87675580e860dcfe183305d35eb Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 11 Jan 2013 14:33:28 +0000 Subject: [PATCH 160/248] ML API: changed context from object to normal type. Removed optional array parameters. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 8 +- src/api/ml/z3.ml | 661 ++++++++++++++++++-------------------- 2 files changed, 323 insertions(+), 346 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 0e8122ae0..129f73d4d 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -38,7 +38,7 @@ let model_converter_test ( ctx : context ) = Printf.printf "Test passed.\n" ); ( - let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") None) g4 None) in + let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") [||]) g4 None) in if ((get_num_subgoals ar) == 1 && ((is_decided_sat (get_subgoal ar 0)) || (is_decided_unsat (get_subgoal ar 0)))) then @@ -49,7 +49,7 @@ let model_converter_test ( ctx : context ) = let solver = (mk_solver ctx None) in let f e = (Solver.assert_ solver [| e |]) in ignore (Array.map f (get_formulas (get_subgoal ar 0))) ; - let q = (check solver None) in + let q = (check solver [||]) in if q != SATISFIABLE then raise (TestFailedException "") else @@ -88,7 +88,7 @@ let basic_tests ( ctx : context ) = ( let solver = (mk_solver ctx None) in (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; - if (check solver None) != SATISFIABLE then + if (check solver [||]) != SATISFIABLE then raise (TestFailedException "") else Printf.printf "Test passed.\n" @@ -204,7 +204,7 @@ let _ = else ( Printf.printf "Running Z3 version %s\n" Version.to_string ; - let cfg = (Some [("model", "true"); ("proof", "false")]) in + let cfg = [("model", "true"); ("proof", "false")] in let ctx = (mk_context cfg) in let is = (Symbol.mk_int ctx 42) in let ss = (Symbol.mk_string ctx "mySymbol") in diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c0711b4eb..c91d909bc 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,46 +7,39 @@ open Z3enums +type context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } + (**/**) +let context_dispose ctx = + if ctx.m_n_obj_cnt == 0 then ( + (* Printf.printf "Disposing context \n" ; *) + (Z3native.del_context ctx.m_n_ctx) + ) else ( + Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; + (* re-queue for finalization? *) + ) -class context settings = -object (self) - val mutable m_n_ctx : Z3native.z3_context = - let cfg = Z3native.mk_config in - let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in - (List.iter f settings) ; - let v = Z3native.mk_context_rc cfg in - Z3native.del_config(cfg) ; - Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; - v - +let context_init settings = + let cfg = Z3native.mk_config in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = Z3native.mk_context_rc cfg in + Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + (* Printf.printf "Installing finalizer on context \n" ; *) + let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in + let f = fun o -> context_dispose o in + Gc.finalise f res; + res (* CMW: Install error handler here! m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. Z3native.set_error_handler(m_ctx, m_n_err_handler); GC.SuppressFinalize(this); *) - val mutable m_obj_cnt : int = 0 - - initializer - (* Printf.printf "Installing finalizer on context %d \n" (Oo.id self) ; *) - let f = fun o -> o#dispose in - let v = self in - Gc.finalise f v; - - method dispose : unit = - if m_obj_cnt == 0 then ( - (* Printf.printf "Disposing context %d \n" (Oo.id self) ; *) - (Z3native.del_context m_n_ctx) - ) else ( - Printf.printf "NOT DISPOSING context %d because it still has %d objects alive\n" (Oo.id self) m_obj_cnt; - (* re-queue for finalization? *) - ) - - method add_one_ctx_obj = m_obj_cnt <- m_obj_cnt + 1 - method sub_one_ctx_obj = m_obj_cnt <- m_obj_cnt - 1 - method gno = m_n_ctx -end +let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) +let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) +let context_gno ctx = ctx.m_n_ctx (**/**) @@ -70,10 +63,8 @@ the context, e.g., like so: (...) *) -let mk_context ( cfg : ( string * string ) list option ) = - match cfg with - | None -> new context [] - | Some(x) -> new context x +let mk_context ( cfg : ( string * string ) list ) = + context_init cfg (**/**) @@ -85,8 +76,8 @@ object (self) initializer (match m_n_obj with - | Some (x) -> self#incref m_ctx#gno x; - m_ctx#add_one_ctx_obj + | Some (x) -> self#incref (context_gno m_ctx) x; + (context_add1 m_ctx) | None -> () ); (* Printf.printf "Installing finalizer on z3object %d \n" (Oo.id self) ; *) @@ -101,8 +92,8 @@ object (self) (* Printf.printf "Disposing z3object %d \n" (Oo.id self) ; *) (match m_n_obj with | Some (x) -> - self#decref m_ctx#gno x; - m_ctx#sub_one_ctx_obj ; + self#decref (context_gno m_ctx) x; + (context_sub1 m_ctx) ; m_n_obj <- None; | None -> () ); @@ -112,16 +103,16 @@ object (self) | None -> raise (Z3native.Exception "Z3 object lost") method sno (ctx : context) o = - m_ctx#add_one_ctx_obj ; - self#incref ctx#gno o ; + (context_add1 m_ctx) ; + self#incref (context_gno ctx) o ; (match m_n_obj with - | Some(x) -> self#decref ctx#gno x ; m_ctx#sub_one_ctx_obj + | Some(x) -> self#decref (context_gno ctx) x ; (context_sub1 m_ctx) | None -> () ); m_n_obj <- Some o method gc = m_ctx - method gnc = m_ctx#gno + method gnc = (context_gno m_ctx) end @@ -134,37 +125,38 @@ object (self) method decref nc o = Z3native.params_dec_ref nc o end + (** Symbol objects *) -class symbol ctx = +class symbol ctx = object (self) - inherit z3object ctx None as super + inherit z3object ctx None as super method cnstr_obj obj = (self#sno ctx obj) ; self method incref nc o = () method decref nc o = () end +(** Int symbol objects *) +class int_symbol ctx = +object(self) + inherit symbol ctx as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_int i = (self#sno ctx (Z3native.mk_int_symbol (context_gno ctx) i)) ; self +end + +(** String symbol objects *) +class string_symbol ctx = +object(self) + inherit symbol ctx as super + method cnstr_obj obj = (self#sno ctx obj) ; self + method cnstr_string name = (self#sno ctx (Z3native.mk_string_symbol (context_gno ctx) name)) ; self +end + let symbolaton (a : symbol array) = let f (e : symbol) = e#gno in Array.map f a -(** Int symbol objects *) -class int_symbol ctx = -object(self) - inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_int i = (self#sno ctx (Z3native.mk_int_symbol ctx#gno i)) ; self -end - -(** String symbol objects *) -class string_symbol ctx = -object(self) - inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_string name = (self#sno ctx (Z3native.mk_string_symbol ctx#gno name)) ; self -end - let create_symbol ctx no = - match (symbol_kind_of_int (Z3native.get_symbol_kind ctx#gno no)) with + match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj no) :> symbol) | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj no) :> symbol) @@ -205,7 +197,7 @@ class array_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx (Z3native.mk_array_sort ctx#gno domain#gno range#gno)) ; self + method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx (Z3native.mk_array_sort (context_gno ctx) domain#gno range#gno)) ; self end (** Bit-vector sort objects *) @@ -241,7 +233,7 @@ class uninterpreted_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_s (s : symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort ctx#gno s#gno)) ; self + method cnstr_s (s : symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) s#gno)) ; self end (** Finite domain sort objects *) @@ -249,7 +241,7 @@ class finite_domain_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort ctx#gno s#gno sz)) ; self + method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort (context_gno ctx) s#gno sz)) ; self end (** Relation sort objects *) @@ -273,7 +265,7 @@ object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_siss (name : symbol) (num_fields: int) (field_names : symbol array) (field_sorts : sort array) = - let (x,_,_) = (Z3native.mk_tuple_sort ctx#gno name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in + let (x,_,_) = (Z3native.mk_tuple_sort (context_gno ctx) name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in (self#sno ctx x) ; self end @@ -284,8 +276,8 @@ class func_decl ctx = object (self) inherit ast ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl ctx#gno name#gno (Array.length domain) (astaton domain) range#gno)) ; self - method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl ctx#gno prefix (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl (context_gno ctx) name#gno (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (astaton domain) range#gno)) ; self method incref nc o = super#incref nc o method decref nc o = super#decref nc o @@ -341,7 +333,7 @@ object (self) val mutable _testerdecls : func_decl array option = None method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (enum_names : symbol array) = - let (r, a, b) = (Z3native.mk_enumeration_sort ctx#gno name#gno (Array.length enum_names) (symbolaton enum_names)) in + let (r, a, b) = (Z3native.mk_enumeration_sort (context_gno ctx) name#gno (Array.length enum_names) (symbolaton enum_names)) in _constdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f a)) ; _testerdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f b)) ; (self#sno ctx r) ; @@ -368,7 +360,7 @@ object (self) val mutable _taildecl : func_decl option = None method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ss (name : symbol) (elem_sort : sort) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort ctx#gno name#gno elem_sort#gno) in + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) name#gno elem_sort#gno) in _nildecl <- Some ((new func_decl ctx)#cnstr_obj a) ; _is_nildecl <- Some ((new func_decl ctx)#cnstr_obj b) ; _consdecl <- Some ((new func_decl ctx)#cnstr_obj c) ; @@ -426,7 +418,7 @@ object (self) if m_n != (Array.length sort_refs) then raise (Z3native.Exception "Number of field names does not match number of sort refs") else - let o = (Z3native.mk_constructor ctx#gno name#gno recognizer#gno m_n (symbolaton field_names) + let o = (Z3native.mk_constructor (context_gno ctx) name#gno recognizer#gno m_n (symbolaton field_names) (sortaton sorts) sort_refs) in self#sno ctx o ; @@ -473,7 +465,7 @@ object (self) Gc.finalise f v method cnstr_obj obj = (self#sno ctx obj) ; self method cnstr_ca ( c : constructor array ) = - self#sno ctx (Z3native.mk_constructor_list ctx#gno (Array.length c) (constructoraton c)) ; + self#sno ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (constructoraton c)) ; self end @@ -486,11 +478,11 @@ class datatype_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_sc (name : symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype ctx#gno name#gno (Array.length constructors) (constructoraton constructors)))) ; self + method cnstr_sc (name : symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype (context_gno ctx) name#gno (Array.length constructors) (constructoraton constructors)))) ; self end let create_sort ctx obj = - match (sort_kind_of_int (Z3native.get_sort_kind ctx#gno obj)) with + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) obj)) with | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) @@ -900,7 +892,7 @@ struct Create a new Boolean sort. *) let mk_bool ( ctx : context ) = - (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort ctx#gno) + (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort (context_gno ctx)) (** Create a new uninterpreted sort. @@ -917,15 +909,15 @@ end (**/**) let create_expr ctx obj = - if ast_kind_of_int (Z3native.get_ast_kind ctx#gno obj) == QUANTIFIER_AST then + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then (((new quantifier ctx)#cnstr_obj obj) :> expr) else - let s = Z3native.get_sort ctx#gno obj in - let sk = (sort_kind_of_int (Z3native.get_sort_kind ctx#gno s)) in - if (Z3native.is_algebraic_number ctx#gno obj) then + let s = Z3native.get_sort (context_gno ctx) obj in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) obj) then (((new algebraic_num ctx)#cnstr_obj obj) :> expr) else - if (Z3native.is_numeral_ast ctx#gno obj) && + if (Z3native.is_numeral_ast (context_gno ctx) obj) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) @@ -943,11 +935,11 @@ let create_expr ctx obj = | _ -> (new expr ctx)#cnstr_obj obj let create_expr_fa (ctx : context) (f : func_decl) (args : expr array) = - let o = Z3native.mk_app ctx#gno f#gno (Array.length args) (astaton args) in + let o = Z3native.mk_app (context_gno ctx) f#gno (Array.length args) (astaton args) in create_expr ctx o let create_ast ctx no = - match (ast_kind_of_int (Z3native.get_ast_kind ctx#gno no)) with + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with | FUNC_DECL_AST -> (((new func_decl ctx)#cnstr_obj no) :> ast) | QUANTIFIER_AST -> (((new quantifier ctx)#cnstr_obj no) :> ast) | SORT_AST -> ((create_sort ctx no) :> ast) @@ -1188,7 +1180,7 @@ struct @return A new ASTVector *) let translate ( x : ast_vector ) ( to_ctx : context ) = - (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno to_ctx#gno) + (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno (context_gno to_ctx)) (** Retrieves a string representation of the vector. *) let to_string ( x : ast_vector ) = @@ -1337,7 +1329,7 @@ struct if x#gc == to_ctx then x else - (create_ast to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno)) + (create_ast to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx))) (** Wraps an AST. @@ -1383,13 +1375,13 @@ struct a string describing all available parameters to Expr.Simplify. *) let get_simplify_help ( ctx : context ) = - Z3native.simplify_get_help ctx#gno + Z3native.simplify_get_help (context_gno ctx) (** Retrieves parameter descriptions for simplifier. *) let get_simplify_parameter_descrs ( ctx : context ) = - (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs ctx#gno) + (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. @@ -1462,7 +1454,7 @@ struct if x#gc == to_ctx then x else - create_expr to_ctx (Z3native.translate x#gnc x#gno to_ctx#gno) + create_expr to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx)) (** Returns a string representation of the expression. @@ -1578,7 +1570,7 @@ struct Creates a new Constant of sort and named . *) let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = - create_expr ctx (Z3native.mk_const ctx#gno name#gno range#gno) + create_expr ctx (Z3native.mk_const (context_gno ctx) name#gno range#gno) (** @@ -1600,7 +1592,7 @@ struct name prefixed with . *) let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort) = - create_expr ctx (Z3native.mk_fresh_const ctx#gno prefix range#gno) + create_expr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix range#gno) (** Create a Boolean constant. @@ -1624,13 +1616,13 @@ struct The true Term. *) let mk_true ( ctx : context ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_true ctx#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_true (context_gno ctx)) (** The false Term. *) let mk_false ( ctx : context ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_false ctx#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_false (context_gno ctx)) (** Creates a Boolean value. @@ -1642,19 +1634,19 @@ struct Creates the equality = . *) let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_eq ctx#gno x#gno y#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_eq (context_gno ctx) x#gno y#gno) (** Creates a distinct term. *) let mk_distinct ( ctx : context ) ( args : expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_distinct ctx#gno (Array.length args) (astaton args)) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_distinct (context_gno ctx) (Array.length args) (astaton args)) (** Mk an expression representing not(a). *) let mk_not ( ctx : context ) ( a : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_not ctx#gno a#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_not (context_gno ctx) a#gno) (** Create an expression representing an if-then-else: ite(t1, t2, t3). @@ -1663,37 +1655,37 @@ struct @param t3 An expression with the same sort as *) let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - create_expr ctx (Z3native.mk_ite ctx#gno t1#gno t2#gno t3#gno) + create_expr ctx (Z3native.mk_ite (context_gno ctx) t1#gno t2#gno t3#gno) (** Create an expression representing t1 iff t2. *) let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_iff ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_iff (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 -> t2. *) let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_implies ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_implies (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 xor t2. *) let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_xor ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_xor (context_gno ctx) t1#gno t2#gno) (** Create an expression representing the AND of args *) let mk_and ( ctx : context ) ( args : bool_expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_and ctx#gno (Array.length args) (astaton args)) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_and (context_gno ctx) (Array.length args) (astaton args)) (** Create an expression representing the OR of args *) let mk_or ( ctx : context ) ( args : bool_expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_or ctx#gno (Array.length args) (astaton args)) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_or (context_gno ctx) (Array.length args) (astaton args)) (** Create a numeral of a given sort. @@ -1702,7 +1694,7 @@ struct @return A Term with value and sort *) let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = - create_expr ctx (Z3native.mk_numeral ctx#gno v ty#gno) + create_expr ctx (Z3native.mk_numeral (context_gno ctx) v ty#gno) (** Create a numeral of a given sort. This function can be use to create numerals that fit in a machine integer. @@ -1712,7 +1704,7 @@ struct @return A Term with value and type *) let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_int ctx#gno v ty#gno) + create_expr ctx (Z3native.mk_int (context_gno ctx) v ty#gno) end (** Quantifier expressions *) @@ -1845,7 +1837,7 @@ struct @param ty The sort of the variable *) let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_bound ctx#gno index ty#gno) + create_expr ctx (Z3native.mk_bound (context_gno ctx) index ty#gno) (** Create a quantifier pattern. @@ -1854,7 +1846,7 @@ struct if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - (new pattern ctx)#cnstr_obj (Z3native.mk_pattern ctx#gno (Array.length terms) (astaton terms)) + (new pattern ctx)#cnstr_obj (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (astaton terms)) (** Create a universal Quantifier. @@ -1875,27 +1867,24 @@ struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") - else if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno true + else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) (Array.length sorts) (astaton sorts) (astaton names) body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno true + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) - (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) - (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) + (Array.length nopatterns) (patternaton nopatterns) (Array.length sorts) (astaton sorts) (astaton names) body#gno) @@ -1903,51 +1892,45 @@ struct (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = - if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno true + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expraton bound_constants) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno true + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) (Array.length bound_constants) (expraton bound_constants) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) - (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) - (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) + (Array.length nopatterns) (patternaton nopatterns) body#gno) (** Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") - else if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier ctx#gno false + else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) (Array.length sorts) (astaton sorts) (astaton names) body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex ctx#gno false + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) - (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) - (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) + (Array.length nopatterns) (patternaton nopatterns) (Array.length sorts) (astaton sorts) (astaton names) body#gno) @@ -1955,31 +1938,28 @@ struct (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = - if (nopatterns == None && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const ctx#gno false + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expraton bound_constants) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) body#gno) else let null = Z3native.mk_null() in - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex ctx#gno false + (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) (match skolem_id with | None -> null | Some(x) -> x#gno) (Array.length bound_constants) (expraton bound_constants) - (match patterns with | None -> 0 | Some(x) -> (Array.length x)) - (match patterns with | None -> [||] | Some(x) -> (patternaton x)) - (match nopatterns with | None -> 0 | Some(x) -> (Array.length x)) - (match nopatterns with | None -> [||] | Some(x) -> (patternaton x)) + (Array.length patterns) (patternaton patterns) + (Array.length nopatterns) (patternaton nopatterns) body#gno) (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -1989,7 +1969,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array option ) ( nopatterns : pattern array option ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -2081,7 +2061,7 @@ struct *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - ((create_expr ctx (Z3native.mk_select ctx#gno a#gno i#gno)) :> array_expr) + ((create_expr ctx (Z3native.mk_select (context_gno ctx) a#gno i#gno)) :> array_expr) (** Array update. @@ -2100,7 +2080,7 @@ struct *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr) = - (new array_expr ctx)#cnstr_obj (Z3native.mk_store ctx#gno a#gno i#gno v#gno) + (new array_expr ctx)#cnstr_obj (Z3native.mk_store (context_gno ctx) a#gno i#gno v#gno) (** Create a constant array. @@ -2111,7 +2091,7 @@ struct *) let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - (new array_expr ctx)#cnstr_obj (Z3native.mk_const_array ctx#gno domain#gno v#gno) + (new array_expr ctx)#cnstr_obj (Z3native.mk_const_array (context_gno ctx) domain#gno v#gno) (** Maps f on the argument arrays. @@ -2124,7 +2104,7 @@ struct *) let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = - ((create_expr ctx (Z3native.mk_map ctx#gno f#gno (Array.length args) (astaton args))) :> array_expr) + ((create_expr ctx (Z3native.mk_map (context_gno ctx) f#gno (Array.length args) (astaton args))) :> array_expr) (** Access the array default value. @@ -2133,7 +2113,7 @@ struct finite maps with a default range value. *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = - ((create_expr ctx (Z3native.mk_array_default ctx#gno arg#gno)) :> array_expr) + ((create_expr ctx (Z3native.mk_array_default (context_gno ctx) arg#gno)) :> array_expr) end (** Functions to manipulate Set expressions *) @@ -2174,61 +2154,61 @@ struct Create an empty set. *) let mk_empty ( ctx : context ) ( domain : sort ) = - (create_expr ctx (Z3native.mk_empty_set ctx#gno domain#gno)) + (create_expr ctx (Z3native.mk_empty_set (context_gno ctx) domain#gno)) (** Create the full set. *) let mk_full ( ctx : context ) ( domain : sort ) = - create_expr ctx (Z3native.mk_full_set ctx#gno domain#gno) + create_expr ctx (Z3native.mk_full_set (context_gno ctx) domain#gno) (** Add an element to the set. *) let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_add ctx#gno set#gno element#gno) + create_expr ctx (Z3native.mk_set_add (context_gno ctx) set#gno element#gno) (** Remove an element from a set. *) let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_del ctx#gno set#gno element#gno) + create_expr ctx (Z3native.mk_set_del (context_gno ctx) set#gno element#gno) (** Take the union of a list of sets. *) let mk_union ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_union ctx#gno (Array.length args) (astaton args)) + create_expr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (astaton args)) (** Take the intersection of a list of sets. *) let mk_intersection ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_intersect ctx#gno (Array.length args) (astaton args)) + create_expr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (astaton args)) (** Take the difference between two sets. *) let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_difference ctx#gno arg1#gno arg2#gno) + create_expr ctx (Z3native.mk_set_difference (context_gno ctx) arg1#gno arg2#gno) (** Take the complement of a set. *) let mk_complement ( ctx : context ) ( arg : expr ) = - create_expr ctx (Z3native.mk_set_complement ctx#gno arg#gno) + create_expr ctx (Z3native.mk_set_complement (context_gno ctx) arg#gno) (** Check for set membership. *) let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - create_expr ctx (Z3native.mk_set_member ctx#gno elem#gno set#gno) + create_expr ctx (Z3native.mk_set_member (context_gno ctx) elem#gno set#gno) (** Check for subsetness of sets. *) let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_subset ctx#gno arg1#gno arg2#gno) + create_expr ctx (Z3native.mk_set_subset (context_gno ctx) arg1#gno arg2#gno) end @@ -2458,7 +2438,7 @@ struct let n = (Array.length names) in let f e = ( (new constructor_list ctx)#cnstr_ca e ) in let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes ctx#gno n (symbolaton names) (constructor_listaton cla)) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (symbolaton names) (constructor_listaton cla)) in let g e = ( (new datatype_sort ctx)#cnstr_obj e) in (Array.map g r) @@ -2592,13 +2572,13 @@ struct Create a new integer sort. *) let mk_int_sort ( ctx : context ) = - (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort ctx#gno) + (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort (context_gno ctx)) (** Create a real sort. *) let mk_real_sort ( ctx : context ) = - (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort ctx#gno) + (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort (context_gno ctx)) (** Indicates whether the term is of integer sort. @@ -2761,75 +2741,75 @@ struct Create an expression representing t[0] + t[1] + .... *) let mk_add ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_add ctx#gno (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) (** Create an expression representing t[0] * t[1] * .... *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_mul ctx#gno (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) (** Create an expression representing t[0] - t[1] - .... *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_sub ctx#gno (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) (** Create an expression representing -t. *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - (create_expr ctx (Z3native.mk_unary_minus ctx#gno t#gno) :> arith_expr) + (create_expr ctx (Z3native.mk_unary_minus (context_gno ctx) t#gno) :> arith_expr) (** Create an expression representing t1 / t2. *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - (create_expr ctx (Z3native.mk_div ctx#gno t1#gno t2#gno) :> arith_expr) + (create_expr ctx (Z3native.mk_div (context_gno ctx) t1#gno t2#gno) :> arith_expr) (** Create an expression representing t1 mod t2. The arguments must have int type. *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_mod ctx#gno t1#gno t2#gno) + (new int_expr ctx)#cnstr_obj (Z3native.mk_mod (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 rem t2. The arguments must have int type. *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_rem ctx#gno t1#gno t2#gno) + (new int_expr ctx)#cnstr_obj (Z3native.mk_rem (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 ^ t2. *) let mk_Power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (create_expr ctx (Z3native.mk_power ctx#gno t1#gno t2#gno) :> arith_expr) + (create_expr ctx (Z3native.mk_power (context_gno ctx) t1#gno t2#gno) :> arith_expr) (** Create an expression representing t1 < t2 *) let mk_lt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_lt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_lt (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 <= t2 *) let mk_le ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_le ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_le (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 > t2 *) let mk_gt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_gt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_gt (context_gno ctx) t1#gno t2#gno) (** Create an expression representing t1 >= t2 *) let mk_ge ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_ge ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_ge (context_gno ctx) t1#gno t2#gno) (** Coerce an integer to a real. @@ -2842,7 +2822,7 @@ struct The argument must be of integer sort. *) let mk_int2real ( ctx : context ) ( t : int_expr ) = - (new real_expr ctx)#cnstr_obj (Z3native.mk_int2real ctx#gno t#gno) + (new real_expr ctx)#cnstr_obj (Z3native.mk_int2real (context_gno ctx) t#gno) (** Coerce a real to an integer. @@ -2852,13 +2832,13 @@ struct The argument must be of real sort. *) let mk_real2int ( ctx : context ) ( t : real_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_real2int ctx#gno t#gno) + (new int_expr ctx)#cnstr_obj (Z3native.mk_real2int (context_gno ctx) t#gno) (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_is_int ctx#gno t#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_is_int (context_gno ctx) t#gno) (** Return a upper bound for a given real algebraic number. @@ -2898,7 +2878,7 @@ struct raise (Z3native.Exception "Denominator is zero") else - (new rat_num ctx)#cnstr_obj (Z3native.mk_real ctx#gno num den) + (new rat_num ctx)#cnstr_obj (Z3native.mk_real (context_gno ctx) num den) (** Create a real numeral. @@ -2906,7 +2886,7 @@ struct @return A Term with value and sort Real *) let mk_real_numeral_s ( ctx : context ) ( v : string ) = - (new rat_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_real_sort ctx)#gno) + (new rat_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_real_sort ctx)#gno) (** Create a real numeral. @@ -2915,14 +2895,14 @@ struct @return A Term with value and sort Real *) let mk_real_numeral_i ( ctx : context ) ( v : int ) = - (new rat_num ctx)#cnstr_obj (Z3native.mk_int ctx#gno v (mk_real_sort ctx)#gno) + (new rat_num ctx)#cnstr_obj (Z3native.mk_int (context_gno ctx) v (mk_real_sort ctx)#gno) (** Create an integer numeral. @param v A string representing the Term value in decimal notation. *) let mk_int_numeral_s ( ctx : context ) ( v : string ) = - (new int_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_int_sort ctx)#gno) + (new int_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_int_sort ctx)#gno) (** Create an integer numeral. @@ -2930,7 +2910,7 @@ struct @return A Term with value and sort Integer *) let mk_int_numeral_i ( ctx : context ) ( v : int ) = - (new int_num ctx)#cnstr_obj (Z3native.mk_int ctx#gno v (mk_int_sort ctx)#gno) + (new int_num ctx)#cnstr_obj (Z3native.mk_int (context_gno ctx) v (mk_int_sort ctx)#gno) (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -2944,7 +2924,7 @@ struct Create a new bit-vector sort. *) let mk_sort ( ctx : context ) size = - (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort ctx#gno size) + (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort (context_gno ctx) size) (** Indicates whether the terms is of bit-vector sort. @@ -3245,91 +3225,91 @@ struct The argument must have a bit-vector sort. *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnot ctx#gno t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnot (context_gno ctx) t#gno) (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredand ctx#gno t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredand (context_gno ctx) t#gno) (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredor ctx#gno t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredor (context_gno ctx) t#gno) (** Bitwise conjunction. The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvand ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvand (context_gno ctx) t1#gno t2#gno) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvor ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvor (context_gno ctx) t1#gno t2#gno) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxor ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxor (context_gno ctx) t1#gno t2#gno) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnand ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnand (context_gno ctx) t1#gno t2#gno) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnor ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnor (context_gno ctx) t1#gno t2#gno) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxnor ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxnor (context_gno ctx) t1#gno t2#gno) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvneg ctx#gno t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvneg (context_gno ctx) t#gno) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvadd ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvadd (context_gno ctx) t1#gno t2#gno) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsub ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsub (context_gno ctx) t1#gno t2#gno) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvmul ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvmul (context_gno ctx) t1#gno t2#gno) (** Unsigned division. @@ -3341,7 +3321,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvudiv ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvudiv (context_gno ctx) t1#gno t2#gno) (** Signed division. @@ -3356,7 +3336,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv (context_gno ctx) t1#gno t2#gno) (** Unsigned remainder. @@ -3366,7 +3346,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvurem ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvurem (context_gno ctx) t1#gno t2#gno) (** Signed remainder. @@ -3378,7 +3358,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsrem ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsrem (context_gno ctx) t1#gno t2#gno) (** Two's complement signed remainder (sign follows divisor). @@ -3387,7 +3367,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsmod ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsmod (context_gno ctx) t1#gno t2#gno) (** Unsigned less-than @@ -3395,7 +3375,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvult ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvult (context_gno ctx) t1#gno t2#gno) (** Two's complement signed less-than @@ -3403,7 +3383,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvslt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvslt (context_gno ctx) t1#gno t2#gno) (** Unsigned less-than or equal to. @@ -3411,7 +3391,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvule ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvule (context_gno ctx) t1#gno t2#gno) (** Two's complement signed less-than or equal to. @@ -3419,7 +3399,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsle ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsle (context_gno ctx) t1#gno t2#gno) (** Unsigned greater than or equal to. @@ -3427,7 +3407,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvuge ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvuge (context_gno ctx) t1#gno t2#gno) (** Two's complement signed greater than or equal to. @@ -3435,7 +3415,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_SGE ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsge ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsge (context_gno ctx) t1#gno t2#gno) (** Unsigned greater-than. @@ -3443,7 +3423,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvugt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvugt (context_gno ctx) t1#gno t2#gno) (** Two's complement signed greater-than. @@ -3451,7 +3431,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsgt ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsgt (context_gno ctx) t1#gno t2#gno) (** Bit-vector concatenation. @@ -3462,7 +3442,7 @@ struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_concat ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_concat (context_gno ctx) t1#gno t2#gno) (** Bit-vector extraction. @@ -3473,7 +3453,7 @@ struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_extract ctx#gno high low t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_extract (context_gno ctx) high low t#gno) (** Bit-vector sign extension. @@ -3483,7 +3463,7 @@ struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_sign_ext ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_sign_ext (context_gno ctx) i t#gno) (** Bit-vector zero extension. @@ -3494,7 +3474,7 @@ struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_zero_ext ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_zero_ext (context_gno ctx) i t#gno) (** Bit-vector repetition. @@ -3502,7 +3482,7 @@ struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_repeat ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_repeat (context_gno ctx) i t#gno) (** Shift left. @@ -3517,7 +3497,7 @@ struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvshl ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvshl (context_gno ctx) t1#gno t2#gno) (** Logical shift right @@ -3531,7 +3511,7 @@ struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvlshr ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvlshr (context_gno ctx) t1#gno t2#gno) (** Arithmetic shift right @@ -3547,7 +3527,7 @@ struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvashr ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvashr (context_gno ctx) t1#gno t2#gno) (** Rotate Left. @@ -3556,7 +3536,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_left ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_left (context_gno ctx) i t#gno) (** Rotate Right. @@ -3565,7 +3545,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_right ctx#gno i t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_right (context_gno ctx) i t#gno) (** Rotate Left. @@ -3574,7 +3554,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_left ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_left (context_gno ctx) t1#gno t2#gno) (** Rotate Right. @@ -3584,7 +3564,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_right ctx#gno t1#gno t2#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_right (context_gno ctx) t1#gno t2#gno) (** Create an bit bit-vector from the integer argument . @@ -3597,7 +3577,7 @@ struct The argument must be of integer sort. *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_int2bv ctx#gno n t#gno) + (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_int2bv (context_gno ctx) n t#gno) (** Create an integer from the bit-vector argument . @@ -3615,7 +3595,7 @@ struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int ctx#gno t#gno signed) + (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int (context_gno ctx) t#gno signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3623,7 +3603,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow ctx#gno t1#gno t2#gno signed) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow (context_gno ctx) t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3631,7 +3611,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_underflow ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_underflow (context_gno ctx) t1#gno t2#gno) (** Create a predicate that checks that the bit-wise subtraction does not overflow. @@ -3639,7 +3619,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_overflow ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_overflow (context_gno ctx) t1#gno t2#gno) (** Create a predicate that checks that the bit-wise subtraction does not underflow. @@ -3647,7 +3627,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow ctx#gno t1#gno t2#gno signed) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow (context_gno ctx) t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3655,7 +3635,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv_no_overflow ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) t1#gno t2#gno) (** Create a predicate that checks that the bit-wise negation does not overflow. @@ -3663,7 +3643,7 @@ struct The arguments must be of bit-vector sort. *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvneg_no_overflow ctx#gno t#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvneg_no_overflow (context_gno ctx) t#gno) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3671,7 +3651,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow ctx#gno t1#gno t2#gno signed) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow (context_gno ctx) t1#gno t2#gno signed) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3679,7 +3659,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow ctx#gno t1#gno t2#gno) + (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow (context_gno ctx) t1#gno t2#gno) (** Create a bit-vector numeral. @@ -3688,7 +3668,7 @@ struct @param size the size of the bit-vector *) let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = - (new bitvec_num ctx)#cnstr_obj (Z3native.mk_numeral ctx#gno v (mk_sort ctx size)#gno) + (new bitvec_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_sort ctx size)#gno) end (** Functions to manipulate proof expressions *) @@ -4248,7 +4228,7 @@ end Creates a new parameter set *) let mk_params ( ctx : context ) = - (new params ctx)#cnstr_obj (Z3native.mk_params ctx#gno) + (new params ctx)#cnstr_obj (Z3native.mk_params (context_gno ctx)) (** A string representation of the parameter set. @@ -4329,7 +4309,7 @@ struct (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = - (new goal to_ctx)#cnstr_obj (Z3native.goal_translate x#gnc x#gno to_ctx#gno) + (new goal to_ctx)#cnstr_obj (Z3native.goal_translate x#gnc x#gno (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) let simplify ( x : goal ) ( p : params option ) = @@ -4360,7 +4340,7 @@ struct @param proofs Indicates whether proof generation should be enabled. *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - (new goal ctx)#cnstr_obj (Z3native.mk_goal ctx#gno models unsat_cores proofs) + (new goal ctx)#cnstr_obj (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno @@ -4429,14 +4409,14 @@ end (** The number of supported tactics. *) - let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics ctx#gno + let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) (** The names of all supported tactics. *) let get_tactic_names ( ctx : context ) = let n = (get_num_tactics ctx ) in - let f i = (Z3native.get_tactic_name ctx#gno i) in + let f i = (Z3native.get_tactic_name (context_gno ctx) i) in Array.init n f @@ -4444,39 +4424,34 @@ end Returns a string containing a description of the tactic with the given name. *) let get_tactic_description ( ctx : context ) ( name : string ) = - Z3native.tactic_get_descr ctx#gno name + Z3native.tactic_get_descr (context_gno ctx) name (** Creates a new Tactic. *) let mk_tactic ( ctx : context ) ( name : string ) = - (new tactic ctx)#cnstr_obj (Z3native.mk_tactic ctx#gno name) + (new tactic ctx)#cnstr_obj (Z3native.mk_tactic (context_gno ctx) name) (** Create a tactic that applies to a Goal and then to every subgoal produced by . *) - let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array option ) = - match - match ts with - | None -> None - | Some(rts) -> ( - let f p c = (match p with - | None -> (Some c#gno) - | Some(x) -> (Some (Z3native.tactic_and_then ctx#gno c#gno x))) in - Array.fold_left f None rts) - with - | None -> (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then ctx#gno t1#gno t2#gno) + let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array ) = + let f p c = (match p with + | None -> (Some c#gno) + | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) c#gno x))) in + match (Array.fold_left f None ts) with + | None -> (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then (context_gno ctx) t1#gno t2#gno) | Some(x) -> - let o = (Z3native.tactic_and_then ctx#gno t2#gno x) in - (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then ctx#gno t1#gno o) + let o = (Z3native.tactic_and_then (context_gno ctx) t2#gno x) in + (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then (context_gno ctx) t1#gno o) (** Create a tactic that first applies to a Goal and if it fails then returns the result of applied to the Goal. *) let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_or_else ctx#gno t1#gno t2#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_or_else (context_gno ctx) t1#gno t2#gno) (** Create a tactic that applies to a goal for milliseconds. @@ -4484,7 +4459,7 @@ end If does not terminate within milliseconds, then it fails. *) let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_try_for ctx#gno t#gno ms) + (new tactic ctx)#cnstr_obj (Z3native.tactic_try_for (context_gno ctx) t#gno ms) (** Create a tactic that applies to a given goal if the probe @@ -4494,52 +4469,52 @@ end *) (* CMW: when is a keyword *) let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_when ctx#gno p#gno t#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_when (context_gno ctx) p#gno t#gno) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_cond ctx#gno p#gno t1#gno t2#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_cond (context_gno ctx) p#gno t1#gno t2#gno) (** Create a tactic that keeps applying until the goal is not modified anymore or the maximum number of iterations is reached. *) let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_repeat ctx#gno t#gno max) + (new tactic ctx)#cnstr_obj (Z3native.tactic_repeat (context_gno ctx) t#gno max) (** Create a tactic that just returns the given goal. *) let skip ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_skip ctx#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_skip (context_gno ctx)) (** Create a tactic always fails. *) let fail ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail ctx#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail (context_gno ctx)) (** Create a tactic that fails if the probe evaluates to false. *) let fail_if ( ctx : context ) ( p : probe ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if ctx#gno p#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if (context_gno ctx) p#gno) (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) or trivially unsatisfiable (i.e., contains `false'). *) let fail_if_not_decided ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if_not_decided ctx#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if_not_decided (context_gno ctx)) (** Create a tactic that applies using the given set of parameters . *) let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_using_params ctx#gno t#gno p#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_using_params (context_gno ctx) t#gno p#gno) (** Create a tactic that applies using the given set of parameters . @@ -4552,21 +4527,21 @@ end Create a tactic that applies the given tactics in parallel. *) let par_or ( ctx : context ) ( t : tactic array ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_par_or ctx#gno (Array.length t) (tacticaton t)) + (new tactic ctx)#cnstr_obj (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (tacticaton t)) (** Create a tactic that applies to a given goal and then to every subgoal produced by . The subgoals are processed in parallel. *) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_par_and_then ctx#gno t1#gno t2#gno) + (new tactic ctx)#cnstr_obj (Z3native.tactic_par_and_then (context_gno ctx) t1#gno t2#gno) (** Interrupt the execution of a Z3 procedure. This procedure can be used to interrupt: solvers, simplifiers and tactics. *) let interrupt ( ctx : context ) = - Z3native.interrupt ctx#gno + Z3native.interrupt (context_gno ctx) end (** Probes @@ -4591,68 +4566,68 @@ struct The number of supported Probes. *) let get_num_probes ( ctx : context ) = - Z3native.get_num_probes ctx#gno + Z3native.get_num_probes (context_gno ctx) (** The names of all supported Probes. *) let get_probe_names ( ctx : context ) = let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name ctx#gno i) in + let f i = (Z3native.get_probe_name (context_gno ctx) i) in Array.init n f (** Returns a string containing a description of the probe with the given name. *) let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr ctx#gno name + Z3native.probe_get_descr (context_gno ctx) name (** Creates a new Probe. *) let mk_probe ( ctx : context ) ( name : string ) = - (new probe ctx)#cnstr_obj (Z3native.mk_probe ctx#gno name) + (new probe ctx)#cnstr_obj (Z3native.mk_probe (context_gno ctx) name) (** Create a probe that always evaluates to . *) let const ( ctx : context ) ( v : float ) = - (new probe ctx)#cnstr_obj (Z3native.probe_const ctx#gno v) + (new probe ctx)#cnstr_obj (Z3native.probe_const (context_gno ctx) v) (** Create a probe that evaluates to "true" when the value returned by is less than the value returned by *) let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_lt ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_lt (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value returned by is greater than the value returned by *) let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_gt ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_gt (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value returned by is less than or equal the value returned by *) let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_le ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_le (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value returned by is greater than or equal the value returned by *) let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_ge ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_ge (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value returned by is equal to the value returned by *) let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_eq ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_eq (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value @@ -4660,7 +4635,7 @@ struct *) (* CMW: and is a keyword *) let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_and ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_and (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value @@ -4668,7 +4643,7 @@ struct *) (* CMW: or is a keyword *) let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_or ctx#gno p1#gno p2#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_or (context_gno ctx) p1#gno p2#gno) (** Create a probe that evaluates to "true" when the value @@ -4676,7 +4651,7 @@ struct *) (* CMW: is not a keyword? *) let not_ ( ctx : context ) ( p : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_not ctx#gno p#gno) + (new probe ctx)#cnstr_obj (Z3native.probe_not (context_gno ctx) p#gno) end (** Solvers *) @@ -4836,11 +4811,12 @@ struct *) - let check ( x : solver ) ( assumptions : bool_expr array option) = + let check ( x : solver ) ( assumptions : bool_expr array) = let r = - match assumptions with - | None -> lbool_of_int (Z3native.solver_check x#gnc x#gno) - | Some (ass) -> lbool_of_int (Z3native.solver_check_assumptions x#gnc x#gno (Array.length ass) (astaton ass)) + if ((Array.length assumptions) == 0) then + lbool_of_int (Z3native.solver_check x#gnc x#gno) + else + lbool_of_int (Z3native.solver_check_assumptions x#gnc x#gno (Array.length assumptions) (astaton assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -4907,8 +4883,8 @@ struct *) let mk_solver ( ctx : context ) ( logic : symbol option) = match logic with - | None -> (new solver ctx)#cnstr_obj (Z3native.mk_solver ctx#gno) - | Some (x) -> (new solver ctx)#cnstr_obj (Z3native.mk_solver_for_logic ctx#gno x#gno) + | None -> (new solver ctx)#cnstr_obj (Z3native.mk_solver (context_gno ctx)) + | Some (x) -> (new solver ctx)#cnstr_obj (Z3native.mk_solver_for_logic (context_gno ctx) x#gno) (** Creates a new (incremental) solver. @@ -4921,7 +4897,7 @@ struct Creates a new (incremental) solver. *) let mk_simple_solver ( ctx : context ) = - (new solver ctx)#cnstr_obj (Z3native.mk_simple_solver ctx#gno) + (new solver ctx)#cnstr_obj (Z3native.mk_simple_solver (context_gno ctx)) (** Creates a solver that is implemented using the given tactic. @@ -4930,7 +4906,7 @@ struct will always solve each check from scratch. *) let mk_solver_t ( ctx : context ) ( t : tactic ) = - (new solver ctx)#cnstr_obj (Z3native.mk_solver_from_tactic ctx#gno t#gno) + (new solver ctx)#cnstr_obj (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno) (** A string representation of the solver. @@ -5333,7 +5309,7 @@ struct Create a Fixedpoint context. *) let mk_fixedpoint ( ctx : context ) = - (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint ctx#gno) + (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint (context_gno ctx)) end (** Global and context options @@ -5354,7 +5330,7 @@ struct *) let update_param_value ( ctx : context ) ( id : string) ( value : string )= - Z3native.update_param_value ctx#gno id value + Z3native.update_param_value (context_gno ctx) id value (** Get a configuration parameter. @@ -5363,7 +5339,7 @@ struct *) let get_param_value ( ctx : context ) ( id : string ) = - let (r, v) = (Z3native.get_param_value ctx#gno id) in + let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in if not r then None else @@ -5385,7 +5361,7 @@ struct *) let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = - Z3native.set_ast_print_mode ctx#gno (int_of_ast_print_mode value) + Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) (** Enable/disable printing of warning messages to the console. @@ -5412,7 +5388,7 @@ struct @return A string representation of the benchmark. *) let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = - Z3native.benchmark_to_smtlib_string ctx#gno name logic status attributes + Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes (Array.length assumptions) (astaton assumptions) formula#gno @@ -5425,92 +5401,93 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = - let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in - let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in - let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in - let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let csn = (Array.length sort_names) in + let cs = (Array.length sorts) in + let cdn = (Array.length decl_names) in + let cd = (Array.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib_string ctx#gno str + Z3native.parse_smtlib_string (context_gno ctx) str cs - (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match sorts with | None -> [||] | Some(x) -> (astaton x)) + (symbolaton sort_names) + (astaton sorts) cd - (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (symbolaton decl_names) + (func_declaton decls) (** Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array option) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = - let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in - let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in - let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in - let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let csn = (Array.length sort_names) in + let cs = (Array.length sorts) in + let cdn = (Array.length decl_names) in + let cd = (Array.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib_file ctx#gno file_name + Z3native.parse_smtlib_file (context_gno ctx) file_name cs - (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match sorts with | None -> [||] | Some(x) -> (astaton x)) + (symbolaton sort_names) + (astaton sorts) cd - (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (symbolaton decl_names) + (func_declaton decls) + (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas ctx#gno + let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = ((create_expr ctx (Z3native.get_smtlib_formula ctx#gno i)) :> bool_expr) in + let f i = ((create_expr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) :> bool_expr) in Array.init n f (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions ctx#gno + let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = ((create_expr ctx (Z3native.get_smtlib_assumption ctx#gno i)) :> bool_expr ) in + let f i = ((create_expr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) :> bool_expr ) in Array.init n f (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls ctx#gno + let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in - let f i = (new func_decl ctx)#cnstr_obj (Z3native.get_smtlib_decl ctx#gno i) in + let f i = (new func_decl ctx)#cnstr_obj (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts ctx#gno + let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in - let f i = (create_sort ctx (Z3native.get_smtlib_sort ctx#gno i)) in + let f i = (create_sort ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in Array.init n f (** @@ -5519,41 +5496,41 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = - let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in - let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in - let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in - let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let csn = (Array.length sort_names) in + let cs = (Array.length sorts) in + let cdn = (Array.length decl_names) in + let cd = (Array.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib2_string ctx#gno str + Z3native.parse_smtlib2_string (context_gno ctx) str cs - (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match sorts with | None -> [||] | Some(x) -> (astaton x)) + (symbolaton sort_names) + (astaton sorts) cd - (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (symbolaton decl_names) + (func_declaton decls) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array option ) ( sorts : sort array option ) ( decl_names : symbol array option ) ( decls : func_decl array option ) = - let csn = (match sort_names with | None -> 0 | Some(x) -> Array.length x) in - let cs = (match sorts with | None -> 0 | Some(x) -> Array.length x) in - let cdn = (match decl_names with | None -> 0 | Some(x) -> Array.length x) in - let cd = (match decls with | None -> 0 | Some(x) -> Array.length x) in + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let csn = (Array.length sort_names) in + let cs = (Array.length sorts) in + let cdn = (Array.length decl_names) in + let cd = (Array.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib2_string ctx#gno file_name + Z3native.parse_smtlib2_string (context_gno ctx) file_name cs - (match sort_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match sorts with | None -> [||] | Some(x) -> (astaton x)) + (symbolaton sort_names) + (astaton sorts) cd - (match decl_names with | None -> [||] | Some(x) -> (symbolaton x)) - (match decls with | None -> [||] | Some(x) -> (func_declaton x)) + (symbolaton decl_names) + (func_declaton decls) end (* From 6257c56901179e6560e57a4483a41d1f6f51c820 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 12 Jan 2013 00:01:50 +0000 Subject: [PATCH 161/248] ML API: bugfixes; starting to replace objects with normal types. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 3 +- scripts/update_api.py | 3 +- src/api/ml/z3.ml | 711 ++++++++++++++++++++------------------ 3 files changed, 382 insertions(+), 335 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 129f73d4d..97985a7bc 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -14,6 +14,7 @@ open Z3.Tactic.ApplyResult open Z3.Probe open Z3.Solver open Z3.Arithmetic +open Z3.Fixedpoints exception TestFailedException of string @@ -216,8 +217,8 @@ let _ = Printf.printf "bool sort: %s\n" (Sort.to_string bs); Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); - Printf.printf "Disposing...\n"; basic_tests ctx ; + Printf.printf "Disposing...\n"; Gc.full_major () ); Printf.printf "Exiting.\n"; diff --git a/scripts/update_api.py b/scripts/update_api.py index 1986f4a7e..c730a325e 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1300,7 +1300,8 @@ def mk_ml(): ml_wrapper.write('extern "C" {\n') ml_wrapper.write('#endif\n\n') ml_wrapper.write('CAMLprim value n_is_null(value p) {\n') - ml_wrapper.write(' return Val_bool(Data_custom_val(p) == 0);\n') + ml_wrapper.write(' void * t = * (void**) Data_custom_val(p);\n') + ml_wrapper.write(' return Val_bool(t == 0);\n') ml_wrapper.write('}\n\n') ml_wrapper.write('CAMLprim value n_mk_null( void ) {\n') ml_wrapper.write(' CAMLparam0();\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c91d909bc..1e8ffe92e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,9 +7,13 @@ open Z3enums -type context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } +type context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } + +(**/**) + +let null = Z3native.mk_null() +let is_null o = (Z3native.is_null o) -(**/**) let context_dispose ctx = if ctx.m_n_obj_cnt == 0 then ( (* Printf.printf "Disposing context \n" ; *) @@ -19,7 +23,7 @@ let context_dispose ctx = (* re-queue for finalization? *) ) -let context_init settings = +let context_cnstr settings = let cfg = Z3native.mk_config in let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; @@ -50,7 +54,7 @@ require one such object, but power users may require more than one. To start usi Z3, do - let ctx = (mk_context None) in + let ctx = (mk_context []) in (...) @@ -58,17 +62,18 @@ where a list of pairs of strings may be passed to set options on the context, e.g., like so: - let cfg = (Some [("model", "true"); ("...", "...")]) in + let cfg = [("model", "true"); ("...", "...")] in let ctx = (mk_context cfg) in (...) *) let mk_context ( cfg : ( string * string ) list ) = - context_init cfg + context_cnstr cfg + + +(* type z3object = { m_ctx : context; m_n_obj : Z3native.ptr option; } *) (**/**) - -(** Z3 objects *) class virtual z3object ctx_init obj_init = object (self) val mutable m_ctx : context = ctx_init @@ -669,15 +674,6 @@ object (self) method decref nc o = Z3native.func_interp_dec_ref nc o end -(** Model objects *) -class model ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.model_inc_ref nc o - method decref nc o = Z3native.model_dec_ref nc o -end - (** Tactic application result objects *) class apply_result ctx = object (self) @@ -724,32 +720,38 @@ object (self) method is_float = m_is_float end -(** Statistics objects *) -class statistics ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.stats_inc_ref nc o - method decref nc o = Z3native.stats_dec_ref nc o -end -(** Solver objects *) -class solver ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.solver_inc_ref nc o - method decref nc o = Z3native.solver_dec_ref nc o -end +type z3_native_object = { + m_ctx : context ; + mutable m_n_obj : Z3native.ptr ; + inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; + dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } -(** Fixedpoint objects *) -class fixedpoint ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.fixedpoint_inc_ref nc o - method decref nc o = Z3native.fixedpoint_dec_ref nc o -end +let z3obj_gc o = o.m_ctx +let z3obj_gnc o = (context_gno o.m_ctx) + +let z3obj_gno o = o.m_n_obj +let z3obj_sno o ctx no = + (context_add1 ctx) ; + o.inc_ref (context_gno ctx) no ; + ( + if not (is_null o.m_n_obj) then + o.dec_ref (context_gno ctx) o.m_n_obj ; + (context_sub1 ctx) + ) ; + o.m_n_obj <- no + +let z3obj_dispose o = + if not (is_null o.m_n_obj) then + ( + o.dec_ref (z3obj_gnc o) o.m_n_obj ; + (context_sub1 (z3obj_gc o)) + ) ; + o.m_n_obj <- null + +let z3obj_cnstr o = + let f = fun o -> (z3obj_dispose o) in + Gc.finalise f o (**/**) @@ -1878,7 +1880,6 @@ struct (astaton names) body#gno) else - let null = Z3native.mk_null() in (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) @@ -1900,7 +1901,6 @@ struct (Array.length patterns) (patternaton patterns) body#gno) else - let null = Z3native.mk_null() in (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) @@ -1924,7 +1924,6 @@ struct (astaton names) body#gno) else - let null = Z3native.mk_null() in (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) @@ -1946,7 +1945,6 @@ struct (Array.length patterns) (patternaton patterns) body#gno) else - let null = Z3native.mk_null() in (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> x#gno) @@ -4347,6 +4345,240 @@ struct end +(** Models + + A Model contains interpretations (assignments) of constants and functions. *) +module Model = +struct + type model = z3_native_object + + (**/**) + let model_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : model = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.model_inc_ref ; + dec_ref = Z3native.model_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. + *) + module FuncInterp = + struct + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. + *) + module FuncEntry = + struct + (** + Return the (symbolic) value of this entry. + *) + let get_value ( x : func_entry ) = + create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + + (** + The number of arguments of the entry. + *) + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + + (** + The arguments of the function entry. + *) + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + Array.init n f + + (** + A string representation of the function entry. + *) + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") + end + + (** + The number of entries in the function interpretation. + *) + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + + (** + The entries in the function interpretation + *) + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + Array.init n f + + (** + The (symbolic) `else' value of the function interpretation. + *) + let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + + (** + The arity of the function interpretation + *) + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + + (** + A string representation of the function interpretation. + *) + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (Array.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + end + + (** Retrieves the interpretation (the assignment) of in the model. + A function declaration of zero arity + An expression if the function has an interpretation in the model, null otherwise. *) + let get_const_interp ( x : model ) ( f : func_decl ) = + if (FuncDecl.get_arity f) != 0 || + (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then + raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") + else + let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) f#gno in + if (Z3native.is_null np) then + None + else + Some (create_expr (z3obj_gc x) np) + + (** Retrieves the interpretation (the assignment) of in the model. + A Constant + An expression if the constant has an interpretation in the model, null otherwise. + *) + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + + + (** Retrieves the interpretation (the assignment) of a non-constant in the model. + A function declaration of non-zero arity + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + let rec get_func_interp ( x : model ) ( f : func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range f#gnc f#gno))) in + if (FuncDecl.get_arity f) == 0 then + let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) f#gno in + if (Z3native.is_null n) then + None + else + match sk with + | ARRAY_SORT -> + if not (Z3native.is_as_array (z3obj_gnc x) n) then + raise (Z3native.Exception "Argument was not an array constant") + else + let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in + get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) + | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); + else + let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) f#gno) in + if (Z3native.is_null n) then None else Some ((new func_interp (z3obj_gc x))#cnstr_obj n) + + (** The number of constants that have an interpretation in the model. *) + let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) + + (** The function declarations of the constants in the model. *) + let get_const_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + Array.init n f + + + (** The number of function interpretations in the model. *) + let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) + + (** The function declarations of the function interpretations in the model. *) + let get_func_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + Array.init n f + + (** All symbols that have an interpretation in the model. *) + let get_decls ( x : model ) = + let n_funcs = (get_num_funcs x) in + let n_consts = (get_num_consts x ) in + let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + Array.append (Array.init n_funcs f) (Array.init n_consts g) + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) + exception ModelEvaluationFailedException of string + + (** + 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. + + The evaluation of in the model. + *) + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) t#gno completion) in + if not r then + raise (ModelEvaluationFailedException "evaluation failed") + else + create_expr (z3obj_gc x) v + + (** Alias for eval. *) + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + eval x t completion + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) + + (** 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. + + + *) + let get_sorts ( x : model ) = + let n = (get_num_sorts x) in + let f i = (create_sort (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in + Array.init n f + + + (** The finite set of distinct values that represent the interpretation for sort . + + An uninterpreted sort + An array of expressions, where each is an element of the universe of + *) + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in + Array.init n f + + (** Conversion of models to strings. + A string representation of the model. + *) + let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) +end + + (** Tactics Tactics are the basic building block for creating custom solvers for specific problem domains. @@ -4380,8 +4612,8 @@ struct goal g, that the ApplyResult was obtained from. #return A model for g *) - let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = - (new model x#gc)#cnstr_obj (Z3native.apply_result_convert_model x#gnc x#gno i m#gno) + let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = + Model.model_cnstr x#gc (Z3native.apply_result_convert_model x#gnc x#gno i (z3obj_gno m)) (** A string representation of the ApplyResult. *) let to_string ( x : apply_result ) = Z3native.apply_result_to_string x#gnc x#gno @@ -4401,11 +4633,6 @@ end | None -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply x#gnc x#gno g#gno) | Some (pn) -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno) - (** creates a solver that is implemented using the given tactic. - *) - let get_solver ( x : tactic ) = - (new solver x#gc)#cnstr_obj (Z3native.mk_solver_from_tactic x#gnc x#gno) - (** The number of supported tactics. *) @@ -4654,9 +4881,23 @@ struct (new probe ctx)#cnstr_obj (Z3native.probe_not (context_gno ctx) p#gno) end + (** Solvers *) module Solver = struct + type solver = z3_native_object + +(**/**) + let solver_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : solver = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.solver_inc_ref ; + dec_ref = Z3native.solver_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res +(**/**) + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE let string_of_status ( s : status) = match s with @@ -4667,6 +4908,18 @@ struct (** Objects that track statistical information about solvers. *) module Statistics = struct + type statistics = z3_native_object + + (**/**) + let statistics_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : statistics = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.stats_inc_ref ; + dec_ref = Z3native.stats_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) (** Statistical data is organized into pairs of [Key, Entry], where every @@ -4703,20 +4956,20 @@ struct end (** A string representation of the statistical data. *) - let to_string ( x : statistics ) = Z3native.stats_to_string x#gnc x#gno + let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) (** The number of statistical data. *) - let get_size ( x : statistics ) = Z3native.stats_size x#gnc x#gno + let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) (** The data entries. *) let get_entries ( x : statistics ) = let n = (get_size x ) in let f i = ( - let k = Z3native.stats_get_key x#gnc x#gno i in - if (Z3native.stats_is_uint x#gnc x#gno i) then - ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value x#gnc x#gno i)) + let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in + if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then + ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value x#gnc x#gno i)) + ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in Array.init n f @@ -4725,7 +4978,7 @@ struct *) let get_keys ( x : statistics ) = let n = (get_size x) in - let f i = (Z3native.stats_get_key x#gnc x#gno i) in + let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** @@ -4739,51 +4992,51 @@ struct (** A string that describes all available solver parameters. *) - let get_help ( x : solver ) = Z3native.solver_get_help x#gnc x#gno + let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) (** Sets the solver parameters. *) let set_parameters ( x : solver ) ( value : params )= - Z3native.solver_set_params x#gnc x#gno value#gno + Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) value#gno (** Retrieves parameter descriptions for solver. *) let get_param_descrs ( x : solver ) = - (new param_descrs x#gc)#cnstr_obj (Z3native.solver_get_param_descrs x#gnc x#gno) + (new param_descrs (z3obj_gc x))#cnstr_obj (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** The current number of backtracking points (scopes). *) - let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes x#gnc x#gno + let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) (** Creates a backtracking point. *) - let push ( x : solver ) = Z3native.solver_push x#gnc x#gno + let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) (** Backtracks backtracking points. Note that an exception is thrown if is not smaller than NumScopes *) - let pop ( x : solver ) ( n : int ) = Z3native.solver_pop x#gnc x#gno n + let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n (** Resets the Solver. This removes all assertions from the solver. *) - let reset ( x : solver ) = Z3native.solver_reset x#gnc x#gno + let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) (** Assert a constraint (or multiple) into the solver. *) let assert_ ( x : solver ) ( constraints : bool_expr array ) = - let f e = (Z3native.solver_assert x#gnc x#gno e#gno) in + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in ignore (Array.map f constraints) ; () @@ -4791,7 +5044,7 @@ struct The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in + let a = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) @@ -4799,9 +5052,9 @@ struct The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_assertions x#gnc x#gno) in + let a = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in - let f i = ((new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get a i)#gno) in + let f i = ((new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get a i)#gno) in Array.init n f (** @@ -4814,9 +5067,9 @@ struct let check ( x : solver ) ( assumptions : bool_expr array) = let r = if ((Array.length assumptions) == 0) then - lbool_of_int (Z3native.solver_check x#gnc x#gno) + lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - lbool_of_int (Z3native.solver_check_assumptions x#gnc x#gno (Array.length assumptions) (astaton assumptions)) + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (astaton assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -4830,11 +5083,11 @@ struct if its results was not SATISFIABLE, or if model production is not enabled. *) let get_model ( x : solver ) = - let q = Z3native.solver_get_model x#gnc x#gno in + let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in if (Z3native.is_null q) then None else - Some ((new model x#gc)#cnstr_obj q) + Some (Model.model_cnstr (z3obj_gc x) q) (** The proof of the last Check. @@ -4843,11 +5096,11 @@ struct if its results was not UNSATISFIABLE, or if proof production is disabled. *) let get_proof ( x : solver ) = - let q = Z3native.solver_get_proof x#gnc x#gno in + let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in if (Z3native.is_null q) then None else - Some (create_expr x#gc q) + Some (create_expr (z3obj_gc x) q) (** The unsat core of the last Check. @@ -4857,7 +5110,7 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = (new ast_vector x#gc)#cnstr_obj (Z3native.solver_get_unsat_core x#gnc x#gno) in + let cn = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f @@ -4865,14 +5118,14 @@ struct (** A brief justification of why the last call to Check returned UNKNOWN. *) - let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown x#gnc x#gno + let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) (** Solver statistics. *) let get_statistics ( x : solver ) = - (new statistics x#gc)#cnstr_obj (Z3native.solver_get_statistics x#gnc x#gno) + (Statistics.statistics_cnstr (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) (** Creates a new (incremental) solver. @@ -4883,8 +5136,8 @@ struct *) let mk_solver ( ctx : context ) ( logic : symbol option) = match logic with - | None -> (new solver ctx)#cnstr_obj (Z3native.mk_solver (context_gno ctx)) - | Some (x) -> (new solver ctx)#cnstr_obj (Z3native.mk_solver_for_logic (context_gno ctx) x#gno) + | None -> (solver_cnstr ctx (Z3native.mk_solver (context_gno ctx))) + | Some (x) -> (solver_cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) x#gno)) (** Creates a new (incremental) solver. @@ -4897,7 +5150,7 @@ struct Creates a new (incremental) solver. *) let mk_simple_solver ( ctx : context ) = - (new solver ctx)#cnstr_obj (Z3native.mk_simple_solver (context_gno ctx)) + (solver_cnstr ctx (Z3native.mk_simple_solver (context_gno ctx))) (** Creates a solver that is implemented using the given tactic. @@ -4906,261 +5159,54 @@ struct will always solve each check from scratch. *) let mk_solver_t ( ctx : context ) ( t : tactic ) = - (new solver ctx)#cnstr_obj (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno) + (solver_cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno)) (** A string representation of the solver. *) - let to_string ( x : solver ) = Z3native.solver_to_string x#gnc x#gno + let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) end -(** Models - - A Model contains interpretations (assignments) of constants and functions. *) -module Model = -struct - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. - *) - module FuncInterp = - struct - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. - *) - module FuncEntry = - struct - (** - Return the (symbolic) value of this entry. - *) - let get_value ( x : func_entry ) = - create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) - - (** - The number of arguments of the entry. - *) - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno - - (** - The arguments of the function entry. - *) - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in - Array.init n f - - (** - A string representation of the function entry. - *) - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") - end - - (** - The number of entries in the function interpretation. - *) - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno - - (** - The entries in the function interpretation - *) - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in - Array.init n f - - (** - The (symbolic) `else' value of the function interpretation. - *) - let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) - - (** - The arity of the function interpretation - *) - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno - - (** - A string representation of the function interpretation. - *) - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (Array.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") - end - - (** Retrieves the interpretation (the assignment) of in the model. - A function declaration of zero arity - An expression if the function has an interpretation in the model, null otherwise. *) - let get_const_interp ( x : model ) ( f : func_decl ) = - if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then - raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") - else - let np = Z3native.model_get_const_interp x#gnc x#gno f#gno in - if (Z3native.is_null np) then - None - else - Some (create_expr x#gc np) - - (** Retrieves the interpretation (the assignment) of in the model. - A Constant - An expression if the constant has an interpretation in the model, null otherwise. - *) - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - - - (** Retrieves the interpretation (the assignment) of a non-constant in the model. - A function declaration of non-zero arity - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_range f#gnc f#gno))) in - if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp x#gnc x#gno f#gno in - if (Z3native.is_null n) then - None - else - match sk with - | ARRAY_SORT -> - if not (Z3native.is_as_array x#gnc n) then - raise (Z3native.Exception "Argument was not an array constant") - else - let fd = Z3native.get_as_array_func_decl x#gnc n in - get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) - | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); - else - let n = (Z3native.model_get_func_interp x#gnc x#gno f#gno) in - if (Z3native.is_null n) then None else Some ((new func_interp x#gc)#cnstr_obj n) - - (** The number of constants that have an interpretation in the model. *) - let get_num_consts ( x : model ) = Z3native.model_get_num_consts x#gnc x#gno - - (** The function declarations of the constants in the model. *) - let get_const_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in - Array.init n f - - - (** The number of function interpretations in the model. *) - let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs x#gnc x#gno - - (** The function declarations of the function interpretations in the model. *) - let get_func_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in - Array.init n f - - (** All symbols that have an interpretation in the model. *) - let get_decls ( x : model ) = - let n_funcs = (get_num_funcs x) in - let n_consts = (get_num_consts x ) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_func_decl x#gnc x#gno i) in - let g i = (new func_decl x#gc)#cnstr_obj (Z3native.model_get_const_decl x#gnc x#gno i) in - Array.append (Array.init n_funcs f) (Array.init n_consts g) - - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) - exception ModelEvaluationFailedException of string - - (** - 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. - - The evaluation of in the model. - *) - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval x#gnc x#gno t#gno completion) in - if not r then - raise (ModelEvaluationFailedException "evaluation failed") - else - create_expr x#gc v - - (** Alias for eval. *) - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = - eval x t completion - - (** The number of uninterpreted sorts that the model has an interpretation for. *) - let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts x#gnc x#gno - - (** 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. - - - *) - let get_sorts ( x : model ) = - let n = (get_num_sorts x) in - let f i = (create_sort x#gc (Z3native.model_get_sort x#gnc x#gno i)) in - Array.init n f - - - (** The finite set of distinct values that represent the interpretation for sort . - - An uninterpreted sort - An array of expressions, where each is an element of the universe of - *) - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = (new ast_vector x#gc)#cnstr_obj (Z3native.model_get_sort_universe x#gnc x#gno s#gno) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in - Array.init n f - - (** Conversion of models to strings. - A string representation of the model. - *) - let to_string ( x : model ) = Z3native.model_to_string x#gnc x#gno -end - (** Fixedpoint solving *) module Fixedpoints = struct + type fixedpoint = z3_native_object + +(**/**) + let fixedpoint_cnstr ( ctx : context ) = + let res : fixedpoint = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.fixedpoint_inc_ref ; + dec_ref = Z3native.fixedpoint_dec_ref } in + (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; + (z3obj_cnstr res) ; + res +(**/**) + (** A string that describes all available fixedpoint solver parameters. *) let get_help ( x : fixedpoint ) = - Z3native.fixedpoint_get_help x#gnc x#gno + Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) (** Sets the fixedpoint solver parameters. *) let set_params ( x : fixedpoint ) ( p : params )= - Z3native.fixedpoint_set_params x#gnc x#gno p#gno + Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) p#gno (** Retrieves parameter descriptions for Fixedpoint solver. *) let get_param_descrs ( x : fixedpoint ) = - (new param_descrs x#gc)#cnstr_obj (Z3native.fixedpoint_get_param_descrs x#gnc x#gno) + (new param_descrs (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Assert a constraints into the fixedpoint solver. *) let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = - let f e = (Z3native.fixedpoint_assert x#gnc x#gno e#gno) in + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in ignore (Array.map f constraints) ; () @@ -5168,21 +5214,21 @@ struct Register predicate as recursive relation. *) let register_relation ( x : fixedpoint ) ( f : func_decl ) = - Z3native.fixedpoint_register_relation x#gnc x#gno f#gno + Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) f#gno (** Add rule into the fixedpoint solver. *) let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = match name with - | None -> Z3native.fixedpoint_add_rule x#gnc x#gno rule#gno (Z3native.mk_null()) - | Some(y) -> Z3native.fixedpoint_add_rule x#gnc x#gno rule#gno y#gno + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno y#gno (** Add table fact to the fixedpoint solver. *) let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = - Z3native.fixedpoint_add_fact x#gnc x#gno pred#gno (Array.length args) args + Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) pred#gno (Array.length args) args (** Query the fixedpoint solver. @@ -5191,7 +5237,7 @@ struct The query is unsatisfiable if there are no derivations satisfying the query variables. *) let query ( x : fixedpoint ) ( query : bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query x#gnc x#gno query#gno)) with + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) query#gno)) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -5203,7 +5249,7 @@ struct The query is unsatisfiable if there are no derivations satisfying any of the relations. *) let query_r ( x : fixedpoint ) ( relations : func_decl array ) = - match (lbool_of_int (Z3native.fixedpoint_query_relations x#gnc x#gno (Array.length relations) (func_declaton relations))) with + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (func_declaton relations))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -5213,7 +5259,7 @@ struct *) let push ( x : fixedpoint ) = - Z3native.fixedpoint_push x#gnc x#gno + Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) (** Backtrack one backtracking point. @@ -5222,94 +5268,93 @@ struct *) let pop ( x : fixedpoint ) = - Z3native.fixedpoint_pop x#gnc x#gno + Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) (** Update named rule into in the fixedpoint solver. *) let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = - Z3native.fixedpoint_update_rule x#gnc x#gno rule#gno name#gno + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) rule#gno name#gno (** Retrieve satisfying instance or instances of solver, or definitions for the recursive predicates that show unsatisfiability. *) let get_answer ( x : fixedpoint ) = - let q = (Z3native.fixedpoint_get_answer x#gnc x#gno) in + let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in if (Z3native.is_null q) then None else - Some (create_expr x#gc q) + Some (create_expr (z3obj_gc x) q) (** Retrieve explanation why fixedpoint engine returned status Unknown. *) let get_reason_unknown ( x : fixedpoint ) = - Z3native.fixedpoint_get_reason_unknown x#gnc x#gno + Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) (** Retrieve the number of levels explored for a given predicate. *) let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = - Z3native.fixedpoint_get_num_levels x#gnc x#gno predicate#gno + Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) predicate#gno (** Retrieve the cover of a predicate. *) let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = - let q = (Z3native.fixedpoint_get_cover_delta x#gnc x#gno level predicate#gno) in + let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level predicate#gno) in if (Z3native.is_null q) then None else - Some (create_expr x#gc q) + Some (create_expr (z3obj_gc x) q) (** Add property about the predicate. The property is added at level. *) let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover x#gnc x#gno level predicate#gno, property#gno + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level predicate#gno property#gno (** Retrieve internal string representation of fixedpoint object. *) - let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string x#gnc x#gno 0 [||] + let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = - Z3native.fixedpoint_set_predicate_representation x#gnc x#gno f#gno (Array.length kinds) (symbolaton kinds) + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) f#gno (Array.length kinds) (symbolaton kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. *) let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = - Z3native.fixedpoint_to_string x#gnc x#gno (Array.length queries) (astaton queries) + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (astaton queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = ((new ast_vector x#gc)#cnstr_obj (Z3native.fixedpoint_get_rules x#gnc x#gno)) in + let v = ((new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get v i)#gno in + let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = ((new ast_vector x#gc)#cnstr_obj (Z3native.fixedpoint_get_assertions x#gnc x#gno)) in + let v = ((new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr x#gc)#cnstr_obj (AST.ASTVector.get v i)#gno in + let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in Array.init n f (** Create a Fixedpoint context. *) - let mk_fixedpoint ( ctx : context ) = - (new fixedpoint ctx)#cnstr_obj (Z3native.mk_fixedpoint (context_gno ctx)) + let mk_fixedpoint ( ctx : context ) = fixedpoint_cnstr ctx end (** Global and context options From 3347d7ca8c74c21fef3218fb486abfb66810fcd2 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 12 Jan 2013 01:15:23 +0000 Subject: [PATCH 162/248] ML API: moved more objects into normal types. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 1 - src/api/ml/z3.ml | 766 +++++++++++++++++++------------------- 2 files changed, 392 insertions(+), 375 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 97985a7bc..38b5fe642 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -14,7 +14,6 @@ open Z3.Tactic.ApplyResult open Z3.Probe open Z3.Solver open Z3.Arithmetic -open Z3.Fixedpoints exception TestFailedException of string diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 1e8ffe92e..545c7c227 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -20,7 +20,7 @@ let context_dispose ctx = (Z3native.del_context ctx.m_n_ctx) ) else ( Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; - (* re-queue for finalization? *) + (* re-queue for finalization? *) ) let context_cnstr settings = @@ -38,7 +38,7 @@ let context_cnstr settings = (* CMW: Install error handler here! m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); + GC.SuppressFinalize(this); *) let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) @@ -49,23 +49,23 @@ let context_gno ctx = ctx.m_n_ctx (** Create a context object. -Most interactions with Z3 are interpreted in some context; many users will only -require one such object, but power users may require more than one. To start using -Z3, do + Most interactions with Z3 are interpreted in some context; many users will only + require one such object, but power users may require more than one. To start using + Z3, do - + let ctx = (mk_context []) in (...) - + -where a list of pairs of strings may be passed to set options on -the context, e.g., like so: + where a list of pairs of strings may be passed to set options on + the context, e.g., like so: - + let cfg = [("model", "true"); ("...", "...")] in let ctx = (mk_context cfg) in (...) - + *) let mk_context ( cfg : ( string * string ) list ) = context_cnstr cfg @@ -656,70 +656,6 @@ let tacticaton (a : tactic array) = let f (e : tactic) = e#gno in Array.map f a -(** Function interpretation entry objects *) -class func_entry ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.func_entry_inc_ref nc o - method decref nc o = Z3native.func_entry_dec_ref nc o -end - -(** Function interpretation objects *) -class func_interp ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.func_interp_inc_ref nc o - method decref nc o = Z3native.func_interp_dec_ref nc o -end - -(** Tactic application result objects *) -class apply_result ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.apply_result_inc_ref nc o - method decref nc o = Z3native.apply_result_dec_ref nc o -end - -(** Probe objects *) -class probe ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.probe_inc_ref nc o - method decref nc o = Z3native.probe_dec_ref nc o -end - -(** Statistical value objects *) -class statistics_entry = -object (self) - val mutable m_key : string = "" - val mutable m_is_int = false - val mutable m_is_float = false - val mutable m_int = 0 - val mutable m_float = 0.0 - - method cnstr_si k v = - m_key <- k; - m_is_int <- true; - m_int <- v; - self - - method cnstr_sd k v = - m_key <- k; - m_is_float <- true; - m_float <- v; - self - - method key = m_key - method int = m_int - method float = m_float - method is_int = m_is_int - method is_float = m_is_float -end - type z3_native_object = { m_ctx : context ; @@ -1012,46 +948,46 @@ struct x#rational end - (** - Creates a new function declaration. - *) - let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr name domain range + (** + Creates a new function declaration. + *) + let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr name domain range - (** - Creates a new function declaration. - *) - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = - mk_func_decl ctx ((Symbol.mk_string ctx name) :> symbol) domain range + (** + Creates a new function declaration. + *) + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = + mk_func_decl ctx ((Symbol.mk_string ctx name) :> symbol) domain range - (** - Creates a fresh function declaration with a name prefixed with . - - - *) - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort) = - (new func_decl ctx)#cnstr_pdr prefix domain range + (** + Creates a fresh function declaration with a name prefixed with . + + + *) + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort) = + (new func_decl ctx)#cnstr_pdr prefix domain range - (** - Creates a new constant function declaration. - *) - let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr name [||] range + (** + Creates a new constant function declaration. + *) + let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr name [||] range - (** - Creates a new constant function declaration. - *) - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr ((Symbol.mk_string ctx name) :> symbol) [||] range + (** + Creates a new constant function declaration. + *) + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = + (new func_decl ctx)#cnstr_ndr ((Symbol.mk_string ctx name) :> symbol) [||] range - (** - Creates a fresh constant function declaration with a name prefixed with . - - - *) - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = - (new func_decl ctx)#cnstr_pdr prefix [||] range + (** + Creates a fresh constant function declaration with a name prefixed with . + + + *) + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = + (new func_decl ctx)#cnstr_pdr prefix [||] range (** @@ -1333,31 +1269,31 @@ struct else (create_ast to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx))) -(** - Wraps an AST. + (** + 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., - . - - @param nativeObject The native pointer to wrap. -*) + 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., + . + + @param nativeObject The native pointer to wrap. + *) let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = - create_ast ctx ptr + create_ast ctx ptr -(** - 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., - ). - - @param a The AST to unwrap. -*) + (** + 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., + ). + + @param a The AST to unwrap. + *) let unwrap_ast ( a : ast ) = a#gno end @@ -1373,17 +1309,17 @@ struct | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno pp#gno) -(** - a string describing all available parameters to Expr.Simplify. -*) + (** + a string describing all available parameters to Expr.Simplify. + *) let get_simplify_help ( ctx : context ) = Z3native.simplify_get_help (context_gno ctx) -(** - Retrieves parameter descriptions for simplifier. -*) - let get_simplify_parameter_descrs ( ctx : context ) = - (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs (context_gno ctx)) + (** + Retrieves parameter descriptions for simplifier. + *) + let get_simplify_parameter_descrs ( ctx : context ) = + (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. @@ -2691,7 +2627,7 @@ struct let (r, v) = Z3native.get_numeral_int x#gnc x#gno in if r then v else raise (Z3native.Exception "Conversion failed.") - + (** Returns a string representation of the numeral. *) let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -3202,7 +3138,7 @@ struct let (r, v) = Z3native.get_numeral_int x#gnc x#gno in if r then v else raise (Z3native.Exception "Conversion failed.") - + (** Returns a string representation of the numeral. *) let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -4150,29 +4086,29 @@ end *) module Params = struct -(** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) -module ParamDescrs = -struct + (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) + module ParamDescrs = + struct - (** Validate a set of parameters. *) - let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno - - (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) + (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno - (** Retrieve all names of parameters. *) - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size x#gnc x#gno in - let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in - Array.init n f + (** Retrieve kind of parameter. *) + let get_kind ( x : param_descrs ) ( name : symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) + + (** Retrieve all names of parameters. *) + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size x#gnc x#gno in + let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in + Array.init n f + + (** The size of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno - (** The size of the ParamDescrs. *) - let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno - - (** Retrieves a string representation of the ParamDescrs. *) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno -end + (** Retrieves a string representation of the ParamDescrs. *) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno + end (** Adds a parameter setting. @@ -4353,11 +4289,11 @@ struct type model = z3_native_object (**/**) - let model_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = let res : model = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.model_inc_ref ; - dec_ref = Z3native.model_dec_ref } in + m_n_obj = null ; + inc_ref = Z3native.model_inc_ref ; + dec_ref = Z3native.model_dec_ref } in (z3obj_sno res ctx no) ; (z3obj_cnstr res) ; res @@ -4370,6 +4306,18 @@ struct *) module FuncInterp = struct + type func_interp = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : func_interp = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.func_interp_inc_ref ; + dec_ref = Z3native.func_interp_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) (** Function interpretations entries @@ -4377,23 +4325,36 @@ struct *) module FuncEntry = struct + type func_entry = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : func_entry = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.func_entry_inc_ref ; + dec_ref = Z3native.func_entry_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + (** Return the (symbolic) value of this entry. *) let get_value ( x : func_entry ) = - create_expr x#gc (Z3native.func_entry_get_value x#gnc x#gno) + create_expr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) (** The number of arguments of the entry. *) - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args x#gnc x#gno + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) (** The arguments of the function entry. *) let get_args ( x : func_entry ) = let n = (get_num_args x) in - let f i = (create_expr x#gc (Z3native.func_entry_get_arg x#gnc x#gno i)) in + let f i = (create_expr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** @@ -4408,25 +4369,25 @@ struct (** The number of entries in the function interpretation. *) - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries x#gnc x#gno + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) (** The entries in the function interpretation *) let get_entries ( x : func_interp ) = let n = (get_num_entries x) in - let f i = ((new func_entry x#gc)#cnstr_obj (Z3native.func_interp_get_entry x#gnc x#gno i)) in + let f i = (FuncEntry.cnstr (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** The (symbolic) `else' value of the function interpretation. *) - let get_else ( x : func_interp ) = create_expr x#gc (Z3native.func_interp_get_else x#gnc x#gno) + let get_else ( x : func_interp ) = create_expr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) (** The arity of the function interpretation *) - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity x#gnc x#gno + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) (** A string representation of the function interpretation. @@ -4486,7 +4447,7 @@ struct | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); else let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) f#gno) in - if (Z3native.is_null n) then None else Some ((new func_interp (z3obj_gc x))#cnstr_obj n) + if (Z3native.is_null n) then None else Some (FuncInterp.cnstr (z3obj_gc x) n) (** The number of constants that have an interpretation in the model. *) let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) @@ -4579,6 +4540,130 @@ struct end +(** Probes + + 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. +*) +module Probe = +struct + type probe = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : probe = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.probe_inc_ref ; + dec_ref = Z3native.probe_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** + Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. + *) + let apply ( x : probe ) (g : goal) = + Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) g#gno + + (** + The number of supported Probes. + *) + let get_num_probes ( ctx : context ) = + Z3native.get_num_probes (context_gno ctx) + + (** + The names of all supported Probes. + *) + let get_probe_names ( ctx : context ) = + let n = (get_num_probes ctx) in + let f i = (Z3native.get_probe_name (context_gno ctx) i) in + Array.init n f + + (** + Returns a string containing a description of the probe with the given name. + *) + let get_probe_description ( ctx : context ) ( name : string ) = + Z3native.probe_get_descr (context_gno ctx) name + + (** + Creates a new Probe. + *) + let mk_probe ( ctx : context ) ( name : string ) = + (cnstr ctx (Z3native.mk_probe (context_gno ctx) name)) + + (** + Create a probe that always evaluates to . + *) + let const ( ctx : context ) ( v : float ) = + (cnstr ctx (Z3native.probe_const (context_gno ctx) v)) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than the value returned by + *) + let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than the value returned by + *) + let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value returned by + is less than or equal the value returned by + *) + let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value returned by + is greater than or equal the value returned by + *) + let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value returned by + is equal to the value returned by + *) + let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value + and evaluate to "true". + *) + (* CMW: and is a keyword *) + let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value + or evaluate to "true". + *) + (* CMW: or is a keyword *) + let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (cnstr ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + (** + Create a probe that evaluates to "true" when the value + does not evaluate to "true". + *) + (* CMW: is not a keyword? *) + let not_ ( ctx : context ) ( p : probe ) = + (cnstr ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) +end + + (** Tactics Tactics are the basic building block for creating custom solvers for specific problem domains. @@ -4588,36 +4673,49 @@ end *) module Tactic = struct -(** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) -module ApplyResult = -struct - (** The number of Subgoals. *) - let get_num_subgoals ( x : apply_result ) = - Z3native.apply_result_get_num_subgoals x#gnc x#gno + (** Tactic application results - (** Retrieves the subgoals from the apply_result. *) - let get_subgoals ( x : apply_result ) = - let n = (get_num_subgoals x) in - let f i = (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) in - Array.init n f - - (** Retrieves the subgoals from the apply_result. *) - let get_subgoal ( x : apply_result ) ( i : int ) = - (new goal x#gc)#cnstr_obj (Z3native.apply_result_get_subgoal x#gnc x#gno i) - - (** 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 - *) - let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = - Model.model_cnstr x#gc (Z3native.apply_result_convert_model x#gnc x#gno i (z3obj_gno m)) - - (** A string representation of the ApplyResult. *) - let to_string ( x : apply_result ) = Z3native.apply_result_to_string x#gnc x#gno -end + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) + module ApplyResult = + struct + type apply_result = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : apply_result = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.apply_result_inc_ref ; + dec_ref = Z3native.apply_result_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** The number of Subgoals. *) + let get_num_subgoals ( x : apply_result ) = + Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoals ( x : apply_result ) = + let n = (get_num_subgoals x) in + let f i = (new goal (z3obj_gc x))#cnstr_obj (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in + Array.init n f + + (** Retrieves the subgoals from the apply_result. *) + let get_subgoal ( x : apply_result ) ( i : int ) = + (new goal (z3obj_gc x))#cnstr_obj (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) + + (** 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 + *) + let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = + Model.cnstr (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) + + (** A string representation of the ApplyResult. *) + let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) + end (** A string containing a description of parameters accepted by the tactic. *) let get_help ( x : tactic ) = Z3native.tactic_get_help x#gnc x#gno @@ -4630,8 +4728,8 @@ end (** Apply the tactic to the goal. *) let apply ( x : tactic ) ( g : goal ) ( p : params option ) = match p with - | None -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply x#gnc x#gno g#gno) - | Some (pn) -> (new apply_result x#gc)#cnstr_obj (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno) + | None -> (ApplyResult.cnstr x#gc (Z3native.tactic_apply x#gnc x#gno g#gno)) + | Some (pn) -> (ApplyResult.cnstr x#gc (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno)) (** The number of supported tactics. @@ -4695,15 +4793,15 @@ end If evaluates to false, then the new tactic behaves like the skip tactic. *) (* CMW: when is a keyword *) - let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_when (context_gno ctx) p#gno t#gno) + let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) t#gno) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) - let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_cond (context_gno ctx) p#gno t1#gno t2#gno) + let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) t1#gno t2#gno) (** Create a tactic that keeps applying until the goal is not @@ -4727,8 +4825,8 @@ end (** Create a tactic that fails if the probe evaluates to false. *) - let fail_if ( ctx : context ) ( p : probe ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if (context_gno ctx) p#gno) + let fail_if ( ctx : context ) ( p : Probe.probe ) = + (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) @@ -4771,124 +4869,14 @@ end Z3native.interrupt (context_gno ctx) end -(** Probes - - 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. -*) -module Probe = -struct - (** - Execute the probe over the goal. - A probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. - *) - let apply ( x : probe ) (g : goal) = - Z3native.probe_apply x#gnc x#gno g#gno - - (** - The number of supported Probes. - *) - let get_num_probes ( ctx : context ) = - Z3native.get_num_probes (context_gno ctx) - - (** - The names of all supported Probes. - *) - let get_probe_names ( ctx : context ) = - let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name (context_gno ctx) i) in - Array.init n f - - (** - Returns a string containing a description of the probe with the given name. - *) - let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr (context_gno ctx) name - - (** - Creates a new Probe. - *) - let mk_probe ( ctx : context ) ( name : string ) = - (new probe ctx)#cnstr_obj (Z3native.mk_probe (context_gno ctx) name) - - (** - Create a probe that always evaluates to . - *) - let const ( ctx : context ) ( v : float ) = - (new probe ctx)#cnstr_obj (Z3native.probe_const (context_gno ctx) v) - - (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by - *) - let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_lt (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by - *) - let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_gt (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by - *) - let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_le (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by - *) - let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_ge (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by - *) - let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_eq (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". - *) - (* CMW: and is a keyword *) - let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_and (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". - *) - (* CMW: or is a keyword *) - let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_or (context_gno ctx) p1#gno p2#gno) - - (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". - *) - (* CMW: is not a keyword? *) - let not_ ( ctx : context ) ( p : probe ) = - (new probe ctx)#cnstr_obj (Z3native.probe_not (context_gno ctx) p#gno) -end - (** Solvers *) module Solver = struct type solver = z3_native_object -(**/**) - let solver_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = let res : solver = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.solver_inc_ref ; @@ -4896,7 +4884,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_cnstr res) ; res -(**/**) + (**/**) type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE @@ -4911,7 +4899,7 @@ struct type statistics = z3_native_object (**/**) - let statistics_cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = let res : statistics = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.stats_inc_ref ; @@ -4919,28 +4907,58 @@ struct (z3obj_sno res ctx no) ; (z3obj_cnstr res) ; res - (**/**) + (**/**) (** - Statistical data is organized into pairs of [Key, Entry], where every - Entry is either a DoubleEntry or a UIntEntry + Statistical data is organized into pairs of \[Key, Entry\], where every + Entry is either a floating point or integer value. + *) module Entry = struct + type statistics_entry = { + mutable m_key : string; + mutable m_is_int : bool ; + mutable m_is_float : bool ; + mutable m_int : int ; + mutable m_float : float } + + (**/**) + let cnstr_si k v = + let res : statistics_entry = { + m_key = k ; + m_is_int = true ; + m_is_float = false ; + m_int = v ; + m_float = 0.0 + } in + res + + let cnstr_sd k v = + let res : statistics_entry = { + m_key = k ; + m_is_int = false ; + m_is_float = true ; + m_int = 0 ; + m_float = v + } in + res + (**/**) + (** The key of the entry. *) - let get_key (x : statistics_entry) = x#key + let get_key (x : statistics_entry) = x.m_key (** The int-value of the entry. *) - let get_int (x : statistics_entry) = x#int + let get_int (x : statistics_entry) = x.m_int (** The float-value of the entry. *) - let get_float (x : statistics_entry) = x#float + let get_float (x : statistics_entry) = x.m_float (** True if the entry is uint-valued. *) - let is_int (x : statistics_entry) = x#is_int + let is_int (x : statistics_entry) = x.m_is_int (** True if the entry is double-valued. *) - let is_float (x : statistics_entry) = x#is_float + let is_float (x : statistics_entry) = x.m_is_float (** The string representation of the the entry's value. *) let to_string_value (x : statistics_entry) = @@ -4967,9 +4985,9 @@ struct let f i = ( let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then - ((new statistics_entry)#cnstr_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.cnstr_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - ((new statistics_entry)#cnstr_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.cnstr_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in Array.init n f @@ -5087,7 +5105,7 @@ struct if (Z3native.is_null q) then None else - Some (Model.model_cnstr (z3obj_gc x) q) + Some (Model.cnstr (z3obj_gc x) q) (** The proof of the last Check. @@ -5125,7 +5143,7 @@ struct Solver statistics. *) let get_statistics ( x : solver ) = - (Statistics.statistics_cnstr (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) + (Statistics.cnstr (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) (** Creates a new (incremental) solver. @@ -5136,8 +5154,8 @@ struct *) let mk_solver ( ctx : context ) ( logic : symbol option) = match logic with - | None -> (solver_cnstr ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (solver_cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) x#gno)) + | None -> (cnstr ctx (Z3native.mk_solver (context_gno ctx))) + | Some (x) -> (cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) x#gno)) (** Creates a new (incremental) solver. @@ -5150,7 +5168,7 @@ struct Creates a new (incremental) solver. *) let mk_simple_solver ( ctx : context ) = - (solver_cnstr ctx (Z3native.mk_simple_solver (context_gno ctx))) + (cnstr ctx (Z3native.mk_simple_solver (context_gno ctx))) (** Creates a solver that is implemented using the given tactic. @@ -5159,7 +5177,7 @@ struct will always solve each check from scratch. *) let mk_solver_t ( ctx : context ) ( t : tactic ) = - (solver_cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno)) + (cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno)) (** A string representation of the solver. @@ -5169,12 +5187,12 @@ end (** Fixedpoint solving *) -module Fixedpoints = +module Fixedpoint = struct type fixedpoint = z3_native_object -(**/**) - let fixedpoint_cnstr ( ctx : context ) = + (**/**) + let cnstr ( ctx : context ) = let res : fixedpoint = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.fixedpoint_inc_ref ; @@ -5182,7 +5200,7 @@ struct (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; (z3obj_cnstr res) ; res -(**/**) + (**/**) (** A string that describes all available fixedpoint solver parameters. @@ -5320,7 +5338,7 @@ struct Retrieve internal string representation of fixedpoint object. *) let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - + (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) @@ -5354,7 +5372,7 @@ struct (** Create a Fixedpoint context. *) - let mk_fixedpoint ( ctx : context ) = fixedpoint_cnstr ctx + let mk_fixedpoint ( ctx : context ) = cnstr ctx end (** Global and context options @@ -5365,24 +5383,24 @@ end module Options = struct -(** - 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. - -*) + (** + 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. + + *) let update_param_value ( ctx : context ) ( id : string) ( value : string )= Z3native.update_param_value (context_gno ctx) id value -(** - Get a configuration parameter. - - Returns None if the parameter value does not exist. - -*) + (** + Get a configuration parameter. + + Returns None if the parameter value does not exist. + + *) let get_param_value ( ctx : context ) ( id : string ) = let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in if not r then @@ -5408,12 +5426,12 @@ struct let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) -(** - Enable/disable printing of warning messages to the console. + (** + Enable/disable printing of warning messages to the console. - Note that this function is static and effects the behaviour of - all contexts globally. -*) + Note that this function is static and effects the behaviour of + all contexts globally. + *) let toggle_warning_messages ( enabled: bool ) = Z3native.toggle_warning_messages enabled end @@ -5581,17 +5599,17 @@ end (* (** - 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. + 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, error_code errorCode, string errorString); + public delegate void ErrorHandler(Context ctx, error_code errorCode, string errorString); - internal Z3native.error_handler m_n_err_handler = null; + internal Z3native.error_handler m_n_err_handler = null; - internal void NativeErrorHandler(IntPtr ctx, error_code errorCode) + internal void NativeErrorHandler(IntPtr ctx, error_code errorCode) - Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. + Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. *) From 1b3e1d1a6c6e18c53cdf8ec893bb52b544a04e8d Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 12 Jan 2013 23:18:05 +0000 Subject: [PATCH 163/248] ML API: moved more objects into normal types. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 734 ++++++++++++++++++++++++++--------------------- 1 file changed, 412 insertions(+), 322 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 545c7c227..8c0f24c4b 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,13 +7,30 @@ open Z3enums -type context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } - -(**/**) - +(**/**) +(* Some helpers. *) + let null = Z3native.mk_null() let is_null o = (Z3native.is_null o) +let mk_list ( f : int -> 'a ) ( n : int ) = + let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = + if (i >= n) then + tail + else + (mk_list' f (i+1) n ((f i) :: tail)) + in + mk_list' f 0 n [] +(**/**) + + +(**/**) +type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } +(**/**) +type context = z3_native_context + +(**/**) + let context_dispose ctx = if ctx.m_n_obj_cnt == 0 then ( (* Printf.printf "Disposing context \n" ; *) @@ -71,8 +88,6 @@ let mk_context ( cfg : ( string * string ) list ) = context_cnstr cfg -(* type z3object = { m_ctx : context; m_n_obj : Z3native.ptr option; } *) - (**/**) class virtual z3object ctx_init obj_init = object (self) @@ -120,17 +135,6 @@ object (self) method gnc = (context_gno m_ctx) end - -(** Parameter set objects *) -class params ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.params_inc_ref nc o - method decref nc o = Z3native.params_dec_ref nc o -end - - (** Symbol objects *) class symbol ctx = object (self) @@ -292,44 +296,6 @@ let func_declaton (a : func_decl array) = let f (e : func_decl) = e#gno in Array.map f a -class parameter = -object (self) - val mutable m_kind : parameter_kind = PARAMETER_INT; - val mutable m_i : int = 0 - val mutable m_d : float = 0.0 - val mutable m_sym : symbol option = None - val mutable m_srt : sort option = None - val mutable m_ast : ast option = None - val mutable m_fd : func_decl option = None - val mutable m_r : string = "" - - method cnstr_int i = m_kind <- PARAMETER_INT; m_i <- i - method cnstr_double d = m_kind <- PARAMETER_DOUBLE; m_d <- d - method cnstr_symbol sym = m_kind <- PARAMETER_SYMBOL; m_sym <- sym - method cnstr_sort srt = m_kind <- PARAMETER_SORT; m_srt <- srt - method cnstr_ast ast = m_kind <- PARAMETER_AST; m_ast <- ast - method cnstr_func_decl fd = m_kind <- PARAMETER_FUNC_DECL; m_fd <- fd - method cnstr_rational r = m_kind <- PARAMETER_RATIONAL; m_r <- r - - method kind = m_kind - method int = m_i - method double = m_d - method symbol = match m_sym with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing parameter symbol") - method sort = match m_srt with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing parameter sort") - method ast = match m_ast with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing parameter ast") - method func_decl = match m_fd with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing parameter func_decl") - method rational = m_r -end - - (** Enum sort objects *) class enum_sort ctx = object (self) @@ -499,26 +465,6 @@ let create_sort ctx obj = | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") -(** AST vector objects *) -class ast_vector ctx = -object (self) - inherit z3object ctx None - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.ast_vector_inc_ref nc o - method decref nc o = Z3native.ast_vector_dec_ref nc o -end - - -(** AST map objects *) -class ast_map ctx = -object (self) - inherit z3object ctx None - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.ast_map_inc_ref nc o - method decref nc o = Z3native.ast_map_dec_ref nc o -end - - (** Expression objects *) class expr ctx = object(self) @@ -625,37 +571,6 @@ let patternaton (a : pattern array) = let f (e : pattern) = e#gno in Array.map f a -(** Parameter description objects *) -class param_descrs ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.param_descrs_inc_ref nc o - method decref nc o = Z3native.param_descrs_dec_ref nc o -end - -(** Goal objects *) -class goal ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.goal_inc_ref nc o - method decref nc o = Z3native.goal_dec_ref nc o -end - -(** Tactic objects *) -class tactic ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = Z3native.tactic_inc_ref nc o - method decref nc o = Z3native.tactic_dec_ref nc o -end - -let tacticaton (a : tactic array) = - let f (e : tactic) = e#gno in - Array.map f a - type z3_native_object = { m_ctx : context ; @@ -689,6 +604,10 @@ let z3obj_cnstr o = let f = fun o -> (z3obj_dispose o) in Gc.finalise f o +let array_to_native a = + let f e = (z3obj_gno e) in + Array.map f a + (**/**) @@ -890,62 +809,153 @@ let create_ast ctx no = (** Function declarations *) module FuncDecl = struct + (** Parameters of Func_Decls *) module Parameter = struct + type parameter = { + m_kind : parameter_kind ; + m_i : int ; + m_d : float ; + m_sym : symbol option ; + m_srt : sort option ; + m_ast : ast option ; + m_fd : func_decl option ; + m_r : string ; + } + + (**/**) + let cnstr_int i = { + m_kind = PARAMETER_INT ; + m_i = i ; + m_d = 0.0 ; + m_sym = None ; + m_srt = None ; + m_ast = None ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_double d = { + m_kind = PARAMETER_DOUBLE ; + m_i = 0 ; + m_d = d ; + m_sym = None ; + m_srt = None ; + m_ast = None ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_symbol sym = { + m_kind = PARAMETER_SYMBOL ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = sym ; + m_srt = None ; + m_ast = None ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_sort srt = { + m_kind = PARAMETER_SORT ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = None ; + m_srt = srt ; + m_ast = None ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_ast ast = { + m_kind = PARAMETER_AST ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = None ; + m_srt = None ; + m_ast = ast ; + m_fd = None ; + m_r = "" ; + } + + let cnstr_func_decl fd ={ + m_kind = PARAMETER_FUNC_DECL ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = None ; + m_srt = None ; + m_ast = None ; + m_fd = fd ; + m_r = "" ; + } + + let cnstr_rational r = { + m_kind = PARAMETER_RATIONAL ; + m_i = 0 ; + m_d = 0.0 ; + m_sym = None ; + m_srt = None ; + m_ast = None ; + m_fd = None ; + m_r = r ; + } + (**/**) + (** The kind of the parameter. *) - let get_kind (x : parameter) = x#kind + let get_kind ( x : parameter ) = x.m_kind (**The int value of the parameter.*) - let get_int (x : parameter) = - if (x#kind != PARAMETER_INT) then + let get_int ( x : parameter ) = + if ((get_kind x) != PARAMETER_INT) then raise (Z3native.Exception "parameter is not an int") else - x#int + x.m_i (**The double value of the parameter.*) - let get_double (x : parameter) = - if (x#kind != PARAMETER_DOUBLE) then + let get_double ( x : parameter ) = + if ((get_kind x) != PARAMETER_DOUBLE) then raise (Z3native.Exception "parameter is not a double") else - x#double + x.m_d (**The Symbol value of the parameter.*) - let get_symbol (x : parameter) = - if (x#kind != PARAMETER_SYMBOL) then + let get_symbol ( x : parameter ) = + if ((get_kind x) != PARAMETER_SYMBOL) then raise (Z3native.Exception "parameter is not a symbol") else - x#symbol + x.m_sym (**The Sort value of the parameter.*) - let get_sort (x : parameter) = - if (x#kind != PARAMETER_SORT) then + let get_sort ( x : parameter ) = + if ((get_kind x) != PARAMETER_SORT) then raise (Z3native.Exception "parameter is not a sort") else - x#sort + x.m_srt (**The AST value of the parameter.*) - let get_ast (x : parameter) = - if (x#kind != PARAMETER_AST) then + let get_ast ( x : parameter ) = + if ((get_kind x) != PARAMETER_AST) then raise (Z3native.Exception "parameter is not an ast") else - x#ast + x.m_ast (**The FunctionDeclaration value of the parameter.*) - let get_ast (x : parameter) = - if (x#kind != PARAMETER_FUNC_DECL) then + let get_ast ( x : parameter ) = + if ((get_kind x) != PARAMETER_FUNC_DECL) then raise (Z3native.Exception "parameter is not an function declaration") else - x#func_decl + x.m_fd (**The rational string value of the parameter.*) - let get_rational (x : parameter) = - if (x#kind != PARAMETER_RATIONAL) then + let get_rational ( x : parameter ) = + if ((get_kind x) != PARAMETER_RATIONAL) then raise (Z3native.Exception "parameter is not a ratinoal string") else - x#rational + x.m_r end (** @@ -1051,7 +1061,7 @@ struct The number of parameters of the function declaration *) let get_num_parameters (x : func_decl) = (Z3native.get_decl_num_parameters x#gnc x#gno) - + (** The parameters of the function declaration *) @@ -1059,15 +1069,15 @@ struct let n = (get_num_parameters x) in let f i = ( match (parameter_kind_of_int (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with - | PARAMETER_INT -> (new parameter)#cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) - | PARAMETER_DOUBLE -> (new parameter)#cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) - | PARAMETER_SYMBOL-> (new parameter)#cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) - | PARAMETER_SORT -> (new parameter)#cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) - | PARAMETER_AST -> (new parameter)#cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) - | PARAMETER_FUNC_DECL -> (new parameter)#cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) - | PARAMETER_RATIONAL -> (new parameter)#cnstr_rational (Z3native.get_decl_rational_parameter x#gnc x#gno i) + | PARAMETER_INT -> Parameter.cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) + | PARAMETER_DOUBLE -> Parameter.cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) + | PARAMETER_SYMBOL-> Parameter.cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) + | PARAMETER_SORT -> Parameter.cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) + | PARAMETER_AST -> Parameter.cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) + | PARAMETER_FUNC_DECL -> Parameter.cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) + | PARAMETER_RATIONAL -> Parameter.cnstr_rational (Z3native.get_decl_rational_parameter x#gnc x#gno i) ) in - Array.init n f + mk_list f n (** Create expression that applies function to arguments. @@ -1083,9 +1093,22 @@ struct (** Vectors of ASTs *) module ASTVector = struct + type ast_vector = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_vector = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_vector_inc_ref ; + dec_ref = Z3native.ast_vector_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + (** The size of the vector *) let get_size ( x : ast_vector ) = - Z3native.ast_vector_size x#gnc x#gno + Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) (** Retrieves the i-th object in the vector. @@ -1093,16 +1116,16 @@ struct @return An AST *) let get ( x : ast_vector ) ( i : int ) = - create_ast x#gc (Z3native.ast_vector_get x#gnc x#gno i) + create_ast (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) (** Sets the i-th object in the vector. *) let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set x#gnc x#gno i value#gno + Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i value#gno (** Resize the vector to . @param newSize The new size of the vector. *) let resize ( x : ast_vector ) ( new_size : int ) = - Z3native.ast_vector_resize x#gnc x#gno new_size + Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size (** Add the AST to the back of the vector. The size @@ -1110,7 +1133,7 @@ struct @param a An AST *) let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push x#gnc x#gno a#gno + Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) a#gno (** Translates all ASTs in the vector to . @@ -1118,60 +1141,73 @@ struct @return A new ASTVector *) let translate ( x : ast_vector ) ( to_ctx : context ) = - (new ast_vector to_ctx)#cnstr_obj (Z3native.ast_vector_translate x#gnc x#gno (context_gno to_ctx)) + cnstr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Retrieves a string representation of the vector. *) let to_string ( x : ast_vector ) = - Z3native.ast_vector_to_string x#gnc x#gno + Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) end (** Map from AST to AST *) module ASTMap = struct + type ast_map = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_map = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_map_inc_ref ; + dec_ref = Z3native.ast_map_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + (** Checks whether the map contains the key . @param k An AST @return True if is a key in the map, false otherwise. *) - let contains ( m : ast_map ) ( key : ast ) = - (Z3native.ast_map_contains m#gnc m#gno key#gno) + let contains ( x : ast_map ) ( key : ast ) = + (Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) key#gno) (** Finds the value associated with the key . This function signs an error when is not a key in the map. @param k An AST *) - let find ( m : ast_map ) ( key : ast ) = - create_ast m#gc (Z3native.ast_map_find m#gnc m#gno key#gno) + let find ( x : ast_map ) ( key : ast ) = + create_ast (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) key#gno) (** Stores or replaces a new key/value pair in the map. @param k The key AST @param v The value AST *) - let insert ( m : ast_map ) ( key : ast ) ( value : ast) = - Z3native.ast_map_insert m#gnc m#gno key#gno value#gno + let insert ( x : ast_map ) ( key : ast ) ( value : ast) = + Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) key#gno value#gno (** Erases the key from the map. @param k An AST *) - let erase ( m : ast_map ) ( key : ast ) = - Z3native.ast_map_erase m#gnc m#gno key#gno + let erase ( x : ast_map ) ( key : ast ) = + Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) key#gno (** Removes all keys from the map. *) - let reset ( m : ast_map ) = - Z3native.ast_map_reset m#gnc m#gno + let reset ( x : ast_map ) = + Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) (** The size of the map *) - let get_size ( m : ast_map ) = - Z3native.ast_map_size m#gnc m#gno + let get_size ( x : ast_map ) = + Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) (** The keys stored in the map. *) - let get_keys ( m : ast_map ) = - (new ast_vector m#gc)#cnstr_obj (Z3native.ast_map_keys m#gnc m#gno) + let get_keys ( x : ast_map ) = + ASTVector.cnstr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) (** Retrieves a string representation of the map.*) - let to_strnig ( m : ast_map ) = - Z3native.ast_map_to_string m#gnc m#gno + let to_string ( x : ast_map ) = + Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) end (** @@ -1297,6 +1333,125 @@ struct let unwrap_ast ( a : ast ) = a#gno end + +(** + Parameter sets (of Solvers, Tactics, ...) + + A Params objects represents a configuration in the form of symbol/value pairs. +*) +module Params = +struct + type params = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : params = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.params_inc_ref ; + dec_ref = Z3native.params_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) + module ParamDescrs = + struct + type param_descrs = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : param_descrs = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.param_descrs_inc_ref ; + dec_ref = Z3native.param_descrs_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + + (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params ) = + Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) + + (** Retrieve kind of parameter. *) + let get_kind ( x : param_descrs ) ( name : symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) name#gno)) + + (** Retrieve all names of parameters. *) + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in + let f i = create_symbol (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in + Array.init n f + + (** The size of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) + + (** Retrieves a string representation of the ParamDescrs. *) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) + end + + (** + Adds a parameter setting. + *) + let add_bool ( x : params ) ( name : symbol ) ( value : bool ) = + Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) name#gno value + + (** + Adds a parameter setting. + *) + let add_int ( x : params ) (name : symbol ) ( value : int ) = + Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) name#gno value + + (** + Adds a parameter setting. + *) + let add_double ( x : params ) ( name : symbol ) ( value : float ) = + Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) name#gno value + + (** + Adds a parameter setting. + *) + let add_symbol ( x : params ) ( name : symbol ) ( value : symbol ) = + Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) name#gno value#gno + + (** + Adds a parameter setting. + *) + let add_s_bool ( x : params ) ( name : string) ( value : bool ) = + add_bool x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + + (** + Adds a parameter setting. + *) + let add_s_int ( x : params) ( name : string ) ( value : int ) = + add_int x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + + (** + Adds a parameter setting. + *) + let add_s_double ( x : params ) ( name : string ) ( value : float ) = + add_double x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + + (** + Adds a parameter setting. + *) + let add_s_symbol ( x : params ) ( name : string ) ( value : symbol ) = + add_symbol x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + + (** + Creates a new parameter set + *) + let mk_params ( ctx : context ) = + cnstr ctx (Z3native.mk_params (context_gno ctx)) + + (** + A string representation of the parameter set. + *) + let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) +end + + (** General expressions (terms), including Boolean logic *) module Expr = struct @@ -1305,9 +1460,9 @@ struct @param p A set of parameters to configure the simplifier *) - let simplify ( x : expr ) ( p : params option ) = match p with + let simplify ( x : expr ) ( p : Params.params option ) = match p with | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) - | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno pp#gno) + | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno (z3obj_gno pp)) (** a string describing all available parameters to Expr.Simplify. @@ -1319,7 +1474,7 @@ struct Retrieves parameter descriptions for simplifier. *) let get_simplify_parameter_descrs ( ctx : context ) = - (new param_descrs ctx)#cnstr_obj (Z3native.simplify_get_param_descrs (context_gno ctx)) + Params.ParamDescrs.cnstr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. @@ -4079,96 +4234,6 @@ struct let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end -(** - Parameter sets (of Solvers, Tactics, ...) - - A Params objects represents a configuration in the form of symbol/value pairs. -*) -module Params = -struct - (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) - module ParamDescrs = - struct - - (** Validate a set of parameters. *) - let validate ( x : param_descrs ) ( p : params )= Z3native.params_validate x#gnc p#gno x#gno - - (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind x#gnc x#gno name#gno)) - - (** Retrieve all names of parameters. *) - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size x#gnc x#gno in - let f i = create_symbol x#gc (Z3native.param_descrs_get_name x#gnc x#gno i) in - Array.init n f - - (** The size of the ParamDescrs. *) - let get_size ( x : param_descrs ) = Z3native.param_descrs_size x#gnc x#gno - - (** Retrieves a string representation of the ParamDescrs. *) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string x#gnc x#gno - end - - (** - Adds a parameter setting. - *) - let add_bool (p : params) (name : symbol) (value : bool) = - Z3native.params_set_bool p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_int (p : params) (name : symbol) (value : int) = - Z3native.params_set_uint p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_double (p : params) (name : symbol) (value : float) = - Z3native.params_set_double p#gnc p#gno name#gno value - - (** - Adds a parameter setting. - *) - let add_symbol (p : params) (name : symbol) (value : symbol) = - Z3native.params_set_symbol p#gnc p#gno name#gno value#gno - - (** - Adds a parameter setting. - *) - let add_s_bool (p : params) (name : string) (value : bool) = - add_bool p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_int (p : params) (name : string) (value : int) = - add_int p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_double (p : params) (name : string) (value : float) = - add_double p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Adds a parameter setting. - *) - let add_s_symbol (p : params) (name : string) (value : symbol) = - add_symbol p ((new symbol p#gc)#cnstr_obj (Z3native.mk_string_symbol p#gnc name)) value - - (** - Creates a new parameter set - *) - let mk_params ( ctx : context ) = - (new params ctx)#cnstr_obj (Z3native.mk_params (context_gno ctx)) - - (** - A string representation of the parameter set. - *) - let to_string (p : params) = Z3native.params_to_string p#gnc p#gno -end (** Goals @@ -4177,6 +4242,18 @@ end tactics and solvers. *) module Goal = struct + type goal = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : goal = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.goal_inc_ref ; + dec_ref = Z3native.goal_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) (** The precision of the goal. @@ -4185,7 +4262,7 @@ struct An over approximation is applied when the objective is to find a proof for a given goal. *) let get_precision ( x : goal ) = - goal_prec_of_int (Z3native.goal_precision x#gnc x#gno) + goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) (** Indicates whether the goal is precise. *) let is_precise ( x : goal ) = @@ -4206,62 +4283,62 @@ struct (** Adds the constraints to the given goal. *) (* CMW: assert seems to be a keyword. *) let assert_ ( x : goal ) ( constraints : bool_expr array ) = - let f e = Z3native.goal_assert x#gnc x#gno e#gno in + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) e#gno in ignore (Array.map f constraints) ; () (** Indicates whether the goal contains `false'. *) let is_inconsistent ( x : goal ) = - Z3native.goal_inconsistent x#gnc x#gno + Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) (** The depth of the goal. This tracks how many transformations were applied to it. *) - let get_depth ( x : goal ) = Z3native.goal_depth x#gnc x#gno + let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) (** Erases all formulas from the given goal. *) - let reset ( x : goal ) = Z3native.goal_reset x#gnc x#gno + let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) (** The number of formulas in the goal. *) - let get_size ( x : goal ) = Z3native.goal_size x#gnc x#gno + let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = (new bool_expr x#gc)#cnstr_obj (Z3native.goal_formula x#gnc x#gno i) in + let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) - let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs x#gnc x#gno + let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) let is_decided_sat ( x : goal ) = - Z3native.goal_is_decided_sat x#gnc x#gno + Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) let is_decided_unsat ( x : goal ) = - Z3native.goal_is_decided_unsat x#gnc x#gno + Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = - (new goal to_ctx)#cnstr_obj (Z3native.goal_translate x#gnc x#gno (context_gno to_ctx)) + cnstr to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - let simplify ( x : goal ) ( p : params option ) = - let tn = Z3native.mk_tactic x#gnc "simplify" in - Z3native.tactic_inc_ref x#gnc tn ; + let simplify ( x : goal ) ( p : Params.params option ) = + let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in + Z3native.tactic_inc_ref (z3obj_gnc x) tn ; let arn = match p with - | None -> Z3native.tactic_apply x#gnc tn x#gno - | Some(pn) -> Z3native.tactic_apply_ex x#gnc tn x#gno pn#gno + | None -> Z3native.tactic_apply (z3obj_gnc x) tn (z3obj_gno x) + | Some(pn) -> Z3native.tactic_apply_ex (z3obj_gnc x) tn (z3obj_gno x) (z3obj_gno pn) in - Z3native.apply_result_inc_ref x#gnc arn ; - let sg = Z3native.apply_result_get_num_subgoals x#gnc arn in + Z3native.apply_result_inc_ref (z3obj_gnc x) arn ; + let sg = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) arn in let res = if sg == 0 then raise (Z3native.Exception "No subgoals") else - Z3native.apply_result_get_subgoal x#gnc arn 0 in - Z3native.apply_result_dec_ref x#gnc arn ; - Z3native.tactic_dec_ref x#gnc tn ; - (new goal x#gc)#cnstr_obj res + Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in + Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; + Z3native.tactic_dec_ref (z3obj_gnc x) tn ; + cnstr (z3obj_gc x) res (** @@ -4274,10 +4351,10 @@ struct @param proofs Indicates whether proof generation should be enabled. *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - (new goal ctx)#cnstr_obj (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) + cnstr ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) (** A string representation of the Goal. *) - let to_string ( x : goal ) = Z3native.goal_to_string x#gnc x#gno + let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) end @@ -4326,7 +4403,7 @@ struct module FuncEntry = struct type func_entry = z3_native_object - + (**/**) let cnstr ( ctx : context ) ( no : Z3native.ptr ) = let res : func_entry = { m_ctx = ctx ; @@ -4528,7 +4605,7 @@ struct An array of expressions, where each is an element of the universe of *) let sort_universe ( x : model ) ( s : sort ) = - let n_univ = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in + let n_univ = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in Array.init n f @@ -4568,8 +4645,8 @@ struct A probe always produce a double value. "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - let apply ( x : probe ) (g : goal) = - Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) g#gno + let apply ( x : probe ) (g : Goal.goal) = + Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (** The number of supported Probes. @@ -4673,6 +4750,19 @@ end *) module Tactic = struct + type tactic = z3_native_object + + (**/**) + let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let res : tactic = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.tactic_inc_ref ; + dec_ref = Z3native.tactic_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + (**/**) + (** Tactic application results ApplyResult objects represent the result of an application of a @@ -4699,12 +4789,12 @@ struct (** Retrieves the subgoals from the apply_result. *) let get_subgoals ( x : apply_result ) = let n = (get_num_subgoals x) in - let f i = (new goal (z3obj_gc x))#cnstr_obj (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in + let f i = Goal.cnstr (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** Retrieves the subgoals from the apply_result. *) let get_subgoal ( x : apply_result ) ( i : int ) = - (new goal (z3obj_gc x))#cnstr_obj (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) + Goal.cnstr (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) (** Convert a model for the subgoal into a model for the original goal g, that the ApplyResult was obtained from. @@ -4718,18 +4808,17 @@ struct end (** A string containing a description of parameters accepted by the tactic. *) - let get_help ( x : tactic ) = Z3native.tactic_get_help x#gnc x#gno - + let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) (** Retrieves parameter descriptions for Tactics. *) let get_param_descrs ( x : tactic ) = - (new param_descrs x#gc)#cnstr_obj (Z3native.tactic_get_param_descrs x#gnc x#gno) + Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Apply the tactic to the goal. *) - let apply ( x : tactic ) ( g : goal ) ( p : params option ) = + let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = match p with - | None -> (ApplyResult.cnstr x#gc (Z3native.tactic_apply x#gnc x#gno g#gno)) - | Some (pn) -> (ApplyResult.cnstr x#gc (Z3native.tactic_apply_ex x#gnc x#gno g#gno pn#gno)) + | None -> (ApplyResult.cnstr (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) + | Some (pn) -> (ApplyResult.cnstr (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) (** The number of supported tactics. @@ -4755,7 +4844,7 @@ struct Creates a new Tactic. *) let mk_tactic ( ctx : context ) ( name : string ) = - (new tactic ctx)#cnstr_obj (Z3native.mk_tactic (context_gno ctx) name) + cnstr ctx (Z3native.mk_tactic (context_gno ctx) name) (** Create a tactic that applies to a Goal and @@ -4763,20 +4852,21 @@ struct *) let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array ) = let f p c = (match p with - | None -> (Some c#gno) - | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) c#gno x))) in + | None -> (Some (z3obj_gno c)) + | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in match (Array.fold_left f None ts) with - | None -> (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then (context_gno ctx) t1#gno t2#gno) + | None -> + cnstr ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) | Some(x) -> - let o = (Z3native.tactic_and_then (context_gno ctx) t2#gno x) in - (new tactic ctx)#cnstr_obj (Z3native.tactic_and_then (context_gno ctx) t1#gno o) + let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in + cnstr ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) (** Create a tactic that first applies to a Goal and if it fails then returns the result of applied to the Goal. *) let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_or_else (context_gno ctx) t1#gno t2#gno) + cnstr ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) (** Create a tactic that applies to a goal for milliseconds. @@ -4784,7 +4874,7 @@ struct If does not terminate within milliseconds, then it fails. *) let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_try_for (context_gno ctx) t#gno ms) + cnstr ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) (** Create a tactic that applies to a given goal if the probe @@ -4794,72 +4884,72 @@ struct *) (* CMW: when is a keyword *) let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) t#gno) + cnstr ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) t1#gno t2#gno) + cnstr ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) (** Create a tactic that keeps applying until the goal is not modified anymore or the maximum number of iterations is reached. *) let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_repeat (context_gno ctx) t#gno max) + cnstr ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) (** Create a tactic that just returns the given goal. *) let skip ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_skip (context_gno ctx)) + cnstr ctx (Z3native.tactic_skip (context_gno ctx)) (** Create a tactic always fails. *) let fail ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail (context_gno ctx)) + cnstr ctx (Z3native.tactic_fail (context_gno ctx)) (** Create a tactic that fails if the probe evaluates to false. *) let fail_if ( ctx : context ) ( p : Probe.probe ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) + cnstr ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) or trivially unsatisfiable (i.e., contains `false'). *) let fail_if_not_decided ( ctx : context ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_fail_if_not_decided (context_gno ctx)) + cnstr ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) (** Create a tactic that applies using the given set of parameters . *) - let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_using_params (context_gno ctx) t#gno p#gno) + let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + cnstr ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) (** Create a tactic that applies using the given set of parameters . Alias for UsingParams*) (* CMW: with is a keyword *) - let with_ ( ctx : context ) ( t : tactic ) ( p : params ) = + let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = using_params ctx t p (** Create a tactic that applies the given tactics in parallel. *) let par_or ( ctx : context ) ( t : tactic array ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (tacticaton t)) + cnstr ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) (** Create a tactic that applies to a given goal and then to every subgoal produced by . The subgoals are processed in parallel. *) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - (new tactic ctx)#cnstr_obj (Z3native.tactic_par_and_then (context_gno ctx) t1#gno t2#gno) + cnstr ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) (** Interrupt the execution of a Z3 procedure. @@ -5015,14 +5105,14 @@ struct (** Sets the solver parameters. *) - let set_parameters ( x : solver ) ( value : params )= - Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) value#gno + let set_parameters ( x : solver ) ( p : Params.params )= + Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** Retrieves parameter descriptions for solver. *) let get_param_descrs ( x : solver ) = - (new param_descrs (z3obj_gc x))#cnstr_obj (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** The current number of backtracking points (scopes). @@ -5062,7 +5152,7 @@ struct The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) @@ -5070,7 +5160,7 @@ struct The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in let f i = ((new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get a i)#gno) in Array.init n f @@ -5128,7 +5218,7 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = (new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let cn = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f @@ -5176,8 +5266,8 @@ struct The solver supports the commands Push and Pop, but it will always solve each check from scratch. *) - let mk_solver_t ( ctx : context ) ( t : tactic ) = - (cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) t#gno)) + let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = + (cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) (** A string representation of the solver. @@ -5211,14 +5301,14 @@ struct (** Sets the fixedpoint solver parameters. *) - let set_params ( x : fixedpoint ) ( p : params )= - Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) p#gno + let set_params ( x : fixedpoint ) ( p : Params.params )= + Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** Retrieves parameter descriptions for Fixedpoint solver. *) let get_param_descrs ( x : fixedpoint ) = - (new param_descrs (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Assert a constraints into the fixedpoint solver. @@ -5355,7 +5445,7 @@ struct Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = ((new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in Array.init n f @@ -5364,7 +5454,7 @@ struct Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = ((new ast_vector (z3obj_gc x))#cnstr_obj (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in Array.init n f From 8d1413bcc82a52034599f7136f6ddcd342b49b8a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sun, 13 Jan 2013 00:02:38 +0000 Subject: [PATCH 164/248] ML API: Symbols are now normal types with visible hierarchy. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 468 ++++++++++++++++++++++++----------------------- 1 file changed, 241 insertions(+), 227 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 8c0f24c4b..378988d59 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -135,39 +135,145 @@ object (self) method gnc = (context_gno m_ctx) end -(** Symbol objects *) -class symbol ctx = -object (self) - inherit z3object ctx None as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method incref nc o = () - method decref nc o = () -end -(** Int symbol objects *) -class int_symbol ctx = -object(self) - inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_int i = (self#sno ctx (Z3native.mk_int_symbol (context_gno ctx) i)) ; self -end -(** String symbol objects *) -class string_symbol ctx = -object(self) - inherit symbol ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_string name = (self#sno ctx (Z3native.mk_string_symbol (context_gno ctx) name)) ; self -end +type z3_native_object = { + m_ctx : context ; + mutable m_n_obj : Z3native.ptr ; + inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; + dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } -let symbolaton (a : symbol array) = - let f (e : symbol) = e#gno in +let z3obj_gc o = o.m_ctx +let z3obj_gnc o = (context_gno o.m_ctx) + +let z3obj_gno o = o.m_n_obj +let z3obj_sno o ctx no = + (context_add1 ctx) ; + o.inc_ref (context_gno ctx) no ; + ( + if not (is_null o.m_n_obj) then + o.dec_ref (context_gno ctx) o.m_n_obj ; + (context_sub1 ctx) + ) ; + o.m_n_obj <- no + +let z3obj_dispose o = + if not (is_null o.m_n_obj) then + ( + o.dec_ref (z3obj_gnc o) o.m_n_obj ; + (context_sub1 (z3obj_gc o)) + ) ; + o.m_n_obj <- null + +let z3obj_cnstr o = + let f = fun o -> (z3obj_dispose o) in + Gc.finalise f o + +let z3obj_nil_ref x y = () + +let array_to_native a = + let f e = (z3obj_gno e) in Array.map f a +(**/**) -let create_symbol ctx no = - match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> (((new int_symbol ctx)#cnstr_obj no) :> symbol) - | STRING_SYMBOL -> (((new string_symbol ctx)#cnstr_obj no) :> symbol) + +(** Symbols are used to name several term and type constructors *) +module Symbol = +struct + (** Int symbol objects *) + type int_symbol = z3_native_object + + (** String symbol objects *) + and string_symbol = z3_native_object + + and symbol = + | IntSymbol of int_symbol + | StringSymbol of string_symbol + + (**/**) + let cnstr_i ( ctx : context ) ( no : Z3native.ptr ) = + let res : int_symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + let cnstr_s ( ctx : context ) ( no : Z3native.ptr ) = + let res : string_symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in + (z3obj_sno res ctx no) ; + (z3obj_cnstr res) ; + res + + let gnc ( x : symbol ) = + match x with + | IntSymbol(n) -> (z3obj_gnc n) + | StringSymbol(n) -> (z3obj_gnc n) + + let gno ( x : symbol ) = + match x with + | IntSymbol(n) -> (z3obj_gno n) + | StringSymbol(n) -> (z3obj_gno n) + + let create ( ctx : context ) ( no : Z3native.ptr ) = + match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with + | INT_SYMBOL -> IntSymbol (cnstr_i ctx no) + | STRING_SYMBOL -> StringSymbol (cnstr_s ctx no) + + let aton a = + let f e = (gno e) in + Array.map f a + (**/**) + + (** The kind of the symbol (int or string) *) + let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) + + (** Indicates whether the symbol is of Int kind *) + let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL + + (** Indicates whether the symbol is of string kind. *) + let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL + + (** The int value of the symbol. *) + let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) + + (** The string value of the symbol. *) + let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) + + (** A string representation of the symbol. *) + let to_string ( o : symbol ) = + match (kind o) with + | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) + | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) + + (** + 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. + *) + let mk_int ( ctx : context ) ( i : int ) = + IntSymbol (cnstr_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) + + (** Creates a new symbol using a string. *) + let mk_string ( ctx : context ) ( s : string ) = + StringSymbol (cnstr_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) + + (** Create an array of symbols. *) + let mk_ints ( ctx : context ) ( names : int array ) = + let f elem = mk_int ( ctx : context ) elem in + (Array.map f names) + + (** Create an array of symbols. *) + let mk_strings ( ctx : context ) ( names : string array ) = + let f elem = mk_string ( ctx : context ) elem in + (Array.map f names) +end + +(**/**) (** AST objects *) class ast ctx = @@ -242,7 +348,7 @@ class uninterpreted_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_s (s : symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) s#gno)) ; self + method cnstr_s (s : Symbol.symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; self end (** Finite domain sort objects *) @@ -250,7 +356,7 @@ class finite_domain_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_si (s : symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort (context_gno ctx) s#gno sz)) ; self + method cnstr_si (s : Symbol.symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno s) sz)) ; self end (** Relation sort objects *) @@ -273,8 +379,8 @@ class tuple_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_siss (name : symbol) (num_fields: int) (field_names : symbol array) (field_sorts : sort array) = - let (x,_,_) = (Z3native.mk_tuple_sort (context_gno ctx) name#gno num_fields (symbolaton field_names) (astaton field_sorts)) in + method cnstr_siss (name : Symbol.symbol) (num_fields: int) (field_names : Symbol.symbol array) (field_sorts : sort array) = + let (x,_,_) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) num_fields (Symbol.aton field_names) (astaton field_sorts)) in (self#sno ctx x) ; self end @@ -285,7 +391,7 @@ class func_decl ctx = object (self) inherit ast ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ndr (name : symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl (context_gno ctx) name#gno (Array.length domain) (astaton domain) range#gno)) ; self + method cnstr_ndr (name : Symbol.symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (astaton domain) range#gno)) ; self method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (astaton domain) range#gno)) ; self method incref nc o = super#incref nc o @@ -303,8 +409,8 @@ object (self) val mutable _constdecls : func_decl array option = None val mutable _testerdecls : func_decl array option = None method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : symbol) (enum_names : symbol array) = - let (r, a, b) = (Z3native.mk_enumeration_sort (context_gno ctx) name#gno (Array.length enum_names) (symbolaton enum_names)) in + method cnstr_ss (name : Symbol.symbol) (enum_names : Symbol.symbol array) = + let (r, a, b) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Symbol.aton enum_names)) in _constdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f a)) ; _testerdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f b)) ; (self#sno ctx r) ; @@ -330,8 +436,8 @@ object (self) val mutable _headdecl : func_decl option = None val mutable _taildecl : func_decl option = None method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : symbol) (elem_sort : sort) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) name#gno elem_sort#gno) in + method cnstr_ss (name : Symbol.symbol) (elem_sort : sort) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) elem_sort#gno) in _nildecl <- Some ((new func_decl ctx)#cnstr_obj a) ; _is_nildecl <- Some ((new func_decl ctx)#cnstr_obj b) ; _consdecl <- Some ((new func_decl ctx)#cnstr_obj c) ; @@ -381,7 +487,7 @@ object (self) let v = self in Gc.finalise f v - method cnstr_ssssi (name : symbol) (recognizer : symbol) (field_names : symbol array) (sorts : sort array) (sort_refs : int array) = + method cnstr_ssssi (name : Symbol.symbol) (recognizer : Symbol.symbol) (field_names : Symbol.symbol array) (sorts : sort array) (sort_refs : int array) = m_n <- (Array.length field_names) ; if m_n != (Array.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -389,7 +495,7 @@ object (self) if m_n != (Array.length sort_refs) then raise (Z3native.Exception "Number of field names does not match number of sort refs") else - let o = (Z3native.mk_constructor (context_gno ctx) name#gno recognizer#gno m_n (symbolaton field_names) + let o = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) (Symbol.gno recognizer) m_n (Symbol.aton field_names) (sortaton sorts) sort_refs) in self#sno ctx o ; @@ -449,7 +555,7 @@ class datatype_sort ctx = object (self) inherit sort ctx as super method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_sc (name : symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype (context_gno ctx) name#gno (Array.length constructors) (constructoraton constructors)))) ; self + method cnstr_sc (name : Symbol.symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (constructoraton constructors)))) ; self end let create_sort ctx obj = @@ -571,43 +677,6 @@ let patternaton (a : pattern array) = let f (e : pattern) = e#gno in Array.map f a - -type z3_native_object = { - m_ctx : context ; - mutable m_n_obj : Z3native.ptr ; - inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; - dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - -let z3obj_gc o = o.m_ctx -let z3obj_gnc o = (context_gno o.m_ctx) - -let z3obj_gno o = o.m_n_obj -let z3obj_sno o ctx no = - (context_add1 ctx) ; - o.inc_ref (context_gno ctx) no ; - ( - if not (is_null o.m_n_obj) then - o.dec_ref (context_gno ctx) o.m_n_obj ; - (context_sub1 ctx) - ) ; - o.m_n_obj <- no - -let z3obj_dispose o = - if not (is_null o.m_n_obj) then - ( - o.dec_ref (z3obj_gnc o) o.m_n_obj ; - (context_sub1 (z3obj_gc o)) - ) ; - o.m_n_obj <- null - -let z3obj_cnstr o = - let f = fun o -> (z3obj_dispose o) in - Gc.finalise f o - -let array_to_native a = - let f e = (z3obj_gno e) in - Array.map f a - (**/**) @@ -656,58 +725,6 @@ struct string_of_int rev ^ "." end -(** Symbols are used to name several term and type constructors *) -module Symbol = -struct - (** The kind of the symbol (int or string) *) - let kind (o : symbol) = (symbol_kind_of_int (Z3native.get_symbol_kind o#gnc o#gno)) - - (** Indicates whether the symbol is of Int kind *) - let is_int_symbol (o : symbol) = (kind o) == INT_SYMBOL - - (** Indicates whether the symbol is of string kind. *) - let is_string_symbol (o : symbol) = (kind o) == STRING_SYMBOL - - (** The int value of the symbol. *) - let get_int (o : int_symbol) = Z3native.get_symbol_int o#gnc o#gno - - (** The string value of the symbol. *) - let get_string (o : string_symbol) = Z3native.get_symbol_string o#gnc o#gno - - (** A string representation of the symbol. *) - let to_string (o : symbol) = - match (kind o) with - | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int o#gnc o#gno)) - | STRING_SYMBOL -> (Z3native.get_symbol_string o#gnc o#gno) - - (** - 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. - *) - let mk_int ( ctx : context ) i = - (new int_symbol ctx)#cnstr_int i - - (** Creates a new symbol using a string. *) - let mk_string ( ctx : context ) s = - (new string_symbol ctx)#cnstr_string s - - (** - Create an array of symbols. - *) - let mk_ints ( ctx : context ) ( names : int array ) = - let f elem = mk_int ( ctx : context ) elem in - (Array.map f names) - - (** - Create an array of symbols. - *) - let mk_strings ( ctx : context ) ( names : string array ) = - let f elem = mk_string ( ctx : context ) elem in - (Array.map f names) -end - (** The Sort module implements type information for ASTs *) module Sort = @@ -738,7 +755,7 @@ struct (** The name of the sort *) - let get_name (x : sort) = (create_symbol x#gc (Z3native.get_sort_name x#gnc x#gno)) + let get_name (x : sort) = (Symbol.create x#gc (Z3native.get_sort_name x#gnc x#gno)) (** A string representation of the sort. @@ -754,14 +771,14 @@ struct (** Create a new uninterpreted sort. *) - let mk_uninterpreted ( ctx : context ) (s : symbol) = + let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = (new uninterpreted_sort ctx)#cnstr_s s (** Create a new uninterpreted sort. *) - let mk_uninterpreted_s ( ctx : context ) (s : string) = - mk_uninterpreted ctx ((Symbol.mk_string ( ctx : context ) s) :> symbol) + let mk_uninterpreted_s ( ctx : context ) ( s : string ) = + mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) end (**/**) @@ -817,7 +834,7 @@ struct m_kind : parameter_kind ; m_i : int ; m_d : float ; - m_sym : symbol option ; + m_sym : Symbol.symbol option ; m_srt : sort option ; m_ast : ast option ; m_fd : func_decl option ; @@ -961,14 +978,14 @@ struct (** Creates a new function declaration. *) - let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort) = + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort) = (new func_decl ctx)#cnstr_ndr name domain range (** Creates a new function declaration. *) let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = - mk_func_decl ctx ((Symbol.mk_string ctx name) :> symbol) domain range + mk_func_decl ctx (Symbol.mk_string ctx name) domain range (** Creates a fresh function declaration with a name prefixed with . @@ -981,7 +998,7 @@ struct (** Creates a new constant function declaration. *) - let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort) = + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort) = (new func_decl ctx)#cnstr_ndr name [||] range @@ -989,7 +1006,7 @@ struct Creates a new constant function declaration. *) let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr ((Symbol.mk_string ctx name) :> symbol) [||] range + (new func_decl ctx)#cnstr_ndr (Symbol.mk_string ctx name) [||] range (** Creates a fresh constant function declaration with a name prefixed with . @@ -1055,7 +1072,7 @@ struct (** The name of the function declaration *) - let get_name (x : func_decl) = (create_symbol x#gc (Z3native.get_decl_name x#gnc x#gno)) + let get_name (x : func_decl) = (Symbol.create x#gc (Z3native.get_decl_name x#gnc x#gno)) (** The number of parameters of the function declaration @@ -1071,7 +1088,7 @@ struct match (parameter_kind_of_int (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with | PARAMETER_INT -> Parameter.cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) | PARAMETER_DOUBLE -> Parameter.cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) - | PARAMETER_SYMBOL-> Parameter.cnstr_symbol (Some (create_symbol x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) + | PARAMETER_SYMBOL-> Parameter.cnstr_symbol (Some (Symbol.create x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) | PARAMETER_SORT -> Parameter.cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) | PARAMETER_AST -> Parameter.cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) | PARAMETER_FUNC_DECL -> Parameter.cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) @@ -1375,13 +1392,13 @@ struct Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) name#gno)) + let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) (** Retrieve all names of parameters. *) let get_names ( x : param_descrs ) = let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in - let f i = create_symbol (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in + let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** The size of the ParamDescrs. *) @@ -1394,50 +1411,50 @@ struct (** Adds a parameter setting. *) - let add_bool ( x : params ) ( name : symbol ) ( value : bool ) = - Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) name#gno value + let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = + Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_int ( x : params ) (name : symbol ) ( value : int ) = - Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) name#gno value + let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = + Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_double ( x : params ) ( name : symbol ) ( value : float ) = - Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) name#gno value + let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = + Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_symbol ( x : params ) ( name : symbol ) ( value : symbol ) = - Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) name#gno value#gno + let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = + Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) (** Adds a parameter setting. *) - let add_s_bool ( x : params ) ( name : string) ( value : bool ) = - add_bool x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = + add_bool x (Symbol.mk_string (z3obj_gc x) name) value (** Adds a parameter setting. *) let add_s_int ( x : params) ( name : string ) ( value : int ) = - add_int x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + add_int x (Symbol.mk_string (z3obj_gc x) name) value (** Adds a parameter setting. *) let add_s_double ( x : params ) ( name : string ) ( value : float ) = - add_double x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + add_double x (Symbol.mk_string (z3obj_gc x) name) value (** Adds a parameter setting. *) - let add_s_symbol ( x : params ) ( name : string ) ( value : symbol ) = - add_symbol x ((new symbol (z3obj_gc x))#cnstr_obj (Z3native.mk_string_symbol (z3obj_gnc x) name)) value + let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = + add_symbol x (Symbol.mk_string (z3obj_gc x) name) value (** Creates a new parameter set @@ -1662,15 +1679,15 @@ struct (** Creates a new Constant of sort and named . *) - let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = - create_expr ctx (Z3native.mk_const (context_gno ctx) name#gno range#gno) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + create_expr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) range#gno) (** Creates a new Constant of sort and named . *) let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = - mk_const ctx ((Symbol.mk_string ctx name) :> symbol) range + mk_const ctx (Symbol.mk_string ctx name)range (** @@ -1690,14 +1707,14 @@ struct (** Create a Boolean constant. *) - let mk_bool_const ( ctx : context ) ( name : symbol ) = + let mk_bool_const ( ctx : context ) ( name : Symbol.symbol ) = ((mk_const ctx name (Sort.mk_bool ctx)) :> bool_expr) (** Create a Boolean constant. *) let mk_bool_const_s ( ctx : context ) ( name : string ) = - mk_bool_const ctx ((Symbol.mk_string ctx name) :> symbol) + mk_bool_const ctx (Symbol.mk_string ctx name) (** Create a new function application. @@ -1907,7 +1924,7 @@ struct *) let get_bound_variable_names ( x : quantifier ) = let n = (get_num_bound x) in - let f i = (create_symbol x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in + let f i = (Symbol.create x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in Array.init n f (** @@ -1960,7 +1977,7 @@ struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then @@ -1968,23 +1985,23 @@ struct (match weight with | None -> 1 | Some(x) -> x) (Array.length patterns) (patternaton patterns) (Array.length sorts) (astaton sorts) - (astaton names) + (Symbol.aton names) body#gno) else (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> x#gno) - (match skolem_id with | None -> null | Some(x) -> x#gno) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length patterns) (patternaton patterns) (Array.length nopatterns) (patternaton nopatterns) (Array.length sorts) (astaton sorts) - (astaton names) + (Symbol.aton names) body#gno) (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) @@ -1994,8 +2011,8 @@ struct else (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> x#gno) - (match skolem_id with | None -> null | Some(x) -> x#gno) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length bound_constants) (expraton bound_constants) (Array.length patterns) (patternaton patterns) (Array.length nopatterns) (patternaton nopatterns) @@ -2004,7 +2021,7 @@ struct Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then @@ -2012,23 +2029,23 @@ struct (match weight with | None -> 1 | Some(x) -> x) (Array.length patterns) (patternaton patterns) (Array.length sorts) (astaton sorts) - (astaton names) + (Symbol.aton names) body#gno) else (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> x#gno) - (match skolem_id with | None -> null | Some(x) -> x#gno) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length patterns) (patternaton patterns) (Array.length nopatterns) (patternaton nopatterns) (Array.length sorts) (astaton sorts) - (astaton names) + (Symbol.aton names) body#gno) (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) @@ -2038,8 +2055,8 @@ struct else (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> x#gno) - (match skolem_id with | None -> null | Some(x) -> x#gno) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length bound_constants) (expraton bound_constants) (Array.length patterns) (patternaton patterns) (Array.length nopatterns) (patternaton nopatterns) @@ -2048,7 +2065,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -2058,7 +2075,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -2128,14 +2145,14 @@ struct (** Create an array constant. *) - let mk_const ( ctx : context ) ( name : symbol ) ( domain : sort ) ( range : sort ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = ((Expr.mk_const ctx name ((mk_sort ctx domain range) :> sort)) :> array_expr) (** Create an array constant. *) let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = - mk_const ctx ((Symbol.mk_string ctx name) :> symbol) domain range + mk_const ctx (Symbol.mk_string ctx name) domain range (** Array read. @@ -2307,14 +2324,14 @@ struct (** Create a new finite domain sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) size = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) size = (new finite_domain_sort ctx)#cnstr_si name size (** Create a new finite domain sort. *) let mk_sort_s ( ctx : context ) ( name : string ) size = - (new finite_domain_sort ctx)#cnstr_si ((Symbol.mk_string ctx name) :> symbol) size + (new finite_domain_sort ctx)#cnstr_si (Symbol.mk_string ctx name) size (** @@ -2488,7 +2505,7 @@ struct 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. *) - let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array) = (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs @@ -2502,32 +2519,32 @@ struct 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. *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = - mk_constructor ctx ((Symbol.mk_string ctx name) :> symbol) recognizer field_names sorts sort_refs + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : constructor array) = (new datatype_sort ctx)#cnstr_sc name constructors (** Create a new datatype sort. *) let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = - mk_sort ctx ((Symbol.mk_string ctx name) :> symbol) constructors + mk_sort ctx (Symbol.mk_string ctx name) constructors (** Create mutually recursive datatypes. @param names names of datatype sorts @param c list of constructors, one list per sort. *) - let mk_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = + let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : constructor array array ) = let n = (Array.length names) in let f e = ( (new constructor_list ctx)#cnstr_ca e ) in let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (symbolaton names) (constructor_listaton cla)) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.aton names) (constructor_listaton cla)) in let g e = ( (new datatype_sort ctx)#cnstr_obj e) in (Array.map g r) @@ -2535,7 +2552,7 @@ struct let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = mk_sorts ctx ( - let f e = ((Symbol.mk_string ctx e) :> symbol) in + let f e = (Symbol.mk_string ctx e) in Array.map f names ) c @@ -2581,10 +2598,8 @@ struct *) let mk_sort_s ( ctx : context ) name enum_names = (new enum_sort ctx)#cnstr_ss - ((Symbol.mk_string ( ctx : context ) name) :> symbol) - (let f e = (e :> symbol) in - (Array.map f (Symbol.mk_strings ( ctx : context ) enum_names)) - ) + (Symbol.mk_string ctx name) + (Symbol.mk_strings ctx enum_names) (** The function declarations of the constants in the enumeration. *) let get_const_decls (x : enum_sort) = x#const_decls @@ -2599,15 +2614,14 @@ struct (** Create a new list sort. *) - let mk_sort ( ctx : context ) (name : symbol) elem_sort = + let mk_sort ( ctx : context ) (name : Symbol.symbol) elem_sort = (new list_sort ctx)#cnstr_ss name elem_sort (** Create a new list sort. *) let mk_list_s ( ctx : context ) (name : string) elem_sort = - mk_sort ctx ((Symbol.mk_string ctx name) :> symbol) elem_sort - + mk_sort ctx (Symbol.mk_string ctx name) elem_sort (** The declaration of the nil function of this list sort. *) let get_nil_decl (x : list_sort) = x#nil_decl @@ -2805,26 +2819,26 @@ struct (** Creates an integer constant. *) - let mk_int_const ( ctx : context ) ( name : symbol ) = + let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = ((Expr.mk_const ctx name (mk_int_sort ctx)) :> int_expr) (** Creates an integer constant. *) let mk_int_const_s ( ctx : context ) ( name : string ) = - mk_int_const ctx ((Symbol.mk_string ctx name) :> symbol) + mk_int_const ctx (Symbol.mk_string ctx name) (** Creates a real constant. *) - let mk_real_const ( ctx : context ) ( name : symbol ) = + let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = ((Expr.mk_const ctx name (mk_real_sort ctx)) :> real_expr) (** Creates a real constant. *) let mk_real_const_s ( ctx : context ) ( name : string ) = - mk_real_const ctx ((Symbol.mk_string ctx name) :> symbol) + mk_real_const ctx (Symbol.mk_string ctx name) (** Create an expression representing t[0] + t[1] + .... @@ -3300,14 +3314,14 @@ struct (** Creates a bit-vector constant. *) - let mk_const ( ctx : context ) ( name : symbol ) ( size : int ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = ((Expr.mk_const ctx name (mk_sort ctx size)) :> bitvec_expr) (** Creates a bit-vector constant. *) let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = - mk_const ctx ((Symbol.mk_string ctx name) :> symbol) size + mk_const ctx (Symbol.mk_string ctx name) size (** Bitwise negation. @@ -5242,17 +5256,17 @@ struct check-sat command, and check-sat commands that take more than a given number of milliseconds to be solved. *) - let mk_solver ( ctx : context ) ( logic : symbol option) = + let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = match logic with | None -> (cnstr ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) x#gno)) + | Some (x) -> (cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) (** Creates a new (incremental) solver. *) let mk_solver_s ( ctx : context ) ( logic : string ) = - mk_solver ctx (Some ((Symbol.mk_string ctx logic) :> symbol)) + mk_solver ctx (Some (Symbol.mk_string ctx logic)) (** Creates a new (incremental) solver. @@ -5327,10 +5341,10 @@ struct (** Add rule into the fixedpoint solver. *) - let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : Symbol.symbol option ) = match name with | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno y#gno + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno (Symbol.gno y) (** Add table fact to the fixedpoint solver. @@ -5381,8 +5395,8 @@ struct (** Update named rule into in the fixedpoint solver. *) - let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) rule#gno name#gno + let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : Symbol.symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) rule#gno (Symbol.gno name) (** Retrieve satisfying instance or instances of solver, @@ -5432,8 +5446,8 @@ struct (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) f#gno (Array.length kinds) (symbolaton kinds) + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) f#gno (Array.length kinds) (Symbol.aton kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. @@ -5554,7 +5568,7 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5564,17 +5578,17 @@ struct else Z3native.parse_smtlib_string (context_gno ctx) str cs - (symbolaton sort_names) + (Symbol.aton sort_names) (astaton sorts) cd - (symbolaton decl_names) + (Symbol.aton decl_names) (func_declaton decls) (** Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5584,10 +5598,10 @@ struct else Z3native.parse_smtlib_file (context_gno ctx) file_name cs - (symbolaton sort_names) + (Symbol.aton sort_names) (astaton sorts) cd - (symbolaton decl_names) + (Symbol.aton decl_names) (func_declaton decls) (** @@ -5649,7 +5663,7 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5659,17 +5673,17 @@ struct else Z3native.parse_smtlib2_string (context_gno ctx) str cs - (symbolaton sort_names) + (Symbol.aton sort_names) (astaton sorts) cd - (symbolaton decl_names) + (Symbol.aton decl_names) (func_declaton decls) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5679,10 +5693,10 @@ struct else Z3native.parse_smtlib2_string (context_gno ctx) file_name cs - (symbolaton sort_names) + (Symbol.aton sort_names) (astaton sorts) cd - (symbolaton decl_names) + (Symbol.aton decl_names) (func_declaton decls) end From 9ed926498f424871e8dd8ab06f0d3d4d2f166b8c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Jan 2013 11:37:39 +0000 Subject: [PATCH 165/248] ML API: updated example Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 38b5fe642..3b13a2462 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -22,8 +22,8 @@ exception TestFailedException of string *) let model_converter_test ( ctx : context ) = Printf.printf "ModelConverterTest\n"; - let xr = ((mk_const ctx ((Symbol.mk_string ctx "x") :> symbol) (mk_real_sort ctx )) :> arith_expr) in - let yr = ((mk_const ctx ((Symbol.mk_string ctx "y") :> symbol) (mk_real_sort ctx )) :> arith_expr) in + let xr = ((mk_const ctx (Symbol.mk_string ctx "x") (mk_real_sort ctx )) :> arith_expr) in + let yr = ((mk_const ctx (Symbol.mk_string ctx "y") (mk_real_sort ctx )) :> arith_expr) in let g4 = (mk_goal ctx true false false ) in (Goal.assert_ g4 [| (mk_gt ctx xr (mk_real_numeral_nd ctx 10 1)) |]) ; (Goal.assert_ g4 [| (mk_eq ctx yr (mk_add ctx [| xr; (mk_real_numeral_nd ctx 1 1) |] )) |] ) ; @@ -68,9 +68,9 @@ let model_converter_test ( ctx : context ) = let basic_tests ( ctx : context ) = Printf.printf "BasicTests\n" ; let qi = (mk_int ctx 1) in - let fname = ((mk_string ctx "f") :> symbol) in - let x = ((mk_string ctx "x") :> symbol) in - let y = ((mk_string ctx "y") :> symbol) in + let fname = (mk_string ctx "f") in + let x = (mk_string ctx "x") in + let y = (mk_string ctx "y") in let bs = (Sort.mk_bool ctx) in let domain = [| bs; bs |] in let f = (FuncDecl.mk_func_decl ctx fname domain bs) in @@ -142,8 +142,8 @@ let basic_tests ( ctx : context ) = ); ( let g3 = (mk_goal ctx true true false) in - let xc = (mk_const ctx ((Symbol.mk_string ctx "x") :> symbol) (mk_int_sort ctx)) in - let yc = (mk_const ctx ((Symbol.mk_string ctx "y") :> symbol) (mk_int_sort ctx)) in + let xc = (mk_const ctx (Symbol.mk_string ctx "x") (mk_int_sort ctx)) in + let yc = (mk_const ctx (Symbol.mk_string ctx "y") (mk_int_sort ctx)) in (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (mk_int_sort ctx))) |]) ; (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (mk_int_sort ctx))) |]) ; let constr = (mk_eq ctx xc yc) in @@ -211,8 +211,8 @@ let _ = let bs = (Sort.mk_bool ctx) in let ints = (mk_int_sort ctx) in let rs = (mk_real_sort ctx) in - Printf.printf "int symbol: %s\n" (Symbol.to_string (is :> symbol)); - Printf.printf "string symbol: %s\n" (Symbol.to_string (ss :> symbol)); + Printf.printf "int symbol: %s\n" (Symbol.to_string is); + Printf.printf "string symbol: %s\n" (Symbol.to_string ss); Printf.printf "bool sort: %s\n" (Sort.to_string bs); Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); From b895d4c8269343216022d0f9bc7103c4f9ce75b2 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Jan 2013 17:51:16 +0000 Subject: [PATCH 166/248] ML API: added functions for global parameter management. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 378988d59..0dfb173c4 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -5700,6 +5700,53 @@ struct (func_declaton decls) end + +(* Global functions *) + +(** + * Set a global (or module) parameter, which is shared by all Z3 contexts. + * + * When a Z3 module is initialized it will use the value of these parameters + * when Z3_params objects are not provided. + * The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. + * The character '.' is a delimiter (more later). + * The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. + * Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". + * This function can be used to set parameters for a specific Z3 module. + * This can be done by using .. + * For example: + * (set_global_param "pp.decimal" "true") + * will set the parameter "decimal" in the module "pp" to true. +*) +let set_global_param ( id : string ) ( value : string ) = + (Z3native.global_param_set id value) + +(** + * Get a global (or module) parameter. + * + * Returns None if the parameter does not exist. + * The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. + * This function cannot be invoked simultaneously from different threads without synchronization. + * The result string stored in param_value is stored in a shared location. +*) +let get_global_param ( id : string ) = + let (r, v) = (Z3native.global_param_get id) in + if not r then + None + else + Some v + +(** + * Restore the value of all global (and module) parameters. + * + * This command will not affect already created objects (such as tactics and solvers) + * +*) +let global_param_reset_all = + Z3native.global_param_reset_all + + + (* (** From 3a0af6d15fc7591594cb0aeed5a3eb9e1f2b6a40 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 17 Jan 2013 19:47:51 +0000 Subject: [PATCH 167/248] ML API: Added Solver.assert_and_track Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 0dfb173c4..f5c3e3d82 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -5159,8 +5159,42 @@ struct *) let assert_ ( x : solver ) ( constraints : bool_expr array ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in - ignore (Array.map f constraints) ; - () + ignore (Array.map f constraints) + + (** + * Assert multiple constraints (cs) into the solver, and track them (in the + * unsat) core + * using the Boolean constants in ps. + * + * This API is an alternative to with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using + * and the Boolean literals + * provided using with assumptions. + *) + let assert_and_track ( x : solver ) ( cs : bool_expr array ) ( ps : bool_expr array ) = + if ((Array.length cs) != (Array.length ps)) then + raise (Z3native.Exception "Argument size mismatch") + else + let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) e#gno (Array.get ps i)#gno) in + ignore (Array.iteri f cs) + + (** + * Assert a constraint (c) into the solver, and track it (in the unsat) core + * using the Boolean constant p. + * + * This API is an alternative to with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using + * and the Boolean literals + * provided using with assumptions. + *) + let assert_and_track ( x : solver ) ( c : bool_expr ) ( p : bool_expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) c#gno p#gno (** The number of assertions in the solver. From 364954e25a0c1495570bbf9c319d501d751d8555 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 31 Jan 2013 12:51:31 +0000 Subject: [PATCH 168/248] ML build Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index befd78be6..1d3412c30 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1345,31 +1345,30 @@ class MLComponent(Component): src_dir = self.to_src_dir sub_dir = os.path.join('api', 'ml') mk_dir(os.path.join(BUILD_DIR, sub_dir)) + api_src = get_component(API_COMPONENT).to_src_dir for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) - out.write('libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s api/ml/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, get_component(API_COMPONENT).to_src_dir)) - out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') - out.write('api/ml/z3.cmxa: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('api/ml/libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, src_dir)) + out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') + out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(src_dir, mlfile)) out.write('\n') - out.write('\tcd %s && %s ' % (sub_dir, OCAMLOPT)) + out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3" z3native.c z3enums.ml z3native.ml z3.ml -a -o ../../z3.cmxa -linkall && popd\n' % get_component(API_COMPONENT).to_src_dir) - out.write('z3.cma:') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" z3enums.ml z3native.ml z3.ml -a -o z3.cmxa -linkall && cd ../..\n' % get_component(API_COMPONENT).to_src_dir) - out.write('api/ml/z3.cma: libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) + out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') - out.write('\tcd %s && %s ' % (sub_dir, OCAMLC)) + out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" z3enums.ml z3native.ml z3.ml -a -o z3.cma -linkall && cd ../..\n' % get_component(API_COMPONENT).to_src_dir) + out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') out.write('\n') From 313ccfbe8de02d0ed61b9330012f6b43ffb2b327 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 4 Feb 2013 21:18:25 +0000 Subject: [PATCH 169/248] Checkpoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2989 ++++++++++++++++++++++++---------------------- 1 file changed, 1544 insertions(+), 1445 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index f5c3e3d82..0e47912ae 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,6 +7,51 @@ open Z3enums +(** 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. *) +module Log = +struct + (** Open an interaction log file. + @param filename the name of the file to open. + @return True if opening the log file succeeds, false otherwise. + *) + (* CMW: "open" seems to be a reserved keyword? *) + let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) + + (** Closes the interaction log. *) + let close = Z3native.close_log + + (** Appends a user-provided string to the interaction log. + @param s the string to append*) + let append s = Z3native.append_log s +end + +(** Version information *) +module Version = +struct + (** The major version. *) + let major = let (x, _, _, _) = Z3native.get_version in x + + (** The minor version. *) + let minor = let (_, x, _, _) = Z3native.get_version in x + + (** The build version. *) + let build = let (_, _, x, _) = Z3native.get_version in x + + (** The revision. *) + let revision = let (_, _, _, x) = Z3native.get_version in x + + (** A string representation of the version information. *) + let to_string = + let (mj, mn, bld, rev) = Z3native.get_version in + string_of_int mj ^ "." ^ + string_of_int mn ^ "." ^ + string_of_int bld ^ "." ^ + string_of_int rev ^ "." +end + (**/**) (* Some helpers. *) @@ -40,7 +85,7 @@ let context_dispose ctx = (* re-queue for finalization? *) ) -let context_cnstr settings = +let context_create settings = let cfg = Z3native.mk_config in let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; @@ -85,7 +130,7 @@ let context_gno ctx = ctx.m_n_ctx *) let mk_context ( cfg : ( string * string ) list ) = - context_cnstr cfg + context_create cfg (**/**) @@ -165,7 +210,7 @@ let z3obj_dispose o = ) ; o.m_n_obj <- null -let z3obj_cnstr o = +let z3obj_create o = let f = fun o -> (z3obj_dispose o) in Gc.finalise f o @@ -184,44 +229,51 @@ struct type int_symbol = z3_native_object (** String symbol objects *) - and string_symbol = z3_native_object + type string_symbol = z3_native_object - and symbol = - | IntSymbol of int_symbol - | StringSymbol of string_symbol + (** Symbol Objects *) + type symbol = + | S_Int of int_symbol + | S_Str of string_symbol (**/**) - let cnstr_i ( ctx : context ) ( no : Z3native.ptr ) = + let create_i ( ctx : context ) ( no : Z3native.ptr ) = let res : int_symbol = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res - let cnstr_s ( ctx : context ) ( no : Z3native.ptr ) = + + let create_s ( ctx : context ) ( no : Z3native.ptr ) = let res : string_symbol = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res + + let gc ( x : symbol ) = + match x with + | S_Int(n) -> (z3obj_gc n) + | S_Str(n) -> (z3obj_gc n) let gnc ( x : symbol ) = match x with - | IntSymbol(n) -> (z3obj_gnc n) - | StringSymbol(n) -> (z3obj_gnc n) + | S_Int(n) -> (z3obj_gnc n) + | S_Str(n) -> (z3obj_gnc n) let gno ( x : symbol ) = match x with - | IntSymbol(n) -> (z3obj_gno n) - | StringSymbol(n) -> (z3obj_gno n) + | S_Int(n) -> (z3obj_gno n) + | S_Str(n) -> (z3obj_gno n) let create ( ctx : context ) ( no : Z3native.ptr ) = match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> IntSymbol (cnstr_i ctx no) - | STRING_SYMBOL -> StringSymbol (cnstr_s ctx no) + | INT_SYMBOL -> S_Int (create_i ctx no) + | STRING_SYMBOL -> S_Str (create_s ctx no) let aton a = let f e = (gno e) in @@ -256,11 +308,11 @@ struct The legal range of unsigned integers is 0 to 2^30-1. *) let mk_int ( ctx : context ) ( i : int ) = - IntSymbol (cnstr_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) + S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) (** Creates a new symbol using a string. *) let mk_string ( ctx : context ) ( s : string ) = - StringSymbol (cnstr_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) + S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) (** Create an array of symbols. *) let mk_ints ( ctx : context ) ( names : int array ) = @@ -273,853 +325,47 @@ struct (Array.map f names) end -(**/**) - -(** AST objects *) -class ast ctx = -object (self) - inherit z3object ctx None as super (* CMW: derive from icomparable? *) - method cnstr_obj obj = (self#sno ctx obj) ; self - - method incref nc o = Z3native.inc_ref nc o - method decref nc o = Z3native.dec_ref nc o -end - -let astaton (a : ast array) = - let f (e : ast) = e#gno in - Array.map f a - -(** Sort objects *) -class sort ctx = -object (self) - inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -let sortaton (a : sort array) = - let f (e : sort) = e#gno in - Array.map f a - -(** Arithmetic sort objects, i.e., Int or Real. *) -class arith_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Array sorts objects *) -class array_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_dr (domain : sort) (range : sort) = (self#sno ctx (Z3native.mk_array_sort (context_gno ctx) domain#gno range#gno)) ; self -end - -(** Bit-vector sort objects *) -class bitvec_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Boolean sort objects *) -class bool_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Int sort objects *) -class int_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Real sort objects *) -class real_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Uninterpreted sort objects *) -class uninterpreted_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_s (s : Symbol.symbol) = (self #sno ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; self -end - -(** Finite domain sort objects *) -class finite_domain_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_si (s : Symbol.symbol) ( sz : int )= (self #sno ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno s) sz)) ; self -end - -(** Relation sort objects *) -class relation_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Set sort objects *) -class set_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_s (s : sort) = (self#sno ctx s#gno) ; self -end - -(** Tuple sort objects *) -class tuple_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_siss (name : Symbol.symbol) (num_fields: int) (field_names : Symbol.symbol array) (field_sorts : sort array) = - let (x,_,_) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) num_fields (Symbol.aton field_names) (astaton field_sorts)) in - (self#sno ctx x) ; - self -end - - -(** Function declaration objects *) -class func_decl ctx = -object (self) - inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ndr (name : Symbol.symbol) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (astaton domain) range#gno)) ; self - method cnstr_pdr (prefix : string) (domain : sort array) (range : sort) = (self#sno ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (astaton domain) range#gno)) ; self - - method incref nc o = super#incref nc o - method decref nc o = super#decref nc o -end - -let func_declaton (a : func_decl array) = - let f (e : func_decl) = e#gno in - Array.map f a - -(** Enum sort objects *) -class enum_sort ctx = -object (self) - inherit sort ctx as super - val mutable _constdecls : func_decl array option = None - val mutable _testerdecls : func_decl array option = None - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : Symbol.symbol) (enum_names : Symbol.symbol array) = - let (r, a, b) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Symbol.aton enum_names)) in - _constdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f a)) ; - _testerdecls <- Some (let f e = (new func_decl ctx)#cnstr_obj e in (Array.map f b)) ; - (self#sno ctx r) ; - self - - method const_decls = match _constdecls with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing const decls") - - method tester_decls = match _testerdecls with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tester decls") -end - -(** List sort objects *) -class list_sort ctx = -object (self) - inherit sort ctx as super - val mutable _nildecl : func_decl option = None - val mutable _is_nildecl : func_decl option = None - val mutable _consdecl : func_decl option = None - val mutable _is_consdecl : func_decl option = None - val mutable _headdecl : func_decl option = None - val mutable _taildecl : func_decl option = None - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ss (name : Symbol.symbol) (elem_sort : sort) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) elem_sort#gno) in - _nildecl <- Some ((new func_decl ctx)#cnstr_obj a) ; - _is_nildecl <- Some ((new func_decl ctx)#cnstr_obj b) ; - _consdecl <- Some ((new func_decl ctx)#cnstr_obj c) ; - _is_consdecl <- Some ((new func_decl ctx)#cnstr_obj d) ; - _headdecl <- Some ((new func_decl ctx)#cnstr_obj e) ; - _taildecl <- Some ((new func_decl ctx)#cnstr_obj f) ; - (self#sno ctx r) ; - self - - method nil_decl = match _nildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing nil decl") - - method is_nil_decl = match _is_nildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_nil decl") - - method cons_decl = match _consdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing cons decl") - - method is_cons_decl = match _is_consdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing is_cons decl") - - method head_decl = match _headdecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing head decl") - - method tail_decl = match _taildecl with - | Some(x) -> x - | None -> raise (Z3native.Exception "Missing tail decl") -end - -(** Constructor objects *) -class constructor ctx = -object (self) - inherit z3object ctx None as super - val mutable m_n : int = 0 - val mutable m_tester_decl : func_decl option = None - val mutable m_constructor_decl : func_decl option = None - val mutable m_accessor_decls : func_decl array option = None - method incref nc o = () - method decref nc o = () - initializer - let f = fun o -> Z3native.del_constructor o#gnc o#gno in - let v = self in - Gc.finalise f v - - method cnstr_ssssi (name : Symbol.symbol) (recognizer : Symbol.symbol) (field_names : Symbol.symbol array) (sorts : sort array) (sort_refs : int array) = - m_n <- (Array.length field_names) ; - if m_n != (Array.length sorts) then - raise (Z3native.Exception "Number of field names does not match number of sorts") - else - if m_n != (Array.length sort_refs) then - raise (Z3native.Exception "Number of field names does not match number of sort refs") - else - let o = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) (Symbol.gno recognizer) m_n (Symbol.aton field_names) - (sortaton sorts) - sort_refs) in - self#sno ctx o ; - self - - method private init = - match m_tester_decl with - | None -> - let (a, b, c) = (Z3native.query_constructor self#gnc self#gno m_n) in - m_constructor_decl <- Some ((new func_decl ctx)#cnstr_obj a) ; - m_tester_decl <- Some ((new func_decl ctx)#cnstr_obj b) ; - m_accessor_decls <- Some (let f e = ((new func_decl ctx)#cnstr_obj e) in Array.map f c) ; - () - | _ -> () - - method get_n = m_n - - method tester_decl = match m_tester_decl with - | Some(x) -> x - | None -> self#init ; self#tester_decl - - method constructor_decl = match m_constructor_decl with - | Some(x) -> x - | None -> self#init ; self#constructor_decl - - method accessor_decls = match m_accessor_decls with - | Some(x) -> x - | None -> self#init ; self#accessor_decls -end - -let constructoraton (a : constructor array) = - let f (e : constructor) = e#gno in - Array.map f a - -(** Constructor list objects *) -class constructor_list ctx = -object (self) - inherit z3object ctx None - method incref nc o = () - method decref nc o = () - initializer - let f = fun o -> Z3native.del_constructor_list o#gnc o#gno in - let v = self in - Gc.finalise f v - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_ca ( c : constructor array ) = - self#sno ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (constructoraton c)) ; - self -end - -let constructor_listaton (a : constructor_list array) = - let f (e : constructor_list) = e#gno in - Array.map f a - -(** Datatype sort objects *) -class datatype_sort ctx = -object (self) - inherit sort ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self - method cnstr_sc (name : Symbol.symbol) (constructors : constructor array) = (self#sno ctx (fst (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (constructoraton constructors)))) ; self -end - -let create_sort ctx obj = - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) obj)) with - | ARRAY_SORT -> (((new array_sort ctx)#cnstr_obj obj) :> sort) - | BOOL_SORT -> (((new bool_sort ctx)#cnstr_obj obj) :> sort) - | BV_SORT -> (((new bitvec_sort ctx)#cnstr_obj obj) :> sort) - | DATATYPE_SORT -> (((new datatype_sort ctx)#cnstr_obj obj) :> sort) - | INT_SORT -> (((new int_sort ctx)#cnstr_obj obj) :> sort) - | REAL_SORT -> (((new real_sort ctx)#cnstr_obj obj) :> sort) - | UNINTERPRETED_SORT -> (((new uninterpreted_sort ctx)#cnstr_obj obj) :> sort) - | FINITE_DOMAIN_SORT -> (((new finite_domain_sort ctx)#cnstr_obj obj) :> sort) - | RELATION_SORT -> (((new relation_sort ctx)#cnstr_obj obj) :> sort) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - -(** Expression objects *) -class expr ctx = -object(self) - inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -let expraton (a : expr array) = - let f (e : expr) = e#gno in - Array.map f a - -(** Boolean expression objects *) -class bool_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Arithmetic expression objects (int/real) *) -class arith_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Int expression objects *) -class int_expr ctx = -object (self) - inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Real expression objects *) -class real_expr ctx = -object (self) - inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Bit-vector expression objects *) -class bitvec_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Array expression objects *) -class array_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Datatype expression objects *) -class datatype_expr ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Integer numeral expression objects *) -class int_num ctx = -object (self) - inherit int_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Rational numeral expression objects *) -class rat_num ctx = -object (self) - inherit real_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Bit-vector numeral expression objects *) -class bitvec_num ctx = -object (self) - inherit bitvec_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Algebraic numeral expression objects *) -class algebraic_num ctx = -object (self) - inherit arith_expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Quantifier objects *) -class quantifier ctx = -object (self) - inherit expr ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -(** Quantifier pattern objects *) -class pattern ctx = -object (self) - inherit ast ctx as super - method cnstr_obj obj = (self#sno ctx obj) ; self -end - -let patternaton (a : pattern array) = - let f (e : pattern) = e#gno in - Array.map f a - -(**/**) - - -(** 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. *) -module Log = -struct - (** Open an interaction log file. - @param filename the name of the file to open. - @return True if opening the log file succeeds, false otherwise. - *) - (* CMW: "open" seems to be a reserved keyword? *) - let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) - - (** Closes the interaction log. *) - let close = Z3native.close_log - - (** Appends a user-provided string to the interaction log. - @param s the string to append*) - let append s = Z3native.append_log s -end - -(** Version information *) -module Version = -struct - (** The major version. *) - let major = let (x, _, _, _) = Z3native.get_version in x - - (** The minor version. *) - let minor = let (_, x, _, _) = Z3native.get_version in x - - (** The build version. *) - let build = let (_, _, x, _) = Z3native.get_version in x - - (** The revision. *) - let revision = let (_, _, _, x) = Z3native.get_version in x - - (** A string representation of the version information. *) - let to_string = - let (mj, mn, bld, rev) = Z3native.get_version in - string_of_int mj ^ "." ^ - string_of_int mn ^ "." ^ - string_of_int bld ^ "." ^ - string_of_int rev ^ "." -end - - -(** The Sort module implements type information for ASTs *) -module Sort = -struct - (** - Comparison operator. - @param a A sort - @param b A sort - @return True if and are from the same context - and represent the same sort; false otherwise. - *) - let ( = ) (a : sort) (b : sort) = (a == b) || - if a#gnc != b#gnc then - false - else - (Z3native.is_eq_sort a#gnc a#gno b#gno) - - (** - Returns a unique identifier for the sort. - *) - let get_id (x : sort) = Z3native.get_sort_id x#gnc x#gno - - (** - The kind of the sort. - *) - let get_sort_kind (x : sort) = (sort_kind_of_int (Z3native.get_sort_kind x#gnc x#gno)) - - (** - The name of the sort - *) - let get_name (x : sort) = (Symbol.create x#gc (Z3native.get_sort_name x#gnc x#gno)) - - (** - A string representation of the sort. - *) - let to_string (x : sort) = Z3native.sort_to_string x#gnc x#gno - - (** - Create a new Boolean sort. - *) - let mk_bool ( ctx : context ) = - (new bool_sort ctx)#cnstr_obj (Z3native.mk_bool_sort (context_gno ctx)) - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = - (new uninterpreted_sort ctx)#cnstr_s s - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted_s ( ctx : context ) ( s : string ) = - mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) -end - -(**/**) -let create_expr ctx obj = - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then - (((new quantifier ctx)#cnstr_obj obj) :> expr) - else - let s = Z3native.get_sort (context_gno ctx) obj in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) obj) then - (((new algebraic_num ctx)#cnstr_obj obj) :> expr) - else - if (Z3native.is_numeral_ast (context_gno ctx) obj) && - (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then - match sk with - | INT_SORT -> (((new int_num ctx)#cnstr_obj obj) :> expr) - | REAL_SORT -> (((new rat_num ctx)#cnstr_obj obj) :> expr) - | BV_SORT -> (((new bitvec_num ctx)#cnstr_obj obj) :> expr) - | _ -> raise (Z3native.Exception "Unsupported numeral object") - else - match sk with - | BOOL_SORT -> (((new bool_expr ctx)#cnstr_obj obj) :> expr) - | INT_SORT -> (((new int_expr ctx)#cnstr_obj obj) :> expr) - | REAL_SORT -> (((new real_expr ctx)#cnstr_obj obj) :> expr) - | BV_SORT -> (((new bitvec_expr ctx)#cnstr_obj obj) :> expr) - | ARRAY_SORT -> (((new array_expr ctx)#cnstr_obj obj) :> expr) - | DATATYPE_SORT -> (((new datatype_expr ctx)#cnstr_obj obj) :> expr) - | _ -> (new expr ctx)#cnstr_obj obj - -let create_expr_fa (ctx : context) (f : func_decl) (args : expr array) = - let o = Z3native.mk_app (context_gno ctx) f#gno (Array.length args) (astaton args) in - create_expr ctx o - -let create_ast ctx no = - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST -> (((new func_decl ctx)#cnstr_obj no) :> ast) - | QUANTIFIER_AST -> (((new quantifier ctx)#cnstr_obj no) :> ast) - | SORT_AST -> ((create_sort ctx no) :> ast) - | APP_AST - | NUMERAL_AST - | VAR_AST -> ((create_expr ctx no) :> ast) - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") -(**/**) - -(** Function declarations *) -module FuncDecl = -struct - - (** Parameters of Func_Decls *) - module Parameter = - struct - type parameter = { - m_kind : parameter_kind ; - m_i : int ; - m_d : float ; - m_sym : Symbol.symbol option ; - m_srt : sort option ; - m_ast : ast option ; - m_fd : func_decl option ; - m_r : string ; - } - - (**/**) - let cnstr_int i = { - m_kind = PARAMETER_INT ; - m_i = i ; - m_d = 0.0 ; - m_sym = None ; - m_srt = None ; - m_ast = None ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_double d = { - m_kind = PARAMETER_DOUBLE ; - m_i = 0 ; - m_d = d ; - m_sym = None ; - m_srt = None ; - m_ast = None ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_symbol sym = { - m_kind = PARAMETER_SYMBOL ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = sym ; - m_srt = None ; - m_ast = None ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_sort srt = { - m_kind = PARAMETER_SORT ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = None ; - m_srt = srt ; - m_ast = None ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_ast ast = { - m_kind = PARAMETER_AST ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = None ; - m_srt = None ; - m_ast = ast ; - m_fd = None ; - m_r = "" ; - } - - let cnstr_func_decl fd ={ - m_kind = PARAMETER_FUNC_DECL ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = None ; - m_srt = None ; - m_ast = None ; - m_fd = fd ; - m_r = "" ; - } - - let cnstr_rational r = { - m_kind = PARAMETER_RATIONAL ; - m_i = 0 ; - m_d = 0.0 ; - m_sym = None ; - m_srt = None ; - m_ast = None ; - m_fd = None ; - m_r = r ; - } - (**/**) - - (** - The kind of the parameter. - *) - let get_kind ( x : parameter ) = x.m_kind - - (**The int value of the parameter.*) - let get_int ( x : parameter ) = - if ((get_kind x) != PARAMETER_INT) then - raise (Z3native.Exception "parameter is not an int") - else - x.m_i - - (**The double value of the parameter.*) - let get_double ( x : parameter ) = - if ((get_kind x) != PARAMETER_DOUBLE) then - raise (Z3native.Exception "parameter is not a double") - else - x.m_d - - (**The Symbol value of the parameter.*) - let get_symbol ( x : parameter ) = - if ((get_kind x) != PARAMETER_SYMBOL) then - raise (Z3native.Exception "parameter is not a symbol") - else - x.m_sym - - (**The Sort value of the parameter.*) - let get_sort ( x : parameter ) = - if ((get_kind x) != PARAMETER_SORT) then - raise (Z3native.Exception "parameter is not a sort") - else - x.m_srt - - (**The AST value of the parameter.*) - let get_ast ( x : parameter ) = - if ((get_kind x) != PARAMETER_AST) then - raise (Z3native.Exception "parameter is not an ast") - else - x.m_ast - - (**The FunctionDeclaration value of the parameter.*) - let get_ast ( x : parameter ) = - if ((get_kind x) != PARAMETER_FUNC_DECL) then - raise (Z3native.Exception "parameter is not an function declaration") - else - x.m_fd - - (**The rational string value of the parameter.*) - let get_rational ( x : parameter ) = - if ((get_kind x) != PARAMETER_RATIONAL) then - raise (Z3native.Exception "parameter is not a ratinoal string") - else - x.m_r - end - - (** - Creates a new function declaration. - *) - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr name domain range - - (** - Creates a new function declaration. - *) - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort) = - mk_func_decl ctx (Symbol.mk_string ctx name) domain range - - (** - Creates a fresh function declaration with a name prefixed with . - - - *) - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort) = - (new func_decl ctx)#cnstr_pdr prefix domain range - - (** - Creates a new constant function declaration. - *) - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr name [||] range - - - (** - Creates a new constant function declaration. - *) - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort) = - (new func_decl ctx)#cnstr_ndr (Symbol.mk_string ctx name) [||] range - - (** - Creates a fresh constant function declaration with a name prefixed with . - - - *) - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort) = - (new func_decl ctx)#cnstr_pdr prefix [||] range - - - (** - Comparison operator. - @param a A func_decl - @param b A func_decl - @return True if and are from the same context - and represent the same func_decl; false otherwise. - *) - let ( = ) (a : func_decl) (b : func_decl) = (a == b) || - if a#gnc == a#gnc then - false - else - (Z3native.is_eq_func_decl a#gnc a#gno b#gno) - (** - A string representations of the function declaration. - *) - let to_string (x : func_decl) = Z3native.func_decl_to_string x#gnc x#gno - - (** - Returns a unique identifier for the function declaration. - *) - let get_id (x : func_decl) = Z3native.get_func_decl_id x#gnc x#gno - - (** - The arity of the function declaration - *) - let get_arity (x : func_decl) = Z3native.get_arity x#gnc x#gno - - (** - The size of the domain of the function declaration - - *) - let get_domain_size (x : func_decl) = Z3native.get_domain_size x#gnc x#gno - - (** - The domain of the function declaration - *) - let get_domain (x : func_decl) = - let n = (get_domain_size x) in - let f i = create_sort x#gc (Z3native.get_domain x#gnc x#gno i) in - Array.init n f - - (** - The range of the function declaration - *) - let get_range (x : func_decl) = - create_sort x#gc (Z3native.get_range x#gnc x#gno) - - (** - The kind of the function declaration. - *) - let get_decl_kind (x : func_decl) = (decl_kind_of_int (Z3native.get_decl_kind x#gnc x#gno)) - - (** - The name of the function declaration - *) - let get_name (x : func_decl) = (Symbol.create x#gc (Z3native.get_decl_name x#gnc x#gno)) - - (** - The number of parameters of the function declaration - *) - let get_num_parameters (x : func_decl) = (Z3native.get_decl_num_parameters x#gnc x#gno) - - (** - The parameters of the function declaration - *) - let get_parameters (x : func_decl) = - let n = (get_num_parameters x) in - let f i = ( - match (parameter_kind_of_int (Z3native.get_decl_parameter_kind x#gnc x#gno i)) with - | PARAMETER_INT -> Parameter.cnstr_int (Z3native.get_decl_int_parameter x#gnc x#gno i) - | PARAMETER_DOUBLE -> Parameter.cnstr_double (Z3native.get_decl_double_parameter x#gnc x#gno i) - | PARAMETER_SYMBOL-> Parameter.cnstr_symbol (Some (Symbol.create x#gc (Z3native.get_decl_symbol_parameter x#gnc x#gno i))) - | PARAMETER_SORT -> Parameter.cnstr_sort (Some (create_sort x#gc (Z3native.get_decl_sort_parameter x#gnc x#gno i))) - | PARAMETER_AST -> Parameter.cnstr_ast (Some (create_ast x#gc (Z3native.get_decl_ast_parameter x#gnc x#gno i))) - | PARAMETER_FUNC_DECL -> Parameter.cnstr_func_decl (Some ((new func_decl x#gc)#cnstr_obj (Z3native.get_decl_func_decl_parameter x#gnc x#gno i))) - | PARAMETER_RATIONAL -> Parameter.cnstr_rational (Z3native.get_decl_rational_parameter x#gnc x#gno i) - ) in - mk_list f n - - (** - Create expression that applies function to arguments. - @param args The arguments - *) - let apply (x : func_decl) (args : expr array) = create_expr_fa x#gc x args - -end (** The abstract syntax tree (AST) module *) -module AST = -struct +module rec AST : +sig + type ast = z3_native_object + + val create : context -> Z3native.ptr -> ast + val aton : ast array -> Z3native.ptr array + + val is_expr : ast -> bool + val is_var : ast -> bool +end = struct + type ast = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let aton (a : ast array) = + let f (e : ast) = (z3obj_gno e) in + Array.map f a + + (** Vectors of ASTs *) module ASTVector = struct type ast_vector = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_vector_inc_ref ; dec_ref = Z3native.ast_vector_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -1133,11 +379,11 @@ struct @return An AST *) let get ( x : ast_vector ) ( i : int ) = - create_ast (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) + create (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) (** Sets the i-th object in the vector. *) let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i value#gno + Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) (** Resize the vector to . @param newSize The new size of the vector. *) @@ -1150,7 +396,7 @@ struct @param a An AST *) let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) a#gno + Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) (** Translates all ASTs in the vector to . @@ -1158,7 +404,7 @@ struct @return A new ASTVector *) let translate ( x : ast_vector ) ( to_ctx : context ) = - cnstr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Retrieves a string representation of the vector. *) let to_string ( x : ast_vector ) = @@ -1171,13 +417,13 @@ struct type ast_map = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_map = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_map_inc_ref ; dec_ref = Z3native.ast_map_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -1185,7 +431,7 @@ struct @param k An AST @return True if is a key in the map, false otherwise. *) let contains ( x : ast_map ) ( key : ast ) = - (Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) key#gno) + Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (** Finds the value associated with the key . @@ -1193,7 +439,7 @@ struct @param k An AST *) let find ( x : ast_map ) ( key : ast ) = - create_ast (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) key#gno) + create (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) (** Stores or replaces a new key/value pair in the map. @@ -1201,14 +447,14 @@ struct @param v The value AST *) let insert ( x : ast_map ) ( key : ast ) ( value : ast) = - Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) key#gno value#gno + Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) (** Erases the key from the map. @param k An AST *) let erase ( x : ast_map ) ( key : ast ) = - Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) key#gno + Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (** Removes all keys from the map. *) let reset ( x : ast_map ) = @@ -1220,7 +466,7 @@ struct (** The keys stored in the map. *) let get_keys ( x : ast_map ) = - ASTVector.cnstr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) (** Retrieves a string representation of the map.*) let to_string ( x : ast_map ) = @@ -1231,23 +477,23 @@ struct The AST's hash code. @return A hash code *) - let get_hash_code ( x : ast) = Z3native.get_ast_hash x#gnc x#gno + let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) (** A unique identifier for the AST (unique among all ASTs). *) - let get_id ( x : ast) = Z3native.get_ast_id x#gnc x#gno + let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) (** The kind of the AST. *) - let get_ast_kind ( x : ast) = (ast_kind_of_int (Z3native.get_ast_kind x#gnc x#gno)) + let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) (** Indicates whether the AST is an Expr *) - let is_expr ( x : ast) = - match get_ast_kind ( x : ast) with + let is_expr ( x : ast ) = + match get_ast_kind ( x : ast ) with | APP_AST | NUMERAL_AST | QUANTIFIER_AST @@ -1257,33 +503,33 @@ struct (** Indicates whether the AST is a bound variable *) - let is_var ( x : ast) = (get_ast_kind x) == VAR_AST + let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST (** Indicates whether the AST is a Quantifier *) - let is_quantifier ( x : ast) = (get_ast_kind x) == QUANTIFIER_AST + let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST (** Indicates whether the AST is a Sort *) - let is_sort ( x : ast) = (get_ast_kind x) == SORT_AST + let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST (** Indicates whether the AST is a FunctionDeclaration *) - let is_func_decl ( x : ast) = (get_ast_kind x) == FUNC_DECL_AST + let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST (** A string representation of the AST. *) - let to_string ( x : ast) = Z3native.ast_to_string x#gnc x#gno + let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) (** A string representation of the AST in s-expression notation. *) - let to_sexpr ( x : ast) = Z3native.ast_to_string x#gnc x#gno + let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) (** Comparison operator. @@ -1292,11 +538,11 @@ struct @return True if and are from the same context and represent the same sort; false otherwise. *) - let ( = ) (a : expr) (b : expr) = (a == b) || - if a#gnc == b#gnc then + let ( = ) ( a : ast ) ( b : ast ) = (a == b) || + if (z3obj_gnc a) != (z3obj_gnc b) then false else - (Z3native.is_eq_ast a#gnc a#gno b#gno) + Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) (** Object Comparison. @@ -1316,11 +562,11 @@ struct @param ctx A context @return A copy of the AST which is associated with *) - let translate ( x : ast) to_ctx = - if x#gc == to_ctx then + let translate ( x : ast ) ( to_ctx : context ) = + if (z3obj_gnc x) == (context_gno to_ctx) then x else - (create_ast to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx))) + create to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Wraps an AST. @@ -1334,7 +580,7 @@ struct @param nativeObject The native pointer to wrap. *) let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = - create_ast ctx ptr + create ctx ptr (** Unwraps an AST. @@ -1347,43 +593,413 @@ struct @param a The AST to unwrap. *) - let unwrap_ast ( a : ast ) = a#gno + let unwrap_ast ( x : ast ) = (z3obj_gno x) + + (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with + | FUNC_DECL_AST -> (match (FuncDecl.create ctx no) with FuncDecl.FuncDecl(x) -> x) + | SORT_AST -> (match (Sort.create ctx no) with Sort.Sort(x) -> x) + | QUANTIFIER_AST -> (match (Quantifiers.create ctx no) with Quantifiers.Quantifier(Expr.Expr(x)) -> x) + | APP_AST + | NUMERAL_AST + | VAR_AST -> (match (Expr.create ctx no) with Expr.Expr(x) -> x) + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") +(**/**) end +(** The Sort module implements type information for ASTs *) +and Sort : +sig + type sort = Sort of AST.ast + type bitvec_sort = BitvecSort of sort + type uninterpreted_sort = UninterpretedSort of sort + + val create : context -> Z3native.ptr -> sort + val gno : sort -> Z3native.ptr + val gnc : sort -> Z3native.ptr + val aton : sort array -> Z3native.ptr array +end = struct + type sort = Sort of AST.ast + type bitvec_sort = BitvecSort of sort + type uninterpreted_sort = UninterpretedSort of sort + + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) + let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) + let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) + + let aton : sort array -> Z3native.ptr array = fun a -> + let f e = (gno e) in + Array.map f a + + let create : context -> Z3native.ptr -> sort = fun ctx no -> + let q : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno q ctx no) ; + (z3obj_create q) ; + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with + | ARRAY_SORT + | BOOL_SORT + | BV_SORT + | DATATYPE_SORT + | INT_SORT + | REAL_SORT + | UNINTERPRETED_SORT + | FINITE_DOMAIN_SORT + | RELATION_SORT -> Sort(q) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + + + (** + Comparison operator. + @param a A sort + @param b A sort + @return True if and are from the same context + and represent the same sort; false otherwise. + *) + let ( = ) : sort -> sort -> bool = fun a b -> + (a == b) || + if (gnc a) != (gnc b) then + false + else + (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) + + (** + Returns a unique identifier for the sort. + *) + let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) + + (** + The kind of the sort. + *) + let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) + + (** + The name of the sort + *) + let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) + + (** + A string representation of the sort. + *) + let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; + (z3obj_create res) ; + UninterpretedSort(Sort(res)) + + (** + Create a new uninterpreted sort. + *) + let mk_uninterpreted_s ( ctx : context ) ( s : string ) = + mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) +end + + +(** Function declarations *) +and FuncDecl : +sig + type func_decl = FuncDecl of AST.ast + + val create : context -> Z3native.ptr -> func_decl + val gno : func_decl -> Z3native.ptr + val gnc : func_decl -> Z3native.ptr + + val get_domain_size : func_decl -> int + val get_decl_kind : func_decl -> Z3enums.decl_kind +end = struct + open Sort + + type func_decl = FuncDecl of AST.ast + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + FuncDecl(res) + + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Sort.aton domain) (Sort.gno range))) ; + (z3obj_create res) ; + FuncDecl(res) + + let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Sort.aton domain) (Sort.gno range))) ; + (z3obj_create res) ; + FuncDecl(res) + + let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) + let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) + let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) + + let aton (a : func_decl array) = + let f (e : func_decl) = (gno e) in + Array.map f a + + (** Parameters of Func_Decls *) + module Parameter = + struct + type parameter = + | P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + (** The kind of the parameter. *) + let get_kind ( x : parameter ) = + (match x with + | P_Int(_) -> PARAMETER_INT + | P_Dbl(_) -> PARAMETER_DOUBLE + | P_Sym(_) -> PARAMETER_SYMBOL + | P_Srt(_) -> PARAMETER_SORT + | P_Ast(_) -> PARAMETER_AST + | P_Fdl(_) -> PARAMETER_FUNC_DECL + | P_Rat(_) -> PARAMETER_RATIONAL) + + (**The int value of the parameter.*) + let get_int ( x : parameter ) = + match x with + | P_Int(x) -> x + | _ -> raise (Z3native.Exception "parameter is not an int") + + (**The double value of the parameter.*) + let get_float ( x : parameter ) = + match x with + | P_Dbl(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a double") + + (**The Symbol value of the parameter.*) + let get_symbol ( x : parameter ) = + match x with + | P_Sym(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a symbol") + + (**The Sort value of the parameter.*) + let get_sort ( x : parameter ) = + match x with + | P_Srt(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a sort") + + (**The AST value of the parameter.*) + let get_ast ( x : parameter ) = + match x with + | P_Ast(x) -> x + | _ -> raise (Z3native.Exception "parameter is not an ast") + + (**The FunctionDeclaration value of the parameter.*) + let get_func_decl ( x : parameter ) = + match x with + | P_Fdl(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a func_decl") + + (**The rational string value of the parameter.*) + let get_func_decl ( x : parameter ) = + match x with + | P_Rat(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a rational string") + end + + open Parameter + + (** + Creates a new function declaration. + *) + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + create_ndr ctx name domain range + + (** + Creates a new function declaration. + *) + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = + mk_func_decl ctx (Symbol.mk_string ctx name) domain range + + (** + Creates a fresh function declaration with a name prefixed with . + + + *) + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + create_pdr ctx prefix domain range + + (** + Creates a new constant function declaration. + *) + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + create_ndr ctx name [||] range + + (** + Creates a new constant function declaration. + *) + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = + create_ndr ctx (Symbol.mk_string ctx name) [||] range + + (** + Creates a fresh constant function declaration with a name prefixed with . + + + *) + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = + create_pdr ctx prefix [||] range + + + (** + Comparison operator. + @param a A func_decl + @param b A func_decl + @return True if and are from the same context + and represent the same func_decl; false otherwise. + *) + let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || + if (gnc a) != (gnc b) then + false + else + (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) + + (** + A string representations of the function declaration. + *) + let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) + + (** + Returns a unique identifier for the function declaration. + *) + let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) + + (** + The arity of the function declaration + *) + let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) + + (** + The size of the domain of the function declaration + + *) + let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) + + (** + The domain of the function declaration + *) + let get_domain ( x : func_decl ) = + let n = (get_domain_size x) in + let f i = Sort.create (gc x) (Z3native.get_domain (gnc x) (gno x) i) in + Array.init n f + + (** + The range of the function declaration + *) + let get_range ( x : func_decl ) = + Sort.create (gc x) (Z3native.get_range (gnc x) (gno x)) + + (** + The kind of the function declaration. + *) + let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) + + (** + The name of the function declaration + *) + let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) + + (** + The number of parameters of the function declaration + *) + let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) + + (** + The parameters of the function declaration + *) + let get_parameters ( x : func_decl ) = + let n = (get_num_parameters x) in + let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with + | PARAMETER_INT -> P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> P_Srt (Sort.create (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> P_Ast (AST.create (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> P_Fdl (create (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + ) in + mk_list f n + + (** + Create expression that applies function to arguments. + @param args The arguments + *) + let apply ( x : func_decl ) ( args : Expr.expr array ) = Expr.create_fa (gc x) x args +end + (** Parameter sets (of Solvers, Tactics, ...) A Params objects represents a configuration in the form of symbol/value pairs. *) -module Params = -struct +and Params : +sig + type params = z3_native_object + + val create : context -> Z3native.ptr -> params + + module ParamDescrs : sig + type param_descrs = z3_native_object + + val create : context -> Z3native.ptr -> param_descrs + end +end = struct type params = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : params = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.params_inc_ref ; dec_ref = Z3native.params_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) - module ParamDescrs = - struct + module ParamDescrs : + sig + type param_descrs = z3_native_object + + val create : context -> Z3native.ptr -> param_descrs + end = struct type param_descrs = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : param_descrs = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.param_descrs_inc_ref ; dec_ref = Z3native.param_descrs_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -1449,7 +1065,6 @@ struct *) let add_s_double ( x : params ) ( name : string ) ( value : float ) = add_double x (Symbol.mk_string (z3obj_gc x) name) value - (** Adds a parameter setting. *) @@ -1460,7 +1075,7 @@ struct Creates a new parameter set *) let mk_params ( ctx : context ) = - cnstr ctx (Z3native.mk_params (context_gno ctx)) + create ctx (Z3native.mk_params (context_gno ctx)) (** A string representation of the parameter set. @@ -1468,18 +1083,69 @@ struct let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) end - (** General expressions (terms), including Boolean logic *) -module Expr = -struct +and Expr : +sig + type expr = Expr of AST.ast + + val create : context -> Z3native.ptr -> expr + val create_fa : context -> FuncDecl.func_decl -> expr array -> expr + val gc : expr -> context + val gno : expr -> Z3native.ptr + val gnc : expr -> Z3native.ptr + val aton : expr array -> Z3native.ptr array + + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + val get_func_decl : expr -> FuncDecl.func_decl +end = struct + type expr = Expr of AST.ast + + let create ( ctx : context ) ( obj : Z3native.ptr ) = + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then + (match (Quantifiers.create ctx obj) with Quantifiers.Quantifier(e) -> e) + else + let s = Z3native.get_sort (context_gno ctx) obj in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) obj) then + (match (Arithmetic.create_algebraic_num ctx obj) with Arithmetic.AlgebraicNum(Arithmetic.Expr(e)) -> e) + else + if (Z3native.is_numeral_ast (context_gno ctx) obj) && + (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + match sk with + | INT_SORT -> (match (Arithmetic.create_int_num ctx obj) with Arithmetic.IntNum(Arithmetic.IntExpr(Arithmetic.Expr(e))) -> e) + | REAL_SORT -> (match (Arithmetic.create_rat_num ctx obj) with Arithmetic.RatNum(Arithmetic.RealExpr(Arithmetic.Expr(e))) -> e) + | BV_SORT -> (match (BitVectors.create_num ctx obj) with BitVectors.BitVecNum(BitVectors.BitVecExpr(e)) -> e) + | _ -> raise (Z3native.Exception "Unsupported numeral object") + else + match sk with + | BOOL_SORT -> (match (Booleans.create ctx obj) with Booleans.BoolExpr(e) -> e) + | INT_SORT -> (match (Arithmetic.create_int_expr ctx obj) with Arithmetic.IntExpr(Arithmetic.Expr(e)) -> e) + | REAL_SORT -> (match (Arithmetic.create_real_expr ctx obj) with Arithmetic.RealExpr(Arithmetic.Expr(e)) -> e) + | BV_SORT -> (match (BitVectors.create_expr ctx obj) with BitVectors.BitVecExpr(e) -> e) + | ARRAY_SORT -> (match (Arrays.create_expr ctx obj) with Arrays.ArrayExpr(e) -> e) + | DATATYPE_SORT -> (match (Datatypes.create_expr ctx obj) with Datatypes.DatatypeExpr(e) -> e) + | _ -> Expr(AST.create ctx obj) + + let aton ( a : expr array ) = + let f ( e : expr ) = match e with Expr(a) -> (z3obj_gno a) in + Array.map f a + + let create_fa ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = + let o = Z3native.mk_app (context_gno ctx) (FuncDecl.gno f) (Array.length args) (aton args) in + Expr.create ctx o + + let gc ( x : expr ) = match x with Expr(a) -> (z3obj_gc a) + let gnc ( x : expr ) = match x with Expr(a) -> (z3obj_gnc a) + let gno ( x : expr ) = match x with Expr(a) -> (z3obj_gno a) + (** Returns a simplified version of the expression. @param p A set of parameters to configure the simplifier *) let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> create_expr x#gc (Z3native.simplify x#gnc x#gno) - | Some pp -> create_expr x#gc (Z3native.simplify_ex x#gnc x#gno (z3obj_gno pp)) + | None -> Expr.create (gc x) (Z3native.simplify (gnc x) (gno x)) + | Some pp -> Expr.create (gc x) (Z3native.simplify_ex (gnc x) (gno x) (z3obj_gno pp)) (** a string describing all available parameters to Expr.Simplify. @@ -1491,29 +1157,29 @@ struct Retrieves parameter descriptions for simplifier. *) let get_simplify_parameter_descrs ( ctx : context ) = - Params.ParamDescrs.cnstr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) + Params.ParamDescrs.create ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. *) - let get_func_decl ( x : expr ) = (new func_decl x#gc)#cnstr_obj (Z3native.get_app_decl x#gnc x#gno) + let get_func_decl ( x : expr ) = FuncDecl.create (gc x) (Z3native.get_app_decl (gnc x) (gno x)) (** Indicates whether the expression is the true or false expression or something else (L_UNDEF). *) - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value x#gnc x#gno) + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) (** The number of arguments of the expression. *) - let get_num_args ( x : expr ) = Z3native.get_app_num_args x#gnc x#gno + let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) (** The arguments of the expression. *) let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = create_expr x#gc (Z3native.get_app_arg x#gnc x#gno i) in + let f i = create (gc x) (Z3native.get_app_arg (gnc x) (gno x) i) in Array.init n f (** @@ -1524,7 +1190,7 @@ struct if (Array.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - x#sno x#gc (Z3native.update_term x#gnc x#gno (Array.length args) (expraton args)) + create (gc x) (Z3native.update_term (gnc x) (gno x) (Array.length args) (aton args)) (** Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. @@ -1537,7 +1203,7 @@ struct if (Array.length from) <> (Array.length to_) then raise (Z3native.Exception "Argument sizes do not match") else - create_expr x#gc (Z3native.substitute x#gnc x#gno (Array.length from) (expraton from) (expraton to_)) + create (gc x) (Z3native.substitute (gnc x) (gno x) (Array.length from) (aton from) (aton to_)) (** Substitute every occurrence of from in the expression with to. @@ -1552,7 +1218,7 @@ struct For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) let substitute_vars ( x : expr ) to_ = - create_expr x#gc (Z3native.substitute_vars x#gnc x#gno (Array.length to_) (expraton to_)) + create (gc x) (Z3native.substitute_vars (gnc x) (gno x) (Array.length to_) (aton to_)) (** @@ -1561,46 +1227,46 @@ struct @return A copy of the term which is associated with *) let translate ( x : expr ) to_ctx = - if x#gc == to_ctx then + if (gc x) == to_ctx then x else - create_expr to_ctx (Z3native.translate x#gnc x#gno (context_gno to_ctx)) + create to_ctx (Z3native.translate (gnc x) (gno x) (context_gno to_ctx)) (** Returns a string representation of the expression. *) - let to_string ( x : expr ) = Z3native.ast_to_string x#gnc x#gno + let to_string ( x : expr ) = Z3native.ast_to_string (gnc x) (gno x) (** Indicates whether the term is a numeral *) - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast x#gnc x#gno) + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (gnc x) (gno x)) (** Indicates whether the term is well-sorted. @return True if the term is well-sorted, false otherwise. *) - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted x#gnc x#gno + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) (** The Sort of the term. *) - let get_sort ( x : expr ) = create_sort x#gc (Z3native.get_sort x#gnc x#gno) + let get_sort ( x : expr ) = Sort.create (gc x) (Z3native.get_sort (gnc x) (gno x)) (** Indicates whether the term has Boolean sort. *) - let is_bool ( x : expr ) = (AST.is_expr x) && - (Z3native.is_eq_sort x#gnc - (Z3native.mk_bool_sort x#gnc) - (Z3native.get_sort x#gnc x#gno)) - + let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + (Z3native.is_eq_sort (gnc x) + (Z3native.mk_bool_sort (gnc x)) + (Z3native.get_sort (gnc x) (gno x))) + (** Indicates whether the term represents a constant. *) - let is_const ( x : expr ) = (AST.is_expr x) && + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && (get_num_args x) == 0 && - FuncDecl.get_domain_size(get_func_decl x) == 0 + (FuncDecl.get_domain_size (get_func_decl x)) == 0 (** Indicates whether the term is the constant true. @@ -1679,123 +1345,36 @@ struct (** Creates a new Constant of sort and named . *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - create_expr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) range#gno) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : Sort.sort ) = + create ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) (** Creates a new Constant of sort and named . *) - let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = - mk_const ctx (Symbol.mk_string ctx name)range + let mk_const_s ( ctx : context ) ( name : string ) ( range : Sort.sort ) = + mk_const ctx (Symbol.mk_string ctx name) range (** Creates a constant from the func_decl . @param f An expression of a 0-arity function *) - let mk_const_f ( ctx : context ) ( f : func_decl ) = - create_expr_fa ctx f [||] + let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = + create_fa ctx f [||] (** Creates a fresh constant of sort and a name prefixed with . *) - let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort) = - create_expr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix range#gno) - - (** - Create a Boolean constant. - *) - let mk_bool_const ( ctx : context ) ( name : Symbol.symbol ) = - ((mk_const ctx name (Sort.mk_bool ctx)) :> bool_expr) - - (** - Create a Boolean constant. - *) - let mk_bool_const_s ( ctx : context ) ( name : string ) = - mk_bool_const ctx (Symbol.mk_string ctx name) + let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : Sort.sort ) = + create ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) (** Create a new function application. *) - let mk_app ( ctx : context ) ( f : func_decl ) ( args : expr array ) = - create_expr_fa ctx f args - - (** - The true Term. - *) - let mk_true ( ctx : context ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_true (context_gno ctx)) - - (** - The false Term. - *) - let mk_false ( ctx : context ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_false (context_gno ctx)) - - (** - Creates a Boolean value. - *) - let mk_bool ( ctx : context ) ( value : bool) = - if value then mk_true ctx else mk_false ctx - - (** - Creates the equality = . - *) - let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_eq (context_gno ctx) x#gno y#gno) - - (** - Creates a distinct term. - *) - let mk_distinct ( ctx : context ) ( args : expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_distinct (context_gno ctx) (Array.length args) (astaton args)) - - (** - Mk an expression representing not(a). - *) - let mk_not ( ctx : context ) ( a : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_not (context_gno ctx) a#gno) - - (** - Create an expression representing an if-then-else: ite(t1, t2, t3). - @param t1 An expression with Boolean sort - @param t2 An expression - @param t3 An expression with the same sort as - *) - let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - create_expr ctx (Z3native.mk_ite (context_gno ctx) t1#gno t2#gno t3#gno) - - (** - Create an expression representing t1 iff t2. - *) - let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_iff (context_gno ctx) t1#gno t2#gno) - - (** - Create an expression representing t1 -> t2. - *) - let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_implies (context_gno ctx) t1#gno t2#gno) - - (** - Create an expression representing t1 xor t2. - *) - let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_xor (context_gno ctx) t1#gno t2#gno) - - (** - Create an expression representing the AND of args - *) - let mk_and ( ctx : context ) ( args : bool_expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_and (context_gno ctx) (Array.length args) (astaton args)) - - (** - Create an expression representing the OR of args - *) - let mk_or ( ctx : context ) ( args : bool_expr array ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_or (context_gno ctx) (Array.length args) (astaton args)) + let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = + create_fa ctx f args (** Create a numeral of a given sort. @@ -1803,8 +1382,8 @@ struct @param ty 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 *) - let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = - create_expr ctx (Z3native.mk_numeral (context_gno ctx) v ty#gno) + let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : Sort.sort ) = + create ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) (** Create a numeral of a given sort. This function can be use to create numerals that fit in a machine integer. @@ -1813,13 +1392,147 @@ struct @param ty Sort of the numeral @return A Term with value and type *) - let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_int (context_gno ctx) v ty#gno) + let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : Sort.sort ) = + create ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) + + let aton (a : expr array) = + let f (e : expr) = (gno e) in + Array.map f a +end + +(** Boolean expressions *) +and Booleans : +sig + type bool_expr = BoolExpr of Expr.expr + type bool_sort = BoolSort of Sort.sort + + val create : context -> Z3native.ptr -> bool_expr + val aton : bool_expr array -> Z3native.ptr array +end = struct + type bool_expr = BoolExpr of Expr.expr + type bool_sort = BoolSort of Sort.sort + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let a = (AST.create ctx no) in + BoolExpr(Expr.Expr(a)) + + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gc e) + let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gnc e) + let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gno e) + + let aton ( a : bool_expr array ) = + let f (e : bool_expr) = (gno e) in + Array.map f a + + let mk_sort ( ctx : context ) = + BoolSort(Sort.create ctx (Z3native.mk_bool_sort (context_gno ctx))) + + (** + Create a Boolean constant. + *) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = + let s = (match (mk_sort ctx) with BoolSort(q) -> q) in + BoolExpr(Expr.mk_const ctx name s) + + (** + Create a Boolean constant. + *) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) + + (** + The true Term. + *) + let mk_true ( ctx : context ) = + create ctx (Z3native.mk_true (context_gno ctx)) + + (** + The false Term. + *) + let mk_false ( ctx : context ) = + create ctx (Z3native.mk_false (context_gno ctx)) + + (** + Creates a Boolean value. + *) + let mk_val ( ctx : context ) ( value : bool ) = + if value then mk_true ctx else mk_false ctx + + (** + Creates the equality = . + *) + let mk_eq ( ctx : context ) ( x : Expr.expr ) ( y : Expr.expr ) = + create ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + + (** + Creates a distinct term. + *) + let mk_distinct ( ctx : context ) ( args : Expr.expr array ) = + create ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (Expr.aton args)) + + (** + Mk an expression representing not(a). + *) + let mk_not ( ctx : context ) ( a : bool_expr ) = + create ctx (Z3native.mk_not (context_gno ctx) (gno a)) + + (** + Create an expression representing an if-then-else: ite(t1, t2, t3). + @param t1 An expression with Boolean sort + @param t2 An expression + @param t3 An expression with the same sort as + *) + let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = + create ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + + (** + Create an expression representing t1 iff t2. + *) + let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + create ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + + (** + Create an expression representing t1 -> t2. + *) + let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + create ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + (** + Create an expression representing t1 xor t2. + *) + let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + create ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + + (** + Create an expression representing the AND of args + *) + let mk_and ( ctx : context ) ( args : bool_expr array ) = + create ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (aton args)) + + (** + Create an expression representing the OR of args + *) + let mk_or ( ctx : context ) ( args : bool_expr array ) = + create ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (aton args)) end (** Quantifier expressions *) -module Quantifiers = -struct +and Quantifiers : +sig + type quantifier = Quantifier of Expr.expr + + val create : context -> Z3native.ptr -> quantifier +end = struct + type quantifier = Quantifier of Expr.expr + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let a = (AST.create ctx no) in + Quantifier(Expr.Expr(a)) + + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) + let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) + let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) + + (** The de-Burijn index of a bound variable. @@ -1838,11 +1551,11 @@ struct on the scope in which it appears. The deeper ( x : expr ) appears, the higher is its index. *) - let get_index ( x : expr ) = - if not (AST.is_var x) then + let get_index ( x : Expr.expr ) = + if not (AST.is_var (match x with Expr.Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else - Z3native.get_index_value x#gnc x#gno + Z3native.get_index_value (Expr.gnc x) (Expr.gno x) (** Quantifier patterns @@ -1850,33 +1563,57 @@ struct non-empty. If the list comprises of more than one term, it is also called a multi-pattern. *) - module Pattern = - struct + module Patterns : + sig + type pattern = Pattern of AST.ast + + val create : context -> Z3native.ptr -> pattern + val aton : pattern array -> Z3native.ptr array + end = struct + type pattern = Pattern of AST.ast + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + Pattern(res) + + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) + let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) + let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) + (** The number of terms in the pattern. *) let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms x#gnc x#gno + Z3native.get_pattern_num_terms (gnc x) (gno x) (** The terms in the pattern. *) let get_terms ( x : pattern ) = let n = (get_num_terms x) in - let f i = (create_expr x#gc (Z3native.get_pattern x#gnc x#gno i)) in + let f i = (Expr.create (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in Array.init n f (** A string representation of the pattern. *) - let to_string ( x : pattern ) = Z3native.pattern_to_string x#gnc x#gno + let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) + + let aton (a : pattern array) = + let f (e : pattern) = (gno e) in + Array.map f a end (** Indicates whether the quantifier is universal. *) let is_universal ( x : quantifier ) = - Z3native.is_quantifier_forall x#gnc x#gno + Z3native.is_quantifier_forall (gnc x) (gno x) (** Indicates whether the quantifier is existential. @@ -1886,45 +1623,45 @@ struct (** The weight of the quantifier. *) - let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight x#gnc x#gno + let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) (** The number of patterns. *) - let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns x#gnc x#gno + let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) (** The patterns. *) let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_pattern_ast x#gnc x#gno i)) in + let f i = (Patterns.create (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** The number of no-patterns. *) - let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns x#gnc x#gno + let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) (** The no-patterns. *) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = ((new pattern x#gc)#cnstr_obj (Z3native.get_quantifier_no_pattern_ast x#gnc x#gno i)) in + let f i = (Patterns.create (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** The number of bound variables. *) - let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound x#gnc x#gno + let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) (** The symbols for the bound variables. *) let get_bound_variable_names ( x : quantifier ) = let n = (get_num_bound x) in - let f i = (Symbol.create x#gc (Z3native.get_quantifier_bound_name x#gnc x#gno i)) in + let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in Array.init n f (** @@ -1932,31 +1669,31 @@ struct *) let get_bound_variable_sorts ( x : quantifier ) = let n = (get_num_bound x) in - let f i = (create_sort x#gc (Z3native.get_quantifier_bound_sort x#gnc x#gno i)) in + let f i = (Sort.create (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in Array.init n f (** The body of the quantifier. *) let get_body ( x : quantifier ) = - (new bool_expr x#gc)#cnstr_obj (Z3native.get_quantifier_body x#gnc x#gno) + Booleans.create (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) (** Creates a new bound variable. @param index The de-Bruijn index of the variable @param ty The sort of the variable *) - let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - create_expr ctx (Z3native.mk_bound (context_gno ctx) index ty#gno) + let mk_bound ( ctx : context ) ( index : int ) ( ty : Sort.sort ) = + Expr.create ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) (** Create a quantifier pattern. *) - let mk_pattern ( ctx : context ) ( terms : expr array ) = + let mk_pattern ( ctx : context ) ( terms : Expr.expr array ) = if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - (new pattern ctx)#cnstr_obj (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (astaton terms)) + Patterns.create ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (Expr.aton terms)) (** Create a universal Quantifier. @@ -1977,95 +1714,96 @@ struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_forall ( ctx : context ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (patternaton patterns) - (Array.length sorts) (astaton sorts) - (Symbol.aton names) - body#gno) + create ctx (Z3native.mk_quantifier (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (Array.length patterns) (Patterns.aton patterns) + (Array.length sorts) (Sort.aton sorts) + (Symbol.aton names) + (Expr.gno body)) else - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (patternaton patterns) - (Array.length nopatterns) (patternaton nopatterns) - (Array.length sorts) (astaton sorts) - (Symbol.aton names) - body#gno) + create ctx (Z3native.mk_quantifier_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length patterns) (Patterns.aton patterns) + (Array.length nopatterns) (Expr.aton nopatterns) + (Array.length sorts) (Sort.aton sorts) + (Symbol.aton names) + (Expr.gno body)) (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_forall_const ( ctx : context ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (expraton bound_constants) - (Array.length patterns) (patternaton patterns) - body#gno) + create ctx (Z3native.mk_quantifier_const (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (Expr.aton bound_constants) + (Array.length patterns) (Patterns.aton patterns) + (Expr.gno body)) else - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (expraton bound_constants) - (Array.length patterns) (patternaton patterns) - (Array.length nopatterns) (patternaton nopatterns) - body#gno) + create ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length bound_constants) (Expr.aton bound_constants) + (Array.length patterns) (Patterns.aton patterns) + (Array.length nopatterns) (Expr.aton nopatterns) + (Expr.gno body)) + (** Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_exists ( ctx : context ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (patternaton patterns) - (Array.length sorts) (astaton sorts) - (Symbol.aton names) - body#gno) + create ctx (Z3native.mk_quantifier (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (Array.length patterns) (Patterns.aton patterns) + (Array.length sorts) (Sort.aton sorts) + (Symbol.aton names) + (Expr.gno body)) else - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (patternaton patterns) - (Array.length nopatterns) (patternaton nopatterns) - (Array.length sorts) (astaton sorts) - (Symbol.aton names) - body#gno) - + create ctx (Z3native.mk_quantifier_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length patterns) (Patterns.aton patterns) + (Array.length nopatterns) (Expr.aton nopatterns) + (Array.length sorts) (Sort.aton sorts) + (Symbol.aton names) + (Expr.gno body)) + (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_exists_const ( ctx : context ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (expraton bound_constants) - (Array.length patterns) (patternaton patterns) - body#gno) + create ctx (Z3native.mk_quantifier_const (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (Expr.aton bound_constants) + (Array.length patterns) (Patterns.aton patterns) + (Expr.gno body)) else - (new quantifier ctx)#cnstr_obj (Z3native.mk_quantifier_const_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (expraton bound_constants) - (Array.length patterns) (patternaton patterns) - (Array.length nopatterns) (patternaton nopatterns) - body#gno) + create ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length bound_constants) (Expr.aton bound_constants) + (Array.length patterns) (Patterns.aton patterns) + (Array.length nopatterns) (Expr.aton nopatterns) + (Expr.gno body)) (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -2075,7 +1813,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : pattern array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -2083,75 +1821,104 @@ struct end (** Functions to manipulate Array expressions *) -module Arrays = -struct +and Arrays : +sig + type array_expr = ArrayExpr of Expr.expr + type array_sort = ArraySort of Sort.sort + + val create_expr : context -> Z3native.ptr -> array_expr +end = struct + type array_expr = ArrayExpr of Expr.expr + type array_sort = ArraySort of Sort.sort + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let e = (Expr.create ctx no) in + ArrayExpr(e) + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + ArraySort(s) + + let sgc ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gc s) + let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gnc s) + let sgno ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gno s) + + let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gc e) + let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gnc e) + let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gno e) + + let aton (a : array_expr array) = + let f (e : array_expr) = (egno e) in + Array.map f a + + (** Create a new array sort. *) - let mk_sort ( ctx : context ) domain range = - (new array_sort ctx)#cnstr_dr domain range + let mk_sort ( ctx : context ) ( domain : Sort.sort ) ( range : Sort.sort ) = + create_sort ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) (** 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. *) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) + let is_store ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) (** Indicates whether the term is an array select. *) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) + let is_select ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) + let is_constant_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) (** Indicates whether the term is a default array. For example default(const(v)) = v. The function is unary. *) - let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) + let is_default_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) + let is_array_map ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + let is_as_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) (** Indicates whether the term is of an array sort. *) - let is_array ( x : expr ) = - (Z3native.is_app x#gnc x#gno) && - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == ARRAY_SORT) + let is_array ( x : Expr.expr ) = + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) (** The domain of the array sort. *) - let get_domain (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_domain x#gnc x#gno) + let get_domain ( x : array_sort ) = Sort.create (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) (** The range of the array sort. *) - let get_range (x : array_sort) = create_sort x#gc (Z3native.get_array_sort_range x#gnc x#gno) + let get_range ( x : array_sort ) = Sort.create (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) (** Create an array constant. *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = - ((Expr.mk_const ctx name ((mk_sort ctx domain range) :> sort)) :> array_expr) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort ) ( range : Sort.sort ) = + ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) (** Create an array constant. *) - let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = + let mk_const_s ( ctx : context ) ( name : string ) ( domain : Sort.sort ) ( range : Sort.sort ) = mk_const ctx (Symbol.mk_string ctx name) domain range (** @@ -2166,8 +1933,8 @@ struct *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - ((create_expr ctx (Z3native.mk_select (context_gno ctx) a#gno i#gno)) :> array_expr) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : Expr.expr ) = + create_expr ctx (Z3native.mk_select (context_gno ctx) (egno a) (Expr.gno i)) (** Array update. @@ -2185,8 +1952,8 @@ struct *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr) = - (new array_expr ctx)#cnstr_obj (Z3native.mk_store (context_gno ctx) a#gno i#gno v#gno) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : Expr.expr ) ( v : Expr.expr ) = + create_expr ctx (Z3native.mk_store (context_gno ctx) (egno a) (Expr.gno i) (Expr.gno v)) (** Create a constant array. @@ -2196,8 +1963,8 @@ struct *) - let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - (new array_expr ctx)#cnstr_obj (Z3native.mk_const_array (context_gno ctx) domain#gno v#gno) + let mk_const_array ( ctx : context ) ( domain : Sort.sort ) ( v : Expr.expr ) = + create_expr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) (** Maps f on the argument arrays. @@ -2209,8 +1976,8 @@ struct *) - let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = - ((create_expr ctx (Z3native.mk_map (context_gno ctx) f#gno (Array.length args) (astaton args))) :> array_expr) + let mk_map ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : array_expr array ) = + create_expr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (aton args)) (** Access the array default value. @@ -2219,149 +1986,184 @@ struct finite maps with a default range value. *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = - ((create_expr ctx (Z3native.mk_array_default (context_gno ctx) arg#gno)) :> array_expr) + create_expr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) end (** Functions to manipulate Set expressions *) -module Sets = -struct +and Sets : +sig + type set_sort = SetSort of Sort.sort + +end = struct + type set_sort = SetSort of Sort.sort + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + SetSort(s) + (** Indicates whether the term is set union *) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_union ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) (** Indicates whether the term is set intersection *) - let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_intersect ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) (** Indicates whether the term is set difference *) - let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_difference ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) (** Indicates whether the term is set complement *) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_complement ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) (** Indicates whether the term is set subset *) - let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + let is_subset ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) (** Create a set type. *) - let mk_sort ( ctx : context ) ( ty : sort) = - (new set_sort ctx)#cnstr_s ty + let mk_sort ( ctx : context ) ( ty : Sort.sort ) = + create_sort ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) (** Create an empty set. *) - let mk_empty ( ctx : context ) ( domain : sort ) = - (create_expr ctx (Z3native.mk_empty_set (context_gno ctx) domain#gno)) + let mk_empty ( ctx : context ) ( domain : Sort.sort ) = + (Expr.create ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) (** Create the full set. *) - let mk_full ( ctx : context ) ( domain : sort ) = - create_expr ctx (Z3native.mk_full_set (context_gno ctx) domain#gno) + let mk_full ( ctx : context ) ( domain : Sort.sort ) = + Expr.create ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) (** Add an element to the set. *) - let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_add (context_gno ctx) set#gno element#gno) + let mk_set_add ( ctx : context ) ( set : Expr.expr ) ( element : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) (** Remove an element from a set. *) - let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - create_expr ctx (Z3native.mk_set_del (context_gno ctx) set#gno element#gno) + let mk_del ( ctx : context ) ( set : Expr.expr ) ( element : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) (** Take the union of a list of sets. *) - let mk_union ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (astaton args)) + let mk_union ( ctx : context ) ( args : Expr.expr array ) = + Expr.create ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (Expr.aton args)) (** Take the intersection of a list of sets. *) - let mk_intersection ( ctx : context ) ( args : expr array ) = - create_expr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (astaton args)) + let mk_intersection ( ctx : context ) ( args : Expr.expr array ) = + Expr.create ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (Expr.aton args)) (** Take the difference between two sets. *) - let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_difference (context_gno ctx) arg1#gno arg2#gno) + let mk_difference ( ctx : context ) ( arg1 : Expr.expr ) ( arg2 : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) (** Take the complement of a set. *) - let mk_complement ( ctx : context ) ( arg : expr ) = - create_expr ctx (Z3native.mk_set_complement (context_gno ctx) arg#gno) + let mk_complement ( ctx : context ) ( arg : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) (** Check for set membership. *) - let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - create_expr ctx (Z3native.mk_set_member (context_gno ctx) elem#gno set#gno) + let mk_membership ( ctx : context ) ( elem : Expr.expr ) ( set : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) (** Check for subsetness of sets. *) - let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr) = - create_expr ctx (Z3native.mk_set_subset (context_gno ctx) arg1#gno arg2#gno) + let mk_subset ( ctx : context ) ( arg1 : Expr.expr ) ( arg2 : Expr.expr ) = + Expr.create ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) end (** Functions to manipulate Finite Domain expressions *) -module FiniteDomains = -struct - (** - Create a new finite domain sort. - *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) size = - (new finite_domain_sort ctx)#cnstr_si name size +and FiniteDomains : +sig + type finite_domain_sort = FiniteDomainSort of Sort.sort + +end = struct + type finite_domain_sort = FiniteDomainSort of Sort.sort + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + FiniteDomainSort(s) + + let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gc s) + let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gnc s) + let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s))-> (z3obj_gno s) (** Create a new finite domain sort. *) - let mk_sort_s ( ctx : context ) ( name : string ) size = - (new finite_domain_sort ctx)#cnstr_si (Symbol.mk_string ctx name) size + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + create_sort ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size) + + (** + Create a new finite domain sort. + *) + let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = + mk_sort ctx (Symbol.mk_string ctx name) size (** Indicates whether the term is of an array sort. *) - let is_finite_domain ( x : expr ) = - (Z3native.is_app x#gnc x#gno) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == FINITE_DOMAIN_SORT) + let is_finite_domain ( x : Expr.expr ) = + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) == FINITE_DOMAIN_SORT) (** Indicates whether the term is a less than predicate over a finite domain. *) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + let is_lt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) (** The size of the finite domain sort. *) - let get_size (x : finite_domain_sort) = - let (r, v) = Z3native.get_finite_domain_sort_size x#gnc x#gno in + let get_size ( x : finite_domain_sort ) = + let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in if r then v else raise (Z3native.Exception "Conversion failed.") end (** Functions to manipulate Relation expressions *) -module Relations = -struct +and Relations : +sig + type relation_sort = RelationSort of Sort.sort + +end = struct + type relation_sort = RelationSort of Sort.sort + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + RelationSort(s) + + let gc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gc s) + let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gnc s) + let gno ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s))-> (z3obj_gno s) + (** Indicates whether the term is of a relation sort. *) - let is_relation ( x : expr ) = - ((Z3native.is_app x#gnc x#gno) && - (sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno)) == RELATION_SORT)) + let is_relation ( x : Expr.expr ) = + ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) == RELATION_SORT)) (** Indicates whether the term is an relation store @@ -2370,40 +2172,40 @@ struct 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. *) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + let is_store ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) (** Indicates whether the term is an empty relation *) - let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + let is_empty ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) (** Indicates whether the term is a test for the emptiness of a relation *) - let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + let is_is_empty ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) (** Indicates whether the term is a relational join *) - let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + let is_join ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) (** Indicates whether the term is the union or convex hull of two relations. The function takes two arguments. *) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + let is_union ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) (** Indicates whether the term is the widening of two relations The function takes two arguments. *) - let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + let is_widen ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). The function takes one argument. *) - let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) + let is_project ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) (** Indicates whether the term is a relation filter @@ -2414,7 +2216,7 @@ struct corresponding to the columns of the relation. So the first column in the relation has index 0. *) - let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) + let is_filter ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) (** Indicates whether the term is an intersection of a relation with the negation of another. @@ -2429,7 +2231,7 @@ struct target are elements in ( x : expr ) in pos, such that there is no y in neg that agrees with ( x : expr ) on the columns c1, d1, .., cN, dN. *) - let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) + let is_negation_filter ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) (** Indicates whether the term is the renaming of a column in a relation @@ -2437,12 +2239,12 @@ struct The function takes one argument. The parameters contain the renaming as a cycle. *) - let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + let is_rename ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) (** Indicates whether the term is the complement of a relation *) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) + let is_complement ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) (** Indicates whether the term is a relational select @@ -2451,7 +2253,7 @@ struct The function takes n+1 arguments, where the first argument is a relation, and the remaining n arguments correspond to a record. *) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) + let is_select ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) (** Indicates whether the term is a relational clone (copy) @@ -2462,38 +2264,153 @@ struct for terms of kind to perform destructive updates to the first argument. *) - let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + let is_clone ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) (** The arity of the relation sort. *) - let get_arity (x : relation_sort) = Z3native.get_relation_arity x#gnc x#gno + let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) (** The sorts of the columns of the relation sort. *) - let get_column_sorts (x : relation_sort) = + let get_column_sorts ( x : relation_sort ) = let n = get_arity x in - let f i = create_sort x#gc (Z3native.get_relation_column x#gnc x#gno i) in + let f i = (create_sort (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in Array.init n f end (** Functions to manipulate Datatype expressions *) -module Datatypes = -struct +and Datatypes : +sig + type datatype_expr = DatatypeExpr of Expr.expr + type datatype_sort = DatatypeSort of Sort.sort + + val create_expr : context -> Z3native.ptr -> datatype_expr +end = struct + type datatype_expr = DatatypeExpr of Expr.expr + type datatype_sort = DatatypeSort of Sort.sort + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let e = (Expr.create ctx no) in + DatatypeExpr(e) + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + DatatypeSort(s) + + let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gc s) + let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gnc s) + let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s))-> (z3obj_gno s) + + (** Constructors *) module Constructor = struct + type constructor_extra = { + m_n : int; + mutable m_tester_decl : FuncDecl.func_decl option; + mutable m_constructor_decl : FuncDecl.func_decl option ; + mutable m_accessor_decls : FuncDecl.func_decl array option} + type constructor = Constructor of (z3_native_object * constructor_extra) + + let create_ssssi ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = + let n = (Array.length field_names) in + if n != (Array.length sorts) then + raise (Z3native.Exception "Number of field names does not match number of sorts") + else + if n != (Array.length sort_refs) then + raise (Z3native.Exception "Number of field names does not match number of sort refs") + else + let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) + (Symbol.gno recognizer) + n + (Symbol.aton field_names) + (Sort.aton sorts) + sort_refs) in + let no : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + let ex : constructor_extra = { m_n = n; + m_tester_decl = None; + m_constructor_decl = None; + m_accessor_decls = None} in + (z3obj_sno no ctx ptr) ; + (z3obj_create no) ; + let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in + Gc.finalise f no ; + Constructor(no, ex) + + let init_extra ( x : constructor ) = + match x with Constructor(no, ex) -> + match ex.m_tester_decl with + | None -> + let (a, b, c) = (Z3native.query_constructor (z3obj_gnc no) (z3obj_gno no) ex.m_n) in + ex.m_constructor_decl <- Some (FuncDecl.create (z3obj_gc no) a) ; + ex.m_tester_decl <- Some (FuncDecl.create (z3obj_gc no) b) ; + ex.m_accessor_decls <- Some (let f e = (FuncDecl.create (z3obj_gc no) e) in Array.map f c) ; + () + | _ -> () + + let get_n ( x : constructor ) = + match x with Constructor(no, ex) -> + ex.m_n + + let rec tester_decl ( x : constructor ) = + match x with Constructor(no, ex) -> + match ex.m_tester_decl with + | Some(s) -> s + | None -> init_extra x ; tester_decl x + + let rec constructor_decl ( x : constructor ) = + match x with Constructor(no, ex) -> + match ex.m_constructor_decl with + | Some(s) -> s + | None -> init_extra x ; constructor_decl x + + let rec accessor_decls ( x : constructor ) = + match x with Constructor(no, ex) -> + match ex.m_accessor_decls with + | Some(s) -> s + | None -> init_extra x ; accessor_decls x + + let aton ( a : constructor array ) = + let f (e : constructor) = match e with Constructor(no, ex) -> (z3obj_gno no)in + Array.map f a + + (** The number of fields of the constructor. *) - let get_num_fields ( x : constructor ) = x#get_n + let get_num_fields ( x : constructor ) = get_n x (** The function declaration of the constructor. *) - let get_constructor_decl ( x : constructor ) = x#constructor_decl + let get_constructor_decl ( x : constructor ) = constructor_decl x (** The function declaration of the tester. *) - let get_tester_decl ( x : constructor ) = x#tester_decl + let get_tester_decl ( x : constructor ) = tester_decl x (** The function declarations of the accessors *) - let get_accessor_decls ( x : constructor ) = x#accessor_decls + let get_accessor_decls ( x : constructor ) = accessor_decls x end + (** Constructor list objects *) + module ConstructorList = + struct + type constructor_list = z3_native_object + + let create ( ctx : context )( c : Constructor.constructor array ) = + let res : constructor_list = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Constructor.aton c))) ; + (z3obj_create res) ; + let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in + Gc.finalise f res; + res + + let aton (a : constructor_list array) = + let f (e : constructor_list) = (z3obj_gno e) in + Array.map f a + end + (* DATATYPES *) (** Create a datatype constructor. @@ -2505,8 +2422,8 @@ struct 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. *) - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array) = - (new constructor ctx)#cnstr_ssssi name recognizer field_names sorts sort_refs + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array) = + Constructor.create_ssssi ctx name recognizer field_names sorts sort_refs (** @@ -2519,20 +2436,21 @@ struct 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. *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : constructor array) = - (new datatype_sort ctx)#cnstr_sc name constructors + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array) = + let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Constructor.aton constructors)) in + create_sort ctx x (** Create a new datatype sort. *) - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array) = + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = mk_sort ctx (Symbol.mk_string ctx name) constructors (** @@ -2540,16 +2458,16 @@ struct @param names names of datatype sorts @param c list of constructors, one list per sort. *) - let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : constructor array array ) = + let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = let n = (Array.length names) in - let f e = ( (new constructor_list ctx)#cnstr_ca e ) in + let f e = (ConstructorList.create ctx e) in let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.aton names) (constructor_listaton cla)) in - let g e = ( (new datatype_sort ctx)#cnstr_obj e) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.aton names) (ConstructorList.aton cla)) in + let g e = (create_sort ctx e) in (Array.map g r) (** Create mutually recursive data-types. *) - let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = + let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = mk_sorts ctx ( let f e = (Symbol.mk_string ctx e) in @@ -2558,130 +2476,230 @@ struct c (** The number of constructors of the datatype sort. *) - let get_num_constructors (x : datatype_sort) = Z3native.get_datatype_sort_num_constructors x#gnc x#gno + let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) (** The range of the array sort. *) - let get_constructors (x : datatype_sort) = + let get_constructors ( x : datatype_sort ) = let n = (get_num_constructors x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i) in + let f i = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in Array.init n f (** The recognizers. *) - let get_recognizers (x : datatype_sort) = + let get_recognizers ( x : datatype_sort ) = let n = (get_num_constructors x) in - let f i = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_recognizer x#gnc x#gno i) in + let f i = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in Array.init n f (** The constructor accessors. *) - let get_accessors (x : datatype_sort) = + let get_accessors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = ( - let fd = ((new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor x#gnc x#gno i)) in - let ds = (Z3native.get_domain_size fd#gnc fd#gno) in - let g j = (new func_decl x#gc)#cnstr_obj (Z3native.get_datatype_sort_constructor_accessor x#gnc x#gno i j) in + let fd = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in + let g j = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in Array.init ds g ) in Array.init n f end (** Functions to manipulate Enumeration expressions *) -module Enumerations = -struct - (** - Create a new enumeration sort. - *) - let mk_sort ( ctx : context ) name enum_names = - (new enum_sort ctx)#cnstr_ss name enum_names +and Enumerations : +sig + type enum_sort_data + type enum_sort = EnumSort of (Sort.sort * enum_sort_data) +end = struct + type enum_sort_data = { mutable _constdecls : FuncDecl.func_decl array ; + mutable _testerdecls : FuncDecl.func_decl array } + type enum_sort = EnumSort of (Sort.sort * enum_sort_data) + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = + let s = (Sort.create ctx no) in + let e = { _constdecls = (let f e = FuncDecl.create ctx e in (Array.map f cdecls)) ; + _testerdecls = (let f e = FuncDecl.create ctx e in (Array.map f tdecls)) } in + EnumSort(s, e) + + let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gc s) + let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gnc s) + let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_)-> (z3obj_gno s) + (** Create a new enumeration sort. *) - let mk_sort_s ( ctx : context ) name enum_names = - (new enum_sort ctx)#cnstr_ss - (Symbol.mk_string ctx name) - (Symbol.mk_strings ctx enum_names) + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = + let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Symbol.aton enum_names)) in + create_sort ctx a b c + + (** + Create a new enumeration sort. + *) + let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string array ) = + mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) (** The function declarations of the constants in the enumeration. *) - let get_const_decls (x : enum_sort) = x#const_decls + let get_const_decls ( x : enum_sort ) = match x with EnumSort(_,ex) -> ex._constdecls (** The test predicates for the constants in the enumeration. *) - let get_tester_decls (x : enum_sort) = x#tester_decls + let get_tester_decls ( x : enum_sort ) = match x with EnumSort(_,ex) -> ex._testerdecls end (** Functions to manipulate List expressions *) -module Lists = -struct - (** - Create a new list sort. - *) - let mk_sort ( ctx : context ) (name : Symbol.symbol) elem_sort = - (new list_sort ctx)#cnstr_ss name elem_sort +and Lists : +sig + type list_sort_data + type list_sort = ListSort of (Sort.sort * list_sort_data) - (** - Create a new list sort. - *) +end = struct + type list_sort_data = { _nildecl : FuncDecl.func_decl ; + _is_nildecl : FuncDecl.func_decl ; + _consdecl : FuncDecl.func_decl ; + _is_consdecl : FuncDecl.func_decl ; + _headdecl : FuncDecl.func_decl ; + _taildecl : FuncDecl.func_decl } + type list_sort = ListSort of (Sort.sort * list_sort_data) + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = + let s = (Sort.create ctx no) in + let e = {_nildecl = FuncDecl.create ctx nildecl; + _is_nildecl = FuncDecl.create ctx is_nildecl; + _consdecl = FuncDecl.create ctx consdecl; + _is_consdecl = FuncDecl.create ctx is_consdecl; + _headdecl = FuncDecl.create ctx headdecl; + _taildecl = FuncDecl.create ctx taildecl} in + ListSort(s, e) + + let sgc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gc s) + let sgnc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gnc s) + let sgno ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_)-> (z3obj_gno s) + + + (** Create a new list sort. *) + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : Sort.sort ) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in + create_sort ctx r a b c d e f + + (** Create a new list sort. *) let mk_list_s ( ctx : context ) (name : string) elem_sort = mk_sort ctx (Symbol.mk_string ctx name) elem_sort (** The declaration of the nil function of this list sort. *) - let get_nil_decl (x : list_sort) = x#nil_decl + let get_nil_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._nildecl (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl (x : list_sort) = x#is_nil_decl + let get_is_nil_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._is_nildecl (** The declaration of the cons function of this list sort. *) - let get_cons_decl (x : list_sort) = x#cons_decl + let get_cons_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._consdecl (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl (x : list_sort) = x#is_cons_decl + let get_is_cons_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._is_consdecl (** The declaration of the head function of this list sort. *) - let get_head_decl (x : list_sort) = x#head_decl + let get_head_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._headdecl (** The declaration of the tail function of this list sort. *) - let get_tail_decl (x : list_sort) = x#tail_decl + let get_tail_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._taildecl (** The empty list. *) - let nil (x : list_sort) = create_expr_fa x#gc (get_nil_decl x) [||] + let nil ( x : list_sort ) = Expr.create_fa (sgc x) (get_nil_decl x) [||] end (** Functions to manipulate Tuple expressions *) -module Tuples = -struct - (** - Create a new tuple sort. - *) - let mk_sort ( ctx : context ) name field_names field_sorts = - (new tuple_sort ctx)#cnstr_siss name (Array.length field_names) field_names field_sorts +and Tuples : +sig + type tuple_sort = TupleSort of Sort.sort +end = struct + type tuple_sort = TupleSort of Sort.sort + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let s = (Sort.create ctx no) in + TupleSort(s) + + let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gc s) + let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gnc s) + let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s))-> (z3obj_gno s) + + (** Create a new tuple sort. *) + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : Sort.sort array ) = + let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Symbol.aton field_names) (Sort.aton field_sorts)) in + (* CMW: leaks a,b? *) + create_sort ctx r (** The constructor function of the tuple. *) - let get_mk_decl (x : tuple_sort) = - (new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_mk_decl x#gnc x#gno) + let get_mk_decl ( x : tuple_sort ) = + FuncDecl.create (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) (** The number of fields in the tuple. *) - let get_num_fields (x : tuple_sort) = Z3native.get_tuple_sort_num_fields x#gnc x#gno + let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) (** The field declarations. *) - let get_field_decls (x : tuple_sort) = + let get_field_decls ( x : tuple_sort ) = let n = get_num_fields x in - let f i = ((new func_decl x#gc)#cnstr_obj (Z3native.get_tuple_sort_field_decl x#gnc x#gno i)) in + let f i = FuncDecl.create (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in Array.init n f end (** Functions to manipulate arithmetic expressions *) -module Arithmetic = -struct +and Arithmetic : +sig + type arith_sort = ArithSort of Sort.sort + type int_sort = IntSort of Sort.sort + type real_sort = RealSort of Sort.sort + + type arith_expr = Expr of Expr.expr + type int_expr = IntExpr of arith_expr + type real_expr = RealExpr of arith_expr + + type int_num = IntNum of int_expr + type rat_num = RatNum of real_expr + type algebraic_num = AlgebraicNum of arith_expr + + + val create_arith_expr : context -> Z3native.ptr -> arith_expr + val create_int_expr : context -> Z3native.ptr -> int_expr + val create_real_expr : context -> Z3native.ptr -> real_expr + val create_int_num : context -> Z3native.ptr -> int_num + val create_rat_num : context -> Z3native.ptr -> rat_num + val create_algebraic_num : context -> Z3native.ptr -> algebraic_num +end = struct + type arith_sort = ArithSort of Sort.sort + type int_sort = IntSort of Sort.sort + type real_sort = RealSort of Sort.sort + + type arith_expr = ArithExpr of Expr.expr + type int_expr = IntExpr of arith_expr + type real_expr = RealExpr of arith_expr + + type int_num = IntNum of int_expr + type rat_num = RatNum of real_expr + type algebraic_num = AlgebraicNum of arith_expr + + let create_arith_expr ( ctx : context ) ( no : Z3native.ptr ) = + ArithExpr(Expr.create ctx no) + + let create_int_expr ( ctx : context ) ( no : Z3native.ptr ) = + IntExpr(create_arith_expr ctx no) + + let create_real_expr ( ctx : context ) ( no : Z3native.ptr ) = + RealExpr(create_arith_expr ctx no) + + let create_int_num ( ctx : context ) ( no : Z3native.ptr ) = + IntNum(create_int_expr ctx no) + + let create_rat_num ( ctx : context ) ( no : Z3native.ptr ) = + RatNum(create_real_expr ctx no) + (** Create a new integer sort. *) let mk_int_sort ( ctx : context ) = - (new int_sort ctx)#cnstr_obj (Z3native.mk_int_sort (context_gno ctx)) + (new int_sort ctx)#create_obj (Z3native.mk_int_sort (context_gno ctx)) (** Create a real sort. *) let mk_real_sort ( ctx : context ) = - (new real_sort ctx)#cnstr_obj (Z3native.mk_real_sort (context_gno ctx)) + (new real_sort ctx)#create_obj (Z3native.mk_real_sort (context_gno ctx)) (** Indicates whether the term is of integer sort. @@ -2802,11 +2820,11 @@ struct (** The numerator of a rational numeral. *) let get_numerator ( x : rat_num ) = - (new int_num x#gc)#cnstr_obj (Z3native.get_numerator x#gnc x#gno) + (new int_num x#gc)#create_obj (Z3native.get_numerator x#gnc x#gno) (** The denominator of a rational numeral. *) let get_denominator ( x : rat_num ) = - (new int_num x#gc)#cnstr_obj (Z3native.get_denominator x#gnc x#gno) + (new int_num x#gc)#create_obj (Z3native.get_denominator x#gnc x#gno) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -2844,75 +2862,92 @@ struct Create an expression representing t[0] + t[1] + .... *) let mk_add ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) (** Create an expression representing t[0] * t[1] * .... *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) (** Create an expression representing t[0] - t[1] - .... *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (astaton t)) :> arith_expr) + (create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) (** Create an expression representing -t. *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - (create_expr ctx (Z3native.mk_unary_minus (context_gno ctx) t#gno) :> arith_expr) + ArithExpr(create ctx (Z3native.mk_unary_minus (context_gno ctx) + (gno (match t with ArithExpr(b) -> b)))) (** Create an expression representing t1 / t2. *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - (create_expr ctx (Z3native.mk_div (context_gno ctx) t1#gno t2#gno) :> arith_expr) + ArithExpr(create ctx (Z3native.mk_div (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 mod t2. The arguments must have int type. *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_mod (context_gno ctx) t1#gno t2#gno) + IntExpr(create ctx (Z3native.mk_mod (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 rem t2. The arguments must have int type. *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_rem (context_gno ctx) t1#gno t2#gno) + IntExpr(create ctx (Z3native.mk_rem (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 ^ t2. *) - let mk_Power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (create_expr ctx (Z3native.mk_power (context_gno ctx) t1#gno t2#gno) :> arith_expr) + let mk_power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + ArithExpr(create_expr ctx (Z3native.mk_power (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 < t2 *) let mk_lt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_lt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_lt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 <= t2 *) let mk_le ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_le (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_le (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 > t2 *) let mk_gt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_gt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_gt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an expression representing t1 >= t2 *) let mk_ge ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_ge (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_ge (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Coerce an integer to a real. @@ -2925,7 +2960,8 @@ struct The argument must be of integer sort. *) let mk_int2real ( ctx : context ) ( t : int_expr ) = - (new real_expr ctx)#cnstr_obj (Z3native.mk_int2real (context_gno ctx) t#gno) + RealExpr(create (Z3native.mk_int2real (context_gno ctx) + (gno (match t with BoolExpr(b) -> b)))) (** Coerce a real to an integer. @@ -2935,14 +2971,14 @@ struct The argument must be of real sort. *) let mk_real2int ( ctx : context ) ( t : real_expr ) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_real2int (context_gno ctx) t#gno) + (new int_expr ctx)#create_obj (Z3native.mk_real2int (context_gno ctx) t#gno) (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_is_int (context_gno ctx) t#gno) - + BoolExpr(create ctx (Z3native.mk_is_int (context_gno ctx) + (gno (match t with BoolExpr(b) -> b)))) (** Return a upper bound for a given real algebraic number. The interval isolating the number is smaller than 1/10^. @@ -2951,7 +2987,7 @@ struct @return A numeral Expr of sort Real *) let to_upper ( x : algebraic_num ) ( precision : int ) = - (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) + (new rat_num x#gc)#create_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) (** Return a lower bound for the given real algebraic number. @@ -2961,7 +2997,7 @@ struct @return A numeral Expr of sort Real *) let to_lower ( x : algebraic_num ) precision = - (new rat_num x#gc)#cnstr_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) + (new rat_num x#gc)#create_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -2981,7 +3017,7 @@ struct raise (Z3native.Exception "Denominator is zero") else - (new rat_num ctx)#cnstr_obj (Z3native.mk_real (context_gno ctx) num den) + (new rat_num ctx)#create_obj (Z3native.mk_real (context_gno ctx) num den) (** Create a real numeral. @@ -2989,7 +3025,7 @@ struct @return A Term with value and sort Real *) let mk_real_numeral_s ( ctx : context ) ( v : string ) = - (new rat_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_real_sort ctx)#gno) + (new rat_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_real_sort ctx)#gno) (** Create a real numeral. @@ -2998,14 +3034,14 @@ struct @return A Term with value and sort Real *) let mk_real_numeral_i ( ctx : context ) ( v : int ) = - (new rat_num ctx)#cnstr_obj (Z3native.mk_int (context_gno ctx) v (mk_real_sort ctx)#gno) + (new rat_num ctx)#create_obj (Z3native.mk_int (context_gno ctx) v (mk_real_sort ctx)#gno) (** Create an integer numeral. @param v A string representing the Term value in decimal notation. *) let mk_int_numeral_s ( ctx : context ) ( v : string ) = - (new int_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_int_sort ctx)#gno) + (new int_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_int_sort ctx)#gno) (** Create an integer numeral. @@ -3013,7 +3049,7 @@ struct @return A Term with value and sort Integer *) let mk_int_numeral_i ( ctx : context ) ( v : int ) = - (new int_num ctx)#cnstr_obj (Z3native.mk_int (context_gno ctx) v (mk_int_sort ctx)#gno) + (new int_num ctx)#create_obj (Z3native.mk_int (context_gno ctx) v (mk_int_sort ctx)#gno) (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno @@ -3021,13 +3057,30 @@ end (** Functions to manipulate bit-vector expressions *) -module BitVectors = -struct +and BitVectors : +sig + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val create_expr : context -> Z3native.ptr -> bitvec_expr + val create_num : context -> Z3native.ptr -> bitvec_num +end = struct + type bitvec_expr = Expr of Expr.expr + type bitvec_num = BitVecExpr of bitvec_expr + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let e = (Expr.create ctx no) in + BitVecExpr(e) + + let create_num ( ctx : context ) ( no : Z3native.ptr ) = + let e = (create_expr ctx no) in + BitVecNum(e) + (** Create a new bit-vector sort. *) let mk_sort ( ctx : context ) size = - (new bitvec_sort ctx)#cnstr_obj (Z3native.mk_bv_sort (context_gno ctx) size) + (new bitvec_sort ctx)#create_obj (Z3native.mk_bv_sort (context_gno ctx) size) (** Indicates whether the terms is of bit-vector sort. @@ -3328,91 +3381,91 @@ struct The argument must have a bit-vector sort. *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnot (context_gno ctx) t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnot (context_gno ctx) t#gno) (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredand (context_gno ctx) t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvredand (context_gno ctx) t#gno) (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvredor (context_gno ctx) t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvredor (context_gno ctx) t#gno) (** Bitwise conjunction. The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvand (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvand (context_gno ctx) t1#gno t2#gno) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvor (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvor (context_gno ctx) t1#gno t2#gno) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxor (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvxor (context_gno ctx) t1#gno t2#gno) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnand (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnand (context_gno ctx) t1#gno t2#gno) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvnor (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnor (context_gno ctx) t1#gno t2#gno) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvxnor (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvxnor (context_gno ctx) t1#gno t2#gno) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvneg (context_gno ctx) t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvneg (context_gno ctx) t#gno) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvadd (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvadd (context_gno ctx) t1#gno t2#gno) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsub (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsub (context_gno ctx) t1#gno t2#gno) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvmul (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvmul (context_gno ctx) t1#gno t2#gno) (** Unsigned division. @@ -3424,7 +3477,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvudiv (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvudiv (context_gno ctx) t1#gno t2#gno) (** Signed division. @@ -3439,7 +3492,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsdiv (context_gno ctx) t1#gno t2#gno) (** Unsigned remainder. @@ -3449,7 +3502,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvurem (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvurem (context_gno ctx) t1#gno t2#gno) (** Signed remainder. @@ -3461,7 +3514,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsrem (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsrem (context_gno ctx) t1#gno t2#gno) (** Two's complement signed remainder (sign follows divisor). @@ -3470,7 +3523,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvsmod (context_gno ctx) t1#gno t2#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsmod (context_gno ctx) t1#gno t2#gno) (** Unsigned less-than @@ -3478,7 +3531,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvult (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvult (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Two's complement signed less-than @@ -3486,7 +3541,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvslt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvslt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Unsigned less-than or equal to. @@ -3494,7 +3551,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvule (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvule (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Two's complement signed less-than or equal to. @@ -3502,7 +3561,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsle (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvsle (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Unsigned greater than or equal to. @@ -3510,7 +3571,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvuge (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvuge (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Two's complement signed greater than or equal to. @@ -3518,7 +3581,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_SGE ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsge (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvsge (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Unsigned greater-than. @@ -3526,7 +3591,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvugt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvugt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Two's complement signed greater-than. @@ -3534,7 +3601,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsgt (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvsgt (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Bit-vector concatenation. @@ -3545,7 +3614,9 @@ struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_concat (context_gno ctx) t1#gno t2#gno) + BitVectors.BitVecExpr(create ctx (Z3native.mk_concat (context_gno ctx) + (gno (match t1 with BitVecExpr(b) -> b)) + (gno (match t2 with BitVecExpr(b) -> b)))) (** Bit-vector extraction. @@ -3556,7 +3627,7 @@ struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_extract (context_gno ctx) high low t#gno) + (new bitvec_expr ctx)#create_obj (Z3native.mk_extract (context_gno ctx) high low t#gno) (** Bit-vector sign extension. @@ -3566,7 +3637,7 @@ struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_sign_ext (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_sign_ext (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) (** Bit-vector zero extension. @@ -3577,7 +3648,7 @@ struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_zero_ext (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_zero_ext (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) (** Bit-vector repetition. @@ -3585,7 +3656,7 @@ struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_repeat (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_repeat (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) (** Shift left. @@ -3600,7 +3671,9 @@ struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvshl (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_bvshl (context_gno ctx) + (gno (match t1 with BitVecExpr(b) -> b)) + (gno (match t2 with BitVecExpr(b) -> b)))) (** Logical shift right @@ -3614,7 +3687,9 @@ struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvlshr (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_bvlshr (context_gno ctx) + (gno (match t1 with BitVecExpr(b) -> b)) + (gno (match t2 with BitVecExpr(b) -> b)))) (** Arithmetic shift right @@ -3630,7 +3705,9 @@ struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_bvashr (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_bvashr (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Rotate Left. @@ -3639,7 +3716,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_left (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_rotate_left (context_gno ctx) i (gno (match t with BoolExpr(b) -> b)))) (** Rotate Right. @@ -3648,7 +3725,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_rotate_right (context_gno ctx) i t#gno) + BitVecExpr(create ctx (Z3native.mk_rotate_right (context_gno ctx) i (gno (match t with BoolExpr(b) -> b)))) (** Rotate Left. @@ -3657,7 +3734,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_left (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_ext_rotate_left (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Rotate Right. @@ -3667,7 +3746,9 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_ext_rotate_right (context_gno ctx) t1#gno t2#gno) + BitVecExpr(create ctx (Z3native.mk_ext_rotate_right (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create an bit bit-vector from the integer argument . @@ -3680,7 +3761,7 @@ struct The argument must be of integer sort. *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - (new bitvec_expr ctx)#cnstr_obj (Z3native.mk_int2bv (context_gno ctx) n t#gno) + BitVecExpr(create ctx (Z3native.mk_int2bv (context_gno ctx) n (gno (match t with IntExpr(b) -> b)))) (** Create an integer from the bit-vector argument . @@ -3698,7 +3779,7 @@ struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = - (new int_expr ctx)#cnstr_obj (Z3native.mk_bv2int (context_gno ctx) t#gno signed) + (new int_expr ctx)#create_obj (Z3native.mk_bv2int (context_gno ctx) t#gno signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3706,7 +3787,10 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_overflow (context_gno ctx) t1#gno t2#gno signed) + BoolExpr(create ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)) + signed)) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3714,23 +3798,30 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvadd_no_underflow (context_gno ctx) t1#gno t2#gno) - + BoolExpr(create ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) + (** Create a predicate that checks that the bit-wise subtraction does not overflow. The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_overflow (context_gno ctx) t1#gno t2#gno) - + BoolExpr(create ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) + (** Create a predicate that checks that the bit-wise subtraction does not underflow. The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsub_no_underflow (context_gno ctx) t1#gno t2#gno signed) + BoolExpr(create ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)) + signed)) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3738,7 +3829,9 @@ struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create a predicate that checks that the bit-wise negation does not overflow. @@ -3746,7 +3839,7 @@ struct The arguments must be of bit-vector sort. *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvneg_no_overflow (context_gno ctx) t#gno) + BoolExpr(create ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (gno (match t with BitVecExpr(b) -> b)))) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3754,7 +3847,10 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_overflow (context_gno ctx) t1#gno t2#gno signed) + BoolExpr(create ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)) + signed)) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3762,7 +3858,9 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bool_expr ctx)#cnstr_obj (Z3native.mk_bvmul_no_underflow (context_gno ctx) t1#gno t2#gno) + BoolExpr(create ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) + (gno (match t1 with BoolExpr(b) -> b)) + (gno (match t2 with BoolExpr(b) -> b)))) (** Create a bit-vector numeral. @@ -3771,12 +3869,13 @@ struct @param size the size of the bit-vector *) let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = - (new bitvec_num ctx)#cnstr_obj (Z3native.mk_numeral (context_gno ctx) v (mk_sort ctx size)#gno) + (new bitvec_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_sort ctx size)#gno) end (** Functions to manipulate proof expressions *) -module Proofs = -struct +and Proofs : +sig +end = struct (** Indicates whether the term is a Proof for the expression 'true'. *) @@ -4259,13 +4358,13 @@ struct type goal = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : goal = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.goal_inc_ref ; dec_ref = Z3native.goal_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4318,7 +4417,7 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in + let f i = (new bool_expr (z3obj_gc x))#create_obj (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) @@ -4334,7 +4433,7 @@ struct (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = - cnstr to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) let simplify ( x : goal ) ( p : Params.params option ) = @@ -4352,7 +4451,7 @@ struct Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; Z3native.tactic_dec_ref (z3obj_gnc x) tn ; - cnstr (z3obj_gc x) res + create (z3obj_gc x) res (** @@ -4365,7 +4464,7 @@ struct @param proofs Indicates whether proof generation should be enabled. *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - cnstr ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) + create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) @@ -4380,13 +4479,13 @@ struct type model = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : model = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.model_inc_ref ; dec_ref = Z3native.model_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4400,13 +4499,13 @@ struct type func_interp = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_interp = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.func_interp_inc_ref ; dec_ref = Z3native.func_interp_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4419,13 +4518,13 @@ struct type func_entry = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_entry = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.func_entry_inc_ref ; dec_ref = Z3native.func_entry_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4467,7 +4566,7 @@ struct *) let get_entries ( x : func_interp ) = let n = (get_num_entries x) in - let f i = (FuncEntry.cnstr (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** @@ -4534,11 +4633,11 @@ struct raise (Z3native.Exception "Argument was not an array constant") else let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x ((new func_decl f#gc)#cnstr_obj fd) + get_func_interp x ((new func_decl f#gc)#create_obj fd) | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); else let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) f#gno) in - if (Z3native.is_null n) then None else Some (FuncInterp.cnstr (z3obj_gc x) n) + if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) (** The number of constants that have an interpretation in the model. *) let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) @@ -4546,7 +4645,7 @@ struct (** The function declarations of the constants in the model. *) let get_const_decls ( x : model ) = let n = (get_num_consts x) in - let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f @@ -4556,15 +4655,15 @@ struct (** The function declarations of the function interpretations in the model. *) let get_func_decls ( x : model ) = let n = (get_num_consts x) in - let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** All symbols that have an interpretation in the model. *) let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in - let f i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = (new func_decl (z3obj_gc x))#cnstr_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.append (Array.init n_funcs f) (Array.init n_consts g) (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) @@ -4619,7 +4718,7 @@ struct An array of expressions, where each is an element of the universe of *) let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in + let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in Array.init n f @@ -4644,13 +4743,13 @@ struct type probe = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : probe = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.probe_inc_ref ; dec_ref = Z3native.probe_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4686,48 +4785,48 @@ struct Creates a new Probe. *) let mk_probe ( ctx : context ) ( name : string ) = - (cnstr ctx (Z3native.mk_probe (context_gno ctx) name)) + (create ctx (Z3native.mk_probe (context_gno ctx) name)) (** Create a probe that always evaluates to . *) let const ( ctx : context ) ( v : float ) = - (cnstr ctx (Z3native.probe_const (context_gno ctx) v)) + (create ctx (Z3native.probe_const (context_gno ctx) v)) (** Create a probe that evaluates to "true" when the value returned by is less than the value returned by *) let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value returned by is greater than the value returned by *) let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value returned by is less than or equal the value returned by *) let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value returned by is greater than or equal the value returned by *) let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value returned by is equal to the value returned by *) let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value @@ -4735,7 +4834,7 @@ struct *) (* CMW: and is a keyword *) let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value @@ -4743,7 +4842,7 @@ struct *) (* CMW: or is a keyword *) let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (cnstr ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) (** Create a probe that evaluates to "true" when the value @@ -4751,7 +4850,7 @@ struct *) (* CMW: is not a keyword? *) let not_ ( ctx : context ) ( p : probe ) = - (cnstr ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) + (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) end @@ -4767,13 +4866,13 @@ struct type tactic = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : tactic = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.tactic_inc_ref ; dec_ref = Z3native.tactic_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4786,13 +4885,13 @@ struct type apply_result = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : apply_result = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.apply_result_inc_ref ; dec_ref = Z3native.apply_result_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -4803,19 +4902,19 @@ struct (** Retrieves the subgoals from the apply_result. *) let get_subgoals ( x : apply_result ) = let n = (get_num_subgoals x) in - let f i = Goal.cnstr (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in + let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** Retrieves the subgoals from the apply_result. *) let get_subgoal ( x : apply_result ) ( i : int ) = - Goal.cnstr (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) + Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) (** 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 *) let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = - Model.cnstr (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) + Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) (** A string representation of the ApplyResult. *) let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) @@ -4826,13 +4925,13 @@ struct (** Retrieves parameter descriptions for Tactics. *) let get_param_descrs ( x : tactic ) = - Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.create (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Apply the tactic to the goal. *) let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = match p with - | None -> (ApplyResult.cnstr (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) - | Some (pn) -> (ApplyResult.cnstr (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) + | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) + | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) (** The number of supported tactics. @@ -4858,7 +4957,7 @@ struct Creates a new Tactic. *) let mk_tactic ( ctx : context ) ( name : string ) = - cnstr ctx (Z3native.mk_tactic (context_gno ctx) name) + create ctx (Z3native.mk_tactic (context_gno ctx) name) (** Create a tactic that applies to a Goal and @@ -4870,17 +4969,17 @@ struct | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in match (Array.fold_left f None ts) with | None -> - cnstr ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) | Some(x) -> let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in - cnstr ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) + create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) (** Create a tactic that first applies to a Goal and if it fails then returns the result of applied to the Goal. *) let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - cnstr ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) (** Create a tactic that applies to a goal for milliseconds. @@ -4888,7 +4987,7 @@ struct If does not terminate within milliseconds, then it fails. *) let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - cnstr ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) + create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) (** Create a tactic that applies to a given goal if the probe @@ -4898,52 +4997,52 @@ struct *) (* CMW: when is a keyword *) let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = - cnstr ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) + create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = - cnstr ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) + create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) (** Create a tactic that keeps applying until the goal is not modified anymore or the maximum number of iterations is reached. *) let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - cnstr ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) + create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) (** Create a tactic that just returns the given goal. *) let skip ( ctx : context ) = - cnstr ctx (Z3native.tactic_skip (context_gno ctx)) + create ctx (Z3native.tactic_skip (context_gno ctx)) (** Create a tactic always fails. *) let fail ( ctx : context ) = - cnstr ctx (Z3native.tactic_fail (context_gno ctx)) + create ctx (Z3native.tactic_fail (context_gno ctx)) (** Create a tactic that fails if the probe evaluates to false. *) let fail_if ( ctx : context ) ( p : Probe.probe ) = - cnstr ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) + create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) or trivially unsatisfiable (i.e., contains `false'). *) let fail_if_not_decided ( ctx : context ) = - cnstr ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) + create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) (** Create a tactic that applies using the given set of parameters . *) let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = - cnstr ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) + create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) (** Create a tactic that applies using the given set of parameters . @@ -4956,14 +5055,14 @@ struct Create a tactic that applies the given tactics in parallel. *) let par_or ( ctx : context ) ( t : tactic array ) = - cnstr ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) + create ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) (** Create a tactic that applies to a given goal and then to every subgoal produced by . The subgoals are processed in parallel. *) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - cnstr ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) (** Interrupt the execution of a Z3 procedure. @@ -4980,13 +5079,13 @@ struct type solver = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : solver = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.solver_inc_ref ; dec_ref = Z3native.solver_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -5003,13 +5102,13 @@ struct type statistics = z3_native_object (**/**) - let cnstr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : statistics = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.stats_inc_ref ; dec_ref = Z3native.stats_dec_ref } in (z3obj_sno res ctx no) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -5028,7 +5127,7 @@ struct mutable m_float : float } (**/**) - let cnstr_si k v = + let create_si k v = let res : statistics_entry = { m_key = k ; m_is_int = true ; @@ -5038,7 +5137,7 @@ struct } in res - let cnstr_sd k v = + let create_sd k v = let res : statistics_entry = { m_key = k ; m_is_int = false ; @@ -5089,9 +5188,9 @@ struct let f i = ( let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then - (Entry.cnstr_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - (Entry.cnstr_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in Array.init n f @@ -5126,7 +5225,7 @@ struct Retrieves parameter descriptions for solver. *) let get_param_descrs ( x : solver ) = - Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.create (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** The current number of backtracking points (scopes). @@ -5200,7 +5299,7 @@ struct The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) @@ -5208,9 +5307,9 @@ struct The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in - let f i = ((new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get a i)#gno) in + let f i = ((new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get a i)#gno) in Array.init n f (** @@ -5225,7 +5324,7 @@ struct if ((Array.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (astaton assumptions)) + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (AST.aton assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -5243,7 +5342,7 @@ struct if (Z3native.is_null q) then None else - Some (Model.cnstr (z3obj_gc x) q) + Some (Model.create (z3obj_gc x) q) (** The proof of the last Check. @@ -5266,7 +5365,7 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.cnstr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f @@ -5281,7 +5380,7 @@ struct Solver statistics. *) let get_statistics ( x : solver ) = - (Statistics.cnstr (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) + (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) (** Creates a new (incremental) solver. @@ -5292,8 +5391,8 @@ struct *) let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = match logic with - | None -> (cnstr ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (cnstr ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) + | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) + | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) (** Creates a new (incremental) solver. @@ -5306,7 +5405,7 @@ struct Creates a new (incremental) solver. *) let mk_simple_solver ( ctx : context ) = - (cnstr ctx (Z3native.mk_simple_solver (context_gno ctx))) + (create ctx (Z3native.mk_simple_solver (context_gno ctx))) (** Creates a solver that is implemented using the given tactic. @@ -5315,7 +5414,7 @@ struct will always solve each check from scratch. *) let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = - (cnstr ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) + (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) (** A string representation of the solver. @@ -5330,13 +5429,13 @@ struct type fixedpoint = z3_native_object (**/**) - let cnstr ( ctx : context ) = + let create ( ctx : context ) = let res : fixedpoint = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.fixedpoint_inc_ref ; dec_ref = Z3native.fixedpoint_dec_ref } in (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; - (z3obj_cnstr res) ; + (z3obj_create res) ; res (**/**) @@ -5356,7 +5455,7 @@ struct Retrieves parameter descriptions for Fixedpoint solver. *) let get_param_descrs ( x : fixedpoint ) = - Params.ParamDescrs.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.create (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Assert a constraints into the fixedpoint solver. @@ -5487,30 +5586,30 @@ struct Convert benchmark given as set of axioms, rules and queries to a string. *) let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (astaton queries) + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (AST.aton queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in + let f i = (new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get v i)#gno in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.cnstr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr (z3obj_gc x))#cnstr_obj (AST.ASTVector.get v i)#gno in + let f i = (new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get v i)#gno in Array.init n f (** Create a Fixedpoint context. *) - let mk_fixedpoint ( ctx : context ) = cnstr ctx + let mk_fixedpoint ( ctx : context ) = create ctx end (** Global and context options @@ -5590,7 +5689,7 @@ struct *) let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (astaton assumptions) + (Array.length assumptions) (AST.aton assumptions) formula#gno (** @@ -5613,7 +5712,7 @@ struct Z3native.parse_smtlib_string (context_gno ctx) str cs (Symbol.aton sort_names) - (astaton sorts) + (AST.aton sorts) cd (Symbol.aton decl_names) (func_declaton decls) @@ -5633,7 +5732,7 @@ struct Z3native.parse_smtlib_file (context_gno ctx) file_name cs (Symbol.aton sort_names) - (astaton sorts) + (AST.aton sorts) cd (Symbol.aton decl_names) (func_declaton decls) @@ -5675,7 +5774,7 @@ struct *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in - let f i = (new func_decl ctx)#cnstr_obj (Z3native.get_smtlib_decl (context_gno ctx) i) in + let f i = (new func_decl ctx)#create_obj (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f (** @@ -5708,7 +5807,7 @@ struct Z3native.parse_smtlib2_string (context_gno ctx) str cs (Symbol.aton sort_names) - (astaton sorts) + (Sort.aton sorts) cd (Symbol.aton decl_names) (func_declaton decls) @@ -5728,7 +5827,7 @@ struct Z3native.parse_smtlib2_string (context_gno ctx) file_name cs (Symbol.aton sort_names) - (astaton sorts) + (Sort.aton sorts) cd (Symbol.aton decl_names) (func_declaton decls) From 12afbfe6dbc5a74f5fd036bd3c97e20a25a4fcdf Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 4 Feb 2013 23:18:55 +0000 Subject: [PATCH 170/248] Checkpoint. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 643 ++++++++++++++++++++++++++--------------------- 1 file changed, 355 insertions(+), 288 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 0e47912ae..58c319d4d 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1097,6 +1097,7 @@ sig val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val get_func_decl : expr -> FuncDecl.func_decl + val is_numeral : expr -> bool end = struct type expr = Expr of AST.ast @@ -1107,20 +1108,20 @@ end = struct let s = Z3native.get_sort (context_gno ctx) obj in let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in if (Z3native.is_algebraic_number (context_gno ctx) obj) then - (match (Arithmetic.create_algebraic_num ctx obj) with Arithmetic.AlgebraicNum(Arithmetic.Expr(e)) -> e) + (match (Arithmetic.AlgebraicNumbers.create_num ctx obj) with Arithmetic.AlgebraicNumbers.AlgebraicNum(Arithmetic.Expr(e)) -> e) else if (Z3native.is_numeral_ast (context_gno ctx) obj) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with - | INT_SORT -> (match (Arithmetic.create_int_num ctx obj) with Arithmetic.IntNum(Arithmetic.IntExpr(Arithmetic.Expr(e))) -> e) - | REAL_SORT -> (match (Arithmetic.create_rat_num ctx obj) with Arithmetic.RatNum(Arithmetic.RealExpr(Arithmetic.Expr(e))) -> e) + | INT_SORT -> (match (Arithmetic.Integers.create_num ctx obj) with Arithmetic.Integers.IntNum(Arithmetic.Integers.IntExpr(Arithmetic.Expr(e))) -> e) + | REAL_SORT -> (match (Arithmetic.Reals.create_num ctx obj) with Arithmetic.Reals.RatNum(Arithmetic.Reals.RealExpr(Arithmetic.Expr(e))) -> e) | BV_SORT -> (match (BitVectors.create_num ctx obj) with BitVectors.BitVecNum(BitVectors.BitVecExpr(e)) -> e) | _ -> raise (Z3native.Exception "Unsupported numeral object") else match sk with - | BOOL_SORT -> (match (Booleans.create ctx obj) with Booleans.BoolExpr(e) -> e) - | INT_SORT -> (match (Arithmetic.create_int_expr ctx obj) with Arithmetic.IntExpr(Arithmetic.Expr(e)) -> e) - | REAL_SORT -> (match (Arithmetic.create_real_expr ctx obj) with Arithmetic.RealExpr(Arithmetic.Expr(e)) -> e) + | BOOL_SORT -> (match (Booleans.create_expr ctx obj) with Booleans.BoolExpr(e) -> e) + | INT_SORT -> (match (Arithmetic.Integers.create_expr ctx obj) with Arithmetic.Integers.IntExpr(Arithmetic.Expr(e)) -> e) + | REAL_SORT -> (match (Arithmetic.Reals.create_expr ctx obj) with Arithmetic.Reals.RealExpr(Arithmetic.Expr(e)) -> e) | BV_SORT -> (match (BitVectors.create_expr ctx obj) with BitVectors.BitVecExpr(e) -> e) | ARRAY_SORT -> (match (Arrays.create_expr ctx obj) with Arrays.ArrayExpr(e) -> e) | DATATYPE_SORT -> (match (Datatypes.create_expr ctx obj) with Datatypes.DatatypeExpr(e) -> e) @@ -1406,16 +1407,20 @@ sig type bool_expr = BoolExpr of Expr.expr type bool_sort = BoolSort of Sort.sort - val create : context -> Z3native.ptr -> bool_expr + val create_expr : context -> Z3native.ptr -> bool_expr + val create_sort : context -> Z3native.ptr -> bool_sort val aton : bool_expr array -> Z3native.ptr array end = struct type bool_expr = BoolExpr of Expr.expr type bool_sort = BoolSort of Sort.sort - let create ( ctx : context ) ( no : Z3native.ptr ) = + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = let a = (AST.create ctx no) in BoolExpr(Expr.Expr(a)) + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + BoolSort(Sort.create ctx no) + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gc e) let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gnc e) let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gno e) @@ -1444,13 +1449,13 @@ end = struct The true Term. *) let mk_true ( ctx : context ) = - create ctx (Z3native.mk_true (context_gno ctx)) + create_expr ctx (Z3native.mk_true (context_gno ctx)) (** The false Term. *) let mk_false ( ctx : context ) = - create ctx (Z3native.mk_false (context_gno ctx)) + create_expr ctx (Z3native.mk_false (context_gno ctx)) (** Creates a Boolean value. @@ -1462,19 +1467,19 @@ end = struct Creates the equality = . *) let mk_eq ( ctx : context ) ( x : Expr.expr ) ( y : Expr.expr ) = - create ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + create_expr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) (** Creates a distinct term. *) let mk_distinct ( ctx : context ) ( args : Expr.expr array ) = - create ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (Expr.aton args)) + create_expr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (Expr.aton args)) (** Mk an expression representing not(a). *) let mk_not ( ctx : context ) ( a : bool_expr ) = - create ctx (Z3native.mk_not (context_gno ctx) (gno a)) + create_expr ctx (Z3native.mk_not (context_gno ctx) (gno a)) (** Create an expression representing an if-then-else: ite(t1, t2, t3). @@ -1483,36 +1488,36 @@ end = struct @param t3 An expression with the same sort as *) let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - create ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + create_expr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) (** Create an expression representing t1 iff t2. *) let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + create_expr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing t1 -> t2. *) let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + create_expr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing t1 xor t2. *) let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + create_expr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing the AND of args *) let mk_and ( ctx : context ) ( args : bool_expr array ) = - create ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (aton args)) + create_expr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (aton args)) (** Create an expression representing the OR of args *) let mk_or ( ctx : context ) ( args : bool_expr array ) = - create ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (aton args)) + create_expr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (aton args)) end (** Quantifier expressions *) @@ -1676,7 +1681,7 @@ end = struct The body of the quantifier. *) let get_body ( x : quantifier ) = - Booleans.create (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) + Booleans.create_expr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) (** Creates a new bound variable. @@ -2643,416 +2648,478 @@ end and Arithmetic : sig type arith_sort = ArithSort of Sort.sort - type int_sort = IntSort of Sort.sort - type real_sort = RealSort of Sort.sort - type arith_expr = Expr of Expr.expr - type int_expr = IntExpr of arith_expr - type real_expr = RealExpr of arith_expr - - type int_num = IntNum of int_expr - type rat_num = RatNum of real_expr - type algebraic_num = AlgebraicNum of arith_expr - - val create_arith_expr : context -> Z3native.ptr -> arith_expr - val create_int_expr : context -> Z3native.ptr -> int_expr - val create_real_expr : context -> Z3native.ptr -> real_expr - val create_int_num : context -> Z3native.ptr -> int_num - val create_rat_num : context -> Z3native.ptr -> rat_num - val create_algebraic_num : context -> Z3native.ptr -> algebraic_num + val create_expr : context -> Z3native.ptr -> arith_expr + val aton : arith_expr array -> Z3native.ptr array + + module Integers : sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val create_sort : context -> Z3native.ptr -> int_sort + val create_expr : context -> Z3native.ptr -> int_expr + val create_num : context -> Z3native.ptr -> int_num + end + + module Reals : sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val create_sort : context -> Z3native.ptr -> real_sort + val create_expr : context -> Z3native.ptr -> real_expr + val create_num : context -> Z3native.ptr -> rat_num + end + + module AlgebraicNumbers : sig + type algebraic_num = AlgebraicNum of arith_expr + + val create_num : context -> Z3native.ptr -> algebraic_num + end + end = struct type arith_sort = ArithSort of Sort.sort - type int_sort = IntSort of Sort.sort - type real_sort = RealSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - type int_expr = IntExpr of arith_expr - type real_expr = RealExpr of arith_expr - - type int_num = IntNum of int_expr - type rat_num = RatNum of real_expr - type algebraic_num = AlgebraicNum of arith_expr let create_arith_expr ( ctx : context ) ( no : Z3native.ptr ) = ArithExpr(Expr.create ctx no) - let create_int_expr ( ctx : context ) ( no : Z3native.ptr ) = - IntExpr(create_arith_expr ctx no) + let create_arith_sort ( ctx : context ) ( no : Z3native.ptr ) = + ArithSort(Sort.create ctx no) - let create_real_expr ( ctx : context ) ( no : Z3native.ptr ) = - RealExpr(create_arith_expr ctx no) + let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gc s) + let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gnc s) + let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gno s) + let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gc e) + let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) + let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) - let create_int_num ( ctx : context ) ( no : Z3native.ptr ) = - IntNum(create_int_expr ctx no) - let create_rat_num ( ctx : context ) ( no : Z3native.ptr ) = - RatNum(create_real_expr ctx no) - - (** - Create a new integer sort. - *) - let mk_int_sort ( ctx : context ) = - (new int_sort ctx)#create_obj (Z3native.mk_int_sort (context_gno ctx)) + module rec Integers : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr - (** - Create a real sort. - *) - let mk_real_sort ( ctx : context ) = - (new real_sort ctx)#create_obj (Z3native.mk_real_sort (context_gno ctx)) + val create_sort : context -> Z3native.ptr -> int_sort + val create_expr : context -> Z3native.ptr -> int_expr + val create_num : context -> Z3native.ptr -> int_num + end = struct + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + IntSort(create_arith_sort ctx no) + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + IntExpr(create_arith_expr ctx no) + + let create_num ( ctx : context ) ( no : Z3native.ptr ) = + IntNum(create_expr ctx no) + + let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) + let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) + let sgno ( x : int_sort ) = match (x) with IntSort(s) -> (sgno s) + let egc ( x : int_expr ) = match (x) with IntExpr(e) -> (egc e) + let egnc ( x : int_expr ) = match (x) with IntExpr(e) -> (egnc e) + let egno ( x : int_expr ) = match (x) with IntExpr(e) -> (egno e) + let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) + let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) + let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) + + (** Create a new integer sort. *) + let mk_sort ( ctx : context ) = + create_sort ctx (Z3native.mk_int_sort (context_gno ctx)) + + (** Retrieve the int value. *) + let get_int ( x : int_num ) = + let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + if r then v + else raise (Z3native.Exception "Conversion failed.") + + (** Returns a string representation of the numeral. *) + let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + + (** + Creates an integer constant. + *) + let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) + + (** + Creates an integer constant. + *) + let mk_int_const_s ( ctx : context ) ( name : string ) = + mk_int_const ctx (Symbol.mk_string ctx name) + + (** + Create an expression representing t1 mod t2. + The arguments must have int type. + *) + let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + create_expr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + + (** + Create an expression representing t1 rem t2. + The arguments must have int type. + *) + let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + create_expr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + + (** + Create an integer numeral. + @param v A string representing the Term value in decimal notation. + *) + let mk_int_numeral_s ( ctx : context ) ( v : string ) = + create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + + (** + Create an integer numeral. + @param v value of the numeral. + @return A Term with value and sort Integer + *) + let mk_int_numeral_i ( ctx : context ) ( v : int ) = + create_num ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + + (** + 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. + *) + let mk_int2real ( ctx : context ) ( t : int_expr ) = + Reals.create_expr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)) + end + + and Reals : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val create_sort : context -> Z3native.ptr -> real_sort + val create_expr : context -> Z3native.ptr -> real_expr + val create_num : context -> Z3native.ptr -> rat_num + end = struct + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + RealSort(create_arith_sort ctx no) + + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + RealExpr(create_arith_expr ctx no) + + let create_num ( ctx : context ) ( no : Z3native.ptr ) = + RatNum(create_expr ctx no) + + let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) + let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) + let sgno ( x : real_sort ) = match (x) with RealSort(s) -> (sgno s) + let egc ( x : real_expr ) = match (x) with RealExpr(e) -> (egc e) + let egnc ( x : real_expr ) = match (x) with RealExpr(e) -> (egnc e) + let egno ( x : real_expr ) = match (x) with RealExpr(e) -> (egno e) + let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) + let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) + let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) + + (** Create a real sort. *) + let mk_sort ( ctx : context ) = + create_sort ctx (Z3native.mk_real_sort (context_gno ctx)) + + (** The numerator of a rational numeral. *) + let get_numerator ( x : rat_num ) = + Integers.create_num (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + + (** The denominator of a rational numeral. *) + let get_denominator ( x : rat_num ) = + Integers.create_num (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : rat_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + + (** Creates a real constant. *) + let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) + + (** Creates a real constant. *) + let mk_real_const_s ( ctx : context ) ( name : string ) = + mk_real_const ctx (Symbol.mk_string ctx name) + + (** + Create a real from a fraction. + + @param num numerator of rational. + @param den denominator of rational. + @return A Term with value / and sort Real + + *) + let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = + if (den == 0) then + raise (Z3native.Exception "Denominator is zero") + else + create_num ctx (Z3native.mk_real (context_gno ctx) num den) + + (** + Create a real numeral. + @param v A string representing the Term value in decimal notation. + @return A Term with value and sort Real + *) + let mk_numeral_s ( ctx : context ) ( v : string ) = + create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + + (** + Create a real numeral. + + @param v value of the numeral. + @return A Term with value and sort Real + *) + let mk_numeral_i ( ctx : context ) ( v : int ) = + create_num ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + + (** Creates an expression that checks whether a real number is an integer. *) + let mk_is_integer ( ctx : context ) ( t : real_expr ) = + Booleans.create_expr ctx (Z3native.mk_is_int (context_gno ctx) (egno t)) + + (** + 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. + *) + let mk_real2int ( ctx : context ) ( t : real_expr ) = + Integers.create_expr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)) + end + + and AlgebraicNumbers : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val create_num : context -> Z3native.ptr -> algebraic_num + end = struct + type algebraic_num = AlgebraicNum of arith_expr + + let create_num ( ctx : context ) ( no : Z3native.ptr ) = + AlgebraicNum(create_arith_expr ctx no) + + let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) + let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) + let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) + + (** + Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + @param precision the precision of the result + @return A numeral Expr of sort Real + *) + let to_upper ( x : algebraic_num ) ( precision : int ) = + Reals.create_num (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + + (** + Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^. + + @param precision the precision of the result + @return A numeral Expr of sort Real + *) + let to_lower ( x : algebraic_num ) precision = + Reals.create_num (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + + (** Returns a string representation in decimal notation. + The result has at most decimal places.*) + let to_decimal_string ( x : algebraic_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + + (** Returns a string representation of the numeral. *) + let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + end + + let aton (a : arith_expr array) = + let f (e : arith_expr) = (egno e) in + Array.map f a (** Indicates whether the term is of integer sort. *) - let is_int ( x : expr ) = - (Z3native.is_numeral_ast x#gnc x#gno) && - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == INT_SORT) + let is_int ( x : Expr.expr ) = + (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) (** Indicates whether the term is an arithmetic numeral. *) - let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + let is_arithmetic_numeral ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) (** Indicates whether the term is a less-than-or-equal *) - let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + let is_le ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) (** Indicates whether the term is a greater-than-or-equal *) - let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + let is_ge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) (** Indicates whether the term is a less-than *) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + let is_lt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) (** Indicates whether the term is a greater-than *) - let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + let is_gt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) (** Indicates whether the term is addition (binary) *) - let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + let is_add ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) (** Indicates whether the term is subtraction (binary) *) - let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + let is_sub ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) (** Indicates whether the term is a unary minus *) - let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + let is_uminus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) (** Indicates whether the term is multiplication (binary) *) - let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + let is_mul ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) (** Indicates whether the term is division (binary) *) - let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + let is_div ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) (** Indicates whether the term is integer division (binary) *) - let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + let is_idiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) (** Indicates whether the term is remainder (binary) *) - let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + let is_remainder ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) (** Indicates whether the term is modulus (binary) *) - let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + let is_modulus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) (** Indicates whether the term is a coercion of integer to real (unary) *) - let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + let is_inttoreal ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) (** Indicates whether the term is a coercion of real to integer (unary) *) - let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + let is_real_to_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) (** Indicates whether the term is a check that tests whether a real is integral (unary) *) - let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + let is_real_is_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) (** Indicates whether the term is of sort real. *) - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == REAL_SORT) + let is_real ( x : Expr.expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) (** Indicates whether the term is an integer numeral. *) - let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) + let is_int_numeral ( x : Expr.expr ) = (Expr.is_numeral x) && (is_int x) (** Indicates whether the term is a real numeral. *) - let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) + let is_rat_num ( x : Expr.expr ) = (Expr.is_numeral x) && (is_real x) (** Indicates whether the term is an algebraic number *) - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number x#gnc x#gno - - (** Retrieve the int value. *) - let get_int ( x : int_num ) = - let (r, v) = Z3native.get_numeral_int x#gnc x#gno in - if r then v - else raise (Z3native.Exception "Conversion failed.") - - (** Returns a string representation of the numeral. *) - let to_string ( x : int_num ) = Z3native.get_numeral_string x#gnc x#gno - - (** The numerator of a rational numeral. *) - let get_numerator ( x : rat_num ) = - (new int_num x#gc)#create_obj (Z3native.get_numerator x#gnc x#gno) - - (** The denominator of a rational numeral. *) - let get_denominator ( x : rat_num ) = - (new int_num x#gc)#create_obj (Z3native.get_denominator x#gnc x#gno) - - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) - let to_decimal_string ( x : rat_num ) (precision : int) = - Z3native.get_numeral_decimal_string x#gnc x#gno precision - - (** Returns a string representation of the numeral. *) - let to_string ( x : rat_num ) = Z3native.get_numeral_string x#gnc x#gno - - (** - Creates an integer constant. - *) - let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = - ((Expr.mk_const ctx name (mk_int_sort ctx)) :> int_expr) - - (** - Creates an integer constant. - *) - let mk_int_const_s ( ctx : context ) ( name : string ) = - mk_int_const ctx (Symbol.mk_string ctx name) - - (** - Creates a real constant. - *) - let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = - ((Expr.mk_const ctx name (mk_real_sort ctx)) :> real_expr) - - (** - Creates a real constant. - *) - let mk_real_const_s ( ctx : context ) ( name : string ) = - mk_real_const ctx (Symbol.mk_string ctx name) + let is_algebraic_number ( x : Expr.expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) (** Create an expression representing t[0] + t[1] + .... *) let mk_add ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) + Arithmetic.create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Arithmetic.aton t)) (** Create an expression representing t[0] * t[1] * .... *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) + Arithmetic.create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Arithmetic.aton t)) (** Create an expression representing t[0] - t[1] - .... *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = - (create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (AST.aton t)) :> arith_expr) + Arithmetic.create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Arithmetic.aton t)) (** Create an expression representing -t. *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - ArithExpr(create ctx (Z3native.mk_unary_minus (context_gno ctx) - (gno (match t with ArithExpr(b) -> b)))) + Arithmetic.create_expr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t)) (** Create an expression representing t1 / t2. *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - ArithExpr(create ctx (Z3native.mk_div (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - - (** - Create an expression representing t1 mod t2. - The arguments must have int type. - *) - let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - IntExpr(create ctx (Z3native.mk_mod (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - - (** - Create an expression representing t1 rem t2. - The arguments must have int type. - *) - let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - IntExpr(create ctx (Z3native.mk_rem (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Arithmetic.create_expr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 ^ t2. *) - let mk_power ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - ArithExpr(create_expr ctx (Z3native.mk_power (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Arithmetic.create_expr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 < t2 *) - let mk_lt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - BoolExpr(create ctx (Z3native.mk_lt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Booleans.create_expr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 <= t2 *) - let mk_le ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - BoolExpr(create ctx (Z3native.mk_le (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Booleans.create_expr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 > t2 *) - let mk_gt ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - BoolExpr(create ctx (Z3native.mk_gt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Booleans.create_expr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 >= t2 *) - let mk_ge ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - BoolExpr(create ctx (Z3native.mk_ge (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - - (** - 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. - *) - let mk_int2real ( ctx : context ) ( t : int_expr ) = - RealExpr(create (Z3native.mk_int2real (context_gno ctx) - (gno (match t with BoolExpr(b) -> b)))) - - (** - 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. - *) - let mk_real2int ( ctx : context ) ( t : real_expr ) = - (new int_expr ctx)#create_obj (Z3native.mk_real2int (context_gno ctx) t#gno) - - (** - Creates an expression that checks whether a real number is an integer. - *) - let mk_is_integer ( ctx : context ) ( t : real_expr ) = - BoolExpr(create ctx (Z3native.mk_is_int (context_gno ctx) - (gno (match t with BoolExpr(b) -> b)))) - (** - Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) - let to_upper ( x : algebraic_num ) ( precision : int ) = - (new rat_num x#gc)#create_obj (Z3native.get_algebraic_number_upper x#gnc x#gno precision) - - (** - Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) - let to_lower ( x : algebraic_num ) precision = - (new rat_num x#gc)#create_obj (Z3native.get_algebraic_number_lower x#gnc x#gno precision) - - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) - let to_decimal_string ( x : algebraic_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string x#gnc x#gno precision - - (** - Create a real from a fraction. - - @param num numerator of rational. - @param den denominator of rational. - @return A Term with value / and sort Real - - *) - let mk_real_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = - if (den == 0) then - raise (Z3native.Exception "Denominator is zero") - else - - (new rat_num ctx)#create_obj (Z3native.mk_real (context_gno ctx) num den) - - (** - Create a real numeral. - @param v A string representing the Term value in decimal notation. - @return A Term with value and sort Real - *) - let mk_real_numeral_s ( ctx : context ) ( v : string ) = - (new rat_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_real_sort ctx)#gno) - - (** - Create a real numeral. - - @param v value of the numeral. - @return A Term with value and sort Real - *) - let mk_real_numeral_i ( ctx : context ) ( v : int ) = - (new rat_num ctx)#create_obj (Z3native.mk_int (context_gno ctx) v (mk_real_sort ctx)#gno) - - (** - Create an integer numeral. - @param v A string representing the Term value in decimal notation. - *) - let mk_int_numeral_s ( ctx : context ) ( v : string ) = - (new int_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_int_sort ctx)#gno) - - (** - Create an integer numeral. - @param v value of the numeral. - @return A Term with value and sort Integer - *) - let mk_int_numeral_i ( ctx : context ) ( v : int ) = - (new int_num ctx)#create_obj (Z3native.mk_int (context_gno ctx) v (mk_int_sort ctx)#gno) - - (** Returns a string representation of the numeral. *) - let to_string ( x : algebraic_num ) = Z3native.get_numeral_string x#gnc x#gno + let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Booleans.create_expr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2)) end From 9845c8ee269bf2c8e0c3b32bfcfb3d735e537a8c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 5 Feb 2013 00:19:06 +0000 Subject: [PATCH 171/248] ML API: No more objects; type hierarchy exposed; clean separation into modules. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 691 ++++++++++++++++++++++++----------------------- 1 file changed, 357 insertions(+), 334 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 58c319d4d..4cf41f420 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -334,6 +334,13 @@ sig val create : context -> Z3native.ptr -> ast val aton : ast array -> Z3native.ptr array + module ASTVectors : sig + type ast_vector + val create : context -> Z3native.ptr -> ast_vector + val get_size : ast_vector -> int + val get : ast_vector -> int -> ast + end + val is_expr : ast -> bool val is_var : ast -> bool end = struct @@ -354,7 +361,7 @@ end = struct (** Vectors of ASTs *) - module ASTVector = + module ASTVectors = struct type ast_vector = z3_native_object @@ -401,7 +408,7 @@ end = struct (** Translates all ASTs in the vector to . @param to_ctx A context - @return A new ASTVector + @return A new ASTVectors *) let translate ( x : ast_vector ) ( to_ctx : context ) = create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) @@ -466,7 +473,7 @@ end = struct (** The keys stored in the map. *) let get_keys ( x : ast_map ) = - ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + ASTVectors.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) (** Retrieves a string representation of the map.*) let to_string ( x : ast_map ) = @@ -613,16 +620,15 @@ end and Sort : sig type sort = Sort of AST.ast - type bitvec_sort = BitvecSort of sort type uninterpreted_sort = UninterpretedSort of sort val create : context -> Z3native.ptr -> sort - val gno : sort -> Z3native.ptr + val gc : sort -> context val gnc : sort -> Z3native.ptr + val gno : sort -> Z3native.ptr val aton : sort array -> Z3native.ptr array end = struct type sort = Sort of AST.ast - type bitvec_sort = BitvecSort of sort type uninterpreted_sort = UninterpretedSort of sort let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) @@ -713,11 +719,14 @@ sig type func_decl = FuncDecl of AST.ast val create : context -> Z3native.ptr -> func_decl + val gc : func_decl -> context val gno : func_decl -> Z3native.ptr val gnc : func_decl -> Z3native.ptr + val aton : func_decl array -> Z3native.ptr array val get_domain_size : func_decl -> int val get_decl_kind : func_decl -> Z3enums.decl_kind + val get_arity : func_decl -> int end = struct open Sort @@ -1098,6 +1107,7 @@ sig val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val get_func_decl : expr -> FuncDecl.func_decl val is_numeral : expr -> bool + val to_string : expr -> string end = struct type expr = Expr of AST.ast @@ -1108,20 +1118,20 @@ end = struct let s = Z3native.get_sort (context_gno ctx) obj in let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in if (Z3native.is_algebraic_number (context_gno ctx) obj) then - (match (Arithmetic.AlgebraicNumbers.create_num ctx obj) with Arithmetic.AlgebraicNumbers.AlgebraicNum(Arithmetic.Expr(e)) -> e) + (match (Arithmetic.AlgebraicNumbers.create_num ctx obj) with Arithmetic.AlgebraicNumbers.AlgebraicNum(Arithmetic.ArithExpr(e)) -> e) else if (Z3native.is_numeral_ast (context_gno ctx) obj) && (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then match sk with - | INT_SORT -> (match (Arithmetic.Integers.create_num ctx obj) with Arithmetic.Integers.IntNum(Arithmetic.Integers.IntExpr(Arithmetic.Expr(e))) -> e) - | REAL_SORT -> (match (Arithmetic.Reals.create_num ctx obj) with Arithmetic.Reals.RatNum(Arithmetic.Reals.RealExpr(Arithmetic.Expr(e))) -> e) + | INT_SORT -> (match (Arithmetic.Integers.create_num ctx obj) with Arithmetic.Integers.IntNum(Arithmetic.Integers.IntExpr(Arithmetic.ArithExpr(e))) -> e) + | REAL_SORT -> (match (Arithmetic.Reals.create_num ctx obj) with Arithmetic.Reals.RatNum(Arithmetic.Reals.RealExpr(Arithmetic.ArithExpr(e))) -> e) | BV_SORT -> (match (BitVectors.create_num ctx obj) with BitVectors.BitVecNum(BitVectors.BitVecExpr(e)) -> e) | _ -> raise (Z3native.Exception "Unsupported numeral object") else match sk with | BOOL_SORT -> (match (Booleans.create_expr ctx obj) with Booleans.BoolExpr(e) -> e) - | INT_SORT -> (match (Arithmetic.Integers.create_expr ctx obj) with Arithmetic.Integers.IntExpr(Arithmetic.Expr(e)) -> e) - | REAL_SORT -> (match (Arithmetic.Reals.create_expr ctx obj) with Arithmetic.Reals.RealExpr(Arithmetic.Expr(e)) -> e) + | INT_SORT -> (match (Arithmetic.Integers.create_expr ctx obj) with Arithmetic.Integers.IntExpr(Arithmetic.ArithExpr(e)) -> e) + | REAL_SORT -> (match (Arithmetic.Reals.create_expr ctx obj) with Arithmetic.Reals.RealExpr(Arithmetic.ArithExpr(e)) -> e) | BV_SORT -> (match (BitVectors.create_expr ctx obj) with BitVectors.BitVecExpr(e) -> e) | ARRAY_SORT -> (match (Arrays.create_expr ctx obj) with Arrays.ArrayExpr(e) -> e) | DATATYPE_SORT -> (match (Datatypes.create_expr ctx obj) with Datatypes.DatatypeExpr(e) -> e) @@ -1409,6 +1419,9 @@ sig val create_expr : context -> Z3native.ptr -> bool_expr val create_sort : context -> Z3native.ptr -> bool_sort + val gc : bool_expr -> context + val gnc : bool_expr -> Z3native.ptr + val gno : bool_expr -> Z3native.ptr val aton : bool_expr array -> Z3native.ptr array end = struct type bool_expr = BoolExpr of Expr.expr @@ -2648,9 +2661,10 @@ end and Arithmetic : sig type arith_sort = ArithSort of Sort.sort - type arith_expr = Expr of Expr.expr + type arith_expr = ArithExpr of Expr.expr val create_expr : context -> Z3native.ptr -> arith_expr + val create_sort : context -> Z3native.ptr -> arith_sort val aton : arith_expr array -> Z3native.ptr array module Integers : sig @@ -2679,14 +2693,53 @@ sig val create_num : context -> Z3native.ptr -> algebraic_num end + val is_int : Expr.expr -> bool + val is_arithmetic_numeral : Expr.expr -> bool + val is_le : Expr.expr -> bool + val is_ge : Expr.expr -> bool + val is_lt : Expr.expr -> bool + val is_gt : Expr.expr -> bool + val is_add : Expr.expr -> bool + val is_sub : Expr.expr -> bool + val is_uminus : Expr.expr -> bool + val is_mul : Expr.expr -> bool + val is_div : Expr.expr -> bool + val is_idiv : Expr.expr -> bool + val is_remainder : Expr.expr -> bool + val is_modulus : Expr.expr -> bool + val is_inttoreal : Expr.expr -> bool + val is_real_to_int : Expr.expr -> bool + val is_real_is_int : Expr.expr -> bool + val is_real : Expr.expr -> bool + val is_int_numeral : Expr.expr -> bool + val is_rat_num : Expr.expr -> bool + val is_algebraic_number : Expr.expr -> bool + val mk_add : context -> arith_expr array -> Arithmetic.arith_expr + val mk_mul : context -> arith_expr array -> Arithmetic.arith_expr + val mk_sub : context -> arith_expr array -> Arithmetic.arith_expr + val mk_unary_minus : + context -> arith_expr -> Arithmetic.arith_expr + val mk_div : + context -> arith_expr -> arith_expr -> Arithmetic.arith_expr + val mk_power : + context -> arith_expr -> arith_expr -> Arithmetic.arith_expr + val mk_lt : + context -> arith_expr -> arith_expr -> Booleans.bool_expr + val mk_le : + context -> arith_expr -> arith_expr -> Booleans.bool_expr + val mk_gt : + context -> arith_expr -> arith_expr -> Booleans.bool_expr + val mk_ge : + context -> arith_expr -> arith_expr -> Booleans.bool_expr + end = struct type arith_sort = ArithSort of Sort.sort type arith_expr = ArithExpr of Expr.expr - let create_arith_expr ( ctx : context ) ( no : Z3native.ptr ) = + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = ArithExpr(Expr.create ctx no) - let create_arith_sort ( ctx : context ) ( no : Z3native.ptr ) = + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = ArithSort(Sort.create ctx no) let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gc s) @@ -2712,10 +2765,10 @@ end = struct type int_num = IntNum of int_expr let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - IntSort(create_arith_sort ctx no) + IntSort(Arithmetic.create_sort ctx no) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - IntExpr(create_arith_expr ctx no) + IntExpr(Arithmetic.create_expr ctx no) let create_num ( ctx : context ) ( no : Z3native.ptr ) = IntNum(create_expr ctx no) @@ -2796,6 +2849,19 @@ end = struct *) let mk_int2real ( ctx : context ) ( t : int_expr ) = Reals.create_expr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)) + + (** + 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. + *) + let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = + BitVectors.create_expr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t)) end and Reals : @@ -2813,10 +2879,10 @@ end = struct type rat_num = RatNum of real_expr let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - RealSort(create_arith_sort ctx no) + RealSort(Arithmetic.create_sort ctx no) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - RealExpr(create_arith_expr ctx no) + RealExpr(Arithmetic.create_expr ctx no) let create_num ( ctx : context ) ( no : Z3native.ptr ) = RatNum(create_expr ctx no) @@ -2914,7 +2980,7 @@ end = struct type algebraic_num = AlgebraicNum of arith_expr let create_num ( ctx : context ) ( no : Z3native.ptr ) = - AlgebraicNum(create_arith_expr ctx no) + AlgebraicNum(Arithmetic.create_expr ctx no) let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) @@ -3126,316 +3192,330 @@ end (** Functions to manipulate bit-vector expressions *) and BitVectors : sig + type bitvec_sort = BitVecSort of Sort.sort type bitvec_expr = BitVecExpr of Expr.expr type bitvec_num = BitVecNum of bitvec_expr + val create_sort : context -> Z3native.ptr -> bitvec_sort val create_expr : context -> Z3native.ptr -> bitvec_expr val create_num : context -> Z3native.ptr -> bitvec_num end = struct - type bitvec_expr = Expr of Expr.expr - type bitvec_num = BitVecExpr of bitvec_expr + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + BitVecSort(Sort.create ctx no) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (Expr.create ctx no) in - BitVecExpr(e) + BitVecExpr(Expr.create ctx no) let create_num ( ctx : context ) ( no : Z3native.ptr ) = - let e = (create_expr ctx no) in - BitVecNum(e) + BitVecNum(create_expr ctx no) + + let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) + let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) + let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) + let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gc e) + let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gnc e) + let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gno e) + let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) + let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) + let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) (** Create a new bit-vector sort. *) let mk_sort ( ctx : context ) size = - (new bitvec_sort ctx)#create_obj (Z3native.mk_bv_sort (context_gno ctx) size) + create_sort ctx (Z3native.mk_bv_sort (context_gno ctx) size) (** Indicates whether the terms is of bit-vector sort. *) - let is_bv ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind x#gnc (Z3native.get_sort x#gnc x#gno))) == BV_SORT) + let is_bv ( x : Expr.expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) (** Indicates whether the term is a bit-vector numeral *) - let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) + let is_bv_numeral ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) (** Indicates whether the term is a one-bit bit-vector with value one *) - let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) + let is_bv_bit1 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) (** Indicates whether the term is a one-bit bit-vector with value zero *) - let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) + let is_bv_bit0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) (** Indicates whether the term is a bit-vector unary minus *) - let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) + let is_bv_uminus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) (** Indicates whether the term is a bit-vector addition (binary) *) - let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) + let is_bv_add ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) (** Indicates whether the term is a bit-vector subtraction (binary) *) - let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) + let is_bv_sub ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) (** Indicates whether the term is a bit-vector multiplication (binary) *) - let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) + let is_bv_mul ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) (** Indicates whether the term is a bit-vector signed division (binary) *) - let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) + let is_bv_sdiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) (** Indicates whether the term is a bit-vector unsigned division (binary) *) - let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) + let is_bv_udiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) (** Indicates whether the term is a bit-vector signed remainder (binary) *) - let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) + let is_bv_SRem ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) + let is_bv_urem ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) (** Indicates whether the term is a bit-vector signed modulus *) - let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) + let is_bv_smod ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) (** Indicates whether the term is a bit-vector signed division by zero *) - let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) + let is_bv_sdiv0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) (** Indicates whether the term is a bit-vector unsigned division by zero *) - let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) + let is_bv_udiv0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) (** Indicates whether the term is a bit-vector signed remainder by zero *) - let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) + let is_bv_srem0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) + let is_bv_urem0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) (** Indicates whether the term is a bit-vector signed modulus by zero *) - let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) + let is_bv_smod0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) + let is_bv_ule ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) + let is_bv_sle ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) + let is_bv_uge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) + let is_bv_sge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) (** Indicates whether the term is an unsigned bit-vector less-than *) - let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) + let is_bv_ult ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) (** Indicates whether the term is a signed bit-vector less-than *) - let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) + let is_bv_slt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) (** Indicates whether the term is an unsigned bit-vector greater-than *) - let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) + let is_bv_ugt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) (** Indicates whether the term is a signed bit-vector greater-than *) - let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) + let is_bv_sgt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) (** Indicates whether the term is a bit-wise AND *) - let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) + let is_bv_and ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) (** Indicates whether the term is a bit-wise OR *) - let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) + let is_bv_or ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) (** Indicates whether the term is a bit-wise NOT *) - let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) + let is_bv_not ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) (** Indicates whether the term is a bit-wise XOR *) - let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) + let is_bv_xor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) (** Indicates whether the term is a bit-wise NAND *) - let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) + let is_bv_nand ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) (** Indicates whether the term is a bit-wise NOR *) - let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) + let is_bv_nor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) (** Indicates whether the term is a bit-wise XNOR *) - let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) + let is_bv_xnor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) (** Indicates whether the term is a bit-vector concatenation (binary) *) - let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) + let is_bv_concat ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) (** Indicates whether the term is a bit-vector sign extension *) - let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) + let is_bv_signextension ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) (** Indicates whether the term is a bit-vector zero extension *) - let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) + let is_bv_zeroextension ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) (** Indicates whether the term is a bit-vector extraction *) - let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) + let is_bv_extract ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) (** Indicates whether the term is a bit-vector repetition *) - let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) + let is_bv_repeat ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) (** Indicates whether the term is a bit-vector reduce OR *) - let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) + let is_bv_reduceor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) (** Indicates whether the term is a bit-vector reduce AND *) - let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) + let is_bv_reduceand ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) (** Indicates whether the term is a bit-vector comparison *) - let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) + let is_bv_comp ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) (** Indicates whether the term is a bit-vector shift left *) - let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) + let is_bv_shiftleft ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) (** Indicates whether the term is a bit-vector logical shift right *) - let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightlogical ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) (** Indicates whether the term is a bit-vector arithmetic shift left *) - let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) + let is_bv_shiftrightarithmetic ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) (** Indicates whether the term is a bit-vector rotate left *) - let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateleft ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) (** Indicates whether the term is a bit-vector rotate right *) - let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateright ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotateleftextended ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_bv_rotaterightextended ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_int_to_bv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_bv_to_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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))) *) - let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) + let is_bv_carry ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) *) - let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + let is_bv_xor3 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) (** The size of a bit-vector sort. *) - let get_size (x : bitvec_sort) = Z3native.get_bv_sort_size x#gnc x#gno + let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) (** Retrieve the int value. *) let get_int ( x : bitvec_num ) = - let (r, v) = Z3native.get_numeral_int x#gnc x#gno in + let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in if r then v else raise (Z3native.Exception "Conversion failed.") (** Returns a string representation of the numeral. *) - let to_string ( x : bitvec_num ) = Z3native.get_numeral_string x#gnc x#gno + let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) (** Creates a bit-vector constant. *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - ((Expr.mk_const ctx name (mk_sort ctx size)) :> bitvec_expr) + BitVecExpr(Expr.mk_const ctx name (match (mk_sort ctx size) with BitVecSort(s) -> s)) (** Creates a bit-vector constant. @@ -3448,91 +3528,91 @@ end = struct The argument must have a bit-vector sort. *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnot (context_gno ctx) t#gno) + create_expr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvredand (context_gno ctx) t#gno) + create_expr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvredor (context_gno ctx) t#gno) + create_expr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) (** Bitwise conjunction. The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvand (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvor (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvxor (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnand (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvnor (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvxnor (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvneg (context_gno ctx) t#gno) + create_expr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvadd (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsub (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvmul (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) (** Unsigned division. @@ -3544,7 +3624,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvudiv (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) (** Signed division. @@ -3559,7 +3639,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsdiv (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) (** Unsigned remainder. @@ -3569,7 +3649,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvurem (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) (** Signed remainder. @@ -3581,7 +3661,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsrem (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed remainder (sign follows divisor). @@ -3590,7 +3670,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_bvsmod (context_gno ctx) t1#gno t2#gno) + create_expr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) (** Unsigned less-than @@ -3598,9 +3678,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvult (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed less-than @@ -3608,9 +3686,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvslt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2)) (** Unsigned less-than or equal to. @@ -3618,9 +3694,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvule (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed less-than or equal to. @@ -3628,9 +3702,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsle (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2)) (** Unsigned greater than or equal to. @@ -3638,19 +3710,15 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvuge (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed greater than or equal to. The arguments must have the same bit-vector sort. *) - let mk_SGE ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsge (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Booleans.create_expr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2)) (** Unsigned greater-than. @@ -3658,9 +3726,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvugt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed greater-than. @@ -3668,9 +3734,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsgt (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2)) (** Bit-vector concatenation. @@ -3681,9 +3745,7 @@ end = struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVectors.BitVecExpr(create ctx (Z3native.mk_concat (context_gno ctx) - (gno (match t1 with BitVecExpr(b) -> b)) - (gno (match t2 with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) (** Bit-vector extraction. @@ -3694,7 +3756,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - (new bitvec_expr ctx)#create_obj (Z3native.mk_extract (context_gno ctx) high low t#gno) + create_expr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) (** Bit-vector sign extension. @@ -3704,7 +3766,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_sign_ext (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) (** Bit-vector zero extension. @@ -3715,7 +3777,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_zero_ext (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) (** Bit-vector repetition. @@ -3723,7 +3785,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_repeat (context_gno ctx) i (gno (match t with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) (** Shift left. @@ -3738,9 +3800,8 @@ end = struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_bvshl (context_gno ctx) - (gno (match t1 with BitVecExpr(b) -> b)) - (gno (match t2 with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) + (** Logical shift right @@ -3754,9 +3815,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_bvlshr (context_gno ctx) - (gno (match t1 with BitVecExpr(b) -> b)) - (gno (match t2 with BitVecExpr(b) -> b)))) + create_expr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) (** Arithmetic shift right @@ -3772,9 +3831,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_bvashr (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + create_expr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) (** Rotate Left. @@ -3783,7 +3840,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_rotate_left (context_gno ctx) i (gno (match t with BoolExpr(b) -> b)))) + create_expr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) (** Rotate Right. @@ -3792,7 +3849,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_rotate_right (context_gno ctx) i (gno (match t with BoolExpr(b) -> b)))) + create_expr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) (** Rotate Left. @@ -3801,9 +3858,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_ext_rotate_left (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + create_expr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) (** Rotate Right. @@ -3813,22 +3868,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BitVecExpr(create ctx (Z3native.mk_ext_rotate_right (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - - (** - 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. - *) - let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - BitVecExpr(create ctx (Z3native.mk_int2bv (context_gno ctx) n (gno (match t with IntExpr(b) -> b)))) + create_expr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) (** Create an integer from the bit-vector argument . @@ -3845,8 +3885,8 @@ end = struct The argument must be of bit-vector sort. *) - let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool) = - (new int_expr ctx)#create_obj (Z3native.mk_bv2int (context_gno ctx) t#gno signed) + let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = + Arithmetic.Integers.create_expr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3854,10 +3894,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - BoolExpr(create ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)) - signed)) + Booleans.create_expr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3865,19 +3902,15 @@ end = struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) - + Booleans.create_expr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2)) + (** Create a predicate that checks that the bit-wise subtraction does not overflow. The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2)) (** Create a predicate that checks that the bit-wise subtraction does not underflow. @@ -3885,10 +3918,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - BoolExpr(create ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)) - signed)) + Booleans.create_expr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3896,17 +3926,15 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2)) (** Create a predicate that checks that the bit-wise negation does not overflow. The arguments must be of bit-vector sort. *) - let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr) = - BoolExpr(create ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (gno (match t with BitVecExpr(b) -> b)))) + let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = + Booleans.create_expr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t)) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3914,10 +3942,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - BoolExpr(create ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)) - signed)) + Booleans.create_expr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3925,9 +3950,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - BoolExpr(create ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) - (gno (match t1 with BoolExpr(b) -> b)) - (gno (match t2 with BoolExpr(b) -> b)))) + Booleans.create_expr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2)) (** Create a bit-vector numeral. @@ -3936,7 +3959,7 @@ end = struct @param size the size of the bit-vector *) let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = - (new bitvec_num ctx)#create_obj (Z3native.mk_numeral (context_gno ctx) v (mk_sort ctx size)#gno) + create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx size))) end (** Functions to manipulate proof expressions *) @@ -3946,17 +3969,17 @@ end = struct (** Indicates whether the term is a Proof for the expression 'true'. *) - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) + let is_true ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) (** Indicates whether the term is a proof for a fact asserted by the user. *) - let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) + let is_asserted ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_goal ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) (** Indicates whether the term is proof via modus ponens @@ -3967,7 +3990,7 @@ end = struct [mp T1 T2]: q The second antecedents may also be a proof for (iff p q). *) - let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) + let is_modus_ponens ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) (** Indicates whether the term is a proof for (R t t), where R is a reflexive relation. @@ -3976,7 +3999,7 @@ end = struct equivalence modulo namings, equality and equivalence. That is, R is either '~', '=' or 'iff'. *) - let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) + let is_reflexivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) (** Indicates whether the term is proof by symmetricity of a relation @@ -3986,7 +4009,7 @@ end = struct [symmetry T1]: (R s t) T1 is the antecedent of this proof object. *) - let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) + let is_symmetry ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) (** Indicates whether the term is a proof by transitivity of a relation @@ -3997,7 +4020,7 @@ end = struct T2: (R s u) [trans T1 T2]: (R t u) *) - let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) + let is_transitivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) (** Indicates whether the term is a proof by condensed transitivity of a relation @@ -4017,7 +4040,7 @@ end = struct if there is a path from s to t, if we view every antecedent (R a b) as an edge between a and b. *) - let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_Transitivity_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) (** @@ -4030,7 +4053,7 @@ end = struct Remark: if t_i == s_i, then the antecedent Ti is suppressed. That is, reflexivity proofs are supressed to save space. *) - let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) + let is_monotonicity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) (** Indicates whether the term is a quant-intro proof @@ -4039,7 +4062,7 @@ end = struct T1: (~ p q) [quant-intro T1]: (~ (forall (x) p) (forall (x) q)) *) - let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) + let is_quant_intro ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) (** Indicates whether the term is a distributivity proof object. @@ -4056,7 +4079,7 @@ end = struct Remark. This rule is used by the CNF conversion pass and instantiated by f = or, and g = and. *) - let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_distributivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) (** Indicates whether the term is a proof by elimination of AND @@ -4065,7 +4088,7 @@ end = struct T1: (and l_1 ... l_n) [and-elim T1]: l_i *) - let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) + let is_and_elimination ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) (** Indicates whether the term is a proof by eliminiation of not-or @@ -4074,7 +4097,7 @@ end = struct T1: (not (or l_1 ... l_n)) [not-or-elim T1]: (not l_i) *) - let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_or_elimination ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) (** Indicates whether the term is a proof by rewriting @@ -4088,11 +4111,11 @@ end = struct Remark: if f is bool, then = is iff. Examples: - (= (+ ( x : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) + (= (+ ( x : Expr.expr ) 0) x) + (= (+ ( x : Expr.expr ) 1 2) (+ 3 x)) + (iff (or ( x : Expr.expr ) false) x) *) - let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) + let is_rewrite ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) (** Indicates whether the term is a proof by rewriting @@ -4107,14 +4130,14 @@ end = struct - When converting bit-vectors to Booleans (BIT2BOOL=true) - When pulling ite expression up (PULL_CHEAP_ITE_TREES=true) *) - let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) + let is_rewrite_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) (** Indicates whether the term is a proof for pulling quantifiers out. @@ -4123,7 +4146,7 @@ end = struct This proof object is only used if the parameter PROOF_MODE is 1. This proof object has no antecedents *) - let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_pull_quant_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) (** Indicates whether the term is a proof for pushing quantifiers in. @@ -4136,7 +4159,7 @@ end = struct This proof object has no antecedents *) - let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) + let is_push_quant ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) (** Indicates whether the term is a proof for elimination of unused variables. @@ -4148,34 +4171,34 @@ end = struct This proof object has no antecedents. *) - let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + let is_elim_unused_vars ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. + (iff (forall (x) (or (not (= ( x : Expr.expr ) t)) P[x])) P[t]) + if ( x : Expr.expr ) does not occur in t. This proof object has no antecedents. Several variables can be eliminated simultaneously. *) - let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) + let is_der ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) (** Indicates whether the term is a proof for quantifier instantiation A proof of (or (not (forall (x) (P x))) (P a)) *) - let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) + let is_quant_inst ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) (** Indicates whether the term is a hypthesis marker. Mark a hypothesis in a natural deduction style proof. *) - let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) + let is_hypothesis ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) (** Indicates whether the term is a proof by lemma @@ -4187,7 +4210,7 @@ end = struct It converts the proof in a proof for (or (not l_1) ... (not l_n)), when T1 contains the hypotheses: l_1, ..., l_n. *) - let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) + let is_lemma ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) (** Indicates whether the term is a proof by unit resolution @@ -4198,7 +4221,7 @@ end = struct T(n+1): (not l_n) [unit-resolution T1 ... T(n+1)]: (or l_1' ... l_m') *) - let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_unit_resolution ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) (** Indicates whether the term is a proof by iff-true @@ -4206,7 +4229,7 @@ end = struct T1: p [iff-true T1]: (iff p true) *) - let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_true ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) (** Indicates whether the term is a proof by iff-false @@ -4214,7 +4237,7 @@ end = struct T1: (not p) [iff-false T1]: (iff p false) *) - let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) + let is_iff_false ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) (** Indicates whether the term is a proof by commutativity @@ -4226,7 +4249,7 @@ end = struct This proof object has no antecedents. Remark: if f is bool, then = is iff. *) - let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_commutativity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) (** Indicates whether the term is a proof for Tseitin-like axioms @@ -4261,7 +4284,7 @@ end = struct unfolding the Boolean connectives in the axioms a small bounded number of steps (=3). *) - let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_axiom ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) (** Indicates whether the term is a proof for introduction of a name @@ -4283,7 +4306,7 @@ end = struct Otherwise: [def-intro]: (= n e) *) - let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) + let is_def_intro ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) (** Indicates whether the term is a proof for application of a definition @@ -4292,7 +4315,7 @@ end = struct F is 'equivalent' to n, given that T1 is a proof that n is a name for F. *) - let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) + let is_apply_def ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) (** Indicates whether the term is a proof iff-oeq @@ -4300,7 +4323,7 @@ end = struct T1: (iff p q) [iff~ T1]: (~ p q) *) - let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) + let is_iff_oeq ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) (** Indicates whether the term is a proof for a positive NNF step @@ -4327,7 +4350,7 @@ end = struct NNF_NEG furthermore handles the case where negation is pushed over Boolean connectives 'and' and 'or'. *) - let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_pos ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) (** Indicates whether the term is a proof for a negative NNF step @@ -4351,7 +4374,7 @@ end = struct [nnf-neg T1 T2 T3 T4]: (~ (not (iff s_1 s_2)) (and (or r_1 r_2) (or r_1' r_2'))) *) - let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_neg ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) (** Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form. @@ -4362,7 +4385,7 @@ end = struct This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO. *) - let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) + let is_nnf_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) (** Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form. @@ -4371,19 +4394,19 @@ end = struct 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. *) - let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) + let is_cnf_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) (** Indicates whether the term is a proof for a Skolemization step Proof for: - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + [sk]: (~ (not (forall ( x : Expr.expr ) (p ( x : Expr.expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : Expr.expr ) (p ( x : Expr.expr ) y)) (p (sk y) y)) This proof object has no antecedents. *) - let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) + let is_skolemize ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) (** Indicates whether the term is a proof by modus ponens for equi-satisfiability. @@ -4393,7 +4416,7 @@ end = struct T2: (~ p q) [mp~ T1 T2]: q *) - let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_modus_ponens_oeq ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) (** Indicates whether the term is a proof for theory lemma @@ -4411,7 +4434,7 @@ end = struct (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. *) - let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) + let is_theory_lemma ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end @@ -4462,8 +4485,8 @@ struct (** Adds the constraints to the given goal. *) (* CMW: assert seems to be a keyword. *) - let assert_ ( x : goal ) ( constraints : bool_expr array ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) e#gno in + let assert_ ( x : goal ) ( constraints : Booleans.bool_expr array ) = + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e) in ignore (Array.map f constraints) ; () @@ -4484,7 +4507,7 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = (new bool_expr (z3obj_gc x))#create_obj (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in + let f i = Booleans.create_expr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) @@ -4599,7 +4622,7 @@ struct Return the (symbolic) value of this entry. *) let get_value ( x : func_entry ) = - create_expr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) + Expr.create (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) (** The number of arguments of the entry. @@ -4611,7 +4634,7 @@ struct *) let get_args ( x : func_entry ) = let n = (get_num_args x) in - let f i = (create_expr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (Expr.create (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** @@ -4639,7 +4662,7 @@ struct (** The (symbolic) `else' value of the function interpretation. *) - let get_else ( x : func_interp ) = create_expr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) + let get_else ( x : func_interp ) = Expr.create (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) (** The arity of the function interpretation @@ -4666,31 +4689,31 @@ struct (** Retrieves the interpretation (the assignment) of in the model. A function declaration of zero arity An expression if the function has an interpretation in the model, null otherwise. *) - let get_const_interp ( x : model ) ( f : func_decl ) = + let get_const_interp ( x : model ) ( f : FuncDecl.func_decl ) = if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind f#gnc (Z3native.get_range f#gnc f#gno))) == ARRAY_SORT then + (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") else - let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) f#gno in + let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in if (Z3native.is_null np) then None else - Some (create_expr (z3obj_gc x) np) + Some (Expr.create (z3obj_gc x) np) (** Retrieves the interpretation (the assignment) of in the model. A Constant An expression if the constant has an interpretation in the model, null otherwise. *) - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + let get_const_interp_e ( x : model ) ( a : Expr.expr ) = get_const_interp x (Expr.get_func_decl a) (** Retrieves the interpretation (the assignment) of a non-constant in the model. A function declaration of non-zero arity A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range f#gnc f#gno))) in + let rec get_func_interp ( x : model ) ( f : FuncDecl.func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) f#gno in + let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in if (Z3native.is_null n) then None else @@ -4700,10 +4723,10 @@ struct raise (Z3native.Exception "Argument was not an array constant") else let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x ((new func_decl f#gc)#create_obj fd) + get_func_interp x (FuncDecl.create (z3obj_gc x) fd) | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); else - let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) f#gno) in + let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) (** The number of constants that have an interpretation in the model. *) @@ -4712,7 +4735,7 @@ struct (** The function declarations of the constants in the model. *) let get_const_decls ( x : model ) = let n = (get_num_consts x) in - let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f @@ -4722,15 +4745,15 @@ struct (** The function declarations of the function interpretations in the model. *) let get_func_decls ( x : model ) = let n = (get_num_consts x) in - let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** All symbols that have an interpretation in the model. *) let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in - let f i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = (new func_decl (z3obj_gc x))#create_obj (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.append (Array.init n_funcs f) (Array.init n_consts g) (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) @@ -4751,15 +4774,15 @@ struct The evaluation of in the model. *) - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) t#gno completion) in + let eval ( x : model ) ( t : Expr.expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in if not r then raise (ModelEvaluationFailedException "evaluation failed") else - create_expr (z3obj_gc x) v + Expr.create (z3obj_gc x) v (** Alias for eval. *) - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + let evaluate ( x : model ) ( t : Expr.expr ) ( completion : bool ) = eval x t completion (** The number of uninterpreted sorts that the model has an interpretation for. *) @@ -4775,7 +4798,7 @@ struct *) let get_sorts ( x : model ) = let n = (get_num_sorts x) in - let f i = (create_sort (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (Sort.create (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f @@ -4784,10 +4807,10 @@ struct An uninterpreted sort An array of expressions, where each is an element of the universe of *) - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) s#gno) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in + let sort_universe ( x : model ) ( s : Sort.sort ) = + let n_univ = AST.ASTVectors.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n = (AST.ASTVectors.get_size n_univ) in + let f i = (AST.ASTVectors.get n_univ i) in Array.init n f (** Conversion of models to strings. @@ -5323,8 +5346,8 @@ struct (** Assert a constraint (or multiple) into the solver. *) - let assert_ ( x : solver ) ( constraints : bool_expr array ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in + let assert_ ( x : solver ) ( constraints : Booleans.bool_expr array ) = + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e)) in ignore (Array.map f constraints) (** @@ -5340,11 +5363,11 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( cs : bool_expr array ) ( ps : bool_expr array ) = + let assert_and_track ( x : solver ) ( cs : Booleans.bool_expr array ) ( ps : Booleans.bool_expr array ) = if ((Array.length cs) != (Array.length ps)) then raise (Z3native.Exception "Argument size mismatch") else - let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) e#gno (Array.get ps i)#gno) in + let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e) (Booleans.gno (Array.get ps i))) in ignore (Array.iteri f cs) (** @@ -5359,24 +5382,24 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( c : bool_expr ) ( p : bool_expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) c#gno p#gno + let assert_and_track ( x : solver ) ( c : Booleans.bool_expr ) ( p : Booleans.bool_expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Booleans.gno c) (Booleans.gno p) (** The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - (AST.ASTVector.get_size a) + let a = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + (AST.ASTVectors.get_size a) (** The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size a) in - let f i = ((new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get a i)#gno) in + let a = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVectors.get_size a) in + let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get a i)) in Array.init n f (** @@ -5386,12 +5409,12 @@ struct *) - let check ( x : solver ) ( assumptions : bool_expr array) = + let check ( x : solver ) ( assumptions : Booleans.bool_expr array) = let r = if ((Array.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (AST.aton assumptions)) + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Booleans.aton assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -5422,7 +5445,7 @@ struct if (Z3native.is_null q) then None else - Some (create_expr (z3obj_gc x) q) + Some (Expr.create (z3obj_gc x) q) (** The unsat core of the last Check. @@ -5432,9 +5455,9 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size cn) in - let f i = (AST.ASTVector.get cn i) in + let cn = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVectors.get_size cn) in + let f i = (AST.ASTVectors.get cn i) in Array.init n f (** @@ -5527,30 +5550,30 @@ struct (** Assert a constraints into the fixedpoint solver. *) - let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) e#gno) in + let assert_ ( x : fixedpoint ) ( constraints : Booleans.bool_expr array ) = + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e)) in ignore (Array.map f constraints) ; () (** Register predicate as recursive relation. *) - let register_relation ( x : fixedpoint ) ( f : func_decl ) = - Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) f#gno + let register_relation ( x : fixedpoint ) ( f : FuncDecl.func_decl ) = + Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (** Add rule into the fixedpoint solver. *) - let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : Symbol.symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : Booleans.bool_expr ) ( name : Symbol.symbol option ) = match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) rule#gno (Symbol.gno y) + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) (Symbol.gno y) (** Add table fact to the fixedpoint solver. *) - let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = - Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) pred#gno (Array.length args) args + let add_fact ( x : fixedpoint ) ( pred : FuncDecl.func_decl ) ( args : int array ) = + Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (Array.length args) args (** Query the fixedpoint solver. @@ -5558,8 +5581,8 @@ struct 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. *) - let query ( x : fixedpoint ) ( query : bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) query#gno)) with + let query ( x : fixedpoint ) ( query : Booleans.bool_expr ) = + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Booleans.gno query))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -5570,8 +5593,8 @@ struct 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. *) - let query_r ( x : fixedpoint ) ( relations : func_decl array ) = - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (func_declaton relations))) with + let query_r ( x : fixedpoint ) ( relations : FuncDecl.func_decl array ) = + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (FuncDecl.aton relations))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -5595,8 +5618,8 @@ struct (** Update named rule into in the fixedpoint solver. *) - let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) rule#gno (Symbol.gno name) + let update_rule ( x : fixedpoint ) ( rule : Booleans.bool_expr ) ( name : Symbol.symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) (Symbol.gno name) (** Retrieve satisfying instance or instances of solver, @@ -5607,7 +5630,7 @@ struct if (Z3native.is_null q) then None else - Some (create_expr (z3obj_gc x) q) + Some (Expr.create (z3obj_gc x) q) (** Retrieve explanation why fixedpoint engine returned status Unknown. @@ -5618,25 +5641,25 @@ struct (** Retrieve the number of levels explored for a given predicate. *) - let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = - Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) predicate#gno + let get_num_levels ( x : fixedpoint ) ( predicate : FuncDecl.func_decl ) = + Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) (** Retrieve the cover of a predicate. *) - let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = - let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level predicate#gno) in + let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : FuncDecl.func_decl ) = + let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in if (Z3native.is_null q) then None else - Some (create_expr (z3obj_gc x) q) + Some (Expr.create (z3obj_gc x) q) (** Add property about the predicate. The property is added at level. *) - let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level predicate#gno property#gno + let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : FuncDecl.func_decl ) ( property : Expr.expr ) = + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) (** Retrieve internal string representation of fixedpoint object. @@ -5646,31 +5669,31 @@ struct (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) f#gno (Array.length kinds) (Symbol.aton kinds) + let set_predicate_representation ( x : fixedpoint ) ( f : FuncDecl.func_decl ) ( kinds : Symbol.symbol array ) = + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Symbol.aton kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. *) - let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (AST.aton queries) + let to_string_q ( x : fixedpoint ) ( queries : Booleans.bool_expr array ) = + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Booleans.aton queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get v i)#gno in + let v = (AST.ASTVectors.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVectors.get_size v) in + let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get v i)) in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i = (new bool_expr (z3obj_gc x))#create_obj (AST.ASTVector.get v i)#gno in + let v = (AST.ASTVectors.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVectors.get_size v) in + let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get v i)) in Array.init n f (** @@ -5754,10 +5777,10 @@ struct @param formula Formula to be checked for consistency in conjunction with assumptions. @return A string representation of the benchmark. *) - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Booleans.bool_expr array ) ( formula : Booleans.bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (AST.aton assumptions) - formula#gno + (Array.length assumptions) (Booleans.aton assumptions) + (Booleans.gno formula) (** Parse the given string using the SMT-LIB parser. @@ -5768,7 +5791,7 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5779,16 +5802,16 @@ struct Z3native.parse_smtlib_string (context_gno ctx) str cs (Symbol.aton sort_names) - (AST.aton sorts) + (Sort.aton sorts) cd (Symbol.aton decl_names) - (func_declaton decls) + (FuncDecl.aton decls) (** Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5799,10 +5822,10 @@ struct Z3native.parse_smtlib_file (context_gno ctx) file_name cs (Symbol.aton sort_names) - (AST.aton sorts) + (Sort.aton sorts) cd (Symbol.aton decl_names) - (func_declaton decls) + (FuncDecl.aton decls) (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. @@ -5814,7 +5837,7 @@ struct *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = ((create_expr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) :> bool_expr) in + let f i = Booleans.create_expr ctx (Z3native.get_smtlib_formula (context_gno ctx) i) in Array.init n f @@ -5828,7 +5851,7 @@ struct *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = ((create_expr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) :> bool_expr ) in + let f i = Booleans.create_expr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i) in Array.init n f (** @@ -5841,7 +5864,7 @@ struct *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in - let f i = (new func_decl ctx)#create_obj (Z3native.get_smtlib_decl (context_gno ctx) i) in + let f i = FuncDecl.create ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f (** @@ -5854,7 +5877,7 @@ struct *) let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in - let f i = (create_sort ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in + let f i = (Sort.create ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in Array.init n f (** @@ -5863,7 +5886,7 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5877,13 +5900,13 @@ struct (Sort.aton sorts) cd (Symbol.aton decl_names) - (func_declaton decls) + (FuncDecl.aton decls) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5897,7 +5920,7 @@ struct (Sort.aton sorts) cd (Symbol.aton decl_names) - (func_declaton decls) + (FuncDecl.aton decls) end From 7eedf1556189b437eb67533bfa1ea11ef62333f5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 5 Feb 2013 00:51:20 +0000 Subject: [PATCH 172/248] ML API: documentation fixes. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 246 +++++++++++++++++++++++++++-------------------- 1 file changed, 141 insertions(+), 105 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 4cf41f420..aeb9c0d03 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -331,8 +331,10 @@ module rec AST : sig type ast = z3_native_object +(**/**) val create : context -> Z3native.ptr -> ast val aton : ast array -> Z3native.ptr array +(**/**) module ASTVectors : sig type ast_vector @@ -346,6 +348,7 @@ sig end = struct type ast = z3_native_object + (**/**) let create ( ctx : context ) ( no : Z3native.ptr ) = let res : z3_native_object = { m_ctx = ctx ; m_n_obj = null ; @@ -358,7 +361,7 @@ end = struct let aton (a : ast array) = let f (e : ast) = (z3obj_gno e) in Array.map f a - + (**/**) (** Vectors of ASTs *) module ASTVectors = @@ -615,7 +618,6 @@ end = struct (**/**) end - (** The Sort module implements type information for ASTs *) and Sort : sig @@ -631,6 +633,7 @@ end = struct type sort = Sort of AST.ast type uninterpreted_sort = UninterpretedSort of sort + (**/**) let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) @@ -657,6 +660,7 @@ end = struct | FINITE_DOMAIN_SORT | RELATION_SORT -> Sort(q) | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + (**/**) (** @@ -728,10 +732,9 @@ sig val get_decl_kind : func_decl -> Z3enums.decl_kind val get_arity : func_decl -> int end = struct - open Sort - type func_decl = FuncDecl of AST.ast + (**/**) let create ( ctx : context ) ( no : Z3native.ptr ) = let res = { m_ctx = ctx ; m_n_obj = null ; @@ -741,7 +744,7 @@ end = struct (z3obj_create res) ; FuncDecl(res) - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort array ) ( range : Sort.sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; @@ -750,7 +753,7 @@ end = struct (z3obj_create res) ; FuncDecl(res) - let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let create_pdr ( ctx : context) ( prefix : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; @@ -766,7 +769,8 @@ end = struct let aton (a : func_decl array) = let f (e : func_decl) = (gno e) in Array.map f a - + (**/**) + (** Parameters of Func_Decls *) module Parameter = struct @@ -833,18 +837,16 @@ end = struct | _ -> raise (Z3native.Exception "parameter is not a rational string") end - open Parameter - (** Creates a new function declaration. *) - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort array ) ( range : Sort.sort ) = create_ndr ctx name domain range (** Creates a new function declaration. *) - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = mk_func_decl ctx (Symbol.mk_string ctx name) domain range (** @@ -852,19 +854,19 @@ end = struct *) - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = create_pdr ctx prefix domain range (** Creates a new constant function declaration. *) - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : Sort.sort ) = create_ndr ctx name [||] range (** Creates a new constant function declaration. *) - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : Sort.sort ) = create_ndr ctx (Symbol.mk_string ctx name) [||] range (** @@ -872,7 +874,7 @@ end = struct *) - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : Sort.sort ) = create_pdr ctx prefix [||] range @@ -945,13 +947,13 @@ end = struct let get_parameters ( x : func_decl ) = let n = (get_num_parameters x) in let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> P_Srt (Sort.create (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> P_Ast (AST.create (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> P_Fdl (create (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> Parameter.P_Srt (Sort.create (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> Parameter.P_Ast (AST.create (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (create (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) ) in mk_list f n @@ -977,6 +979,7 @@ sig type param_descrs = z3_native_object val create : context -> Z3native.ptr -> param_descrs + val validate : param_descrs -> params -> unit end end = struct type params = z3_native_object @@ -998,6 +1001,7 @@ end = struct type param_descrs = z3_native_object val create : context -> Z3native.ptr -> param_descrs + val validate : param_descrs -> params -> unit end = struct type param_descrs = z3_native_object @@ -1025,7 +1029,7 @@ end = struct let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - + (** The size of the ParamDescrs. *) let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) @@ -1092,7 +1096,7 @@ end = struct let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) end -(** General expressions (terms), including Boolean logic *) +(** General expressions (terms) *) and Expr : sig type expr = Expr of AST.ast @@ -1111,6 +1115,7 @@ sig end = struct type expr = Expr of AST.ast + (**/**) let create ( ctx : context ) ( obj : Z3native.ptr ) = if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then (match (Quantifiers.create ctx obj) with Quantifiers.Quantifier(e) -> e) @@ -1148,7 +1153,12 @@ end = struct let gc ( x : expr ) = match x with Expr(a) -> (z3obj_gc a) let gnc ( x : expr ) = match x with Expr(a) -> (z3obj_gnc a) let gno ( x : expr ) = match x with Expr(a) -> (z3obj_gno a) - + + let aton (a : expr array) = + let f (e : expr) = (gno e) in + Array.map f a + (**/**) + (** Returns a simplified version of the expression. @param p A set of parameters to configure the simplifier @@ -1405,10 +1415,6 @@ end = struct *) let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : Sort.sort ) = create ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) - - let aton (a : expr array) = - let f (e : expr) = (gno e) in - Array.map f a end (** Boolean expressions *) @@ -1427,6 +1433,7 @@ end = struct type bool_expr = BoolExpr of Expr.expr type bool_sort = BoolSort of Sort.sort + (**/**) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = let a = (AST.create ctx no) in BoolExpr(Expr.Expr(a)) @@ -1441,6 +1448,7 @@ end = struct let aton ( a : bool_expr array ) = let f (e : bool_expr) = (gno e) in Array.map f a + (**/**) let mk_sort ( ctx : context ) = BoolSort(Sort.create ctx (Z3native.mk_bool_sort (context_gno ctx))) @@ -1542,6 +1550,7 @@ sig end = struct type quantifier = Quantifier of Expr.expr + (**/**) let create ( ctx : context ) ( no : Z3native.ptr ) = let a = (AST.create ctx no) in Quantifier(Expr.Expr(a)) @@ -1549,7 +1558,61 @@ end = struct let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) - + (**/**) + + (** Quantifier patterns + + 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. + *) + module Patterns : + sig + type pattern = Pattern of AST.ast + + val create : context -> Z3native.ptr -> pattern + val aton : pattern array -> Z3native.ptr array + end = struct + type pattern = Pattern of AST.ast + + (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + Pattern(res) + + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) + let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) + let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) + + let aton (a : pattern array) = + let f (e : pattern) = (gno e) in + Array.map f a + (**/**) + + (** + The number of terms in the pattern. + *) + let get_num_terms ( x : pattern ) = + Z3native.get_pattern_num_terms (gnc x) (gno x) + + (** + The terms in the pattern. + *) + let get_terms ( x : pattern ) = + let n = (get_num_terms x) in + let f i = (Expr.create (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in + Array.init n f + + (** + A string representation of the pattern. + *) + let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) + end (** The de-Burijn index of a bound variable. @@ -1575,58 +1638,6 @@ end = struct else Z3native.get_index_value (Expr.gnc x) (Expr.gno x) - (** Quantifier patterns - - 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. - *) - module Patterns : - sig - type pattern = Pattern of AST.ast - - val create : context -> Z3native.ptr -> pattern - val aton : pattern array -> Z3native.ptr array - end = struct - type pattern = Pattern of AST.ast - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - Pattern(res) - - let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) - let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) - let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - - (** - The number of terms in the pattern. - *) - let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms (gnc x) (gno x) - - (** - The terms in the pattern. - *) - let get_terms ( x : pattern ) = - let n = (get_num_terms x) in - let f i = (Expr.create (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in - Array.init n f - - (** - A string representation of the pattern. - *) - let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) - - let aton (a : pattern array) = - let f (e : pattern) = (gno e) in - Array.map f a - end - (** Indicates whether the quantifier is universal. *) @@ -1849,6 +1860,7 @@ end = struct type array_expr = ArrayExpr of Expr.expr type array_sort = ArraySort of Sort.sort + (**/**) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = let e = (Expr.create ctx no) in ArrayExpr(e) @@ -1868,7 +1880,7 @@ end = struct let aton (a : array_expr array) = let f (e : array_expr) = (egno e) in Array.map f a - + (**/**) (** Create a new array sort. @@ -2120,6 +2132,7 @@ sig end = struct type finite_domain_sort = FiniteDomainSort of Sort.sort + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = let s = (Sort.create ctx no) in FiniteDomainSort(s) @@ -2127,7 +2140,8 @@ end = struct let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gc s) let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gnc s) let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s))-> (z3obj_gno s) - + (**/**) + (** Create a new finite domain sort. *) @@ -2168,6 +2182,7 @@ sig end = struct type relation_sort = RelationSort of Sort.sort + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = let s = (Sort.create ctx no) in RelationSort(s) @@ -2175,7 +2190,8 @@ end = struct let gc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gc s) let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gnc s) let gno ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s))-> (z3obj_gno s) - + (**/**) + (** Indicates whether the term is of a relation sort. *) @@ -2306,6 +2322,7 @@ end = struct type datatype_expr = DatatypeExpr of Expr.expr type datatype_sort = DatatypeSort of Sort.sort + (**/**) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = let e = (Expr.create ctx no) in DatatypeExpr(e) @@ -2317,19 +2334,24 @@ end = struct let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gc s) let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gnc s) let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s))-> (z3obj_gno s) - + (**/**) (** Constructors *) - module Constructor = - struct + module Constructor : sig + type constructor + val create : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> constructor + val aton : constructor array -> Z3native.ptr array + end = struct type constructor_extra = { m_n : int; mutable m_tester_decl : FuncDecl.func_decl option; mutable m_constructor_decl : FuncDecl.func_decl option ; mutable m_accessor_decls : FuncDecl.func_decl array option} + type constructor = Constructor of (z3_native_object * constructor_extra) - let create_ssssi ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = + (**/**) + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -2356,6 +2378,10 @@ end = struct let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; Constructor(no, ex) + + let aton ( a : constructor array ) = + let f (e : constructor) = match e with Constructor(no, ex) -> (z3obj_gno no)in + Array.map f a let init_extra ( x : constructor ) = match x with Constructor(no, ex) -> @@ -2367,7 +2393,8 @@ end = struct ex.m_accessor_decls <- Some (let f e = (FuncDecl.create (z3obj_gc no) e) in Array.map f c) ; () | _ -> () - + (**/**) + let get_n ( x : constructor ) = match x with Constructor(no, ex) -> ex.m_n @@ -2389,12 +2416,7 @@ end = struct match ex.m_accessor_decls with | Some(s) -> s | None -> init_extra x ; accessor_decls x - - let aton ( a : constructor array ) = - let f (e : constructor) = match e with Constructor(no, ex) -> (z3obj_gno no)in - Array.map f a - - + (** The number of fields of the constructor. *) let get_num_fields ( x : constructor ) = get_n x @@ -2413,6 +2435,7 @@ end = struct struct type constructor_list = z3_native_object + (**/**) let create ( ctx : context )( c : Constructor.constructor array ) = let res : constructor_list = { m_ctx = ctx ; m_n_obj = null ; @@ -2427,6 +2450,7 @@ end = struct let aton (a : constructor_list array) = let f (e : constructor_list) = (z3obj_gno e) in Array.map f a + (**/**) end (* DATATYPES *) @@ -2441,7 +2465,7 @@ end = struct referring to one of the recursive datatypes that is declared. *) let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array) = - Constructor.create_ssssi ctx name recognizer field_names sorts sort_refs + Constructor.create ctx name recognizer field_names sorts sort_refs (** @@ -2530,6 +2554,7 @@ end = struct mutable _testerdecls : FuncDecl.func_decl array } type enum_sort = EnumSort of (Sort.sort * enum_sort_data) + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = let s = (Sort.create ctx no) in let e = { _constdecls = (let f e = FuncDecl.create ctx e in (Array.map f cdecls)) ; @@ -2539,7 +2564,7 @@ end = struct let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gc s) let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gnc s) let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_)-> (z3obj_gno s) - + (**/**) (** Create a new enumeration sort. @@ -2576,6 +2601,7 @@ end = struct _taildecl : FuncDecl.func_decl } type list_sort = ListSort of (Sort.sort * list_sort_data) + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = let s = (Sort.create ctx no) in let e = {_nildecl = FuncDecl.create ctx nildecl; @@ -2589,7 +2615,7 @@ end = struct let sgc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gc s) let sgnc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gnc s) let sgno ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_)-> (z3obj_gno s) - + (**/**) (** Create a new list sort. *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : Sort.sort ) = @@ -2629,6 +2655,7 @@ sig end = struct type tuple_sort = TupleSort of Sort.sort + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = let s = (Sort.create ctx no) in TupleSort(s) @@ -2636,6 +2663,7 @@ end = struct let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gc s) let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gnc s) let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s))-> (z3obj_gno s) + (**/**) (** Create a new tuple sort. *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : Sort.sort array ) = @@ -2736,6 +2764,7 @@ end = struct type arith_sort = ArithSort of Sort.sort type arith_expr = ArithExpr of Expr.expr + (**/**) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = ArithExpr(Expr.create ctx no) @@ -2749,6 +2778,10 @@ end = struct let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) + let aton (a : arith_expr array) = + let f (e : arith_expr) = (egno e) in + Array.map f a + (**/**) module rec Integers : sig @@ -2764,6 +2797,7 @@ end = struct type int_expr = IntExpr of arith_expr type int_num = IntNum of int_expr + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = IntSort(Arithmetic.create_sort ctx no) @@ -2782,6 +2816,7 @@ end = struct let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) + (**/**) (** Create a new integer sort. *) let mk_sort ( ctx : context ) = @@ -2878,6 +2913,7 @@ end = struct type real_expr = RealExpr of arith_expr type rat_num = RatNum of real_expr + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = RealSort(Arithmetic.create_sort ctx no) @@ -2896,7 +2932,8 @@ end = struct let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - + (**/**) + (** Create a real sort. *) let mk_sort ( ctx : context ) = create_sort ctx (Z3native.mk_real_sort (context_gno ctx)) @@ -2979,12 +3016,14 @@ end = struct end = struct type algebraic_num = AlgebraicNum of arith_expr + (**/**) let create_num ( ctx : context ) ( no : Z3native.ptr ) = AlgebraicNum(Arithmetic.create_expr ctx no) let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) + (**/**) (** Return a upper bound for a given real algebraic number. @@ -3015,10 +3054,6 @@ end = struct let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) end - let aton (a : arith_expr array) = - let f (e : arith_expr) = (egno e) in - Array.map f a - (** Indicates whether the term is of integer sort. *) @@ -3188,7 +3223,6 @@ end = struct Booleans.create_expr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2)) end - (** Functions to manipulate bit-vector expressions *) and BitVectors : sig @@ -3204,6 +3238,7 @@ end = struct type bitvec_expr = BitVecExpr of Expr.expr type bitvec_num = BitVecNum of bitvec_expr + (**/**) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = BitVecSort(Sort.create ctx no) @@ -3222,6 +3257,7 @@ end = struct let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) + (**/**) (** Create a new bit-vector sort. From 7ec027dadb4ae56497ce8b9aaadfe2000d701ef8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 19:49:27 +0000 Subject: [PATCH 173/248] ML API: basic structure and interface Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 81 +- scripts/update_api.py | 30 +- src/api/ml/Makefile | 2 +- src/api/ml/z3.ml | 2714 +++++++++++++++++++---------------------- 4 files changed, 1380 insertions(+), 1447 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 1d3412c30..cfea8d0f1 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1350,10 +1350,17 @@ class MLComponent(Component): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) + cmis = '%s/z3enums.cmi %s/z3native.cmi %s/z3.cmi' % (src_dir,src_dir,src_dir) + out.write('%s/z3enums.cmi: %s/z3enums.mli\n' % (src_dir,src_dir)) + out.write('\t%s -I %s -c %s/z3enums.mli\n' % (OCAMLC,src_dir,src_dir)) + out.write('%s/z3native.cmi: %s/z3native.mli\n' % (src_dir,src_dir)) + out.write('\t%s -I %s -c %s/z3native.mli\n' % (OCAMLC,src_dir,src_dir)) + out.write('%s/z3.cmi: %s/z3.mli\n' % (src_dir,src_dir)) + out.write('\t%s -I %s -c %s/z3.mli\n' % (OCAMLC,src_dir,src_dir)) out.write('api/ml/libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, src_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') - out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(src_dir, mlfile)) out.write('\n') @@ -1361,7 +1368,7 @@ class MLComponent(Component): if DEBUG_MODE: out.write('-g ') out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) - out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT)' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) out.write('\n') @@ -2732,6 +2739,76 @@ def mk_z3consts_ml(api_files): efile.write('end\n') if VERBOSE: print "Generated '%s/z3enums.ml'" % ('%s' % gendir) + efile = open('%s.mli' % os.path.join(gendir, "z3enums"), 'w') + efile.write('(* Automatically generated file *)\n\n') + efile.write('(** The enumeration types of Z3. *)\n\n') + for api_file in api_files: + api_file_c = ml.find_file(api_file, ml.name) + api_file = os.path.join(api_file_c.src_dir, api_file) + + api = open(api_file, 'r') + + SEARCHING = 0 + FOUND_ENUM = 1 + IN_ENUM = 2 + + mode = SEARCHING + decls = {} + idx = 0 + + linenum = 1 + for line in api: + m1 = blank_pat.match(line) + m2 = comment_pat.match(line) + if m1 or m2: + # skip blank lines and comments + linenum = linenum + 1 + elif mode == SEARCHING: + m = typedef_pat.match(line) + if m: + mode = FOUND_ENUM + m = typedef2_pat.match(line) + if m: + mode = IN_ENUM + decls = {} + idx = 0 + elif mode == FOUND_ENUM: + m = openbrace_pat.match(line) + if m: + mode = IN_ENUM + decls = {} + idx = 0 + else: + assert False, "Invalid %s, line: %s" % (api_file, linenum) + else: + assert mode == IN_ENUM + words = re.split('[^\-a-zA-Z0-9_]+', line) + m = closebrace_pat.match(line) + if m: + name = words[1] + if name not in DeprecatedEnums: + efile.write('(** %s *)\n' % name[3:]) + efile.write('type %s =\n' % name[3:]) # strip Z3_ + for k, i in decls.iteritems(): + efile.write(' | %s \n' % k[3:]) # strip Z3_ + efile.write('\n') + efile.write('(** Convert %s to int*)\n' % name[3:]) + efile.write('val int_of_%s : %s -> int\n' % (name[3:], name[3:])) # strip Z3_ + efile.write('(** Convert int to %s*)\n' % name[3:]) + efile.write('val %s_of_int : int -> %s\n' % (name[3:],name[3:])) # strip Z3_ + efile.write('\n') + mode = SEARCHING + else: + if words[2] != '': + if len(words[2]) > 1 and words[2][1] == 'x': + idx = int(words[2], 16) + else: + idx = int(words[2]) + decls[words[1]] = idx + idx = idx + 1 + linenum = linenum + 1 + if VERBOSE: + print "Generated '%s/z3enums.mli'" % ('%s' % gendir) def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index c730a325e..6e9c14355 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1147,49 +1147,66 @@ def mk_ml(): return ml_dir = get_component('ml').src_dir ml_nativef = os.path.join(ml_dir, 'z3native.ml') + ml_nativefi = os.path.join(ml_dir, 'z3native.mli') ml_wrapperf = os.path.join(ml_dir, 'z3native.c') ml_native = open(ml_nativef, 'w') + ml_i = open(ml_nativefi, 'w') ml_native.write('(* Automatically generated file *)\n\n') ml_native.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') + ml_i.write('(* Automatically generated file *)\n\n') + ml_i.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') ml_native.write('open Z3enums\n\n') ml_native.write('(**/**)\n') ml_native.write('type ptr\n') + ml_i.write('type ptr\n') ml_native.write('and z3_symbol = ptr\n') + ml_i.write('and z3_symbol = ptr\n') for k, v in Type2Str.iteritems(): if is_obj(k): ml_native.write('and %s = ptr\n' % v.lower()) + ml_i.write('and %s = ptr\n' % v.lower()) ml_native.write('\n') - ml_native.write('external is_null : ptr -> bool\n') - ml_native.write(' = "n_is_null"\n\n') - ml_native.write('external mk_null : unit -> ptr\n') - ml_native.write(' = "n_mk_null"\n\n') + ml_i.write('\n') + ml_native.write('external is_null : ptr -> bool\n = "n_is_null"\n\n') + ml_native.write('external mk_null : unit -> ptr\n = "n_mk_null"\n\n') ml_native.write('exception Exception of string\n\n') + ml_i.write('val is_null : ptr -> bool\n') + ml_i.write('val mk_null : unit -> ptr\n') + ml_i.write('exception Exception of string\n\n') # ML declarations - ml_native.write(' module ML2C = struct\n\n') + ml_native.write('module ML2C = struct\n\n') for name, result, params in _dotnet_decls: ml_native.write(' external n_%s : ' % ml_method_name(name)) + ml_i.write('val %s : ' % ml_method_name(name)) ip = inparams(params) op = outparams(params) if len(ip) == 0: - ml_native.write(' unit -> ') + ml_native.write(' unit -> ') for p in ip: ml_native.write('%s -> ' % param2ml(p)) + ml_i.write('%s -> ' % param2ml(p)) if len(op) > 0: ml_native.write('(') + ml_i.write('(') first = True if result != VOID or len(op) == 0: ml_native.write('%s' % type2ml(result)) + ml_i.write('%s' % type2ml(result)) first = False for p in op: if first: first = False else: ml_native.write(' * ') + ml_i.write(' * ') ml_native.write('%s' % param2ml(p)) + ml_i.write('%s' % param2ml(p)) if len(op) > 0: ml_native.write(')') + ml_i.write(')') ml_native.write('\n') + ml_i.write('\n') ml_native.write(' = "n_%s"\n' % ml_method_name(name)) if len(ip) > 5: ml_native.write(' "n_%s_bytecode"\n' % ml_method_name(name)) @@ -1201,6 +1218,7 @@ def mk_ml(): ip = inparams(params) op = outparams(params) ml_native.write(' let %s ' % ml_method_name(name)) + first = True i = 0; for p in params: diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile index ad5442327..abcefa4af 100644 --- a/src/api/ml/Makefile +++ b/src/api/ml/Makefile @@ -7,4 +7,4 @@ all: doc: *.ml mkdir -p doc - ocamldoc -html -d doc -I ../../../bld_dbg/api/ml -sort *.ml -hide Z3 + ocamldoc -html -d doc -I ../../../bld_dbg/api/ml -sort *.mli -hide Z3 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index aeb9c0d03..ea8c9576e 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,8 +7,479 @@ open Z3enums -(** Interaction logging for Z3 +(* Some helpers. *) +let null = Z3native.mk_null() +let is_null o = (Z3native.is_null o) + +(* Internal types *) +type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } +type context = z3_native_context + + + +type z3_native_object = { + m_ctx : context ; + mutable m_n_obj : Z3native.ptr ; + inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; + dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } + + +(* Symbol types *) +type int_symbol = z3_native_object +type string_symbol = z3_native_object + +type symbol = + | S_Int of int_symbol + | S_Str of string_symbol + +(* AST types *) +type ast = z3_native_object +type ast_vector = z3_native_object +type ast_map = z3_native_object + +(* FuncDecl types *) +type func_decl = FuncDecl of ast + +(* Sort types *) +type sort = Sort of ast +type uninterpreted_sort = UninterpretedSort of sort +type bool_sort = BoolSort of sort +type array_sort = ArraySort of sort +type set_sort = SetSort of sort +type datatype_sort = DatatypeSort of sort +type relation_sort = RelationSort of sort +type finite_domain_sort = FiniteDomainSort of sort +type enum_sort = EnumSort of sort +type list_sort = ListSort of sort +type tuple_sort = TupleSort of sort +type arith_sort = ArithSort of sort +type bitvec_sort = BitVecSort of sort + +type int_sort = IntSort of arith_sort +type real_sort = RealSort of arith_sort + +(* FuncDecl parameters *) +type parameter = + | P_Int of int + | P_Dbl of float + | P_Sym of symbol + | P_Srt of sort + | P_Ast of ast + | P_Fdl of func_decl + | P_Rat of string +type params = z3_native_object +type param_descrs = z3_native_object + +(* Expr types *) +type expr = Expr of ast + +type bool_expr = BoolExpr of expr +type arith_expr = ArithExpr of expr +type int_expr = IntExpr of arith_expr +type real_expr = RealExpr of arith_expr +type bitvec_expr = BitVecExpr of expr +type array_expr = ArrayExpr of expr +type datatype_expr = DatatypeExpr of expr + +(* Numerals *) +type int_num = IntNum of int_expr +type rat_num = RatNum of real_expr +type algebraic_num = AlgebraicNum of arith_expr +type bitvec_num = BitVecNum of bitvec_expr + +(* Quantifier stuff *) +type quantifier = Quantifier of expr +type pattern = Pattern of ast + +(* Datatype stuff *) +type constructor_extra = { + m_n : int; + mutable m_tester_decl : func_decl option; + mutable m_constructor_decl : func_decl option ; + mutable m_accessor_decls : func_decl array option} + +type constructor = Constructor of (z3_native_object * constructor_extra) +type constructor_list = z3_native_object + +(* Tactical interface *) +type goal = z3_native_object +type model = z3_native_object +type func_interp = z3_native_object +type func_entry = z3_native_object +type probe = z3_native_object +type tactic = z3_native_object +type apply_result = z3_native_object +type solver = z3_native_object +type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE +type statistics = z3_native_object +type statistics_entry = { + mutable m_key : string; + mutable m_is_int : bool ; + mutable m_is_float : bool ; + mutable m_int : int ; + mutable m_float : float } +type fixedpoint = z3_native_object + + +(** Internal stuff *) +module Internal = +struct + let dispose_context ctx = + if ctx.m_n_obj_cnt == 0 then ( + (* Printf.printf "Disposing context \n" ; *) + (Z3native.del_context ctx.m_n_ctx) + ) else ( + Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; + (* re-queue for finalization? *) + ) + + let create_context settings = + let cfg = Z3native.mk_config in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = Z3native.mk_context_rc cfg in + Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + (* Printf.printf "Installing finalizer on context \n" ; *) + let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in + let f = fun o -> dispose_context o in + Gc.finalise f res; + res + (* CMW: Install error handler here! + m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. + Z3native.set_error_handler(m_ctx, m_n_err_handler); + GC.SuppressFinalize(this); + *) + + let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) + let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) + let context_gno ctx = ctx.m_n_ctx + + + let z3obj_gc o = o.m_ctx + let z3obj_gnc o = (context_gno o.m_ctx) + + let z3obj_gno o = o.m_n_obj + let z3obj_sno o ctx no = + (context_add1 ctx) ; + o.inc_ref (context_gno ctx) no ; + ( + if not (is_null o.m_n_obj) then + o.dec_ref (context_gno ctx) o.m_n_obj ; + (context_sub1 ctx) + ) ; + o.m_n_obj <- no + + let z3obj_dispose o = + if not (is_null o.m_n_obj) then + ( + o.dec_ref (z3obj_gnc o) o.m_n_obj ; + (context_sub1 (z3obj_gc o)) + ) ; + o.m_n_obj <- null + + let z3obj_create o = + let f = fun o -> (z3obj_dispose o) in + Gc.finalise f o + + let z3obj_nil_ref x y = () + + let array_to_native a = + let f e = (z3obj_gno e) in + Array.map f a + + (* Internal coercions *) + let context_of_ast ( x : ast ) = (z3obj_gc x) + let nc_of_ast ( x : ast ) = (z3obj_gnc x) + let ptr_of_ast ( x : ast ) = (z3obj_gno x) + + let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) + let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) + let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) + + + let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> + let res : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> + let q = (z3_native_object_of_ast_ptr ctx no) in + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then + raise (Z3native.Exception "Invalid coercion") + else + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with + | ARRAY_SORT + | BOOL_SORT + | BV_SORT + | DATATYPE_SORT + | INT_SORT + | REAL_SORT + | UNINTERPRETED_SORT + | FINITE_DOMAIN_SORT + | RELATION_SORT -> Sort(q) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + + let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + FuncDecl(z3_native_object_of_ast_ptr ctx no) + + let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with + | FUNC_DECL_AST + | SORT_AST + | QUANTIFIER_AST + | APP_AST + | NUMERAL_AST + | VAR_AST -> z3_native_object_of_ast_ptr ctx no + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") + + and expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then + Expr(z3_native_object_of_ast_ptr ctx no) + else + let s = Z3native.get_sort (context_gno ctx) no in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) no) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + if (Z3native.is_numeral_ast (context_gno ctx) no) then + if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + raise (Z3native.Exception "Unsupported numeral object") + else + Expr(z3_native_object_of_ast_ptr ctx no) + + let expr_aton ( a : expr array ) = + let f ( e : expr ) = match e with Expr(a) -> (ptr_of_ast a) in + Array.map f a + + let expr_of_func_app : context -> func_decl -> expr array -> expr = fun ctx f args -> + match f with FuncDecl(fa) -> + let o = Z3native.mk_app (context_gno ctx) (ptr_of_ast fa) (Array.length args) (expr_aton args) in + expr_of_ptr ctx o +end + + +open Internal + + + +(* Sort coercions *) +let ast_of_sort s = match s with Sort(x) -> x +let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x +let sort_of_bool_sort s = match s with BoolSort(x) -> x +let sort_of_array_sort s = match s with ArraySort(x) -> x +let sort_of_set_sort s = match s with SetSort(x) -> x +let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x +let sort_of_relation_sort s = match s with RelationSort(x) -> x +let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x +let sort_of_enum_sort s = match s with EnumSort(x) -> x +let sort_of_list_sort s = match s with ListSort(x) -> x +let sort_of_tuple_sort s = match s with TupleSort(x) -> x +let sort_of_arith_sort s = match s with ArithSort(x) -> x +let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x +let arith_sort_of_int_sort s = match s with IntSort(x) -> x +let arith_sort_of_real_sort s = match s with RealSort(x) -> x + +let uninterpreted_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + UninterpretedSort(s) + +let bool_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolSort(s) + +let array_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArraySort(s) + +let datatype_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeSort(s) + +let relation_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RelationSort(s) + +let finite_domain_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + FiniteDomainSort(s) + +let arith_sort_of_sort s = match s with Sort(a) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithSort(s) + +let bitvec_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecSort(s) + +let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntSort(s) + +let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealSort(s) + +(* FuncDecl coercions *) +let ast_of_func_decl f = match f with FuncDecl(x) -> x + +(* Expr coercions *) +let ast_of_expr e = match e with Expr(a) -> a +let expr_of_bool_expr e = match e with BoolExpr(x) -> x +let expr_of_arith_expr e = match e with ArithExpr(x) -> x +let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x +let expr_of_array_expr e = match e with ArrayExpr(x) -> x +let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x + +let arith_expr_of_int_expr e = match e with IntExpr(x) -> x +let arith_expr_of_real_expr e = match e with RealExpr(x) -> x + +let int_expr_of_int_num e = match e with IntNum(x) -> x +let real_expr_of_rat_num e = match e with RatNum(x) -> x +let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x +let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x + +let expr_of_quantifier e = match e with Quantifier(x) -> x +let ast_of_pattern e = match e with Pattern(x) -> x + + +let expr_of_ast a = + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Expr(a) + +let bool_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolExpr(e) + +let arith_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithExpr(e) + +let bitvec_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecExpr(e) + +let array_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArrayExpr(e) + +let datatype_expr_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeExpr(e) + +let int_expr_of_arith_expr e = + match e with ArithExpr(Expr(no)) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntExpr(e) + +let real_expr_of_arith_expr e = + match e with ArithExpr(Expr(no)) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealExpr(e) + +let int_num_of_int_expr e = + match e with IntExpr(ArithExpr(Expr(no))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + raise (Z3native.Exception "Invalid coercion") + else + IntNum(e) + +let rat_num_of_real_expr e = + match e with RealExpr(ArithExpr(Expr(no))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + raise (Z3native.Exception "Invalid coercion") + else + RatNum(e) + +let algebraic_num_of_arith_expr e = + match e with ArithExpr(Expr(no)) -> + if (not (Z3native.is_algebraic_number (z3obj_gnc no) (z3obj_gno no))) then + raise (Z3native.Exception "Invalid coercion") + else + AlgebraicNum(e) + +let bitvec_num_of_bitvec_expr e = + match e with BitVecExpr(Expr(no)) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecNum(e) + +let quantifier_of_expr e = + match e with Expr(no) -> + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc no) (z3obj_gno no))) in + if (q != Z3enums.QUANTIFIER_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Quantifier(e) + +let pattern_of_ast a = + (* CMW: Unchecked ok? *) + Pattern(a) + + + +(** 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. *) module Log = @@ -28,6 +499,7 @@ struct let append s = Z3native.append_log s end + (** Version information *) module Version = struct @@ -52,11 +524,6 @@ struct string_of_int rev ^ "." end -(**/**) -(* Some helpers. *) - -let null = Z3native.mk_null() -let is_null o = (Z3native.is_null o) let mk_list ( f : int -> 'a ) ( n : int ) = let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = @@ -66,49 +533,8 @@ let mk_list ( f : int -> 'a ) ( n : int ) = (mk_list' f (i+1) n ((f i) :: tail)) in mk_list' f 0 n [] -(**/**) -(**/**) -type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } -(**/**) -type context = z3_native_context - -(**/**) - -let context_dispose ctx = - if ctx.m_n_obj_cnt == 0 then ( - (* Printf.printf "Disposing context \n" ; *) - (Z3native.del_context ctx.m_n_ctx) - ) else ( - Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; - (* re-queue for finalization? *) - ) - -let context_create settings = - let cfg = Z3native.mk_config in - let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in - (List.iter f settings) ; - let v = Z3native.mk_context_rc cfg in - Z3native.del_config(cfg) ; - Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; - (* Printf.printf "Installing finalizer on context \n" ; *) - let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in - let f = fun o -> context_dispose o in - Gc.finalise f res; - res -(* CMW: Install error handler here! - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); -*) - -let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) -let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) -let context_gno ctx = ctx.m_n_ctx - -(**/**) - (** Create a context object. Most interactions with Z3 are interpreted in some context; many users will only @@ -130,113 +556,14 @@ let context_gno ctx = ctx.m_n_ctx *) let mk_context ( cfg : ( string * string ) list ) = - context_create cfg + create_context cfg -(**/**) -class virtual z3object ctx_init obj_init = -object (self) - val mutable m_ctx : context = ctx_init - val mutable m_n_obj : Z3native.ptr option = obj_init - - initializer - (match m_n_obj with - | Some (x) -> self#incref (context_gno m_ctx) x; - (context_add1 m_ctx) - | None -> () - ); - (* Printf.printf "Installing finalizer on z3object %d \n" (Oo.id self) ; *) - let f = fun o -> o#dispose in - let v = self in - Gc.finalise f v - - method virtual incref : Z3native.ptr -> Z3native.ptr -> unit - method virtual decref : Z3native.ptr -> Z3native.ptr -> unit - - method dispose = - (* Printf.printf "Disposing z3object %d \n" (Oo.id self) ; *) - (match m_n_obj with - | Some (x) -> - self#decref (context_gno m_ctx) x; - (context_sub1 m_ctx) ; - m_n_obj <- None; - | None -> () - ); - - method gno = match m_n_obj with - | Some(x) -> x - | None -> raise (Z3native.Exception "Z3 object lost") - - method sno (ctx : context) o = - (context_add1 m_ctx) ; - self#incref (context_gno ctx) o ; - (match m_n_obj with - | Some(x) -> self#decref (context_gno ctx) x ; (context_sub1 m_ctx) - | None -> () - ); - m_n_obj <- Some o - - method gc = m_ctx - method gnc = (context_gno m_ctx) -end - - - -type z3_native_object = { - m_ctx : context ; - mutable m_n_obj : Z3native.ptr ; - inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; - dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - -let z3obj_gc o = o.m_ctx -let z3obj_gnc o = (context_gno o.m_ctx) - -let z3obj_gno o = o.m_n_obj -let z3obj_sno o ctx no = - (context_add1 ctx) ; - o.inc_ref (context_gno ctx) no ; - ( - if not (is_null o.m_n_obj) then - o.dec_ref (context_gno ctx) o.m_n_obj ; - (context_sub1 ctx) - ) ; - o.m_n_obj <- no - -let z3obj_dispose o = - if not (is_null o.m_n_obj) then - ( - o.dec_ref (z3obj_gnc o) o.m_n_obj ; - (context_sub1 (z3obj_gc o)) - ) ; - o.m_n_obj <- null - -let z3obj_create o = - let f = fun o -> (z3obj_dispose o) in - Gc.finalise f o - -let z3obj_nil_ref x y = () - -let array_to_native a = - let f e = (z3obj_gno e) in - Array.map f a -(**/**) (** Symbols are used to name several term and type constructors *) module Symbol = -struct - (** Int symbol objects *) - type int_symbol = z3_native_object - - (** String symbol objects *) - type string_symbol = z3_native_object - - (** Symbol Objects *) - type symbol = - | S_Int of int_symbol - | S_Str of string_symbol - - (**/**) +struct let create_i ( ctx : context ) ( no : Z3native.ptr ) = let res : int_symbol = { m_ctx = ctx ; m_n_obj = null ; @@ -255,6 +582,11 @@ struct (z3obj_create res) ; res + let create ( ctx : context ) ( no : Z3native.ptr ) = + match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with + | INT_SYMBOL -> S_Int (create_i ctx no) + | STRING_SYMBOL -> S_Str (create_s ctx no) + let gc ( x : symbol ) = match x with | S_Int(n) -> (z3obj_gc n) @@ -269,17 +601,7 @@ struct match x with | S_Int(n) -> (z3obj_gno n) | S_Str(n) -> (z3obj_gno n) - - let create ( ctx : context ) ( no : Z3native.ptr ) = - match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> S_Int (create_i ctx no) - | STRING_SYMBOL -> S_Str (create_s ctx no) - - let aton a = - let f e = (gno e) in - Array.map f a - (**/**) - + (** The kind of the symbol (int or string) *) let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) @@ -327,48 +649,11 @@ end (** The abstract syntax tree (AST) module *) -module rec AST : -sig - type ast = z3_native_object - -(**/**) - val create : context -> Z3native.ptr -> ast - val aton : ast array -> Z3native.ptr array -(**/**) - - module ASTVectors : sig - type ast_vector - val create : context -> Z3native.ptr -> ast_vector - val get_size : ast_vector -> int - val get : ast_vector -> int -> ast - end - - val is_expr : ast -> bool - val is_var : ast -> bool -end = struct - type ast = z3_native_object - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let aton (a : ast array) = - let f (e : ast) = (z3obj_gno e) in - Array.map f a - (**/**) - +module AST = +struct (** Vectors of ASTs *) - module ASTVectors = + module ASTVector = struct - type ast_vector = z3_native_object - - (**/**) let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; @@ -377,7 +662,7 @@ end = struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** The size of the vector *) let get_size ( x : ast_vector ) = @@ -411,7 +696,7 @@ end = struct (** Translates all ASTs in the vector to . @param to_ctx A context - @return A new ASTVectors + @return A new ASTVector *) let translate ( x : ast_vector ) ( to_ctx : context ) = create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) @@ -423,10 +708,8 @@ end = struct (** Map from AST to AST *) module ASTMap = - struct - type ast_map = z3_native_object - - (**/**) + struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_map = { m_ctx = ctx ; m_n_obj = null ; @@ -435,7 +718,7 @@ end = struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Checks whether the map contains the key . @param k An AST @@ -476,7 +759,7 @@ end = struct (** The keys stored in the map. *) let get_keys ( x : ast_map ) = - ASTVectors.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) (** Retrieves a string representation of the map.*) let to_string ( x : ast_map ) = @@ -576,7 +859,7 @@ end = struct if (z3obj_gnc x) == (context_gno to_ctx) then x else - create to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Wraps an AST. @@ -590,7 +873,7 @@ end = struct @param nativeObject The native pointer to wrap. *) let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = - create ctx ptr + ast_of_ptr ctx ptr (** Unwraps an AST. @@ -603,66 +886,17 @@ end = struct @param a The AST to unwrap. *) - let unwrap_ast ( x : ast ) = (z3obj_gno x) - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST -> (match (FuncDecl.create ctx no) with FuncDecl.FuncDecl(x) -> x) - | SORT_AST -> (match (Sort.create ctx no) with Sort.Sort(x) -> x) - | QUANTIFIER_AST -> (match (Quantifiers.create ctx no) with Quantifiers.Quantifier(Expr.Expr(x)) -> x) - | APP_AST - | NUMERAL_AST - | VAR_AST -> (match (Expr.create ctx no) with Expr.Expr(x) -> x) - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") -(**/**) + let unwrap_ast ( x : ast ) = (z3obj_gno x) end (** The Sort module implements type information for ASTs *) -and Sort : -sig - type sort = Sort of AST.ast - type uninterpreted_sort = UninterpretedSort of sort - - val create : context -> Z3native.ptr -> sort - val gc : sort -> context - val gnc : sort -> Z3native.ptr - val gno : sort -> Z3native.ptr - val aton : sort array -> Z3native.ptr array -end = struct - type sort = Sort of AST.ast - type uninterpreted_sort = UninterpretedSort of sort - - (**/**) +module Sort = +struct + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) - let aton : sort array -> Z3native.ptr array = fun a -> - let f e = (gno e) in - Array.map f a - - let create : context -> Z3native.ptr -> sort = fun ctx no -> - let q : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno q ctx no) ; - (z3obj_create q) ; - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with - | ARRAY_SORT - | BOOL_SORT - | BV_SORT - | DATATYPE_SORT - | INT_SORT - | REAL_SORT - | UNINTERPRETED_SORT - | FINITE_DOMAIN_SORT - | RELATION_SORT -> Sort(q) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - (**/**) - - (** Comparison operator. @param a A sort @@ -700,7 +934,7 @@ end = struct (** Create a new uninterpreted sort. *) - let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = + let mk_uninterpreted ( ctx : context ) ( s : symbol ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; @@ -718,71 +952,37 @@ end (** Function declarations *) -and FuncDecl : -sig - type func_decl = FuncDecl of AST.ast - - val create : context -> Z3native.ptr -> func_decl - val gc : func_decl -> context - val gno : func_decl -> Z3native.ptr - val gnc : func_decl -> Z3native.ptr - val aton : func_decl array -> Z3native.ptr array - - val get_domain_size : func_decl -> int - val get_decl_kind : func_decl -> Z3enums.decl_kind - val get_arity : func_decl -> int -end = struct - type func_decl = FuncDecl of AST.ast - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - FuncDecl(res) - - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort array ) ( range : Sort.sort ) = +module FuncDecl = +struct + (**/**) + let create_ndr ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Sort.aton domain) (Sort.gno range))) ; + let f x = (ptr_of_ast (ast_of_sort x)) in + (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Array.map f domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) - let create_pdr ( ctx : context) ( prefix : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = + let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort array ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Sort.aton domain) (Sort.gno range))) ; + let f x = (ptr_of_ast (ast_of_sort x)) in + (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Array.map f domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - - let aton (a : func_decl array) = - let f (e : func_decl) = (gno e) in - Array.map f a - (**/**) + (**/**) (** Parameters of Func_Decls *) module Parameter = - struct - type parameter = - | P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - + struct (** The kind of the parameter. *) let get_kind ( x : parameter ) = (match x with @@ -840,13 +1040,13 @@ end = struct (** Creates a new function declaration. *) - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort array ) ( range : Sort.sort ) = + let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort ) = create_ndr ctx name domain range (** Creates a new function declaration. *) - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = mk_func_decl ctx (Symbol.mk_string ctx name) domain range (** @@ -854,19 +1054,19 @@ end = struct *) - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : Sort.sort array ) ( range : Sort.sort ) = + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = create_pdr ctx prefix domain range (** Creates a new constant function declaration. *) - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : Sort.sort ) = + let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort ) = create_ndr ctx name [||] range (** Creates a new constant function declaration. *) - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : Sort.sort ) = + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = create_ndr ctx (Symbol.mk_string ctx name) [||] range (** @@ -874,7 +1074,7 @@ end = struct *) - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : Sort.sort ) = + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = create_pdr ctx prefix [||] range @@ -917,14 +1117,14 @@ end = struct *) let get_domain ( x : func_decl ) = let n = (get_domain_size x) in - let f i = Sort.create (gc x) (Z3native.get_domain (gnc x) (gno x) i) in + let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in Array.init n f (** The range of the function declaration *) let get_range ( x : func_decl ) = - Sort.create (gc x) (Z3native.get_range (gnc x) (gno x)) + sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) (** The kind of the function declaration. @@ -947,13 +1147,13 @@ end = struct let get_parameters ( x : func_decl ) = let n = (get_num_parameters x) in let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> Parameter.P_Srt (Sort.create (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> Parameter.P_Ast (AST.create (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (create (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + | PARAMETER_INT -> P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> P_Ast (ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) ) in mk_list f n @@ -961,7 +1161,7 @@ end = struct Create expression that applies function to arguments. @param args The arguments *) - let apply ( x : func_decl ) ( args : Expr.expr array ) = Expr.create_fa (gc x) x args + let apply ( x : func_decl ) ( args : expr array ) = expr_of_func_app (gc x) x args end (** @@ -969,43 +1169,12 @@ end A Params objects represents a configuration in the form of symbol/value pairs. *) -and Params : -sig - type params = z3_native_object - - val create : context -> Z3native.ptr -> params - - module ParamDescrs : sig - type param_descrs = z3_native_object - - val create : context -> Z3native.ptr -> param_descrs - val validate : param_descrs -> params -> unit - end -end = struct - type params = z3_native_object - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : params = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.params_inc_ref ; - dec_ref = Z3native.params_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - (**/**) - +module Params = +struct (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) - module ParamDescrs : - sig - type param_descrs = z3_native_object - - val create : context -> Z3native.ptr -> param_descrs - val validate : param_descrs -> params -> unit - end = struct - type param_descrs = z3_native_object - - (**/**) + module ParamDescrs = + struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : param_descrs = { m_ctx = ctx ; m_n_obj = null ; @@ -1014,14 +1183,14 @@ end = struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Validate a set of parameters. *) let validate ( x : param_descrs ) ( p : params ) = Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = + let get_kind ( x : param_descrs ) ( name : symbol ) = (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) (** Retrieve all names of parameters. *) @@ -1040,25 +1209,25 @@ end = struct (** Adds a parameter setting. *) - let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = + let add_bool ( x : params ) ( name : symbol ) ( value : bool ) = Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = + let add_int ( x : params ) (name : symbol ) ( value : int ) = Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = + let add_double ( x : params ) ( name : symbol ) ( value : float ) = Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value (** Adds a parameter setting. *) - let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = + let add_symbol ( x : params ) ( name : symbol ) ( value : symbol ) = Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) (** @@ -1081,14 +1250,20 @@ end = struct (** Adds a parameter setting. *) - let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = + let add_s_symbol ( x : params ) ( name : string ) ( value : symbol ) = add_symbol x (Symbol.mk_string (z3obj_gc x) name) value (** Creates a new parameter set *) let mk_params ( ctx : context ) = - create ctx (Z3native.mk_params (context_gno ctx)) + let res : params = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.params_inc_ref ; + dec_ref = Z3native.params_dec_ref } in + (z3obj_sno res ctx (Z3native.mk_params (context_gno ctx))) ; + (z3obj_create res) ; + res (** A string representation of the parameter set. @@ -1097,76 +1272,16 @@ end = struct end (** General expressions (terms) *) -and Expr : -sig - type expr = Expr of AST.ast - - val create : context -> Z3native.ptr -> expr - val create_fa : context -> FuncDecl.func_decl -> expr array -> expr - val gc : expr -> context - val gno : expr -> Z3native.ptr - val gnc : expr -> Z3native.ptr - val aton : expr array -> Z3native.ptr array - - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - val get_func_decl : expr -> FuncDecl.func_decl - val is_numeral : expr -> bool - val to_string : expr -> string -end = struct - type expr = Expr of AST.ast - - (**/**) - let create ( ctx : context ) ( obj : Z3native.ptr ) = - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) obj) == QUANTIFIER_AST then - (match (Quantifiers.create ctx obj) with Quantifiers.Quantifier(e) -> e) - else - let s = Z3native.get_sort (context_gno ctx) obj in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) obj) then - (match (Arithmetic.AlgebraicNumbers.create_num ctx obj) with Arithmetic.AlgebraicNumbers.AlgebraicNum(Arithmetic.ArithExpr(e)) -> e) - else - if (Z3native.is_numeral_ast (context_gno ctx) obj) && - (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then - match sk with - | INT_SORT -> (match (Arithmetic.Integers.create_num ctx obj) with Arithmetic.Integers.IntNum(Arithmetic.Integers.IntExpr(Arithmetic.ArithExpr(e))) -> e) - | REAL_SORT -> (match (Arithmetic.Reals.create_num ctx obj) with Arithmetic.Reals.RatNum(Arithmetic.Reals.RealExpr(Arithmetic.ArithExpr(e))) -> e) - | BV_SORT -> (match (BitVectors.create_num ctx obj) with BitVectors.BitVecNum(BitVectors.BitVecExpr(e)) -> e) - | _ -> raise (Z3native.Exception "Unsupported numeral object") - else - match sk with - | BOOL_SORT -> (match (Booleans.create_expr ctx obj) with Booleans.BoolExpr(e) -> e) - | INT_SORT -> (match (Arithmetic.Integers.create_expr ctx obj) with Arithmetic.Integers.IntExpr(Arithmetic.ArithExpr(e)) -> e) - | REAL_SORT -> (match (Arithmetic.Reals.create_expr ctx obj) with Arithmetic.Reals.RealExpr(Arithmetic.ArithExpr(e)) -> e) - | BV_SORT -> (match (BitVectors.create_expr ctx obj) with BitVectors.BitVecExpr(e) -> e) - | ARRAY_SORT -> (match (Arrays.create_expr ctx obj) with Arrays.ArrayExpr(e) -> e) - | DATATYPE_SORT -> (match (Datatypes.create_expr ctx obj) with Datatypes.DatatypeExpr(e) -> e) - | _ -> Expr(AST.create ctx obj) - - let aton ( a : expr array ) = - let f ( e : expr ) = match e with Expr(a) -> (z3obj_gno a) in - Array.map f a - - let create_fa ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = - let o = Z3native.mk_app (context_gno ctx) (FuncDecl.gno f) (Array.length args) (aton args) in - Expr.create ctx o - - let gc ( x : expr ) = match x with Expr(a) -> (z3obj_gc a) - let gnc ( x : expr ) = match x with Expr(a) -> (z3obj_gnc a) - let gno ( x : expr ) = match x with Expr(a) -> (z3obj_gno a) - - let aton (a : expr array) = - let f (e : expr) = (gno e) in - Array.map f a - (**/**) - +module Expr = +struct (** Returns a simplified version of the expression. @param p A set of parameters to configure the simplifier *) - let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> Expr.create (gc x) (Z3native.simplify (gnc x) (gno x)) - | Some pp -> Expr.create (gc x) (Z3native.simplify_ex (gnc x) (gno x) (z3obj_gno pp)) + let simplify ( x : expr ) ( p : params option ) = match p with + | None -> expr_of_ptr (c_of_expr x) (Z3native.simplify (nc_of_expr x) (ptr_of_expr x)) + | Some pp -> expr_of_ptr (c_of_expr x) (Z3native.simplify_ex (nc_of_expr x) (ptr_of_expr x) (z3obj_gno pp)) (** a string describing all available parameters to Expr.Simplify. @@ -1183,24 +1298,24 @@ end = struct (** The function declaration of the function that is applied in this expression. *) - let get_func_decl ( x : expr ) = FuncDecl.create (gc x) (Z3native.get_app_decl (gnc x) (gno x)) + let get_func_decl ( x : expr ) = func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) (** Indicates whether the expression is the true or false expression or something else (L_UNDEF). *) - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (nc_of_expr x) (ptr_of_expr x)) (** The number of arguments of the expression. *) - let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) + let get_num_args ( x : expr ) = Z3native.get_app_num_args (nc_of_expr x) (ptr_of_expr x) (** The arguments of the expression. *) let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = create (gc x) (Z3native.get_app_arg (gnc x) (gno x) i) in + let f i = expr_of_ptr (c_of_expr x) (Z3native.get_app_arg (nc_of_expr x) (ptr_of_expr x) i) in Array.init n f (** @@ -1211,7 +1326,7 @@ end = struct if (Array.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - create (gc x) (Z3native.update_term (gnc x) (gno x) (Array.length args) (aton args)) + expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (Array.length args) (expr_aton args)) (** Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. @@ -1224,7 +1339,7 @@ end = struct if (Array.length from) <> (Array.length to_) then raise (Z3native.Exception "Argument sizes do not match") else - create (gc x) (Z3native.substitute (gnc x) (gno x) (Array.length from) (aton from) (aton to_)) + expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (Array.length from) (expr_aton from) (expr_aton to_)) (** Substitute every occurrence of from in the expression with to. @@ -1239,48 +1354,47 @@ end = struct For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) let substitute_vars ( x : expr ) to_ = - create (gc x) (Z3native.substitute_vars (gnc x) (gno x) (Array.length to_) (aton to_)) + expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (Array.length to_) (expr_aton to_)) - (** Translates (copies) the term to the Context . @param ctx A context @return A copy of the term which is associated with *) let translate ( x : expr ) to_ctx = - if (gc x) == to_ctx then + if (c_of_expr x) == to_ctx then x else - create to_ctx (Z3native.translate (gnc x) (gno x) (context_gno to_ctx)) + expr_of_ptr to_ctx (Z3native.translate (nc_of_expr x) (ptr_of_expr x) (context_gno to_ctx)) (** Returns a string representation of the expression. *) - let to_string ( x : expr ) = Z3native.ast_to_string (gnc x) (gno x) + let to_string ( x : expr ) = Z3native.ast_to_string (nc_of_expr x) (ptr_of_expr x) (** Indicates whether the term is a numeral *) - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (gnc x) (gno x)) + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (nc_of_expr x) (ptr_of_expr x)) (** Indicates whether the term is well-sorted. @return True if the term is well-sorted, false otherwise. *) - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (nc_of_expr x) (ptr_of_expr x) (** The Sort of the term. *) - let get_sort ( x : expr ) = Sort.create (gc x) (Z3native.get_sort (gnc x) (gno x)) + let get_sort ( x : expr ) = sort_of_ptr (c_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)) (** Indicates whether the term has Boolean sort. *) let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (gnc x) - (Z3native.mk_bool_sort (gnc x)) - (Z3native.get_sort (gnc x) (gno x))) + (Z3native.is_eq_sort (nc_of_expr x) + (Z3native.mk_bool_sort (nc_of_expr x)) + (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x))) (** Indicates whether the term represents a constant. @@ -1366,14 +1480,14 @@ end = struct (** Creates a new Constant of sort and named . *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : Sort.sort ) = - create ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) + let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = + expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) (** Creates a new Constant of sort and named . *) - let mk_const_s ( ctx : context ) ( name : string ) ( range : Sort.sort ) = + let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) range @@ -1381,21 +1495,21 @@ end = struct Creates a constant from the func_decl . @param f An expression of a 0-arity function *) - let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = - create_fa ctx f [||] + let mk_const_f ( ctx : context ) ( f : func_decl ) = + expr_of_func_app ctx f [||] (** Creates a fresh constant of sort and a name prefixed with . *) - let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : Sort.sort ) = - create ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) + let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = + expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) (** Create a new function application. *) - let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = - create_fa ctx f args + let mk_app ( ctx : context ) ( f : func_decl ) ( args : expr array ) = + expr_of_func_app ctx f args (** Create a numeral of a given sort. @@ -1403,8 +1517,8 @@ end = struct @param ty 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 *) - let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : Sort.sort ) = - create ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) + let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) (** Create a numeral of a given sort. This function can be use to create numerals that fit in a machine integer. @@ -1413,50 +1527,31 @@ end = struct @param ty Sort of the numeral @return A Term with value and type *) - let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : Sort.sort ) = - create ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) + let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) end (** Boolean expressions *) -and Booleans : -sig - type bool_expr = BoolExpr of Expr.expr - type bool_sort = BoolSort of Sort.sort +module Boolean = +struct + let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let a = (ast_of_ptr ctx no) in + BoolExpr(Expr(a)) - val create_expr : context -> Z3native.ptr -> bool_expr - val create_sort : context -> Z3native.ptr -> bool_sort - val gc : bool_expr -> context - val gnc : bool_expr -> Z3native.ptr - val gno : bool_expr -> Z3native.ptr - val aton : bool_expr array -> Z3native.ptr array -end = struct - type bool_expr = BoolExpr of Expr.expr - type bool_sort = BoolSort of Sort.sort - - (**/**) - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - let a = (AST.create ctx no) in - BoolExpr(Expr.Expr(a)) + let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + BoolSort(sort_of_ptr ctx no) - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - BoolSort(Sort.create ctx no) - - let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gc e) - let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gnc e) - let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.gno e) - - let aton ( a : bool_expr array ) = - let f (e : bool_expr) = (gno e) in - Array.map f a - (**/**) + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (c_of_expr e) + let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (nc_of_expr e) + let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (ptr_of_expr e) let mk_sort ( ctx : context ) = - BoolSort(Sort.create ctx (Z3native.mk_bool_sort (context_gno ctx))) + BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) (** Create a Boolean constant. *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : symbol ) = let s = (match (mk_sort ctx) with BoolSort(q) -> q) in BoolExpr(Expr.mk_const ctx name s) @@ -1470,13 +1565,13 @@ end = struct The true Term. *) let mk_true ( ctx : context ) = - create_expr ctx (Z3native.mk_true (context_gno ctx)) + bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) (** The false Term. *) let mk_false ( ctx : context ) = - create_expr ctx (Z3native.mk_false (context_gno ctx)) + bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) (** Creates a Boolean value. @@ -1487,20 +1582,20 @@ end = struct (** Creates the equality = . *) - let mk_eq ( ctx : context ) ( x : Expr.expr ) ( y : Expr.expr ) = - create_expr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = + bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (ptr_of_expr x) (ptr_of_expr y)) (** Creates a distinct term. *) - let mk_distinct ( ctx : context ) ( args : Expr.expr array ) = - create_expr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (Expr.aton args)) + let mk_distinct ( ctx : context ) ( args : expr array ) = + bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (expr_aton args)) (** Mk an expression representing not(a). *) let mk_not ( ctx : context ) ( a : bool_expr ) = - create_expr ctx (Z3native.mk_not (context_gno ctx) (gno a)) + bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) (** Create an expression representing an if-then-else: ite(t1, t2, t3). @@ -1509,103 +1604,70 @@ end = struct @param t3 An expression with the same sort as *) let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - create_expr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) (** Create an expression representing t1 iff t2. *) let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create_expr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing t1 -> t2. *) let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create_expr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing t1 xor t2. *) let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - create_expr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) (** Create an expression representing the AND of args *) let mk_and ( ctx : context ) ( args : bool_expr array ) = - create_expr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (aton args)) + let f x = (ptr_of_expr (expr_of_bool_expr x)) in + bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (Array.map f args)) (** Create an expression representing the OR of args *) let mk_or ( ctx : context ) ( args : bool_expr array ) = - create_expr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (aton args)) + let f x = (ptr_of_expr (expr_of_bool_expr x)) in + bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (Array.map f args)) end (** Quantifier expressions *) -and Quantifiers : -sig - type quantifier = Quantifier of Expr.expr - - val create : context -> Z3native.ptr -> quantifier -end = struct - type quantifier = Quantifier of Expr.expr - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let a = (AST.create ctx no) in - Quantifier(Expr.Expr(a)) - - let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) - let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) - let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) - (**/**) - +module Quantifier = +struct + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (c_of_expr e) + let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (nc_of_expr e) + let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (ptr_of_expr e) + (** Quantifier patterns 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. *) - module Patterns : - sig - type pattern = Pattern of AST.ast - - val create : context -> Z3native.ptr -> pattern - val aton : pattern array -> Z3native.ptr array - end = struct - type pattern = Pattern of AST.ast - - (**/**) - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - Pattern(res) - + module Pattern = struct let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - let aton (a : pattern array) = - let f (e : pattern) = (gno e) in - Array.map f a - (**/**) - (** The number of terms in the pattern. *) let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms (gnc x) (gno x) - + Z3native.get_pattern_num_terms (gnc x) (gno x) + (** The terms in the pattern. *) let get_terms ( x : pattern ) = let n = (get_num_terms x) in - let f i = (Expr.create (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in + let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in Array.init n f (** @@ -1632,11 +1694,11 @@ end = struct on the scope in which it appears. The deeper ( x : expr ) appears, the higher is its index. *) - let get_index ( x : Expr.expr ) = - if not (AST.is_var (match x with Expr.Expr(a) -> a)) then + let get_index ( x : expr ) = + if not (AST.is_var (match x with Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else - Z3native.get_index_value (Expr.gnc x) (Expr.gno x) + Z3native.get_index_value (nc_of_expr x) (ptr_of_expr x) (** Indicates whether the quantifier is universal. @@ -1664,7 +1726,7 @@ end = struct *) let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = (Patterns.create (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in + let f i = Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** @@ -1677,7 +1739,7 @@ end = struct *) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = (Patterns.create (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in + let f i = Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** @@ -1698,31 +1760,31 @@ end = struct *) let get_bound_variable_sorts ( x : quantifier ) = let n = (get_num_bound x) in - let f i = (Sort.create (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in + let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in Array.init n f (** The body of the quantifier. *) let get_body ( x : quantifier ) = - Booleans.create_expr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) + Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) (** Creates a new bound variable. @param index The de-Bruijn index of the variable @param ty The sort of the variable *) - let mk_bound ( ctx : context ) ( index : int ) ( ty : Sort.sort ) = - Expr.create ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) + let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) (** Create a quantifier pattern. *) - let mk_pattern ( ctx : context ) ( terms : Expr.expr array ) = + let mk_pattern ( ctx : context ) ( terms : expr array ) = if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - Patterns.create ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (Expr.aton terms)) + Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) (** Create a universal Quantifier. @@ -1743,96 +1805,96 @@ end = struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - create ctx (Z3native.mk_quantifier (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (Patterns.aton patterns) - (Array.length sorts) (Sort.aton sorts) - (Symbol.aton names) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (let f x = (Symbol.gno x) in (Array.map f names)) + (ptr_of_expr body))) else - create ctx (Z3native.mk_quantifier_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (Patterns.aton patterns) - (Array.length nopatterns) (Expr.aton nopatterns) - (Array.length sorts) (Sort.aton sorts) - (Symbol.aton names) - (Expr.gno body)) - + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length nopatterns) (expr_aton nopatterns) + (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (let f x = (Symbol.gno x) in (Array.map f names)) + (ptr_of_expr body))) + (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - create ctx (Z3native.mk_quantifier_const (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (Expr.aton bound_constants) - (Array.length patterns) (Patterns.aton patterns) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (expr_aton bound_constants) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (ptr_of_expr body))) else - create ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (Expr.aton bound_constants) - (Array.length patterns) (Patterns.aton patterns) - (Array.length nopatterns) (Expr.aton nopatterns) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length bound_constants) (expr_aton bound_constants) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length nopatterns) (expr_aton nopatterns) + (ptr_of_expr body))) (** Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - create ctx (Z3native.mk_quantifier (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (Patterns.aton patterns) - (Array.length sorts) (Sort.aton sorts) - (Symbol.aton names) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (let f x = (Symbol.gno x) in (Array.map f names)) + (ptr_of_expr body))) else - create ctx (Z3native.mk_quantifier_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (Patterns.aton patterns) - (Array.length nopatterns) (Expr.aton nopatterns) - (Array.length sorts) (Sort.aton sorts) - (Symbol.aton names) - (Expr.gno body)) - + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length nopatterns) (expr_aton nopatterns) + (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (let f x = (Symbol.gno x) in (Array.map f names)) + (ptr_of_expr body))) + (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - create ctx (Z3native.mk_quantifier_const (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (Expr.aton bound_constants) - (Array.length patterns) (Patterns.aton patterns) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (Array.length bound_constants) (expr_aton bound_constants) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (ptr_of_expr body))) else - create ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (Expr.aton bound_constants) - (Array.length patterns) (Patterns.aton patterns) - (Array.length nopatterns) (Expr.aton nopatterns) - (Expr.gno body)) + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (Array.length bound_constants) (expr_aton bound_constants) + (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length nopatterns) (expr_aton nopatterns) + (ptr_of_expr body))) (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : Sort.sort array ) ( names : Symbol.symbol array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -1842,7 +1904,7 @@ end = struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : Expr.expr array ) ( body : Expr.expr ) ( weight : int option ) ( patterns : Patterns.pattern array ) ( nopatterns : Expr.expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -1850,42 +1912,29 @@ end = struct end (** Functions to manipulate Array expressions *) -and Arrays : -sig - type array_expr = ArrayExpr of Expr.expr - type array_sort = ArraySort of Sort.sort - - val create_expr : context -> Z3native.ptr -> array_expr -end = struct - type array_expr = ArrayExpr of Expr.expr - type array_sort = ArraySort of Sort.sort - - (**/**) +module Array_ = +struct + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (Expr.create ctx no) in + let e = (expr_of_ptr ctx no) in ArrayExpr(e) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in ArraySort(s) - let sgc ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gc s) - let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gnc s) - let sgno ( x : array_sort ) = match (x) with ArraySort(Sort.Sort(s)) -> (z3obj_gno s) + let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gno s) - let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gc e) - let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gnc e) - let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr.Expr(e)) -> (z3obj_gno e) + let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gc e) + let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) + let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) - let aton (a : array_expr array) = - let f (e : array_expr) = (egno e) in - Array.map f a - (**/**) - (** Create a new array sort. *) - let mk_sort ( ctx : context ) ( domain : Sort.sort ) ( range : Sort.sort ) = + let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = create_sort ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) (** @@ -1893,62 +1942,62 @@ end = struct It satisfies select(store(a,i,v),j) = if i = j then v else select(a,j). Array store takes at least 3 arguments. *) - let is_store ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) (** Indicates whether the term is an array select. *) - let is_select ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_constant_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) + let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) (** Indicates whether the term is a default array. For example default(const(v)) = v. The function is unary. *) - let is_default_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) + let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_array_map ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) + let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_as_array ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) (** Indicates whether the term is of an array sort. *) - let is_array ( x : Expr.expr ) = - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) + let is_array ( x : expr ) = + (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == ARRAY_SORT) (** The domain of the array sort. *) - let get_domain ( x : array_sort ) = Sort.create (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) + let get_domain ( x : array_sort ) = sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) (** The range of the array sort. *) - let get_range ( x : array_sort ) = Sort.create (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) + let get_range ( x : array_sort ) = sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) (** Create an array constant. *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : Sort.sort ) ( range : Sort.sort ) = + let mk_const ( ctx : context ) ( name : symbol ) ( domain : sort ) ( range : sort ) = ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) (** Create an array constant. *) - let mk_const_s ( ctx : context ) ( name : string ) ( domain : Sort.sort ) ( range : Sort.sort ) = + let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) domain range (** @@ -1963,8 +2012,8 @@ end = struct *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : Expr.expr ) = - create_expr ctx (Z3native.mk_select (context_gno ctx) (egno a) (Expr.gno i)) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = + expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) (** Array update. @@ -1982,8 +2031,8 @@ end = struct *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : Expr.expr ) ( v : Expr.expr ) = - create_expr ctx (Z3native.mk_store (context_gno ctx) (egno a) (Expr.gno i) (Expr.gno v)) + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = + expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) (** Create a constant array. @@ -1993,8 +2042,8 @@ end = struct *) - let mk_const_array ( ctx : context ) ( domain : Sort.sort ) ( v : Expr.expr ) = - create_expr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) + let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = + expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) (** Maps f on the argument arrays. @@ -2006,8 +2055,9 @@ end = struct *) - let mk_map ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : array_expr array ) = - create_expr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (aton args)) + let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = + let m x = (ptr_of_expr (expr_of_array_expr x)) in + expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m args)) (** Access the array default value. @@ -2016,137 +2066,122 @@ end = struct finite maps with a default range value. *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = - create_expr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) + expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) end (** Functions to manipulate Set expressions *) -and Sets : -sig - type set_sort = SetSort of Sort.sort - -end = struct - type set_sort = SetSort of Sort.sort - +module Set = +struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in SetSort(s) (** Indicates whether the term is set union *) - let is_union ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) (** Indicates whether the term is set intersection *) - let is_intersect ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) (** Indicates whether the term is set difference *) - let is_difference ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) (** Indicates whether the term is set complement *) - let is_complement ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) (** Indicates whether the term is set subset *) - let is_subset ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) (** Create a set type. *) - let mk_sort ( ctx : context ) ( ty : Sort.sort ) = + let mk_sort ( ctx : context ) ( ty : sort ) = create_sort ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) (** Create an empty set. *) - let mk_empty ( ctx : context ) ( domain : Sort.sort ) = - (Expr.create ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) + let mk_empty ( ctx : context ) ( domain : sort ) = + (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) (** Create the full set. *) - let mk_full ( ctx : context ) ( domain : Sort.sort ) = - Expr.create ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) + let mk_full ( ctx : context ) ( domain : sort ) = + expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) (** Add an element to the set. *) - let mk_set_add ( ctx : context ) ( set : Expr.expr ) ( element : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) + let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = + expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) (** Remove an element from a set. *) - let mk_del ( ctx : context ) ( set : Expr.expr ) ( element : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) + let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = + expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) (** Take the union of a list of sets. *) - let mk_union ( ctx : context ) ( args : Expr.expr array ) = - Expr.create ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (Expr.aton args)) + let mk_union ( ctx : context ) ( args : expr array ) = + expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (expr_aton args)) (** Take the intersection of a list of sets. *) - let mk_intersection ( ctx : context ) ( args : Expr.expr array ) = - Expr.create ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (Expr.aton args)) + let mk_intersection ( ctx : context ) ( args : expr array ) = + expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (expr_aton args)) (** Take the difference between two sets. *) - let mk_difference ( ctx : context ) ( arg1 : Expr.expr ) ( arg2 : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) + let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = + expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) (** Take the complement of a set. *) - let mk_complement ( ctx : context ) ( arg : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) + let mk_complement ( ctx : context ) ( arg : expr ) = + expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (ptr_of_expr arg)) (** Check for set membership. *) - let mk_membership ( ctx : context ) ( elem : Expr.expr ) ( set : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) + let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = + expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (ptr_of_expr elem) (ptr_of_expr set)) (** Check for subsetness of sets. *) - let mk_subset ( ctx : context ) ( arg1 : Expr.expr ) ( arg2 : Expr.expr ) = - Expr.create ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) + let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = + expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) end (** Functions to manipulate Finite Domain expressions *) -and FiniteDomains : -sig - type finite_domain_sort = FiniteDomainSort of Sort.sort - -end = struct - type finite_domain_sort = FiniteDomainSort of Sort.sort - - (**/**) - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in - FiniteDomainSort(s) - - let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gc s) - let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s)) -> (z3obj_gnc s) - let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort.Sort(s))-> (z3obj_gno s) - (**/**) - +module FiniteDomain = +struct + let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) + let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) + let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) + (** Create a new finite domain sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - create_sort ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size) + let mk_sort ( ctx : context ) ( name : symbol ) ( size : int ) = + let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in + FiniteDomainSort(s) (** Create a new finite domain sort. @@ -2158,14 +2193,15 @@ end = struct (** Indicates whether the term is of an array sort. *) - let is_finite_domain ( x : Expr.expr ) = - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) == FINITE_DOMAIN_SORT) + let is_finite_domain ( x : expr ) = + let nc = (nc_of_expr x) in + (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == FINITE_DOMAIN_SORT) (** Indicates whether the term is a less than predicate over a finite domain. *) - let is_lt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) (** The size of the finite domain sort. *) let get_size ( x : finite_domain_sort ) = @@ -2175,29 +2211,25 @@ end = struct end (** Functions to manipulate Relation expressions *) -and Relations : -sig - type relation_sort = RelationSort of Sort.sort - -end = struct - type relation_sort = RelationSort of Sort.sort - - (**/**) +module Relation = +struct + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in RelationSort(s) - let gc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gc s) - let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s)) -> (z3obj_gnc s) - let gno ( x : relation_sort ) = match (x) with RelationSort(Sort.Sort(s))-> (z3obj_gno s) - (**/**) + let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) + let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) + let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) + (** Indicates whether the term is of a relation sort. *) - let is_relation ( x : Expr.expr ) = - ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) == RELATION_SORT)) + let is_relation ( x : expr ) = + let nc = (nc_of_expr x) in + ((Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == RELATION_SORT)) (** Indicates whether the term is an relation store @@ -2206,40 +2238,40 @@ end = struct 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. *) - let is_store ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) (** Indicates whether the term is an empty relation *) - let is_empty ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) (** Indicates whether the term is a test for the emptiness of a relation *) - let is_is_empty ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) (** Indicates whether the term is a relational join *) - let is_join ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) (** Indicates whether the term is the union or convex hull of two relations. The function takes two arguments. *) - let is_union ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) (** Indicates whether the term is the widening of two relations The function takes two arguments. *) - let is_widen ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). The function takes one argument. *) - let is_project ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) + let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) (** Indicates whether the term is a relation filter @@ -2250,7 +2282,7 @@ end = struct corresponding to the columns of the relation. So the first column in the relation has index 0. *) - let is_filter ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) + let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) (** Indicates whether the term is an intersection of a relation with the negation of another. @@ -2265,7 +2297,7 @@ end = struct target are elements in ( x : expr ) in pos, such that there is no y in neg that agrees with ( x : expr ) on the columns c1, d1, .., cN, dN. *) - let is_negation_filter ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) + let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) (** Indicates whether the term is the renaming of a column in a relation @@ -2273,12 +2305,12 @@ end = struct The function takes one argument. The parameters contain the renaming as a cycle. *) - let is_rename ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) (** Indicates whether the term is the complement of a relation *) - let is_complement ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) (** Indicates whether the term is a relational select @@ -2287,7 +2319,7 @@ end = struct The function takes n+1 arguments, where the first argument is a relation, and the remaining n arguments correspond to a record. *) - let is_select ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) (** Indicates whether the term is a relational clone (copy) @@ -2298,7 +2330,7 @@ end = struct for terms of kind to perform destructive updates to the first argument. *) - let is_clone ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) (** The arity of the relation sort. *) let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) @@ -2312,46 +2344,22 @@ end = struct end (** Functions to manipulate Datatype expressions *) -and Datatypes : -sig - type datatype_expr = DatatypeExpr of Expr.expr - type datatype_sort = DatatypeSort of Sort.sort - - val create_expr : context -> Z3native.ptr -> datatype_expr -end = struct - type datatype_expr = DatatypeExpr of Expr.expr - type datatype_sort = DatatypeSort of Sort.sort - - (**/**) - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (Expr.create ctx no) in - DatatypeExpr(e) - +module Datatype = +struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in DatatypeSort(s) - let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gc s) - let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s)) -> (z3obj_gnc s) - let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort.Sort(s))-> (z3obj_gno s) - (**/**) + let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) + (** Constructors *) - module Constructor : sig - type constructor - val create : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> constructor - val aton : constructor array -> Z3native.ptr array - end = struct - type constructor_extra = { - m_n : int; - mutable m_tester_decl : FuncDecl.func_decl option; - mutable m_constructor_decl : FuncDecl.func_decl option ; - mutable m_accessor_decls : FuncDecl.func_decl array option} - - type constructor = Constructor of (z3_native_object * constructor_extra) - - (**/**) - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = + module Constructor = + struct + + let create ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -2362,8 +2370,8 @@ end = struct let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) (Symbol.gno recognizer) n - (Symbol.aton field_names) - (Sort.aton sorts) + (let f x = (Symbol.gno x) in (Array.map f field_names)) + (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) sort_refs) in let no : z3_native_object = { m_ctx = ctx ; m_n_obj = null ; @@ -2379,21 +2387,17 @@ end = struct Gc.finalise f no ; Constructor(no, ex) - let aton ( a : constructor array ) = - let f (e : constructor) = match e with Constructor(no, ex) -> (z3obj_gno no)in - Array.map f a - let init_extra ( x : constructor ) = match x with Constructor(no, ex) -> match ex.m_tester_decl with | None -> let (a, b, c) = (Z3native.query_constructor (z3obj_gnc no) (z3obj_gno no) ex.m_n) in - ex.m_constructor_decl <- Some (FuncDecl.create (z3obj_gc no) a) ; - ex.m_tester_decl <- Some (FuncDecl.create (z3obj_gc no) b) ; - ex.m_accessor_decls <- Some (let f e = (FuncDecl.create (z3obj_gc no) e) in Array.map f c) ; + ex.m_constructor_decl <- Some (func_decl_of_ptr (z3obj_gc no) a) ; + ex.m_tester_decl <- Some (func_decl_of_ptr (z3obj_gc no) b) ; + ex.m_accessor_decls <- Some (let f e = (func_decl_of_ptr (z3obj_gc no) e) in Array.map f c) ; () | _ -> () - (**/**) + let get_n ( x : constructor ) = match x with Constructor(no, ex) -> @@ -2433,24 +2437,18 @@ end = struct (** Constructor list objects *) module ConstructorList = struct - type constructor_list = z3_native_object - - (**/**) - let create ( ctx : context )( c : Constructor.constructor array ) = + + let create ( ctx : context ) ( c : constructor array ) = let res : constructor_list = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref} in - (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Constructor.aton c))) ; + let f x = match x with Constructor(no,_) -> (z3obj_gno no) in + (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Array.map f c))) ; (z3obj_create res) ; let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f res; res - - let aton (a : constructor_list array) = - let f (e : constructor_list) = (z3obj_gno e) in - Array.map f a - (**/**) end (* DATATYPES *) @@ -2464,7 +2462,7 @@ end = struct 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. *) - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array) = + let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = Constructor.create ctx name recognizer field_names sorts sort_refs @@ -2478,21 +2476,22 @@ end = struct 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. *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( sort_refs : int array ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array) = - let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Constructor.aton constructors)) in + let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = + let f x = match x with Constructor(no,_) -> (z3obj_gno no) in + let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in create_sort ctx x (** Create a new datatype sort. *) - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array ) = mk_sort ctx (Symbol.mk_string ctx name) constructors (** @@ -2500,16 +2499,17 @@ end = struct @param names names of datatype sorts @param c list of constructors, one list per sort. *) - let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = + let mk_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = let n = (Array.length names) in - let f e = (ConstructorList.create ctx e) in + let f e = (ptr_of_ast (ConstructorList.create ctx e)) in let cla = (Array.map f c) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.aton names) (ConstructorList.aton cla)) in + let f2 x = (Symbol.gno x) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Array.map f2 names) cla) in let g e = (create_sort ctx e) in (Array.map g r) (** Create mutually recursive data-types. *) - let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = + let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = mk_sorts ctx ( let f e = (Symbol.mk_string ctx e) in @@ -2523,54 +2523,50 @@ end = struct (** The range of the array sort. *) let get_constructors ( x : datatype_sort ) = let n = (get_num_constructors x) in - let f i = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in Array.init n f (** The recognizers. *) let get_recognizers ( x : datatype_sort ) = let n = (get_num_constructors x) in - let f i = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in Array.init n f (** The constructor accessors. *) let get_accessors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = ( - let fd = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in - let g j = FuncDecl.create (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in + let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in Array.init ds g ) in Array.init n f end (** Functions to manipulate Enumeration expressions *) -and Enumerations : -sig - type enum_sort_data - type enum_sort = EnumSort of (Sort.sort * enum_sort_data) -end = struct - type enum_sort_data = { mutable _constdecls : FuncDecl.func_decl array ; - mutable _testerdecls : FuncDecl.func_decl array } - type enum_sort = EnumSort of (Sort.sort * enum_sort_data) - - (**/**) +module Enumeration = +struct + let _constdecls = Hashtbl.create 0 + let _testerdecls = Hashtbl.create 0 + let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = - let s = (Sort.create ctx no) in - let e = { _constdecls = (let f e = FuncDecl.create ctx e in (Array.map f cdecls)) ; - _testerdecls = (let f e = FuncDecl.create ctx e in (Array.map f tdecls)) } in - EnumSort(s, e) + let s = (sort_of_ptr ctx no) in + let res = EnumSort(s) in + Hashtbl.add _constdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f cdecls)) ; + Hashtbl.add _testerdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f tdecls)) ; + res - let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gc s) - let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_) -> (z3obj_gnc s) - let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort.Sort(s),_)-> (z3obj_gno s) - (**/**) + let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) (** Create a new enumeration sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = - let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Symbol.aton enum_names)) in + let mk_sort ( ctx : context ) ( name : symbol ) ( enum_names : symbol array ) = + let f x = Symbol.gno x in + let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Array.map f enum_names)) in create_sort ctx a b c (** @@ -2580,45 +2576,40 @@ end = struct mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) (** The function declarations of the constants in the enumeration. *) - let get_const_decls ( x : enum_sort ) = match x with EnumSort(_,ex) -> ex._constdecls + let get_const_decls ( x : enum_sort ) = Hashtbl.find _constdecls x (** The test predicates for the constants in the enumeration. *) - let get_tester_decls ( x : enum_sort ) = match x with EnumSort(_,ex) -> ex._testerdecls + let get_tester_decls ( x : enum_sort ) = Hashtbl.find _testerdecls x end (** Functions to manipulate List expressions *) -and Lists : -sig - type list_sort_data - type list_sort = ListSort of (Sort.sort * list_sort_data) - -end = struct - type list_sort_data = { _nildecl : FuncDecl.func_decl ; - _is_nildecl : FuncDecl.func_decl ; - _consdecl : FuncDecl.func_decl ; - _is_consdecl : FuncDecl.func_decl ; - _headdecl : FuncDecl.func_decl ; - _taildecl : FuncDecl.func_decl } - type list_sort = ListSort of (Sort.sort * list_sort_data) - - (**/**) +module List_ = +struct + let _nildecls = Hashtbl.create 0 + let _is_nildecls = Hashtbl.create 0 + let _consdecls = Hashtbl.create 0 + let _is_consdecls = Hashtbl.create 0 + let _headdecls = Hashtbl.create 0 + let _taildecls = Hashtbl.create 0 + let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = - let s = (Sort.create ctx no) in - let e = {_nildecl = FuncDecl.create ctx nildecl; - _is_nildecl = FuncDecl.create ctx is_nildecl; - _consdecl = FuncDecl.create ctx consdecl; - _is_consdecl = FuncDecl.create ctx is_consdecl; - _headdecl = FuncDecl.create ctx headdecl; - _taildecl = FuncDecl.create ctx taildecl} in - ListSort(s, e) + let s = (sort_of_ptr ctx no) in + let res = ListSort(s) in + Hashtbl.add _nildecls res (func_decl_of_ptr ctx nildecl) ; + Hashtbl.add _is_nildecls res (func_decl_of_ptr ctx is_nildecl) ; + Hashtbl.add _consdecls res (func_decl_of_ptr ctx consdecl) ; + Hashtbl.add _is_consdecls res (func_decl_of_ptr ctx is_consdecl) ; + Hashtbl.add _headdecls res (func_decl_of_ptr ctx headdecl) ; + Hashtbl.add _taildecls res (func_decl_of_ptr ctx taildecl) ; + res - let sgc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gc s) - let sgnc ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_) -> (z3obj_gnc s) - let sgno ( x : list_sort ) = match (x) with ListSort(Sort.Sort(s),_)-> (z3obj_gno s) - (**/**) + let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) + (** Create a new list sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : Sort.sort ) = + let mk_sort ( ctx : context ) ( name : symbol ) ( elem_sort : sort ) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in create_sort ctx r a b c d e f @@ -2627,53 +2618,51 @@ end = struct mk_sort ctx (Symbol.mk_string ctx name) elem_sort (** The declaration of the nil function of this list sort. *) - let get_nil_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._nildecl + let get_nil_decl ( x : list_sort ) = (Hashtbl.find _nildecls x) (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._is_nildecl + let get_is_nil_decl ( x : list_sort ) = (Hashtbl.find _is_nildecls x) (** The declaration of the cons function of this list sort. *) - let get_cons_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._consdecl + let get_cons_decl ( x : list_sort ) = (Hashtbl.find _consdecls x) (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._is_consdecl + let get_is_cons_decl ( x : list_sort ) = (Hashtbl.find _is_consdecls x) (** The declaration of the head function of this list sort. *) - let get_head_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._headdecl + let get_head_decl ( x : list_sort ) = (Hashtbl.find _headdecls x) (** The declaration of the tail function of this list sort. *) - let get_tail_decl ( x : list_sort ) = match x with ListSort(no, ex) -> ex._taildecl + let get_tail_decl ( x : list_sort ) = (Hashtbl.find _taildecls x) (** The empty list. *) - let nil ( x : list_sort ) = Expr.create_fa (sgc x) (get_nil_decl x) [||] + let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [||] end (** Functions to manipulate Tuple expressions *) -and Tuples : -sig - type tuple_sort = TupleSort of Sort.sort -end = struct - type tuple_sort = TupleSort of Sort.sort - - (**/**) +module Tuple = +struct + let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - let s = (Sort.create ctx no) in + let s = (sort_of_ptr ctx no) in TupleSort(s) - let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gc s) - let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s)) -> (z3obj_gnc s) - let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort.Sort(s))-> (z3obj_gno s) - (**/**) + let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) + (** Create a new tuple sort. *) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : Sort.sort array ) = - let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Symbol.aton field_names) (Sort.aton field_sorts)) in + let mk_sort ( ctx : context ) ( name : symbol ) ( field_names : symbol array ) ( field_sorts : sort array ) = + let f x = Symbol.gno x in + let f2 x = ptr_of_ast (ast_of_sort x) in + let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in (* CMW: leaks a,b? *) create_sort ctx r (** The constructor function of the tuple. *) let get_mk_decl ( x : tuple_sort ) = - FuncDecl.create (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) + func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) (** The number of fields in the tuple. *) let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) @@ -2681,131 +2670,37 @@ end = struct (** The field declarations. *) let get_field_decls ( x : tuple_sort ) = let n = get_num_fields x in - let f i = FuncDecl.create (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in Array.init n f end (** Functions to manipulate arithmetic expressions *) -and Arithmetic : -sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val create_expr : context -> Z3native.ptr -> arith_expr - val create_sort : context -> Z3native.ptr -> arith_sort - val aton : arith_expr array -> Z3native.ptr array - - module Integers : sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val create_sort : context -> Z3native.ptr -> int_sort - val create_expr : context -> Z3native.ptr -> int_expr - val create_num : context -> Z3native.ptr -> int_num - end - - module Reals : sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val create_sort : context -> Z3native.ptr -> real_sort - val create_expr : context -> Z3native.ptr -> real_expr - val create_num : context -> Z3native.ptr -> rat_num - end - - module AlgebraicNumbers : sig - type algebraic_num = AlgebraicNum of arith_expr - - val create_num : context -> Z3native.ptr -> algebraic_num - end - - val is_int : Expr.expr -> bool - val is_arithmetic_numeral : Expr.expr -> bool - val is_le : Expr.expr -> bool - val is_ge : Expr.expr -> bool - val is_lt : Expr.expr -> bool - val is_gt : Expr.expr -> bool - val is_add : Expr.expr -> bool - val is_sub : Expr.expr -> bool - val is_uminus : Expr.expr -> bool - val is_mul : Expr.expr -> bool - val is_div : Expr.expr -> bool - val is_idiv : Expr.expr -> bool - val is_remainder : Expr.expr -> bool - val is_modulus : Expr.expr -> bool - val is_inttoreal : Expr.expr -> bool - val is_real_to_int : Expr.expr -> bool - val is_real_is_int : Expr.expr -> bool - val is_real : Expr.expr -> bool - val is_int_numeral : Expr.expr -> bool - val is_rat_num : Expr.expr -> bool - val is_algebraic_number : Expr.expr -> bool - val mk_add : context -> arith_expr array -> Arithmetic.arith_expr - val mk_mul : context -> arith_expr array -> Arithmetic.arith_expr - val mk_sub : context -> arith_expr array -> Arithmetic.arith_expr - val mk_unary_minus : - context -> arith_expr -> Arithmetic.arith_expr - val mk_div : - context -> arith_expr -> arith_expr -> Arithmetic.arith_expr - val mk_power : - context -> arith_expr -> arith_expr -> Arithmetic.arith_expr - val mk_lt : - context -> arith_expr -> arith_expr -> Booleans.bool_expr - val mk_le : - context -> arith_expr -> arith_expr -> Booleans.bool_expr - val mk_gt : - context -> arith_expr -> arith_expr -> Booleans.bool_expr - val mk_ge : - context -> arith_expr -> arith_expr -> Booleans.bool_expr - -end = struct - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - (**/**) +module Arithmetic = +struct + let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - ArithExpr(Expr.create ctx no) + arith_expr_of_expr (expr_of_ptr ctx no) let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - ArithSort(Sort.create ctx no) + arith_sort_of_sort (sort_of_ptr ctx no) - let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gc s) - let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gnc s) - let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort.Sort(s)) -> (z3obj_gno s) - let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gc e) - let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) - let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) + let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gno s) + let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (c_of_expr e) + let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (nc_of_expr e) + let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (ptr_of_expr e) - let aton (a : arith_expr array) = - let f (e : arith_expr) = (egno e) in - Array.map f a - (**/**) - - module rec Integers : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val create_sort : context -> Z3native.ptr -> int_sort - val create_expr : context -> Z3native.ptr -> int_expr - val create_num : context -> Z3native.ptr -> int_num - end = struct - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - (**/**) + module Integer = + struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - IntSort(Arithmetic.create_sort ctx no) + int_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - IntExpr(Arithmetic.create_expr ctx no) + int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) let create_num ( ctx : context ) ( no : Z3native.ptr ) = - IntNum(create_expr ctx no) + int_num_of_int_expr (create_expr ctx no) let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) @@ -2816,7 +2711,7 @@ end = struct let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - (**/**) + (** Create a new integer sort. *) let mk_sort ( ctx : context ) = @@ -2834,7 +2729,7 @@ end = struct (** Creates an integer constant. *) - let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_int_const ( ctx : context ) ( name : symbol ) = IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) (** @@ -2848,14 +2743,14 @@ end = struct The arguments must have int type. *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - create_expr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 rem t2. The arguments must have int type. *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - create_expr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) (** Create an integer numeral. @@ -2883,7 +2778,7 @@ end = struct The argument must be of integer sort. *) let mk_int2real ( ctx : context ) ( t : int_expr ) = - Reals.create_expr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)) + real_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) (** Create an bit bit-vector from the integer argument . @@ -2896,32 +2791,19 @@ end = struct The argument must be of integer sort. *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - BitVectors.create_expr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t)) + bitvec_expr_of_expr (expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) end - and Reals : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val create_sort : context -> Z3native.ptr -> real_sort - val create_expr : context -> Z3native.ptr -> real_expr - val create_num : context -> Z3native.ptr -> rat_num - end = struct - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - (**/**) + module Real = + struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - RealSort(Arithmetic.create_sort ctx no) + real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - RealExpr(Arithmetic.create_expr ctx no) - + real_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + let create_num ( ctx : context ) ( no : Z3native.ptr ) = - RatNum(create_expr ctx no) + rat_num_of_real_expr (create_expr ctx no) let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) @@ -2932,7 +2814,7 @@ end = struct let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - (**/**) + (** Create a real sort. *) let mk_sort ( ctx : context ) = @@ -2940,11 +2822,11 @@ end = struct (** The numerator of a rational numeral. *) let get_numerator ( x : rat_num ) = - Integers.create_num (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + Integer.create_num (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) (** The denominator of a rational numeral. *) let get_denominator ( x : rat_num ) = - Integers.create_num (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + Integer.create_num (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -2955,7 +2837,7 @@ end = struct let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) (** Creates a real constant. *) - let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_real_const ( ctx : context ) ( name : symbol ) = RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) (** Creates a real constant. *) @@ -2995,7 +2877,7 @@ end = struct (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = - Booleans.create_expr ctx (Z3native.mk_is_int (context_gno ctx) (egno t)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) (** Coerce a real to an integer. @@ -3005,25 +2887,18 @@ end = struct The argument must be of real sort. *) let mk_real2int ( ctx : context ) ( t : real_expr ) = - Integers.create_expr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)) + int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) end - and AlgebraicNumbers : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val create_num : context -> Z3native.ptr -> algebraic_num - end = struct - type algebraic_num = AlgebraicNum of arith_expr - - (**/**) + module AlgebraicNumber = + struct let create_num ( ctx : context ) ( no : Z3native.ptr ) = - AlgebraicNum(Arithmetic.create_expr ctx no) + algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - (**/**) + (** Return a upper bound for a given real algebraic number. @@ -3033,7 +2908,7 @@ end = struct @return A numeral Expr of sort Real *) let to_upper ( x : algebraic_num ) ( precision : int ) = - Reals.create_num (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + Real.create_num (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) (** Return a lower bound for the given real algebraic number. @@ -3043,7 +2918,7 @@ end = struct @return A numeral Expr of sort Real *) let to_lower ( x : algebraic_num ) precision = - Reals.create_num (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + Real.create_num (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -3057,207 +2932,197 @@ end = struct (** Indicates whether the term is of integer sort. *) - let is_int ( x : Expr.expr ) = - (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) + let is_int ( x : expr ) = + (Z3native.is_numeral_ast (nc_of_expr x) (nc_of_expr x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == INT_SORT) (** Indicates whether the term is an arithmetic numeral. *) - let is_arithmetic_numeral ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) (** Indicates whether the term is a less-than-or-equal *) - let is_le ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) (** Indicates whether the term is a greater-than-or-equal *) - let is_ge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) (** Indicates whether the term is a less-than *) - let is_lt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) (** Indicates whether the term is a greater-than *) - let is_gt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) (** Indicates whether the term is addition (binary) *) - let is_add ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) (** Indicates whether the term is subtraction (binary) *) - let is_sub ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) (** Indicates whether the term is a unary minus *) - let is_uminus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) (** Indicates whether the term is multiplication (binary) *) - let is_mul ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) (** Indicates whether the term is division (binary) *) - let is_div ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) (** Indicates whether the term is integer division (binary) *) - let is_idiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) (** Indicates whether the term is remainder (binary) *) - let is_remainder ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) (** Indicates whether the term is modulus (binary) *) - let is_modulus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) (** Indicates whether the term is a coercion of integer to real (unary) *) - let is_inttoreal ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) (** Indicates whether the term is a coercion of real to integer (unary) *) - let is_real_to_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) (** Indicates whether the term is a check that tests whether a real is integral (unary) *) - let is_real_is_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) (** Indicates whether the term is of sort real. *) - let is_real ( x : Expr.expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) + let is_real ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == REAL_SORT) (** Indicates whether the term is an integer numeral. *) - let is_int_numeral ( x : Expr.expr ) = (Expr.is_numeral x) && (is_int x) + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) (** Indicates whether the term is a real numeral. *) - let is_rat_num ( x : Expr.expr ) = (Expr.is_numeral x) && (is_real x) + let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) (** Indicates whether the term is an algebraic number *) - let is_algebraic_number ( x : Expr.expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (nc_of_expr x) (nc_of_expr x) (** Create an expression representing t[0] + t[1] + .... *) let mk_add ( ctx : context ) ( t : arith_expr array ) = - Arithmetic.create_expr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Arithmetic.aton t)) + let f x = (ptr_of_expr (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Array.map f t))) (** Create an expression representing t[0] * t[1] * .... *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = - Arithmetic.create_expr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Arithmetic.aton t)) + let f x = (ptr_of_expr (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Array.map f t))) (** Create an expression representing t[0] - t[1] - .... *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = - Arithmetic.create_expr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Arithmetic.aton t)) + let f x = (ptr_of_expr (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Array.map f t))) (** Create an expression representing -t. *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - Arithmetic.create_expr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t)) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) (** Create an expression representing t1 / t2. *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Arithmetic.create_expr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2)) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 ^ t2. *) let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Arithmetic.create_expr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2)) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 < t2 *) let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Booleans.create_expr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 <= t2 *) let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Booleans.create_expr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 > t2 *) let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Booleans.create_expr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 >= t2 *) let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Booleans.create_expr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) end (** Functions to manipulate bit-vector expressions *) -and BitVectors : -sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val create_sort : context -> Z3native.ptr -> bitvec_sort - val create_expr : context -> Z3native.ptr -> bitvec_expr - val create_num : context -> Z3native.ptr -> bitvec_num -end = struct - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - (**/**) +module BitVector = +struct let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - BitVecSort(Sort.create ctx no) + bitvec_sort_of_sort (sort_of_ptr ctx no) let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - BitVecExpr(Expr.create ctx no) + bitvec_expr_of_expr (expr_of_ptr ctx no) let create_num ( ctx : context ) ( no : Z3native.ptr ) = - BitVecNum(create_expr ctx no) + bitvec_num_of_bitvec_expr (create_expr ctx no) let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) - let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gc e) - let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gnc e) - let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gno e) + let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (c_of_expr e) + let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (nc_of_expr e) + let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (ptr_of_expr e) let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - (**/**) + (** Create a new bit-vector sort. @@ -3268,272 +3133,272 @@ end = struct (** Indicates whether the terms is of bit-vector sort. *) - let is_bv ( x : Expr.expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) + let is_bv ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == BV_SORT) (** Indicates whether the term is a bit-vector numeral *) - let is_bv_numeral ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) + let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) (** Indicates whether the term is a one-bit bit-vector with value one *) - let is_bv_bit1 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) + let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) (** Indicates whether the term is a one-bit bit-vector with value zero *) - let is_bv_bit0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) + let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) (** Indicates whether the term is a bit-vector unary minus *) - let is_bv_uminus ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) + let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) (** Indicates whether the term is a bit-vector addition (binary) *) - let is_bv_add ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) + let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) (** Indicates whether the term is a bit-vector subtraction (binary) *) - let is_bv_sub ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) + let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) (** Indicates whether the term is a bit-vector multiplication (binary) *) - let is_bv_mul ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) + let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) (** Indicates whether the term is a bit-vector signed division (binary) *) - let is_bv_sdiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) + let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) (** Indicates whether the term is a bit-vector unsigned division (binary) *) - let is_bv_udiv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) + let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) (** Indicates whether the term is a bit-vector signed remainder (binary) *) - let is_bv_SRem ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) + let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - let is_bv_urem ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) + let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) (** Indicates whether the term is a bit-vector signed modulus *) - let is_bv_smod ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) + let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) (** Indicates whether the term is a bit-vector signed division by zero *) - let is_bv_sdiv0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) + let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) (** Indicates whether the term is a bit-vector unsigned division by zero *) - let is_bv_udiv0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) + let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) (** Indicates whether the term is a bit-vector signed remainder by zero *) - let is_bv_srem0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) + let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - let is_bv_urem0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) + let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) (** Indicates whether the term is a bit-vector signed modulus by zero *) - let is_bv_smod0 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) + let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - let is_bv_ule ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) + let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - let is_bv_sle ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) + let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - let is_bv_uge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) + let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - let is_bv_sge ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) + let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) (** Indicates whether the term is an unsigned bit-vector less-than *) - let is_bv_ult ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) + let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) (** Indicates whether the term is a signed bit-vector less-than *) - let is_bv_slt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) + let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) (** Indicates whether the term is an unsigned bit-vector greater-than *) - let is_bv_ugt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) + let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) (** Indicates whether the term is a signed bit-vector greater-than *) - let is_bv_sgt ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) + let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) (** Indicates whether the term is a bit-wise AND *) - let is_bv_and ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) + let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) (** Indicates whether the term is a bit-wise OR *) - let is_bv_or ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) + let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) (** Indicates whether the term is a bit-wise NOT *) - let is_bv_not ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) + let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) (** Indicates whether the term is a bit-wise XOR *) - let is_bv_xor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) + let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) (** Indicates whether the term is a bit-wise NAND *) - let is_bv_nand ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) + let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) (** Indicates whether the term is a bit-wise NOR *) - let is_bv_nor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) + let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) (** Indicates whether the term is a bit-wise XNOR *) - let is_bv_xnor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) + let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) (** Indicates whether the term is a bit-vector concatenation (binary) *) - let is_bv_concat ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) + let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) (** Indicates whether the term is a bit-vector sign extension *) - let is_bv_signextension ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) + let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) (** Indicates whether the term is a bit-vector zero extension *) - let is_bv_zeroextension ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) + let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) (** Indicates whether the term is a bit-vector extraction *) - let is_bv_extract ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) + let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) (** Indicates whether the term is a bit-vector repetition *) - let is_bv_repeat ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) + let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) (** Indicates whether the term is a bit-vector reduce OR *) - let is_bv_reduceor ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) + let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) (** Indicates whether the term is a bit-vector reduce AND *) - let is_bv_reduceand ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) + let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) (** Indicates whether the term is a bit-vector comparison *) - let is_bv_comp ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) + let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) (** Indicates whether the term is a bit-vector shift left *) - let is_bv_shiftleft ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) + let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) (** Indicates whether the term is a bit-vector logical shift right *) - let is_bv_shiftrightlogical ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) (** Indicates whether the term is a bit-vector arithmetic shift left *) - let is_bv_shiftrightarithmetic ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) + let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) (** Indicates whether the term is a bit-vector rotate left *) - let is_bv_rotateleft ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) (** Indicates whether the term is a bit-vector rotate right *) - let is_bv_rotateright ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_rotateleftextended ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_rotaterightextended ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_int_to_bv ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_bv_to_int ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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))) *) - let is_bv_carry ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) + let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) *) - let is_bv_xor3 ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) (** The size of a bit-vector sort. *) let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) @@ -3550,7 +3415,7 @@ end = struct (** Creates a bit-vector constant. *) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + let mk_const ( ctx : context ) ( name : symbol ) ( size : int ) = BitVecExpr(Expr.mk_const ctx name (match (mk_sort ctx size) with BitVecSort(s) -> s)) (** @@ -3564,91 +3429,91 @@ end = struct The argument must have a bit-vector sort. *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) + expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = - create_expr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) + expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = - create_expr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) + expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) (** Bitwise conjunction. The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - create_expr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) + expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) (** Unsigned division. @@ -3660,7 +3525,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) (** Signed division. @@ -3675,7 +3540,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) (** Unsigned remainder. @@ -3685,7 +3550,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) (** Signed remainder. @@ -3697,7 +3562,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed remainder (sign follows divisor). @@ -3706,7 +3571,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) (** Unsigned less-than @@ -3714,7 +3579,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed less-than @@ -3722,7 +3587,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) (** Unsigned less-than or equal to. @@ -3730,7 +3595,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed less-than or equal to. @@ -3738,7 +3603,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) (** Unsigned greater than or equal to. @@ -3746,7 +3611,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed greater than or equal to. @@ -3754,7 +3619,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) (** Unsigned greater-than. @@ -3762,7 +3627,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed greater-than. @@ -3770,7 +3635,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) (** Bit-vector concatenation. @@ -3781,7 +3646,7 @@ end = struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) (** Bit-vector extraction. @@ -3792,7 +3657,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) + expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) (** Bit-vector sign extension. @@ -3802,7 +3667,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) (** Bit-vector zero extension. @@ -3813,7 +3678,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) (** Bit-vector repetition. @@ -3821,7 +3686,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) (** Shift left. @@ -3836,7 +3701,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) (** @@ -3851,7 +3716,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) (** Arithmetic shift right @@ -3867,7 +3732,7 @@ end = struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) (** Rotate Left. @@ -3876,7 +3741,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) (** Rotate Right. @@ -3885,7 +3750,7 @@ end = struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - create_expr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) + expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) (** Rotate Left. @@ -3894,7 +3759,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) (** Rotate Right. @@ -3904,7 +3769,7 @@ end = struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - create_expr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) + expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) (** Create an integer from the bit-vector argument . @@ -3922,7 +3787,7 @@ end = struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = - Arithmetic.Integers.create_expr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) + Arithmetic.Integer.create_expr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3930,7 +3795,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Booleans.create_expr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3938,7 +3803,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise subtraction does not overflow. @@ -3946,7 +3811,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise subtraction does not underflow. @@ -3954,7 +3819,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Booleans.create_expr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3962,7 +3827,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise negation does not overflow. @@ -3970,7 +3835,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3978,7 +3843,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Booleans.create_expr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3986,7 +3851,7 @@ end = struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Booleans.create_expr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2)) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) (** Create a bit-vector numeral. @@ -3994,28 +3859,27 @@ end = struct @param v A string representing the value in decimal notation. @param size the size of the bit-vector *) - let mk_numeral ( ctx : context ) ( ctx : context ) ( v : string ) ( size : int) = + let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx size))) end (** Functions to manipulate proof expressions *) -and Proofs : -sig -end = struct +module Proof = +struct (** Indicates whether the term is a Proof for the expression 'true'. *) - let is_true ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) (** Indicates whether the term is a proof for a fact asserted by the user. *) - let is_asserted ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) + let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - let is_goal ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) (** Indicates whether the term is proof via modus ponens @@ -4026,7 +3890,7 @@ end = struct [mp T1 T2]: q The second antecedents may also be a proof for (iff p q). *) - let is_modus_ponens ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) + let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) (** Indicates whether the term is a proof for (R t t), where R is a reflexive relation. @@ -4035,7 +3899,7 @@ end = struct equivalence modulo namings, equality and equivalence. That is, R is either '~', '=' or 'iff'. *) - let is_reflexivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) + let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) (** Indicates whether the term is proof by symmetricity of a relation @@ -4045,7 +3909,7 @@ end = struct [symmetry T1]: (R s t) T1 is the antecedent of this proof object. *) - let is_symmetry ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) + let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) (** Indicates whether the term is a proof by transitivity of a relation @@ -4056,7 +3920,7 @@ end = struct T2: (R s u) [trans T1 T2]: (R t u) *) - let is_transitivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) + let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) (** Indicates whether the term is a proof by condensed transitivity of a relation @@ -4076,7 +3940,7 @@ end = struct if there is a path from s to t, if we view every antecedent (R a b) as an edge between a and b. *) - let is_Transitivity_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) (** @@ -4089,7 +3953,7 @@ end = struct Remark: if t_i == s_i, then the antecedent Ti is suppressed. That is, reflexivity proofs are supressed to save space. *) - let is_monotonicity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) + let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) (** Indicates whether the term is a quant-intro proof @@ -4098,7 +3962,7 @@ end = struct T1: (~ p q) [quant-intro T1]: (~ (forall (x) p) (forall (x) q)) *) - let is_quant_intro ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) + let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) (** Indicates whether the term is a distributivity proof object. @@ -4115,7 +3979,7 @@ end = struct Remark. This rule is used by the CNF conversion pass and instantiated by f = or, and g = and. *) - let is_distributivity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) (** Indicates whether the term is a proof by elimination of AND @@ -4124,7 +3988,7 @@ end = struct T1: (and l_1 ... l_n) [and-elim T1]: l_i *) - let is_and_elimination ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) + let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) (** Indicates whether the term is a proof by eliminiation of not-or @@ -4133,7 +3997,7 @@ end = struct T1: (not (or l_1 ... l_n)) [not-or-elim T1]: (not l_i) *) - let is_or_elimination ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) (** Indicates whether the term is a proof by rewriting @@ -4147,11 +4011,11 @@ end = struct Remark: if f is bool, then = is iff. Examples: - (= (+ ( x : Expr.expr ) 0) x) - (= (+ ( x : Expr.expr ) 1 2) (+ 3 x)) - (iff (or ( x : Expr.expr ) false) x) + (= (+ ( x : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) *) - let is_rewrite ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) + let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) (** Indicates whether the term is a proof by rewriting @@ -4166,14 +4030,14 @@ end = struct - When converting bit-vectors to Booleans (BIT2BOOL=true) - When pulling ite expression up (PULL_CHEAP_ITE_TREES=true) *) - let is_rewrite_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) + let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. *) - let is_pull_quant ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) (** Indicates whether the term is a proof for pulling quantifiers out. @@ -4182,7 +4046,7 @@ end = struct This proof object is only used if the parameter PROOF_MODE is 1. This proof object has no antecedents *) - let is_pull_quant_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) (** Indicates whether the term is a proof for pushing quantifiers in. @@ -4195,7 +4059,7 @@ end = struct This proof object has no antecedents *) - let is_push_quant ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) + let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) (** Indicates whether the term is a proof for elimination of unused variables. @@ -4207,34 +4071,34 @@ end = struct This proof object has no antecedents. *) - let is_elim_unused_vars ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : Expr.expr ) t)) P[x])) P[t]) - if ( x : Expr.expr ) does not occur in t. + (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. This proof object has no antecedents. Several variables can be eliminated simultaneously. *) - let is_der ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) + let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) (** Indicates whether the term is a proof for quantifier instantiation A proof of (or (not (forall (x) (P x))) (P a)) *) - let is_quant_inst ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) + let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) (** Indicates whether the term is a hypthesis marker. Mark a hypothesis in a natural deduction style proof. *) - let is_hypothesis ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) + let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) (** Indicates whether the term is a proof by lemma @@ -4246,7 +4110,7 @@ end = struct It converts the proof in a proof for (or (not l_1) ... (not l_n)), when T1 contains the hypotheses: l_1, ..., l_n. *) - let is_lemma ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) + let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) (** Indicates whether the term is a proof by unit resolution @@ -4257,7 +4121,7 @@ end = struct T(n+1): (not l_n) [unit-resolution T1 ... T(n+1)]: (or l_1' ... l_m') *) - let is_unit_resolution ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) (** Indicates whether the term is a proof by iff-true @@ -4265,7 +4129,7 @@ end = struct T1: p [iff-true T1]: (iff p true) *) - let is_iff_true ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) (** Indicates whether the term is a proof by iff-false @@ -4273,7 +4137,7 @@ end = struct T1: (not p) [iff-false T1]: (iff p false) *) - let is_iff_false ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) + let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) (** Indicates whether the term is a proof by commutativity @@ -4285,7 +4149,7 @@ end = struct This proof object has no antecedents. Remark: if f is bool, then = is iff. *) - let is_commutativity ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) (** Indicates whether the term is a proof for Tseitin-like axioms @@ -4320,7 +4184,7 @@ end = struct unfolding the Boolean connectives in the axioms a small bounded number of steps (=3). *) - let is_def_axiom ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) (** Indicates whether the term is a proof for introduction of a name @@ -4342,7 +4206,7 @@ end = struct Otherwise: [def-intro]: (= n e) *) - let is_def_intro ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) + let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) (** Indicates whether the term is a proof for application of a definition @@ -4351,7 +4215,7 @@ end = struct F is 'equivalent' to n, given that T1 is a proof that n is a name for F. *) - let is_apply_def ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) + let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) (** Indicates whether the term is a proof iff-oeq @@ -4359,7 +4223,7 @@ end = struct T1: (iff p q) [iff~ T1]: (~ p q) *) - let is_iff_oeq ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) + let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) (** Indicates whether the term is a proof for a positive NNF step @@ -4386,7 +4250,7 @@ end = struct NNF_NEG furthermore handles the case where negation is pushed over Boolean connectives 'and' and 'or'. *) - let is_nnf_pos ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) (** Indicates whether the term is a proof for a negative NNF step @@ -4410,7 +4274,7 @@ end = struct [nnf-neg T1 T2 T3 T4]: (~ (not (iff s_1 s_2)) (and (or r_1 r_2) (or r_1' r_2'))) *) - let is_nnf_neg ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) (** Indicates whether the term is a proof for (~ P Q) here Q is in negation normal form. @@ -4421,7 +4285,7 @@ end = struct This proof object may have n antecedents. Each antecedent is a PR_DEF_INTRO. *) - let is_nnf_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) + let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) (** Indicates whether the term is a proof for (~ P Q) where Q is in conjunctive normal form. @@ -4430,19 +4294,19 @@ end = struct 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. *) - let is_cnf_star ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) + let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) (** Indicates whether the term is a proof for a Skolemization step Proof for: - [sk]: (~ (not (forall ( x : Expr.expr ) (p ( x : Expr.expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : Expr.expr ) (p ( x : Expr.expr ) y)) (p (sk y) y)) + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) This proof object has no antecedents. *) - let is_skolemize ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) + let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) (** Indicates whether the term is a proof by modus ponens for equi-satisfiability. @@ -4452,7 +4316,7 @@ end = struct T2: (~ p q) [mp~ T1 T2]: q *) - let is_modus_ponens_oeq ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) (** Indicates whether the term is a proof for theory lemma @@ -4470,7 +4334,7 @@ end = struct (iff (= t1 t2) (and (<= t1 t2) (<= t2 t1))) - gcd-test - Indicates an integer linear arithmetic lemma that uses a gcd test. *) - let is_theory_lemma ( x : Expr.expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) + let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end @@ -4480,10 +4344,8 @@ end of formulas, that can be solved and/or transformed using tactics and solvers. *) module Goal = -struct - type goal = z3_native_object - - (**/**) +struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : goal = { m_ctx = ctx ; m_n_obj = null ; @@ -4492,7 +4354,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** The precision of the goal. @@ -4521,8 +4383,8 @@ struct (** Adds the constraints to the given goal. *) (* CMW: assert seems to be a keyword. *) - let assert_ ( x : goal ) ( constraints : Booleans.bool_expr array ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e) in + let assert_ ( x : goal ) ( constraints : bool_expr array ) = + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in ignore (Array.map f constraints) ; () @@ -4543,7 +4405,7 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = Booleans.create_expr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i) in + let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) @@ -4562,7 +4424,7 @@ struct create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - let simplify ( x : goal ) ( p : Params.params option ) = + let simplify ( x : goal ) ( p : params option ) = let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in Z3native.tactic_inc_ref (z3obj_gnc x) tn ; let arn = match p with @@ -4602,9 +4464,7 @@ end A Model contains interpretations (assignments) of constants and functions. *) module Model = struct - type model = z3_native_object - - (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : model = { m_ctx = ctx ; m_n_obj = null ; @@ -4613,7 +4473,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Function interpretations @@ -4622,9 +4482,7 @@ struct *) module FuncInterp = struct - type func_interp = z3_native_object - - (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_interp = { m_ctx = ctx ; m_n_obj = null ; @@ -4633,17 +4491,15 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Function interpretations entries An Entry object represents an element in the finite map used to a function interpretation. *) module FuncEntry = - struct - type func_entry = z3_native_object - - (**/**) + struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_entry = { m_ctx = ctx ; m_n_obj = null ; @@ -4652,13 +4508,13 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Return the (symbolic) value of this entry. *) let get_value ( x : func_entry ) = - Expr.create (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) + expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) (** The number of arguments of the entry. @@ -4670,7 +4526,7 @@ struct *) let get_args ( x : func_entry ) = let n = (get_num_args x) in - let f i = (Expr.create (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f (** @@ -4698,7 +4554,7 @@ struct (** The (symbolic) `else' value of the function interpretation. *) - let get_else ( x : func_interp ) = Expr.create (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) + let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) (** The arity of the function interpretation @@ -4725,7 +4581,7 @@ struct (** Retrieves the interpretation (the assignment) of in the model. A function declaration of zero arity An expression if the function has an interpretation in the model, null otherwise. *) - let get_const_interp ( x : model ) ( f : FuncDecl.func_decl ) = + let get_const_interp ( x : model ) ( f : func_decl ) = if (FuncDecl.get_arity f) != 0 || (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") @@ -4734,19 +4590,19 @@ struct if (Z3native.is_null np) then None else - Some (Expr.create (z3obj_gc x) np) + Some (expr_of_ptr (z3obj_gc x) np) (** Retrieves the interpretation (the assignment) of in the model. A Constant An expression if the constant has an interpretation in the model, null otherwise. *) - let get_const_interp_e ( x : model ) ( a : Expr.expr ) = get_const_interp x (Expr.get_func_decl a) + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) (** Retrieves the interpretation (the assignment) of a non-constant in the model. A function declaration of non-zero arity A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - let rec get_func_interp ( x : model ) ( f : FuncDecl.func_decl ) = + let rec get_func_interp ( x : model ) ( f : func_decl ) = let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in if (FuncDecl.get_arity f) == 0 then let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in @@ -4759,7 +4615,7 @@ struct raise (Z3native.Exception "Argument was not an array constant") else let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x (FuncDecl.create (z3obj_gc x) fd) + get_func_interp x (func_decl_of_ptr (z3obj_gc x) fd) | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); else let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in @@ -4771,7 +4627,7 @@ struct (** The function declarations of the constants in the model. *) let get_const_decls ( x : model ) = let n = (get_num_consts x) in - let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f @@ -4781,15 +4637,15 @@ struct (** The function declarations of the function interpretations in the model. *) let get_func_decls ( x : model ) = let n = (get_num_consts x) in - let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f (** All symbols that have an interpretation in the model. *) let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in - let f i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = FuncDecl.create (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.append (Array.init n_funcs f) (Array.init n_consts g) (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) @@ -4810,15 +4666,15 @@ struct The evaluation of in the model. *) - let eval ( x : model ) ( t : Expr.expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (ptr_of_expr t) completion) in if not r then raise (ModelEvaluationFailedException "evaluation failed") else - Expr.create (z3obj_gc x) v + expr_of_ptr (z3obj_gc x) v (** Alias for eval. *) - let evaluate ( x : model ) ( t : Expr.expr ) ( completion : bool ) = + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = eval x t completion (** The number of uninterpreted sorts that the model has an interpretation for. *) @@ -4834,7 +4690,7 @@ struct *) let get_sorts ( x : model ) = let n = (get_num_sorts x) in - let f i = (Sort.create (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f @@ -4843,10 +4699,10 @@ struct An uninterpreted sort An array of expressions, where each is an element of the universe of *) - let sort_universe ( x : model ) ( s : Sort.sort ) = - let n_univ = AST.ASTVectors.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in - let n = (AST.ASTVectors.get_size n_univ) in - let f i = (AST.ASTVectors.get n_univ i) in + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in Array.init n f (** Conversion of models to strings. @@ -4866,9 +4722,7 @@ end *) module Probe = struct - type probe = z3_native_object - - (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : probe = { m_ctx = ctx ; m_n_obj = null ; @@ -4877,14 +4731,14 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Execute the probe over the goal. A probe always produce a double value. "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - let apply ( x : probe ) (g : Goal.goal) = + let apply ( x : probe ) (g : goal) = Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (** @@ -4988,10 +4842,8 @@ end It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. *) module Tactic = -struct - type tactic = z3_native_object - - (**/**) +struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : tactic = { m_ctx = ctx ; m_n_obj = null ; @@ -5000,7 +4852,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Tactic application results @@ -5008,9 +4860,7 @@ struct tactic to a goal. It contains the subgoals that were produced. *) module ApplyResult = struct - type apply_result = z3_native_object - - (**/**) + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : apply_result = { m_ctx = ctx ; m_n_obj = null ; @@ -5019,7 +4869,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** The number of Subgoals. *) let get_num_subgoals ( x : apply_result ) = @@ -5039,7 +4889,7 @@ struct goal g, that the ApplyResult was obtained from. #return A model for g *) - let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = + let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) (** A string representation of the ApplyResult. *) @@ -5054,7 +4904,7 @@ struct Params.ParamDescrs.create (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Apply the tactic to the goal. *) - let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = + let apply ( x : tactic ) ( g : goal ) ( p : params option ) = match p with | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) @@ -5122,14 +4972,14 @@ struct If evaluates to false, then the new tactic behaves like the skip tactic. *) (* CMW: when is a keyword *) - let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = + let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) - let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = + let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) (** @@ -5154,7 +5004,7 @@ struct (** Create a tactic that fails if the probe evaluates to false. *) - let fail_if ( ctx : context ) ( p : Probe.probe ) = + let fail_if ( ctx : context ) ( p : probe ) = create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** @@ -5167,14 +5017,14 @@ struct (** Create a tactic that applies using the given set of parameters . *) - let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) (** Create a tactic that applies using the given set of parameters . Alias for UsingParams*) (* CMW: with is a keyword *) - let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + let with_ ( ctx : context ) ( t : tactic ) ( p : params ) = using_params ctx t p (** @@ -5201,10 +5051,8 @@ end (** Solvers *) module Solver = -struct - type solver = z3_native_object - - (**/**) +struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : solver = { m_ctx = ctx ; m_n_obj = null ; @@ -5213,9 +5061,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) - - type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + let string_of_status ( s : status) = match s with | UNSATISFIABLE -> "unsatisfiable" @@ -5224,10 +5070,8 @@ struct (** Objects that track statistical information about solvers. *) module Statistics = - struct - type statistics = z3_native_object - - (**/**) + struct + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : statistics = { m_ctx = ctx ; m_n_obj = null ; @@ -5236,7 +5080,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - (**/**) + (** Statistical data is organized into pairs of \[Key, Entry\], where every @@ -5245,14 +5089,7 @@ struct *) module Entry = struct - type statistics_entry = { - mutable m_key : string; - mutable m_is_int : bool ; - mutable m_is_float : bool ; - mutable m_int : int ; - mutable m_float : float } - - (**/**) + let create_si k v = let res : statistics_entry = { m_key = k ; @@ -5272,7 +5109,7 @@ struct m_float = v } in res - (**/**) + (** The key of the entry. *) let get_key (x : statistics_entry) = x.m_key @@ -5344,7 +5181,7 @@ struct (** Sets the solver parameters. *) - let set_parameters ( x : solver ) ( p : Params.params )= + let set_parameters ( x : solver ) ( p : params )= Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** @@ -5382,8 +5219,8 @@ struct (** Assert a constraint (or multiple) into the solver. *) - let assert_ ( x : solver ) ( constraints : Booleans.bool_expr array ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e)) in + let assert_ ( x : solver ) ( constraints : bool_expr array ) = + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) (** @@ -5399,11 +5236,11 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( cs : Booleans.bool_expr array ) ( ps : Booleans.bool_expr array ) = + let assert_and_track ( x : solver ) ( cs : bool_expr array ) ( ps : bool_expr array ) = if ((Array.length cs) != (Array.length ps)) then raise (Z3native.Exception "Argument size mismatch") else - let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e) (Booleans.gno (Array.get ps i))) in + let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) (Boolean.gno (Array.get ps i))) in ignore (Array.iteri f cs) (** @@ -5418,24 +5255,24 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( c : Booleans.bool_expr ) ( p : Booleans.bool_expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Booleans.gno c) (Booleans.gno p) + let assert_and_track ( x : solver ) ( c : bool_expr ) ( p : bool_expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) (** The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - (AST.ASTVectors.get_size a) + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + (AST.ASTVector.get_size a) (** The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVectors.get_size a) in - let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get a i)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVector.get_size a) in + let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in Array.init n f (** @@ -5445,12 +5282,13 @@ struct *) - let check ( x : solver ) ( assumptions : Booleans.bool_expr array) = + let check ( x : solver ) ( assumptions : bool_expr array) = let r = if ((Array.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Booleans.aton assumptions)) + let f x = (ptr_of_expr (expr_of_bool_expr x)) in + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Array.map f assumptions)) in match r with | L_TRUE -> SATISFIABLE @@ -5481,7 +5319,7 @@ struct if (Z3native.is_null q) then None else - Some (Expr.create (z3obj_gc x) q) + Some (expr_of_ptr (z3obj_gc x) q) (** The unsat core of the last Check. @@ -5491,9 +5329,9 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVectors.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVectors.get_size cn) in - let f i = (AST.ASTVectors.get cn i) in + let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVector.get_size cn) in + let f i = (AST.ASTVector.get cn i) in Array.init n f (** @@ -5515,7 +5353,7 @@ struct check-sat command, and check-sat commands that take more than a given number of milliseconds to be solved. *) - let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = + let mk_solver ( ctx : context ) ( logic : symbol option ) = match logic with | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) @@ -5539,7 +5377,7 @@ struct The solver supports the commands Push and Pop, but it will always solve each check from scratch. *) - let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = + let mk_solver_t ( ctx : context ) ( t : tactic ) = (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) (** @@ -5551,10 +5389,7 @@ end (** Fixedpoint solving *) module Fixedpoint = -struct - type fixedpoint = z3_native_object - - (**/**) +struct let create ( ctx : context ) = let res : fixedpoint = { m_ctx = ctx ; m_n_obj = null ; @@ -5563,7 +5398,7 @@ struct (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; (z3obj_create res) ; res - (**/**) + (** A string that describes all available fixedpoint solver parameters. @@ -5574,7 +5409,7 @@ struct (** Sets the fixedpoint solver parameters. *) - let set_params ( x : fixedpoint ) ( p : Params.params )= + let set_params ( x : fixedpoint ) ( p : params )= Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** @@ -5586,29 +5421,29 @@ struct (** Assert a constraints into the fixedpoint solver. *) - let assert_ ( x : fixedpoint ) ( constraints : Booleans.bool_expr array ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Booleans.gno e)) in + let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) ; () (** Register predicate as recursive relation. *) - let register_relation ( x : fixedpoint ) ( f : FuncDecl.func_decl ) = + let register_relation ( x : fixedpoint ) ( f : func_decl ) = Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (** Add rule into the fixedpoint solver. *) - let add_rule ( x : fixedpoint ) ( rule : Booleans.bool_expr ) ( name : Symbol.symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) (Symbol.gno y) + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) (** Add table fact to the fixedpoint solver. *) - let add_fact ( x : fixedpoint ) ( pred : FuncDecl.func_decl ) ( args : int array ) = + let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (Array.length args) args (** @@ -5617,11 +5452,11 @@ struct 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. *) - let query ( x : fixedpoint ) ( query : Booleans.bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Booleans.gno query))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN + let query ( x : fixedpoint ) ( query : bool_expr ) = + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with + | L_TRUE -> SATISFIABLE + | L_FALSE -> UNSATISFIABLE + | _ -> UNKNOWN (** Query the fixedpoint solver. @@ -5629,11 +5464,12 @@ struct 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. *) - let query_r ( x : fixedpoint ) ( relations : FuncDecl.func_decl array ) = - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (FuncDecl.aton relations))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN + let query_r ( x : fixedpoint ) ( relations : func_decl array ) = + let f x = ptr_of_ast (ast_of_func_decl x) in + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (Array.map f relations))) with + | L_TRUE -> SATISFIABLE + | L_FALSE -> UNSATISFIABLE + | _ -> UNKNOWN (** Creates a backtracking point. @@ -5654,8 +5490,8 @@ struct (** Update named rule into in the fixedpoint solver. *) - let update_rule ( x : fixedpoint ) ( rule : Booleans.bool_expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Booleans.gno rule) (Symbol.gno name) + let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) (** Retrieve satisfying instance or instances of solver, @@ -5666,7 +5502,7 @@ struct if (Z3native.is_null q) then None else - Some (Expr.create (z3obj_gc x) q) + Some (expr_of_ptr (z3obj_gc x) q) (** Retrieve explanation why fixedpoint engine returned status Unknown. @@ -5677,25 +5513,25 @@ struct (** Retrieve the number of levels explored for a given predicate. *) - let get_num_levels ( x : fixedpoint ) ( predicate : FuncDecl.func_decl ) = + let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) (** Retrieve the cover of a predicate. *) - let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : FuncDecl.func_decl ) = + let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in if (Z3native.is_null q) then None else - Some (Expr.create (z3obj_gc x) q) + Some (expr_of_ptr (z3obj_gc x) q) (** Add property about the predicate. The property is added at level. *) - let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : FuncDecl.func_decl ) ( property : Expr.expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) + let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (ptr_of_expr property) (** Retrieve internal string representation of fixedpoint object. @@ -5705,31 +5541,33 @@ struct (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - let set_predicate_representation ( x : fixedpoint ) ( f : FuncDecl.func_decl ) ( kinds : Symbol.symbol array ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Symbol.aton kinds) + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = + let f2 x = (Symbol.gno x) in + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Array.map f2 kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. *) - let to_string_q ( x : fixedpoint ) ( queries : Booleans.bool_expr array ) = - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Booleans.aton queries) + let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = + let f x = ptr_of_expr (expr_of_bool_expr x) in + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Array.map f queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVectors.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVectors.get_size v) in - let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get v i)) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVector.get_size v) in + let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVectors.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVectors.get_size v) in - let f i = Booleans.create_expr (z3obj_gc x) (z3obj_gno (AST.ASTVectors.get v i)) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVector.get_size v) in + let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f (** @@ -5813,10 +5651,10 @@ struct @param formula Formula to be checked for consistency in conjunction with assumptions. @return A string representation of the benchmark. *) - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Booleans.bool_expr array ) ( formula : Booleans.bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (Booleans.aton assumptions) - (Booleans.gno formula) + (Array.length assumptions) (let f x = ptr_of_expr (expr_of_bool_expr x) in (Array.map f assumptions)) + (Boolean.gno formula) (** Parse the given string using the SMT-LIB parser. @@ -5827,7 +5665,7 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5837,17 +5675,17 @@ struct else Z3native.parse_smtlib_string (context_gno ctx) str cs - (Symbol.aton sort_names) - (Sort.aton sorts) + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) cd - (Symbol.aton decl_names) - (FuncDecl.aton decls) + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)) (** Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5857,11 +5695,11 @@ struct else Z3native.parse_smtlib_file (context_gno ctx) file_name cs - (Symbol.aton sort_names) - (Sort.aton sorts) + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) cd - (Symbol.aton decl_names) - (FuncDecl.aton decls) + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)) (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. @@ -5873,7 +5711,7 @@ struct *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = Booleans.create_expr ctx (Z3native.get_smtlib_formula (context_gno ctx) i) in + let f i = bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in Array.init n f @@ -5887,7 +5725,7 @@ struct *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = Booleans.create_expr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i) in + let f i = bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in Array.init n f (** @@ -5900,7 +5738,7 @@ struct *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in - let f i = FuncDecl.create ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in + let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f (** @@ -5913,7 +5751,7 @@ struct *) let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in - let f i = (Sort.create ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in + let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in Array.init n f (** @@ -5922,7 +5760,7 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5930,19 +5768,19 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (Symbol.aton sort_names) - (Sort.aton sorts) - cd - (Symbol.aton decl_names) - (FuncDecl.aton decls) + bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str + cs + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) + cd + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)))) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : Sort.sort array ) ( decl_names : Symbol.symbol array ) ( decls : FuncDecl.func_decl array ) = + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5950,13 +5788,13 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Z3native.parse_smtlib2_string (context_gno ctx) file_name + bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name cs - (Symbol.aton sort_names) - (Sort.aton sorts) + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) cd - (Symbol.aton decl_names) - (FuncDecl.aton decls) + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)))) end From 4e8d05dcf6bcdd69c85d763dda6730be87783b4d Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 19:51:09 +0000 Subject: [PATCH 174/248] ML API: formatting. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.mli | 3331 +++++++++------------------------------------ 1 file changed, 654 insertions(+), 2677 deletions(-) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index b2f0939d0..f82492e8a 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1,3001 +1,978 @@ (** - The Z3 ML/OCaml Interface. + The Z3 ML/Ocaml Interface. Copyright (C) 2012 Microsoft Corporation @author CM Wintersteiger (cwinter) 2012-12-17 *) -(** General Z3 exceptions - - Many functions in this API may throw an exception; if they do, it is this one.*) -exception Error of string - -(** Context objects. - - Most interactions with Z3 are interpreted in some context; many users will only - require one such object, but power users may require more than one. To start using - Z3, do - - - let ctx = (mk_context []) in - (...) - - - where a list of pairs of strings may be passed to set options on - the context, e.g., like so: - - - let cfg = [("model", "true"); ("...", "...")] in - let ctx = (mk_context cfg) in - (...) - -*) type context -(** Create a context object - The following parameters can be set: - - - proof (Boolean) Enable proof generation - - debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting - - trace (Boolean) Tracing support for VCC - - trace_file_name (String) Trace out file for VCC traces - - timeout (unsigned) default timeout (in milliseconds) used for solvers - - well_sorted_check type checker - - auto_config use heuristics to automatically select solver and configure it - - model model generation for solvers, this parameter can be overwritten when creating a solver - - model_validate validate models produced by solvers - - unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver -*) -val mk_context : (string * string) list -> context +type int_symbol +type string_symbol +type symbol = S_Int of int_symbol | S_Str of string_symbol + +type ast +type ast_vector +type ast_map + +type sort = Sort of ast + +type uninterpreted_sort = UninterpretedSort of sort +type bool_sort = BoolSort of sort +type array_sort = ArraySort of sort +type set_sort = SetSort of sort +type datatype_sort = DatatypeSort of sort +type relation_sort = RelationSort of sort +type finite_domain_sort = FiniteDomainSort of sort +type enum_sort = EnumSort of sort +type list_sort = ListSort of sort +type tuple_sort = TupleSort of sort +type arith_sort = ArithSort of sort +type bitvec_sort = BitVecSort of sort +type int_sort = IntSort of arith_sort +type real_sort = RealSort of arith_sort + +type func_decl = FuncDecl of ast + +type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of symbol + | P_Srt of sort + | P_Ast of ast + | P_Fdl of func_decl + | P_Rat of string + +type params +type param_descrs + +type expr = Expr of ast +type bool_expr = BoolExpr of expr +type arith_expr = ArithExpr of expr +type int_expr = IntExpr of arith_expr +type real_expr = RealExpr of arith_expr +type bitvec_expr = BitVecExpr of expr +type array_expr = ArrayExpr of expr +type datatype_expr = DatatypeExpr of expr +type int_num = IntNum of int_expr +type rat_num = RatNum of real_expr +type algebraic_num = AlgebraicNum of arith_expr +type bitvec_num = BitVecNum of bitvec_expr +type quantifier = Quantifier of expr +type pattern = Pattern of ast + +type constructor + +type goal + +type model +type func_interp +type func_entry + +type probe + +type tactic +type apply_result + +type solver +type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + +type statistics +type statistics_entry + +type fixedpoint + +val ast_of_sort : sort -> ast +val sort_of_uninterpreted_sort : uninterpreted_sort -> sort +val sort_of_bool_sort : bool_sort -> sort +val sort_of_array_sort : array_sort -> sort +val sort_of_set_sort : set_sort -> sort +val sort_of_datatype_sort : datatype_sort -> sort +val sort_of_relation_sort : relation_sort -> sort +val sort_of_finite_domain_sort : finite_domain_sort -> sort +val sort_of_enum_sort : enum_sort -> sort +val sort_of_list_sort : list_sort -> sort +val sort_of_tuple_sort : tuple_sort -> sort +val sort_of_arith_sort : arith_sort -> sort +val sort_of_bitvec_sort : bitvec_sort -> sort +val arith_sort_of_int_sort : int_sort -> arith_sort +val arith_sort_of_real_sort : real_sort -> arith_sort +val uninterpreted_sort_of_sort : sort -> uninterpreted_sort +val bool_sort_of_sort : sort -> bool_sort +val array_sort_of_sort : sort -> array_sort +val datatype_sort_of_sort : sort -> datatype_sort +val relation_sort_of_sort : sort -> relation_sort +val finite_domain_sort_of_sort : sort -> finite_domain_sort +val arith_sort_of_sort : sort -> arith_sort +val bitvec_sort_of_sort : sort -> bitvec_sort +val int_sort_of_arith_sort : arith_sort -> int_sort +val real_sort_of_arith_sort : arith_sort -> real_sort +val ast_of_func_decl : func_decl -> ast +val ast_of_expr : expr -> ast +val expr_of_bool_expr : bool_expr -> expr +val expr_of_arith_expr : arith_expr -> expr +val expr_of_bitvec_expr : bitvec_expr -> expr +val expr_of_array_expr : array_expr -> expr +val expr_of_datatype_expr : datatype_expr -> expr +val arith_expr_of_int_expr : int_expr -> arith_expr +val arith_expr_of_real_expr : real_expr -> arith_expr +val int_expr_of_int_num : int_num -> int_expr +val real_expr_of_rat_num : rat_num -> real_expr +val arith_expr_of_algebraic_num : algebraic_num -> arith_expr +val bitvec_expr_of_bitvec_num : bitvec_num -> bitvec_expr +val expr_of_quantifier : quantifier -> expr +val ast_of_pattern : pattern -> ast +val expr_of_ast : ast -> expr +val bool_expr_of_expr : expr -> bool_expr +val arith_expr_of_expr : expr -> arith_expr +val bitvec_expr_of_expr : expr -> bitvec_expr +val array_expr_of_expr : expr -> array_expr +val datatype_expr_of_expr : expr -> datatype_expr +val int_expr_of_arith_expr : arith_expr -> int_expr +val real_expr_of_arith_expr : arith_expr -> real_expr +val int_num_of_int_expr : int_expr -> int_num +val rat_num_of_real_expr : real_expr -> rat_num +val algebraic_num_of_arith_expr : arith_expr -> algebraic_num +val bitvec_num_of_bitvec_expr : bitvec_expr -> bitvec_num +val quantifier_of_expr : expr -> quantifier +val pattern_of_ast : ast -> pattern -(** 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. *) module Log : sig - (** Open an interaction log file. - @return True if opening the log file succeeds, false otherwise. *) - (* CMW: "open" is a reserved keyword. *) val open_ : string -> bool - - (** Closes the interaction log. *) - val close : unit -> unit - - (** Appends a user-provided string to the interaction log. *) + val close : unit val append : string -> unit end -(** Version information *) module Version : sig - (** The major version. *) val major : int - - (** The minor version. *) val minor : int - - (** The build version. *) val build : int - - (** The revision. *) val revision : int - - (** A string representation of the version information. *) val to_string : string end -(** Symbols are used to name several term and type constructors *) +val mk_context : (string * string) list -> context + module Symbol : sig - type symbol - - (** The kind of the symbol (int or string) *) val kind : symbol -> Z3enums.symbol_kind - - (** Indicates whether the symbol is of Int kind *) val is_int_symbol : symbol -> bool - - (** Indicates whether the symbol is of string kind. *) val is_string_symbol : symbol -> bool - - (** The int value of the symbol. *) - val get_int : symbol -> int - - (** The string value of the symbol. *) - val get_string : symbol -> string - - (** A string representation of the symbol. *) + val get_int : int_symbol -> int + val get_string : string_symbol -> string val to_string : symbol -> string - - (** 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. *) val mk_int : context -> int -> symbol - - (** Creates a new symbol using a string. *) val mk_string : context -> string -> symbol - - (** Create a list of symbols. *) - val mk_ints : context -> int list -> symbol list - - (** Create a list of symbols. *) - val mk_strings : context -> string list -> symbol list + val mk_ints : context -> int array -> symbol array + val mk_strings : context -> string array -> symbol array end -(** The abstract syntax tree (AST) module *) module AST : sig - type ast - (** Vectors of ASTs *) module ASTVector : sig - type ast_vector - - (** Create an empty AST vector *) - val mk_ast_vector : context -> ast_vector - - (** The size of the vector *) val get_size : ast_vector -> int - - (** Retrieves the i-th object in the vector. - @return An AST *) - val get : ast_vector -> int -> ast - - (** Sets the i-th object in the vector. *) + val get : ast_vector -> int -> ast_vector val set : ast_vector -> int -> ast -> unit - - (** Resize the vector to a new size. *) val resize : ast_vector -> int -> unit - - (** Add an ast to the back of the vector. The size - is increased by 1. *) val push : ast_vector -> ast -> unit - - (** Translates all ASTs in the vector to another context. - @return A new ASTVector *) val translate : ast_vector -> context -> ast_vector - - (** Retrieves a string representation of the vector. *) val to_string : ast_vector -> string end - (** Map from AST to AST *) module ASTMap : sig - type ast_map - - (** Create an empty mapping from AST to AST *) - val mk_ast_map : context -> ast_map - - (** Checks whether the map contains a key. - @return True if the key in the map, false otherwise. *) val contains : ast_map -> ast -> bool - - (** Finds the value associated with the key. - This function signs an error when the key is not a key in the map. *) - val find : ast_map -> ast -> ast - - (** Stores or replaces a new key/value pair in the map. *) + val find : ast_map -> ast -> ast_map val insert : ast_map -> ast -> ast -> unit - - (** Erases the key from the map.*) val erase : ast_map -> ast -> unit - - (** Removes all keys from the map. *) val reset : ast_map -> unit - - (** The size of the map *) val get_size : ast_map -> int - - (** The keys stored in the map. *) - val get_keys : ast_map -> ast list - - (** Retrieves a string representation of the map.*) + val get_keys : ast_map -> ast_vector val to_string : ast_map -> string end - (** The AST's hash code. - @return A hash code *) - val hash : ast -> int - - (** A unique identifier for the AST (unique among all ASTs). *) + val get_hash_code : ast -> int val get_id : ast -> int - - (** The kind of the AST. *) val get_ast_kind : ast -> Z3enums.ast_kind - - (** Indicates whether the AST is an Expr *) val is_expr : ast -> bool - - (** Indicates whether the AST is a bound variable*) val is_var : ast -> bool - - (** Indicates whether the AST is a Quantifier *) val is_quantifier : ast -> bool - - (** Indicates whether the AST is a Sort *) val is_sort : ast -> bool - - (** Indicates whether the AST is a func_decl *) val is_func_decl : ast -> bool - - (** A string representation of the AST. *) val to_string : ast -> string - - (** A string representation of the AST in s-expression notation. *) val to_sexpr : ast -> string - - (** Comparison operator. - @return True if the two ast's are from the same context - and represent the same sort; false otherwise. *) - val equal : ast -> ast -> bool - - (** Object Comparison. - @return Negative if the first ast should be sorted before the second, positive if after else zero. *) + val ( = ) : ast -> ast -> bool val compare : ast -> ast -> int - - (** Translates (copies) the AST to another context. - @return A copy of the AST which is associated with the other context. *) + val ( < ) : ast -> ast -> int val translate : ast -> context -> ast - - (** 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., - [Z3native.inc_ref]). - {!wrap_ast} *) + val wrap : context -> Z3native.z3_ast -> ast val unwrap_ast : ast -> Z3native.ptr - - (** Wraps an AST. - - This function is used for transitions between native and - managed objects. Note that the native ast that is passed must be a - native object obtained from Z3 (e.g., through {!unwrap_ast}) - and that it must have a correct reference count (see e.g., - [Z3native.inc_ref]). *) - val wrap_ast : context -> Z3native.z3_ast -> ast end -(** The Sort module implements type information for ASTs *) module Sort : sig - type sort = Sort of AST.ast - - val ast_of_sort : sort -> AST.ast - - (** Comparison operator. - @return True if the two sorts are from the same context - and represent the same sort; false otherwise. *) - val equal : sort -> sort -> bool - - (** Returns a unique identifier for the sort. *) + val ( = ) : sort -> sort -> bool val get_id : sort -> int - - (** The kind of the sort. *) val get_sort_kind : sort -> Z3enums.sort_kind - - (** The name of the sort *) - val get_name : sort -> Symbol.symbol - - (** A string representation of the sort. *) + val get_name : sort -> symbol val to_string : sort -> string - - (** Create a new uninterpreted sort. *) - val mk_uninterpreted : context -> Symbol.symbol -> sort - - (** Create a new uninterpreted sort. *) - val mk_uninterpreted_s : context -> string -> sort + val mk_uninterpreted : context -> symbol -> uninterpreted_sort + val mk_uninterpreted_s : context -> string -> uninterpreted_sort end -(** Function declarations *) -module rec FuncDecl : +module FuncDecl : sig - type func_decl = FuncDecl of AST.ast - val ast_of_func_decl : FuncDecl.func_decl -> AST.ast - - (** Parameters of Func_Decls *) module Parameter : sig - (** Parameters of func_decls *) - type parameter = - P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - (** The kind of the parameter. *) val get_kind : parameter -> Z3enums.parameter_kind - - (** The int value of the parameter.*) val get_int : parameter -> int - - (** The float value of the parameter.*) val get_float : parameter -> float - - (** The Symbol.Symbol value of the parameter.*) - val get_symbol : parameter -> Symbol.symbol - - (** The Sort value of the parameter.*) - val get_sort : parameter -> Sort.sort - - (** The AST value of the parameter.*) - val get_ast : parameter -> AST.ast - - (** The FunctionDeclaration value of the parameter.*) - val get_func_decl : parameter -> func_decl - - (** The rational string value of the parameter.*) - val get_rational : parameter -> string + val get_symbol : parameter -> symbol + val get_sort : parameter -> sort + val get_ast : parameter -> ast + val get_func_decl : parameter -> string end - (** Creates a new function declaration. *) - val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl - - (** Creates a new function declaration. *) - val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl - (** Creates a fresh function declaration with a name prefixed with a prefix string. *) - - val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl - - (** Creates a new constant function declaration. *) - val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl - - (** Creates a new constant function declaration. *) - val mk_const_decl_s : context -> string -> Sort.sort -> func_decl - - (** Creates a fresh constant function declaration with a name prefixed with a prefix string. - {!mk_func_decl} - {!mk_func_decl} *) - val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl - - (** Comparison operator. - @return True if a and b are from the same context and represent the same func_decl; false otherwise. *) - val equal : func_decl -> func_decl -> bool - - (** A string representations of the function declaration. *) + val mk_func_decl : context -> symbol -> sort array -> sort -> func_decl + val mk_func_decl_s : context -> string -> sort array -> sort -> func_decl + val mk_fresh_func_decl : context -> string -> sort array -> sort -> func_decl + val mk_const_decl : context -> symbol -> sort -> func_decl + val mk_const_decl_s : context -> string -> sort -> func_decl + val mk_fresh_const_decl : context -> string -> sort -> func_decl + val ( = ) : func_decl -> func_decl -> bool val to_string : func_decl -> string - - (** Returns a unique identifier for the function declaration. *) val get_id : func_decl -> int - - (** The arity of the function declaration *) val get_arity : func_decl -> int - - (** The size of the domain of the function declaration - {!get_arity} *) val get_domain_size : func_decl -> int - - (** The domain of the function declaration *) - val get_domain : func_decl -> Sort.sort list - - (** The range of the function declaration *) - val get_range : func_decl -> Sort.sort - - (** The kind of the function declaration. *) + val get_domain : func_decl -> sort array + val get_range : func_decl -> sort val get_decl_kind : func_decl -> Z3enums.decl_kind - - (** The name of the function declaration*) - val get_name : func_decl -> Symbol.symbol - - (** The number of parameters of the function declaration *) + val get_name : func_decl -> symbol val get_num_parameters : func_decl -> int - - (** The parameters of the function declaration *) - val get_parameters : func_decl -> Parameter.parameter list - - (** Create expression that applies function to arguments. *) - val apply : func_decl -> Expr.expr list -> Expr.expr + val get_parameters : func_decl -> parameter list + val apply : func_decl -> expr array -> expr end -(** Parameter sets (of Solvers, Tactics, ...) - - A Params objects represents a configuration in the form of Symbol.symbol/value pairs. *) -and Params : +module Params : sig - type params - (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) module ParamDescrs : sig - type param_descrs - - (** Validate a set of parameters. *) val validate : param_descrs -> params -> unit - - (** Retrieve kind of parameter. *) - val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind - - (** Retrieve all names of parameters. *) - val get_names : param_descrs -> Symbol.symbol list - - (** The size of the ParamDescrs. *) + val get_kind : param_descrs -> symbol -> Z3enums.param_kind + val get_names : param_descrs -> symbol array val get_size : param_descrs -> int - - (** Retrieves a string representation of the ParamDescrs. *) val to_string : param_descrs -> string end - (** Adds a parameter setting. *) - val add_bool : params -> Symbol.symbol -> bool -> unit - - (** Adds a parameter setting. *) - val add_int : params -> Symbol.symbol -> int -> unit - - (** Adds a parameter setting. *) - val add_float : params -> Symbol.symbol -> float -> unit - - (** Adds a parameter setting. *) - val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - - (** Creates a new parameter set *) + val add_bool : params -> symbol -> bool -> unit + val add_int : params -> symbol -> int -> unit + val add_double : params -> symbol -> float -> unit + val add_symbol : params -> symbol -> symbol -> unit + val add_s_bool : params -> string -> bool -> unit + val add_s_int : params -> string -> int -> unit + val add_s_double : params -> string -> float -> unit + val add_s_symbol : params -> string -> symbol -> unit val mk_params : context -> params - - (** A string representation of the parameter set. *) val to_string : params -> string - - (** Update a mutable configuration parameter. - - The list of all configuration parameters can be obtained using the Z3 executable: - [z3.exe -p] - Only a few configuration parameters are mutable once the context is created. - An exception is thrown when trying to modify an immutable parameter. *) - val update_param_value : context -> string -> string -> unit - - (** 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 PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - {!AST.to_string} - {!Quantifier.Pattern.to_string} - {!FuncDecl.to_string} - {!Sort.to_string} *) - val set_print_mode : context -> Z3enums.ast_print_mode -> unit end -(** General Expressions (terms) *) -and Expr : +module Expr : sig - type expr = Expr of AST.ast - - val ast_of_expr : Expr.expr -> AST.ast - val expr_of_ast : AST.ast -> Expr.expr - - (** Returns a simplified version of the expression. - {!get_simplify_help} *) - val simplify : Expr.expr -> Params.params option -> expr - - (** A string describing all available parameters to [Expr.Simplify]. *) + val simplify : expr -> params option -> expr val get_simplify_help : context -> string - - (** Retrieves parameter descriptions for simplifier. *) - val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs - - (** The function declaration of the function that is applied in this expression. *) - val get_func_decl : Expr.expr -> FuncDecl.func_decl - - (** The number of arguments of the expression. *) - val get_num_args : Expr.expr -> int - - (** The arguments of the expression. *) - val get_args : Expr.expr -> Expr.expr list - - (** Update the arguments of the expression using an array of expressions. - The number of new arguments should coincide with the current number of arguments. *) - val update : Expr.expr -> Expr.expr list -> expr - - (** 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]]. *) - val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr - - (** Substitute every occurrence of [from] in the expression with [to]. - {!substitute} *) - val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr - - (** Substitute the free variables in the expression with the expressions in the expr array - - For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term [to[i]]. *) - val substitute_vars : Expr.expr -> Expr.expr list -> expr - - (** Translates (copies) the term to another context. - @return A copy of the term which is associated with the other context *) - val translate : Expr.expr -> context -> expr - - (** Returns a string representation of the expression. *) - val to_string : Expr.expr -> string - - (** Indicates whether the term is a numeral *) - val is_numeral : Expr.expr -> bool - - (** Indicates whether the term is well-sorted. - @return True if the term is well-sorted, false otherwise. *) - val is_well_sorted : Expr.expr -> bool - - (** The Sort of the term. *) - val get_sort : Expr.expr -> Sort.sort - - (** Indicates whether the term represents a constant. *) - val is_const : Expr.expr -> bool - - (** Creates a new constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - - (** Creates a new constant. *) - val mk_const_s : context -> string -> Sort.sort -> expr - - (** Creates a constant from the func_decl. *) - val mk_const_f : context -> FuncDecl.func_decl -> expr - - (** Creates a fresh constant with a name prefixed with a string. *) - val mk_fresh_const : context -> string -> Sort.sort -> expr - - (** Create a new function application. *) - val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr - - (** Create a numeral of a given sort. - @return A Term with the given value and sort *) - val mk_numeral_string : context -> string -> Sort.sort -> expr - - (** Create a numeral 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. - @return A Term with the given value and sort *) - val mk_numeral_int : context -> int -> Sort.sort -> expr - - (** Comparison operator. - @return True if the two expr's are equal; false otherwise. *) - val equal : expr -> expr -> bool - - (** Object Comparison. - @return Negative if the first expr should be sorted before the second, positive if after, else zero. *) - val compare : expr -> expr -> int + val get_simplify_parameter_descrs : context -> param_descrs + val get_func_decl : expr -> func_decl + val get_bool_value : expr -> Z3enums.lbool + val get_num_args : expr -> int + val get_args : expr -> expr array + val update : expr -> expr array -> expr + val substitute : expr -> expr array -> expr array -> expr + val substitute_one : expr -> expr -> expr -> expr + val substitute_vars : expr -> expr array -> expr + val translate : expr -> context -> expr + val to_string : expr -> string + val is_numeral : expr -> bool + val is_well_sorted : expr -> bool + val get_sort : expr -> sort + val is_bool : expr -> bool + val is_const : expr -> bool + val is_true : expr -> bool + val is_false : expr -> bool + val is_eq : expr -> bool + val is_distinct : expr -> bool + val is_ite : expr -> bool + val is_and : expr -> bool + val is_or : expr -> bool + val is_iff : expr -> bool + val is_xor : expr -> bool + val is_not : expr -> bool + val is_implies : expr -> bool + val is_label : expr -> bool + val is_oeq : expr -> bool + val mk_const : context -> symbol -> sort -> expr + val mk_const_s : context -> string -> sort -> expr + val mk_const_f : context -> func_decl -> expr + val mk_fresh_const : context -> string -> sort -> expr + val mk_app : context -> func_decl -> expr array -> expr + val mk_numeral_string : context -> string -> sort -> expr + val mk_numeral_int : context -> int -> sort -> expr end -(** Boolean expressions; Propositional logic and equality *) module Boolean : sig - (** Create a Boolean sort *) - val mk_sort : context -> Sort.sort - - (** Create a Boolean constant. *) - val mk_const : context -> Symbol.symbol -> Expr.expr - - (** Create a Boolean constant. *) - val mk_const_s : context -> string -> Expr.expr - - (** The true Term. *) - val mk_true : context -> Expr.expr - - (** The false Term. *) - val mk_false : context -> Expr.expr - - (** Creates a Boolean value. *) - val mk_val : context -> bool -> Expr.expr - - (** Mk an expression representing [not(a)]. *) - val mk_not : context -> Expr.expr -> Expr.expr - - (** Create an expression representing an if-then-else: [ite(t1, t2, t3)]. *) - val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 iff t2]. *) - val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 -> t2]. *) - val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 xor t2]. *) - val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing the AND of args *) - val mk_and : context -> Expr.expr list -> Expr.expr - - (** Create an expression representing the OR of args *) - val mk_or : context -> Expr.expr list -> Expr.expr - - (** Creates the equality between two expr's. *) - val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Creates a [distinct] term. *) - val mk_distinct : context -> Expr.expr list -> Expr.expr - - (** Indicates whether the expression is the true or false expression - or something else (L_UNDEF). *) - val get_bool_value : Expr.expr -> Z3enums.lbool - - (** Indicates whether the term has Boolean sort. *) - val is_bool : Expr.expr -> bool - - (** Indicates whether the term is the constant true. *) - val is_true : Expr.expr -> bool - - (** Indicates whether the term is the constant false. *) - val is_false : Expr.expr -> bool - - (** Indicates whether the term is an equality predicate. *) - val is_eq : Expr.expr -> bool - - (** Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). *) - val is_distinct : Expr.expr -> bool - - (** Indicates whether the term is a ternary if-then-else term *) - val is_ite : Expr.expr -> bool - - (** Indicates whether the term is an n-ary conjunction *) - val is_and : Expr.expr -> bool - - (** Indicates whether the term is an n-ary disjunction *) - val is_or : Expr.expr -> bool - - (** Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) *) - val is_iff : Expr.expr -> bool - - (** Indicates whether the term is an exclusive or *) - val is_xor : Expr.expr -> bool - - (** Indicates whether the term is a negation *) - val is_not : Expr.expr -> bool - - (** Indicates whether the term is an implication *) - val is_implies : Expr.expr -> bool + val mk_sort : context -> bool_sort + val mk_const : context -> symbol -> bool_expr + val mk_const_s : context -> string -> bool_expr + val mk_true : context -> bool_expr + val mk_false : context -> bool_expr + val mk_val : context -> bool -> bool_expr + val mk_eq : context -> expr -> expr -> bool_expr + val mk_distinct : context -> expr array -> bool_expr + val mk_not : context -> bool_expr -> bool_expr + val mk_ite : context -> bool_expr -> bool_expr -> bool_expr -> bool_expr + val mk_iff : context -> bool_expr -> bool_expr -> bool_expr + val mk_implies : context -> bool_expr -> bool_expr -> bool_expr + val mk_xor : context -> bool_expr -> bool_expr -> bool_expr + val mk_and : context -> bool_expr array -> bool_expr + val mk_or : context -> bool_expr array -> bool_expr end -(** Quantifier expressions *) module Quantifier : sig - type quantifier = Quantifier of Expr.expr - val expr_of_quantifier : quantifier -> Expr.expr - val quantifier_of_expr : Expr.expr -> quantifier - - (** Quantifier patterns - - 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. *) module Pattern : sig - type pattern = Pattern of AST.ast - - val ast_of_pattern : pattern -> AST.ast - val pattern_of_ast : AST.ast -> pattern - - (** The number of terms in the pattern. *) val get_num_terms : pattern -> int - - (** The terms in the pattern. *) - val get_terms : pattern -> Expr.expr list - - (** A string representation of the pattern. *) + val get_terms : pattern -> expr array val to_string : pattern -> string end - - (** 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 : expr ) appears, the higher is its - index. *) - val get_index : Expr.expr -> int - - (** Indicates whether the quantifier is universal. *) + val get_index : expr -> int val is_universal : quantifier -> bool - - (** Indicates whether the quantifier is existential. *) val is_existential : quantifier -> bool - - (** The weight of the quantifier. *) val get_weight : quantifier -> int - - (** The number of patterns. *) val get_num_patterns : quantifier -> int - - (** The patterns. *) - val get_patterns : quantifier -> Pattern.pattern list - - (** The number of no-patterns. *) + val get_patterns : quantifier -> pattern array val get_num_no_patterns : quantifier -> int - - (** The no-patterns. *) - val get_no_patterns : quantifier -> Pattern.pattern list - - (** The number of bound variables. *) + val get_no_patterns : quantifier -> pattern array val get_num_bound : quantifier -> int - - (** The symbols for the bound variables. *) - val get_bound_variable_names : quantifier -> Symbol.symbol list - - (** The sorts of the bound variables. *) - val get_bound_variable_sorts : quantifier -> Sort.sort list - - (** The body of the quantifier. *) - val get_body : quantifier -> Expr.expr - - (** Creates a new bound variable. *) - val mk_bound : context -> int -> Sort.sort -> Expr.expr - - (** Create a quantifier pattern. *) - val mk_pattern : context -> Expr.expr list -> Pattern.pattern - - (** Create a universal Quantifier. *) - val mk_forall : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a universal Quantifier. *) - val mk_forall_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create an existential Quantifier. *) - val mk_exists : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create an existential Quantifier. *) - val mk_exists_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a Quantifier. *) - val mk_quantifier : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a Quantifier. *) - val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** A string representation of the quantifier. *) - val to_string : quantifier -> string + val get_bound_variable_names : quantifier -> symbol array + val get_bound_variable_sorts : quantifier -> sort array + val get_body : quantifier -> bool_expr + val mk_bound : context -> int -> sort -> expr + val mk_pattern : context -> expr array -> pattern + val mk_forall : + context -> + sort array -> + symbol array -> + expr -> + int option -> + pattern array -> + expr array -> symbol option -> symbol option -> quantifier + val mk_forall_const : + context -> + expr array -> + expr -> + int option -> + pattern array -> + expr array -> symbol option -> symbol option -> quantifier + val mk_exists : + context -> + sort array -> + symbol array -> + expr -> + int option -> + pattern array -> + expr array -> symbol option -> symbol option -> quantifier + val mk_exists_const : + context -> + expr array -> + expr -> + int option -> + pattern array -> + expr array -> symbol option -> symbol option -> quantifier + val mk_quantifier : + context -> + bool -> + expr array -> + expr -> + int option -> + pattern array -> + expr array -> symbol option -> symbol option -> quantifier end -(** Functions to manipulate Array expressions *) -module Z3Array : +module Array_ : sig - (** Create a new array sort. *) - val mk_sort : context -> Sort.sort -> Sort.sort -> Sort.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. *) - val is_store : Expr.expr -> bool - - (** Indicates whether the term is an array select. *) - val is_select : Expr.expr -> bool - - (** 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. *) - val is_constant_array : Expr.expr -> bool - - (** Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. *) - val is_default_array : Expr.expr -> bool - - (** 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. *) - val is_array_map : Expr.expr -> bool - - (** 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. *) - val is_as_array : Expr.expr -> bool - - (** Indicates whether the term is of an array sort. *) - val is_array : Expr.expr -> bool - - (** The domain of the array sort. *) - val get_domain : Sort.sort -> Sort.sort - - (** The range of the array sort. *) - val get_range : Sort.sort -> Sort.sort - - (** Create an array constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> Expr.expr - - (** Create an array constant. *) - val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> Expr.expr - - (** 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]. - {!Z3Array.mk_sort} - {!mk_store} *) - val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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). - {!Z3Array.mk_sort} - {!mk_select} *) - val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create a constant array. - - The resulting term is an array, such that a [select]on an arbitrary index - produces the value [v]. - {!Z3Array.mk_sort} - {!mk_select} *) - val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr - - (** 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]]. - {!Z3Array.mk_sort} - {!mk_select} - {!mk_store} *) - val mk_map : context -> FuncDecl.func_decl -> Expr.expr list -> Expr.expr - - (** Access the array default value. - - Produces the default range value, for arrays that can be represented as - finite maps with a default range value. *) - val mk_term_array : context -> Expr.expr -> Expr.expr + val mk_sort : context -> sort -> sort -> array_sort + val is_store : expr -> bool + val is_select : expr -> bool + val is_constant_array : expr -> bool + val is_default_array : expr -> bool + val is_array_map : expr -> bool + val is_as_array : expr -> bool + val is_array : expr -> bool + val get_domain : array_sort -> sort + val get_range : array_sort -> sort + val mk_const : context -> symbol -> sort -> sort -> array_expr + val mk_const_s : context -> string -> sort -> sort -> array_expr + val mk_select : context -> array_expr -> expr -> expr -> expr + val mk_const_array : context -> sort -> expr -> expr + val mk_map : context -> func_decl -> array_expr array -> expr + val mk_term_array : context -> array_expr -> expr end -(** Functions to manipulate Set expressions *) module Set : sig - (** Create a set type. *) - val mk_sort : context -> Sort.sort -> Sort.sort - - (** Indicates whether the term is set union *) - val is_union : Expr.expr -> bool - - (** Indicates whether the term is set intersection *) - val is_intersect : Expr.expr -> bool - - (** Indicates whether the term is set difference *) - val is_difference : Expr.expr -> bool - - (** Indicates whether the term is set complement *) - val is_complement : Expr.expr -> bool - - (** Indicates whether the term is set subset *) - val is_subset : Expr.expr -> bool - - (** Create an empty set. *) - val mk_empty : context -> Sort.sort -> Expr.expr - - (** Create the full set. *) - val mk_full : context -> Sort.sort -> Expr.expr - - (** Add an element to the set. *) - val mk_set_add : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Remove an element from a set. *) - val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Take the union of a list of sets. *) - val mk_union : context -> Expr.expr list -> Expr.expr - - (** Take the intersection of a list of sets. *) - val mk_intersection : context -> Expr.expr list -> Expr.expr - - (** Take the difference between two sets. *) - val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Take the complement of a set. *) - val mk_complement : context -> Expr.expr -> Expr.expr - - (** Check for set membership. *) - val mk_membership : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Check for subsetness of sets. *) - val mk_subset : context -> Expr.expr -> Expr.expr -> Expr.expr + val is_union : expr -> bool + val is_intersect : expr -> bool + val is_difference : expr -> bool + val is_complement : expr -> bool + val is_subset : expr -> bool + val mk_sort : context -> sort -> set_sort + val mk_empty : context -> sort -> expr + val mk_full : context -> sort -> expr + val mk_set_add : context -> expr -> expr -> expr + val mk_del : context -> expr -> expr -> expr + val mk_union : context -> expr array -> expr + val mk_intersection : context -> expr array -> expr + val mk_difference : context -> expr -> expr -> expr + val mk_complement : context -> expr -> expr + val mk_membership : context -> expr -> expr -> expr + val mk_subset : context -> expr -> expr -> expr end -(** Functions to manipulate Finite Domain expressions *) module FiniteDomain : sig - (** Create a new finite domain sort. *) - val mk_sort : context -> Symbol.symbol -> int -> Sort.sort - - (** Create a new finite domain sort. *) - val mk_sort_s : context -> string -> int -> Sort.sort - - (** Indicates whether the term is of an array sort. *) - val is_finite_domain : Expr.expr -> bool - - (** Indicates whether the term is a less than predicate over a finite domain. *) - val is_lt : Expr.expr -> bool - - (** The size of the finite domain sort. *) - val get_size : Sort.sort -> int + val mk_sort : context -> symbol -> int -> finite_domain_sort + val mk_sort_s : context -> string -> int -> finite_domain_sort + val is_finite_domain : expr -> bool + val is_lt : expr -> bool + val get_size : finite_domain_sort -> int end - -(** Functions to manipulate Relation expressions *) module Relation : sig - (** Indicates whether the term is of a relation sort. *) - val is_relation : Expr.expr -> bool - - (** 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. *) - val is_store : Expr.expr -> bool - - (** Indicates whether the term is an empty relation *) - val is_empty : Expr.expr -> bool - - (** Indicates whether the term is a test for the emptiness of a relation *) - val is_is_empty : Expr.expr -> bool - - (** Indicates whether the term is a relational join *) - val is_join : Expr.expr -> bool - - (** Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. *) - val is_union : Expr.expr -> bool - - (** Indicates whether the term is the widening of two relations - The function takes two arguments. *) - val is_widen : Expr.expr -> bool - - (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. *) - val is_project : Expr.expr -> bool - - (** 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. *) - val is_filter : Expr.expr -> bool - - (** 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. *) - val is_negation_filter : Expr.expr -> bool - - (** 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. *) - val is_rename : Expr.expr -> bool - - (** Indicates whether the term is the complement of a relation *) - val is_complement : Expr.expr -> bool - - (** 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. *) - val is_select : Expr.expr -> bool - - (** 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 {!is_union} - to perform destructive updates to the first argument. *) - val is_clone : Expr.expr -> bool - - (** The arity of the relation sort. *) - val get_arity : Sort.sort -> int - - (** The sorts of the columns of the relation sort. *) - val get_column_sorts : Sort.sort -> Sort.sort list + val is_relation : expr -> bool + val is_store : expr -> bool + val is_empty : expr -> bool + val is_is_empty : expr -> bool + val is_join : expr -> bool + val is_union : expr -> bool + val is_widen : expr -> bool + val is_project : expr -> bool + val is_filter : expr -> bool + val is_negation_filter : expr -> bool + val is_rename : expr -> bool + val is_complement : expr -> bool + val is_select : expr -> bool + val is_clone : expr -> bool + val get_arity : relation_sort -> int + val get_column_sorts : relation_sort -> relation_sort array end -(** Functions to manipulate Datatype expressions *) module Datatype : sig - (** Datatype Constructors *) + module Constructor : sig - type constructor - - (** The number of fields of the constructor. *) + val get_n : constructor -> int + val tester_decl : constructor -> func_decl + val constructor_decl : constructor -> func_decl + val accessor_decls : constructor -> func_decl array val get_num_fields : constructor -> int - - (** The function declaration of the constructor. *) - val get_constructor_decl : constructor -> FuncDecl.func_decl - - (** The function declaration of the tester. *) - val get_tester_decl : constructor -> FuncDecl.func_decl - - (** The function declarations of the accessors *) - val get_accessor_decls : constructor -> FuncDecl.func_decl list + val get_constructor_decl : constructor -> func_decl + val get_tester_decl : constructor -> func_decl + val get_accessor_decls : constructor -> func_decl array end - (** Create a datatype 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. *) - val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor - - (** Create a datatype 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. *) - val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor - - (** Create a new datatype sort. *) - val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> Sort.sort - - (** Create a new datatype sort. *) - val mk_sort_s : context -> string -> Constructor.constructor list -> Sort.sort - - (** Create mutually recursive datatypes. *) - val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> Sort.sort list - - (** Create mutually recursive data-types. *) - val mk_sorts_s : context -> string list -> Constructor.constructor list list -> Sort.sort list - - - (** The number of constructors of the datatype sort. *) - val get_num_constructors : Sort.sort -> int - - (** The constructors. *) - val get_constructors : Sort.sort -> FuncDecl.func_decl list - - (** The recognizers. *) - val get_recognizers : Sort.sort -> FuncDecl.func_decl list - - (** The constructor accessors. *) - val get_accessors : Sort.sort -> FuncDecl.func_decl list list + val mk_constructor : context -> symbol -> symbol -> symbol array -> sort array -> int array -> constructor + val mk_constructor_s : context -> string -> symbol -> symbol array -> sort array -> int array -> constructor + val mk_sort : context -> symbol -> constructor array -> datatype_sort + val mk_sort_s : context -> string -> constructor array -> datatype_sort + val mk_sorts : context -> symbol array -> constructor array array -> datatype_sort array + val mk_sorts_s : context -> string array -> constructor array array -> datatype_sort array + val get_num_constructors : datatype_sort -> int + val get_constructors : datatype_sort -> func_decl array + val get_recognizers : datatype_sort -> func_decl array + val get_accessors : datatype_sort -> func_decl array array end -(** Functions to manipulate Enumeration expressions *) module Enumeration : sig - (** Create a new enumeration sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort - - (** Create a new enumeration sort. *) - val mk_sort_s : context -> string -> string list -> Sort.sort - - (** The function declarations of the constants in the enumeration. *) - val get_const_decls : Sort.sort -> FuncDecl.func_decl list - - (** The test predicates for the constants in the enumeration. *) - val get_tester_decls : Sort.sort -> FuncDecl.func_decl list + val mk_sort : context -> symbol -> symbol array -> enum_sort + val mk_sort_s : context -> string -> string array -> enum_sort + val get_const_decls : enum_sort -> func_decl array + val get_tester_decls : enum_sort -> func_decl array end -(** Functions to manipulate List expressions *) -module Z3List : +module List_ : sig - (** Create a new list sort. *) - val mk_sort : context -> Symbol.symbol -> Sort.sort -> Sort.sort - - (** Create a new list sort. *) - val mk_list_s : context -> string -> Sort.sort -> Sort.sort - - (** The declaration of the nil function of this list sort. *) - val get_nil_decl : Sort.sort -> FuncDecl.func_decl - - (** The declaration of the isNil function of this list sort. *) - val get_is_nil_decl : Sort.sort -> FuncDecl.func_decl - - (** The declaration of the cons function of this list sort. *) - val get_cons_decl : Sort.sort -> FuncDecl.func_decl - - (** The declaration of the isCons function of this list sort. *) - val get_is_cons_decl : Sort.sort -> FuncDecl.func_decl - - (** The declaration of the head function of this list sort. *) - val get_head_decl : Sort.sort -> FuncDecl.func_decl - - (** The declaration of the tail function of this list sort. *) - val get_tail_decl : Sort.sort -> FuncDecl.func_decl - - (** The empty list. *) - val nil : Sort.sort -> Expr.expr + val mk_sort : context -> symbol -> sort -> list_sort + val mk_list_s : context -> string -> sort -> list_sort + val get_nil_decl : list_sort -> func_decl + val get_is_nil_decl : list_sort -> func_decl + val get_cons_decl : list_sort -> func_decl + val get_is_cons_decl : list_sort -> func_decl + val get_head_decl : list_sort -> func_decl + val get_tail_decl : list_sort -> func_decl + val nil : list_sort -> expr end -(** Functions to manipulate Tuple expressions *) module Tuple : sig - (** Create a new tuple sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> Sort.sort - - (** The constructor function of the tuple. *) - val get_mk_decl : Sort.sort -> FuncDecl.func_decl - - (** The number of fields in the tuple. *) - val get_num_fields : Sort.sort -> int - - (** The field declarations. *) - val get_field_decls : Sort.sort -> FuncDecl.func_decl list + val mk_sort : + context -> symbol -> symbol array -> sort array -> tuple_sort + val get_mk_decl : tuple_sort -> func_decl + val get_num_fields : tuple_sort -> int + val get_field_decls : tuple_sort -> func_decl array end -(** Functions to manipulate arithmetic expressions *) module Arithmetic : sig - (** Integer Arithmetic *) + module Integer : sig - (** Create a new integer sort. *) - val mk_sort : context -> Sort.sort - - (** Retrieve the int value. *) - val get_int : Expr.expr -> int - - (** Get a big_int from an integer numeral *) - val get_big_int : Expr.expr -> Big_int.big_int - - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr -> string - - (** Creates an integer constant. *) - val mk_const : context -> Symbol.symbol -> Expr.expr - - (** Creates an integer constant. *) - val mk_const_s : context -> string -> Expr.expr - - (** Create an expression representing [t1 mod t2]. - The arguments must have int type. *) - val mk_mod : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 rem t2]. - The arguments must have int type. *) - val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an integer numeral. *) - val mk_numeral_s : context -> string -> Expr.expr - - (** Create an integer numeral. - @return A Term with the given value and sort Integer *) - val mk_numeral_i : context -> int -> Expr.expr - - (** 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. *) - val mk_int2real : context -> Expr.expr -> Expr.expr - - (** Create an n-bit bit-vector from an 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. *) - val mk_int2bv : context -> int -> Expr.expr -> Expr.expr + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> expr + val mk_rem : context -> int_expr -> int_expr -> expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> real_expr + val mk_int2bv : context -> int -> int_expr -> bitvec_expr end - (** Real Arithmetic *) module Real : sig - (** Create a real sort. *) - val mk_sort : context -> Sort.sort - - (** The numerator of a rational numeral. *) - val get_numerator : Expr.expr -> Expr.expr - - (** The denominator of a rational numeral. *) - val get_denominator : Expr.expr -> Expr.expr - - (** Get a ratio from a real numeral *) - val get_ratio : Expr.expr -> Ratio.ratio - - (** Returns a string representation in decimal notation. - The result has at most as many decimal places as indicated by the int argument.*) - val to_decimal_string : Expr.expr-> int -> string - - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr-> string - - (** Creates a real constant. *) - val mk_const : context -> Symbol.symbol -> Expr.expr - - (** Creates a real constant. *) - val mk_const_s : context -> string -> Expr.expr - - (** Create a real numeral from a fraction. - @return A Term with rational value and sort Real - {!mk_numeral_s} *) - val mk_numeral_nd : context -> int -> int -> Expr.expr - - (** Create a real numeral. - @return A Term with the given value and sort Real *) - val mk_numeral_s : context -> string -> Expr.expr - - (** Create a real numeral. - @return A Term with the given value and sort Real *) - val mk_numeral_i : context -> int -> Expr.expr - - (** Creates an expression that checks whether a real number is an integer. *) - val mk_is_integer : context -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_real2int : context -> Expr.expr -> Expr.expr - - (** Algebraic Numbers *) - module AlgebraicNumber : - sig - (** Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) - val to_upper : Expr.expr -> int -> Expr.expr - - (** Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) - val to_lower : Expr.expr -> int -> Expr.expr - - (** Returns a string representation in decimal notation. - The result has at most as many decimal places as the int argument provided.*) - val to_decimal_string : Expr.expr -> int -> string - - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr -> string - end + val mk_sort : context -> real_sort + val get_numerator : rat_num -> int_num + val get_denominator : rat_num -> int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> bool_expr + val mk_real2int : context -> real_expr -> int_expr end - (** Indicates whether the term is of integer sort. *) - val is_int : Expr.expr -> bool + module AlgebraicNumber : + sig + val to_upper : algebraic_num -> int -> rat_num + val to_lower : algebraic_num -> int -> rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end - (** Indicates whether the term is an arithmetic numeral. *) - val is_arithmetic_numeral : Expr.expr -> bool - - (** Indicates whether the term is a less-than-or-equal *) - val is_le : Expr.expr -> bool - - (** Indicates whether the term is a greater-than-or-equal *) - val is_ge : Expr.expr -> bool - - (** Indicates whether the term is a less-than *) - val is_lt : Expr.expr -> bool - - (** Indicates whether the term is a greater-than *) - val is_gt : Expr.expr -> bool - - (** Indicates whether the term is addition (binary) *) - val is_add : Expr.expr -> bool - - (** Indicates whether the term is subtraction (binary) *) - val is_sub : Expr.expr -> bool - - (** Indicates whether the term is a unary minus *) - val is_uminus : Expr.expr -> bool - - (** Indicates whether the term is multiplication (binary) *) - val is_mul : Expr.expr -> bool - - (** Indicates whether the term is division (binary) *) - val is_div : Expr.expr -> bool - - (** Indicates whether the term is integer division (binary) *) - val is_idiv : Expr.expr -> bool - - (** Indicates whether the term is remainder (binary) *) - val is_remainder : Expr.expr -> bool - - (** Indicates whether the term is modulus (binary) *) - val is_modulus : Expr.expr -> bool - - (** Indicates whether the term is a coercion of integer to real (unary) *) - val is_inttoreal : Expr.expr -> bool - - (** Indicates whether the term is a coercion of real to integer (unary) *) - val is_real_to_int : Expr.expr -> bool - - (** Indicates whether the term is a check that tests whether a real is integral (unary) *) - val is_real_is_int : Expr.expr -> bool - - (** Indicates whether the term is of sort real. *) - val is_real : Expr.expr -> bool - - (** Indicates whether the term is an integer numeral. *) - val is_int_numeral : Expr.expr -> bool - - (** Indicates whether the term is a real numeral. *) - val is_rat_numeral : Expr.expr -> bool - - (** Indicates whether the term is an algebraic number *) - val is_algebraic_number : Expr.expr -> bool - - (** Create an expression representing [t[0] + t[1] + ...]. *) - val mk_add : context -> Expr.expr list -> Expr.expr - - (** Create an expression representing [t[0] * t[1] * ...]. *) - val mk_mul : context -> Expr.expr list -> Expr.expr - - (** Create an expression representing [t[0] - t[1] - ...]. *) - val mk_sub : context -> Expr.expr list -> Expr.expr - - (** Create an expression representing [-t]. *) - val mk_unary_minus : context -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 / t2]. *) - val mk_div : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 ^ t2]. *) - val mk_power : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 < t2] *) - val mk_lt : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 <= t2] *) - val mk_le : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 > t2] *) - val mk_gt : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing [t1 >= t2] *) - val mk_ge : context -> Expr.expr -> Expr.expr -> Expr.expr + val is_int : expr -> bool + val is_arithmetic_numeral : expr -> bool + val is_le : expr -> bool + val is_ge : expr -> bool + val is_lt : expr -> bool + val is_gt : expr -> bool + val is_add : expr -> bool + val is_sub : expr -> bool + val is_uminus : expr -> bool + val is_mul : expr -> bool + val is_div : expr -> bool + val is_idiv : expr -> bool + val is_remainder : expr -> bool + val is_modulus : expr -> bool + val is_inttoreal : expr -> bool + val is_real_to_int : expr -> bool + val is_real_is_int : expr -> bool + val is_real : expr -> bool + val is_int_numeral : expr -> bool + val is_rat_num : expr -> bool + val is_algebraic_number : expr -> bool + val mk_add : context -> arith_expr array -> arith_expr + val mk_mul : context -> arith_expr array -> arith_expr + val mk_sub : context -> arith_expr array -> arith_expr + val mk_unary_minus : context -> arith_expr -> arith_expr + val mk_div : context -> arith_expr -> arith_expr -> arith_expr + val mk_power : context -> arith_expr -> arith_expr -> arith_expr + val mk_lt : context -> arith_expr -> arith_expr -> bool_expr + val mk_le : context -> arith_expr -> arith_expr -> bool_expr + val mk_gt : context -> arith_expr -> arith_expr -> bool_expr + val mk_ge : context -> arith_expr -> arith_expr -> bool_expr end -(** Functions to manipulate bit-vector expressions *) module BitVector : sig - (** Create a new bit-vector sort. *) - val mk_sort : context -> int -> Sort.sort - - (** Indicates whether the terms is of bit-vector sort. *) - val is_bv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector numeral *) - val is_bv_numeral : Expr.expr -> bool - - (** Indicates whether the term is a one-bit bit-vector with value one *) - val is_bv_bit1 : Expr.expr -> bool - - (** Indicates whether the term is a one-bit bit-vector with value zero *) - val is_bv_bit0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unary minus *) - val is_bv_uminus : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector addition (binary) *) - val is_bv_add : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector subtraction (binary) *) - val is_bv_sub : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector multiplication (binary) *) - val is_bv_mul : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed division (binary) *) - val is_bv_sdiv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned division (binary) *) - val is_bv_udiv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed remainder (binary) *) - val is_bv_SRem : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - val is_bv_urem : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed modulus *) - val is_bv_smod : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed division by zero *) - val is_bv_sdiv0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned division by zero *) - val is_bv_udiv0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed remainder by zero *) - val is_bv_srem0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - val is_bv_urem0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed modulus by zero *) - val is_bv_smod0 : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - val is_bv_ule : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - val is_bv_sle : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - val is_bv_uge : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - val is_bv_sge : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector less-than *) - val is_bv_ult : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector less-than *) - val is_bv_slt : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector greater-than *) - val is_bv_ugt : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector greater-than *) - val is_bv_sgt : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise AND *) - val is_bv_and : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise OR *) - val is_bv_or : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NOT *) - val is_bv_not : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise XOR *) - val is_bv_xor : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NAND *) - val is_bv_nand : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NOR *) - val is_bv_nor : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise XNOR *) - val is_bv_xnor : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector concatenation (binary) *) - val is_bv_concat : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector sign extension *) - val is_bv_signextension : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector zero extension *) - val is_bv_zeroextension : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector extraction *) - val is_bv_extract : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector repetition *) - val is_bv_repeat : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector reduce OR *) - val is_bv_reduceor : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector reduce AND *) - val is_bv_reduceand : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector comparison *) - val is_bv_comp : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector shift left *) - val is_bv_shiftleft : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector logical shift right *) - val is_bv_shiftrightlogical : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector arithmetic shift left *) - val is_bv_shiftrightarithmetic : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector rotate left *) - val is_bv_rotateleft : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector rotate right *) - val is_bv_rotateright : Expr.expr -> bool - - (** 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. *) - val is_bv_rotateleftextended : Expr.expr -> bool - - (** 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. *) - val is_bv_rotaterightextended : Expr.expr -> bool - - (** 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. *) - - (** 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. *) - val is_int_to_bv : Expr.expr -> bool - - (** 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. *) - val is_bv_to_int : Expr.expr -> bool - - (** 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))) *) - val is_bv_carry : Expr.expr -> bool - - (** 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) *) - val is_bv_xor3 : Expr.expr -> bool - - (** The size of a bit-vector sort. *) - val get_size : Sort.sort -> int - - (** Retrieve the int value. *) - val get_int : Expr.expr -> int - - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr -> string - - (** Creates a bit-vector constant. *) - val mk_const : context -> Symbol.symbol -> int -> Expr.expr - - (** Creates a bit-vector constant. *) - val mk_const_s : context -> string -> int -> Expr.expr - - (** Bitwise negation. - The argument must have a bit-vector sort. *) - val mk_not : context -> Expr.expr -> Expr.expr - - (** Take conjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) - val mk_redand : context -> Expr.expr -> Expr.expr - - (** Take disjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) - val mk_redor : context -> Expr.expr -> Expr.expr - - (** Bitwise conjunction. - The arguments must have a bit-vector sort. *) - val mk_and : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Bitwise disjunction. - The arguments must have a bit-vector sort. *) - val mk_or : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Bitwise XOR. - The arguments must have a bit-vector sort. *) - val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Bitwise NAND. - The arguments must have a bit-vector sort. *) - val mk_nand : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Bitwise NOR. - The arguments must have a bit-vector sort. *) - val mk_nor : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Bitwise XNOR. - The arguments must have a bit-vector sort. *) - val mk_xnor : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Standard two's complement unary minus. - The arguments must have a bit-vector sort. *) - val mk_neg : context -> Expr.expr -> Expr.expr - - (** Two's complement addition. - The arguments must have the same bit-vector sort. *) - val mk_add : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Two's complement subtraction. - The arguments must have the same bit-vector sort. *) - val mk_sub : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Two's complement multiplication. - The arguments must have the same bit-vector sort. *) - val mk_mul : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_udiv : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_sdiv : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_urem : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_srem : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_smod : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Unsigned less-than - - The arguments must have the same bit-vector sort. *) - val mk_ult : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Two's complement signed less-than - - The arguments must have the same bit-vector sort. *) - val mk_slt : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Unsigned less-than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_ule : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Two's complement signed less-than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_sle : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Unsigned greater than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_uge : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Two's complement signed greater than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_sge : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Unsigned greater-than. - - The arguments must have the same bit-vector sort. *) - val mk_ugt : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Two's complement signed greater-than. - - The arguments must have the same bit-vector sort. *) - val mk_sgt : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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]). *) - val mk_concat : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Bit-vector extraction. - - Extract the bits between two limits from a bitvector of - size [m] to yield a new bitvector of size [n], where - [n = high - low + 1]. *) - val mk_extract : context -> int -> int -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_sign_ext : context -> int -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_zero_ext : context -> int -> Expr.expr -> Expr.expr - - (** Bit-vector repetition. *) - val mk_repeat : context -> int -> Expr.expr -> Expr.expr - - (** Shift left. - - It is equivalent to multiplication by [2^x] where \c x is the value of third 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.*) - val mk_shl : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Logical shift right - - It is equivalent to unsigned division by [2^x] where \c x is the value of the third 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. *) - val mk_lshr : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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. *) - val mk_ashr : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Rotate Left. - Rotate bits of \c t to the left \c i times. *) - val mk_rotate_left : context -> int -> Expr.expr -> Expr.expr - - (** Rotate Right. - Rotate bits of \c t to the right \c i times.*) - val mk_rotate_right : context -> int -> Expr.expr -> Expr.expr - - (** Rotate Left. - Rotate bits of the second argument to the left.*) - val mk_ext_rotate_left : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Rotate Right. - Rotate bits of the second argument to the right. *) - val mk_ext_rotate_right : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** 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 the argument. - 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.*) - val mk_bv2int : context -> Expr.expr -> bool -> Expr.expr - - (** Create a predicate that checks that the bit-wise addition does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_add_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr - - (** Create a predicate that checks that the bit-wise addition does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_add_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create a predicate that checks that the bit-wise subtraction does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_sub_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create a predicate that checks that the bit-wise subtraction does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_sub_no_underflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr - - (** Create a predicate that checks that the bit-wise signed division does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_sdiv_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create a predicate that checks that the bit-wise negation does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_neg_no_overflow : context -> Expr.expr -> Expr.expr - - (** Create a predicate that checks that the bit-wise multiplication does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_mul_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr - - (** Create a predicate that checks that the bit-wise multiplication does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_mul_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create a bit-vector numeral. *) - val mk_numeral : context -> string -> int -> Expr.expr + val mk_sort : context -> int -> bitvec_sort + val is_bv : expr -> bool + val is_bv_numeral : expr -> bool + val is_bv_bit1 : expr -> bool + val is_bv_bit0 : expr -> bool + val is_bv_uminus : expr -> bool + val is_bv_add : expr -> bool + val is_bv_sub : expr -> bool + val is_bv_mul : expr -> bool + val is_bv_sdiv : expr -> bool + val is_bv_udiv : expr -> bool + val is_bv_SRem : expr -> bool + val is_bv_urem : expr -> bool + val is_bv_smod : expr -> bool + val is_bv_sdiv0 : expr -> bool + val is_bv_udiv0 : expr -> bool + val is_bv_srem0 : expr -> bool + val is_bv_urem0 : expr -> bool + val is_bv_smod0 : expr -> bool + val is_bv_ule : expr -> bool + val is_bv_sle : expr -> bool + val is_bv_uge : expr -> bool + val is_bv_sge : expr -> bool + val is_bv_ult : expr -> bool + val is_bv_slt : expr -> bool + val is_bv_ugt : expr -> bool + val is_bv_sgt : expr -> bool + val is_bv_and : expr -> bool + val is_bv_or : expr -> bool + val is_bv_not : expr -> bool + val is_bv_xor : expr -> bool + val is_bv_nand : expr -> bool + val is_bv_nor : expr -> bool + val is_bv_xnor : expr -> bool + val is_bv_concat : expr -> bool + val is_bv_signextension : expr -> bool + val is_bv_zeroextension : expr -> bool + val is_bv_extract : expr -> bool + val is_bv_repeat : expr -> bool + val is_bv_reduceor : expr -> bool + val is_bv_reduceand : expr -> bool + val is_bv_comp : expr -> bool + val is_bv_shiftleft : expr -> bool + val is_bv_shiftrightlogical : expr -> bool + val is_bv_shiftrightarithmetic : expr -> bool + val is_bv_rotateleft : expr -> bool + val is_bv_rotateright : expr -> bool + val is_bv_rotateleftextended : expr -> bool + val is_bv_rotaterightextended : expr -> bool + val is_int_to_bv : expr -> bool + val is_bv_to_int : expr -> bool + val is_bv_carry : expr -> bool + val is_bv_xor3 : expr -> bool + val get_size : bitvec_sort -> int + val get_int : bitvec_num -> int + val to_string : bitvec_num -> string + val mk_const : context -> symbol -> int -> bitvec_expr + val mk_const_s : context -> string -> int -> bitvec_expr + val mk_not : context -> bitvec_expr -> expr + val mk_redand : context -> bitvec_expr -> expr + val mk_redor : context -> bitvec_expr -> expr + val mk_and : context -> bitvec_expr -> bitvec_expr -> expr + val mk_or : context -> bitvec_expr -> bitvec_expr -> expr + val mk_xor : context -> bitvec_expr -> bitvec_expr -> expr + val mk_nand : context -> bitvec_expr -> bitvec_expr -> expr + val mk_nor : context -> bitvec_expr -> bitvec_expr -> expr + val mk_xnor : context -> bitvec_expr -> bitvec_expr -> expr + val mk_neg : context -> bitvec_expr -> expr + val mk_add : context -> bitvec_expr -> bitvec_expr -> expr + val mk_sub : context -> bitvec_expr -> bitvec_expr -> expr + val mk_mul : context -> bitvec_expr -> bitvec_expr -> expr + val mk_udiv : context -> bitvec_expr -> bitvec_expr -> expr + val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> expr + val mk_urem : context -> bitvec_expr -> bitvec_expr -> expr + val mk_srem : context -> bitvec_expr -> bitvec_expr -> expr + val mk_smod : context -> bitvec_expr -> bitvec_expr -> expr + val mk_ult : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_slt : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_ule : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_sle : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_uge : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_sge : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_ugt : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_sgt : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_concat : context -> bitvec_expr -> bitvec_expr -> expr + val mk_extract : context -> int -> int -> bitvec_expr -> expr + val mk_sign_ext : context -> int -> bitvec_expr -> expr + val mk_zero_ext : context -> int -> bitvec_expr -> expr + val mk_repeat : context -> int -> bitvec_expr -> expr + val mk_shl : context -> bitvec_expr -> bitvec_expr -> expr + val mk_lshr : context -> bitvec_expr -> bitvec_expr -> expr + val mk_ashr : context -> bitvec_expr -> bitvec_expr -> expr + val mk_rotate_left : context -> bitvec_expr -> bitvec_expr -> expr + val mk_rotate_right : context -> bitvec_expr -> bitvec_expr -> expr + val mk_bv2int : context -> bitvec_expr -> bool -> int_expr + val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> bool_expr + val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> bool_expr + val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_neg_no_overflow : context -> bitvec_expr -> bool_expr + val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> bool_expr + val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_numeral : context -> string -> int -> bitvec_num end -(** Functions to manipulate proof expressions *) module Proof : sig - (** Indicates whether the term is a Proof for the expression 'true'. *) - val is_true : Expr.expr -> bool - - (** Indicates whether the term is a proof for a fact asserted by the user. *) - val is_asserted : Expr.expr -> bool - - (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - val is_goal : Expr.expr -> bool - - (** 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. *) - val is_oeq : Expr.expr -> bool - - (** 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). *) - val is_modus_ponens : Expr.expr -> bool - - (** 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'. *) - val is_reflexivity : Expr.expr -> bool - - (** 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. *) - val is_symmetry : Expr.expr -> bool - - (** 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) *) - val is_transitivity : Expr.expr -> bool - - (** 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. *) - val is_Transitivity_star : Expr.expr -> bool - - (** 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. *) - val is_monotonicity : Expr.expr -> bool - - (** 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)) *) - val is_quant_intro : Expr.expr -> bool - - (** 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. *) - val is_distributivity : Expr.expr -> bool - - (** 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 *) - val is_and_elimination : Expr.expr -> bool - - (** 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) *) - val is_or_elimination : Expr.expr -> bool - - (** 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 : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) *) - val is_rewrite : Expr.expr -> bool - - (** 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) *) - val is_rewrite_star : Expr.expr -> bool - - (** 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. *) - val is_pull_quant : Expr.expr -> bool - - (** 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 *) - val is_pull_quant_star : Expr.expr -> bool - - (** 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 *) - val is_push_quant : Expr.expr -> bool - - (** 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. *) - val is_elim_unused_vars : Expr.expr -> bool - - (** Indicates whether the term is a proof for destructive equality resolution - - A proof for destructive equality resolution: - (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. - - This proof object has no antecedents. - - Several variables can be eliminated simultaneously. *) - val is_der : Expr.expr -> bool - - (** Indicates whether the term is a proof for quantifier instantiation - - A proof of (or (not (forall (x) (P x))) (P a)) *) - val is_quant_inst : Expr.expr -> bool - - (** Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. *) - val is_hypothesis : Expr.expr -> bool - - (** 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. *) - val is_lemma : Expr.expr -> bool - - (** 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') *) - val is_unit_resolution : Expr.expr -> bool - - (** Indicates whether the term is a proof by iff-true - - T1: p - [iff-true T1]: (iff p true) *) - val is_iff_true : Expr.expr -> bool - - (** Indicates whether the term is a proof by iff-false - - T1: (not p) - [iff-false T1]: (iff p false) *) - val is_iff_false : Expr.expr -> bool - - (** 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. *) - val is_commutativity : Expr.expr -> bool - - (** 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). *) - val is_def_axiom : Expr.expr -> bool - - (** 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) *) - val is_def_intro : Expr.expr -> bool - - (** 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. *) - val is_apply_def : Expr.expr -> bool - - (** Indicates whether the term is a proof iff-oeq - - T1: (iff p q) - [iff~ T1]: (~ p q) *) - val is_iff_oeq : Expr.expr -> bool - - (** 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'. *) - val is_nnf_pos : Expr.expr -> bool - - (** 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'))) *) - val is_nnf_neg : Expr.expr -> bool - - (** 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. *) - val is_nnf_star : Expr.expr -> bool - - (** 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. *) - val is_cnf_star : Expr.expr -> bool - - (** Indicates whether the term is a proof for a Skolemization step - - Proof for: - - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) - - This proof object has no antecedents. *) - val is_skolemize : Expr.expr -> bool - - (** 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 *) - val is_modus_ponens_oeq : Expr.expr -> bool - - (** 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. *) - val is_theory_lemma : Expr.expr -> bool + val is_true : expr -> bool + val is_asserted : expr -> bool + val is_goal : expr -> bool + val is_modus_ponens : expr -> bool + val is_reflexivity : expr -> bool + val is_symmetry : expr -> bool + val is_transitivity : expr -> bool + val is_Transitivity_star : expr -> bool + val is_monotonicity : expr -> bool + val is_quant_intro : expr -> bool + val is_distributivity : expr -> bool + val is_and_elimination : expr -> bool + val is_or_elimination : expr -> bool + val is_rewrite : expr -> bool + val is_rewrite_star : expr -> bool + val is_pull_quant : expr -> bool + val is_pull_quant_star : expr -> bool + val is_push_quant : expr -> bool + val is_elim_unused_vars : expr -> bool + val is_der : expr -> bool + val is_quant_inst : expr -> bool + val is_hypothesis : expr -> bool + val is_lemma : expr -> bool + val is_unit_resolution : expr -> bool + val is_iff_true : expr -> bool + val is_iff_false : expr -> bool + val is_commutativity : expr -> bool + val is_def_axiom : expr -> bool + val is_def_intro : expr -> bool + val is_apply_def : expr -> bool + val is_iff_oeq : expr -> bool + val is_nnf_pos : expr -> bool + val is_nnf_neg : expr -> bool + val is_nnf_star : expr -> bool + val is_cnf_star : expr -> bool + val is_skolemize : expr -> bool + val is_modus_ponens_oeq : expr -> bool + val is_theory_lemma : expr -> bool end -(** Goals - - A goal (aka problem). A goal is essentially a - of formulas, that can be solved and/or transformed using - tactics and solvers. *) module Goal : sig - type goal - - (** 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. *) val get_precision : goal -> Z3enums.goal_prec - - (** Indicates whether the goal is precise. *) val is_precise : goal -> bool - - (** Indicates whether the goal is an under-approximation. *) val is_underapproximation : goal -> bool - - (** Indicates whether the goal is an over-approximation. *) val is_overapproximation : goal -> bool - - (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) val is_garbage : goal -> bool - - (** Adds the constraints to the given goal. *) - val add : goal -> Expr.expr list -> unit - - (** Indicates whether the goal contains `false'. *) + val assert_ : goal -> bool_expr array -> unit val is_inconsistent : goal -> bool - - (** The depth of the goal. - This tracks how many transformations were applied to it. *) val get_depth : goal -> int - - (** Erases all formulas from the given goal. *) val reset : goal -> unit - - (** The number of formulas in the goal. *) val get_size : goal -> int - - (** The formulas in the goal. *) - val get_formulas : goal -> Expr.expr list - - (** The number of formulas, subformulas and terms in the goal. *) + val get_formulas : goal -> bool_expr array val get_num_exprs : goal -> int - - (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) val is_decided_sat : goal -> bool - - (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) val is_decided_unsat : goal -> bool - - (** Translates (copies) the Goal to another context.. *) val translate : goal -> context -> goal - - (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - val simplify : goal -> Params.params option -> goal - - (** Creates a new Goal. - - Note that the Context must have been created with proof generation support if - the fourth argument is set to true here. *) + val simplify : goal -> params option -> goal val mk_goal : context -> bool -> bool -> bool -> goal - - (** A string representation of the Goal. *) val to_string : goal -> string end -(** Models - - A Model contains interpretations (assignments) of constants and functions. *) module Model : sig - type model - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. *) module FuncInterp : sig - type func_interp - - (** Function interpretations entries - An Entry object represents an element in the finite map used to a function interpretation. *) module FuncEntry : sig - type func_entry - - (** Return the (symbolic) value of this entry. - *) - val get_value : func_entry -> Expr.expr - - (** The number of arguments of the entry. - *) + val get_value : func_entry -> expr val get_num_args : func_entry -> int - - (** The arguments of the function entry. - *) - val get_args : func_entry -> Expr.expr list - - (** A string representation of the function entry. - *) + val get_args : func_entry -> expr array val to_string : func_entry -> string end - (** The number of entries in the function interpretation. *) val get_num_entries : func_interp -> int - - (** The entries in the function interpretation *) - val get_entries : func_interp -> FuncEntry.func_entry list - - (** The (symbolic) `else' value of the function interpretation. *) - val get_else : func_interp -> Expr.expr - - (** The arity of the function interpretation *) + val get_entries : func_interp -> func_entry array + val get_else : func_interp -> expr val get_arity : func_interp -> int - - (** A string representation of the function interpretation. *) val to_string : func_interp -> string end - (** Retrieves the interpretation (the assignment) of a func_decl in the model. - @return An expression if the function has an interpretation in the model, null otherwise. *) - val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option - - (** Retrieves the interpretation (the assignment) of an expression in the model. - @return An expression if the constant has an interpretation in the model, null otherwise. *) - val get_const_interp_e : model -> Expr.expr -> Expr.expr option - - (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. - @return A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option - - (** The number of constant interpretations in the model. *) + val get_const_interp : model -> func_decl -> expr option + val get_const_interp_e : model -> expr -> expr option + val get_func_interp : model -> func_decl -> func_interp option val get_num_consts : model -> int - - (** The function declarations of the constants in the model. *) - val get_const_decls : model -> FuncDecl.func_decl list - - (** The number of function interpretations in the model. *) + val get_const_decls : model -> func_decl array val get_num_funcs : model -> int - - (** The function declarations of the function interpretations in the model. *) - val get_func_decls : model -> FuncDecl.func_decl list - - (** All symbols that have an interpretation in the model. *) - val get_decls : model -> FuncDecl.func_decl list - - (** Evaluates an expression in the current model. - - This function may fail if the argument contains quantifiers, - is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. - In this case a [ModelEvaluationFailedException] is thrown. - *) - val eval : model -> Expr.expr -> bool -> Expr.expr option - - (** Alias for [eval]. *) - val evaluate : model -> Expr.expr -> bool -> Expr.expr option - - (** The number of uninterpreted sorts that the model has an interpretation for. *) + val get_func_decls : model -> func_decl array + val get_decls : model -> func_decl array + exception ModelEvaluationFailedException of string + val eval : model -> expr -> bool -> expr + val evaluate : model -> expr -> bool -> expr val get_num_sorts : model -> int - - (** 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. - {!get_num_sorts} - {!sort_universe} *) - val get_sorts : model -> Sort.sort list - - (** The finite set of distinct values that represent the interpretation of a sort. - {!get_sorts} - @return A list of expressions, where each is an element of the universe of the sort *) - val sort_universe : model -> Sort.sort -> AST.ast list - - (** Conversion of models to strings. - @return A string representation of the model. *) + val get_sorts : model -> sort array + val sort_universe : model -> sort -> ast_vector array val to_string : model -> string end -(** Probes - - 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. -*) module Probe : sig - type probe - - (** Execute the probe over the goal. - @return A probe always produce a float value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - val apply : probe -> Goal.goal -> float - - (** The number of supported Probes. *) + val apply : probe -> goal -> float val get_num_probes : context -> int - - (** The names of all supported Probes. *) - val get_probe_names : context -> string list - - (** Returns a string containing a description of the probe with the given name. *) + val get_probe_names : context -> string array val get_probe_description : context -> string -> string - - (** Creates a new Probe. *) val mk_probe : context -> string -> probe - - (** Create a probe that always evaluates to a float value. *) val const : context -> float -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is less than the value returned by second argument *) val lt : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is greater than the value returned by second argument *) val gt : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is less than or equal the value returned by second argument *) val le : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is greater than or equal the value returned by second argument *) val ge : context -> probe -> probe -> probe - - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is equal the value returned by second argument *) val eq : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when both of two probes evaluate to "true". *) val and_ : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when either of two probes evaluates to "true". *) val or_ : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when another probe does not evaluate to "true". *) val not_ : context -> probe -> probe end -(** Tactics - - Tactics are the basic building block for creating custom solvers for specific problem domains. - The complete list of tactics may be obtained using [Context.get_num_tactics] - and [Context.get_tactic_names]. - It may also be obtained using the command [(help-tactics)] in the SMT 2.0 front-end. -*) module Tactic : sig - type tactic - (** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) module ApplyResult : sig - type apply_result - - (** The number of Subgoals. *) val get_num_subgoals : apply_result -> int - - (** Retrieves the subgoals from the apply_result. *) - val get_subgoals : apply_result -> Goal.goal list - - (** Retrieves a subgoal from the apply_result. *) - val get_subgoal : apply_result -> int -> Goal.goal - - (** Convert a model for a subgoal into a model for the original - goal [g], that the ApplyResult was obtained from. - #return A model for [g] *) - val convert_model : apply_result -> int -> Model.model -> Model.model - - (** A string representation of the ApplyResult. *) + val get_subgoals : apply_result -> goal array + val get_subgoal : apply_result -> int -> goal + val convert_model : apply_result -> int -> model -> model val to_string : apply_result -> string end - (** A string containing a description of parameters accepted by the tactic. *) val get_help : tactic -> string - - (** Retrieves parameter descriptions for Tactics. *) - val get_param_descrs : tactic -> Params.ParamDescrs.param_descrs - - (** Apply the tactic to the goal. *) - val apply : tactic -> Goal.goal -> Params.params option -> ApplyResult.apply_result - - (** The number of supported tactics. *) + val get_param_descrs : tactic -> param_descrs + val apply : tactic -> goal -> params option -> apply_result val get_num_tactics : context -> int - - (** The names of all supported tactics. *) - val get_tactic_names : context -> string list - - (** Returns a string containing a description of the tactic with the given name. *) + val get_tactic_names : context -> string array val get_tactic_description : context -> string -> string - - (** Creates a new Tactic. *) val mk_tactic : context -> string -> tactic - - (** Create a tactic that applies one tactic to a Goal and - then another one to every subgoal produced by the first one. *) - val and_then : context -> tactic -> tactic -> tactic list -> tactic - - (** Create a tactic that first applies one tactic to a Goal and - if it fails then returns the result of another tactic applied to the Goal. *) + val and_then : context -> tactic -> tactic -> tactic array -> tactic val or_else : context -> tactic -> tactic -> tactic - - (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). - - If the tactic does not terminate within the timeout, then it fails. *) val try_for : context -> tactic -> int -> tactic - - (** Create a tactic that applies one tactic to a given goal if the probe - evaluates to true. - - If the probe evaluates to false, then the new tactic behaves like the [skip] tactic. *) - val when_ : context -> Probe.probe -> tactic -> tactic - - (** Create a tactic that applies a tactic to a given goal if the probe - evaluates to true and another tactic otherwise. *) - val cond : context -> Probe.probe -> tactic -> tactic -> tactic - - (** Create a tactic that keeps applying one tactic until the goal is not - modified anymore or the maximum number of iterations is reached. *) + val when_ : context -> probe -> tactic -> tactic + val cond : context -> probe -> tactic -> tactic -> tactic val repeat : context -> tactic -> int -> tactic - - (** Create a tactic that just returns the given goal. *) val skip : context -> tactic - - (** Create a tactic always fails. *) val fail : context -> tactic - - (** Create a tactic that fails if the probe evaluates to false. *) - val fail_if : context -> Probe.probe -> tactic - - (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). *) + val fail_if : context -> probe -> tactic val fail_if_not_decided : context -> tactic - - (** Create a tactic that applies a tactic using the given set of parameters. *) - val using_params : context -> tactic -> Params.params -> tactic - - (** Create a tactic that applies a tactic using the given set of parameters. - Alias for [UsingParams]*) - val with_ : context -> tactic -> Params.params -> tactic - - (** Create a tactic that applies the given tactics in parallel. *) - val par_or : context -> tactic list -> tactic - - (** Create a tactic that applies a tactic to a given goal and then another tactic - to every subgoal produced by the first one. The subgoals are processed in parallel. *) + val using_params : context -> tactic -> params -> tactic + val with_ : context -> tactic -> params -> tactic + val par_or : context -> tactic array -> tactic val par_and_then : context -> tactic -> tactic -> tactic - - (** Interrupt the execution of a Z3 procedure. - This procedure can be used to interrupt: solvers, simplifiers and tactics. *) val interrupt : context -> unit end -(** Solvers *) module Solver : sig - type solver - type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE - val string_of_status : status -> string - (** Objects that track statistical information about solvers. *) module Statistics : sig - type statistics - (** Statistical data is organized into pairs of \[Key, Entry\], where every - Entry is either a floating point or integer value. - *) module Entry : sig - type statistics_entry - - (** The key of the entry. *) val get_key : statistics_entry -> string - - (** The int-value of the entry. *) val get_int : statistics_entry -> int - - (** The float-value of the entry. *) val get_float : statistics_entry -> float - - (** True if the entry is uint-valued. *) val is_int : statistics_entry -> bool - - (** True if the entry is float-valued. *) val is_float : statistics_entry -> bool - - (** The string representation of the the entry's value. *) val to_string_value : statistics_entry -> string - - (** The string representation of the entry (key and value) *) val to_string : statistics_entry -> string end - (** A string representation of the statistical data. *) val to_string : statistics -> string - - (** The number of statistical data. *) val get_size : statistics -> int - - (** The data entries. *) - val get_entries : statistics -> Entry.statistics_entry list - - (** The statistical counters. *) - val get_keys : statistics -> string list - - (** The value of a particular statistical counter. *) - val get : statistics -> string -> Entry.statistics_entry option + val get_entries : statistics -> statistics_entry array + val get_keys : statistics -> string array + val get : statistics -> string -> statistics_entry option end - (** A string that describes all available solver parameters. *) val get_help : solver -> string - - (** Sets the solver parameters. *) - val set_parameters : solver -> Params.params -> unit - - (** Retrieves parameter descriptions for solver. *) - val get_param_descrs : solver -> Params.ParamDescrs.param_descrs - - (** The current number of backtracking points (scopes). - {!pop} - {!push} *) + val set_parameters : solver -> params -> unit + val get_param_descrs : solver -> param_descrs val get_num_scopes : solver -> int - - (** Creates a backtracking point. - {!pop} *) val push : solver -> unit - - (** Backtracks a number of backtracking points. - Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} - {!push} *) val pop : solver -> int -> unit - - (** Resets the Solver. - This removes all assertions from the solver. *) val reset : solver -> unit - - (** Assert a constraint (or multiple) into the solver. *) - val add : solver -> Expr.expr list -> unit - - (** * Assert multiple constraints (cs) into the solver, and track them (in the - * unsat) core - * using the Boolean constants in ps. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) - val assert_and_track_l : solver -> Expr.expr list -> Expr.expr list -> unit - - (** * Assert a constraint (c) into the solver, and track it (in the unsat) core - * using the Boolean constant p. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) - val assert_and_track : solver -> Expr.expr -> Expr.expr -> unit - - (** The number of assertions in the solver. *) + val assert_ : solver -> bool_expr array -> unit + val assert_and_track : solver -> bool_expr -> bool_expr -> unit val get_num_assertions : solver -> int - - (** The set of asserted formulas. *) - val get_assertions : solver -> Expr.expr list - - (** Checks whether the assertions in the solver are consistent or not. - - {!Model} - {!get_unsat_core} - {!Proof} *) - val check : solver -> Expr.expr list -> status - - (** The model of the last [Check]. - - The result is [None] if [Check] was not invoked before, - if its results was not [SATISFIABLE], or if model production is not enabled. *) - val get_model : solver -> Model.model option - - (** 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. *) - val get_proof : solver -> Expr.expr option - - (** 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. *) - val get_unsat_core : solver -> AST.ast list - - (** A brief justification of why the last call to [Check] returned [UNKNOWN]. *) + val get_assertions : solver -> bool_expr array + val check : solver -> bool_expr array -> status + val get_model : solver -> model option + val get_proof : solver -> expr option + val get_unsat_core : solver -> ast_vector array val get_reason_unknown : solver -> string - - (** Solver statistics. *) - val get_statistics : solver -> Statistics.statistics - - (** 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. *) - val mk_solver : context -> Symbol.symbol option -> solver - - (** Creates a new (incremental) solver. - {!mk_solver} *) + val get_statistics : solver -> statistics + val mk_solver : context -> symbol option -> solver val mk_solver_s : context -> string -> solver - - (** Creates a new (incremental) solver. *) val mk_simple_solver : context -> solver - - (** 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. *) - val mk_solver_t : context -> Tactic.tactic -> solver - - (** A string representation of the solver. *) + val mk_solver_t : context -> tactic -> solver val to_string : solver -> string end -(** Fixedpoint solving *) module Fixedpoint : sig - type fixedpoint - - (** A string that describes all available fixedpoint solver parameters. *) val get_help : fixedpoint -> string - - (** Sets the fixedpoint solver parameters. *) - val set_params : fixedpoint -> Params.params -> unit - - (** Retrieves parameter descriptions for Fixedpoint solver. *) - val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs - - (** Assert a constraints into the fixedpoint solver. *) - val add : fixedpoint -> Expr.expr list -> unit - - (** Register predicate as recursive relation. *) - val register_relation : fixedpoint -> FuncDecl.func_decl -> unit - - (** Add rule into the fixedpoint solver. *) - val add_rule : fixedpoint -> Expr.expr -> Symbol.symbol option -> unit - - (** Add table fact to the fixedpoint solver. *) - val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit - - (** 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. *) - val query : fixedpoint -> Expr.expr -> Solver.status - - (** 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. *) - val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status - - (** Creates a backtracking point. - {!pop} *) + val set_params : fixedpoint -> params -> unit + val get_param_descrs : fixedpoint -> param_descrs + val assert_ : fixedpoint -> bool_expr array -> unit + val register_relation : fixedpoint -> func_decl -> unit + val add_rule : fixedpoint -> bool_expr -> symbol option -> unit + val add_fact : fixedpoint -> func_decl -> int array -> unit + val query : fixedpoint -> bool_expr -> status + val query_r : fixedpoint -> func_decl array -> status val push : fixedpoint -> unit - - (** Backtrack one backtracking point. - - Note that an exception is thrown if Pop is called without a corresponding [Push] - {!push} *) val pop : fixedpoint -> unit - - (** Update named rule into in the fixedpoint solver. *) - val update_rule : fixedpoint -> Expr.expr -> Symbol.symbol -> unit - - (** Retrieve satisfying instance or instances of solver, - or definitions for the recursive predicates that show unsatisfiability. *) - val get_answer : fixedpoint -> Expr.expr option - - (** Retrieve explanation why fixedpoint engine returned status Unknown. *) + val update_rule : fixedpoint -> bool_expr -> symbol -> unit + val get_answer : fixedpoint -> expr option val get_reason_unknown : fixedpoint -> string - - (** Retrieve the number of levels explored for a given predicate. *) - val get_num_levels : fixedpoint -> FuncDecl.func_decl -> int - - (** Retrieve the cover of a predicate. *) - val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option - - (** Add property about the predicate. - The property is added at level. *) - val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit - - (** Retrieve internal string representation of fixedpoint object. *) + val get_num_levels : fixedpoint -> func_decl -> int + val get_cover_delta : fixedpoint -> int -> func_decl -> expr option + val add_cover : fixedpoint -> int -> func_decl -> expr -> unit val to_string : fixedpoint -> string - - (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol list -> unit - - (** Convert benchmark given as set of axioms, rules and queries to a string. *) - val to_string_q : fixedpoint -> Expr.expr list -> string - - (** Retrieve set of rules added to fixedpoint context. *) - val get_rules : fixedpoint -> Expr.expr list - - (** Retrieve set of assertions added to fixedpoint context. *) - val get_assertions : fixedpoint -> Expr.expr list - - (** Create a Fixedpoint context. *) + val set_predicate_representation : fixedpoint -> func_decl -> symbol array -> unit + val to_string_q : fixedpoint -> bool_expr array -> string + val get_rules : fixedpoint -> bool_expr array + val get_assertions : fixedpoint -> bool_expr array val mk_fixedpoint : context -> fixedpoint end -(** Functions for handling SMT and SMT2 expressions and files *) +module Options : +sig + val update_param_value : context -> string -> string -> unit + val get_param_value : context -> string -> string option + val set_print_mode : context -> Z3enums.ast_print_mode -> unit + val toggle_warning_messages : bool -> unit +end + module SMT : sig - (** Convert a benchmark into an SMT-LIB formatted string. - - @return A string representation of the benchmark. *) - val benchmark_to_smtstring : context -> string -> string -> string -> string -> Expr.expr list -> Expr.expr -> string - - (** 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 in the third and fifth argument - don't need to match the names of the sorts and declarations in the arrays in the fourth - and sixth argument. This is a useful feature since we can use arbitrary names to - reference sorts and declarations. *) - val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit - - (** Parse the given file using the SMT-LIB parser. - {!parse_smtlib_string} *) - val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit - - (** The number of SMTLIB formulas parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) + val benchmark_to_smtstring : context -> string -> string -> string -> string -> bool_expr array -> bool_expr -> string + val parse_smtlib_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit + val parse_smtlib_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit val get_num_smtlib_formulas : context -> int - - (** The formulas parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) - val get_smtlib_formulas : context -> Expr.expr list - - (** The number of SMTLIB assumptions parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) + val get_smtlib_formulas : context -> bool_expr array val get_num_smtlib_assumptions : context -> int - - (** The assumptions parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) - val get_smtlib_assumptions : context -> Expr.expr list - - (** The number of SMTLIB declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) + val get_smtlib_assumptions : context -> bool_expr array val get_num_smtlib_decls : context -> int - - (** The declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) - val get_smtlib_decls : context -> FuncDecl.func_decl list - - (** The number of SMTLIB sorts parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) + val get_smtlib_decls : context -> func_decl array val get_num_smtlib_sorts : context -> int - - (** The sort declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) - val get_smtlib_sorts : context -> Sort.sort list - - (** Parse the given string using the SMT-LIB2 parser. - - {!parse_smtlib_string} - @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr - - (** Parse the given file using the SMT-LIB2 parser. - {!parse_smtlib2_string} *) - val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr + val get_smtlib_sorts : context -> sort array + val parse_smtlib2_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> bool_expr + val parse_smtlib2_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> bool_expr end -(** Interpolation *) -module Interpolation : -sig - - (** Create an AST node marking a formula position for interpolation. - The expression must have Boolean sort. *) - val mk_interpolant : context -> Expr.expr -> Expr.expr - - (** The interpolation context is suitable for generation of interpolants. - For more information on interpolation please refer - too the C/C++ API, which is well documented. *) - val mk_interpolation_context : (string * string) list -> context - - (** Gets an interpolant. - For more information on interpolation please refer - too the C/C++ API, which is well documented. *) - val get_interpolant : context -> Expr.expr -> Expr.expr -> Params.params -> AST.ASTVector.ast_vector - - (** Computes an interpolant. - For more information on interpolation please refer - too the C/C++ API, which is well documented. *) - val compute_interpolant : context -> Expr.expr -> Params.params -> (AST.ASTVector.ast_vector * Model.model) - - (** Retrieves an interpolation profile. - For more information on interpolation please refer - too the C/C++ API, which is well documented. *) - val get_interpolation_profile : context -> string - - (** Read an interpolation problem from file. - For more information on interpolation please refer - too the C/C++ API, which is well documented. *) - val read_interpolation_problem : context -> string -> (Expr.expr list * int list * Expr.expr list) - - (** Check the correctness of an interpolant. - For more information on interpolation please refer - too the C/C++ API, which is well documented. *) - val check_interpolant : context -> int -> Expr.expr list -> int list -> Expr.expr list -> int -> Expr.expr list -> unit - - (** Write an interpolation problem to file suitable for reading with - Z3_read_interpolation_problem. - For more information on interpolation please refer - too the C/C++ API, which is well documented. *) - val write_interpolation_problem : context -> int -> Expr.expr list -> int list -> string -> int -> Expr.expr list -> unit - -end - -(** Set a global (or module) parameter, which is shared by all Z3 contexts. - - When a Z3 module is initialized it will use the value of these parameters - when Z3_params objects are not provided. - The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. - The character '.' is a delimiter (more later). - The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. - Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". - This function can be used to set parameters for a specific Z3 module. - This can be done by using .. - For example: - (set_global_param "pp.decimal" "true") - will set the parameter "decimal" in the module "pp" to true. -*) val set_global_param : string -> string -> unit - -(** Get a global (or module) parameter. - - Returns None if the parameter does not exist. - The caller must invoke #Z3_global_param_del_value to delete the value returned at param_value. - This function cannot be invoked simultaneously from different threads without synchronization. - The result string stored in param_value is stored in a shared location. -*) val get_global_param : string -> string option - -(** Restore the value of all global (and module) parameters. - - This command will not affect already created objects (such as tactics and solvers) - {!set_global_param} -*) - -val global_param_reset_all : unit -> unit - -(** Enable/disable printing of warning messages to the console. - - Note that this function is static and effects the behaviour of - all contexts globally. *) -val toggle_warning_messages : bool -> unit - +val global_param_reset_all : unit From fd78e45a2a6f0b040a96705494038186f4b361bd Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 20:04:11 +0000 Subject: [PATCH 175/248] ML API: got rid of "extra" objects on types. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 73 +++++++++++++++-------------------------------- src/api/ml/z3.mli | 2 +- 2 files changed, 24 insertions(+), 51 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index ea8c9576e..aa919e7fc 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -93,13 +93,7 @@ type quantifier = Quantifier of expr type pattern = Pattern of ast (* Datatype stuff *) -type constructor_extra = { - m_n : int; - mutable m_tester_decl : func_decl option; - mutable m_constructor_decl : func_decl option ; - mutable m_accessor_decls : func_decl array option} - -type constructor = Constructor of (z3_native_object * constructor_extra) +type constructor = z3_native_object type constructor_list = z3_native_object (* Tactical interface *) @@ -2358,7 +2352,8 @@ struct (** Constructors *) module Constructor = struct - + let _counts = Hashtbl.create 0 + let create ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then @@ -2373,53 +2368,31 @@ struct (let f x = (Symbol.gno x) in (Array.map f field_names)) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) sort_refs) in - let no : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref} in - let ex : constructor_extra = { m_n = n; - m_tester_decl = None; - m_constructor_decl = None; - m_accessor_decls = None} in + let no : constructor = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + Hashtbl.add _counts no n ; (z3obj_sno no ctx ptr) ; (z3obj_create no) ; let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; - Constructor(no, ex) + no - let init_extra ( x : constructor ) = - match x with Constructor(no, ex) -> - match ex.m_tester_decl with - | None -> - let (a, b, c) = (Z3native.query_constructor (z3obj_gnc no) (z3obj_gno no) ex.m_n) in - ex.m_constructor_decl <- Some (func_decl_of_ptr (z3obj_gc no) a) ; - ex.m_tester_decl <- Some (func_decl_of_ptr (z3obj_gc no) b) ; - ex.m_accessor_decls <- Some (let f e = (func_decl_of_ptr (z3obj_gc no) e) in Array.map f c) ; - () - | _ -> () - - - let get_n ( x : constructor ) = - match x with Constructor(no, ex) -> - ex.m_n + let get_n ( x : constructor ) = (Hashtbl.find _counts x) - let rec tester_decl ( x : constructor ) = - match x with Constructor(no, ex) -> - match ex.m_tester_decl with - | Some(s) -> s - | None -> init_extra x ; tester_decl x - let rec constructor_decl ( x : constructor ) = - match x with Constructor(no, ex) -> - match ex.m_constructor_decl with - | Some(s) -> s - | None -> init_extra x ; constructor_decl x + let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + func_decl_of_ptr (z3obj_gc x) a + + let rec tester_decl ( x : constructor ) = + let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + func_decl_of_ptr (z3obj_gc x) b let rec accessor_decls ( x : constructor ) = - match x with Constructor(no, ex) -> - match ex.m_accessor_decls with - | Some(s) -> s - | None -> init_extra x ; accessor_decls x + let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + let f y = func_decl_of_ptr (z3obj_gc x) y in + Array.map f c (** The number of fields of the constructor. *) let get_num_fields ( x : constructor ) = get_n x @@ -2443,7 +2416,7 @@ struct m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref} in - let f x = match x with Constructor(no,_) -> (z3obj_gno no) in + let f x =(z3obj_gno x) in (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Array.map f c))) ; (z3obj_create res) ; let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in @@ -2462,7 +2435,7 @@ struct 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. *) - let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array) = + let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = Constructor.create ctx name recognizer field_names sorts sort_refs @@ -2483,8 +2456,8 @@ struct (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array) = - let f x = match x with Constructor(no,_) -> (z3obj_gno no) in + let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array ) = + let f x = (z3obj_gno x) in let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in create_sort ctx x diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index f82492e8a..5d5d7adf0 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -482,8 +482,8 @@ sig module Constructor : sig val get_n : constructor -> int - val tester_decl : constructor -> func_decl val constructor_decl : constructor -> func_decl + val tester_decl : constructor -> func_decl val accessor_decls : constructor -> func_decl array val get_num_fields : constructor -> int val get_constructor_decl : constructor -> func_decl From 25615aedd9173d7f17b113e50aab9b9ab89fc2c2 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 22:49:19 +0000 Subject: [PATCH 176/248] ML API: build system fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index cfea8d0f1..5a5dbc3a4 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1342,40 +1342,49 @@ class MLComponent(Component): def mk_makefile(self, out): if is_ml_enabled(): + CP_CMD = "cp" + if IS_WINDOWS: + CP_CMD = "copy" src_dir = self.to_src_dir sub_dir = os.path.join('api', 'ml') mk_dir(os.path.join(BUILD_DIR, sub_dir)) api_src = get_component(API_COMPONENT).to_src_dir for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): - shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) + out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) + out.write('\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f)) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): - shutil.copyfile(os.path.join(self.src_dir, f), os.path.join(BUILD_DIR, sub_dir, f)) - cmis = '%s/z3enums.cmi %s/z3native.cmi %s/z3.cmi' % (src_dir,src_dir,src_dir) - out.write('%s/z3enums.cmi: %s/z3enums.mli\n' % (src_dir,src_dir)) - out.write('\t%s -I %s -c %s/z3enums.mli\n' % (OCAMLC,src_dir,src_dir)) - out.write('%s/z3native.cmi: %s/z3native.mli\n' % (src_dir,src_dir)) - out.write('\t%s -I %s -c %s/z3native.mli\n' % (OCAMLC,src_dir,src_dir)) - out.write('%s/z3.cmi: %s/z3.mli\n' % (src_dir,src_dir)) - out.write('\t%s -I %s -c %s/z3.mli\n' % (OCAMLC,src_dir,src_dir)) - out.write('api/ml/libz3ml$(LIB_EXT): %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, src_dir)) + out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) + out.write('\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f)) + modules = ["z3enums", "z3native", "z3"] # dependencies in this order! + prev = '' + for m in modules: + out.write('%s/%s.mli: %s/%s.ml %s\n' % (sub_dir,m,sub_dir,m,prev)) + out.write('\t%s -I %s -i -c %s/%s.ml > %s/%s.mli\n' % (OCAMLC,sub_dir,sub_dir,m,sub_dir,m)) + prev = prev + ' ' + sub_dir + '/' + m + '.mli' + cmis = '' + for m in modules: + out.write('%s/%s.cmi: %s/%s.mli\n' % (sub_dir,m,sub_dir,m)) + out.write('\t%s -I %s -c %s/%s.mli\n' % (OCAMLC,sub_dir,sub_dir,m)) + cmis = cmis + ' ' + sub_dir + '/' + m + '.cmi' + out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(src_dir, mlfile)) + out.write(' %s' % os.path.join(sub_dir, mlfile)) out.write('\n') out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) + out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(self.to_src_dir, mlfile)) + out.write(' %s' % os.path.join(sub_dir, mlfile)) out.write('\n') out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-ccopt "-I../../%s" -cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (api_src,src_dir,src_dir,src_dir,src_dir)) + out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') out.write('\n') From 9142901efe0322e9d30c20c3da819924727ece18 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Feb 2013 23:42:50 +0000 Subject: [PATCH 177/248] ML API: bugfixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 54 +++++++++++++++++++++-------------- src/api/ml/z3.ml | 60 ++++++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 47 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 3b13a2462..49db6fb50 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -7,6 +7,7 @@ open Z3 open Z3.Symbol open Z3.Sort open Z3.Expr +open Z3.Boolean open Z3.FuncDecl open Z3.Goal open Z3.Tactic @@ -22,12 +23,20 @@ exception TestFailedException of string *) let model_converter_test ( ctx : context ) = Printf.printf "ModelConverterTest\n"; - let xr = ((mk_const ctx (Symbol.mk_string ctx "x") (mk_real_sort ctx )) :> arith_expr) in - let yr = ((mk_const ctx (Symbol.mk_string ctx "y") (mk_real_sort ctx )) :> arith_expr) in + let xr = (arith_expr_of_expr + (Expr.mk_const ctx (Symbol.mk_string ctx "x") + (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in + let yr = (arith_expr_of_expr + (Expr.mk_const ctx (Symbol.mk_string ctx "y") + (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in let g4 = (mk_goal ctx true false false ) in - (Goal.assert_ g4 [| (mk_gt ctx xr (mk_real_numeral_nd ctx 10 1)) |]) ; - (Goal.assert_ g4 [| (mk_eq ctx yr (mk_add ctx [| xr; (mk_real_numeral_nd ctx 1 1) |] )) |] ) ; - (Goal.assert_ g4 [| (mk_gt ctx yr (mk_real_numeral_nd ctx 1 1)) |]) ; + (Goal.assert_ g4 [| (mk_gt ctx xr + (arith_expr_of_real_expr (real_expr_of_rat_num + (Real.mk_numeral_nd ctx 10 1)))) |]) ; + (Goal.assert_ g4 [| (mk_eq ctx + (expr_of_arith_expr yr) + (expr_of_arith_expr (mk_add ctx [| xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) |] ))) |] ) ; + (Goal.assert_ g4 [| (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) |]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in if ((get_num_subgoals ar) == 1 && @@ -67,15 +76,15 @@ let model_converter_test ( ctx : context ) = *) let basic_tests ( ctx : context ) = Printf.printf "BasicTests\n" ; - let qi = (mk_int ctx 1) in +(* let qi = (mk_int ctx 1) in *) let fname = (mk_string ctx "f") in let x = (mk_string ctx "x") in let y = (mk_string ctx "y") in - let bs = (Sort.mk_bool ctx) in + let bs = (sort_of_bool_sort (Boolean.mk_sort ctx)) in let domain = [| bs; bs |] in let f = (FuncDecl.mk_func_decl ctx fname domain bs) in let fapp = (mk_app ctx f - [| (mk_const ctx x bs); (mk_const ctx y bs) |]) in + [| (Expr.mk_const ctx x bs); (Expr.mk_const ctx y bs) |]) in let fargs2 = [| (mk_fresh_const ctx "cp" bs) |] in let domain2 = [| bs |] in let fapp2 = (mk_app ctx (mk_fresh_func_decl ctx "fp" domain2 bs) fargs2) in @@ -110,8 +119,11 @@ let basic_tests ( ctx : context ) = else Printf.printf "Test passed.\n" ); - (Goal.assert_ g [| (mk_eq ctx (mk_numeral_int ctx 1 (BitVectors.mk_sort ctx 32)) - (mk_numeral_int ctx 2 (BitVectors.mk_sort ctx 32))) |] ) + (Goal.assert_ g [| (mk_eq ctx + (mk_numeral_int ctx 1 + (sort_of_bitvec_sort (BitVector.mk_sort ctx 32))) + (mk_numeral_int ctx 2 + (sort_of_bitvec_sort (BitVector.mk_sort ctx 32)))) |] ) ; ( let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in @@ -132,7 +144,7 @@ let basic_tests ( ctx : context ) = ); ( let g2 = (mk_goal ctx true true false) in - (Goal.assert_ g2 [| (mk_false ctx) |]) ; + (Goal.assert_ g2 [| (Boolean.mk_false ctx) |]) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then @@ -142,10 +154,10 @@ let basic_tests ( ctx : context ) = ); ( let g3 = (mk_goal ctx true true false) in - let xc = (mk_const ctx (Symbol.mk_string ctx "x") (mk_int_sort ctx)) in - let yc = (mk_const ctx (Symbol.mk_string ctx "y") (mk_int_sort ctx)) in - (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (mk_int_sort ctx))) |]) ; - (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (mk_int_sort ctx))) |]) ; + let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in + let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in + (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) |]) ; + (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) |]) ; let constr = (mk_eq ctx xc yc) in (Goal.assert_ g3 [| constr |] ) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in @@ -208,14 +220,14 @@ let _ = let ctx = (mk_context cfg) in let is = (Symbol.mk_int ctx 42) in let ss = (Symbol.mk_string ctx "mySymbol") in - let bs = (Sort.mk_bool ctx) in - let ints = (mk_int_sort ctx) in - let rs = (mk_real_sort ctx) in + let bs = (Boolean.mk_sort ctx) in + let ints = (Integer.mk_sort ctx) in + let rs = (Real.mk_sort ctx) in Printf.printf "int symbol: %s\n" (Symbol.to_string is); Printf.printf "string symbol: %s\n" (Symbol.to_string ss); - Printf.printf "bool sort: %s\n" (Sort.to_string bs); - Printf.printf "int sort: %s\n" (Sort.to_string ints); - Printf.printf "real sort: %s\n" (Sort.to_string rs); + Printf.printf "bool sort: %s\n" (Sort.to_string (sort_of_bool_sort bs)); + Printf.printf "int sort: %s\n" (Sort.to_string (sort_of_arith_sort (arith_sort_of_int_sort ints))); + Printf.printf "real sort: %s\n" (Sort.to_string (sort_of_arith_sort (arith_sort_of_real_sort rs))); basic_tests ctx ; Printf.printf "Disposing...\n"; Gc.full_major () diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index aa919e7fc..651102bc8 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -240,7 +240,7 @@ struct Expr(z3_native_object_of_ast_ptr ctx no) else let s = Z3native.get_sort (context_gno ctx) no in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in if (Z3native.is_algebraic_number (context_gno ctx) no) then Expr(z3_native_object_of_ast_ptr ctx no) else @@ -376,92 +376,99 @@ let expr_of_ast a = Expr(a) let bool_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.BOOL_SORT) then raise (Z3native.Exception "Invalid coercion") else BoolExpr(e) let arith_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then raise (Z3native.Exception "Invalid coercion") else ArithExpr(e) let bitvec_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.BV_SORT) then raise (Z3native.Exception "Invalid coercion") else BitVecExpr(e) let array_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.ARRAY_SORT) then raise (Z3native.Exception "Invalid coercion") else ArrayExpr(e) let datatype_expr_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.DATATYPE_SORT) then raise (Z3native.Exception "Invalid coercion") else DatatypeExpr(e) let int_expr_of_arith_expr e = - match e with ArithExpr(Expr(no)) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.INT_SORT) then raise (Z3native.Exception "Invalid coercion") else IntExpr(e) let real_expr_of_arith_expr e = - match e with ArithExpr(Expr(no)) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in if (q != Z3enums.REAL_SORT) then raise (Z3native.Exception "Invalid coercion") else RealExpr(e) let int_num_of_int_expr e = - match e with IntExpr(ArithExpr(Expr(no))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + match e with IntExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then raise (Z3native.Exception "Invalid coercion") else IntNum(e) let rat_num_of_real_expr e = - match e with RealExpr(ArithExpr(Expr(no))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + match e with RealExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then raise (Z3native.Exception "Invalid coercion") else RatNum(e) let algebraic_num_of_arith_expr e = - match e with ArithExpr(Expr(no)) -> - if (not (Z3native.is_algebraic_number (z3obj_gnc no) (z3obj_gno no))) then + match e with ArithExpr(Expr(a)) -> + if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then raise (Z3native.Exception "Invalid coercion") else AlgebraicNum(e) let bitvec_num_of_bitvec_expr e = - match e with BitVecExpr(Expr(no)) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc no) (z3obj_gno no))) then + match e with BitVecExpr(Expr(a)) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then raise (Z3native.Exception "Invalid coercion") else BitVecNum(e) let quantifier_of_expr e = - match e with Expr(no) -> - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc no) (z3obj_gno no))) in + match e with Expr(a) -> + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in if (q != Z3enums.QUANTIFIER_AST) then raise (Z3native.Exception "Invalid coercion") else @@ -4378,7 +4385,8 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i)) in + let f i = (bool_expr_of_expr (expr_of_ptr (z3obj_gc x) + (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in Array.init n f (** The number of formulas, subformulas and terms in the goal. *) From dcdcd7b14050991be33513212e8b95dc21fc5032 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 20 Feb 2013 11:49:00 +0000 Subject: [PATCH 178/248] ML API: Build system and error handling fixes. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 8 ++++++-- scripts/update_api.py | 12 ++++++++++++ src/api/ml/z3.ml | 6 +----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 5a5dbc3a4..4082bb2b8 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1351,10 +1351,14 @@ class MLComponent(Component): api_src = get_component(API_COMPONENT).to_src_dir for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) - out.write('\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f)) + str = '\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f) + if IS_WINDOWS: str = str.replace('/','\\') + out.write(str) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) - out.write('\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f)) + str = '\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f) + if IS_WINDOWS: str = str.replace('/','\\') + out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! prev = '' for m in modules: diff --git a/scripts/update_api.py b/scripts/update_api.py index 6e9c14355..e5c66dd39 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1169,9 +1169,11 @@ def mk_ml(): ml_i.write('\n') ml_native.write('external is_null : ptr -> bool\n = "n_is_null"\n\n') ml_native.write('external mk_null : unit -> ptr\n = "n_mk_null"\n\n') + ml_native.write('external set_internal_error_handler : ptr -> unit\n = "n_set_internal_error_handler"\n\n') ml_native.write('exception Exception of string\n\n') ml_i.write('val is_null : ptr -> bool\n') ml_i.write('val mk_null : unit -> ptr\n') + ml_i.write('val set_internal_error_handler : ptr -> unit\n\n') ml_i.write('exception Exception of string\n\n') # ML declarations @@ -1329,6 +1331,16 @@ def mk_ml(): ml_wrapper.write(' memcpy( Data_custom_val(result), &z3_result, sizeof(void*));\n') ml_wrapper.write(' CAMLreturn (result);\n') ml_wrapper.write('}\n\n') + ml_wrapper.write('void MLErrorHandler(Z3_context c, Z3_error_code e)\n') + ml_wrapper.write('{\n') + ml_wrapper.write(' // Internal do-nothing error handler. This is required to avoid that Z3 calls exit()\n') + ml_wrapper.write(' // upon errors, but the actual error handling is done by throwing exceptions in the\n') + ml_wrapper.write(' // wrappers below.\n') + ml_wrapper.write('}\n\n') + ml_wrapper.write('void n_set_internal_error_handler(Z3_context c)\n') + ml_wrapper.write('{\n') + ml_wrapper.write(' Z3_set_error_handler(c, MLErrorHandler);\n') + ml_wrapper.write('}\n\n') for name, result, params in _dotnet_decls: ip = inparams(params) op = outparams(params) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 651102bc8..45faae468 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -135,16 +135,12 @@ struct let v = Z3native.mk_context_rc cfg in Z3native.del_config(cfg) ; Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + Z3native.set_internal_error_handler v ; (* Printf.printf "Installing finalizer on context \n" ; *) let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in let f = fun o -> dispose_context o in Gc.finalise f res; res - (* CMW: Install error handler here! - m_n_err_handler = new Z3native.error_handler(NativeErrorHandler); keep reference so it doesn't get collected. - Z3native.set_error_handler(m_ctx, m_n_err_handler); - GC.SuppressFinalize(this); - *) let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) From 6842acbea85d6417dc4f1deb0752a551c9e5f580 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 20 Feb 2013 18:37:52 +0000 Subject: [PATCH 179/248] ML API: Cleanup Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 5 +- scripts/update_api.py | 2 + src/api/ml/z3.ml | 2247 +++++++++++++++++++------------------ src/api/ml/z3.mli | 1462 +++++++++++++++--------- 4 files changed, 2064 insertions(+), 1652 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 49db6fb50..6dfe11623 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -15,6 +15,9 @@ open Z3.Tactic.ApplyResult open Z3.Probe open Z3.Solver open Z3.Arithmetic +open Z3.Arithmetic.Integer +open Z3.Arithmetic.Real +open Z3.BitVector exception TestFailedException of string @@ -35,7 +38,7 @@ let model_converter_test ( ctx : context ) = (Real.mk_numeral_nd ctx 10 1)))) |]) ; (Goal.assert_ g4 [| (mk_eq ctx (expr_of_arith_expr yr) - (expr_of_arith_expr (mk_add ctx [| xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) |] ))) |] ) ; + (expr_of_arith_expr (Arithmetic.mk_add ctx [| xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) |]) ) ) |] ) ; (Goal.assert_ g4 [| (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) |]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in diff --git a/scripts/update_api.py b/scripts/update_api.py index e5c66dd39..a0b7e6250 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1155,6 +1155,7 @@ def mk_ml(): ml_native.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') ml_i.write('(* Automatically generated file *)\n\n') ml_i.write('(** The native (raw) interface to the dynamic Z3 library. *)\n\n') + ml_i.write('(**/**)\n\n'); ml_native.write('open Z3enums\n\n') ml_native.write('(**/**)\n') ml_native.write('type ptr\n') @@ -1214,6 +1215,7 @@ def mk_ml(): ml_native.write(' "n_%s_bytecode"\n' % ml_method_name(name)) ml_native.write('\n') ml_native.write(' end\n\n') + ml_i.write('\n(**/**)\n'); # Exception wrappers for name, result, params in _dotnet_decls: diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 45faae468..c261fce05 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -16,104 +16,11 @@ let is_null o = (Z3native.is_null o) type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } type context = z3_native_context - - type z3_native_object = { m_ctx : context ; mutable m_n_obj : Z3native.ptr ; inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - - -(* Symbol types *) -type int_symbol = z3_native_object -type string_symbol = z3_native_object - -type symbol = - | S_Int of int_symbol - | S_Str of string_symbol - -(* AST types *) -type ast = z3_native_object -type ast_vector = z3_native_object -type ast_map = z3_native_object - -(* FuncDecl types *) -type func_decl = FuncDecl of ast - -(* Sort types *) -type sort = Sort of ast -type uninterpreted_sort = UninterpretedSort of sort -type bool_sort = BoolSort of sort -type array_sort = ArraySort of sort -type set_sort = SetSort of sort -type datatype_sort = DatatypeSort of sort -type relation_sort = RelationSort of sort -type finite_domain_sort = FiniteDomainSort of sort -type enum_sort = EnumSort of sort -type list_sort = ListSort of sort -type tuple_sort = TupleSort of sort -type arith_sort = ArithSort of sort -type bitvec_sort = BitVecSort of sort - -type int_sort = IntSort of arith_sort -type real_sort = RealSort of arith_sort - -(* FuncDecl parameters *) -type parameter = - | P_Int of int - | P_Dbl of float - | P_Sym of symbol - | P_Srt of sort - | P_Ast of ast - | P_Fdl of func_decl - | P_Rat of string -type params = z3_native_object -type param_descrs = z3_native_object - -(* Expr types *) -type expr = Expr of ast - -type bool_expr = BoolExpr of expr -type arith_expr = ArithExpr of expr -type int_expr = IntExpr of arith_expr -type real_expr = RealExpr of arith_expr -type bitvec_expr = BitVecExpr of expr -type array_expr = ArrayExpr of expr -type datatype_expr = DatatypeExpr of expr - -(* Numerals *) -type int_num = IntNum of int_expr -type rat_num = RatNum of real_expr -type algebraic_num = AlgebraicNum of arith_expr -type bitvec_num = BitVecNum of bitvec_expr - -(* Quantifier stuff *) -type quantifier = Quantifier of expr -type pattern = Pattern of ast - -(* Datatype stuff *) -type constructor = z3_native_object -type constructor_list = z3_native_object - -(* Tactical interface *) -type goal = z3_native_object -type model = z3_native_object -type func_interp = z3_native_object -type func_entry = z3_native_object -type probe = z3_native_object -type tactic = z3_native_object -type apply_result = z3_native_object -type solver = z3_native_object -type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE -type statistics = z3_native_object -type statistics_entry = { - mutable m_key : string; - mutable m_is_int : bool ; - mutable m_is_float : bool ; - mutable m_int : int ; - mutable m_float : float } -type fixedpoint = z3_native_object (** Internal stuff *) @@ -121,11 +28,9 @@ module Internal = struct let dispose_context ctx = if ctx.m_n_obj_cnt == 0 then ( - (* Printf.printf "Disposing context \n" ; *) (Z3native.del_context ctx.m_n_ctx) ) else ( - Printf.printf "NOT DISPOSING context because it still has %d objects alive\n" ctx.m_n_obj_cnt; - (* re-queue for finalization? *) + Printf.printf "ERROR: NOT DISPOSING CONTEXT (because it still has %d objects alive)\n" ctx.m_n_obj_cnt; ) let create_context settings = @@ -136,7 +41,6 @@ struct Z3native.del_config(cfg) ; Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; Z3native.set_internal_error_handler v ; - (* Printf.printf "Installing finalizer on context \n" ; *) let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in let f = fun o -> dispose_context o in Gc.finalise f res; @@ -178,16 +82,6 @@ struct let array_to_native a = let f e = (z3obj_gno e) in Array.map f a - - (* Internal coercions *) - let context_of_ast ( x : ast ) = (z3obj_gc x) - let nc_of_ast ( x : ast ) = (z3obj_gnc x) - let ptr_of_ast ( x : ast ) = (z3obj_gno x) - - let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) - let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) - let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) - let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> let res : z3_native_object = { m_ctx = ctx ; @@ -196,323 +90,25 @@ struct dec_ref = Z3native.dec_ref } in (z3obj_sno res ctx no) ; (z3obj_create res) ; - res - - let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> - let q = (z3_native_object_of_ast_ptr ctx no) in - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then - raise (Z3native.Exception "Invalid coercion") - else - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with - | ARRAY_SORT - | BOOL_SORT - | BV_SORT - | DATATYPE_SORT - | INT_SORT - | REAL_SORT - | UNINTERPRETED_SORT - | FINITE_DOMAIN_SORT - | RELATION_SORT -> Sort(q) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - - let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - FuncDecl(z3_native_object_of_ast_ptr ctx no) - - let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST - | SORT_AST - | QUANTIFIER_AST - | APP_AST - | NUMERAL_AST - | VAR_AST -> z3_native_object_of_ast_ptr ctx no - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") - - and expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then - Expr(z3_native_object_of_ast_ptr ctx no) - else - let s = Z3native.get_sort (context_gno ctx) no in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) no) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - if (Z3native.is_numeral_ast (context_gno ctx) no) then - if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - raise (Z3native.Exception "Unsupported numeral object") - else - Expr(z3_native_object_of_ast_ptr ctx no) - - let expr_aton ( a : expr array ) = - let f ( e : expr ) = match e with Expr(a) -> (ptr_of_ast a) in - Array.map f a - - let expr_of_func_app : context -> func_decl -> expr array -> expr = fun ctx f args -> - match f with FuncDecl(fa) -> - let o = Z3native.mk_app (context_gno ctx) (ptr_of_ast fa) (Array.length args) (expr_aton args) in - expr_of_ptr ctx o + res end - open Internal - - -(* Sort coercions *) -let ast_of_sort s = match s with Sort(x) -> x -let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x -let sort_of_bool_sort s = match s with BoolSort(x) -> x -let sort_of_array_sort s = match s with ArraySort(x) -> x -let sort_of_set_sort s = match s with SetSort(x) -> x -let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x -let sort_of_relation_sort s = match s with RelationSort(x) -> x -let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x -let sort_of_enum_sort s = match s with EnumSort(x) -> x -let sort_of_list_sort s = match s with ListSort(x) -> x -let sort_of_tuple_sort s = match s with TupleSort(x) -> x -let sort_of_arith_sort s = match s with ArithSort(x) -> x -let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x -let arith_sort_of_int_sort s = match s with IntSort(x) -> x -let arith_sort_of_real_sort s = match s with RealSort(x) -> x - -let uninterpreted_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - UninterpretedSort(s) - -let bool_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolSort(s) - -let array_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArraySort(s) - -let datatype_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeSort(s) - -let relation_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RelationSort(s) - -let finite_domain_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - FiniteDomainSort(s) - -let arith_sort_of_sort s = match s with Sort(a) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithSort(s) - -let bitvec_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecSort(s) - -let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntSort(s) - -let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealSort(s) - -(* FuncDecl coercions *) -let ast_of_func_decl f = match f with FuncDecl(x) -> x - -(* Expr coercions *) -let ast_of_expr e = match e with Expr(a) -> a -let expr_of_bool_expr e = match e with BoolExpr(x) -> x -let expr_of_arith_expr e = match e with ArithExpr(x) -> x -let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x -let expr_of_array_expr e = match e with ArrayExpr(x) -> x -let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x - -let arith_expr_of_int_expr e = match e with IntExpr(x) -> x -let arith_expr_of_real_expr e = match e with RealExpr(x) -> x - -let int_expr_of_int_num e = match e with IntNum(x) -> x -let real_expr_of_rat_num e = match e with RatNum(x) -> x -let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x -let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x - -let expr_of_quantifier e = match e with Quantifier(x) -> x -let ast_of_pattern e = match e with Pattern(x) -> x - - -let expr_of_ast a = - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Expr(a) - -let bool_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolExpr(e) - -let arith_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithExpr(e) - -let bitvec_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecExpr(e) - -let array_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArrayExpr(e) - -let datatype_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeExpr(e) - -let int_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntExpr(e) - -let real_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealExpr(e) - -let int_num_of_int_expr e = - match e with IntExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - IntNum(e) - -let rat_num_of_real_expr e = - match e with RealExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - RatNum(e) - -let algebraic_num_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - AlgebraicNum(e) - -let bitvec_num_of_bitvec_expr e = - match e with BitVecExpr(Expr(a)) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecNum(e) - -let quantifier_of_expr e = - match e with Expr(a) -> - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.QUANTIFIER_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Quantifier(e) - -let pattern_of_ast a = - (* CMW: Unchecked ok? *) - Pattern(a) - - - -(** 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. *) module Log = struct - (** Open an interaction log file. - @param filename the name of the file to open. - @return True if opening the log file succeeds, false otherwise. - *) - (* CMW: "open" seems to be a reserved keyword? *) let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) - - (** Closes the interaction log. *) let close = Z3native.close_log - - (** Appends a user-provided string to the interaction log. - @param s the string to append*) let append s = Z3native.append_log s end -(** Version information *) module Version = struct - (** The major version. *) let major = let (x, _, _, _) = Z3native.get_version in x - - (** The minor version. *) let minor = let (_, x, _, _) = Z3native.get_version in x - - (** The build version. *) let build = let (_, _, x, _) = Z3native.get_version in x - - (** The revision. *) let revision = let (_, _, _, x) = Z3native.get_version in x - - (** A string representation of the version information. *) let to_string = let (mj, mn, bld, rev) = Z3native.get_version in string_of_int mj ^ "." ^ @@ -532,35 +128,21 @@ let mk_list ( f : int -> 'a ) ( n : int ) = mk_list' f 0 n [] -(** Create a context object. - - Most interactions with Z3 are interpreted in some context; many users will only - require one such object, but power users may require more than one. To start using - Z3, do - - - let ctx = (mk_context []) in - (...) - - - where a list of pairs of strings may be passed to set options on - the context, e.g., like so: - - - let cfg = [("model", "true"); ("...", "...")] in - let ctx = (mk_context cfg) in - (...) - -*) let mk_context ( cfg : ( string * string ) list ) = create_context cfg - - -(** Symbols are used to name several term and type constructors *) module Symbol = -struct +struct + (* Symbol types *) + type int_symbol = z3_native_object + type string_symbol = z3_native_object + + type symbol = + | S_Int of int_symbol + | S_Str of string_symbol + + let create_i ( ctx : context ) ( no : Z3native.ptr ) = let res : int_symbol = { m_ctx = ctx ; m_n_obj = null ; @@ -588,7 +170,7 @@ struct match x with | S_Int(n) -> (z3obj_gc n) | S_Str(n) -> (z3obj_gc n) - + let gnc ( x : symbol ) = match x with | S_Int(n) -> (z3obj_gnc n) @@ -599,59 +181,55 @@ struct | S_Int(n) -> (z3obj_gno n) | S_Str(n) -> (z3obj_gno n) - (** The kind of the symbol (int or string) *) - let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) - - (** Indicates whether the symbol is of Int kind *) + let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL - - (** Indicates whether the symbol is of string kind. *) let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL - - (** The int value of the symbol. *) let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) - - (** The string value of the symbol. *) let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) - - (** A string representation of the symbol. *) let to_string ( o : symbol ) = match (kind o) with | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) - (** - 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. - *) let mk_int ( ctx : context ) ( i : int ) = S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) - (** Creates a new symbol using a string. *) let mk_string ( ctx : context ) ( s : string ) = S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) - (** Create an array of symbols. *) let mk_ints ( ctx : context ) ( names : int array ) = let f elem = mk_int ( ctx : context ) elem in (Array.map f names) - (** Create an array of symbols. *) let mk_strings ( ctx : context ) ( names : string array ) = let f elem = mk_string ( ctx : context ) elem in (Array.map f names) end -(** The abstract syntax tree (AST) module *) module AST = -struct - (** Vectors of ASTs *) +struct + type ast = z3_native_object + + let context_of_ast ( x : ast ) = (z3obj_gc x) + let nc_of_ast ( x : ast ) = (z3obj_gnc x) + let ptr_of_ast ( x : ast ) = (z3obj_gno x) + + let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with + | FUNC_DECL_AST + | SORT_AST + | QUANTIFIER_AST + | APP_AST + | NUMERAL_AST + | VAR_AST -> z3_native_object_of_ast_ptr ctx no + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") + module ASTVector = struct - let create ( ctx : context ) ( no : Z3native.ptr ) = + type ast_vector = z3_native_object + + let ast_vector_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_vector_inc_ref ; @@ -659,55 +237,34 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - - - (** The size of the vector *) + let get_size ( x : ast_vector ) = Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) - (** - Retrieves the i-th object in the vector. - @param i Index - @return An AST - *) let get ( x : ast_vector ) ( i : int ) = - create (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) + ast_of_ptr (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) - (** Sets the i-th object in the vector. *) let set ( x : ast_vector ) ( i : int ) ( value : ast ) = Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) - (** Resize the vector to . - @param newSize The new size of the vector. *) let resize ( x : ast_vector ) ( new_size : int ) = Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size - (** - Add the AST to the back of the vector. The size - is increased by 1. - @param a An AST - *) let push ( x : ast_vector ) ( a : ast ) = Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) - (** - Translates all ASTs in the vector to . - @param to_ctx A context - @return A new ASTVector - *) let translate ( x : ast_vector ) ( to_ctx : context ) = - create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + ast_vector_of_ptr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - (** Retrieves a string representation of the vector. *) let to_string ( x : ast_vector ) = Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) end - (** Map from AST to AST *) module ASTMap = struct + type ast_map = z3_native_object - let create ( ctx : context ) ( no : Z3native.ptr ) = + let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_map = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_map_inc_ref ; @@ -715,73 +272,36 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - - - (** Checks whether the map contains the key . - @param k An AST - @return True if is a key in the map, false otherwise. *) + let contains ( x : ast_map ) ( key : ast ) = Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - (** Finds the value associated with the key . - - This function signs an error when is not a key in the map. - @param k An AST - *) let find ( x : ast_map ) ( key : ast ) = - create (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) + ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) - (** - Stores or replaces a new key/value pair in the map. - @param k The key AST - @param v The value AST - *) let insert ( x : ast_map ) ( key : ast ) ( value : ast) = Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) - (** - Erases the key from the map. - @param k An AST - *) let erase ( x : ast_map ) ( key : ast ) = Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - (** Removes all keys from the map. *) let reset ( x : ast_map ) = Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) - (** The size of the map *) let get_size ( x : ast_map ) = Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) - (** The keys stored in the map. *) let get_keys ( x : ast_map ) = - ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) - (** Retrieves a string representation of the map.*) let to_string ( x : ast_map ) = Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) end - (** - The AST's hash code. - @return A hash code - *) let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) - - (** - A unique identifier for the AST (unique among all ASTs). - *) let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) - - (** - The kind of the AST. - *) let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) - (** - Indicates whether the AST is an Expr - *) let is_expr ( x : ast ) = match get_ast_kind ( x : ast ) with | APP_AST @@ -790,117 +310,77 @@ struct | VAR_AST -> true | _ -> false - (** - Indicates whether the AST is a bound variable - *) let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST - - (** - Indicates whether the AST is a Quantifier - *) let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST - - - (** - Indicates whether the AST is a Sort - *) let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST - - (** - Indicates whether the AST is a FunctionDeclaration - *) let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST - (** - A string representation of the AST. - *) let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - - (** - A string representation of the AST in s-expression notation. - *) let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - (** - Comparison operator. - @param a An AST - @param b An AST - @return True if and are from the same context - and represent the same sort; false otherwise. - *) + let ( = ) ( a : ast ) ( b : ast ) = (a == b) || if (z3obj_gnc a) != (z3obj_gnc b) then false else Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) - (** - Object Comparison. - @param other Another ast - @return Negative if the object should be sorted before , positive if after else zero. - *) let compare a b = if (get_id a) < (get_id b) then -1 else if (get_id a) > (get_id b) then 1 else 0 - (** Operator < *) let ( < ) (a : ast) (b : ast) = (compare a b) - (** - Translates (copies) the AST to the Context . - @param ctx A context - @return A copy of the AST which is associated with - *) let translate ( x : ast ) ( to_ctx : context ) = if (z3obj_gnc x) == (context_gno to_ctx) then x else ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - (** - 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., - . - - @param nativeObject The native pointer to wrap. - *) - let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = - ast_of_ptr ctx ptr - - (** - 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., - ). - - @param a The AST to unwrap. - *) + let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr let unwrap_ast ( x : ast ) = (z3obj_gno x) end -(** The Sort module implements type information for ASTs *) +open AST + + module Sort = struct - + type sort = Sort of AST.ast + type uninterpreted_sort = UninterpretedSort of sort + + let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> + let q = (z3_native_object_of_ast_ptr ctx no) in + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then + raise (Z3native.Exception "Invalid coercion") + else + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with + | ARRAY_SORT + | BOOL_SORT + | BV_SORT + | DATATYPE_SORT + | INT_SORT + | REAL_SORT + | UNINTERPRETED_SORT + | FINITE_DOMAIN_SORT + | RELATION_SORT -> Sort(q) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + + let ast_of_sort s = match s with Sort(x) -> x + let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x + + let uninterpreted_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + UninterpretedSort(s) + + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) - - (** - Comparison operator. - @param a A sort - @param b A sort - @return True if and are from the same context - and represent the same sort; false otherwise. - *) + let ( = ) : sort -> sort -> bool = fun a b -> (a == b) || if (gnc a) != (gnc b) then @@ -908,30 +388,13 @@ struct else (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) - (** - Returns a unique identifier for the sort. - *) + let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) - - (** - The kind of the sort. - *) let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) - - (** - The name of the sort - *) let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) - - (** - A string representation of the sort. - *) let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) - - (** - Create a new uninterpreted sort. - *) - let mk_uninterpreted ( ctx : context ) ( s : symbol ) = + + let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; @@ -940,24 +403,76 @@ struct (z3obj_create res) ; UninterpretedSort(Sort(res)) - (** - Create a new uninterpreted sort. - *) let mk_uninterpreted_s ( ctx : context ) ( s : string ) = mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) end +open Sort -(** Function declarations *) -module FuncDecl = -struct - (**/**) - let create_ndr ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort ) = + +module rec FuncDecl : +sig + type func_decl = FuncDecl of AST.ast + val ast_of_func_decl : FuncDecl.func_decl -> AST.ast + val func_decl_of_ptr : context -> Z3native.ptr -> func_decl + val gc : func_decl -> context + val gnc : func_decl -> Z3native.ptr + val gno : func_decl -> Z3native.ptr + module Parameter : + sig + type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + val get_kind : parameter -> Z3enums.parameter_kind + val get_int : parameter -> int + val get_float : parameter -> float + val get_symbol : parameter -> Symbol.symbol + val get_sort : parameter -> Sort.sort + val get_ast : parameter -> AST.ast + val get_func_decl : parameter -> func_decl + val get_rational : parameter -> string + end + val mk_func_decl : context -> Symbol.symbol -> Sort.sort array -> Sort.sort -> func_decl + val mk_func_decl_s : context -> string -> Sort.sort array -> Sort.sort -> func_decl + val mk_fresh_func_decl : context -> string -> Sort.sort array -> Sort.sort -> func_decl + val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl + val mk_const_decl_s : context -> string -> Sort.sort -> func_decl + val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl + val ( = ) : func_decl -> func_decl -> bool + val to_string : func_decl -> string + val get_id : func_decl -> int + val get_arity : func_decl -> int + val get_domain_size : func_decl -> int + val get_domain : func_decl -> Sort.sort array + val get_range : func_decl -> Sort.sort + val get_decl_kind : func_decl -> Z3enums.decl_kind + val get_name : func_decl -> Symbol.symbol + val get_num_parameters : func_decl -> int + val get_parameters : func_decl -> Parameter.parameter list + val apply : func_decl -> Expr.expr array -> Expr.expr +end = struct + type func_decl = FuncDecl of AST.ast + + let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + FuncDecl(z3_native_object_of_ast_ptr ctx no) + + let ast_of_func_decl f = match f with FuncDecl(x) -> x + + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - let f x = (ptr_of_ast (ast_of_sort x)) in + let f x = (AST.ptr_of_ast (ast_of_sort x)) in (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Array.map f domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) @@ -967,20 +482,26 @@ struct m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - let f x = (ptr_of_ast (ast_of_sort x)) in + let f x = (AST.ptr_of_ast (ast_of_sort x)) in (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Array.map f domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) - let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - (**/**) + let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - (** Parameters of Func_Decls *) module Parameter = - struct - (** The kind of the parameter. *) + struct + type parameter = + | P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + let get_kind ( x : parameter ) = (match x with | P_Int(_) -> PARAMETER_INT @@ -991,188 +512,137 @@ struct | P_Fdl(_) -> PARAMETER_FUNC_DECL | P_Rat(_) -> PARAMETER_RATIONAL) - (**The int value of the parameter.*) let get_int ( x : parameter ) = match x with | P_Int(x) -> x | _ -> raise (Z3native.Exception "parameter is not an int") - - (**The double value of the parameter.*) + let get_float ( x : parameter ) = match x with | P_Dbl(x) -> x | _ -> raise (Z3native.Exception "parameter is not a double") - - (**The Symbol value of the parameter.*) + let get_symbol ( x : parameter ) = match x with | P_Sym(x) -> x | _ -> raise (Z3native.Exception "parameter is not a symbol") - (**The Sort value of the parameter.*) let get_sort ( x : parameter ) = match x with | P_Srt(x) -> x | _ -> raise (Z3native.Exception "parameter is not a sort") - (**The AST value of the parameter.*) let get_ast ( x : parameter ) = match x with | P_Ast(x) -> x | _ -> raise (Z3native.Exception "parameter is not an ast") - (**The FunctionDeclaration value of the parameter.*) let get_func_decl ( x : parameter ) = match x with | P_Fdl(x) -> x | _ -> raise (Z3native.Exception "parameter is not a func_decl") - (**The rational string value of the parameter.*) - let get_func_decl ( x : parameter ) = + let get_rational ( x : parameter ) = match x with | P_Rat(x) -> x | _ -> raise (Z3native.Exception "parameter is not a rational string") end - (** - Creates a new function declaration. - *) - let mk_func_decl ( ctx : context ) ( name : symbol ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = create_ndr ctx name domain range - (** - Creates a new function declaration. - *) let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = mk_func_decl ctx (Symbol.mk_string ctx name) domain range - (** - Creates a fresh function declaration with a name prefixed with . - - - *) let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = create_pdr ctx prefix domain range - (** - Creates a new constant function declaration. - *) - let mk_const_decl ( ctx : context ) ( name : symbol ) ( range : sort ) = + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = create_ndr ctx name [||] range - (** - Creates a new constant function declaration. - *) let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = create_ndr ctx (Symbol.mk_string ctx name) [||] range - (** - Creates a fresh constant function declaration with a name prefixed with . - - - *) let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = create_pdr ctx prefix [||] range - (** - Comparison operator. - @param a A func_decl - @param b A func_decl - @return True if and are from the same context - and represent the same func_decl; false otherwise. - *) let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || if (gnc a) != (gnc b) then false else (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) - (** - A string representations of the function declaration. - *) let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) - (** - Returns a unique identifier for the function declaration. - *) let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) - (** - The arity of the function declaration - *) let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) - (** - The size of the domain of the function declaration - - *) let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) - (** - The domain of the function declaration - *) let get_domain ( x : func_decl ) = let n = (get_domain_size x) in let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in Array.init n f - (** - The range of the function declaration - *) let get_range ( x : func_decl ) = sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) - (** - The kind of the function declaration. - *) let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) - (** - The name of the function declaration - *) let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) - (** - The number of parameters of the function declaration - *) let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) - (** - The parameters of the function declaration - *) let get_parameters ( x : func_decl ) = let n = (get_num_parameters x) in let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> P_Ast (ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> Parameter.P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> Parameter.P_Ast (AST.ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) ) in mk_list f n - (** - Create expression that applies function to arguments. - @param args The arguments - *) - let apply ( x : func_decl ) ( args : expr array ) = expr_of_func_app (gc x) x args + let apply ( x : func_decl ) ( args : Expr.expr array ) = Expr.expr_of_func_app (gc x) x args end -(** - Parameter sets (of Solvers, Tactics, ...) - A Params objects represents a configuration in the form of symbol/value pairs. -*) -module Params = -struct - (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) +and Params : +sig + type params = z3_native_object + module ParamDescrs : + sig + type param_descrs + val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs + val validate : param_descrs -> params -> unit + val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind + val get_names : param_descrs -> Symbol.symbol array + val get_size : param_descrs -> int + val to_string : param_descrs -> string + end + val add_bool : params -> Symbol.symbol -> bool -> unit + val add_int : params -> Symbol.symbol -> int -> unit + val add_double : params -> Symbol.symbol -> float -> unit + val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit + val add_s_bool : params -> string -> bool -> unit + val add_s_int : params -> string -> int -> unit + val add_s_double : params -> string -> float -> unit + val add_s_symbol : params -> string -> Symbol.symbol -> unit + val mk_params : context -> params + val to_string : params -> string +end = struct + type params = z3_native_object + module ParamDescrs = - struct - - let create ( ctx : context ) ( no : Z3native.ptr ) = + struct + type param_descrs = z3_native_object + + let param_descrs_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let res : param_descrs = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.param_descrs_inc_ref ; @@ -1180,79 +650,46 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - - - (** Validate a set of parameters. *) + let validate ( x : param_descrs ) ( p : params ) = Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) - (** Retrieve kind of parameter. *) - let get_kind ( x : param_descrs ) ( name : symbol ) = + let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) - (** Retrieve all names of parameters. *) let get_names ( x : param_descrs ) = let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** The size of the ParamDescrs. *) - let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) - - (** Retrieves a string representation of the ParamDescrs. *) + let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) end - (** - Adds a parameter setting. - *) - let add_bool ( x : params ) ( name : symbol ) ( value : bool ) = + let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - (** - Adds a parameter setting. - *) - let add_int ( x : params ) (name : symbol ) ( value : int ) = + let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - (** - Adds a parameter setting. - *) - let add_double ( x : params ) ( name : symbol ) ( value : float ) = + let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - (** - Adds a parameter setting. - *) - let add_symbol ( x : params ) ( name : symbol ) ( value : symbol ) = + let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) - (** - Adds a parameter setting. - *) let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = add_bool x (Symbol.mk_string (z3obj_gc x) name) value - (** - Adds a parameter setting. - *) let add_s_int ( x : params) ( name : string ) ( value : int ) = add_int x (Symbol.mk_string (z3obj_gc x) name) value - (** - Adds a parameter setting. - *) let add_s_double ( x : params ) ( name : string ) ( value : float ) = add_double x (Symbol.mk_string (z3obj_gc x) name) value - (** - Adds a parameter setting. - *) - let add_s_symbol ( x : params ) ( name : string ) ( value : symbol ) = + + let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = add_symbol x (Symbol.mk_string (z3obj_gc x) name) value - (** - Creates a new parameter set - *) let mk_params ( ctx : context ) = let res : params = { m_ctx = ctx ; m_n_obj = null ; @@ -1262,21 +699,107 @@ struct (z3obj_create res) ; res - (** - A string representation of the parameter set. - *) let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) end (** General expressions (terms) *) -module Expr = -struct +and Expr : +sig + type expr = Expr of AST.ast + val expr_of_ptr : context -> Z3native.ptr -> expr + val c_of_expr : expr -> context + val nc_of_expr : expr -> Z3native.ptr + val ptr_of_expr : expr -> Z3native.ptr + val expr_aton : expr array -> Z3native.ptr array + val ast_of_expr : expr -> AST.ast + val expr_of_ast : AST.ast -> expr + val expr_of_func_app : context -> FuncDecl.func_decl -> expr array -> expr + val simplify : expr -> Params.params option -> expr + val get_simplify_help : context -> string + val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs + val get_func_decl : expr -> FuncDecl.func_decl + val get_bool_value : expr -> Z3enums.lbool + val get_num_args : expr -> int + val get_args : expr -> expr array + val update : expr -> expr array -> expr + val substitute : expr -> expr array -> expr array -> expr + val substitute_one : expr -> expr -> expr -> expr + val substitute_vars : expr -> expr array -> expr + val translate : expr -> context -> expr + val to_string : expr -> string + val is_numeral : expr -> bool + val is_well_sorted : expr -> bool + val get_sort : expr -> Sort.sort + val is_bool : expr -> bool + val is_const : expr -> bool + val is_true : expr -> bool + val is_false : expr -> bool + val is_eq : expr -> bool + val is_distinct : expr -> bool + val is_ite : expr -> bool + val is_and : expr -> bool + val is_or : expr -> bool + val is_iff : expr -> bool + val is_xor : expr -> bool + val is_not : expr -> bool + val is_implies : expr -> bool + val is_label : expr -> bool + val is_oeq : expr -> bool + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + val mk_const_s : context -> string -> Sort.sort -> expr + val mk_const_f : context -> FuncDecl.func_decl -> expr + val mk_fresh_const : context -> string -> Sort.sort -> expr + val mk_app : context -> FuncDecl.func_decl -> expr array -> expr + val mk_numeral_string : context -> string -> Sort.sort -> expr + val mk_numeral_int : context -> int -> Sort.sort -> expr +end = struct + type expr = Expr of AST.ast + + let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) + let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) + let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) + + let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then + Expr(z3_native_object_of_ast_ptr ctx no) + else + let s = Z3native.get_sort (context_gno ctx) no in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) no) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + if (Z3native.is_numeral_ast (context_gno ctx) no) then + if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + raise (Z3native.Exception "Unsupported numeral object") + else + Expr(z3_native_object_of_ast_ptr ctx no) + + let expr_of_ast a = + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Expr(a) + + let ast_of_expr e = match e with Expr(a) -> a + + let expr_aton ( a : expr array ) = + let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in + Array.map f a + + let expr_of_func_app : context -> FuncDecl.func_decl -> expr array -> expr = fun ctx f args -> + match f with FuncDecl.FuncDecl(fa) -> + let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (Array.length args) (expr_aton args) in + expr_of_ptr ctx o + (** Returns a simplified version of the expression. @param p A set of parameters to configure the simplifier *) - let simplify ( x : expr ) ( p : params option ) = match p with + let simplify ( x : expr ) ( p : Params.params option ) = match p with | None -> expr_of_ptr (c_of_expr x) (Z3native.simplify (nc_of_expr x) (ptr_of_expr x)) | Some pp -> expr_of_ptr (c_of_expr x) (Z3native.simplify_ex (nc_of_expr x) (ptr_of_expr x) (z3obj_gno pp)) @@ -1290,12 +813,12 @@ struct Retrieves parameter descriptions for simplifier. *) let get_simplify_parameter_descrs ( ctx : context ) = - Params.ParamDescrs.create ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) + Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) (** The function declaration of the function that is applied in this expression. *) - let get_func_decl ( x : expr ) = func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) + let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) (** Indicates whether the expression is the true or false expression @@ -1477,7 +1000,7 @@ struct (** Creates a new Constant of sort and named . *) - let mk_const ( ctx : context ) ( name : symbol ) ( range : sort ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) @@ -1492,8 +1015,7 @@ struct Creates a constant from the func_decl . @param f An expression of a 0-arity function *) - let mk_const_f ( ctx : context ) ( f : func_decl ) = - expr_of_func_app ctx f [||] + let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [||] (** Creates a fresh constant of sort and a @@ -1505,8 +1027,7 @@ struct (** Create a new function application. *) - let mk_app ( ctx : context ) ( f : func_decl ) ( args : expr array ) = - expr_of_func_app ctx f args + let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = expr_of_func_app ctx f args (** Create a numeral of a given sort. @@ -1528,19 +1049,44 @@ struct expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) end +open FuncDecl +open Expr + (** Boolean expressions *) module Boolean = -struct +struct + type bool_sort = BoolSort of Sort.sort + type bool_expr = BoolExpr of Expr.expr + let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let a = (ast_of_ptr ctx no) in - BoolExpr(Expr(a)) + let a = (AST.ast_of_ptr ctx no) in + BoolExpr(Expr.Expr(a)) + + let bool_expr_of_expr e = + match e with Expr.Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolExpr(e) let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = BoolSort(sort_of_ptr ctx no) - let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (c_of_expr e) - let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (nc_of_expr e) - let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (ptr_of_expr e) + let sort_of_bool_sort s = match s with BoolSort(x) -> x + + let bool_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolSort(s) + + let expr_of_bool_expr e = match e with BoolExpr(x) -> x + + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.c_of_expr e) + let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.nc_of_expr e) + let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.ptr_of_expr e) let mk_sort ( ctx : context ) = BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) @@ -1548,7 +1094,7 @@ struct (** Create a Boolean constant. *) - let mk_const ( ctx : context ) ( name : symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = let s = (match (mk_sort ctx) with BoolSort(q) -> q) in BoolExpr(Expr.mk_const ctx name s) @@ -1638,17 +1184,38 @@ end (** Quantifier expressions *) module Quantifier = struct + type quantifier = Quantifier of expr + + let expr_of_quantifier e = match e with Quantifier(x) -> x + + let quantifier_of_expr e = + match e with Expr.Expr(a) -> + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.QUANTIFIER_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Quantifier(e) + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (c_of_expr e) let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (nc_of_expr e) let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (ptr_of_expr e) - + (** Quantifier patterns 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. *) - module Pattern = struct + module Pattern = + struct + type pattern = Pattern of ast + + let ast_of_pattern e = match e with Pattern(x) -> x + + let pattern_of_ast a = + (* CMW: Unchecked ok? *) + Pattern(a) + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) @@ -1692,7 +1259,7 @@ struct index. *) let get_index ( x : expr ) = - if not (AST.is_var (match x with Expr(a) -> a)) then + if not (AST.is_var (match x with Expr.Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else Z3native.get_index_value (nc_of_expr x) (ptr_of_expr x) @@ -1723,7 +1290,7 @@ struct *) let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in + let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** @@ -1736,7 +1303,7 @@ struct *) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in - let f i = Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in + let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in Array.init n f (** @@ -1781,7 +1348,7 @@ struct if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) + Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) (** Create a universal Quantifier. @@ -1802,14 +1369,14 @@ struct @param quantifierID optional symbol to track quantifier. @param skolemID optional symbol to track skolem constants. *) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) - (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) + (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) else @@ -1817,21 +1384,21 @@ struct (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (Array.length nopatterns) (expr_aton nopatterns) - (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) (** Create a universal Quantifier. *) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true @@ -1839,7 +1406,7 @@ struct (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (Array.length nopatterns) (expr_aton nopatterns) (ptr_of_expr body))) @@ -1847,14 +1414,14 @@ struct Create an existential Quantifier. *) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) - (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) + (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) else @@ -1862,21 +1429,21 @@ struct (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (Array.length nopatterns) (expr_aton nopatterns) - (Array.length sorts) (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) - + (** Create an existential Quantifier. *) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false @@ -1884,14 +1451,14 @@ struct (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (ptr_of_ast (ast_of_pattern x)) in (Array.map f patterns)) + (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) (Array.length nopatterns) (expr_aton nopatterns) (ptr_of_expr body))) (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : symbol array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else @@ -1901,7 +1468,7 @@ struct (** Create a Quantifier. *) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : pattern array ) ( nopatterns : expr array ) ( quantifier_id : symbol option ) ( skolem_id : symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -1911,14 +1478,35 @@ end (** Functions to manipulate Array expressions *) module Array_ = struct + type array_sort = ArraySort of sort + type array_expr = ArrayExpr of expr - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let array_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let e = (expr_of_ptr ctx no) in ArrayExpr(e) - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + let array_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in - ArraySort(s) + ArraySort(s) + + let sort_of_array_sort s = match s with ArraySort(x) -> x + + let array_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArraySort(s) + + let array_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArrayExpr(e) + + let expr_of_array_expr e = match e with ArrayExpr(x) -> x let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) @@ -1932,7 +1520,7 @@ struct Create a new array sort. *) let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = - create_sort ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) + array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) (** Indicates whether the term is an array store. @@ -1979,16 +1567,15 @@ struct ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == ARRAY_SORT) (** The domain of the array sort. *) - let get_domain ( x : array_sort ) = sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) + let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) (** The range of the array sort. *) - let get_range ( x : array_sort ) = sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) - + let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) (** Create an array constant. *) - let mk_const ( ctx : context ) ( name : symbol ) ( domain : sort ) ( range : sort ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) (** @@ -2010,7 +1597,7 @@ struct *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) + array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) (** Array update. @@ -2029,7 +1616,7 @@ struct *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = - expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) + array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) (** Create a constant array. @@ -2040,7 +1627,7 @@ struct *) let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) + array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) (** Maps f on the argument arrays. @@ -2054,7 +1641,7 @@ struct *) let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = let m x = (ptr_of_expr (expr_of_array_expr x)) in - expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m args)) + array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m args)) (** Access the array default value. @@ -2063,16 +1650,20 @@ struct finite maps with a default range value. *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = - expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) + array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) end (** Functions to manipulate Set expressions *) module Set = struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + type set_sort = SetSort of sort + + let set_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in SetSort(s) + let sort_of_set_sort s = match s with SetSort(x) -> x + (** Indicates whether the term is set union *) @@ -2102,7 +1693,7 @@ struct Create a set type. *) let mk_sort ( ctx : context ) ( ty : sort ) = - create_sort ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) + set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) (** Create an empty set. @@ -2169,14 +1760,24 @@ end (** Functions to manipulate Finite Domain expressions *) module FiniteDomain = struct + type finite_domain_sort = FiniteDomainSort of sort + + let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x + + let finite_domain_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + FiniteDomainSort(s) + let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) - + (** Create a new finite domain sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( size : int ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in FiniteDomainSort(s) @@ -2210,15 +1811,24 @@ end (** Functions to manipulate Relation expressions *) module Relation = struct - - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + type relation_sort = RelationSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in RelationSort(s) + let sort_of_relation_sort s = match s with RelationSort(x) -> x + + let relation_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RelationSort(s) + let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) - + (** Indicates whether the term is of a relation sort. @@ -2335,29 +1945,53 @@ struct (** The sorts of the columns of the relation sort. *) let get_column_sorts ( x : relation_sort ) = let n = get_arity x in - let f i = (create_sort (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in + let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in Array.init n f end (** Functions to manipulate Datatype expressions *) module Datatype = -struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = +struct + type datatype_sort = DatatypeSort of sort + type datatype_expr = DatatypeExpr of expr + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in DatatypeSort(s) + let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x + + let datatype_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeSort(s) + + let datatype_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeExpr(e) + + let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x + let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) - + (** Constructors *) module Constructor = struct + type constructor = z3_native_object + let _counts = Hashtbl.create 0 - let create ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -2366,11 +2000,11 @@ struct raise (Z3native.Exception "Number of field names does not match number of sort refs") else let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) - (Symbol.gno recognizer) - n - (let f x = (Symbol.gno x) in (Array.map f field_names)) - (let f x = (ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - sort_refs) in + (Symbol.gno recognizer) + n + (let f x = (Symbol.gno x) in (Array.map f field_names)) + (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) + sort_refs) in let no : constructor = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; @@ -2383,7 +2017,7 @@ struct no let get_n ( x : constructor ) = (Hashtbl.find _counts x) - + let rec constructor_decl ( x : constructor ) = let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in func_decl_of_ptr (z3obj_gc x) a @@ -2391,12 +2025,12 @@ struct let rec tester_decl ( x : constructor ) = let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in func_decl_of_ptr (z3obj_gc x) b - + let rec accessor_decls ( x : constructor ) = let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in let f y = func_decl_of_ptr (z3obj_gc x) y in Array.map f c - + (** The number of fields of the constructor. *) let get_num_fields ( x : constructor ) = get_n x @@ -2413,8 +2047,9 @@ struct (** Constructor list objects *) module ConstructorList = struct - - let create ( ctx : context ) ( c : constructor array ) = + type constructor_list = z3_native_object + + let create ( ctx : context ) ( c : Constructor.constructor array ) = let res : constructor_list = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; @@ -2438,7 +2073,7 @@ struct 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. *) - let mk_constructor ( ctx : context ) ( name : symbol ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = Constructor.create ctx name recognizer field_names sorts sort_refs @@ -2452,22 +2087,22 @@ struct 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. *) - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : symbol ) ( field_names : symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs (** Create a new datatype sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( constructors : constructor array ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array ) = let f x = (z3obj_gno x) in let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in - create_sort ctx x + sort_of_ptr ctx x (** Create a new datatype sort. *) - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : constructor array ) = + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = mk_sort ctx (Symbol.mk_string ctx name) constructors (** @@ -2475,17 +2110,17 @@ struct @param names names of datatype sorts @param c list of constructors, one list per sort. *) - let mk_sorts ( ctx : context ) ( names : symbol array ) ( c : constructor array array ) = + let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = let n = (Array.length names) in - let f e = (ptr_of_ast (ConstructorList.create ctx e)) in + let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in let cla = (Array.map f c) in let f2 x = (Symbol.gno x) in let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Array.map f2 names) cla) in - let g e = (create_sort ctx e) in + let g e = (sort_of_ptr ctx e) in (Array.map g r) (** Create mutually recursive data-types. *) - let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : constructor array array ) = + let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = mk_sorts ctx ( let f e = (Symbol.mk_string ctx e) in @@ -2522,17 +2157,21 @@ end (** Functions to manipulate Enumeration expressions *) module Enumeration = -struct +struct + type enum_sort = EnumSort of sort + let _constdecls = Hashtbl.create 0 let _testerdecls = Hashtbl.create 0 - - let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = let s = (sort_of_ptr ctx no) in let res = EnumSort(s) in Hashtbl.add _constdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f cdecls)) ; Hashtbl.add _testerdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f tdecls)) ; res + let sort_of_enum_sort s = match s with EnumSort(x) -> x + let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) @@ -2540,10 +2179,10 @@ struct (** Create a new enumeration sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( enum_names : symbol array ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = let f x = Symbol.gno x in let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Array.map f enum_names)) in - create_sort ctx a b c + sort_of_ptr ctx a b c (** Create a new enumeration sort. @@ -2561,14 +2200,16 @@ end (** Functions to manipulate List expressions *) module List_ = struct + type list_sort = ListSort of sort + let _nildecls = Hashtbl.create 0 let _is_nildecls = Hashtbl.create 0 let _consdecls = Hashtbl.create 0 let _is_consdecls = Hashtbl.create 0 let _headdecls = Hashtbl.create 0 let _taildecls = Hashtbl.create 0 - - let create_sort ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in let res = ListSort(s) in Hashtbl.add _nildecls res (func_decl_of_ptr ctx nildecl) ; @@ -2578,16 +2219,18 @@ struct Hashtbl.add _headdecls res (func_decl_of_ptr ctx headdecl) ; Hashtbl.add _taildecls res (func_decl_of_ptr ctx taildecl) ; res + + let sort_of_list_sort s = match s with ListSort(x) -> x let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) - - + + (** Create a new list sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( elem_sort : sort ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in - create_sort ctx r a b c d e f + sort_of_ptr ctx r a b c d e f (** Create a new list sort. *) let mk_list_s ( ctx : context ) (name : string) elem_sort = @@ -2618,23 +2261,26 @@ end (** Functions to manipulate Tuple expressions *) module Tuple = struct - - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + type tuple_sort = TupleSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in TupleSort(s) + let sort_of_tuple_sort s = match s with TupleSort(x) -> x + let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - + (** Create a new tuple sort. *) - let mk_sort ( ctx : context ) ( name : symbol ) ( field_names : symbol array ) ( field_sorts : sort array ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : sort array ) = let f x = Symbol.gno x in let f2 x = ptr_of_ast (ast_of_sort x) in let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in (* CMW: leaks a,b? *) - create_sort ctx r + sort_of_ptr ctx r (** The constructor function of the tuple. *) let get_mk_decl ( x : tuple_sort ) = @@ -2651,13 +2297,144 @@ struct end (** Functions to manipulate arithmetic expressions *) -module Arithmetic = -struct - - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - arith_expr_of_expr (expr_of_ptr ctx no) +module rec Arithmetic : +sig + type arith_sort = ArithSort of Sort.sort + type arith_expr = ArithExpr of Expr.expr + + val sort_of_arith_sort : arith_sort -> Sort.sort + val arith_sort_of_sort : Sort.sort -> arith_sort + val expr_of_arith_expr : arith_expr -> Expr.expr + val arith_expr_of_expr : Expr.expr -> arith_expr - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val int_expr_of_ptr : context -> Z3native.ptr -> int_expr + val int_num_of_ptr : context -> Z3native.ptr -> int_num + + val arith_sort_of_int_sort : Integer.int_sort -> arith_sort + val int_sort_of_arith_sort : arith_sort -> int_sort + val arith_expr_of_int_expr : int_expr -> arith_expr + val int_expr_of_int_num : int_num -> int_expr + val int_expr_of_arith_expr : arith_expr -> int_expr + val int_num_of_int_expr : int_expr -> int_num + + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val real_expr_of_ptr : context -> Z3native.ptr -> real_expr + val rat_num_of_ptr : context -> Z3native.ptr -> rat_num + + val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort + val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort + val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr + val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr + val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr + val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num + + val mk_sort : context -> real_sort + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr + end + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : algebraic_num -> arith_expr + val algebraic_num_of_arith_expr : arith_expr -> algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end + + val is_int : Expr.expr -> bool + val is_arithmetic_numeral : Expr.expr -> bool + val is_le : Expr.expr -> bool + val is_ge : Expr.expr -> bool + val is_lt : Expr.expr -> bool + val is_gt : Expr.expr -> bool + val is_add : Expr.expr -> bool + val is_sub : Expr.expr -> bool + val is_uminus : Expr.expr -> bool + val is_mul : Expr.expr -> bool + val is_div : Expr.expr -> bool + val is_idiv : Expr.expr -> bool + val is_remainder : Expr.expr -> bool + val is_modulus : Expr.expr -> bool + val is_inttoreal : Expr.expr -> bool + val is_real_to_int : Expr.expr -> bool + val is_real_is_int : Expr.expr -> bool + val is_real : Expr.expr -> bool + val is_int_numeral : Expr.expr -> bool + val is_rat_num : Expr.expr -> bool + val is_algebraic_number : Expr.expr -> bool + val mk_add : context -> arith_expr array -> arith_expr + val mk_mul : context -> arith_expr array -> arith_expr + val mk_sub : context -> arith_expr array -> arith_expr + val mk_unary_minus : context -> arith_expr -> arith_expr + val mk_div : context -> arith_expr -> arith_expr -> arith_expr + val mk_power : context -> arith_expr -> arith_expr -> arith_expr + val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr +end = struct + type arith_sort = ArithSort of sort + type arith_expr = ArithExpr of expr + + let arith_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithExpr(e) + + let arith_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + arith_expr_of_expr (expr_of_ptr ctx no) + + let sort_of_arith_sort s = match s with ArithSort(x) -> x + let expr_of_arith_expr e = match e with ArithExpr(x) -> x + + let arith_sort_of_sort s = match s with Sort(a) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithSort(s) + + let arith_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = arith_sort_of_sort (sort_of_ptr ctx no) let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) @@ -2667,16 +2444,72 @@ struct let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (nc_of_expr e) let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (ptr_of_expr e) - module Integer = - struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - int_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) - - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr - let create_num ( ctx : context ) ( no : Z3native.ptr ) = - int_num_of_int_expr (create_expr ctx no) + val int_expr_of_ptr : context -> Z3native.ptr -> int_expr + val int_num_of_ptr : context -> Z3native.ptr -> int_num + + val arith_sort_of_int_sort : Integer.int_sort -> arith_sort + val int_sort_of_arith_sort : arith_sort -> int_sort + val arith_expr_of_int_expr : int_expr -> arith_expr + val int_expr_of_int_num : int_num -> int_expr + val int_expr_of_arith_expr : arith_expr -> int_expr + val int_num_of_int_expr : int_expr -> int_num + + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end = struct + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + let int_expr_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntExpr(e) + + let int_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) + + let int_num_of_int_expr e = + match e with IntExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + IntNum(e) + + let int_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_num_of_int_expr (int_expr_of_ptr ctx no) + + let arith_sort_of_int_sort s = match s with IntSort(x) -> x + let arith_expr_of_int_expr e = match e with IntExpr(x) -> x + let int_expr_of_int_num e = match e with IntNum(x) -> x + + let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntSort(s) + + let int_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_sort_of_arith_sort (arith_sort_of_sort (Sort.sort_of_ptr ctx no)) let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) @@ -2687,11 +2520,11 @@ struct let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - + (** Create a new integer sort. *) let mk_sort ( ctx : context ) = - create_sort ctx (Z3native.mk_int_sort (context_gno ctx)) + int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) (** Retrieve the int value. *) let get_int ( x : int_num ) = @@ -2705,7 +2538,7 @@ struct (** Creates an integer constant. *) - let mk_int_const ( ctx : context ) ( name : symbol ) = + let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) (** @@ -2719,21 +2552,21 @@ struct The arguments must have int type. *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) (** Create an expression representing t1 rem t2. The arguments must have int type. *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) (** Create an integer numeral. @param v A string representing the Term value in decimal notation. *) let mk_int_numeral_s ( ctx : context ) ( v : string ) = - create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) (** Create an integer numeral. @@ -2741,7 +2574,7 @@ struct @return A Term with value and sort Integer *) let mk_int_numeral_i ( ctx : context ) ( v : int ) = - create_num ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) (** Coerce an integer to a real. @@ -2754,7 +2587,7 @@ struct The argument must be of integer sort. *) let mk_int2real ( ctx : context ) ( t : int_expr ) = - real_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) + Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) (** Create an bit bit-vector from the integer argument . @@ -2767,19 +2600,76 @@ struct The argument must be of integer sort. *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - bitvec_expr_of_expr (expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) + BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) end - module Real = - struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = - real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) - - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = - real_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr - let create_num ( ctx : context ) ( no : Z3native.ptr ) = - rat_num_of_real_expr (create_expr ctx no) + val real_expr_of_ptr : context -> Z3native.ptr -> real_expr + val rat_num_of_ptr : context -> Z3native.ptr -> rat_num + + val arith_sort_of_real_sort : real_sort -> arith_sort + val real_sort_of_arith_sort : arith_sort -> real_sort + val arith_expr_of_real_expr : real_expr -> arith_expr + val real_expr_of_rat_num : rat_num -> real_expr + val real_expr_of_arith_expr : arith_expr -> real_expr + val rat_num_of_real_expr : real_expr -> rat_num + + val mk_sort : context -> real_sort + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr + end = struct + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + let arith_sort_of_real_sort s = match s with RealSort(x) -> x + let arith_expr_of_real_expr e = match e with RealExpr(x) -> x + let real_expr_of_rat_num e = match e with RatNum(x) -> x + + let real_expr_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealExpr(e) + + let real_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) + + let rat_num_of_real_expr e = + match e with RealExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + RatNum(e) + + let rat_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + rat_num_of_real_expr (real_expr_of_ptr ctx no) + + let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealSort(s) + + let real_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) @@ -2790,19 +2680,19 @@ struct let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - + (** Create a real sort. *) let mk_sort ( ctx : context ) = - create_sort ctx (Z3native.mk_real_sort (context_gno ctx)) + real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) (** The numerator of a rational numeral. *) let get_numerator ( x : rat_num ) = - Integer.create_num (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) (** The denominator of a rational numeral. *) let get_denominator ( x : rat_num ) = - Integer.create_num (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -2813,7 +2703,7 @@ struct let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) (** Creates a real constant. *) - let mk_real_const ( ctx : context ) ( name : symbol ) = + let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) (** Creates a real constant. *) @@ -2832,7 +2722,7 @@ struct if (den == 0) then raise (Z3native.Exception "Denominator is zero") else - create_num ctx (Z3native.mk_real (context_gno ctx) num den) + rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) (** Create a real numeral. @@ -2840,7 +2730,7 @@ struct @return A Term with value and sort Real *) let mk_numeral_s ( ctx : context ) ( v : string ) = - create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) (** Create a real numeral. @@ -2849,11 +2739,11 @@ struct @return A Term with value and sort Real *) let mk_numeral_i ( ctx : context ) ( v : int ) = - create_num ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) (** Coerce a real to an integer. @@ -2863,18 +2753,39 @@ struct The argument must be of real sort. *) let mk_real2int ( ctx : context ) ( t : real_expr ) = - int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) + Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) end - module AlgebraicNumber = - struct - let create_num ( ctx : context ) ( no : Z3native.ptr ) = - algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + val arith_expr_of_algebraic_num : algebraic_num -> arith_expr + val algebraic_num_of_arith_expr : arith_expr -> algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end = struct + type algebraic_num = AlgebraicNum of arith_expr + + let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x + + let algebraic_num_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + AlgebraicNum(e) + + let algebraic_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - + (** Return a upper bound for a given real algebraic number. @@ -2884,7 +2795,7 @@ struct @return A numeral Expr of sort Real *) let to_upper ( x : algebraic_num ) ( precision : int ) = - Real.create_num (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) (** Return a lower bound for the given real algebraic number. @@ -2894,7 +2805,7 @@ struct @return A numeral Expr of sort Real *) let to_lower ( x : algebraic_num ) precision = - Real.create_num (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) (** Returns a string representation in decimal notation. The result has at most decimal places.*) @@ -3056,38 +2967,186 @@ struct Create an expression representing t1 < t2 *) let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 <= t2 *) let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 > t2 *) let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) (** Create an expression representing t1 >= t2 *) let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) end (** Functions to manipulate bit-vector expressions *) -module BitVector = -struct - let create_sort ( ctx : context ) ( no : Z3native.ptr ) = +and BitVector : +sig + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort + val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort + val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr + val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr + val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr + val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num + + val mk_sort : context -> int -> bitvec_sort + val is_bv : Expr.expr -> bool + val is_bv_numeral : Expr.expr -> bool + val is_bv_bit1 : Expr.expr -> bool + val is_bv_bit0 : Expr.expr -> bool + val is_bv_uminus : Expr.expr -> bool + val is_bv_add : Expr.expr -> bool + val is_bv_sub : Expr.expr -> bool + val is_bv_mul : Expr.expr -> bool + val is_bv_sdiv : Expr.expr -> bool + val is_bv_udiv : Expr.expr -> bool + val is_bv_SRem : Expr.expr -> bool + val is_bv_urem : Expr.expr -> bool + val is_bv_smod : Expr.expr -> bool + val is_bv_sdiv0 : Expr.expr -> bool + val is_bv_udiv0 : Expr.expr -> bool + val is_bv_srem0 : Expr.expr -> bool + val is_bv_urem0 : Expr.expr -> bool + val is_bv_smod0 : Expr.expr -> bool + val is_bv_ule : Expr.expr -> bool + val is_bv_sle : Expr.expr -> bool + val is_bv_uge : Expr.expr -> bool + val is_bv_sge : Expr.expr -> bool + val is_bv_ult : Expr.expr -> bool + val is_bv_slt : Expr.expr -> bool + val is_bv_ugt : Expr.expr -> bool + val is_bv_sgt : Expr.expr -> bool + val is_bv_and : Expr.expr -> bool + val is_bv_or : Expr.expr -> bool + val is_bv_not : Expr.expr -> bool + val is_bv_xor : Expr.expr -> bool + val is_bv_nand : Expr.expr -> bool + val is_bv_nor : Expr.expr -> bool + val is_bv_xnor : Expr.expr -> bool + val is_bv_concat : Expr.expr -> bool + val is_bv_signextension : Expr.expr -> bool + val is_bv_zeroextension : Expr.expr -> bool + val is_bv_extract : Expr.expr -> bool + val is_bv_repeat : Expr.expr -> bool + val is_bv_reduceor : Expr.expr -> bool + val is_bv_reduceand : Expr.expr -> bool + val is_bv_comp : Expr.expr -> bool + val is_bv_shiftleft : Expr.expr -> bool + val is_bv_shiftrightlogical : Expr.expr -> bool + val is_bv_shiftrightarithmetic : Expr.expr -> bool + val is_bv_rotateleft : Expr.expr -> bool + val is_bv_rotateright : Expr.expr -> bool + val is_bv_rotateleftextended : Expr.expr -> bool + val is_bv_rotaterightextended : Expr.expr -> bool + val is_int_to_bv : Expr.expr -> bool + val is_bv_to_int : Expr.expr -> bool + val is_bv_carry : Expr.expr -> bool + val is_bv_xor3 : Expr.expr -> bool + val get_size : bitvec_sort -> int + val get_int : bitvec_num -> int + val to_string : bitvec_num -> string + val mk_const : context -> Symbol.symbol -> int -> bitvec_expr + val mk_const_s : context -> string -> int -> bitvec_expr + val mk_not : context -> bitvec_expr -> Expr.expr + val mk_redand : context -> bitvec_expr -> Expr.expr + val mk_redor : context -> bitvec_expr -> Expr.expr + val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_neg : context -> bitvec_expr -> bitvec_expr + val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_numeral : context -> string -> int -> bitvec_num +end = struct + type bitvec_sort = BitVecSort of sort + type bitvec_expr = BitVecExpr of expr + type bitvec_num = BitVecNum of bitvec_expr + + let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x + + let bitvec_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecSort(s) + + let bitvec_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = bitvec_sort_of_sort (sort_of_ptr ctx no) - let create_expr ( ctx : context ) ( no : Z3native.ptr ) = + let bitvec_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecExpr(e) + + let bitvec_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = bitvec_expr_of_expr (expr_of_ptr ctx no) - let create_num ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_num_of_bitvec_expr (create_expr ctx no) + let bitvec_num_of_bitvec_expr e = + match e with BitVecExpr(Expr(a)) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecNum(e) + + let bitvec_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + bitvec_num_of_bitvec_expr (bitvec_expr_of_expr (expr_of_ptr ctx no)) + + let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x + let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x + let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) @@ -3098,13 +3157,13 @@ struct let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - + (** Create a new bit-vector sort. *) let mk_sort ( ctx : context ) size = - create_sort ctx (Z3native.mk_bv_sort (context_gno ctx) size) + bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) (** Indicates whether the terms is of bit-vector sort. @@ -3391,8 +3450,8 @@ struct (** Creates a bit-vector constant. *) - let mk_const ( ctx : context ) ( name : symbol ) ( size : int ) = - BitVecExpr(Expr.mk_const ctx name (match (mk_sort ctx size) with BitVecSort(s) -> s)) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) (** Creates a bit-vector constant. @@ -3426,70 +3485,70 @@ struct The arguments must have a bit-vector sort. *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise disjunction. The arguments must have a bit-vector sort. *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XOR. The arguments must have a bit-vector sort. *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NAND. The arguments must have a bit-vector sort. *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) (** Bitwise NOR. The arguments must have a bit-vector sort. *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) (** Bitwise XNOR. The arguments must have a bit-vector sort. *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) (** Two's complement addition. The arguments must have the same bit-vector sort. *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) (** Unsigned division. @@ -3501,7 +3560,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) (** Signed division. @@ -3516,7 +3575,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) (** Unsigned remainder. @@ -3526,7 +3585,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) (** Signed remainder. @@ -3538,7 +3597,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) (** Two's complement signed remainder (sign follows divisor). @@ -3547,7 +3606,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) (** Unsigned less-than @@ -3555,7 +3614,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed less-than @@ -3563,7 +3622,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) (** Unsigned less-than or equal to. @@ -3571,7 +3630,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed less-than or equal to. @@ -3579,7 +3638,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) (** Unsigned greater than or equal to. @@ -3587,7 +3646,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed greater than or equal to. @@ -3595,7 +3654,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) (** Unsigned greater-than. @@ -3603,7 +3662,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) (** Two's complement signed greater-than. @@ -3611,7 +3670,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) (** Bit-vector concatenation. @@ -3622,7 +3681,7 @@ struct is the size of t1 (t2). *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) (** Bit-vector extraction. @@ -3633,7 +3692,7 @@ struct The argument must have a bit-vector sort. *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) (** Bit-vector sign extension. @@ -3643,7 +3702,7 @@ struct The argument must have a bit-vector sort. *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) (** Bit-vector zero extension. @@ -3654,7 +3713,7 @@ struct The argument must have a bit-vector sort. *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) (** Bit-vector repetition. @@ -3662,7 +3721,7 @@ struct The argument must have a bit-vector sort. *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) (** Shift left. @@ -3677,8 +3736,8 @@ struct The arguments must have a bit-vector sort. *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) - + bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) + (** Logical shift right @@ -3692,7 +3751,7 @@ struct The arguments must have a bit-vector sort. *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) (** Arithmetic shift right @@ -3708,7 +3767,7 @@ struct The arguments must have a bit-vector sort. *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) (** Rotate Left. @@ -3717,7 +3776,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) (** Rotate Right. @@ -3726,7 +3785,7 @@ struct The argument must have a bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) + bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) (** Rotate Left. @@ -3735,7 +3794,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) (** Rotate Right. @@ -3745,7 +3804,7 @@ struct The arguments must have the same bit-vector sort. *) let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) + bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) (** Create an integer from the bit-vector argument . @@ -3763,7 +3822,7 @@ struct The argument must be of bit-vector sort. *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = - Arithmetic.Integer.create_expr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) + Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) (** Create a predicate that checks that the bit-wise addition does not overflow. @@ -3771,7 +3830,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise addition does not underflow. @@ -3779,7 +3838,7 @@ struct The arguments must be of bit-vector sort. *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise subtraction does not overflow. @@ -3787,7 +3846,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise subtraction does not underflow. @@ -3795,7 +3854,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise signed division does not overflow. @@ -3803,7 +3862,7 @@ struct The arguments must be of bit-vector sort. *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) (** Create a predicate that checks that the bit-wise negation does not overflow. @@ -3811,7 +3870,7 @@ struct The arguments must be of bit-vector sort. *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) (** Create a predicate that checks that the bit-wise multiplication does not overflow. @@ -3819,7 +3878,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) (** Create a predicate that checks that the bit-wise multiplication does not underflow. @@ -3827,7 +3886,7 @@ struct The arguments must be of bit-vector sort. *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) (** Create a bit-vector numeral. @@ -3836,7 +3895,7 @@ struct @param size the size of the bit-vector *) let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = - create_num ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx size))) + bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) end (** Functions to manipulate proof expressions *) @@ -4321,7 +4380,8 @@ end tactics and solvers. *) module Goal = struct - + type goal = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : goal = { m_ctx = ctx ; m_n_obj = null ; @@ -4330,7 +4390,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** The precision of the goal. @@ -4359,7 +4419,7 @@ struct (** Adds the constraints to the given goal. *) (* CMW: assert seems to be a keyword. *) - let assert_ ( x : goal ) ( constraints : bool_expr array ) = + let assert_ ( x : goal ) ( constraints : Boolean.bool_expr array ) = let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in ignore (Array.map f constraints) ; () @@ -4381,7 +4441,7 @@ struct (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in - let f i = (bool_expr_of_expr (expr_of_ptr (z3obj_gc x) + let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in Array.init n f @@ -4401,7 +4461,7 @@ struct create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - let simplify ( x : goal ) ( p : params option ) = + let simplify ( x : goal ) ( p : Params.params option ) = let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in Z3native.tactic_inc_ref (z3obj_gnc x) tn ; let arn = match p with @@ -4441,7 +4501,8 @@ end A Model contains interpretations (assignments) of constants and functions. *) module Model = struct - + type model = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : model = { m_ctx = ctx ; m_n_obj = null ; @@ -4450,7 +4511,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Function interpretations @@ -4459,7 +4520,8 @@ struct *) module FuncInterp = struct - + type func_interp = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_interp = { m_ctx = ctx ; m_n_obj = null ; @@ -4468,7 +4530,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Function interpretations entries @@ -4476,7 +4538,8 @@ struct *) module FuncEntry = struct - + type func_entry = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : func_entry = { m_ctx = ctx ; m_n_obj = null ; @@ -4485,7 +4548,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Return the (symbolic) value of this entry. @@ -4677,7 +4740,7 @@ struct An array of expressions, where each is an element of the universe of *) let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in Array.init n f @@ -4699,7 +4762,8 @@ end *) module Probe = struct - + type probe = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : probe = { m_ctx = ctx ; m_n_obj = null ; @@ -4708,14 +4772,14 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Execute the probe over the goal. A probe always produce a double value. "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - let apply ( x : probe ) (g : goal) = + let apply ( x : probe ) ( g : Goal.goal ) = Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (** @@ -4820,7 +4884,8 @@ end *) module Tactic = struct - + type tactic = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : tactic = { m_ctx = ctx ; m_n_obj = null ; @@ -4829,7 +4894,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** Tactic application results @@ -4837,7 +4902,8 @@ struct tactic to a goal. It contains the subgoals that were produced. *) module ApplyResult = struct - + type apply_result = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : apply_result = { m_ctx = ctx ; m_n_obj = null ; @@ -4846,7 +4912,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + (** The number of Subgoals. *) let get_num_subgoals ( x : apply_result ) = @@ -4866,7 +4932,7 @@ struct goal g, that the ApplyResult was obtained from. #return A model for g *) - let convert_model ( x : apply_result ) ( i : int ) ( m : model ) = + let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) (** A string representation of the ApplyResult. *) @@ -4878,10 +4944,10 @@ struct (** Retrieves parameter descriptions for Tactics. *) let get_param_descrs ( x : tactic ) = - Params.ParamDescrs.create (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Apply the tactic to the goal. *) - let apply ( x : tactic ) ( g : goal ) ( p : params option ) = + let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = match p with | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) @@ -4949,14 +5015,14 @@ struct If evaluates to false, then the new tactic behaves like the skip tactic. *) (* CMW: when is a keyword *) - let when_ ( ctx : context ) ( p : probe ) ( t : tactic ) = + let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) (** Create a tactic that applies to a given goal if the probe evaluates to true and otherwise. *) - let cond ( ctx : context ) ( p : probe ) ( t1 : tactic ) ( t2 : tactic ) = + let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) (** @@ -4981,7 +5047,7 @@ struct (** Create a tactic that fails if the probe evaluates to false. *) - let fail_if ( ctx : context ) ( p : probe ) = + let fail_if ( ctx : context ) ( p : Probe.probe ) = create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) (** @@ -4994,14 +5060,14 @@ struct (** Create a tactic that applies using the given set of parameters . *) - let using_params ( ctx : context ) ( t : tactic ) ( p : params ) = + let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) (** Create a tactic that applies using the given set of parameters . Alias for UsingParams*) (* CMW: with is a keyword *) - let with_ ( ctx : context ) ( t : tactic ) ( p : params ) = + let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = using_params ctx t p (** @@ -5029,7 +5095,9 @@ end (** Solvers *) module Solver = struct - + type solver = z3_native_object + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : solver = { m_ctx = ctx ; m_n_obj = null ; @@ -5038,7 +5106,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + let string_of_status ( s : status) = match s with | UNSATISFIABLE -> "unsatisfiable" @@ -5048,7 +5116,8 @@ struct (** Objects that track statistical information about solvers. *) module Statistics = struct - + type statistics = z3_native_object + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : statistics = { m_ctx = ctx ; m_n_obj = null ; @@ -5066,7 +5135,13 @@ struct *) module Entry = struct - + type statistics_entry = { + mutable m_key : string; + mutable m_is_int : bool ; + mutable m_is_float : bool ; + mutable m_int : int ; + mutable m_float : float } + let create_si k v = let res : statistics_entry = { m_key = k ; @@ -5086,7 +5161,7 @@ struct m_float = v } in res - + (** The key of the entry. *) let get_key (x : statistics_entry) = x.m_key @@ -5142,11 +5217,9 @@ struct let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** - The value of a particular statistical counter. - *) + (** The value of a particular statistical counter. *) let get ( x : statistics ) ( key : string ) = - let f p c = (if (Entry.get_key c) = key then (Some c) else p) in + let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in Array.fold_left f None (get_entries x) end @@ -5158,14 +5231,14 @@ struct (** Sets the solver parameters. *) - let set_parameters ( x : solver ) ( p : params )= + let set_parameters ( x : solver ) ( p : Params.params )= Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** Retrieves parameter descriptions for solver. *) let get_param_descrs ( x : solver ) = - Params.ParamDescrs.create (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** The current number of backtracking points (scopes). @@ -5196,7 +5269,7 @@ struct (** Assert a constraint (or multiple) into the solver. *) - let assert_ ( x : solver ) ( constraints : bool_expr array ) = + let assert_ ( x : solver ) ( constraints : Boolean.bool_expr array ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) @@ -5213,7 +5286,7 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( cs : bool_expr array ) ( ps : bool_expr array ) = + let assert_and_track ( x : solver ) ( cs : Boolean.bool_expr array ) ( ps : Boolean.bool_expr array ) = if ((Array.length cs) != (Array.length ps)) then raise (Z3native.Exception "Argument size mismatch") else @@ -5232,14 +5305,14 @@ struct * and the Boolean literals * provided using with assumptions. *) - let assert_and_track ( x : solver ) ( c : bool_expr ) ( p : bool_expr ) = + let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) (** The number of assertions in the solver. *) let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) @@ -5247,9 +5320,9 @@ struct The set of asserted formulas. *) let get_assertions ( x : solver ) = - let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in - let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in Array.init n f (** @@ -5259,12 +5332,12 @@ struct *) - let check ( x : solver ) ( assumptions : bool_expr array) = + let check ( x : solver ) ( assumptions : Boolean.bool_expr array) = let r = if ((Array.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - let f x = (ptr_of_expr (expr_of_bool_expr x)) in + let f x = (ptr_of_expr (Boolean.expr_of_bool_expr x)) in lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Array.map f assumptions)) in match r with @@ -5306,7 +5379,7 @@ struct if its results was not UNSATISFIABLE, or if core production is disabled. *) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f @@ -5330,7 +5403,7 @@ struct check-sat command, and check-sat commands that take more than a given number of milliseconds to be solved. *) - let mk_solver ( ctx : context ) ( logic : symbol option ) = + let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = match logic with | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) @@ -5354,7 +5427,7 @@ struct The solver supports the commands Push and Pop, but it will always solve each check from scratch. *) - let mk_solver_t ( ctx : context ) ( t : tactic ) = + let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) (** @@ -5366,7 +5439,9 @@ end (** Fixedpoint solving *) module Fixedpoint = -struct +struct + type fixedpoint = z3_native_object + let create ( ctx : context ) = let res : fixedpoint = { m_ctx = ctx ; m_n_obj = null ; @@ -5375,7 +5450,7 @@ struct (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; (z3obj_create res) ; res - + (** A string that describes all available fixedpoint solver parameters. @@ -5386,19 +5461,19 @@ struct (** Sets the fixedpoint solver parameters. *) - let set_params ( x : fixedpoint ) ( p : params )= + let set_params ( x : fixedpoint ) ( p : Params.params )= Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) (** Retrieves parameter descriptions for Fixedpoint solver. *) let get_param_descrs ( x : fixedpoint ) = - Params.ParamDescrs.create (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) (** Assert a constraints into the fixedpoint solver. *) - let assert_ ( x : fixedpoint ) ( constraints : bool_expr array ) = + let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr array ) = let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) ; () @@ -5412,7 +5487,7 @@ struct (** Add rule into the fixedpoint solver. *) - let add_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = match name with | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) @@ -5429,11 +5504,11 @@ struct 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. *) - let query ( x : fixedpoint ) ( query : bool_expr ) = + let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with - | L_TRUE -> SATISFIABLE - | L_FALSE -> UNSATISFIABLE - | _ -> UNKNOWN + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN (** Query the fixedpoint solver. @@ -5444,9 +5519,9 @@ struct let query_r ( x : fixedpoint ) ( relations : func_decl array ) = let f x = ptr_of_ast (ast_of_func_decl x) in match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (Array.map f relations))) with - | L_TRUE -> SATISFIABLE - | L_FALSE -> UNSATISFIABLE - | _ -> UNKNOWN + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN (** Creates a backtracking point. @@ -5467,7 +5542,7 @@ struct (** Update named rule into in the fixedpoint solver. *) - let update_rule ( x : fixedpoint ) ( rule : bool_expr ) ( name : symbol ) = + let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) (** @@ -5518,33 +5593,33 @@ struct (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : symbol array ) = + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = let f2 x = (Symbol.gno x) in Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Array.map f2 kinds) (** Convert benchmark given as set of axioms, rules and queries to a string. *) - let to_string_q ( x : fixedpoint ) ( queries : bool_expr array ) = - let f x = ptr_of_expr (expr_of_bool_expr x) in + let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr array ) = + let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Array.map f queries) (** Retrieve set of rules added to fixedpoint context. *) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f (** Retrieve set of assertions added to fixedpoint context. *) let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f (** @@ -5628,9 +5703,9 @@ struct @param formula Formula to be checked for consistency in conjunction with assumptions. @return A string representation of the benchmark. *) - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : bool_expr array ) ( formula : bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr array ) ( formula : Boolean.bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (let f x = ptr_of_expr (expr_of_bool_expr x) in (Array.map f assumptions)) + (Array.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.map f assumptions)) (Boolean.gno formula) (** @@ -5642,7 +5717,7 @@ struct and . This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5662,7 +5737,7 @@ struct Parse the given file using the SMT-LIB parser. *) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5688,7 +5763,7 @@ struct *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in Array.init n f @@ -5702,7 +5777,7 @@ struct *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in Array.init n f (** @@ -5737,7 +5812,7 @@ struct @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5745,19 +5820,19 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) - cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str + cs + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) + cd + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)))) (** Parse the given file using the SMT-LIB2 parser. *) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : symbol array ) ( sorts : sort array ) ( decl_names : symbol array ) ( decls : func_decl array ) = + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in let cdn = (Array.length decl_names) in @@ -5765,13 +5840,13 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name - cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) - cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)))) + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name + cs + (let f x = Symbol.gno x in (Array.map f sort_names)) + (let f x = Sort.gno x in (Array.map f sorts)) + cd + (let f x = Symbol.gno x in (Array.map f decl_names)) + (let f x = FuncDecl.gno x in (Array.map f decls)))) end @@ -5818,23 +5893,3 @@ let get_global_param ( id : string ) = *) let global_param_reset_all = Z3native.global_param_reset_all - - - -(* - -(** - 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, error_code errorCode, string errorString); - - internal Z3native.error_handler m_n_err_handler = null; - - internal void NativeErrorHandler(IntPtr ctx, error_code errorCode) - - Do-nothing error handler. The wrappers in Z3.Native will throw exceptions upon errors. - -*) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 5d5d7adf0..5b1b2073a 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -7,333 +7,566 @@ type context -type int_symbol -type string_symbol -type symbol = S_Int of int_symbol | S_Str of string_symbol +(** Create a context object. -type ast -type ast_vector -type ast_map + Most interactions with Z3 are interpreted in some context; many users will only + require one such object, but power users may require more than one. To start using + Z3, do -type sort = Sort of ast + + let ctx = (mk_context []) in + (...) + -type uninterpreted_sort = UninterpretedSort of sort -type bool_sort = BoolSort of sort -type array_sort = ArraySort of sort -type set_sort = SetSort of sort -type datatype_sort = DatatypeSort of sort -type relation_sort = RelationSort of sort -type finite_domain_sort = FiniteDomainSort of sort -type enum_sort = EnumSort of sort -type list_sort = ListSort of sort -type tuple_sort = TupleSort of sort -type arith_sort = ArithSort of sort -type bitvec_sort = BitVecSort of sort -type int_sort = IntSort of arith_sort -type real_sort = RealSort of arith_sort + where a list of pairs of strings may be passed to set options on + the context, e.g., like so: -type func_decl = FuncDecl of ast + + let cfg = [("model", "true"); ("...", "...")] in + let ctx = (mk_context cfg) in + (...) + +*) +val mk_context : (string * string) list -> context -type parameter = - P_Int of int - | P_Dbl of float - | P_Sym of symbol - | P_Srt of sort - | P_Ast of ast - | P_Fdl of func_decl - | P_Rat of string - -type params -type param_descrs - -type expr = Expr of ast -type bool_expr = BoolExpr of expr -type arith_expr = ArithExpr of expr -type int_expr = IntExpr of arith_expr -type real_expr = RealExpr of arith_expr -type bitvec_expr = BitVecExpr of expr -type array_expr = ArrayExpr of expr -type datatype_expr = DatatypeExpr of expr -type int_num = IntNum of int_expr -type rat_num = RatNum of real_expr -type algebraic_num = AlgebraicNum of arith_expr -type bitvec_num = BitVecNum of bitvec_expr -type quantifier = Quantifier of expr -type pattern = Pattern of ast - -type constructor - -type goal - -type model -type func_interp -type func_entry - -type probe - -type tactic -type apply_result - -type solver -type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE - -type statistics -type statistics_entry - -type fixedpoint - -val ast_of_sort : sort -> ast -val sort_of_uninterpreted_sort : uninterpreted_sort -> sort -val sort_of_bool_sort : bool_sort -> sort -val sort_of_array_sort : array_sort -> sort -val sort_of_set_sort : set_sort -> sort -val sort_of_datatype_sort : datatype_sort -> sort -val sort_of_relation_sort : relation_sort -> sort -val sort_of_finite_domain_sort : finite_domain_sort -> sort -val sort_of_enum_sort : enum_sort -> sort -val sort_of_list_sort : list_sort -> sort -val sort_of_tuple_sort : tuple_sort -> sort -val sort_of_arith_sort : arith_sort -> sort -val sort_of_bitvec_sort : bitvec_sort -> sort -val arith_sort_of_int_sort : int_sort -> arith_sort -val arith_sort_of_real_sort : real_sort -> arith_sort -val uninterpreted_sort_of_sort : sort -> uninterpreted_sort -val bool_sort_of_sort : sort -> bool_sort -val array_sort_of_sort : sort -> array_sort -val datatype_sort_of_sort : sort -> datatype_sort -val relation_sort_of_sort : sort -> relation_sort -val finite_domain_sort_of_sort : sort -> finite_domain_sort -val arith_sort_of_sort : sort -> arith_sort -val bitvec_sort_of_sort : sort -> bitvec_sort -val int_sort_of_arith_sort : arith_sort -> int_sort -val real_sort_of_arith_sort : arith_sort -> real_sort -val ast_of_func_decl : func_decl -> ast -val ast_of_expr : expr -> ast -val expr_of_bool_expr : bool_expr -> expr -val expr_of_arith_expr : arith_expr -> expr -val expr_of_bitvec_expr : bitvec_expr -> expr -val expr_of_array_expr : array_expr -> expr -val expr_of_datatype_expr : datatype_expr -> expr -val arith_expr_of_int_expr : int_expr -> arith_expr -val arith_expr_of_real_expr : real_expr -> arith_expr -val int_expr_of_int_num : int_num -> int_expr -val real_expr_of_rat_num : rat_num -> real_expr -val arith_expr_of_algebraic_num : algebraic_num -> arith_expr -val bitvec_expr_of_bitvec_num : bitvec_num -> bitvec_expr -val expr_of_quantifier : quantifier -> expr -val ast_of_pattern : pattern -> ast -val expr_of_ast : ast -> expr -val bool_expr_of_expr : expr -> bool_expr -val arith_expr_of_expr : expr -> arith_expr -val bitvec_expr_of_expr : expr -> bitvec_expr -val array_expr_of_expr : expr -> array_expr -val datatype_expr_of_expr : expr -> datatype_expr -val int_expr_of_arith_expr : arith_expr -> int_expr -val real_expr_of_arith_expr : arith_expr -> real_expr -val int_num_of_int_expr : int_expr -> int_num -val rat_num_of_real_expr : real_expr -> rat_num -val algebraic_num_of_arith_expr : arith_expr -> algebraic_num -val bitvec_num_of_bitvec_expr : bitvec_expr -> bitvec_num -val quantifier_of_expr : expr -> quantifier -val pattern_of_ast : ast -> pattern +(** 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. *) module Log : sig + (** Open an interaction log file. + @param filename the name of the file to open. + @return True if opening the log file succeeds, false otherwise. + *) + (* CMW: "open" seems to be a reserved keyword? *) val open_ : string -> bool + + (** Closes the interaction log. *) val close : unit + + (** Appends a user-provided string to the interaction log. + @param s the string to append*) val append : string -> unit end +(** Version information *) module Version : sig + (** The major version. *) val major : int + + (** The minor version. *) val minor : int + + (** The build version. *) val build : int + + (** The revision. *) val revision : int + + (** A string representation of the version information. *) val to_string : string end -val mk_context : (string * string) list -> context - +(** Symbols are used to name several term and type constructors *) module Symbol : sig + (** Numbered Symbols *) + type int_symbol + + (** Named Symbols *) + type string_symbol + + (** Symbols *) + type symbol = S_Int of int_symbol | S_Str of string_symbol + + (** The kind of the symbol (int or string) *) val kind : symbol -> Z3enums.symbol_kind + + (** Indicates whether the symbol is of Int kind *) val is_int_symbol : symbol -> bool + + (** Indicates whether the symbol is of string kind. *) val is_string_symbol : symbol -> bool + + (** The int value of the symbol. *) val get_int : int_symbol -> int + + (** The string value of the symbol. *) val get_string : string_symbol -> string + + (** A string representation of the symbol. *) val to_string : symbol -> string + + (** + 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. + *) val mk_int : context -> int -> symbol + + (** Creates a new symbol using a string. *) val mk_string : context -> string -> symbol + + (** Create an array of symbols. *) val mk_ints : context -> int array -> symbol array + + (** Create an array of symbols. *) val mk_strings : context -> string array -> symbol array end +(** The abstract syntax tree (AST) module *) module AST : sig + type ast + (** Vectors of ASTs *) module ASTVector : sig + type ast_vector + + (** The size of the vector *) val get_size : ast_vector -> int - val get : ast_vector -> int -> ast_vector + + (** + Retrieves the i-th object in the vector. + @param i Index + @return An AST + *) + val get : ast_vector -> int -> ast + + (** Sets the i-th object in the vector. *) val set : ast_vector -> int -> ast -> unit + + (** Resize the vector to . + @param newSize The new size of the vector. *) val resize : ast_vector -> int -> unit + + (** + Add the AST to the back of the vector. The size + is increased by 1. + @param a An AST + *) val push : ast_vector -> ast -> unit + + (** + Translates all ASTs in the vector to . + @param to_ctx A context + @return A new ASTVector + *) val translate : ast_vector -> context -> ast_vector + + (** Retrieves a string representation of the vector. *) val to_string : ast_vector -> string end + (** Map from AST to AST *) module ASTMap : sig + type ast_map + + (** Checks whether the map contains the key . + @param k An AST + @return True if is a key in the map, false otherwise. *) val contains : ast_map -> ast -> bool - val find : ast_map -> ast -> ast_map + + (** Finds the value associated with the key . + + This function signs an error when is not a key in the map. + @param k An AST + *) + val find : ast_map -> ast -> ast + + (** + Stores or replaces a new key/value pair in the map. + @param k The key AST + @param v The value AST + *) val insert : ast_map -> ast -> ast -> unit + + (** + Erases the key from the map. + @param k An AST + *) val erase : ast_map -> ast -> unit + + (** Removes all keys from the map. *) val reset : ast_map -> unit + + (** The size of the map *) val get_size : ast_map -> int - val get_keys : ast_map -> ast_vector + + (** The keys stored in the map. *) + val get_keys : ast_map -> ASTVector.ast_vector + + (** Retrieves a string representation of the map.*) val to_string : ast_map -> string end + (** + The AST's hash code. + @return A hash code + *) val get_hash_code : ast -> int + + (** A unique identifier for the AST (unique among all ASTs). *) val get_id : ast -> int + + (** The kind of the AST. *) val get_ast_kind : ast -> Z3enums.ast_kind + + (** Indicates whether the AST is an Expr *) val is_expr : ast -> bool + + (** Indicates whether the AST is a bound variable*) val is_var : ast -> bool + + (** Indicates whether the AST is a Quantifier *) val is_quantifier : ast -> bool + + (** Indicates whether the AST is a Sort *) val is_sort : ast -> bool + + (** Indicates whether the AST is a func_decl *) val is_func_decl : ast -> bool + + (** A string representation of the AST. *) val to_string : ast -> string + + (** A string representation of the AST in s-expression notation. *) val to_sexpr : ast -> string + + (** + Comparison operator. + @param a An AST + @param b An AST + @return True if and are from the same context + and represent the same sort; false otherwise. + *) val ( = ) : ast -> ast -> bool + + (** + Object Comparison. + @param other Another ast + @return Negative if the object should be sorted before , positive if after else zero. + *) val compare : ast -> ast -> int + + (** Operator < *) val ( < ) : ast -> ast -> int + + (** + Translates (copies) the AST to the Context . + @param ctx A context + @return A copy of the AST which is associated with + *) val translate : ast -> context -> ast + + (** + 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., + . + + @param nativeObject The native pointer to wrap. + *) val wrap : context -> Z3native.z3_ast -> ast + + (** + 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., + ). + + @param a The AST to unwrap. + *) val unwrap_ast : ast -> Z3native.ptr end +(** The Sort module implements type information for ASTs *) module Sort : sig + (** Sorts *) + type sort = Sort of AST.ast + + (** Uninterpreted Sorts *) + type uninterpreted_sort = UninterpretedSort of sort + + val ast_of_sort : sort -> AST.ast + val sort_of_uninterpreted_sort : uninterpreted_sort -> sort + val uninterpreted_sort_of_sort : sort -> uninterpreted_sort + + (** + Comparison operator. + @param a A sort + @param b A sort + @return True if and are from the same context + and represent the same sort; false otherwise. + *) val ( = ) : sort -> sort -> bool + + (** Returns a unique identifier for the sort. *) val get_id : sort -> int + + (** The kind of the sort. *) val get_sort_kind : sort -> Z3enums.sort_kind - val get_name : sort -> symbol + + (** The name of the sort *) + val get_name : sort -> Symbol.symbol + + (** A string representation of the sort. *) val to_string : sort -> string - val mk_uninterpreted : context -> symbol -> uninterpreted_sort + + (** Create a new uninterpreted sort. *) + val mk_uninterpreted : context -> Symbol.symbol -> uninterpreted_sort + + (** Create a new uninterpreted sort. *) val mk_uninterpreted_s : context -> string -> uninterpreted_sort end -module FuncDecl : +(** Function declarations *) +module rec FuncDecl : sig + type func_decl = FuncDecl of AST.ast + val ast_of_func_decl : FuncDecl.func_decl -> AST.ast + + (** Parameters of Func_Decls *) module Parameter : sig + (** Parameters of func_decls *) + type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + (** The kind of the parameter. *) val get_kind : parameter -> Z3enums.parameter_kind + + (** The int value of the parameter.*) val get_int : parameter -> int + + (** The double value of the parameter.*) val get_float : parameter -> float - val get_symbol : parameter -> symbol - val get_sort : parameter -> sort - val get_ast : parameter -> ast - val get_func_decl : parameter -> string + + (** The Symbol.Symbol value of the parameter.*) + val get_symbol : parameter -> Symbol.symbol + + (** The Sort value of the parameter.*) + val get_sort : parameter -> Sort.sort + + (** The AST value of the parameter.*) + val get_ast : parameter -> AST.ast + + (** The FunctionDeclaration value of the parameter.*) + val get_func_decl : parameter -> func_decl + + (** The rational string value of the parameter.*) + val get_rational : parameter -> string end - val mk_func_decl : context -> symbol -> sort array -> sort -> func_decl - val mk_func_decl_s : context -> string -> sort array -> sort -> func_decl - val mk_fresh_func_decl : context -> string -> sort array -> sort -> func_decl - val mk_const_decl : context -> symbol -> sort -> func_decl - val mk_const_decl_s : context -> string -> sort -> func_decl - val mk_fresh_const_decl : context -> string -> sort -> func_decl + (** Creates a new function declaration. *) + val mk_func_decl : context -> Symbol.symbol -> Sort.sort array -> Sort.sort -> func_decl + + (** Creates a new function declaration. *) + val mk_func_decl_s : context -> string -> Sort.sort array -> Sort.sort -> func_decl + (** Creates a fresh function declaration with a name prefixed with . + + *) + + val mk_fresh_func_decl : context -> string -> Sort.sort array -> Sort.sort -> func_decl + + (** Creates a new constant function declaration. *) + val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl + + (** Creates a new constant function declaration. *) + val mk_const_decl_s : context -> string -> Sort.sort -> func_decl + + (** Creates a fresh constant function declaration with a name prefixed with . + + *) + val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl + + (** Comparison operator. + @param a A func_decl + @param b A func_decl + @return True if and are from the same context + and represent the same func_decl; false otherwise. *) val ( = ) : func_decl -> func_decl -> bool + + (** A string representations of the function declaration. *) val to_string : func_decl -> string + + (** Returns a unique identifier for the function declaration. *) val get_id : func_decl -> int + + (** The arity of the function declaration *) val get_arity : func_decl -> int + + (** The size of the domain of the function declaration + *) val get_domain_size : func_decl -> int - val get_domain : func_decl -> sort array - val get_range : func_decl -> sort + + (** The domain of the function declaration *) + val get_domain : func_decl -> Sort.sort array + + (** The range of the function declaration *) + val get_range : func_decl -> Sort.sort + + (** The kind of the function declaration. *) val get_decl_kind : func_decl -> Z3enums.decl_kind - val get_name : func_decl -> symbol + + (** The name of the function declaration*) + val get_name : func_decl -> Symbol.symbol + + (** The number of parameters of the function declaration *) val get_num_parameters : func_decl -> int - val get_parameters : func_decl -> parameter list - val apply : func_decl -> expr array -> expr + + (** The parameters of the function declaration *) + val get_parameters : func_decl -> Parameter.parameter list + + (** Create expression that applies function to arguments. + @param args The arguments *) + val apply : func_decl -> Expr.expr array -> Expr.expr end -module Params : -sig +(** Parameter sets (of Solvers, Tactics, ...) + A Params objects represents a configuration in the form of Symbol.symbol/value pairs. *) +and Params : +sig + type params + + (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) module ParamDescrs : sig + type param_descrs + + (** Validate a set of parameters. *) val validate : param_descrs -> params -> unit - val get_kind : param_descrs -> symbol -> Z3enums.param_kind - val get_names : param_descrs -> symbol array + + (** Retrieve kind of parameter. *) + val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind + + (** Retrieve all names of parameters. *) + val get_names : param_descrs -> Symbol.symbol array + + (** The size of the ParamDescrs. *) val get_size : param_descrs -> int + + (** Retrieves a string representation of the ParamDescrs. *) val to_string : param_descrs -> string end - val add_bool : params -> symbol -> bool -> unit - val add_int : params -> symbol -> int -> unit - val add_double : params -> symbol -> float -> unit - val add_symbol : params -> symbol -> symbol -> unit + (** Adds a parameter setting. *) + val add_bool : params -> Symbol.symbol -> bool -> unit + + (** Adds a parameter setting. *) + val add_int : params -> Symbol.symbol -> int -> unit + + (** Adds a parameter setting. *) + val add_double : params -> Symbol.symbol -> float -> unit + + (** Adds a parameter setting. *) + val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit + + (** Adds a parameter setting. *) val add_s_bool : params -> string -> bool -> unit + + (** Adds a parameter setting. *) val add_s_int : params -> string -> int -> unit + + (** Adds a parameter setting. *) val add_s_double : params -> string -> float -> unit - val add_s_symbol : params -> string -> symbol -> unit + + (** Adds a parameter setting. *) + val add_s_symbol : params -> string -> Symbol.symbol -> unit + + (** Creates a new parameter set *) val mk_params : context -> params + + (** A string representation of the parameter set. *) val to_string : params -> string end -module Expr : +and Expr : sig - val simplify : expr -> params option -> expr + (** General Expressions (Terms) *) + type expr = Expr of AST.ast + + val ast_of_expr : Expr.expr -> AST.ast + val expr_of_ast : AST.ast -> Expr.expr + + val simplify : Expr.expr -> Params.params option -> expr val get_simplify_help : context -> string - val get_simplify_parameter_descrs : context -> param_descrs - val get_func_decl : expr -> func_decl - val get_bool_value : expr -> Z3enums.lbool - val get_num_args : expr -> int - val get_args : expr -> expr array - val update : expr -> expr array -> expr - val substitute : expr -> expr array -> expr array -> expr - val substitute_one : expr -> expr -> expr -> expr - val substitute_vars : expr -> expr array -> expr - val translate : expr -> context -> expr - val to_string : expr -> string - val is_numeral : expr -> bool - val is_well_sorted : expr -> bool - val get_sort : expr -> sort - val is_bool : expr -> bool - val is_const : expr -> bool - val is_true : expr -> bool - val is_false : expr -> bool - val is_eq : expr -> bool - val is_distinct : expr -> bool - val is_ite : expr -> bool - val is_and : expr -> bool - val is_or : expr -> bool - val is_iff : expr -> bool - val is_xor : expr -> bool - val is_not : expr -> bool - val is_implies : expr -> bool - val is_label : expr -> bool - val is_oeq : expr -> bool - val mk_const : context -> symbol -> sort -> expr - val mk_const_s : context -> string -> sort -> expr - val mk_const_f : context -> func_decl -> expr - val mk_fresh_const : context -> string -> sort -> expr - val mk_app : context -> func_decl -> expr array -> expr - val mk_numeral_string : context -> string -> sort -> expr - val mk_numeral_int : context -> int -> sort -> expr + val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs + val get_func_decl : Expr.expr -> FuncDecl.func_decl + val get_bool_value : Expr.expr -> Z3enums.lbool + val get_num_args : Expr.expr -> int + val get_args : Expr.expr -> Expr.expr array + val update : Expr.expr -> Expr.expr array -> expr + val substitute : Expr.expr -> Expr.expr array -> Expr.expr array -> expr + val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr + val substitute_vars : Expr.expr -> Expr.expr array -> expr + val translate : Expr.expr -> context -> expr + val to_string : Expr.expr -> string + val is_numeral : Expr.expr -> bool + val is_well_sorted : Expr.expr -> bool + val get_sort : Expr.expr -> Sort.sort + val is_bool : Expr.expr -> bool + val is_const : Expr.expr -> bool + val is_true : Expr.expr -> bool + val is_false : Expr.expr -> bool + val is_eq : Expr.expr -> bool + val is_distinct : Expr.expr -> bool + val is_ite : Expr.expr -> bool + val is_and : Expr.expr -> bool + val is_or : Expr.expr -> bool + val is_iff : Expr.expr -> bool + val is_xor : Expr.expr -> bool + val is_not : Expr.expr -> bool + val is_implies : Expr.expr -> bool + val is_label : Expr.expr -> bool + val is_oeq : Expr.expr -> bool + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + val mk_const_s : context -> string -> Sort.sort -> expr + val mk_const_f : context -> FuncDecl.func_decl -> expr + val mk_fresh_const : context -> string -> Sort.sort -> expr + val mk_app : context -> FuncDecl.func_decl -> Expr.expr array -> expr + val mk_numeral_string : context -> string -> Sort.sort -> expr + val mk_numeral_int : context -> int -> Sort.sort -> expr end module Boolean : sig + type bool_sort = BoolSort of Sort.sort + type bool_expr = BoolExpr of Expr.expr + + val expr_of_bool_expr : bool_expr -> Expr.expr + val sort_of_bool_sort : bool_sort -> Sort.sort + val bool_sort_of_sort : Sort.sort -> bool_sort + val bool_expr_of_expr : Expr.expr -> bool_expr + val mk_sort : context -> bool_sort - val mk_const : context -> symbol -> bool_expr + val mk_const : context -> Symbol.symbol -> bool_expr val mk_const_s : context -> string -> bool_expr val mk_true : context -> bool_expr val mk_false : context -> bool_expr val mk_val : context -> bool -> bool_expr - val mk_eq : context -> expr -> expr -> bool_expr - val mk_distinct : context -> expr array -> bool_expr + val mk_eq : context -> Expr.expr -> Expr.expr -> bool_expr + val mk_distinct : context -> Expr.expr array -> bool_expr val mk_not : context -> bool_expr -> bool_expr val mk_ite : context -> bool_expr -> bool_expr -> bool_expr -> bool_expr val mk_iff : context -> bool_expr -> bool_expr -> bool_expr @@ -345,482 +578,590 @@ end module Quantifier : sig + type quantifier = Quantifier of Expr.expr + + val expr_of_quantifier : quantifier -> Expr.expr + val quantifier_of_expr : Expr.expr -> quantifier + module Pattern : sig + type pattern = Pattern of AST.ast + + val ast_of_pattern : pattern -> AST.ast + val pattern_of_ast : AST.ast -> pattern + val get_num_terms : pattern -> int - val get_terms : pattern -> expr array + val get_terms : pattern -> Expr.expr array val to_string : pattern -> string end - val get_index : expr -> int + val get_index : Expr.expr -> int val is_universal : quantifier -> bool val is_existential : quantifier -> bool val get_weight : quantifier -> int val get_num_patterns : quantifier -> int - val get_patterns : quantifier -> pattern array + val get_patterns : quantifier -> Pattern.pattern array val get_num_no_patterns : quantifier -> int - val get_no_patterns : quantifier -> pattern array + val get_no_patterns : quantifier -> Pattern.pattern array val get_num_bound : quantifier -> int - val get_bound_variable_names : quantifier -> symbol array - val get_bound_variable_sorts : quantifier -> sort array - val get_body : quantifier -> bool_expr - val mk_bound : context -> int -> sort -> expr - val mk_pattern : context -> expr array -> pattern + val get_bound_variable_names : quantifier -> Symbol.symbol array + val get_bound_variable_sorts : quantifier -> Sort.sort array + val get_body : quantifier -> Boolean.bool_expr + val mk_bound : context -> int -> Sort.sort -> Expr.expr + val mk_pattern : context -> Expr.expr array -> Pattern.pattern val mk_forall : context -> - sort array -> - symbol array -> - expr -> + Sort.sort array -> + Symbol.symbol array -> + Expr.expr -> int option -> - pattern array -> - expr array -> symbol option -> symbol option -> quantifier + Pattern.pattern array -> + Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier val mk_forall_const : context -> - expr array -> - expr -> + Expr.expr array -> + Expr.expr -> int option -> - pattern array -> - expr array -> symbol option -> symbol option -> quantifier + Pattern.pattern array -> + Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier val mk_exists : context -> - sort array -> - symbol array -> - expr -> + Sort.sort array -> + Symbol.symbol array -> + Expr.expr -> int option -> - pattern array -> - expr array -> symbol option -> symbol option -> quantifier + Pattern.pattern array -> + Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier val mk_exists_const : context -> - expr array -> - expr -> + Expr.expr array -> + Expr.expr -> int option -> - pattern array -> - expr array -> symbol option -> symbol option -> quantifier + Pattern.pattern array -> + Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier val mk_quantifier : context -> bool -> - expr array -> - expr -> + Expr.expr array -> + Expr.expr -> int option -> - pattern array -> - expr array -> symbol option -> symbol option -> quantifier + Pattern.pattern array -> + Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier end module Array_ : sig - val mk_sort : context -> sort -> sort -> array_sort - val is_store : expr -> bool - val is_select : expr -> bool - val is_constant_array : expr -> bool - val is_default_array : expr -> bool - val is_array_map : expr -> bool - val is_as_array : expr -> bool - val is_array : expr -> bool - val get_domain : array_sort -> sort - val get_range : array_sort -> sort - val mk_const : context -> symbol -> sort -> sort -> array_expr - val mk_const_s : context -> string -> sort -> sort -> array_expr - val mk_select : context -> array_expr -> expr -> expr -> expr - val mk_const_array : context -> sort -> expr -> expr - val mk_map : context -> func_decl -> array_expr array -> expr - val mk_term_array : context -> array_expr -> expr + type array_sort = ArraySort of Sort.sort + type array_expr = ArrayExpr of Expr.expr + + val sort_of_array_sort : array_sort -> Sort.sort + val array_sort_of_sort : Sort.sort -> array_sort + val expr_of_array_expr : array_expr -> Expr.expr + + val array_expr_of_expr : Expr.expr -> array_expr + + val mk_sort : context -> Sort.sort -> Sort.sort -> array_sort + val is_store : Expr.expr -> bool + val is_select : Expr.expr -> bool + val is_constant_array : Expr.expr -> bool + val is_default_array : Expr.expr -> bool + val is_array_map : Expr.expr -> bool + val is_as_array : Expr.expr -> bool + val is_array : Expr.expr -> bool + val get_domain : array_sort -> Sort.sort + val get_range : array_sort -> Sort.sort + val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> array_expr + val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> array_expr + val mk_select : context -> array_expr -> Expr.expr -> Expr.expr -> array_expr + val mk_const_array : context -> Sort.sort -> Expr.expr -> array_expr + val mk_map : context -> FuncDecl.func_decl -> array_expr array -> array_expr + val mk_term_array : context -> array_expr -> array_expr end module Set : sig - val is_union : expr -> bool - val is_intersect : expr -> bool - val is_difference : expr -> bool - val is_complement : expr -> bool - val is_subset : expr -> bool - val mk_sort : context -> sort -> set_sort - val mk_empty : context -> sort -> expr - val mk_full : context -> sort -> expr - val mk_set_add : context -> expr -> expr -> expr - val mk_del : context -> expr -> expr -> expr - val mk_union : context -> expr array -> expr - val mk_intersection : context -> expr array -> expr - val mk_difference : context -> expr -> expr -> expr - val mk_complement : context -> expr -> expr - val mk_membership : context -> expr -> expr -> expr - val mk_subset : context -> expr -> expr -> expr + type set_sort = SetSort of Sort.sort + + val sort_of_set_sort : set_sort -> Sort.sort + + val is_union : Expr.expr -> bool + val is_intersect : Expr.expr -> bool + val is_difference : Expr.expr -> bool + val is_complement : Expr.expr -> bool + val is_subset : Expr.expr -> bool + val mk_sort : context -> Sort.sort -> set_sort + val mk_empty : context -> Sort.sort -> Expr.expr + val mk_full : context -> Sort.sort -> Expr.expr + val mk_set_add : context -> Expr.expr -> Expr.expr -> Expr.expr + val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr + val mk_union : context -> Expr.expr array -> Expr.expr + val mk_intersection : context -> Expr.expr array -> Expr.expr + val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr + val mk_complement : context -> Expr.expr -> Expr.expr + val mk_membership : context -> Expr.expr -> Expr.expr -> Expr.expr + val mk_subset : context -> Expr.expr -> Expr.expr -> Expr.expr end module FiniteDomain : sig - val mk_sort : context -> symbol -> int -> finite_domain_sort + type finite_domain_sort = FiniteDomainSort of Sort.sort + + val sort_of_finite_domain_sort : finite_domain_sort -> Sort.sort + val finite_domain_sort_of_sort : Sort.sort -> finite_domain_sort + + val mk_sort : context -> Symbol.symbol -> int -> finite_domain_sort val mk_sort_s : context -> string -> int -> finite_domain_sort - val is_finite_domain : expr -> bool - val is_lt : expr -> bool + val is_finite_domain : Expr.expr -> bool + val is_lt : Expr.expr -> bool val get_size : finite_domain_sort -> int end module Relation : sig - val is_relation : expr -> bool - val is_store : expr -> bool - val is_empty : expr -> bool - val is_is_empty : expr -> bool - val is_join : expr -> bool - val is_union : expr -> bool - val is_widen : expr -> bool - val is_project : expr -> bool - val is_filter : expr -> bool - val is_negation_filter : expr -> bool - val is_rename : expr -> bool - val is_complement : expr -> bool - val is_select : expr -> bool - val is_clone : expr -> bool + type relation_sort = RelationSort of Sort.sort + + val sort_of_relation_sort : relation_sort -> Sort.sort + val relation_sort_of_sort : Sort.sort -> relation_sort + + val is_relation : Expr.expr -> bool + val is_store : Expr.expr -> bool + val is_empty : Expr.expr -> bool + val is_is_empty : Expr.expr -> bool + val is_join : Expr.expr -> bool + val is_union : Expr.expr -> bool + val is_widen : Expr.expr -> bool + val is_project : Expr.expr -> bool + val is_filter : Expr.expr -> bool + val is_negation_filter : Expr.expr -> bool + val is_rename : Expr.expr -> bool + val is_complement : Expr.expr -> bool + val is_select : Expr.expr -> bool + val is_clone : Expr.expr -> bool val get_arity : relation_sort -> int val get_column_sorts : relation_sort -> relation_sort array end module Datatype : sig + type datatype_sort = DatatypeSort of Sort.sort + type datatype_expr = DatatypeExpr of Expr.expr + + val sort_of_datatype_sort : datatype_sort -> Sort.sort + val datatype_sort_of_sort : Sort.sort -> datatype_sort + val expr_of_datatype_expr : datatype_expr -> Expr.expr + val datatype_expr_of_expr : Expr.expr -> datatype_expr module Constructor : sig + (** Constructors *) + type constructor + val get_n : constructor -> int - val constructor_decl : constructor -> func_decl - val tester_decl : constructor -> func_decl - val accessor_decls : constructor -> func_decl array + val constructor_decl : constructor -> FuncDecl.func_decl + val tester_decl : constructor -> FuncDecl.func_decl + val accessor_decls : constructor -> FuncDecl.func_decl array val get_num_fields : constructor -> int - val get_constructor_decl : constructor -> func_decl - val get_tester_decl : constructor -> func_decl - val get_accessor_decls : constructor -> func_decl array + val get_constructor_decl : constructor -> FuncDecl.func_decl + val get_tester_decl : constructor -> FuncDecl.func_decl + val get_accessor_decls : constructor -> FuncDecl.func_decl array end - val mk_constructor : context -> symbol -> symbol -> symbol array -> sort array -> int array -> constructor - val mk_constructor_s : context -> string -> symbol -> symbol array -> sort array -> int array -> constructor - val mk_sort : context -> symbol -> constructor array -> datatype_sort - val mk_sort_s : context -> string -> constructor array -> datatype_sort - val mk_sorts : context -> symbol array -> constructor array array -> datatype_sort array - val mk_sorts_s : context -> string array -> constructor array array -> datatype_sort array + val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> Constructor.constructor + val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> Constructor.constructor + val mk_sort : context -> Symbol.symbol -> Constructor.constructor array -> datatype_sort + val mk_sort_s : context -> string -> Constructor.constructor array -> datatype_sort + val mk_sorts : context -> Symbol.symbol array -> Constructor.constructor array array -> datatype_sort array + val mk_sorts_s : context -> string array -> Constructor.constructor array array -> datatype_sort array val get_num_constructors : datatype_sort -> int - val get_constructors : datatype_sort -> func_decl array - val get_recognizers : datatype_sort -> func_decl array - val get_accessors : datatype_sort -> func_decl array array + val get_constructors : datatype_sort -> FuncDecl.func_decl array + val get_recognizers : datatype_sort -> FuncDecl.func_decl array + val get_accessors : datatype_sort -> FuncDecl.func_decl array array end module Enumeration : sig - val mk_sort : context -> symbol -> symbol array -> enum_sort + type enum_sort = EnumSort of Sort.sort + + val sort_of_enum_sort : enum_sort -> Sort.sort + + val mk_sort : context -> Symbol.symbol -> Symbol.symbol array -> enum_sort val mk_sort_s : context -> string -> string array -> enum_sort - val get_const_decls : enum_sort -> func_decl array - val get_tester_decls : enum_sort -> func_decl array + val get_const_decls : enum_sort -> FuncDecl.func_decl array + val get_tester_decls : enum_sort -> FuncDecl.func_decl array end module List_ : sig - val mk_sort : context -> symbol -> sort -> list_sort - val mk_list_s : context -> string -> sort -> list_sort - val get_nil_decl : list_sort -> func_decl - val get_is_nil_decl : list_sort -> func_decl - val get_cons_decl : list_sort -> func_decl - val get_is_cons_decl : list_sort -> func_decl - val get_head_decl : list_sort -> func_decl - val get_tail_decl : list_sort -> func_decl - val nil : list_sort -> expr + type list_sort = ListSort of Sort.sort + + val sort_of_list_sort : list_sort -> Sort.sort + + val mk_sort : context -> Symbol.symbol -> Sort.sort -> list_sort + val mk_list_s : context -> string -> Sort.sort -> list_sort + val get_nil_decl : list_sort -> FuncDecl.func_decl + val get_is_nil_decl : list_sort -> FuncDecl.func_decl + val get_cons_decl : list_sort -> FuncDecl.func_decl + val get_is_cons_decl : list_sort -> FuncDecl.func_decl + val get_head_decl : list_sort -> FuncDecl.func_decl + val get_tail_decl : list_sort -> FuncDecl.func_decl + val nil : list_sort -> Expr.expr end module Tuple : sig - val mk_sort : - context -> symbol -> symbol array -> sort array -> tuple_sort - val get_mk_decl : tuple_sort -> func_decl + type tuple_sort = TupleSort of Sort.sort + + val sort_of_tuple_sort : tuple_sort -> Sort.sort + + val mk_sort : context -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> tuple_sort + val get_mk_decl : tuple_sort -> FuncDecl.func_decl val get_num_fields : tuple_sort -> int - val get_field_decls : tuple_sort -> func_decl array + val get_field_decls : tuple_sort -> FuncDecl.func_decl array end -module Arithmetic : +module rec Arithmetic : sig + type arith_sort = ArithSort of Sort.sort + type arith_expr = ArithExpr of Expr.expr - module Integer : + val sort_of_arith_sort : Arithmetic.arith_sort -> Sort.sort + val arith_sort_of_sort : Sort.sort -> Arithmetic.arith_sort + val expr_of_arith_expr : Arithmetic.arith_expr -> Expr.expr + val arith_expr_of_expr : Expr.expr -> Arithmetic.arith_expr + + module rec Integer : sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val arith_sort_of_int_sort : Arithmetic.Integer.int_sort -> Arithmetic.arith_sort + val int_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Integer.int_sort + val arith_expr_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.arith_expr + val int_expr_of_int_num : Arithmetic.Integer.int_num -> Arithmetic.Integer.int_expr + val int_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Integer.int_expr + val int_num_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.Integer.int_num + val mk_sort : context -> int_sort val get_int : int_num -> int val to_string : int_num -> string - val mk_int_const : context -> symbol -> int_expr + val mk_int_const : context -> Symbol.symbol -> int_expr val mk_int_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> expr - val mk_rem : context -> int_expr -> int_expr -> expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr val mk_int_numeral_s : context -> string -> int_num val mk_int_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> real_expr - val mk_int2bv : context -> int -> int_expr -> bitvec_expr + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr end - module Real : + and Real : sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort + val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort + val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr + val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr + val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr + val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num + val mk_sort : context -> real_sort - val get_numerator : rat_num -> int_num - val get_denominator : rat_num -> int_num + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num val to_decimal_string : rat_num -> int -> string val to_string : rat_num -> string - val mk_real_const : context -> symbol -> real_expr + val mk_real_const : context -> Symbol.symbol -> real_expr val mk_real_const_s : context -> string -> real_expr val mk_numeral_nd : context -> int -> int -> rat_num val mk_numeral_s : context -> string -> rat_num val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> bool_expr - val mk_real2int : context -> real_expr -> int_expr + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr end - module AlgebraicNumber : + and AlgebraicNumber : sig - val to_upper : algebraic_num -> int -> rat_num - val to_lower : algebraic_num -> int -> rat_num + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : Arithmetic.AlgebraicNumber.algebraic_num -> Arithmetic.arith_expr + val algebraic_num_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.AlgebraicNumber.algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num val to_decimal_string : algebraic_num -> int -> string val to_string : algebraic_num -> string end - val is_int : expr -> bool - val is_arithmetic_numeral : expr -> bool - val is_le : expr -> bool - val is_ge : expr -> bool - val is_lt : expr -> bool - val is_gt : expr -> bool - val is_add : expr -> bool - val is_sub : expr -> bool - val is_uminus : expr -> bool - val is_mul : expr -> bool - val is_div : expr -> bool - val is_idiv : expr -> bool - val is_remainder : expr -> bool - val is_modulus : expr -> bool - val is_inttoreal : expr -> bool - val is_real_to_int : expr -> bool - val is_real_is_int : expr -> bool - val is_real : expr -> bool - val is_int_numeral : expr -> bool - val is_rat_num : expr -> bool - val is_algebraic_number : expr -> bool + val is_int : Expr.expr -> bool + val is_arithmetic_numeral : Expr.expr -> bool + val is_le : Expr.expr -> bool + val is_ge : Expr.expr -> bool + val is_lt : Expr.expr -> bool + val is_gt : Expr.expr -> bool + val is_add : Expr.expr -> bool + val is_sub : Expr.expr -> bool + val is_uminus : Expr.expr -> bool + val is_mul : Expr.expr -> bool + val is_div : Expr.expr -> bool + val is_idiv : Expr.expr -> bool + val is_remainder : Expr.expr -> bool + val is_modulus : Expr.expr -> bool + val is_inttoreal : Expr.expr -> bool + val is_real_to_int : Expr.expr -> bool + val is_real_is_int : Expr.expr -> bool + val is_real : Expr.expr -> bool + val is_int_numeral : Expr.expr -> bool + val is_rat_num : Expr.expr -> bool + val is_algebraic_number : Expr.expr -> bool val mk_add : context -> arith_expr array -> arith_expr val mk_mul : context -> arith_expr array -> arith_expr val mk_sub : context -> arith_expr array -> arith_expr val mk_unary_minus : context -> arith_expr -> arith_expr val mk_div : context -> arith_expr -> arith_expr -> arith_expr val mk_power : context -> arith_expr -> arith_expr -> arith_expr - val mk_lt : context -> arith_expr -> arith_expr -> bool_expr - val mk_le : context -> arith_expr -> arith_expr -> bool_expr - val mk_gt : context -> arith_expr -> arith_expr -> bool_expr - val mk_ge : context -> arith_expr -> arith_expr -> bool_expr + val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr end -module BitVector : +and BitVector : sig + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort + val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort + val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr + val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr + val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr + val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num + val mk_sort : context -> int -> bitvec_sort - val is_bv : expr -> bool - val is_bv_numeral : expr -> bool - val is_bv_bit1 : expr -> bool - val is_bv_bit0 : expr -> bool - val is_bv_uminus : expr -> bool - val is_bv_add : expr -> bool - val is_bv_sub : expr -> bool - val is_bv_mul : expr -> bool - val is_bv_sdiv : expr -> bool - val is_bv_udiv : expr -> bool - val is_bv_SRem : expr -> bool - val is_bv_urem : expr -> bool - val is_bv_smod : expr -> bool - val is_bv_sdiv0 : expr -> bool - val is_bv_udiv0 : expr -> bool - val is_bv_srem0 : expr -> bool - val is_bv_urem0 : expr -> bool - val is_bv_smod0 : expr -> bool - val is_bv_ule : expr -> bool - val is_bv_sle : expr -> bool - val is_bv_uge : expr -> bool - val is_bv_sge : expr -> bool - val is_bv_ult : expr -> bool - val is_bv_slt : expr -> bool - val is_bv_ugt : expr -> bool - val is_bv_sgt : expr -> bool - val is_bv_and : expr -> bool - val is_bv_or : expr -> bool - val is_bv_not : expr -> bool - val is_bv_xor : expr -> bool - val is_bv_nand : expr -> bool - val is_bv_nor : expr -> bool - val is_bv_xnor : expr -> bool - val is_bv_concat : expr -> bool - val is_bv_signextension : expr -> bool - val is_bv_zeroextension : expr -> bool - val is_bv_extract : expr -> bool - val is_bv_repeat : expr -> bool - val is_bv_reduceor : expr -> bool - val is_bv_reduceand : expr -> bool - val is_bv_comp : expr -> bool - val is_bv_shiftleft : expr -> bool - val is_bv_shiftrightlogical : expr -> bool - val is_bv_shiftrightarithmetic : expr -> bool - val is_bv_rotateleft : expr -> bool - val is_bv_rotateright : expr -> bool - val is_bv_rotateleftextended : expr -> bool - val is_bv_rotaterightextended : expr -> bool - val is_int_to_bv : expr -> bool - val is_bv_to_int : expr -> bool - val is_bv_carry : expr -> bool - val is_bv_xor3 : expr -> bool + val is_bv : Expr.expr -> bool + val is_bv_numeral : Expr.expr -> bool + val is_bv_bit1 : Expr.expr -> bool + val is_bv_bit0 : Expr.expr -> bool + val is_bv_uminus : Expr.expr -> bool + val is_bv_add : Expr.expr -> bool + val is_bv_sub : Expr.expr -> bool + val is_bv_mul : Expr.expr -> bool + val is_bv_sdiv : Expr.expr -> bool + val is_bv_udiv : Expr.expr -> bool + val is_bv_SRem : Expr.expr -> bool + val is_bv_urem : Expr.expr -> bool + val is_bv_smod : Expr.expr -> bool + val is_bv_sdiv0 : Expr.expr -> bool + val is_bv_udiv0 : Expr.expr -> bool + val is_bv_srem0 : Expr.expr -> bool + val is_bv_urem0 : Expr.expr -> bool + val is_bv_smod0 : Expr.expr -> bool + val is_bv_ule : Expr.expr -> bool + val is_bv_sle : Expr.expr -> bool + val is_bv_uge : Expr.expr -> bool + val is_bv_sge : Expr.expr -> bool + val is_bv_ult : Expr.expr -> bool + val is_bv_slt : Expr.expr -> bool + val is_bv_ugt : Expr.expr -> bool + val is_bv_sgt : Expr.expr -> bool + val is_bv_and : Expr.expr -> bool + val is_bv_or : Expr.expr -> bool + val is_bv_not : Expr.expr -> bool + val is_bv_xor : Expr.expr -> bool + val is_bv_nand : Expr.expr -> bool + val is_bv_nor : Expr.expr -> bool + val is_bv_xnor : Expr.expr -> bool + val is_bv_concat : Expr.expr -> bool + val is_bv_signextension : Expr.expr -> bool + val is_bv_zeroextension : Expr.expr -> bool + val is_bv_extract : Expr.expr -> bool + val is_bv_repeat : Expr.expr -> bool + val is_bv_reduceor : Expr.expr -> bool + val is_bv_reduceand : Expr.expr -> bool + val is_bv_comp : Expr.expr -> bool + val is_bv_shiftleft : Expr.expr -> bool + val is_bv_shiftrightlogical : Expr.expr -> bool + val is_bv_shiftrightarithmetic : Expr.expr -> bool + val is_bv_rotateleft : Expr.expr -> bool + val is_bv_rotateright : Expr.expr -> bool + val is_bv_rotateleftextended : Expr.expr -> bool + val is_bv_rotaterightextended : Expr.expr -> bool + val is_int_to_bv : Expr.expr -> bool + val is_bv_to_int : Expr.expr -> bool + val is_bv_carry : Expr.expr -> bool + val is_bv_xor3 : Expr.expr -> bool val get_size : bitvec_sort -> int val get_int : bitvec_num -> int val to_string : bitvec_num -> string - val mk_const : context -> symbol -> int -> bitvec_expr + val mk_const : context -> Symbol.symbol -> int -> bitvec_expr val mk_const_s : context -> string -> int -> bitvec_expr - val mk_not : context -> bitvec_expr -> expr - val mk_redand : context -> bitvec_expr -> expr - val mk_redor : context -> bitvec_expr -> expr - val mk_and : context -> bitvec_expr -> bitvec_expr -> expr - val mk_or : context -> bitvec_expr -> bitvec_expr -> expr - val mk_xor : context -> bitvec_expr -> bitvec_expr -> expr - val mk_nand : context -> bitvec_expr -> bitvec_expr -> expr - val mk_nor : context -> bitvec_expr -> bitvec_expr -> expr - val mk_xnor : context -> bitvec_expr -> bitvec_expr -> expr - val mk_neg : context -> bitvec_expr -> expr - val mk_add : context -> bitvec_expr -> bitvec_expr -> expr - val mk_sub : context -> bitvec_expr -> bitvec_expr -> expr - val mk_mul : context -> bitvec_expr -> bitvec_expr -> expr - val mk_udiv : context -> bitvec_expr -> bitvec_expr -> expr - val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> expr - val mk_urem : context -> bitvec_expr -> bitvec_expr -> expr - val mk_srem : context -> bitvec_expr -> bitvec_expr -> expr - val mk_smod : context -> bitvec_expr -> bitvec_expr -> expr - val mk_ult : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_slt : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_ule : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_sle : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_uge : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_sge : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_ugt : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_sgt : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_concat : context -> bitvec_expr -> bitvec_expr -> expr - val mk_extract : context -> int -> int -> bitvec_expr -> expr - val mk_sign_ext : context -> int -> bitvec_expr -> expr - val mk_zero_ext : context -> int -> bitvec_expr -> expr - val mk_repeat : context -> int -> bitvec_expr -> expr - val mk_shl : context -> bitvec_expr -> bitvec_expr -> expr - val mk_lshr : context -> bitvec_expr -> bitvec_expr -> expr - val mk_ashr : context -> bitvec_expr -> bitvec_expr -> expr - val mk_rotate_left : context -> bitvec_expr -> bitvec_expr -> expr - val mk_rotate_right : context -> bitvec_expr -> bitvec_expr -> expr - val mk_bv2int : context -> bitvec_expr -> bool -> int_expr - val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> bool_expr - val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> bool_expr - val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool_expr - val mk_neg_no_overflow : context -> bitvec_expr -> bool_expr - val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> bool_expr - val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool_expr + val mk_not : context -> bitvec_expr -> Expr.expr + val mk_redand : context -> bitvec_expr -> Expr.expr + val mk_redor : context -> bitvec_expr -> Expr.expr + val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_neg : context -> bitvec_expr -> bitvec_expr + val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr val mk_numeral : context -> string -> int -> bitvec_num end module Proof : sig - val is_true : expr -> bool - val is_asserted : expr -> bool - val is_goal : expr -> bool - val is_modus_ponens : expr -> bool - val is_reflexivity : expr -> bool - val is_symmetry : expr -> bool - val is_transitivity : expr -> bool - val is_Transitivity_star : expr -> bool - val is_monotonicity : expr -> bool - val is_quant_intro : expr -> bool - val is_distributivity : expr -> bool - val is_and_elimination : expr -> bool - val is_or_elimination : expr -> bool - val is_rewrite : expr -> bool - val is_rewrite_star : expr -> bool - val is_pull_quant : expr -> bool - val is_pull_quant_star : expr -> bool - val is_push_quant : expr -> bool - val is_elim_unused_vars : expr -> bool - val is_der : expr -> bool - val is_quant_inst : expr -> bool - val is_hypothesis : expr -> bool - val is_lemma : expr -> bool - val is_unit_resolution : expr -> bool - val is_iff_true : expr -> bool - val is_iff_false : expr -> bool - val is_commutativity : expr -> bool - val is_def_axiom : expr -> bool - val is_def_intro : expr -> bool - val is_apply_def : expr -> bool - val is_iff_oeq : expr -> bool - val is_nnf_pos : expr -> bool - val is_nnf_neg : expr -> bool - val is_nnf_star : expr -> bool - val is_cnf_star : expr -> bool - val is_skolemize : expr -> bool - val is_modus_ponens_oeq : expr -> bool - val is_theory_lemma : expr -> bool + val is_true : Expr.expr -> bool + val is_asserted : Expr.expr -> bool + val is_goal : Expr.expr -> bool + val is_modus_ponens : Expr.expr -> bool + val is_reflexivity : Expr.expr -> bool + val is_symmetry : Expr.expr -> bool + val is_transitivity : Expr.expr -> bool + val is_Transitivity_star : Expr.expr -> bool + val is_monotonicity : Expr.expr -> bool + val is_quant_intro : Expr.expr -> bool + val is_distributivity : Expr.expr -> bool + val is_and_elimination : Expr.expr -> bool + val is_or_elimination : Expr.expr -> bool + val is_rewrite : Expr.expr -> bool + val is_rewrite_star : Expr.expr -> bool + val is_pull_quant : Expr.expr -> bool + val is_pull_quant_star : Expr.expr -> bool + val is_push_quant : Expr.expr -> bool + val is_elim_unused_vars : Expr.expr -> bool + val is_der : Expr.expr -> bool + val is_quant_inst : Expr.expr -> bool + val is_hypothesis : Expr.expr -> bool + val is_lemma : Expr.expr -> bool + val is_unit_resolution : Expr.expr -> bool + val is_iff_true : Expr.expr -> bool + val is_iff_false : Expr.expr -> bool + val is_commutativity : Expr.expr -> bool + val is_def_axiom : Expr.expr -> bool + val is_def_intro : Expr.expr -> bool + val is_apply_def : Expr.expr -> bool + val is_iff_oeq : Expr.expr -> bool + val is_nnf_pos : Expr.expr -> bool + val is_nnf_neg : Expr.expr -> bool + val is_nnf_star : Expr.expr -> bool + val is_cnf_star : Expr.expr -> bool + val is_skolemize : Expr.expr -> bool + val is_modus_ponens_oeq : Expr.expr -> bool + val is_theory_lemma : Expr.expr -> bool end + module Goal : sig + type goal + val get_precision : goal -> Z3enums.goal_prec val is_precise : goal -> bool val is_underapproximation : goal -> bool val is_overapproximation : goal -> bool val is_garbage : goal -> bool - val assert_ : goal -> bool_expr array -> unit + val assert_ : goal -> Boolean.bool_expr array -> unit val is_inconsistent : goal -> bool val get_depth : goal -> int val reset : goal -> unit val get_size : goal -> int - val get_formulas : goal -> bool_expr array + val get_formulas : goal -> Boolean.bool_expr array val get_num_exprs : goal -> int val is_decided_sat : goal -> bool val is_decided_unsat : goal -> bool val translate : goal -> context -> goal - val simplify : goal -> params option -> goal + val simplify : goal -> Params.params option -> goal val mk_goal : context -> bool -> bool -> bool -> goal val to_string : goal -> string end module Model : sig + type model module FuncInterp : sig - + type func_interp + module FuncEntry : sig - val get_value : func_entry -> expr + type func_entry + + val get_value : func_entry -> Expr.expr val get_num_args : func_entry -> int - val get_args : func_entry -> expr array + val get_args : func_entry -> Expr.expr array val to_string : func_entry -> string end val get_num_entries : func_interp -> int - val get_entries : func_interp -> func_entry array - val get_else : func_interp -> expr + val get_entries : func_interp -> FuncEntry.func_entry array + val get_else : func_interp -> Expr.expr val get_arity : func_interp -> int val to_string : func_interp -> string end - val get_const_interp : model -> func_decl -> expr option - val get_const_interp_e : model -> expr -> expr option - val get_func_interp : model -> func_decl -> func_interp option + val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option + val get_const_interp_e : model -> Expr.expr -> Expr.expr option + val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option val get_num_consts : model -> int - val get_const_decls : model -> func_decl array + val get_const_decls : model -> FuncDecl.func_decl array val get_num_funcs : model -> int - val get_func_decls : model -> func_decl array - val get_decls : model -> func_decl array + val get_func_decls : model -> FuncDecl.func_decl array + val get_decls : model -> FuncDecl.func_decl array exception ModelEvaluationFailedException of string - val eval : model -> expr -> bool -> expr - val evaluate : model -> expr -> bool -> expr + val eval : model -> Expr.expr -> bool -> Expr.expr + val evaluate : model -> Expr.expr -> bool -> Expr.expr val get_num_sorts : model -> int - val get_sorts : model -> sort array - val sort_universe : model -> sort -> ast_vector array + val get_sorts : model -> Sort.sort array + val sort_universe : model -> Sort.sort -> AST.ASTVector.ast_vector array val to_string : model -> string end module Probe : sig - val apply : probe -> goal -> float + type probe + + val apply : probe -> Goal.goal -> float val get_num_probes : context -> int val get_probe_names : context -> string array val get_probe_description : context -> string -> string @@ -838,19 +1179,22 @@ end module Tactic : sig + type tactic module ApplyResult : sig + type apply_result + val get_num_subgoals : apply_result -> int - val get_subgoals : apply_result -> goal array - val get_subgoal : apply_result -> int -> goal - val convert_model : apply_result -> int -> model -> model + val get_subgoals : apply_result -> Goal.goal array + val get_subgoal : apply_result -> int -> Goal.goal + val convert_model : apply_result -> int -> Model.model -> Model.model val to_string : apply_result -> string end val get_help : tactic -> string - val get_param_descrs : tactic -> param_descrs - val apply : tactic -> goal -> params option -> apply_result + val get_param_descrs : tactic -> Params.ParamDescrs.param_descrs + val apply : tactic -> Goal.goal -> Params.params option -> ApplyResult.apply_result val get_num_tactics : context -> int val get_tactic_names : context -> string array val get_tactic_description : context -> string -> string @@ -858,15 +1202,15 @@ sig val and_then : context -> tactic -> tactic -> tactic array -> tactic val or_else : context -> tactic -> tactic -> tactic val try_for : context -> tactic -> int -> tactic - val when_ : context -> probe -> tactic -> tactic - val cond : context -> probe -> tactic -> tactic -> tactic + val when_ : context -> Probe.probe -> tactic -> tactic + val cond : context -> Probe.probe -> tactic -> tactic -> tactic val repeat : context -> tactic -> int -> tactic val skip : context -> tactic val fail : context -> tactic - val fail_if : context -> probe -> tactic + val fail_if : context -> Probe.probe -> tactic val fail_if_not_decided : context -> tactic - val using_params : context -> tactic -> params -> tactic - val with_ : context -> tactic -> params -> tactic + val using_params : context -> tactic -> Params.params -> tactic + val with_ : context -> tactic -> Params.params -> tactic val par_or : context -> tactic array -> tactic val par_and_then : context -> tactic -> tactic -> tactic val interrupt : context -> unit @@ -874,13 +1218,19 @@ end module Solver : sig + type solver + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + val string_of_status : status -> string module Statistics : sig + type statistics module Entry : sig + type statistics_entry + val get_key : statistics_entry -> string val get_int : statistics_entry -> int val get_float : statistics_entry -> float @@ -892,59 +1242,61 @@ sig val to_string : statistics -> string val get_size : statistics -> int - val get_entries : statistics -> statistics_entry array + val get_entries : statistics -> Entry.statistics_entry array val get_keys : statistics -> string array - val get : statistics -> string -> statistics_entry option + val get : statistics -> string -> Entry.statistics_entry option end val get_help : solver -> string - val set_parameters : solver -> params -> unit - val get_param_descrs : solver -> param_descrs + val set_parameters : solver -> Params.params -> unit + val get_param_descrs : solver -> Params.ParamDescrs.param_descrs val get_num_scopes : solver -> int val push : solver -> unit val pop : solver -> int -> unit val reset : solver -> unit - val assert_ : solver -> bool_expr array -> unit - val assert_and_track : solver -> bool_expr -> bool_expr -> unit + val assert_ : solver -> Boolean.bool_expr array -> unit + val assert_and_track : solver -> Boolean.bool_expr -> Boolean.bool_expr -> unit val get_num_assertions : solver -> int - val get_assertions : solver -> bool_expr array - val check : solver -> bool_expr array -> status - val get_model : solver -> model option - val get_proof : solver -> expr option - val get_unsat_core : solver -> ast_vector array + val get_assertions : solver -> Boolean.bool_expr array + val check : solver -> Boolean.bool_expr array -> status + val get_model : solver -> Model.model option + val get_proof : solver -> Expr.expr option + val get_unsat_core : solver -> AST.ASTVector.ast_vector array val get_reason_unknown : solver -> string - val get_statistics : solver -> statistics - val mk_solver : context -> symbol option -> solver + val get_statistics : solver -> Statistics.statistics + val mk_solver : context -> Symbol.symbol option -> solver val mk_solver_s : context -> string -> solver val mk_simple_solver : context -> solver - val mk_solver_t : context -> tactic -> solver + val mk_solver_t : context -> Tactic.tactic -> solver val to_string : solver -> string end module Fixedpoint : sig + type fixedpoint + val get_help : fixedpoint -> string - val set_params : fixedpoint -> params -> unit - val get_param_descrs : fixedpoint -> param_descrs - val assert_ : fixedpoint -> bool_expr array -> unit - val register_relation : fixedpoint -> func_decl -> unit - val add_rule : fixedpoint -> bool_expr -> symbol option -> unit - val add_fact : fixedpoint -> func_decl -> int array -> unit - val query : fixedpoint -> bool_expr -> status - val query_r : fixedpoint -> func_decl array -> status + val set_params : fixedpoint -> Params.params -> unit + val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs + val assert_ : fixedpoint -> Boolean.bool_expr array -> unit + val register_relation : fixedpoint -> FuncDecl.func_decl -> unit + val add_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol option -> unit + val add_fact : fixedpoint -> FuncDecl.func_decl -> int array -> unit + val query : fixedpoint -> Boolean.bool_expr -> Solver.status + val query_r : fixedpoint -> FuncDecl.func_decl array -> Solver.status val push : fixedpoint -> unit val pop : fixedpoint -> unit - val update_rule : fixedpoint -> bool_expr -> symbol -> unit - val get_answer : fixedpoint -> expr option + val update_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol -> unit + val get_answer : fixedpoint -> Expr.expr option val get_reason_unknown : fixedpoint -> string - val get_num_levels : fixedpoint -> func_decl -> int - val get_cover_delta : fixedpoint -> int -> func_decl -> expr option - val add_cover : fixedpoint -> int -> func_decl -> expr -> unit + val get_num_levels : fixedpoint -> FuncDecl.func_decl -> int + val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option + val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit val to_string : fixedpoint -> string - val set_predicate_representation : fixedpoint -> func_decl -> symbol array -> unit - val to_string_q : fixedpoint -> bool_expr array -> string - val get_rules : fixedpoint -> bool_expr array - val get_assertions : fixedpoint -> bool_expr array + val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol array -> unit + val to_string_q : fixedpoint -> Boolean.bool_expr array -> string + val get_rules : fixedpoint -> Boolean.bool_expr array + val get_assertions : fixedpoint -> Boolean.bool_expr array val mk_fixedpoint : context -> fixedpoint end @@ -958,19 +1310,19 @@ end module SMT : sig - val benchmark_to_smtstring : context -> string -> string -> string -> string -> bool_expr array -> bool_expr -> string - val parse_smtlib_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit - val parse_smtlib_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> unit + val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr array -> Boolean.bool_expr -> string + val parse_smtlib_string : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> unit + val parse_smtlib_file : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> unit val get_num_smtlib_formulas : context -> int - val get_smtlib_formulas : context -> bool_expr array + val get_smtlib_formulas : context -> Boolean.bool_expr array val get_num_smtlib_assumptions : context -> int - val get_smtlib_assumptions : context -> bool_expr array + val get_smtlib_assumptions : context -> Boolean.bool_expr array val get_num_smtlib_decls : context -> int - val get_smtlib_decls : context -> func_decl array + val get_smtlib_decls : context -> FuncDecl.func_decl array val get_num_smtlib_sorts : context -> int - val get_smtlib_sorts : context -> sort array - val parse_smtlib2_string : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> bool_expr - val parse_smtlib2_file : context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> bool_expr + val get_smtlib_sorts : context -> Sort.sort array + val parse_smtlib2_string : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> Boolean.bool_expr + val parse_smtlib2_file : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> Boolean.bool_expr end val set_global_param : string -> string -> unit From dc03e2903f619d1191b143c62c84e8ce9f092c57 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 20 Feb 2013 19:49:09 +0000 Subject: [PATCH 180/248] ML API: proper use of datatype API for list/enum/constructor. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/Makefile | 2 +- src/api/ml/z3.ml | 47 ++++++++++++++++++++------------------------- src/api/ml/z3.mli | 7 +++++-- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/api/ml/Makefile b/src/api/ml/Makefile index abcefa4af..96fd0a55d 100644 --- a/src/api/ml/Makefile +++ b/src/api/ml/Makefile @@ -7,4 +7,4 @@ all: doc: *.ml mkdir -p doc - ocamldoc -html -d doc -I ../../../bld_dbg/api/ml -sort *.mli -hide Z3 + ocamldoc -html -d doc -I _build -sort *.mli -hide Z3 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c261fce05..344e542f7 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -2159,15 +2159,10 @@ end module Enumeration = struct type enum_sort = EnumSort of sort - - let _constdecls = Hashtbl.create 0 - let _testerdecls = Hashtbl.create 0 let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = let s = (sort_of_ptr ctx no) in let res = EnumSort(s) in - Hashtbl.add _constdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f cdecls)) ; - Hashtbl.add _testerdecls res (let f e = func_decl_of_ptr ctx e in (Array.map f tdecls)) ; res let sort_of_enum_sort s = match s with EnumSort(x) -> x @@ -2191,33 +2186,27 @@ struct mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) (** The function declarations of the constants in the enumeration. *) - let get_const_decls ( x : enum_sort ) = Hashtbl.find _constdecls x + let get_const_decls ( x : enum_sort ) = + let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in + let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in + Array.init n f (** The test predicates for the constants in the enumeration. *) - let get_tester_decls ( x : enum_sort ) = Hashtbl.find _testerdecls x + let get_tester_decls ( x : enum_sort ) = + let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in + let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in + Array.init n f + end (** Functions to manipulate List expressions *) module List_ = struct type list_sort = ListSort of sort - - let _nildecls = Hashtbl.create 0 - let _is_nildecls = Hashtbl.create 0 - let _consdecls = Hashtbl.create 0 - let _is_consdecls = Hashtbl.create 0 - let _headdecls = Hashtbl.create 0 - let _taildecls = Hashtbl.create 0 let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = let s = (sort_of_ptr ctx no) in let res = ListSort(s) in - Hashtbl.add _nildecls res (func_decl_of_ptr ctx nildecl) ; - Hashtbl.add _is_nildecls res (func_decl_of_ptr ctx is_nildecl) ; - Hashtbl.add _consdecls res (func_decl_of_ptr ctx consdecl) ; - Hashtbl.add _is_consdecls res (func_decl_of_ptr ctx is_consdecl) ; - Hashtbl.add _headdecls res (func_decl_of_ptr ctx headdecl) ; - Hashtbl.add _taildecls res (func_decl_of_ptr ctx taildecl) ; res let sort_of_list_sort s = match s with ListSort(x) -> x @@ -2237,22 +2226,28 @@ struct mk_sort ctx (Symbol.mk_string ctx name) elem_sort (** The declaration of the nil function of this list sort. *) - let get_nil_decl ( x : list_sort ) = (Hashtbl.find _nildecls x) + let get_nil_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) (** The declaration of the isNil function of this list sort. *) - let get_is_nil_decl ( x : list_sort ) = (Hashtbl.find _is_nildecls x) + let get_is_nil_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) (** The declaration of the cons function of this list sort. *) - let get_cons_decl ( x : list_sort ) = (Hashtbl.find _consdecls x) + let get_cons_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) (** The declaration of the isCons function of this list sort. *) - let get_is_cons_decl ( x : list_sort ) = (Hashtbl.find _is_consdecls x) + let get_is_cons_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) (** The declaration of the head function of this list sort. *) - let get_head_decl ( x : list_sort ) = (Hashtbl.find _headdecls x) + let get_head_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) (** The declaration of the tail function of this list sort. *) - let get_tail_decl ( x : list_sort ) = (Hashtbl.find _taildecls x) + let get_tail_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) (** The empty list. *) let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [||] diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 5b1b2073a..87318d2a7 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -5,9 +5,9 @@ @author CM Wintersteiger (cwinter) 2012-12-17 *) -type context -(** Create a context object. + +(** Context objects. Most interactions with Z3 are interpreted in some context; many users will only require one such object, but power users may require more than one. To start using @@ -27,6 +27,9 @@ type context (...) *) +type context + +(** Create a context object *) val mk_context : (string * string) list -> context From 303b4e6735246634bcb3f76aa25e687c8c8e2b44 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 20 Feb 2013 22:07:18 +0000 Subject: [PATCH 181/248] ML API savepoint Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2595 +-------------------------------------------- src/api/ml/z3.mli | 2049 ++++++++++++++++++++++++++++++++--- 2 files changed, 1942 insertions(+), 2702 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 344e542f7..b1e40fcac 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -338,7 +338,7 @@ struct else ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - let wrap ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr + let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr let unwrap_ast ( x : ast ) = (z3obj_gno x) end @@ -744,6 +744,7 @@ sig val is_not : expr -> bool val is_implies : expr -> bool val is_label : expr -> bool + val is_label_lit : expr -> bool val is_oeq : expr -> bool val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val mk_const_s : context -> string -> Sort.sort -> expr @@ -794,257 +795,97 @@ end = struct let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (Array.length args) (expr_aton args) in expr_of_ptr ctx o - (** - Returns a simplified version of the expression. - @param p A set of parameters to configure the simplifier - - *) let simplify ( x : expr ) ( p : Params.params option ) = match p with | None -> expr_of_ptr (c_of_expr x) (Z3native.simplify (nc_of_expr x) (ptr_of_expr x)) | Some pp -> expr_of_ptr (c_of_expr x) (Z3native.simplify_ex (nc_of_expr x) (ptr_of_expr x) (z3obj_gno pp)) - (** - a string describing all available parameters to Expr.Simplify. - *) let get_simplify_help ( ctx : context ) = Z3native.simplify_get_help (context_gno ctx) - (** - Retrieves parameter descriptions for simplifier. - *) let get_simplify_parameter_descrs ( ctx : context ) = Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - - (** - The function declaration of the function that is applied in this expression. - *) let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) - (** - Indicates whether the expression is the true or false expression - or something else (L_UNDEF). - *) let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (nc_of_expr x) (ptr_of_expr x)) - (** - The number of arguments of the expression. - *) let get_num_args ( x : expr ) = Z3native.get_app_num_args (nc_of_expr x) (ptr_of_expr x) - (** - The arguments of the expression. - *) let get_args ( x : expr ) = let n = (get_num_args x) in let f i = expr_of_ptr (c_of_expr x) (Z3native.get_app_arg (nc_of_expr x) (ptr_of_expr x) i) in Array.init n f - (** - Update the arguments of the expression using the arguments - The number of new arguments should coincide with the current number of arguments. - *) let update ( x : expr ) args = if (Array.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (Array.length args) (expr_aton 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]. - *) let substitute ( x : expr ) from to_ = if (Array.length from) <> (Array.length to_) then raise (Z3native.Exception "Argument sizes do not match") else expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (Array.length from) (expr_aton from) (expr_aton to_)) - (** - Substitute every occurrence of from in the expression with to. - - *) let substitute_one ( x : expr ) from to_ = substitute ( x : expr ) [| from |] [| 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]. - *) let substitute_vars ( x : expr ) to_ = expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (Array.length to_) (expr_aton to_)) - (** - Translates (copies) the term to the Context . - @param ctx A context - @return A copy of the term which is associated with - *) let translate ( x : expr ) to_ctx = if (c_of_expr x) == to_ctx then x else expr_of_ptr to_ctx (Z3native.translate (nc_of_expr x) (ptr_of_expr x) (context_gno to_ctx)) - (** - Returns a string representation of the expression. - *) let to_string ( x : expr ) = Z3native.ast_to_string (nc_of_expr x) (ptr_of_expr x) - (** - Indicates whether the term is a numeral - *) let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (nc_of_expr x) (ptr_of_expr x)) - (** - Indicates whether the term is well-sorted. - @return True if the term is well-sorted, false otherwise. - *) let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (nc_of_expr x) (ptr_of_expr x) - (** - The Sort of the term. - *) let get_sort ( x : expr ) = sort_of_ptr (c_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)) - (** - Indicates whether the term has Boolean sort. - *) let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && (Z3native.is_eq_sort (nc_of_expr x) (Z3native.mk_bool_sort (nc_of_expr x)) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x))) - (** - Indicates whether the term represents a constant. - *) let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && (get_num_args x) == 0 && (FuncDecl.get_domain_size (get_func_decl x)) == 0 - - (** - Indicates whether the term is the constant true. - *) + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - - (** - Indicates whether the term is the constant false. - *) let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - - (** - Indicates whether the term is an equality predicate. - *) let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - - (** - Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). - *) let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - - (** - Indicates whether the term is a ternary if-then-else term - *) let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - - (** - Indicates whether the term is an n-ary conjunction - *) let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - - (** - Indicates whether the term is an n-ary disjunction - *) let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - - (** - Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) - *) let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - - (** - Indicates whether the term is an exclusive or - *) let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - - (** - Indicates whether the term is a negation - *) let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - - (** - Indicates whether the term is an implication - *) let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - - (** - 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. - *) let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == 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. - *) + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) - (** - Creates a new Constant of sort and named . - *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) - - (** - Creates a new Constant of sort and named . - *) let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) range - - (** - Creates a constant from the func_decl . - @param f An expression of a 0-arity function - *) let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [||] - (** - Creates a fresh constant of sort and a - name prefixed with . - *) let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) - (** - Create a new function application. - *) let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = expr_of_func_app ctx f args - (** - Create a numeral of a given sort. - @param v 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]*. - @param ty 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 - *) let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) - (** - Create a numeral 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. - @param v Value of the numeral - @param ty Sort of the numeral - @return A Term with value and type - *) let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) end @@ -1052,7 +893,6 @@ end open FuncDecl open Expr -(** Boolean expressions *) module Boolean = struct type bool_sort = BoolSort of Sort.sort @@ -1091,97 +931,53 @@ struct let mk_sort ( ctx : context ) = BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) - (** - Create a Boolean constant. - *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) = let s = (match (mk_sort ctx) with BoolSort(q) -> q) in BoolExpr(Expr.mk_const ctx name s) - (** - Create a Boolean constant. - *) let mk_const_s ( ctx : context ) ( name : string ) = mk_const ctx (Symbol.mk_string ctx name) - (** - The true Term. - *) let mk_true ( ctx : context ) = bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) - (** - The false Term. - *) let mk_false ( ctx : context ) = bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) - (** - Creates a Boolean value. - *) let mk_val ( ctx : context ) ( value : bool ) = if value then mk_true ctx else mk_false ctx - (** - Creates the equality = . - *) let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (ptr_of_expr x) (ptr_of_expr y)) - (** - Creates a distinct term. - *) let mk_distinct ( ctx : context ) ( args : expr array ) = bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (expr_aton args)) - (** - Mk an expression representing not(a). - *) let mk_not ( ctx : context ) ( a : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) - (** - Create an expression representing an if-then-else: ite(t1, t2, t3). - @param t1 An expression with Boolean sort - @param t2 An expression - @param t3 An expression with the same sort as - *) let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) - (** - Create an expression representing t1 iff t2. - *) let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) - (** - Create an expression representing t1 -> t2. - *) let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) - (** - Create an expression representing t1 xor t2. - *) + let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - (** - Create an expression representing the AND of args - *) let mk_and ( ctx : context ) ( args : bool_expr array ) = let f x = (ptr_of_expr (expr_of_bool_expr x)) in bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (Array.map f args)) - (** - Create an expression representing the OR of args - *) let mk_or ( ctx : context ) ( args : bool_expr array ) = let f x = (ptr_of_expr (expr_of_bool_expr x)) in bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (Array.map f args)) end -(** Quantifier expressions *) + module Quantifier = struct type quantifier = Quantifier of expr @@ -1200,12 +996,6 @@ struct let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (nc_of_expr e) let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (ptr_of_expr e) - (** Quantifier patterns - - 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. - *) module Pattern = struct type pattern = Pattern of ast @@ -1220,155 +1010,68 @@ struct let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - (** - The number of terms in the pattern. - *) let get_num_terms ( x : pattern ) = Z3native.get_pattern_num_terms (gnc x) (gno x) - (** - The terms in the pattern. - *) let get_terms ( x : pattern ) = let n = (get_num_terms x) in let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in Array.init n f - (** - A string representation of the pattern. - *) let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) end - (** - 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 : expr ) appears, the higher is its - index. - *) let get_index ( x : expr ) = if not (AST.is_var (match x with Expr.Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else Z3native.get_index_value (nc_of_expr x) (ptr_of_expr x) - (** - Indicates whether the quantifier is universal. - *) let is_universal ( x : quantifier ) = Z3native.is_quantifier_forall (gnc x) (gno x) - (** - Indicates whether the quantifier is existential. - *) let is_existential ( x : quantifier ) = not (is_universal x) - (** - The weight of the quantifier. - *) let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) - (** - The number of patterns. - *) let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) - (** - The patterns. - *) let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in Array.init n f - (** - The number of no-patterns. - *) let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) - (** - The no-patterns. - *) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in Array.init n f - (** - The number of bound variables. - *) let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) - (** - The symbols for the bound variables. - *) let get_bound_variable_names ( x : quantifier ) = let n = (get_num_bound x) in let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in Array.init n f - (** - The sorts of the bound variables. - *) let get_bound_variable_sorts ( x : quantifier ) = let n = (get_num_bound x) in let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in Array.init n f - (** - The body of the quantifier. - *) let get_body ( x : quantifier ) = Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) - (** - Creates a new bound variable. - @param index The de-Bruijn index of the variable - @param ty The sort of the variable - *) let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) - (** - Create a quantifier pattern. - *) let mk_pattern ( ctx : context ) ( terms : expr array ) = if (Array.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) - (** - 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. - - @param sorts the sorts of the bound variables. - @param names names of the bound variables - @param body the body of the quantifier. - @param weight quantifiers are associated with weights indicating the importance of using the quantifier during instantiation. By default, pass the weight 0. - @param patterns array containing the patterns created using MkPattern. - @param noPatterns array containing the anti-patterns created using MkPattern. - @param quantifierID optional symbol to track quantifier. - @param skolemID optional symbol to track skolem constants. - *) let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") @@ -1390,9 +1093,6 @@ struct (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) - (** - Create a universal Quantifier. - *) let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true @@ -1410,10 +1110,6 @@ struct (Array.length nopatterns) (expr_aton nopatterns) (ptr_of_expr body))) - (** - Create an existential Quantifier. - - *) let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (Array.length sorts) != (Array.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") @@ -1435,9 +1131,6 @@ struct (let f x = (Symbol.gno x) in (Array.map f names)) (ptr_of_expr body))) - (** - Create an existential Quantifier. - *) let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false @@ -1455,19 +1148,12 @@ struct (Array.length nopatterns) (expr_aton nopatterns) (ptr_of_expr body))) - (** - Create a Quantifier. - *) let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - - (** - Create a Quantifier. - *) let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id @@ -1475,7 +1161,7 @@ struct mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id end -(** Functions to manipulate Array expressions *) + module Array_ = struct type array_sort = ArraySort of sort @@ -1516,144 +1202,46 @@ struct let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) - (** - Create a new array sort. - *) let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) - (** - 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. - *) let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) - - (** - Indicates whether the term is an array select. - *) let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) - - (** - Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. - *) let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) - - (** - Indicates whether the term is of an array sort. - *) let is_array ( x : expr ) = (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == ARRAY_SORT) - (** The domain of the array sort. *) let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) - - (** The range of the array sort. *) let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) - (** - Create an array constant. - *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) - (** - Create an array constant. - *) let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) 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. - - - *) let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) - - (** - 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). - - - *) - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = + array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) + + let mk_store ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) - (** - Create a constant array. - - The resulting term is an array, such that a selecton an arbitrary index - produces the value v. - - - *) let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) - (** - 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]. - - - - *) let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = let m x = (ptr_of_expr (expr_of_array_expr x)) in array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m 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. - *) let mk_term_array ( ctx : context ) ( arg : array_expr ) = array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) end -(** Functions to manipulate Set expressions *) + module Set = struct type set_sort = SetSort of sort @@ -1664,100 +1252,49 @@ struct let sort_of_set_sort s = match s with SetSort(x) -> x - (** - Indicates whether the term is set union - *) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) - - (** - Indicates whether the term is set intersection - *) - let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) - - (** - Indicates whether the term is set difference - *) - let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) - - (** - Indicates whether the term is set complement - *) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) - - (** - Indicates whether the term is set subset - *) - let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) - - (** - Create a set type. - *) let mk_sort ( ctx : context ) ( ty : sort ) = set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) - (** - Create an empty set. - *) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + + let mk_empty ( ctx : context ) ( domain : sort ) = (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) - (** - Create the full set. - *) let mk_full ( ctx : context ) ( domain : sort ) = expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) - (** - Add an element to the set. - *) let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) - (** - Remove an element from a set. - *) let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) - (** - Take the union of a list of sets. - *) let mk_union ( ctx : context ) ( args : expr array ) = expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (expr_aton args)) - (** - Take the intersection of a list of sets. - *) let mk_intersection ( ctx : context ) ( args : expr array ) = expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (expr_aton args)) - (** - Take the difference between two sets. - *) let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) - (** - Take the complement of a set. - *) let mk_complement ( ctx : context ) ( arg : expr ) = expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (ptr_of_expr arg)) - (** - Check for set membership. - *) let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (ptr_of_expr elem) (ptr_of_expr set)) - (** - Check for subsetness of sets. - *) let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) end -(** Functions to manipulate Finite Domain expressions *) + module FiniteDomain = struct type finite_domain_sort = FiniteDomainSort of sort @@ -1774,41 +1311,28 @@ struct let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) - (** - Create a new finite domain sort. - *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in FiniteDomainSort(s) - (** - Create a new finite domain sort. - *) let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = mk_sort ctx (Symbol.mk_string ctx name) size - (** - Indicates whether the term is of an array sort. - *) let is_finite_domain ( x : expr ) = let nc = (nc_of_expr x) in (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == FINITE_DOMAIN_SORT) - (** - Indicates whether the term is a less than predicate over a finite domain. - *) let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) - (** The size of the finite domain sort. *) let get_size ( x : finite_domain_sort ) = let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in if r then v else raise (Z3native.Exception "Conversion failed.") end -(** Functions to manipulate Relation expressions *) + module Relation = struct type relation_sort = RelationSort of sort @@ -1830,119 +1354,27 @@ struct let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) - (** - Indicates whether the term is of a relation sort. - *) let is_relation ( x : expr ) = let nc = (nc_of_expr x) in ((Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == 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. - *) let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) - - (** - Indicates whether the term is an empty relation - *) let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) - - (** - Indicates whether the term is a test for the emptiness of a relation - *) let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) - - (** - Indicates whether the term is a relational join - *) let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) - - (** - Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. - *) let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) - - (** - Indicates whether the term is the widening of two relations - The function takes two arguments. - *) let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) - - (** - Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. - *) let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. - *) let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) - - (** - Indicates whether the term is the complement of a relation - *) let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) - (** The arity of the relation sort. *) let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) - (** The sorts of the columns of the relation sort. *) let get_column_sorts ( x : relation_sort ) = let n = get_arity x in let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in @@ -1950,7 +1382,7 @@ struct end -(** Functions to manipulate Datatype expressions *) + module Datatype = struct type datatype_sort = DatatypeSort of sort @@ -1983,14 +1415,10 @@ struct let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) - - (** Constructors *) module Constructor = struct type constructor = z3_native_object - let _counts = Hashtbl.create 0 - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = let n = (Array.length field_names) in if n != (Array.length sorts) then @@ -2009,42 +1437,29 @@ struct m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref} in - Hashtbl.add _counts no n ; (z3obj_sno no ctx ptr) ; (z3obj_create no) ; let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; no + + let get_num_fields ( x : constructor ) = Z3native.get_arity (z3obj_gnc x) (z3obj_gno x) - let get_n ( x : constructor ) = (Hashtbl.find _counts x) - - let rec constructor_decl ( x : constructor ) = - let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + let get_constructor_decl ( x : constructor ) = + let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in func_decl_of_ptr (z3obj_gc x) a - let rec tester_decl ( x : constructor ) = - let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + let get_tester_decl ( x : constructor ) = + let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in func_decl_of_ptr (z3obj_gc x) b - - let rec accessor_decls ( x : constructor ) = - let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (Hashtbl.find _counts x)) in + + let get_accessor_decls ( x : constructor ) = + let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in let f y = func_decl_of_ptr (z3obj_gc x) y in Array.map f c - (** The number of fields of the constructor. *) - let get_num_fields ( x : constructor ) = get_n x - - (** The function declaration of the constructor. *) - let get_constructor_decl ( x : constructor ) = constructor_decl x - - (** The function declaration of the tester. *) - let get_tester_decl ( x : constructor ) = tester_decl x - - (** The function declarations of the accessors *) - let get_accessor_decls ( x : constructor ) = accessor_decls x end - (** Constructor list objects *) module ConstructorList = struct type constructor_list = z3_native_object @@ -2062,54 +1477,21 @@ struct res end - (* DATATYPES *) - (** - Create a datatype constructor. - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - *) let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = Constructor.create ctx name recognizer field_names sorts sort_refs - (** - Create a datatype constructor. - @param name constructor name - @param recognizer name of recognizer function. - @param fieldNames names of the constructor fields. - @param sorts field sorts, 0 if the field sort refers to a recursive sort. - @param sortRefs reference to datatype sort that is an argument to the constructor; - if the corresponding sort reference is 0, then the value in sort_refs should be an index - referring to one of the recursive datatypes that is declared. - *) let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs - - (** - Create a new datatype sort. - *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array ) = let f x = (z3obj_gno x) in let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in sort_of_ptr ctx x - (** - Create a new datatype sort. - *) let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = mk_sort ctx (Symbol.mk_string ctx name) constructors - (** - Create mutually recursive datatypes. - @param names names of datatype sorts - @param c list of constructors, one list per sort. - *) let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = let n = (Array.length names) in let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in @@ -2119,7 +1501,6 @@ struct let g e = (sort_of_ptr ctx e) in (Array.map g r) - (** Create mutually recursive data-types. *) let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = mk_sorts ctx ( @@ -2128,22 +1509,18 @@ struct ) c - (** The number of constructors of the datatype sort. *) let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) - (** The range of the array sort. *) let get_constructors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in Array.init n f - (** The recognizers. *) let get_recognizers ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in Array.init n f - (** The constructor accessors. *) let get_accessors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = ( @@ -2155,7 +1532,7 @@ struct Array.init n f end -(** Functions to manipulate Enumeration expressions *) + module Enumeration = struct type enum_sort = EnumSort of sort @@ -2171,27 +1548,19 @@ struct let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) - (** - Create a new enumeration sort. - *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = let f x = Symbol.gno x in let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Array.map f enum_names)) in sort_of_ptr ctx a b c - (** - Create a new enumeration sort. - *) let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string array ) = mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) - (** The function declarations of the constants in the enumeration. *) let get_const_decls ( x : enum_sort ) = let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in Array.init n f - (** The test predicates for the constants in the enumeration. *) let get_tester_decls ( x : enum_sort ) = let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in @@ -2199,7 +1568,7 @@ struct end -(** Functions to manipulate List expressions *) + module List_ = struct type list_sort = ListSort of sort @@ -2214,46 +1583,36 @@ struct let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) - - - (** Create a new list sort. *) + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in sort_of_ptr ctx r a b c d e f - (** Create a new list sort. *) let mk_list_s ( ctx : context ) (name : string) elem_sort = mk_sort ctx (Symbol.mk_string ctx name) elem_sort - (** The declaration of the nil function of this list sort. *) let get_nil_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) - (** The declaration of the isNil function of this list sort. *) let get_is_nil_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) - (** The declaration of the cons function of this list sort. *) let get_cons_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) - (** The declaration of the isCons function of this list sort. *) let get_is_cons_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) - (** The declaration of the head function of this list sort. *) let get_head_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) - (** The declaration of the tail function of this list sort. *) let get_tail_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) - (** The empty list. *) let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [||] end -(** Functions to manipulate Tuple expressions *) + module Tuple = struct type tuple_sort = TupleSort of sort @@ -2268,30 +1627,24 @@ struct let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - - (** Create a new tuple sort. *) let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : sort array ) = let f x = Symbol.gno x in let f2 x = ptr_of_ast (ast_of_sort x) in - let (r, a, b) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in - (* CMW: leaks a,b? *) + let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in sort_of_ptr ctx r - (** The constructor function of the tuple. *) let get_mk_decl ( x : tuple_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) - (** The number of fields in the tuple. *) let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) - (** The field declarations. *) let get_field_decls ( x : tuple_sort ) = let n = get_num_fields x in let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in Array.init n f end -(** Functions to manipulate arithmetic expressions *) + module rec Arithmetic : sig type arith_sort = ArithSort of Sort.sort @@ -2516,84 +1869,37 @@ end = struct let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - - (** Create a new integer sort. *) let mk_sort ( ctx : context ) = int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) - (** Retrieve the int value. *) let get_int ( x : int_num ) = let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - (** Returns a string representation of the numeral. *) let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - (** - Creates an integer constant. - *) let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) - (** - Creates an integer constant. - *) let mk_int_const_s ( ctx : context ) ( name : string ) = mk_int_const ctx (Symbol.mk_string ctx name) - (** - Create an expression representing t1 mod t2. - The arguments must have int type. - *) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) - (** - Create an expression representing t1 rem t2. - The arguments must have int type. - *) let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) - (** - Create an integer numeral. - @param v A string representing the Term value in decimal notation. - *) let mk_int_numeral_s ( ctx : context ) ( v : string ) = int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - (** - Create an integer numeral. - @param v value of the numeral. - @return A Term with value and sort Integer - *) let mk_int_numeral_i ( ctx : context ) ( v : int ) = int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) - (** - 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. - *) let mk_int2real ( ctx : context ) ( t : int_expr ) = Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) - (** - 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. - *) let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) end @@ -2677,76 +1983,41 @@ end = struct let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - (** Create a real sort. *) let mk_sort ( ctx : context ) = real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) - (** The numerator of a rational numeral. *) let get_numerator ( x : rat_num ) = Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) - (** The denominator of a rational numeral. *) let get_denominator ( x : rat_num ) = Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) let to_decimal_string ( x : rat_num ) ( precision : int ) = Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision - (** Returns a string representation of the numeral. *) let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - (** Creates a real constant. *) let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) - (** Creates a real constant. *) let mk_real_const_s ( ctx : context ) ( name : string ) = mk_real_const ctx (Symbol.mk_string ctx name) - (** - Create a real from a fraction. - - @param num numerator of rational. - @param den denominator of rational. - @return A Term with value / and sort Real - - *) let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = if (den == 0) then raise (Z3native.Exception "Denominator is zero") else rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) - (** - Create a real numeral. - @param v A string representing the Term value in decimal notation. - @return A Term with value and sort Real - *) let mk_numeral_s ( ctx : context ) ( v : string ) = rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - (** - Create a real numeral. - - @param v value of the numeral. - @return A Term with value and sort Real - *) let mk_numeral_i ( ctx : context ) ( v : int ) = rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) - (** Creates an expression that checks whether a real number is an integer. *) let mk_is_integer ( ctx : context ) ( t : real_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) - (** - 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. - *) let mk_real2int ( ctx : context ) ( t : real_expr ) = Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) end @@ -2782,208 +2053,97 @@ end = struct let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - (** - Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) let to_upper ( x : algebraic_num ) ( precision : int ) = Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) - (** - Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^. - - @param precision the precision of the result - @return A numeral Expr of sort Real - *) let to_lower ( x : algebraic_num ) precision = Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) - (** Returns a string representation in decimal notation. - The result has at most decimal places.*) let to_decimal_string ( x : algebraic_num ) ( precision : int ) = Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision - (** Returns a string representation of the numeral. *) let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) end - (** - Indicates whether the term is of integer sort. - *) let is_int ( x : expr ) = (Z3native.is_numeral_ast (nc_of_expr x) (nc_of_expr x)) && ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == INT_SORT) - (** - Indicates whether the term is an arithmetic numeral. - *) let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - (** - Indicates whether the term is a less-than-or-equal - *) let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - (** - Indicates whether the term is a greater-than-or-equal - *) let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - (** - Indicates whether the term is a less-than - *) let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - (** - Indicates whether the term is a greater-than - *) let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - (** - Indicates whether the term is addition (binary) - *) let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - (** - Indicates whether the term is subtraction (binary) - *) let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - (** - Indicates whether the term is a unary minus - *) let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - (** - Indicates whether the term is multiplication (binary) - *) let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - (** - Indicates whether the term is division (binary) - *) let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - (** - Indicates whether the term is integer division (binary) - *) let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - (** - Indicates whether the term is remainder (binary) - *) let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - (** - Indicates whether the term is modulus (binary) - *) let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - (** - Indicates whether the term is a coercion of integer to real (unary) - *) let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - (** - Indicates whether the term is a coercion of real to integer (unary) - *) let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - (** - Indicates whether the term is a check that tests whether a real is integral (unary) - *) let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) - (** - Indicates whether the term is of sort real. - *) let is_real ( x : expr ) = ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == REAL_SORT) - - (** - Indicates whether the term is an integer numeral. - *) let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) - (** - Indicates whether the term is a real numeral. - *) let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) - (** - Indicates whether the term is an algebraic number - *) let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (nc_of_expr x) (nc_of_expr x) - (** - Create an expression representing t[0] + t[1] + .... - *) let mk_add ( ctx : context ) ( t : arith_expr array ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Array.map f t))) - (** - Create an expression representing t[0] * t[1] * .... - *) let mk_mul ( ctx : context ) ( t : arith_expr array ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Array.map f t))) - (** - Create an expression representing t[0] - t[1] - .... - *) let mk_sub ( ctx : context ) ( t : arith_expr array ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Array.map f t))) - (** - Create an expression representing -t. - *) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) - (** - Create an expression representing t1 / t2. - *) let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 ^ t2. - *) let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 < t2 - *) let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 <= t2 - *) let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 > t2 - *) let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) - (** - Create an expression representing t1 >= t2 - *) let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) end -(** Functions to manipulate bit-vector expressions *) + and BitVector : sig type bitvec_sort = BitVecSort of Sort.sort @@ -3089,8 +2249,10 @@ sig val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr + val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr @@ -3154,1225 +2316,213 @@ end = struct let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - (** - Create a new bit-vector sort. - *) let mk_sort ( ctx : context ) size = bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) - - (** - Indicates whether the terms is of bit-vector sort. - *) let is_bv ( x : expr ) = ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == BV_SORT) - - (** - Indicates whether the term is a bit-vector numeral - *) let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) - - (** - Indicates whether the term is a one-bit bit-vector with value one - *) let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) - - (** - Indicates whether the term is a one-bit bit-vector with value zero - *) let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) - - (** - Indicates whether the term is a bit-vector unary minus - *) let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) - - (** - Indicates whether the term is a bit-vector addition (binary) - *) let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) - - (** - Indicates whether the term is a bit-vector subtraction (binary) - *) let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) - - (** - Indicates whether the term is a bit-vector multiplication (binary) - *) let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) - - (** - Indicates whether the term is a bit-vector signed division (binary) - *) let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) - - (** - Indicates whether the term is a bit-vector unsigned division (binary) - *) let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) - - (** - Indicates whether the term is a bit-vector signed remainder (binary) - *) let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) - - (** - Indicates whether the term is a bit-vector unsigned remainder (binary) - *) let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) - - (** - Indicates whether the term is a bit-vector signed modulus - *) let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) - - (** - Indicates whether the term is a bit-vector signed division by zero - *) let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) - - (** - Indicates whether the term is a bit-vector unsigned division by zero - *) let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) - - (** - Indicates whether the term is a bit-vector signed remainder by zero - *) let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) - - (** - Indicates whether the term is a bit-vector unsigned remainder by zero - *) let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) - - (** - Indicates whether the term is a bit-vector signed modulus by zero - *) let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) - - (** - Indicates whether the term is an unsigned bit-vector less-than-or-equal - *) let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) - - (** - Indicates whether the term is a signed bit-vector less-than-or-equal - *) let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) - - (** - Indicates whether the term is an unsigned bit-vector greater-than-or-equal - *) let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) - - (** - Indicates whether the term is a signed bit-vector greater-than-or-equal - *) let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) - - (** - Indicates whether the term is an unsigned bit-vector less-than - *) let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) - - (** - Indicates whether the term is a signed bit-vector less-than - *) let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) - - (** - Indicates whether the term is an unsigned bit-vector greater-than - *) let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) - - (** - Indicates whether the term is a signed bit-vector greater-than - *) let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) - - (** - Indicates whether the term is a bit-wise AND - *) let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) - - (** - Indicates whether the term is a bit-wise OR - *) let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) - - (** - Indicates whether the term is a bit-wise NOT - *) let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) - - (** - Indicates whether the term is a bit-wise XOR - *) let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) - - (** - Indicates whether the term is a bit-wise NAND - *) let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) - - (** - Indicates whether the term is a bit-wise NOR - *) let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) - - (** - Indicates whether the term is a bit-wise XNOR - *) let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) - - (** - Indicates whether the term is a bit-vector concatenation (binary) - *) let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) - - (** - Indicates whether the term is a bit-vector sign extension - *) let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) - - (** - Indicates whether the term is a bit-vector zero extension - *) let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) - - (** - Indicates whether the term is a bit-vector extraction - *) let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) - - (** - Indicates whether the term is a bit-vector repetition - *) let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) - - (** - Indicates whether the term is a bit-vector reduce OR - *) let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) - - (** - Indicates whether the term is a bit-vector reduce AND - *) let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) - - (** - Indicates whether the term is a bit-vector comparison - *) let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) - - (** - Indicates whether the term is a bit-vector shift left - *) let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) - - (** - Indicates whether the term is a bit-vector logical shift right - *) let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) - - (** - Indicates whether the term is a bit-vector arithmetic shift left - *) let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) - - (** - Indicates whether the term is a bit-vector rotate left - *) let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) - - (** - Indicates whether the term is a bit-vector rotate right - *) let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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))) - *) let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) - - (** The size of a bit-vector sort. *) let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) - - (** Retrieve the int value. *) let get_int ( x : bitvec_num ) = let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - - (** Returns a string representation of the numeral. *) let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - - (** - Creates a bit-vector constant. - *) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) - - (** - Creates a bit-vector constant. - *) let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = mk_const ctx (Symbol.mk_string ctx name) size - - (** - Bitwise negation. - The argument must have a bit-vector sort. - *) let mk_not ( ctx : context ) ( t : bitvec_expr ) = expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) - - (** - Take conjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. - *) let mk_redand ( ctx : context ) ( t : bitvec_expr) = expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) - - (** - Take disjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. - *) let mk_redor ( ctx : context ) ( t : bitvec_expr) = expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) - - (** - Bitwise conjunction. - The arguments must have a bit-vector sort. - *) let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise disjunction. - The arguments must have a bit-vector sort. - *) let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise XOR. - The arguments must have a bit-vector sort. - *) let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise NAND. - The arguments must have a bit-vector sort. - *) let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise NOR. - The arguments must have a bit-vector sort. - *) let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) - - (** - Bitwise XNOR. - The arguments must have a bit-vector sort. - *) let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) - - (** - Standard two's complement unary minus. - The arguments must have a bit-vector sort. - *) let mk_neg ( ctx : context ) ( t : bitvec_expr) = bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) - - (** - Two's complement addition. - The arguments must have the same bit-vector sort. - *) let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) - - (** - Two's complement subtraction. - The arguments must have the same bit-vector sort. - *) let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) - - (** - Two's complement multiplication. - The arguments must have the same bit-vector sort. - *) let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) - - (** - Unsigned less-than - - The arguments must have the same bit-vector sort. - *) let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) - - (** - Two's complement signed less-than - - The arguments must have the same bit-vector sort. - *) let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) - - (** - Unsigned less-than or equal to. - - The arguments must have the same bit-vector sort. - *) let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) - - (** - Two's complement signed less-than or equal to. - - The arguments must have the same bit-vector sort. - *) let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) - - (** - Unsigned greater than or equal to. - - The arguments must have the same bit-vector sort. - *) let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) - - (** - Two's complement signed greater than or equal to. - - The arguments must have the same bit-vector sort. - *) let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) - - (** - Unsigned greater-than. - - The arguments must have the same bit-vector sort. - *) let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) - - (** - Two's complement signed greater-than. - - The arguments must have the same bit-vector sort. - *) let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) - - (** - 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). - *) let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) - - (** - 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. - *) let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) - - (** - 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. - *) let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) - - (** - Bit-vector repetition. - - The argument must have a bit-vector sort. - *) let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) - - (** - 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. - *) let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) - - - (** - 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. - *) let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) - - (** - Rotate Left. - - Rotate bits of \c t to the left \c i times. - The argument must have a bit-vector sort. - *) let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) - - (** - Rotate Right. - - Rotate bits of \c t to the right \c i times. - The argument must have a bit-vector sort. - *) let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) - - (** - Rotate Left. - - Rotate bits of to the left times. - The arguments must have the same bit-vector sort. - *) - let mk_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + let mk_ext_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) - - (** - Rotate Right. - - - Rotate bits of to the right times. - The arguments must have the same bit-vector sort. - *) - let mk_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + let mk_ext_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) - - (** - 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. - *) let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) - - (** - Create a predicate that checks that the bit-wise addition does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - - (** - Create a predicate that checks that the bit-wise addition does not underflow. - - The arguments must be of bit-vector sort. - *) let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) - - (** - Create a predicate that checks that the bit-wise subtraction does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) - - (** - Create a predicate that checks that the bit-wise subtraction does not underflow. - - The arguments must be of bit-vector sort. - *) let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) - - (** - Create a predicate that checks that the bit-wise signed division does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) - - (** - Create a predicate that checks that the bit-wise negation does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) - - (** - Create a predicate that checks that the bit-wise multiplication does not overflow. - - The arguments must be of bit-vector sort. - *) let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - - (** - Create a predicate that checks that the bit-wise multiplication does not underflow. - - The arguments must be of bit-vector sort. - *) let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) - - (** - Create a bit-vector numeral. - - @param v A string representing the value in decimal notation. - @param size the size of the bit-vector - *) let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) end -(** Functions to manipulate proof expressions *) + module Proof = struct - (** - Indicates whether the term is a Proof for the expression 'true'. - *) let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) - - (** - Indicates whether the term is a proof for a fact asserted by the user. - *) let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) - - (** - Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. - *) let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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). - *) let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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'. - *) let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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)) - *) let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 - *) let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) - *) let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 - *) let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 - *) - let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) - let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. - - This proof object has no antecedents. - - Several variables can be eliminated simultaneously. - *) - let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) - - (** - Indicates whether the term is a proof for quantifier instantiation - - A proof of (or (not (forall (x) (P x))) (P a)) - *) let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) - - (** - Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. - *) let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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') - *) let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) - - (** - Indicates whether the term is a proof by iff-true - - T1: p - [iff-true T1]: (iff p true) - *) let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) - - (** - Indicates whether the term is a proof by iff-false - - T1: (not p) - [iff-false T1]: (iff p false) - *) let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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). - *) let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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) - *) let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) - - (** - Indicates whether the term is a proof iff-oeq - - T1: (iff p q) - [iff~ T1]: (~ p q) - *) let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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'. - *) let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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'))) - *) let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) - - (** - Indicates whether the term is a proof for a Skolemization step - - Proof for: - - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) - - This proof object has no antecedents. - *) let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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 - *) let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == 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. - *) let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end -(** Goals - - A goal (aka problem). A goal is essentially a - of formulas, that can be solved and/or transformed using - tactics and solvers. *) module Goal = struct type goal = z3_native_object @@ -4386,76 +2536,52 @@ struct (z3obj_create res) ; res - - (** 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. - *) let get_precision ( x : goal ) = goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) - (** Indicates whether the goal is precise. *) let is_precise ( x : goal ) = (get_precision x) == GOAL_PRECISE - (** Indicates whether the goal is an under-approximation. *) let is_underapproximation ( x : goal ) = (get_precision x) == GOAL_UNDER - (** Indicates whether the goal is an over-approximation. *) let is_overapproximation ( x : goal ) = (get_precision x) == GOAL_OVER - (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) let is_garbage ( x : goal ) = (get_precision x) == GOAL_UNDER_OVER - (** Adds the constraints to the given goal. *) - (* CMW: assert seems to be a keyword. *) let assert_ ( x : goal ) ( constraints : Boolean.bool_expr array ) = let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in ignore (Array.map f constraints) ; () - (** Indicates whether the goal contains `false'. *) let is_inconsistent ( x : goal ) = Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) - (** The depth of the goal. - This tracks how many transformations were applied to it. *) let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) - (** Erases all formulas from the given goal. *) let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) - (** The number of formulas in the goal. *) let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) - (** The formulas in the goal. *) let get_formulas ( x : goal ) = let n = get_size x in let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in Array.init n f - (** The number of formulas, subformulas and terms in the goal. *) let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) - (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) let is_decided_sat ( x : goal ) = Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) - (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) let is_decided_unsat ( x : goal ) = Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) - (** Translates (copies) the Goal to the target Context . *) let translate ( x : goal ) ( to_ctx : context ) = create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) let simplify ( x : goal ) ( p : Params.params option ) = let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in Z3native.tactic_inc_ref (z3obj_gnc x) tn ; @@ -4473,27 +2599,13 @@ struct Z3native.tactic_dec_ref (z3obj_gnc x) tn ; create (z3obj_gc x) res - - (** - Creates a new Goal. - - Note that the Context must have been created with proof generation support if - is set to true here. - @param models Indicates whether model generation should be enabled. - @param unsat_cores Indicates whether unsat core generation should be enabled. - @param proofs Indicates whether proof generation should be enabled. - *) let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) - (** A string representation of the Goal. *) let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) end -(** Models - - A Model contains interpretations (assignments) of constants and functions. *) module Model = struct type model = z3_native_object @@ -4507,12 +2619,6 @@ struct (z3obj_create res) ; res - - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. - *) module FuncInterp = struct type func_interp = z3_native_object @@ -4526,11 +2632,6 @@ struct (z3obj_create res) ; res - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. - *) module FuncEntry = struct type func_entry = z3_native_object @@ -4544,61 +2645,33 @@ struct (z3obj_create res) ; res - - (** - Return the (symbolic) value of this entry. - *) let get_value ( x : func_entry ) = expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) - (** - The number of arguments of the entry. - *) let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) - (** - The arguments of the function entry. - *) let get_args ( x : func_entry ) = let n = (get_num_args x) in let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f - (** - A string representation of the function entry. - *) let to_string ( x : func_entry ) = let a = (get_args x) in let f c p = (p ^ (Expr.to_string c) ^ ", ") in "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") end - (** - The number of entries in the function interpretation. - *) let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) - (** - The entries in the function interpretation - *) let get_entries ( x : func_interp ) = let n = (get_num_entries x) in let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f - (** - The (symbolic) `else' value of the function interpretation. - *) let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) - (** - The arity of the function interpretation - *) let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) - (** - A string representation of the function interpretation. - *) let to_string ( x : func_interp ) = let f c p = ( let n = (FuncEntry.get_num_args c) in @@ -4613,9 +2686,6 @@ struct Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") end - (** Retrieves the interpretation (the assignment) of in the model. - A function declaration of zero arity - An expression if the function has an interpretation in the model, null otherwise. *) let get_const_interp ( x : model ) ( f : func_decl ) = if (FuncDecl.get_arity f) != 0 || (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then @@ -4627,16 +2697,9 @@ struct else Some (expr_of_ptr (z3obj_gc x) np) - (** Retrieves the interpretation (the assignment) of in the model. - A Constant - An expression if the constant has an interpretation in the model, null otherwise. - *) let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - (** Retrieves the interpretation (the assignment) of a non-constant in the model. - A function declaration of non-zero arity - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) let rec get_func_interp ( x : model ) ( f : func_decl ) = let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in if (FuncDecl.get_arity f) == 0 then @@ -4659,23 +2722,18 @@ struct (** The number of constants that have an interpretation in the model. *) let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) - (** The function declarations of the constants in the model. *) let get_const_decls ( x : model ) = let n = (get_num_consts x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - - (** The number of function interpretations in the model. *) let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) - (** The function declarations of the function interpretations in the model. *) let get_func_decls ( x : model ) = let n = (get_num_consts x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** All symbols that have an interpretation in the model. *) let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in @@ -4683,24 +2741,8 @@ struct let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in Array.append (Array.init n_funcs f) (Array.init n_consts g) - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) exception ModelEvaluationFailedException of string - (** - 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. - - The evaluation of in the model. - *) let eval ( x : model ) ( t : expr ) ( completion : bool ) = let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (ptr_of_expr t) completion) in if not r then @@ -4708,53 +2750,26 @@ struct else expr_of_ptr (z3obj_gc x) v - (** Alias for eval. *) let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = eval x t completion - (** The number of uninterpreted sorts that the model has an interpretation for. *) let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) - (** 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. - - - *) let get_sorts ( x : model ) = let n = (get_num_sorts x) in let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in Array.init n f - - (** The finite set of distinct values that represent the interpretation for sort . - - An uninterpreted sort - An array of expressions, where each is an element of the universe of - *) let sort_universe ( x : model ) ( s : sort ) = let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in Array.init n f - - (** Conversion of models to strings. - A string representation of the model. - *) + let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) end -(** Probes - - 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. -*) module Probe = struct type probe = z3_native_object @@ -4769,114 +2784,52 @@ struct res - (** - Execute the probe over the goal. - A probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. - *) let apply ( x : probe ) ( g : Goal.goal ) = Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) - (** - The number of supported Probes. - *) let get_num_probes ( ctx : context ) = Z3native.get_num_probes (context_gno ctx) - (** - The names of all supported Probes. - *) let get_probe_names ( ctx : context ) = let n = (get_num_probes ctx) in let f i = (Z3native.get_probe_name (context_gno ctx) i) in Array.init n f - (** - Returns a string containing a description of the probe with the given name. - *) let get_probe_description ( ctx : context ) ( name : string ) = Z3native.probe_get_descr (context_gno ctx) name - (** - Creates a new Probe. - *) let mk_probe ( ctx : context ) ( name : string ) = (create ctx (Z3native.mk_probe (context_gno ctx) name)) - (** - Create a probe that always evaluates to . - *) let const ( ctx : context ) ( v : float ) = (create ctx (Z3native.probe_const (context_gno ctx) v)) - (** - Create a probe that evaluates to "true" when the value returned by - is less than the value returned by - *) let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value returned by - is greater than the value returned by - *) let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value returned by - is less than or equal the value returned by - *) let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value returned by - is greater than or equal the value returned by - *) let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value returned by - is equal to the value returned by - *) let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value - and evaluate to "true". - *) - (* CMW: and is a keyword *) let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value - or evaluate to "true". - *) - (* CMW: or is a keyword *) let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - (** - Create a probe that evaluates to "true" when the value - does not evaluate to "true". - *) - (* CMW: is not a keyword? *) let not_ ( ctx : context ) ( p : probe ) = (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) end -(** Tactics - - Tactics are the basic building block for creating custom solvers for specific problem domains. - The complete list of tactics may be obtained using Context.get_num_tactics - and Context.get_tactic_names. - It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. -*) module Tactic = struct type tactic = z3_native_object @@ -4890,11 +2843,6 @@ struct (z3obj_create res) ; res - - (** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) module ApplyResult = struct type apply_result = z3_native_object @@ -4908,75 +2856,46 @@ struct (z3obj_create res) ; res - - (** The number of Subgoals. *) let get_num_subgoals ( x : apply_result ) = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) - (** Retrieves the subgoals from the apply_result. *) let get_subgoals ( x : apply_result ) = let n = (get_num_subgoals x) in let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** Retrieves the subgoals from the apply_result. *) let get_subgoal ( x : apply_result ) ( i : int ) = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) - (** 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 - *) let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) - (** A string representation of the ApplyResult. *) let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) end - (** A string containing a description of parameters accepted by the tactic. *) let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) - (** Retrieves parameter descriptions for Tactics. *) let get_param_descrs ( x : tactic ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - (** Apply the tactic to the goal. *) let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = match p with | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) - (** - The number of supported tactics. - *) let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) - (** - The names of all supported tactics. - *) let get_tactic_names ( ctx : context ) = let n = (get_num_tactics ctx ) in let f i = (Z3native.get_tactic_name (context_gno ctx) i) in Array.init n f - - (** - Returns a string containing a description of the tactic with the given name. - *) let get_tactic_description ( ctx : context ) ( name : string ) = Z3native.tactic_get_descr (context_gno ctx) name - (** - Creates a new Tactic. - *) let mk_tactic ( ctx : context ) ( name : string ) = create ctx (Z3native.mk_tactic (context_gno ctx) name) - (** - Create a tactic that applies to a Goal and - then to every subgoal produced by . - *) let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array ) = let f p c = (match p with | None -> (Some (z3obj_gno c)) @@ -4988,106 +2907,50 @@ struct let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) - (** - Create a tactic that first applies to a Goal and - if it fails then returns the result of applied to the Goal. - *) let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - (** - Create a tactic that applies to a goal for milliseconds. - - If does not terminate within milliseconds, then it fails. - *) let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) 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. - *) - (* CMW: when is a keyword *) let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) - (** - Create a tactic that applies to a given goal if the probe - evaluates to true and otherwise. - *) let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) - (** - Create a tactic that keeps applying until the goal is not - modified anymore or the maximum number of iterations is reached. - *) let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) - (** - Create a tactic that just returns the given goal. - *) let skip ( ctx : context ) = create ctx (Z3native.tactic_skip (context_gno ctx)) - (** - Create a tactic always fails. - *) let fail ( ctx : context ) = create ctx (Z3native.tactic_fail (context_gno ctx)) - (** - Create a tactic that fails if the probe evaluates to false. - *) let fail_if ( ctx : context ) ( p : Probe.probe ) = create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) - (** - Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). - *) let fail_if_not_decided ( ctx : context ) = create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) - (** - Create a tactic that applies using the given set of parameters . - *) let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) - (** - Create a tactic that applies using the given set of parameters . - Alias for UsingParams*) - (* CMW: with is a keyword *) let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = using_params ctx t p - (** - Create a tactic that applies the given tactics in parallel. - *) let par_or ( ctx : context ) ( t : tactic array ) = create ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) - (** - Create a tactic that applies to a given goal and then - to every subgoal produced by . The subgoals are processed in parallel. - *) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - (** - Interrupt the execution of a Z3 procedure. - This procedure can be used to interrupt: solvers, simplifiers and tactics. - *) let interrupt ( ctx : context ) = Z3native.interrupt (context_gno ctx) end -(** Solvers *) module Solver = struct type solver = z3_native_object @@ -5102,13 +2965,11 @@ struct (z3obj_create res) ; res - let string_of_status ( s : status) = match s with | UNSATISFIABLE -> "unsatisfiable" | SATISFIABLE -> "satisfiable" | _ -> "unknown" - (** Objects that track statistical information about solvers. *) module Statistics = struct type statistics = z3_native_object @@ -5123,11 +2984,6 @@ struct res - (** - Statistical data is organized into pairs of \[Key, Entry\], where every - Entry is either a floating point or integer value. - - *) module Entry = struct type statistics_entry = { @@ -5158,22 +3014,11 @@ struct res - (** The key of the entry. *) let get_key (x : statistics_entry) = x.m_key - - (** The int-value of the entry. *) - let get_int (x : statistics_entry) = x.m_int - - (** The float-value of the entry. *) + let get_int (x : statistics_entry) = x.m_int let get_float (x : statistics_entry) = x.m_float - - (** True if the entry is uint-valued. *) let is_int (x : statistics_entry) = x.m_is_int - - (** True if the entry is double-valued. *) let is_float (x : statistics_entry) = x.m_is_float - - (** The string representation of the the entry's value. *) let to_string_value (x : statistics_entry) = if (is_int x) then string_of_int (get_int x) @@ -5181,18 +3026,13 @@ struct string_of_float (get_float x) else raise (Z3native.Exception "Unknown statistical entry type") - - (** The string representation of the entry (key and value) *) let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) end - (** A string representation of the statistical data. *) let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) - (** The number of statistical data. *) let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) - (** The data entries. *) let get_entries ( x : statistics ) = let n = (get_size x ) in let f i = ( @@ -5204,129 +3044,56 @@ struct ) in Array.init n f - (** - The statistical counters. - *) let get_keys ( x : statistics ) = let n = (get_size x) in let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in Array.init n f - (** The value of a particular statistical counter. *) let get ( x : statistics ) ( key : string ) = let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in Array.fold_left f None (get_entries x) end - (** - A string that describes all available solver parameters. - *) let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) - (** - Sets the solver parameters. - *) let set_parameters ( x : solver ) ( p : Params.params )= Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - (** - Retrieves parameter descriptions for solver. - *) let get_param_descrs ( x : solver ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - (** - The current number of backtracking points (scopes). - - - *) let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) - (** - Creates a backtracking point. - - *) let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) - (** - Backtracks backtracking points. - Note that an exception is thrown if is not smaller than NumScopes - - *) let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n - (** - Resets the Solver. - This removes all assertions from the solver. - *) let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - (** - Assert a constraint (or multiple) into the solver. - *) let assert_ ( x : solver ) ( constraints : Boolean.bool_expr array ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) - (** - * Assert multiple constraints (cs) into the solver, and track them (in the - * unsat) core - * using the Boolean constants in ps. - * - * This API is an alternative to with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using - * and the Boolean literals - * provided using with assumptions. - *) - let assert_and_track ( x : solver ) ( cs : Boolean.bool_expr array ) ( ps : Boolean.bool_expr array ) = + let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr array ) ( ps : Boolean.bool_expr array ) = if ((Array.length cs) != (Array.length ps)) then raise (Z3native.Exception "Argument size mismatch") else let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) (Boolean.gno (Array.get ps i))) in ignore (Array.iteri f cs) - (** - * Assert a constraint (c) into the solver, and track it (in the unsat) core - * using the Boolean constant p. - * - * This API is an alternative to with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using - * and the Boolean literals - * provided using with assumptions. - *) let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) - (** - The number of assertions in the solver. - *) let get_num_assertions ( x : solver ) = let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) - - (** - The set of asserted formulas. - *) let get_assertions ( x : solver ) = let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in Array.init n f - (** - Checks whether the assertions in the solver are consistent or not. - - - - - *) let check ( x : solver ) ( assumptions : Boolean.bool_expr array) = let r = if ((Array.length assumptions) == 0) then @@ -5340,12 +3107,6 @@ struct | L_FALSE -> UNSATISFIABLE | _ -> UNKNOWN - (** - The model of the last Check. - - The result is None if Check was not invoked before, - if its results was not SATISFIABLE, or if model production is not enabled. - *) let get_model ( x : solver ) = let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in if (Z3native.is_null q) then @@ -5353,12 +3114,6 @@ struct else Some (Model.create (z3obj_gc x) q) - (** - 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. - *) let get_proof ( x : solver ) = let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in if (Z3native.is_null q) then @@ -5366,73 +3121,35 @@ struct else Some (expr_of_ptr (z3obj_gc x) q) - (** - 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. - *) let get_unsat_core ( x : solver ) = let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in Array.init n f - (** - A brief justification of why the last call to Check returned UNKNOWN. - *) let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - - (** - Solver statistics. - *) let get_statistics ( x : solver ) = (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) - (** - 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. - *) let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = match logic with | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) - (** - Creates a new (incremental) solver. - - *) let mk_solver_s ( ctx : context ) ( logic : string ) = mk_solver ctx (Some (Symbol.mk_string ctx logic)) - (** - Creates a new (incremental) solver. - *) let mk_simple_solver ( ctx : context ) = (create ctx (Z3native.mk_simple_solver (context_gno ctx))) - (** - 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. - *) let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) - (** - A string representation of the solver. - *) let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) end -(** Fixedpoint solving *) module Fixedpoint = struct type fixedpoint = z3_native_object @@ -5447,70 +3164,37 @@ struct res - (** - A string that describes all available fixedpoint solver parameters. - *) let get_help ( x : fixedpoint ) = Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) - (** - Sets the fixedpoint solver parameters. - *) let set_params ( x : fixedpoint ) ( p : Params.params )= Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - (** - Retrieves parameter descriptions for Fixedpoint solver. - *) let get_param_descrs ( x : fixedpoint ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - (** - Assert a constraints into the fixedpoint solver. - *) let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr array ) = let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in ignore (Array.map f constraints) ; () - (** - Register predicate as recursive relation. - *) let register_relation ( x : fixedpoint ) ( f : func_decl ) = Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) - (** - Add rule into the fixedpoint solver. - *) let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = match name with | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) - (** - Add table fact to the fixedpoint solver. - *) let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (Array.length args) 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. - *) let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.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. - *) let query_r ( x : fixedpoint ) ( relations : func_decl array ) = let f x = ptr_of_ast (ast_of_func_decl x) in match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (Array.map f relations))) with @@ -5518,32 +3202,15 @@ struct | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN - (** - Creates a backtracking point. - - *) let push ( x : fixedpoint ) = Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) - (** - Backtrack one backtracking point. - - Note that an exception is thrown if Pop is called without a corresponding Push - - *) let pop ( x : fixedpoint ) = Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) - (** - Update named rule into in the fixedpoint solver. - *) let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) - (** - Retrieve satisfying instance or instances of solver, - or definitions for the recursive predicates that show unsatisfiability. - *) let get_answer ( x : fixedpoint ) = let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in if (Z3native.is_null q) then @@ -5551,21 +3218,12 @@ struct else Some (expr_of_ptr (z3obj_gc x) q) - (** - Retrieve explanation why fixedpoint engine returned status Unknown. - *) let get_reason_unknown ( x : fixedpoint ) = Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - (** - Retrieve the number of levels explored for a given predicate. - *) let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) - (** - Retrieve the cover of a predicate. - *) let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in if (Z3native.is_null q) then @@ -5573,82 +3231,40 @@ struct else Some (expr_of_ptr (z3obj_gc x) q) - (** - Add property about the predicate. - The property is added at level. - *) let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (ptr_of_expr property) - (** - Retrieve internal string representation of fixedpoint object. - *) let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - (** - Instrument the Datalog engine on which table representation to use for recursive predicate. - *) let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = let f2 x = (Symbol.gno x) in Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Array.map f2 kinds) - (** - Convert benchmark given as set of axioms, rules and queries to a string. - *) let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr array ) = let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Array.map f queries) - (** - Retrieve set of rules added to fixedpoint context. - *) let get_rules ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f - (** - Retrieve set of assertions added to fixedpoint context. - *) let get_assertions ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in Array.init n f - (** - Create a Fixedpoint context. - *) let mk_fixedpoint ( ctx : context ) = create ctx end -(** Global and context options - - Note: This module contains functions that set parameters/options for context - objects as well as functions that set options that are used globally, across - contexts.*) module Options = struct - (** - 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. - - *) let update_param_value ( ctx : context ) ( id : string) ( value : string )= Z3native.update_param_value (context_gno ctx) id value - (** - Get a configuration parameter. - - Returns None if the parameter value does not exist. - - *) let get_param_value ( ctx : context ) ( id : string ) = let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in if not r then @@ -5656,62 +3272,21 @@ struct else Some v - (** - 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 PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - - - - - *) let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) - (** - Enable/disable printing of warning messages to the console. - - Note that this function is static and effects the behaviour of - all contexts globally. - *) let toggle_warning_messages ( enabled: bool ) = Z3native.toggle_warning_messages enabled end -(** Functions for handling SMT and SMT2 expressions and files *) + module SMT = struct - (** - Convert a benchmark into an SMT-LIB formatted string. - - @param name Name of the benchmark. The argument is optional. - @param logic The benchmark logic. - @param status The status string (sat, unsat, or unknown) - @param attributes Other attributes, such as source, difficulty or category. - @param assumptions Auxiliary assumptions. - @param formula Formula to be checked for consistency in conjunction with assumptions. - @return A string representation of the benchmark. - *) let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr array ) ( formula : Boolean.bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes (Array.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.map f assumptions)) (Boolean.gno formula) - (** - 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. - *) let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in @@ -5728,10 +3303,6 @@ struct (let f x = Symbol.gno x in (Array.map f decl_names)) (let f x = FuncDecl.gno x in (Array.map f decls)) - (** - Parse the given file using the SMT-LIB parser. - - *) let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in @@ -5748,65 +3319,34 @@ struct (let f x = Symbol.gno x in (Array.map f decl_names)) (let f x = FuncDecl.gno x in (Array.map f decls)) - (** - The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) - (** - The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in Array.init n f - - (** - The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) - (** - The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in Array.init n f - (** - The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) - (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in Array.init n f - (** - The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) - - (** - The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. - *) + let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in Array.init n f - (** - 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. - *) let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in @@ -5823,10 +3363,6 @@ struct (let f x = Symbol.gno x in (Array.map f decl_names)) (let f x = FuncDecl.gno x in (Array.map f decls)))) - (** - Parse the given file using the SMT-LIB2 parser. - - *) let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = let csn = (Array.length sort_names) in let cs = (Array.length sorts) in @@ -5845,34 +3381,9 @@ struct end -(* Global functions *) - -(** - * Set a global (or module) parameter, which is shared by all Z3 contexts. - * - * When a Z3 module is initialized it will use the value of these parameters - * when Z3_params objects are not provided. - * The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. - * The character '.' is a delimiter (more later). - * The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. - * Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". - * This function can be used to set parameters for a specific Z3 module. - * This can be done by using .. - * For example: - * (set_global_param "pp.decimal" "true") - * will set the parameter "decimal" in the module "pp" to true. -*) let set_global_param ( id : string ) ( value : string ) = (Z3native.global_param_set id value) -(** - * Get a global (or module) parameter. - * - * Returns None if the parameter does not exist. - * The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. - * This function cannot be invoked simultaneously from different threads without synchronization. - * The result string stored in param_value is stored in a shared location. -*) let get_global_param ( id : string ) = let (r, v) = (Z3native.global_param_get id) in if not r then @@ -5880,11 +3391,5 @@ let get_global_param ( id : string ) = else Some v -(** - * Restore the value of all global (and module) parameters. - * - * This command will not affect already created objects (such as tactics and solvers) - * -*) let global_param_reset_all = Z3native.global_param_reset_all diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 87318d2a7..49a78f724 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -5,8 +5,6 @@ @author CM Wintersteiger (cwinter) 2012-12-17 *) - - (** Context objects. Most interactions with Z3 are interpreted in some context; many users will only @@ -39,17 +37,14 @@ val mk_context : (string * string) list -> context module Log : sig (** Open an interaction log file. - @param filename the name of the file to open. - @return True if opening the log file succeeds, false otherwise. - *) + @return True if opening the log file succeeds, false otherwise. *) (* CMW: "open" seems to be a reserved keyword? *) val open_ : string -> bool (** Closes the interaction log. *) val close : unit - (** Appends a user-provided string to the interaction log. - @param s the string to append*) + (** Appends a user-provided string to the interaction log. *) val append : string -> unit end @@ -102,12 +97,10 @@ sig (** A string representation of the symbol. *) val to_string : symbol -> string - (** - Creates a new symbol using an integer. + (** 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. - *) + The legal range of unsigned integers is 0 to 2^30-1. *) val mk_int : context -> int -> symbol (** Creates a new symbol using a string. *) @@ -135,30 +128,21 @@ sig (** Retrieves the i-th object in the vector. - @param i Index - @return An AST - *) + @return An AST *) val get : ast_vector -> int -> ast (** Sets the i-th object in the vector. *) val set : ast_vector -> int -> ast -> unit - (** Resize the vector to . - @param newSize The new size of the vector. *) + (** Resize the vector to a new size. *) val resize : ast_vector -> int -> unit - (** - Add the AST to the back of the vector. The size - is increased by 1. - @param a An AST - *) + (** Add an ast to the back of the vector. The size + is increased by 1. *) val push : ast_vector -> ast -> unit - (** - Translates all ASTs in the vector to . - @param to_ctx A context - @return A new ASTVector - *) + (** Translates all ASTs in the vector to another context. + @return A new ASTVector *) val translate : ast_vector -> context -> ast_vector (** Retrieves a string representation of the vector. *) @@ -170,29 +154,18 @@ sig sig type ast_map - (** Checks whether the map contains the key . - @param k An AST - @return True if is a key in the map, false otherwise. *) + (** Checks whether the map contains a key. + @return True if the key in the map, false otherwise. *) val contains : ast_map -> ast -> bool - (** Finds the value associated with the key . - - This function signs an error when is not a key in the map. - @param k An AST - *) + (** Finds the value associated with the key. + This function signs an error when the key is not a key in the map. *) val find : ast_map -> ast -> ast - (** - Stores or replaces a new key/value pair in the map. - @param k The key AST - @param v The value AST - *) + (** Stores or replaces a new key/value pair in the map. *) val insert : ast_map -> ast -> ast -> unit - (** - Erases the key from the map. - @param k An AST - *) + (** Erases the key from the map.*) val erase : ast_map -> ast -> unit (** Removes all keys from the map. *) @@ -208,10 +181,8 @@ sig val to_string : ast_map -> string end - (** - The AST's hash code. - @return A hash code - *) + (** The AST's hash code. + @return A hash code *) val get_hash_code : ast -> int (** A unique identifier for the AST (unique among all ASTs). *) @@ -241,56 +212,39 @@ sig (** A string representation of the AST in s-expression notation. *) val to_sexpr : ast -> string - (** - Comparison operator. - @param a An AST - @param b An AST - @return True if and are from the same context - and represent the same sort; false otherwise. - *) + (** Comparison operator. + @return True if the two ast's are from the same context + and represent the same sort; false otherwise. *) val ( = ) : ast -> ast -> bool - (** - Object Comparison. - @param other Another ast - @return Negative if the object should be sorted before , positive if after else zero. - *) + (** Object Comparison. + @return Negative if the first ast should be sorted before the second, positive if after else zero. *) val compare : ast -> ast -> int (** Operator < *) val ( < ) : ast -> ast -> int - (** - Translates (copies) the AST to the Context . - @param ctx A context - @return A copy of the AST which is associated with - *) + (** Translates (copies) the AST to another context. + @return A copy of the AST which is associated with the other context. *) val translate : ast -> context -> ast - (** - Wraps an AST. + (** 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 ) + This function is used for transitions between native and + managed objects. Note that the native ast that is passed must be a + native object obtained from Z3 (e.g., through {!unwrap_ast}) and that it must have a correct reference count (see e.g., - . - - @param nativeObject The native pointer to wrap. - *) - val wrap : context -> Z3native.z3_ast -> ast + Z3native.inc_ref). *) + val wrap_ast : context -> Z3native.z3_ast -> ast - (** - Unwraps an AST. - This function is used for transitions between native and + (** 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., - ). - - @param a The AST to unwrap. - *) + Z3native.inc_ref). + {!wrap_ast} *) val unwrap_ast : ast -> Z3native.ptr end @@ -307,13 +261,9 @@ sig val sort_of_uninterpreted_sort : uninterpreted_sort -> sort val uninterpreted_sort_of_sort : sort -> uninterpreted_sort - (** - Comparison operator. - @param a A sort - @param b A sort - @return True if and are from the same context - and represent the same sort; false otherwise. - *) + (** Comparison operator. + @return True if the two sorts are from the same context + and represent the same sort; false otherwise. *) val ( = ) : sort -> sort -> bool (** Returns a unique identifier for the sort. *) @@ -385,9 +335,7 @@ sig (** Creates a new function declaration. *) val mk_func_decl_s : context -> string -> Sort.sort array -> Sort.sort -> func_decl - (** Creates a fresh function declaration with a name prefixed with . - - *) + (** Creates a fresh function declaration with a name prefixed with a prefix string. *) val mk_fresh_func_decl : context -> string -> Sort.sort array -> Sort.sort -> func_decl @@ -397,16 +345,13 @@ sig (** Creates a new constant function declaration. *) val mk_const_decl_s : context -> string -> Sort.sort -> func_decl - (** Creates a fresh constant function declaration with a name prefixed with . - - *) + (** Creates a fresh constant function declaration with a name prefixed with a prefix string. + {!mk_func_decl} + {!mk_func_decl} *) val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl (** Comparison operator. - @param a A func_decl - @param b A func_decl - @return True if and are from the same context - and represent the same func_decl; false otherwise. *) + @return True if a and b are from the same context and represent the same func_decl; false otherwise. *) val ( = ) : func_decl -> func_decl -> bool (** A string representations of the function declaration. *) @@ -419,7 +364,7 @@ sig val get_arity : func_decl -> int (** The size of the domain of the function declaration - *) + {!get_arity} *) val get_domain_size : func_decl -> int (** The domain of the function declaration *) @@ -440,8 +385,7 @@ sig (** The parameters of the function declaration *) val get_parameters : func_decl -> Parameter.parameter list - (** Create expression that applies function to arguments. - @param args The arguments *) + (** Create expression that applies function to arguments. *) val apply : func_decl -> Expr.expr array -> Expr.expr end @@ -504,54 +448,153 @@ sig val to_string : params -> string end +(** General Expressions (terms) *) and Expr : sig - (** General Expressions (Terms) *) type expr = Expr of AST.ast val ast_of_expr : Expr.expr -> AST.ast val expr_of_ast : AST.ast -> Expr.expr + (** Returns a simplified version of the expression. + {!get_simplify_help} *) val simplify : Expr.expr -> Params.params option -> expr + + (** A string describing all available parameters to Expr.Simplify. *) val get_simplify_help : context -> string + + (** Retrieves parameter descriptions for simplifier. *) val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs + + (** The function declaration of the function that is applied in this expression. *) val get_func_decl : Expr.expr -> FuncDecl.func_decl + + (** Indicates whether the expression is the true or false expression + or something else (L_UNDEF). *) val get_bool_value : Expr.expr -> Z3enums.lbool + + (** The number of arguments of the expression. *) val get_num_args : Expr.expr -> int + + (** The arguments of the expression. *) val get_args : Expr.expr -> Expr.expr array + + (** Update the arguments of the expression using an array of expressions. + The number of new arguments should coincide with the current number of arguments. *) val update : Expr.expr -> Expr.expr array -> expr + + (** 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]. *) val substitute : Expr.expr -> Expr.expr array -> Expr.expr array -> expr + + (** Substitute every occurrence of from in the expression with to. + {!substitute} *) val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr + + (** Substitute the free variables in the expression with the expressions in the expr array + + For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) val substitute_vars : Expr.expr -> Expr.expr array -> expr + + (** Translates (copies) the term to another context. + @return A copy of the term which is associated with the other context *) val translate : Expr.expr -> context -> expr + + (** Returns a string representation of the expression. *) val to_string : Expr.expr -> string + + (** Indicates whether the term is a numeral *) val is_numeral : Expr.expr -> bool + + (** Indicates whether the term is well-sorted. + @return True if the term is well-sorted, false otherwise. *) val is_well_sorted : Expr.expr -> bool + + (** The Sort of the term. *) val get_sort : Expr.expr -> Sort.sort + + (** Indicates whether the term has Boolean sort. *) val is_bool : Expr.expr -> bool + + (** Indicates whether the term represents a constant. *) val is_const : Expr.expr -> bool + + (** Indicates whether the term is the constant true. *) val is_true : Expr.expr -> bool + + (** Indicates whether the term is the constant false. *) val is_false : Expr.expr -> bool + + (** Indicates whether the term is an equality predicate. *) val is_eq : Expr.expr -> bool + + (** Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). *) val is_distinct : Expr.expr -> bool + + (** Indicates whether the term is a ternary if-then-else term *) val is_ite : Expr.expr -> bool + + (** Indicates whether the term is an n-ary conjunction *) val is_and : Expr.expr -> bool + + (** Indicates whether the term is an n-ary disjunction *) val is_or : Expr.expr -> bool + + (** Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) *) val is_iff : Expr.expr -> bool + + (** Indicates whether the term is an exclusive or *) val is_xor : Expr.expr -> bool + + (** Indicates whether the term is a negation *) val is_not : Expr.expr -> bool + + (** Indicates whether the term is an implication *) val is_implies : Expr.expr -> bool + + (** 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. *) val is_label : Expr.expr -> bool + + (** 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. + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) *) + val is_label_lit : Expr.expr -> bool + + (** 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. *) val is_oeq : Expr.expr -> bool + + (** Creates a new constant. *) val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + + (** Creates a new constant. *) val mk_const_s : context -> string -> Sort.sort -> expr + + (** Creates a constant from the func_decl. *) val mk_const_f : context -> FuncDecl.func_decl -> expr + + (** Creates a fresh constant with a name prefixed with a string. *) val mk_fresh_const : context -> string -> Sort.sort -> expr + + (** Create a new function application. *) val mk_app : context -> FuncDecl.func_decl -> Expr.expr array -> expr + + (** Create a numeral of a given sort. + @return A Term with the goven value and sort *) val mk_numeral_string : context -> string -> Sort.sort -> expr + + (** Create a numeral 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. + @return A Term with the given value and sort *) val mk_numeral_int : context -> int -> Sort.sort -> expr end +(** Boolean expressions *) module Boolean : sig type bool_sort = BoolSort of Sort.sort @@ -562,23 +605,53 @@ sig val bool_sort_of_sort : Sort.sort -> bool_sort val bool_expr_of_expr : Expr.expr -> bool_expr + (** Create a Boolean sort *) val mk_sort : context -> bool_sort + + (** Create a Boolean constant. *) val mk_const : context -> Symbol.symbol -> bool_expr + + (** Create a Boolean constant. *) val mk_const_s : context -> string -> bool_expr + + (** The true Term. *) val mk_true : context -> bool_expr + + (** The false Term. *) val mk_false : context -> bool_expr + + (** Creates a Boolean value. *) val mk_val : context -> bool -> bool_expr + + (** Creates the equality between two expr's. *) val mk_eq : context -> Expr.expr -> Expr.expr -> bool_expr + + (** Creates a distinct term. *) val mk_distinct : context -> Expr.expr array -> bool_expr + + (** Mk an expression representing not(a). *) val mk_not : context -> bool_expr -> bool_expr + + (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) val mk_ite : context -> bool_expr -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 iff t2. *) val mk_iff : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 -> t2. *) val mk_implies : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 xor t2. *) val mk_xor : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing the AND of args *) val mk_and : context -> bool_expr array -> bool_expr + + (** Create an expression representing the OR of args *) val mk_or : context -> bool_expr array -> bool_expr end +(** Quantifier expressions *) module Quantifier : sig type quantifier = Quantifier of Expr.expr @@ -586,7 +659,11 @@ sig val expr_of_quantifier : quantifier -> Expr.expr val quantifier_of_expr : Expr.expr -> quantifier + (** Quantifier patterns + 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. *) module Pattern : sig type pattern = Pattern of AST.ast @@ -594,65 +671,94 @@ sig val ast_of_pattern : pattern -> AST.ast val pattern_of_ast : AST.ast -> pattern + (** The number of terms in the pattern. *) val get_num_terms : pattern -> int + + (** The terms in the pattern. *) val get_terms : pattern -> Expr.expr array + + (** A string representation of the pattern. *) val to_string : pattern -> string end + + (** 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 : expr ) appears, the higher is its + index. *) val get_index : Expr.expr -> int + + (** Indicates whether the quantifier is universal. *) val is_universal : quantifier -> bool + + (** Indicates whether the quantifier is existential. *) val is_existential : quantifier -> bool + + (** The weight of the quantifier. *) val get_weight : quantifier -> int + + (** The number of patterns. *) val get_num_patterns : quantifier -> int + + (** The patterns. *) val get_patterns : quantifier -> Pattern.pattern array + + (** The number of no-patterns. *) val get_num_no_patterns : quantifier -> int + + (** The no-patterns. *) val get_no_patterns : quantifier -> Pattern.pattern array - val get_num_bound : quantifier -> int + + (** The number of bound variables. *) + val get_num_bound : quantifier -> int + + (** The symbols for the bound variables. *) val get_bound_variable_names : quantifier -> Symbol.symbol array + + (** The sorts of the bound variables. *) val get_bound_variable_sorts : quantifier -> Sort.sort array + + (** The body of the quantifier. *) val get_body : quantifier -> Boolean.bool_expr + + (** Creates a new bound variable. *) val mk_bound : context -> int -> Sort.sort -> Expr.expr + + (** Create a quantifier pattern. *) val mk_pattern : context -> Expr.expr array -> Pattern.pattern - val mk_forall : - context -> - Sort.sort array -> - Symbol.symbol array -> - Expr.expr -> - int option -> - Pattern.pattern array -> - Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier - val mk_forall_const : - context -> - Expr.expr array -> - Expr.expr -> - int option -> - Pattern.pattern array -> - Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier - val mk_exists : - context -> - Sort.sort array -> - Symbol.symbol array -> - Expr.expr -> - int option -> - Pattern.pattern array -> - Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier - val mk_exists_const : - context -> - Expr.expr array -> - Expr.expr -> - int option -> - Pattern.pattern array -> - Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier - val mk_quantifier : - context -> - bool -> - Expr.expr array -> - Expr.expr -> - int option -> - Pattern.pattern array -> - Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a universal Quantifier. *) + val mk_forall : context -> Sort.sort array -> Symbol.symbol array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a universal Quantifier. *) + val mk_forall_const : context -> Expr.expr array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create an existential Quantifier. *) + val mk_exists : context -> Sort.sort array -> Symbol.symbol array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create an existential Quantifier. *) + val mk_exists_const : context -> Expr.expr array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a Quantifier. *) + val mk_quantifier : context -> Sort.sort array -> Symbol.symbol array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a Quantifier. *) + val mk_quantifier : context -> bool -> Expr.expr array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier end +(** Functions to manipulate Array expressions *) module Array_ : sig type array_sort = ArraySort of Sort.sort @@ -664,48 +770,159 @@ sig val array_expr_of_expr : Expr.expr -> array_expr + (** Create a new array sort. *) val mk_sort : context -> Sort.sort -> Sort.sort -> 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. *) val is_store : Expr.expr -> bool + + (** Indicates whether the term is an array select. *) val is_select : Expr.expr -> bool + + (** 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. *) val is_constant_array : Expr.expr -> bool + + (** Indicates whether the term is a default array. + For example default(const(v)) = v. The function is unary. *) val is_default_array : Expr.expr -> bool + + (** 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. *) val is_array_map : Expr.expr -> bool + + (** 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. *) val is_as_array : Expr.expr -> bool + + (** Indicates whether the term is of an array sort. *) val is_array : Expr.expr -> bool + + (** The domain of the array sort. *) val get_domain : array_sort -> Sort.sort + + (** The range of the array sort. *) val get_range : array_sort -> Sort.sort + + (** Create an array constant. *) val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> array_expr + + (** Create an array constant. *) val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> array_expr - val mk_select : context -> array_expr -> Expr.expr -> Expr.expr -> array_expr + + (** 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. + {!Array_.mk_sort} + {!mk_store} *) + val mk_select : context -> array_expr -> Expr.expr -> array_expr + + (** 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). + {!Array_.mk_sort} + {!mk_select} *) + val mk_store : context -> array_expr -> Expr.expr -> Expr.expr -> array_expr + + (** Create a constant array. + + The resulting term is an array, such that a selecton an arbitrary index + produces the value v. + {!Array_.mk_sort} + {!mk_select} *) val mk_const_array : context -> Sort.sort -> Expr.expr -> array_expr + + (** 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]. + {!Array_.mk_sort} + {!mk_select} + {!mk_store} *) val mk_map : context -> FuncDecl.func_decl -> array_expr array -> array_expr + + (** Access the array default value. + + Produces the default range value, for arrays that can be represented as + finite maps with a default range value. *) val mk_term_array : context -> array_expr -> array_expr end +(** Functions to manipulate Set expressions *) module Set : sig type set_sort = SetSort of Sort.sort val sort_of_set_sort : set_sort -> Sort.sort - val is_union : Expr.expr -> bool - val is_intersect : Expr.expr -> bool - val is_difference : Expr.expr -> bool - val is_complement : Expr.expr -> bool - val is_subset : Expr.expr -> bool + (** Create a set type. *) val mk_sort : context -> Sort.sort -> set_sort + + (** Indicates whether the term is set union *) + val is_union : Expr.expr -> bool + + (** Indicates whether the term is set intersection *) + val is_intersect : Expr.expr -> bool + + (** Indicates whether the term is set difference *) + val is_difference : Expr.expr -> bool + + (** Indicates whether the term is set complement *) + val is_complement : Expr.expr -> bool + + (** Indicates whether the term is set subset *) + val is_subset : Expr.expr -> bool + + (** Create an empty set. *) val mk_empty : context -> Sort.sort -> Expr.expr + + (** Create the full set. *) val mk_full : context -> Sort.sort -> Expr.expr + + (** Add an element to the set. *) val mk_set_add : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Remove an element from a set. *) val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Take the union of a list of sets. *) val mk_union : context -> Expr.expr array -> Expr.expr + + (** Take the intersection of a list of sets. *) val mk_intersection : context -> Expr.expr array -> Expr.expr + + (** Take the difference between two sets. *) val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Take the complement of a set. *) val mk_complement : context -> Expr.expr -> Expr.expr + + (** Check for set membership. *) val mk_membership : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Check for subsetness of sets. *) val mk_subset : context -> Expr.expr -> Expr.expr -> Expr.expr end +(** Functions to manipulate Finite Domain expressions *) module FiniteDomain : sig type finite_domain_sort = FiniteDomainSort of Sort.sort @@ -713,13 +930,24 @@ sig val sort_of_finite_domain_sort : finite_domain_sort -> Sort.sort val finite_domain_sort_of_sort : Sort.sort -> finite_domain_sort + (** Create a new finite domain sort. *) val mk_sort : context -> Symbol.symbol -> int -> finite_domain_sort + + (** Create a new finite domain sort. *) val mk_sort_s : context -> string -> int -> finite_domain_sort + + (** Indicates whether the term is of an array sort. *) val is_finite_domain : Expr.expr -> bool + + (** Indicates whether the term is a less than predicate over a finite domain. *) val is_lt : Expr.expr -> bool + + (** The size of the finite domain sort. *) val get_size : finite_domain_sort -> int end + +(** Functions to manipulate Relation expressions *) module Relation : sig type relation_sort = RelationSort of Sort.sort @@ -727,24 +955,92 @@ sig val sort_of_relation_sort : relation_sort -> Sort.sort val relation_sort_of_sort : Sort.sort -> relation_sort + (** Indicates whether the term is of a relation sort. *) val is_relation : Expr.expr -> bool + + (** 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. *) val is_store : Expr.expr -> bool + + (** Indicates whether the term is an empty relation *) val is_empty : Expr.expr -> bool + + (** Indicates whether the term is a test for the emptiness of a relation *) val is_is_empty : Expr.expr -> bool + + (** Indicates whether the term is a relational join *) val is_join : Expr.expr -> bool + + (** Indicates whether the term is the union or convex hull of two relations. + The function takes two arguments. *) val is_union : Expr.expr -> bool + + (** Indicates whether the term is the widening of two relations + The function takes two arguments. *) val is_widen : Expr.expr -> bool + + (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). + The function takes one argument. *) val is_project : Expr.expr -> bool + + (** 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. *) val is_filter : Expr.expr -> bool + + (** 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. *) val is_negation_filter : Expr.expr -> bool + + (** 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. *) val is_rename : Expr.expr -> bool + + (** Indicates whether the term is the complement of a relation *) val is_complement : Expr.expr -> bool + + (** 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. *) val is_select : Expr.expr -> bool + + (** 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 {!is_union} + to perform destructive updates to the first argument. *) val is_clone : Expr.expr -> bool + + (** The arity of the relation sort. *) val get_arity : relation_sort -> int + + (** The sorts of the columns of the relation sort. *) val get_column_sorts : relation_sort -> relation_sort array end +(** Functions to manipulate Datatype expressions *) module Datatype : sig type datatype_sort = DatatypeSort of Sort.sort @@ -755,74 +1051,136 @@ sig val expr_of_datatype_expr : datatype_expr -> Expr.expr val datatype_expr_of_expr : Expr.expr -> datatype_expr + (** Datatype Constructors *) module Constructor : sig - (** Constructors *) type constructor - val get_n : constructor -> int - val constructor_decl : constructor -> FuncDecl.func_decl - val tester_decl : constructor -> FuncDecl.func_decl - val accessor_decls : constructor -> FuncDecl.func_decl array + (** The number of fields of the constructor. *) val get_num_fields : constructor -> int + + (** The function declaration of the constructor. *) val get_constructor_decl : constructor -> FuncDecl.func_decl + + (** The function declaration of the tester. *) val get_tester_decl : constructor -> FuncDecl.func_decl + + (** The function declarations of the accessors *) val get_accessor_decls : constructor -> FuncDecl.func_decl array end + (** Create a datatype 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. *) val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> Constructor.constructor + + (** Create a datatype 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. *) val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> Constructor.constructor + + (** Create a new datatype sort. *) val mk_sort : context -> Symbol.symbol -> Constructor.constructor array -> datatype_sort + + (** Create a new datatype sort. *) val mk_sort_s : context -> string -> Constructor.constructor array -> datatype_sort + + (** Create mutually recursive datatypes. *) val mk_sorts : context -> Symbol.symbol array -> Constructor.constructor array array -> datatype_sort array + + (** Create mutually recursive data-types. *) val mk_sorts_s : context -> string array -> Constructor.constructor array array -> datatype_sort array + + + (** The number of constructors of the datatype sort. *) val get_num_constructors : datatype_sort -> int + + (** The constructors. *) val get_constructors : datatype_sort -> FuncDecl.func_decl array + + (** The recognizers. *) val get_recognizers : datatype_sort -> FuncDecl.func_decl array + + (** The constructor accessors. *) val get_accessors : datatype_sort -> FuncDecl.func_decl array array end +(** Functions to manipulate Enumeration expressions *) module Enumeration : sig type enum_sort = EnumSort of Sort.sort val sort_of_enum_sort : enum_sort -> Sort.sort + (** Create a new enumeration sort. *) val mk_sort : context -> Symbol.symbol -> Symbol.symbol array -> enum_sort + + (** Create a new enumeration sort. *) val mk_sort_s : context -> string -> string array -> enum_sort + + (** The function declarations of the constants in the enumeration. *) val get_const_decls : enum_sort -> FuncDecl.func_decl array + + (** The test predicates for the constants in the enumeration. *) val get_tester_decls : enum_sort -> FuncDecl.func_decl array end +(** Functions to manipulate List expressions *) module List_ : sig type list_sort = ListSort of Sort.sort val sort_of_list_sort : list_sort -> Sort.sort + (** Create a new list sort. *) val mk_sort : context -> Symbol.symbol -> Sort.sort -> list_sort + + (** Create a new list sort. *) val mk_list_s : context -> string -> Sort.sort -> list_sort + + (** The declaration of the nil function of this list sort. *) val get_nil_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the isNil function of this list sort. *) val get_is_nil_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the cons function of this list sort. *) val get_cons_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the isCons function of this list sort. *) val get_is_cons_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the head function of this list sort. *) val get_head_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the tail function of this list sort. *) val get_tail_decl : list_sort -> FuncDecl.func_decl + + (** The empty list. *) val nil : list_sort -> Expr.expr end +(** Functions to manipulate Tuple expressions *) module Tuple : sig type tuple_sort = TupleSort of Sort.sort val sort_of_tuple_sort : tuple_sort -> Sort.sort + (** Create a new tuple sort. *) val mk_sort : context -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> tuple_sort + + (** The constructor function of the tuple. *) val get_mk_decl : tuple_sort -> FuncDecl.func_decl + + (** The number of fields in the tuple. *) val get_num_fields : tuple_sort -> int + + (** The field declarations. *) val get_field_decls : tuple_sort -> FuncDecl.func_decl array end +(** Functions to manipulate arithmetic expressions *) module rec Arithmetic : sig type arith_sort = ArithSort of Sort.sort @@ -833,6 +1191,7 @@ sig val expr_of_arith_expr : Arithmetic.arith_expr -> Expr.expr val arith_expr_of_expr : Expr.expr -> Arithmetic.arith_expr + (** Integer Arithmetic *) module rec Integer : sig type int_sort = IntSort of arith_sort @@ -845,20 +1204,59 @@ sig val int_expr_of_int_num : Arithmetic.Integer.int_num -> Arithmetic.Integer.int_expr val int_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Integer.int_expr val int_num_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.Integer.int_num - + + (** Create a new integer sort. *) val mk_sort : context -> int_sort + + (** Retrieve the int value. *) val get_int : int_num -> int + + (** Returns a string representation of the numeral. *) val to_string : int_num -> string + + (** Creates an integer constant. *) val mk_int_const : context -> Symbol.symbol -> int_expr + + (** Creates an integer constant. *) val mk_int_const_s : context -> string -> int_expr + + (** Create an expression representing t1 mod t2. + The arguments must have int type. *) val mk_mod : context -> int_expr -> int_expr -> int_expr + + (** Create an expression representing t1 rem t2. + The arguments must have int type. *) val mk_rem : context -> int_expr -> int_expr -> int_expr + + (** Create an integer numeral. *) val mk_int_numeral_s : context -> string -> int_num + + (** Create an integer numeral. + @return A Term with the given value and sort Integer *) val mk_int_numeral_i : context -> int -> int_num + + (** 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. *) val mk_int2real : context -> int_expr -> Real.real_expr + + (** Create an n-bit bit-vector from an 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. *) val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr end + (** Real Arithmetic *) and Real : sig type real_sort = RealSort of arith_sort @@ -872,20 +1270,52 @@ sig val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num + (** Create a real sort. *) val mk_sort : context -> real_sort + + (** The numerator of a rational numeral. *) val get_numerator : rat_num -> Integer.int_num + + (** The denominator of a rational numeral. *) val get_denominator : rat_num -> Integer.int_num + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as indicated by the int argument.*) val to_decimal_string : rat_num -> int -> string + + (** Returns a string representation of the numeral. *) val to_string : rat_num -> string + + (** Creates a real constant. *) val mk_real_const : context -> Symbol.symbol -> real_expr + + (** Creates a real constant. *) val mk_real_const_s : context -> string -> real_expr + + (** Create a real numeral from a fraction. + @return A Term with rational value and sort Real + {!mk_numeral_s} *) val mk_numeral_nd : context -> int -> int -> rat_num + + (** Create a real numeral. + @return A Term with the given value and sort Real *) val mk_numeral_s : context -> string -> rat_num + + (** Create a real numeral. + @return A Term with the given value and sort Real *) val mk_numeral_i : context -> int -> rat_num + + (** Creates an expression that checks whether a real number is an integer. *) val mk_is_integer : context -> real_expr -> Boolean.bool_expr + + (** 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. *) val mk_real2int : context -> real_expr -> Integer.int_expr end + (** Algebraic Numbers *) and AlgebraicNumber : sig type algebraic_num = AlgebraicNum of arith_expr @@ -893,45 +1323,121 @@ sig val arith_expr_of_algebraic_num : Arithmetic.AlgebraicNumber.algebraic_num -> Arithmetic.arith_expr val algebraic_num_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.AlgebraicNumber.algebraic_num + (** Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) val to_upper : algebraic_num -> int -> Real.rat_num + + (** Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) val to_lower : algebraic_num -> int -> Real.rat_num + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as the int argument provided.*) val to_decimal_string : algebraic_num -> int -> string + + (** Returns a string representation of the numeral. *) val to_string : algebraic_num -> string end + (** Indicates whether the term is of integer sort. *) val is_int : Expr.expr -> bool + + (** Indicates whether the term is an arithmetic numeral. *) val is_arithmetic_numeral : Expr.expr -> bool + + (** Indicates whether the term is a less-than-or-equal *) val is_le : Expr.expr -> bool + + (** Indicates whether the term is a greater-than-or-equal *) val is_ge : Expr.expr -> bool + + (** Indicates whether the term is a less-than *) val is_lt : Expr.expr -> bool + + (** Indicates whether the term is a greater-than *) val is_gt : Expr.expr -> bool + + (** Indicates whether the term is addition (binary) *) val is_add : Expr.expr -> bool + + (** Indicates whether the term is subtraction (binary) *) val is_sub : Expr.expr -> bool + + (** Indicates whether the term is a unary minus *) val is_uminus : Expr.expr -> bool + + (** Indicates whether the term is multiplication (binary) *) val is_mul : Expr.expr -> bool + + (** Indicates whether the term is division (binary) *) val is_div : Expr.expr -> bool + + (** Indicates whether the term is integer division (binary) *) val is_idiv : Expr.expr -> bool + + (** Indicates whether the term is remainder (binary) *) val is_remainder : Expr.expr -> bool + + (** Indicates whether the term is modulus (binary) *) val is_modulus : Expr.expr -> bool + + (** Indicates whether the term is a coercion of integer to real (unary) *) val is_inttoreal : Expr.expr -> bool + + (** Indicates whether the term is a coercion of real to integer (unary) *) val is_real_to_int : Expr.expr -> bool + + (** Indicates whether the term is a check that tests whether a real is integral (unary) *) val is_real_is_int : Expr.expr -> bool + + (** Indicates whether the term is of sort real. *) val is_real : Expr.expr -> bool + + (** Indicates whether the term is an integer numeral. *) val is_int_numeral : Expr.expr -> bool + + (** Indicates whether the term is a real numeral. *) val is_rat_num : Expr.expr -> bool + + (** Indicates whether the term is an algebraic number *) val is_algebraic_number : Expr.expr -> bool + + (** Create an expression representing t[0] + t[1] + .... *) val mk_add : context -> arith_expr array -> arith_expr + + (** Create an expression representing t[0] * t[1] * .... *) val mk_mul : context -> arith_expr array -> arith_expr + + (** Create an expression representing t[0] - t[1] - .... *) val mk_sub : context -> arith_expr array -> arith_expr + + (** Create an expression representing -t. *) val mk_unary_minus : context -> arith_expr -> arith_expr + + (** Create an expression representing t1 / t2. *) val mk_div : context -> arith_expr -> arith_expr -> arith_expr + + (** Create an expression representing t1 ^ t2. *) val mk_power : context -> arith_expr -> arith_expr -> arith_expr + + (** Create an expression representing t1 < t2 *) val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 <= t2 *) val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 > t2 *) val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 >= t2 *) val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr end +(** Functions to manipulate bit-vector expressions *) and BitVector : sig type bitvec_sort = BitVecSort of Sort.sort @@ -945,280 +1451,1229 @@ sig val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num + (** Create a new bit-vector sort. *) val mk_sort : context -> int -> bitvec_sort + + (** Indicates whether the terms is of bit-vector sort. *) val is_bv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector numeral *) val is_bv_numeral : Expr.expr -> bool + + (** Indicates whether the term is a one-bit bit-vector with value one *) val is_bv_bit1 : Expr.expr -> bool + + (** Indicates whether the term is a one-bit bit-vector with value zero *) val is_bv_bit0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unary minus *) val is_bv_uminus : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector addition (binary) *) val is_bv_add : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector subtraction (binary) *) val is_bv_sub : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector multiplication (binary) *) val is_bv_mul : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed division (binary) *) val is_bv_sdiv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned division (binary) *) val is_bv_udiv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed remainder (binary) *) val is_bv_SRem : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) val is_bv_urem : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed modulus *) val is_bv_smod : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed division by zero *) val is_bv_sdiv0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned division by zero *) val is_bv_udiv0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed remainder by zero *) val is_bv_srem0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned remainder by zero *) val is_bv_urem0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed modulus by zero *) val is_bv_smod0 : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) val is_bv_ule : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector less-than-or-equal *) val is_bv_sle : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) val is_bv_uge : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) val is_bv_sge : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector less-than *) val is_bv_ult : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector less-than *) val is_bv_slt : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector greater-than *) val is_bv_ugt : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector greater-than *) val is_bv_sgt : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise AND *) val is_bv_and : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise OR *) val is_bv_or : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NOT *) val is_bv_not : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise XOR *) val is_bv_xor : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NAND *) val is_bv_nand : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NOR *) val is_bv_nor : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise XNOR *) val is_bv_xnor : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector concatenation (binary) *) val is_bv_concat : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector sign extension *) val is_bv_signextension : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector zero extension *) val is_bv_zeroextension : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector extraction *) val is_bv_extract : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector repetition *) val is_bv_repeat : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector reduce OR *) val is_bv_reduceor : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector reduce AND *) val is_bv_reduceand : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector comparison *) val is_bv_comp : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector shift left *) val is_bv_shiftleft : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector logical shift right *) val is_bv_shiftrightlogical : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector arithmetic shift left *) val is_bv_shiftrightarithmetic : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector rotate left *) val is_bv_rotateleft : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector rotate right *) val is_bv_rotateright : Expr.expr -> bool + + (** 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. *) val is_bv_rotateleftextended : Expr.expr -> bool + + (** 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. *) val is_bv_rotaterightextended : Expr.expr -> bool + + (** 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. *) + + (** 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. *) val is_int_to_bv : Expr.expr -> bool + + (** 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. *) val is_bv_to_int : Expr.expr -> bool + + (** 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))) *) val is_bv_carry : Expr.expr -> bool + + (** 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) *) val is_bv_xor3 : Expr.expr -> bool + + (** The size of a bit-vector sort. *) val get_size : bitvec_sort -> int + + (** Retrieve the int value. *) val get_int : bitvec_num -> int + + (** Returns a string representation of the numeral. *) val to_string : bitvec_num -> string + + (** Creates a bit-vector constant. *) val mk_const : context -> Symbol.symbol -> int -> bitvec_expr + + (** Creates a bit-vector constant. *) val mk_const_s : context -> string -> int -> bitvec_expr + + (** Bitwise negation. + The argument must have a bit-vector sort. *) val mk_not : context -> bitvec_expr -> Expr.expr + + (** Take conjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. *) val mk_redand : context -> bitvec_expr -> Expr.expr + + (** Take disjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. *) val mk_redor : context -> bitvec_expr -> Expr.expr + + (** Bitwise conjunction. + The arguments must have a bit-vector sort. *) val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise disjunction. + The arguments must have a bit-vector sort. *) val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise XOR. + The arguments must have a bit-vector sort. *) val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise NAND. + The arguments must have a bit-vector sort. *) val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise NOR. + The arguments must have a bit-vector sort. *) val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise XNOR. + The arguments must have a bit-vector sort. *) val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Standard two's complement unary minus. + The arguments must have a bit-vector sort. *) val mk_neg : context -> bitvec_expr -> bitvec_expr + + (** Two's complement addition. + The arguments must have the same bit-vector sort. *) val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Two's complement subtraction. + The arguments must have the same bit-vector sort. *) val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Two's complement multiplication. + The arguments must have the same bit-vector sort. *) val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Unsigned less-than + + The arguments must have the same bit-vector sort. *) val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed less-than + + The arguments must have the same bit-vector sort. *) val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned less-than or equal to. + + The arguments must have the same bit-vector sort. *) val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed less-than or equal to. + + The arguments must have the same bit-vector sort. *) val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned greater than or equal to. + + The arguments must have the same bit-vector sort. *) val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed greater than or equal to. + + The arguments must have the same bit-vector sort. *) val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned greater-than. + + The arguments must have the same bit-vector sort. *) val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed greater-than. + + The arguments must have the same bit-vector sort. *) val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** 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). *) val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bit-vector extraction. + + Extract the bits between two limits from a bitvector of + size m to yield a new bitvector of size n, where + n = high - low + 1. *) val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + + (** 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. *) val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + + (** 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. *) val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + + (** Bit-vector repetition. *) val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + + (** Shift left. + + It is equivalent to multiplication by 2^x where \c x is the value of third 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.*) val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Logical shift right + + It is equivalent to unsigned division by 2^x where \c x is the value of the third 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. *) val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Rotate Left. + Rotate bits of \c t to the left \c i times. *) + val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr + + (** Rotate Right. + Rotate bits of \c t to the right \c i times.*) + val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr + + (** Rotate Left. + Rotate bits of the second argument to the left.*) + val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Rotate Right. + Rotate bits of the second argument to the right. *) + val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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 the argument. + 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.*) val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + + (** Create a predicate that checks that the bit-wise addition does not overflow. + + The arguments must be of bit-vector sort. *) val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise addition does not underflow. + + The arguments must be of bit-vector sort. *) val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise subtraction does not overflow. + + The arguments must be of bit-vector sort. *) val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise subtraction does not underflow. + + The arguments must be of bit-vector sort. *) val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise signed division does not overflow. + + The arguments must be of bit-vector sort. *) val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise negation does not overflow. + + The arguments must be of bit-vector sort. *) val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise multiplication does not overflow. + + The arguments must be of bit-vector sort. *) val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise multiplication does not underflow. + + The arguments must be of bit-vector sort. *) val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a bit-vector numeral. *) val mk_numeral : context -> string -> int -> bitvec_num end +(** Functions to manipulate proof expressions *) module Proof : sig + (** Indicates whether the term is a Proof for the expression 'true'. *) val is_true : Expr.expr -> bool + + (** Indicates whether the term is a proof for a fact asserted by the user. *) val is_asserted : Expr.expr -> bool + + (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) val is_goal : Expr.expr -> bool + + (** 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). *) val is_modus_ponens : Expr.expr -> bool + + (** 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'. *) val is_reflexivity : Expr.expr -> bool + + (** 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. *) val is_symmetry : Expr.expr -> bool + + (** 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) *) val is_transitivity : Expr.expr -> bool + + (** 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. *) val is_Transitivity_star : Expr.expr -> bool + + (** 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. *) val is_monotonicity : Expr.expr -> bool + + (** 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)) *) val is_quant_intro : Expr.expr -> bool + + (** 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. *) val is_distributivity : Expr.expr -> bool + + (** 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 *) val is_and_elimination : Expr.expr -> bool + + (** 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) *) val is_or_elimination : Expr.expr -> bool + + (** 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 : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) *) val is_rewrite : Expr.expr -> bool + + (** 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) *) val is_rewrite_star : Expr.expr -> bool + + (** 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. *) val is_pull_quant : Expr.expr -> bool + + (** 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 *) val is_pull_quant_star : Expr.expr -> bool + + (** 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 *) val is_push_quant : Expr.expr -> bool + + (** 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. *) val is_elim_unused_vars : Expr.expr -> bool + + (** Indicates whether the term is a proof for destructive equality resolution + + A proof for destructive equality resolution: + (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. + + This proof object has no antecedents. + + Several variables can be eliminated simultaneously. *) val is_der : Expr.expr -> bool + + (** Indicates whether the term is a proof for quantifier instantiation + + A proof of (or (not (forall (x) (P x))) (P a)) *) val is_quant_inst : Expr.expr -> bool + + (** Indicates whether the term is a hypthesis marker. + Mark a hypothesis in a natural deduction style proof. *) val is_hypothesis : Expr.expr -> bool + + (** 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. *) val is_lemma : Expr.expr -> bool + + (** 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') *) val is_unit_resolution : Expr.expr -> bool + + (** Indicates whether the term is a proof by iff-true + + T1: p + [iff-true T1]: (iff p true) *) val is_iff_true : Expr.expr -> bool + + (** Indicates whether the term is a proof by iff-false + + T1: (not p) + [iff-false T1]: (iff p false) *) val is_iff_false : Expr.expr -> bool + + (** 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. *) val is_commutativity : Expr.expr -> bool + + (** 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). *) val is_def_axiom : Expr.expr -> bool + + (** 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) *) val is_def_intro : Expr.expr -> bool + + (** 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. *) val is_apply_def : Expr.expr -> bool + + (** Indicates whether the term is a proof iff-oeq + + T1: (iff p q) + [iff~ T1]: (~ p q) *) val is_iff_oeq : Expr.expr -> bool + + (** 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'. *) val is_nnf_pos : Expr.expr -> bool + + (** 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'))) *) val is_nnf_neg : Expr.expr -> bool + + (** 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. *) val is_nnf_star : Expr.expr -> bool + + (** 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. *) val is_cnf_star : Expr.expr -> bool + + (** Indicates whether the term is a proof for a Skolemization step + + Proof for: + + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + + This proof object has no antecedents. *) val is_skolemize : Expr.expr -> bool + + (** 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 *) val is_modus_ponens_oeq : Expr.expr -> bool + + (** 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. *) val is_theory_lemma : Expr.expr -> bool end +(** Goals + A goal (aka problem). A goal is essentially a + of formulas, that can be solved and/or transformed using + tactics and solvers. *) module Goal : sig type goal + (** 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. *) val get_precision : goal -> Z3enums.goal_prec + + (** Indicates whether the goal is precise. *) val is_precise : goal -> bool + + (** Indicates whether the goal is an under-approximation. *) val is_underapproximation : goal -> bool + + (** Indicates whether the goal is an over-approximation. *) val is_overapproximation : goal -> bool + + (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) val is_garbage : goal -> bool + + (** Adds the constraints to the given goal. *) val assert_ : goal -> Boolean.bool_expr array -> unit + + (** Indicates whether the goal contains `false'. *) val is_inconsistent : goal -> bool + + (** The depth of the goal. + This tracks how many transformations were applied to it. *) val get_depth : goal -> int + + (** Erases all formulas from the given goal. *) val reset : goal -> unit + + (** The number of formulas in the goal. *) val get_size : goal -> int + + (** The formulas in the goal. *) val get_formulas : goal -> Boolean.bool_expr array + + (** The number of formulas, subformulas and terms in the goal. *) val get_num_exprs : goal -> int + + (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) val is_decided_sat : goal -> bool + + (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) val is_decided_unsat : goal -> bool + + (** Translates (copies) the Goal to another context.. *) val translate : goal -> context -> goal + + (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) val simplify : goal -> Params.params option -> goal + + (** Creates a new Goal. + + Note that the Context must have been created with proof generation support if + the fourth argument is set to true here. *) val mk_goal : context -> bool -> bool -> bool -> goal + + (** A string representation of the Goal. *) val to_string : goal -> string end +(** Models + + A Model contains interpretations (assignments) of constants and functions. *) module Model : sig type model + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. *) module FuncInterp : sig type func_interp - + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. *) module FuncEntry : sig type func_entry - + + (** Return the (symbolic) value of this entry. + *) val get_value : func_entry -> Expr.expr + + (** The number of arguments of the entry. + *) val get_num_args : func_entry -> int + + (** The arguments of the function entry. + *) val get_args : func_entry -> Expr.expr array + + (** A string representation of the function entry. + *) val to_string : func_entry -> string end + (** The number of entries in the function interpretation. *) val get_num_entries : func_interp -> int + + (** The entries in the function interpretation *) val get_entries : func_interp -> FuncEntry.func_entry array + + (** The (symbolic) `else' value of the function interpretation. *) val get_else : func_interp -> Expr.expr + + (** The arity of the function interpretation *) val get_arity : func_interp -> int + + (** A string representation of the function interpretation. *) val to_string : func_interp -> string end + (** Retrieves the interpretation (the assignment) of a func_decl in the model. + An expression if the function has an interpretation in the model, null otherwise. *) val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option + + (** Retrieves the interpretation (the assignment) of an expression in the model. + An expression if the constant has an interpretation in the model, null otherwise. *) val get_const_interp_e : model -> Expr.expr -> Expr.expr option + + (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option + + (** The number of constant interpretations in the model. *) val get_num_consts : model -> int + + (** The function declarations of the constants in the model. *) val get_const_decls : model -> FuncDecl.func_decl array + + (** The number of function interpretations in the model. *) val get_num_funcs : model -> int + + (** The function declarations of the function interpretations in the model. *) val get_func_decls : model -> FuncDecl.func_decl array + + (** All symbols that have an interpretation in the model. *) val get_decls : model -> FuncDecl.func_decl array + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) exception ModelEvaluationFailedException of string + + (** Evaluates an expression in the current model. + + This function may fail if the argument contains quantifiers, + is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. + In this case a ModelEvaluationFailedException is thrown. + *) val eval : model -> Expr.expr -> bool -> Expr.expr + + (** Alias for eval. *) val evaluate : model -> Expr.expr -> bool -> Expr.expr + + (** The number of uninterpreted sorts that the model has an interpretation for. *) val get_num_sorts : model -> int + + (** 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. + {!get_num_sorts} + {!sort_universe} *) val get_sorts : model -> Sort.sort array + + (** The finite set of distinct values that represent the interpretation of a sort. + {!get_sorts} + @returns An array of expressions, where each is an element of the universe of the sort *) val sort_universe : model -> Sort.sort -> AST.ASTVector.ast_vector array + + (** Conversion of models to strings. + A string representation of the model. *) val to_string : model -> string end +(** Probes + + 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. +*) module Probe : sig type probe + (** Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) val apply : probe -> Goal.goal -> float + + (** The number of supported Probes. *) val get_num_probes : context -> int + + (** The names of all supported Probes. *) val get_probe_names : context -> string array + + (** Returns a string containing a description of the probe with the given name. *) val get_probe_description : context -> string -> string + + (** Creates a new Probe. *) val mk_probe : context -> string -> probe + + (** Create a probe that always evaluates to a float value. *) val const : context -> float -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is less than the value returned by second argument *) val lt : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is greater than the value returned by second argument *) val gt : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is less than or equal the value returned by second argument *) val le : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is greater than or equal the value returned by second argument *) val ge : context -> probe -> probe -> probe + + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is equal the value returned by second argument *) val eq : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when both of two probes evaluate to "true". *) val and_ : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when either of two probes evaluates to "true". *) val or_ : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when another probe does not evaluate to "true". *) val not_ : context -> probe -> probe end +(** Tactics + + Tactics are the basic building block for creating custom solvers for specific problem domains. + The complete list of tactics may be obtained using Context.get_num_tactics + and Context.get_tactic_names. + It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. +*) module Tactic : sig type tactic + (** Tactic application results + + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) module ApplyResult : sig type apply_result + (** The number of Subgoals. *) val get_num_subgoals : apply_result -> int + + (** Retrieves the subgoals from the apply_result. *) val get_subgoals : apply_result -> Goal.goal array + + (** Retrieves a subgoal from the apply_result. *) val get_subgoal : apply_result -> int -> Goal.goal + + (** Convert a model for a subgoal into a model for the original + goal g, that the ApplyResult was obtained from. + #return A model for g *) val convert_model : apply_result -> int -> Model.model -> Model.model + + (** A string representation of the ApplyResult. *) val to_string : apply_result -> string end + (** A string containing a description of parameters accepted by the tactic. *) val get_help : tactic -> string + + (** Retrieves parameter descriptions for Tactics. *) val get_param_descrs : tactic -> Params.ParamDescrs.param_descrs + + (** Apply the tactic to the goal. *) val apply : tactic -> Goal.goal -> Params.params option -> ApplyResult.apply_result + + (** The number of supported tactics. *) val get_num_tactics : context -> int + + (** The names of all supported tactics. *) val get_tactic_names : context -> string array + + (** Returns a string containing a description of the tactic with the given name. *) val get_tactic_description : context -> string -> string + + (** Creates a new Tactic. *) val mk_tactic : context -> string -> tactic + + (** Create a tactic that applies one tactic to a Goal and + then another one to every subgoal produced by the first one. *) val and_then : context -> tactic -> tactic -> tactic array -> tactic + + (** Create a tactic that first applies one tactic to a Goal and + if it fails then returns the result of another tactic applied to the Goal. *) val or_else : context -> tactic -> tactic -> tactic + + (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). + + If the tactic does not terminate within the timeout, then it fails. *) val try_for : context -> tactic -> int -> tactic + + (** Create a tactic that applies one tactic to a given goal if the probe + evaluates to true. + + If the probe evaluates to false, then the new tactic behaves like the skip tactic. *) val when_ : context -> Probe.probe -> tactic -> tactic + + (** Create a tactic that applies a tactic to a given goal if the probe + evaluates to true and another tactic otherwise. *) val cond : context -> Probe.probe -> tactic -> tactic -> tactic + + (** Create a tactic that keeps applying one tactic until the goal is not + modified anymore or the maximum number of iterations is reached. *) val repeat : context -> tactic -> int -> tactic + + (** Create a tactic that just returns the given goal. *) val skip : context -> tactic + + (** Create a tactic always fails. *) val fail : context -> tactic + + (** Create a tactic that fails if the probe evaluates to false. *) val fail_if : context -> Probe.probe -> tactic + + (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) + or trivially unsatisfiable (i.e., contains `false'). *) val fail_if_not_decided : context -> tactic + + (** Create a tactic that applies a tactic using the given set of parameters. *) val using_params : context -> tactic -> Params.params -> tactic + + (** Create a tactic that applies a tactic using the given set of parameters. + Alias for UsingParams*) val with_ : context -> tactic -> Params.params -> tactic + + (** Create a tactic that applies the given tactics in parallel. *) val par_or : context -> tactic array -> tactic + + (** Create a tactic that applies a tactic to a given goal and then another tactic + to every subgoal produced by the first one. The subgoals are processed in parallel. *) val par_and_then : context -> tactic -> tactic -> tactic + + (** Interrupt the execution of a Z3 procedure. + This procedure can be used to interrupt: solvers, simplifiers and tactics. *) val interrupt : context -> unit end +(** Solvers *) module Solver : sig type solver @@ -1226,108 +2681,388 @@ sig val string_of_status : status -> string + (** Objects that track statistical information about solvers. *) module Statistics : sig type statistics + (** Statistical data is organized into pairs of \[Key, Entry\], where every + Entry is either a floating point or integer value. + *) module Entry : sig type statistics_entry + (** The key of the entry. *) val get_key : statistics_entry -> string + + (** The int-value of the entry. *) val get_int : statistics_entry -> int + + (** The float-value of the entry. *) val get_float : statistics_entry -> float + + (** True if the entry is uint-valued. *) val is_int : statistics_entry -> bool + + (** True if the entry is double-valued. *) val is_float : statistics_entry -> bool + + (** The string representation of the the entry's value. *) val to_string_value : statistics_entry -> string + + (** The string representation of the entry (key and value) *) val to_string : statistics_entry -> string end + (** A string representation of the statistical data. *) val to_string : statistics -> string + + (** The number of statistical data. *) val get_size : statistics -> int + + (** The data entries. *) val get_entries : statistics -> Entry.statistics_entry array + + (** The statistical counters. *) val get_keys : statistics -> string array + + (** The value of a particular statistical counter. *) val get : statistics -> string -> Entry.statistics_entry option end + (** A string that describes all available solver parameters. *) val get_help : solver -> string + + (** Sets the solver parameters. *) val set_parameters : solver -> Params.params -> unit + + (** Retrieves parameter descriptions for solver. *) val get_param_descrs : solver -> Params.ParamDescrs.param_descrs + + (** The current number of backtracking points (scopes). + {!pop} + {!push} *) val get_num_scopes : solver -> int + + (** Creates a backtracking point. + {!pop} *) val push : solver -> unit + + (** Backtracks a number of backtracking points. + Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} + {!push} *) val pop : solver -> int -> unit + + (** Resets the Solver. + This removes all assertions from the solver. *) val reset : solver -> unit + + (** Assert a constraint (or multiple) into the solver. *) val assert_ : solver -> Boolean.bool_expr array -> unit + + (** * Assert multiple constraints (cs) into the solver, and track them (in the + * unsat) core + * using the Boolean constants in ps. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) + val assert_and_track_a : solver -> Boolean.bool_expr array -> Boolean.bool_expr array -> unit + + (** * Assert a constraint (c) into the solver, and track it (in the unsat) core + * using the Boolean constant p. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) val assert_and_track : solver -> Boolean.bool_expr -> Boolean.bool_expr -> unit + + (** The number of assertions in the solver. *) val get_num_assertions : solver -> int + + (** The set of asserted formulas. *) val get_assertions : solver -> Boolean.bool_expr array + + (** Checks whether the assertions in the solver are consistent or not. + + {!Model} + {!get_unsat_core} + {!Proof} *) val check : solver -> Boolean.bool_expr array -> status + + (** The model of the last Check. + + The result is None if Check was not invoked before, + if its results was not SATISFIABLE, or if model production is not enabled. *) val get_model : solver -> Model.model option + + (** 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. *) val get_proof : solver -> Expr.expr option + + (** 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. *) val get_unsat_core : solver -> AST.ASTVector.ast_vector array + + (** A brief justification of why the last call to Check returned UNKNOWN. *) val get_reason_unknown : solver -> string + + (** Solver statistics. *) val get_statistics : solver -> Statistics.statistics + + (** 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. *) val mk_solver : context -> Symbol.symbol option -> solver + + (** Creates a new (incremental) solver. + {!mk_solver} *) val mk_solver_s : context -> string -> solver + + (** Creates a new (incremental) solver. *) val mk_simple_solver : context -> solver + + (** 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. *) val mk_solver_t : context -> Tactic.tactic -> solver + + (** A string representation of the solver. *) val to_string : solver -> string end +(** Fixedpoint solving *) module Fixedpoint : sig type fixedpoint + (** A string that describes all available fixedpoint solver parameters. *) val get_help : fixedpoint -> string + + (** Sets the fixedpoint solver parameters. *) val set_params : fixedpoint -> Params.params -> unit + + (** Retrieves parameter descriptions for Fixedpoint solver. *) val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs + + (** Assert a constraints into the fixedpoint solver. *) val assert_ : fixedpoint -> Boolean.bool_expr array -> unit + + (** Register predicate as recursive relation. *) val register_relation : fixedpoint -> FuncDecl.func_decl -> unit + + (** Add rule into the fixedpoint solver. *) val add_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol option -> unit + + (** Add table fact to the fixedpoint solver. *) val add_fact : fixedpoint -> FuncDecl.func_decl -> int array -> unit + + (** 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. *) val query : fixedpoint -> Boolean.bool_expr -> Solver.status + + (** 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. *) val query_r : fixedpoint -> FuncDecl.func_decl array -> Solver.status + + (** Creates a backtracking point. + {!pop} *) val push : fixedpoint -> unit + + (** Backtrack one backtracking point. + + Note that an exception is thrown if Pop is called without a corresponding Push + {!push} *) val pop : fixedpoint -> unit + + (** Update named rule into in the fixedpoint solver. *) val update_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol -> unit + + (** Retrieve satisfying instance or instances of solver, + or definitions for the recursive predicates that show unsatisfiability. *) val get_answer : fixedpoint -> Expr.expr option + + (** Retrieve explanation why fixedpoint engine returned status Unknown. *) val get_reason_unknown : fixedpoint -> string + + (** Retrieve the number of levels explored for a given predicate. *) val get_num_levels : fixedpoint -> FuncDecl.func_decl -> int + + (** Retrieve the cover of a predicate. *) val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option + + (** Add property about the predicate. + The property is added at level. *) val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit + + (** Retrieve internal string representation of fixedpoint object. *) val to_string : fixedpoint -> string + + (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol array -> unit + + (** Convert benchmark given as set of axioms, rules and queries to a string. *) val to_string_q : fixedpoint -> Boolean.bool_expr array -> string + + (** Retrieve set of rules added to fixedpoint context. *) val get_rules : fixedpoint -> Boolean.bool_expr array + + (** Retrieve set of assertions added to fixedpoint context. *) val get_assertions : fixedpoint -> Boolean.bool_expr array + + (** Create a Fixedpoint context. *) val mk_fixedpoint : context -> fixedpoint end +(** Global and context options + + Note: This module contains functions that set parameters/options for context + objects as well as functions that set options that are used globally, across + contexts.*) module Options : sig + (** 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. + {!get_param_value} *) val update_param_value : context -> string -> string -> unit + + (** Get a configuration parameter. + + Returns None if the parameter value does not exist. + {!update_param_value} *) val get_param_value : context -> string -> string option + + (** 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + {!AST.to_string} + {!Quantifier.Pattern.to_string} + {!FuncDecl.to_string} + {!Sort.to_string} *) val set_print_mode : context -> Z3enums.ast_print_mode -> unit + + (** Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) val toggle_warning_messages : bool -> unit end +(** Functions for handling SMT and SMT2 expressions and files *) module SMT : sig + (** Convert a benchmark into an SMT-LIB formatted string. + + @return A string representation of the benchmark. *) val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr array -> Boolean.bool_expr -> string + + (** 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 in the third and fifth argument + don't need to match the names of the sorts and declarations in the arrays in the fourth + and sixth argument. This is a useful feature since we can use arbitrary names to + reference sorts and declarations. *) val parse_smtlib_string : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> unit + + (** Parse the given file using the SMT-LIB parser. + {!parse_smtlib_string} *) val parse_smtlib_file : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> unit + + (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_formulas : context -> int + + (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_smtlib_formulas : context -> Boolean.bool_expr array + + (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_assumptions : context -> int + + (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_smtlib_assumptions : context -> Boolean.bool_expr array + + (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_decls : context -> int + + (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_smtlib_decls : context -> FuncDecl.func_decl array + + (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_sorts : context -> int + + (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_smtlib_sorts : context -> Sort.sort array + + (** Parse the given string using the SMT-LIB2 parser. + + {!parse_smtlib_string} + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) val parse_smtlib2_string : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> Boolean.bool_expr + + (** Parse the given file using the SMT-LIB2 parser. + {!parse_smtlib2_string} *) val parse_smtlib2_file : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> Boolean.bool_expr end +(** Set a global (or module) parameter, which is shared by all Z3 contexts. + + When a Z3 module is initialized it will use the value of these parameters + when Z3_params objects are not provided. + The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. + The character '.' is a delimiter (more later). + The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. + Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". + This function can be used to set parameters for a specific Z3 module. + This can be done by using .. + For example: + (set_global_param "pp.decimal" "true") + will set the parameter "decimal" in the module "pp" to true. +*) val set_global_param : string -> string -> unit + +(** Get a global (or module) parameter. + + Returns None if the parameter does not exist. + The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. + This function cannot be invoked simultaneously from different threads without synchronization. + The result string stored in param_value is stored in a shared location. +*) val get_global_param : string -> string option + +(** Restore the value of all global (and module) parameters. + + This command will not affect already created objects (such as tactics and solvers) + {!set_global_param} +*) val global_param_reset_all : unit From 79d0c32c919a18b175b1d33e6b64b7a0caa1319a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 21 Feb 2013 00:29:51 +0000 Subject: [PATCH 182/248] ML API: replaced arrays with lists. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 46 ++-- src/api/ml/z3.ml | 507 +++++++++++++++++++------------------- src/api/ml/z3.mli | 184 +++++++------- 3 files changed, 371 insertions(+), 366 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 6dfe11623..31f31d566 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -33,13 +33,13 @@ let model_converter_test ( ctx : context ) = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in let g4 = (mk_goal ctx true false false ) in - (Goal.assert_ g4 [| (mk_gt ctx xr + (Goal.assert_ g4 [ (mk_gt ctx xr (arith_expr_of_real_expr (real_expr_of_rat_num - (Real.mk_numeral_nd ctx 10 1)))) |]) ; - (Goal.assert_ g4 [| (mk_eq ctx + (Real.mk_numeral_nd ctx 10 1)))) ]) ; + (Goal.assert_ g4 [ (mk_eq ctx (expr_of_arith_expr yr) - (expr_of_arith_expr (Arithmetic.mk_add ctx [| xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) |]) ) ) |] ) ; - (Goal.assert_ g4 [| (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) |]) ; + (expr_of_arith_expr (Arithmetic.mk_add ctx [ xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) ]) ) ) ] ) ; + (Goal.assert_ g4 [ (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) ]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in if ((get_num_subgoals ar) == 1 && @@ -50,7 +50,7 @@ let model_converter_test ( ctx : context ) = Printf.printf "Test passed.\n" ); ( - let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") [||]) g4 None) in + let ar = (Tactic.apply (and_then ctx (mk_tactic ctx ("simplify")) (mk_tactic ctx "solve-eqs") []) g4 None) in if ((get_num_subgoals ar) == 1 && ((is_decided_sat (get_subgoal ar 0)) || (is_decided_unsat (get_subgoal ar 0)))) then @@ -59,9 +59,9 @@ let model_converter_test ( ctx : context ) = Printf.printf "Test passed.\n" ; let solver = (mk_solver ctx None) in - let f e = (Solver.assert_ solver [| e |]) in - ignore (Array.map f (get_formulas (get_subgoal ar 0))) ; - let q = (check solver [||]) in + let f e = (Solver.assert_ solver [ e ]) in + ignore (List.map f (get_formulas (get_subgoal ar 0))) ; + let q = (check solver []) in if q != SATISFIABLE then raise (TestFailedException "") else @@ -84,23 +84,23 @@ let basic_tests ( ctx : context ) = let x = (mk_string ctx "x") in let y = (mk_string ctx "y") in let bs = (sort_of_bool_sort (Boolean.mk_sort ctx)) in - let domain = [| bs; bs |] in + let domain = [ bs; bs ] in let f = (FuncDecl.mk_func_decl ctx fname domain bs) in let fapp = (mk_app ctx f - [| (Expr.mk_const ctx x bs); (Expr.mk_const ctx y bs) |]) in - let fargs2 = [| (mk_fresh_const ctx "cp" bs) |] in - let domain2 = [| bs |] in + [ (Expr.mk_const ctx x bs); (Expr.mk_const ctx y bs) ]) in + let fargs2 = [ (mk_fresh_const ctx "cp" bs) ] in + let domain2 = [ bs ] in let fapp2 = (mk_app ctx (mk_fresh_func_decl ctx "fp" domain2 bs) fargs2) in let trivial_eq = (mk_eq ctx fapp fapp) in let nontrivial_eq = (mk_eq ctx fapp fapp2) in let g = (mk_goal ctx true false false) in - (Goal.assert_ g [| trivial_eq |]) ; - (Goal.assert_ g [| nontrivial_eq |]) ; + (Goal.assert_ g [ trivial_eq ]) ; + (Goal.assert_ g [ nontrivial_eq ]) ; Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; ( let solver = (mk_solver ctx None) in - (Array.iter (fun a -> (Solver.assert_ solver [| a |])) (get_formulas g)) ; - if (check solver [||]) != SATISFIABLE then + (List.iter (fun a -> (Solver.assert_ solver [ a ])) (get_formulas g)) ; + if (check solver []) != SATISFIABLE then raise (TestFailedException "") else Printf.printf "Test passed.\n" @@ -122,11 +122,11 @@ let basic_tests ( ctx : context ) = else Printf.printf "Test passed.\n" ); - (Goal.assert_ g [| (mk_eq ctx + (Goal.assert_ g [ (mk_eq ctx (mk_numeral_int ctx 1 (sort_of_bitvec_sort (BitVector.mk_sort ctx 32))) (mk_numeral_int ctx 2 - (sort_of_bitvec_sort (BitVector.mk_sort ctx 32)))) |] ) + (sort_of_bitvec_sort (BitVector.mk_sort ctx 32)))) ] ) ; ( let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in @@ -147,7 +147,7 @@ let basic_tests ( ctx : context ) = ); ( let g2 = (mk_goal ctx true true false) in - (Goal.assert_ g2 [| (Boolean.mk_false ctx) |]) ; + (Goal.assert_ g2 [ (Boolean.mk_false ctx) ]) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then @@ -159,10 +159,10 @@ let basic_tests ( ctx : context ) = let g3 = (mk_goal ctx true true false) in let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in - (Goal.assert_ g3 [| (mk_eq ctx xc (mk_numeral_int ctx 1 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) |]) ; - (Goal.assert_ g3 [| (mk_eq ctx yc (mk_numeral_int ctx 2 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) |]) ; + (Goal.assert_ g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) ]) ; + (Goal.assert_ g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) ]) ; let constr = (mk_eq ctx xc yc) in - (Goal.assert_ g3 [| constr |] ) ; + (Goal.assert_ g3 [ constr ] ) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index b1e40fcac..56d319c1a 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -79,10 +79,6 @@ struct let z3obj_nil_ref x y = () - let array_to_native a = - let f e = (z3obj_gno e) in - Array.map f a - let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> let res : z3_native_object = { m_ctx = ctx ; m_n_obj = null ; @@ -127,6 +123,9 @@ let mk_list ( f : int -> 'a ) ( n : int ) = in mk_list' f 0 n [] +let list_of_array ( x : _ array ) = + let f i = (Array.get x i) in + mk_list f (Array.length x) let mk_context ( cfg : ( string * string ) list ) = create_context cfg @@ -180,6 +179,10 @@ struct match x with | S_Int(n) -> (z3obj_gno n) | S_Str(n) -> (z3obj_gno n) + + let symbol_lton ( a : symbol list ) = + let f ( e : symbol ) = (gno e) in + Array.of_list (List.map f a) let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL @@ -197,13 +200,13 @@ struct let mk_string ( ctx : context ) ( s : string ) = S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) - let mk_ints ( ctx : context ) ( names : int array ) = + let mk_ints ( ctx : context ) ( names : int list ) = let f elem = mk_int ( ctx : context ) elem in - (Array.map f names) + (List.map f names) - let mk_strings ( ctx : context ) ( names : string array ) = + let mk_strings ( ctx : context ) ( names : string list ) = let f elem = mk_string ( ctx : context ) elem in - (Array.map f names) + (List.map f names) end @@ -292,7 +295,9 @@ struct Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) let get_keys ( x : ast_map ) = - ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) + let av = ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in + let f i = (ASTVector.get av i) in + mk_list f (ASTVector.get_size av) let to_string ( x : ast_map ) = Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) @@ -376,10 +381,13 @@ struct else UninterpretedSort(s) - let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) + + let sort_lton ( a : sort list ) = + let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in + Array.of_list (List.map f a) let ( = ) : sort -> sort -> bool = fun a b -> (a == b) || @@ -438,9 +446,9 @@ sig val get_func_decl : parameter -> func_decl val get_rational : parameter -> string end - val mk_func_decl : context -> Symbol.symbol -> Sort.sort array -> Sort.sort -> func_decl - val mk_func_decl_s : context -> string -> Sort.sort array -> Sort.sort -> func_decl - val mk_fresh_func_decl : context -> string -> Sort.sort array -> Sort.sort -> func_decl + val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl + val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl + val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl val mk_const_decl_s : context -> string -> Sort.sort -> func_decl val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl @@ -449,13 +457,13 @@ sig val get_id : func_decl -> int val get_arity : func_decl -> int val get_domain_size : func_decl -> int - val get_domain : func_decl -> Sort.sort array + val get_domain : func_decl -> Sort.sort list val get_range : func_decl -> Sort.sort val get_decl_kind : func_decl -> Z3enums.decl_kind val get_name : func_decl -> Symbol.symbol val get_num_parameters : func_decl -> int val get_parameters : func_decl -> Parameter.parameter list - val apply : func_decl -> Expr.expr array -> Expr.expr + val apply : func_decl -> Expr.expr list -> Expr.expr end = struct type func_decl = FuncDecl of AST.ast @@ -467,23 +475,21 @@ end = struct let ast_of_func_decl f = match f with FuncDecl(x) -> x - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - let f x = (AST.ptr_of_ast (ast_of_sort x)) in - (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (Array.length domain) (Array.map f domain) (Sort.gno range))) ; + (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (List.length domain) (sort_lton domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) - let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort list ) ( range : sort ) = let res = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.inc_ref ; dec_ref = Z3native.dec_ref } in - let f x = (AST.ptr_of_ast (ast_of_sort x)) in - (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (Array.length domain) (Array.map f domain) (Sort.gno range))) ; + (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (List.length domain) (sort_lton domain) (Sort.gno range))) ; (z3obj_create res) ; FuncDecl(res) @@ -548,23 +554,23 @@ end = struct | _ -> raise (Z3native.Exception "parameter is not a rational string") end - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = create_ndr ctx name domain range - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort array ) ( range : sort ) = + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort list ) ( range : sort ) = mk_func_decl ctx (Symbol.mk_string ctx name) domain range - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort array ) ( range : sort ) = + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort list ) ( range : sort ) = create_pdr ctx prefix domain range let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - create_ndr ctx name [||] range + create_ndr ctx name [] range let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = - create_ndr ctx (Symbol.mk_string ctx name) [||] range + create_ndr ctx (Symbol.mk_string ctx name) [] range let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = - create_pdr ctx prefix [||] range + create_pdr ctx prefix [] range let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || @@ -584,7 +590,7 @@ end = struct let get_domain ( x : func_decl ) = let n = (get_domain_size x) in let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in - Array.init n f + mk_list f n let get_range ( x : func_decl ) = sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) @@ -608,7 +614,7 @@ end = struct ) in mk_list f n - let apply ( x : func_decl ) ( args : Expr.expr array ) = Expr.expr_of_func_app (gc x) x args + let apply ( x : func_decl ) ( args : Expr.expr list ) = Expr.expr_of_func_app (gc x) x args end @@ -621,7 +627,7 @@ sig val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs val validate : param_descrs -> params -> unit val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind - val get_names : param_descrs -> Symbol.symbol array + val get_names : param_descrs -> Symbol.symbol list val get_size : param_descrs -> int val to_string : param_descrs -> string end @@ -660,7 +666,7 @@ end = struct let get_names ( x : param_descrs ) = let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) @@ -710,21 +716,21 @@ sig val c_of_expr : expr -> context val nc_of_expr : expr -> Z3native.ptr val ptr_of_expr : expr -> Z3native.ptr - val expr_aton : expr array -> Z3native.ptr array + val expr_lton : expr list -> Z3native.ptr array val ast_of_expr : expr -> AST.ast val expr_of_ast : AST.ast -> expr - val expr_of_func_app : context -> FuncDecl.func_decl -> expr array -> expr + val expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr val simplify : expr -> Params.params option -> expr val get_simplify_help : context -> string val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs val get_func_decl : expr -> FuncDecl.func_decl val get_bool_value : expr -> Z3enums.lbool val get_num_args : expr -> int - val get_args : expr -> expr array - val update : expr -> expr array -> expr - val substitute : expr -> expr array -> expr array -> expr + val get_args : expr -> expr list + val update : expr -> expr list -> expr + val substitute : expr -> expr list -> expr list -> expr val substitute_one : expr -> expr -> expr -> expr - val substitute_vars : expr -> expr array -> expr + val substitute_vars : expr -> expr list -> expr val translate : expr -> context -> expr val to_string : expr -> string val is_numeral : expr -> bool @@ -750,7 +756,7 @@ sig val mk_const_s : context -> string -> Sort.sort -> expr val mk_const_f : context -> FuncDecl.func_decl -> expr val mk_fresh_const : context -> string -> Sort.sort -> expr - val mk_app : context -> FuncDecl.func_decl -> expr array -> expr + val mk_app : context -> FuncDecl.func_decl -> expr list -> expr val mk_numeral_string : context -> string -> Sort.sort -> expr val mk_numeral_int : context -> int -> Sort.sort -> expr end = struct @@ -786,13 +792,13 @@ end = struct let ast_of_expr e = match e with Expr(a) -> a - let expr_aton ( a : expr array ) = + let expr_lton ( a : expr list ) = let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in - Array.map f a + Array.of_list (List.map f a) - let expr_of_func_app : context -> FuncDecl.func_decl -> expr array -> expr = fun ctx f args -> + let expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr = fun ctx f args -> match f with FuncDecl.FuncDecl(fa) -> - let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (Array.length args) (expr_aton args) in + let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (List.length args) (expr_lton args) in expr_of_ptr ctx o let simplify ( x : expr ) ( p : Params.params option ) = match p with @@ -812,25 +818,25 @@ end = struct let get_args ( x : expr ) = let n = (get_num_args x) in let f i = expr_of_ptr (c_of_expr x) (Z3native.get_app_arg (nc_of_expr x) (ptr_of_expr x) i) in - Array.init n f + mk_list f n - let update ( x : expr ) args = - if (Array.length args <> (get_num_args x)) then + let update ( x : expr ) ( args : expr list ) = + if (List.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (Array.length args) (expr_aton args)) + expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (List.length args) (expr_lton args)) let substitute ( x : expr ) from to_ = - if (Array.length from) <> (Array.length to_) then + if (List.length from) <> (List.length to_) then raise (Z3native.Exception "Argument sizes do not match") else - expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (Array.length from) (expr_aton from) (expr_aton to_)) + expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (List.length from) (expr_lton from) (expr_lton to_)) let substitute_one ( x : expr ) from to_ = - substitute ( x : expr ) [| from |] [| to_ |] + substitute ( x : expr ) [ from ] [ to_ ] let substitute_vars ( x : expr ) to_ = - expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (Array.length to_) (expr_aton to_)) + expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (List.length to_) (expr_lton to_)) let translate ( x : expr ) to_ctx = if (c_of_expr x) == to_ctx then @@ -876,12 +882,12 @@ end = struct let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) range - let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [||] + let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [] let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) - let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr array ) = expr_of_func_app ctx f args + let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr list ) = expr_of_func_app ctx f args let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) @@ -950,8 +956,8 @@ struct let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (ptr_of_expr x) (ptr_of_expr y)) - let mk_distinct ( ctx : context ) ( args : expr array ) = - bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (Array.length args) (expr_aton args)) + let mk_distinct ( ctx : context ) ( args : expr list ) = + bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) let mk_not ( ctx : context ) ( a : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) @@ -968,13 +974,13 @@ struct let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - let mk_and ( ctx : context ) ( args : bool_expr array ) = + let mk_and ( ctx : context ) ( args : bool_expr list ) = let f x = (ptr_of_expr (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (Array.length args) (Array.map f args)) + bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) - let mk_or ( ctx : context ) ( args : bool_expr array ) = + let mk_or ( ctx : context ) ( args : bool_expr list ) = let f x = (ptr_of_expr (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (Array.length args) (Array.map f args)) + bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) end @@ -1016,7 +1022,7 @@ struct let get_terms ( x : pattern ) = let n = (get_num_terms x) in let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) end @@ -1039,26 +1045,26 @@ struct let get_patterns ( x : quantifier ) = let n = (get_num_patterns x) in let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) let get_no_patterns ( x : quantifier ) = let n = (get_num_patterns x) in let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) let get_bound_variable_names ( x : quantifier ) = let n = (get_num_bound x) in let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let get_bound_variable_sorts ( x : quantifier ) = let n = (get_num_bound x) in let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in - Array.init n f + mk_list f n let get_body ( x : quantifier ) = Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) @@ -1066,95 +1072,95 @@ struct let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) - let mk_pattern ( ctx : context ) ( terms : expr array ) = - if (Array.length terms) == 0 then + let mk_pattern ( ctx : context ) ( terms : expr list ) = + if (List.length terms) == 0 then raise (Z3native.Exception "Cannot create a pattern from zero terms") else - Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (Array.length terms) (expr_aton terms))) + Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (List.length terms) (expr_lton terms))) - let mk_forall ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (Array.length sorts) != (Array.length names) then + let mk_forall ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (List.length sorts) != (List.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - (let f x = (Symbol.gno x) in (Array.map f names)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length nopatterns) (expr_aton nopatterns) - (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - (let f x = (Symbol.gno x) in (Array.map f names)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) (ptr_of_expr body))) - let mk_forall_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length nopatterns) (expr_aton nopatterns) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) (ptr_of_expr body))) - let mk_exists ( ctx : context ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (Array.length sorts) != (Array.length names) then + let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (List.length sorts) != (List.length names) then raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - (let f x = (Symbol.gno x) in (Array.map f names)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length nopatterns) (expr_aton nopatterns) - (Array.length sorts) (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - (let f x = (Symbol.gno x) in (Array.map f names)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) (ptr_of_expr body))) - let mk_exists_const ( ctx : context ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((Array.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) - (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (ptr_of_expr body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (Array.length bound_constants) (expr_aton bound_constants) - (Array.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.map f patterns)) - (Array.length nopatterns) (expr_aton nopatterns) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) (ptr_of_expr body))) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort array ) ( names : Symbol.symbol array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) else (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr array ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern array ) ( nopatterns : expr array ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else @@ -1233,9 +1239,9 @@ struct let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) - let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr array ) = + let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr list ) = let m x = (ptr_of_expr (expr_of_array_expr x)) in - array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (Array.length args) (Array.map m args)) + array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) let mk_term_array ( ctx : context ) ( arg : array_expr ) = array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) @@ -1274,11 +1280,11 @@ struct let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) - let mk_union ( ctx : context ) ( args : expr array ) = - expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (Array.length args) (expr_aton args)) + let mk_union ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) - let mk_intersection ( ctx : context ) ( args : expr array ) = - expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (Array.length args) (expr_aton args)) + let mk_intersection ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) @@ -1378,7 +1384,7 @@ struct let get_column_sorts ( x : relation_sort ) = let n = get_arity x in let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in - Array.init n f + mk_list f n end @@ -1418,21 +1424,23 @@ struct module Constructor = struct type constructor = z3_native_object + + let _sizes = Hashtbl.create 0 - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = - let n = (Array.length field_names) in - if n != (Array.length sorts) then + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let n = (List.length field_names) in + if n != (List.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") else - if n != (Array.length sort_refs) then + if n != (List.length sort_refs) then raise (Z3native.Exception "Number of field names does not match number of sort refs") else let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) (Symbol.gno recognizer) n - (let f x = (Symbol.gno x) in (Array.map f field_names)) - (let f x = (AST.ptr_of_ast (ast_of_sort x)) in (Array.map f sorts)) - sort_refs) in + (Symbol.symbol_lton field_names) + (sort_lton sorts) + (Array.of_list sort_refs)) in let no : constructor = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; @@ -1441,9 +1449,10 @@ struct (z3obj_create no) ; let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; + Hashtbl.add _sizes no n ; no - let get_num_fields ( x : constructor ) = Z3native.get_arity (z3obj_gnc x) (z3obj_gno x) + let get_num_fields ( x : constructor ) = Hashtbl.find _sizes x let get_constructor_decl ( x : constructor ) = let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in @@ -1455,8 +1464,8 @@ struct let get_accessor_decls ( x : constructor ) = let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - let f y = func_decl_of_ptr (z3obj_gc x) y in - Array.map f c + let f i = func_decl_of_ptr (z3obj_gc x) (Array.get c i) in + mk_list f (Array.length c) end @@ -1464,48 +1473,47 @@ struct struct type constructor_list = z3_native_object - let create ( ctx : context ) ( c : Constructor.constructor array ) = + let create ( ctx : context ) ( c : Constructor.constructor list ) = let res : constructor_list = { m_ctx = ctx ; m_n_obj = null ; inc_ref = z3obj_nil_ref ; dec_ref = z3obj_nil_ref} in let f x =(z3obj_gno x) in - (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (Array.length c) (Array.map f c))) ; + (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (List.length c) (Array.of_list (List.map f c)))) ; (z3obj_create res) ; let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f res; res end - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = Constructor.create ctx name recognizer field_names sorts sort_refs - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( sorts : sort array ) ( sort_refs : int array ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor array ) = + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = let f x = (z3obj_gno x) in - let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (Array.length constructors) (Array.map f constructors)) in + let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (List.length constructors) (Array.of_list (List.map f constructors))) in sort_of_ptr ctx x - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor array ) = + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor list ) = mk_sort ctx (Symbol.mk_string ctx name) constructors - let mk_sorts ( ctx : context ) ( names : Symbol.symbol array ) ( c : Constructor.constructor array array ) = - let n = (Array.length names) in + let mk_sorts ( ctx : context ) ( names : Symbol.symbol list ) ( c : Constructor.constructor list list ) = + let n = (List.length names) in let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in - let cla = (Array.map f c) in - let f2 x = (Symbol.gno x) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Array.map f2 names) cla) in - let g e = (sort_of_ptr ctx e) in - (Array.map g r) + let cla = (Array.of_list (List.map f c)) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.symbol_lton names) cla) in + let g i = (sort_of_ptr ctx (Array.get r i)) in + mk_list g (Array.length r) - let mk_sorts_s ( ctx : context ) ( names : string array ) ( c : Constructor.constructor array array ) = + let mk_sorts_s ( ctx : context ) ( names : string list ) ( c : Constructor.constructor list list ) = mk_sorts ctx ( let f e = (Symbol.mk_string ctx e) in - Array.map f names + List.map f names ) c @@ -1514,12 +1522,12 @@ struct let get_constructors ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in - Array.init n f + mk_list f n let get_recognizers ( x : datatype_sort ) = let n = (get_num_constructors x) in let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in - Array.init n f + mk_list f n let get_accessors ( x : datatype_sort ) = let n = (get_num_constructors x) in @@ -1527,9 +1535,9 @@ struct let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in - Array.init ds g + mk_list g ds ) in - Array.init n f + mk_list f n end @@ -1537,7 +1545,7 @@ module Enumeration = struct type enum_sort = EnumSort of sort - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl array ) ( tdecls : Z3native.z3_func_decl array ) = + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl list ) ( tdecls : Z3native.z3_func_decl list ) = let s = (sort_of_ptr ctx no) in let res = EnumSort(s) in res @@ -1548,23 +1556,22 @@ struct let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol array ) = - let f x = Symbol.gno x in - let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (Array.length enum_names) (Array.map f enum_names)) in - sort_of_ptr ctx a b c + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = + let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in + sort_of_ptr ctx a (list_of_array b) (list_of_array c) - let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string array ) = + let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) let get_const_decls ( x : enum_sort ) = let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in - Array.init n f + mk_list f n let get_tester_decls ( x : enum_sort ) = let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in - Array.init n f + mk_list f n end @@ -1609,7 +1616,7 @@ struct let get_tail_decl ( x : list_sort ) = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) - let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [||] + let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [] end @@ -1627,10 +1634,8 @@ struct let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol array ) ( field_sorts : sort array ) = - let f x = Symbol.gno x in - let f2 x = ptr_of_ast (ast_of_sort x) in - let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (Array.length field_names) (Array.map f field_names) (Array.map f2 field_sorts)) in + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = + let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in sort_of_ptr ctx r let get_mk_decl ( x : tuple_sort ) = @@ -1641,7 +1646,7 @@ struct let get_field_decls ( x : tuple_sort ) = let n = get_num_fields x in let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in - Array.init n f + mk_list f n end @@ -1746,9 +1751,9 @@ sig val is_int_numeral : Expr.expr -> bool val is_rat_num : Expr.expr -> bool val is_algebraic_number : Expr.expr -> bool - val mk_add : context -> arith_expr array -> arith_expr - val mk_mul : context -> arith_expr array -> arith_expr - val mk_sub : context -> arith_expr array -> arith_expr + val mk_add : context -> arith_expr list -> arith_expr + val mk_mul : context -> arith_expr list -> arith_expr + val mk_sub : context -> arith_expr list -> arith_expr val mk_unary_minus : context -> arith_expr -> arith_expr val mk_div : context -> arith_expr -> arith_expr -> arith_expr val mk_power : context -> arith_expr -> arith_expr -> arith_expr @@ -2109,17 +2114,17 @@ end = struct let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (nc_of_expr x) (nc_of_expr x) - let mk_add ( ctx : context ) ( t : arith_expr array ) = + let mk_add ( ctx : context ) ( t : arith_expr list ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (Array.length t) (Array.map f t))) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_mul ( ctx : context ) ( t : arith_expr array ) = + let mk_mul ( ctx : context ) ( t : arith_expr list ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (Array.length t) (Array.map f t))) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_sub ( ctx : context ) ( t : arith_expr array ) = + let mk_sub ( ctx : context ) ( t : arith_expr list ) = let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (Array.length t) (Array.map f t))) + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) @@ -2551,9 +2556,9 @@ struct let is_garbage ( x : goal ) = (get_precision x) == GOAL_UNDER_OVER - let assert_ ( x : goal ) ( constraints : Boolean.bool_expr array ) = + let assert_ ( x : goal ) ( constraints : Boolean.bool_expr list ) = let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in - ignore (Array.map f constraints) ; + ignore (List.map f constraints) ; () let is_inconsistent ( x : goal ) = @@ -2569,7 +2574,7 @@ struct let n = get_size x in let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in - Array.init n f + mk_list f n let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) @@ -2653,12 +2658,12 @@ struct let get_args ( x : func_entry ) = let n = (get_num_args x) in let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in - Array.init n f + mk_list f n let to_string ( x : func_entry ) = let a = (get_args x) in let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ Array.fold_right f a ((Expr.to_string (get_value x)) ^ "]") + "[" ^ List.fold_right f a ((Expr.to_string (get_value x)) ^ "]") end let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) @@ -2666,7 +2671,7 @@ struct let get_entries ( x : func_interp ) = let n = (get_num_entries x) in let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in - Array.init n f + mk_list f n let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) @@ -2678,12 +2683,12 @@ struct p ^ let g c p = (p ^ (Expr.to_string c) ^ ", ") in (if n > 1 then "[" else "") ^ - (Array.fold_right + (List.fold_right g (FuncEntry.get_args c) ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) ) in - Array.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + List.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") end let get_const_interp ( x : model ) ( f : func_decl ) = @@ -2725,21 +2730,21 @@ struct let get_const_decls ( x : model ) = let n = (get_num_consts x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) let get_func_decls ( x : model ) = let n = (get_num_consts x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get_decls ( x : model ) = let n_funcs = (get_num_funcs x) in let n_consts = (get_num_consts x ) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - Array.append (Array.init n_funcs f) (Array.init n_consts g) + (mk_list f n_funcs) @ (mk_list g n_consts) exception ModelEvaluationFailedException of string @@ -2758,13 +2763,13 @@ struct let get_sorts ( x : model ) = let n = (get_num_sorts x) in let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in - Array.init n f + mk_list f n let sort_universe ( x : model ) ( s : sort ) = let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in - Array.init n f + mk_list f n let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) end @@ -2793,7 +2798,7 @@ struct let get_probe_names ( ctx : context ) = let n = (get_num_probes ctx) in let f i = (Z3native.get_probe_name (context_gno ctx) i) in - Array.init n f + mk_list f n let get_probe_description ( ctx : context ) ( name : string ) = Z3native.probe_get_descr (context_gno ctx) name @@ -2862,7 +2867,7 @@ struct let get_subgoals ( x : apply_result ) = let n = (get_num_subgoals x) in let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get_subgoal ( x : apply_result ) ( i : int ) = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) @@ -2888,7 +2893,7 @@ struct let get_tactic_names ( ctx : context ) = let n = (get_num_tactics ctx ) in let f i = (Z3native.get_tactic_name (context_gno ctx) i) in - Array.init n f + mk_list f n let get_tactic_description ( ctx : context ) ( name : string ) = Z3native.tactic_get_descr (context_gno ctx) name @@ -2896,11 +2901,11 @@ struct let mk_tactic ( ctx : context ) ( name : string ) = create ctx (Z3native.mk_tactic (context_gno ctx) name) - let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic array ) = + let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic list ) = let f p c = (match p with | None -> (Some (z3obj_gno c)) | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in - match (Array.fold_left f None ts) with + match (List.fold_left f None ts) with | None -> create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) | Some(x) -> @@ -2940,8 +2945,9 @@ struct let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = using_params ctx t p - let par_or ( ctx : context ) ( t : tactic array ) = - create ctx (Z3native.tactic_par_or (context_gno ctx) (Array.length t) (array_to_native t)) + let par_or ( ctx : context ) ( t : tactic list ) = + let f e = (z3obj_gno e) in + create ctx (Z3native.tactic_par_or (context_gno ctx) (List.length t) (Array.of_list (List.map f t))) let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) @@ -3042,16 +3048,16 @@ struct else (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in - Array.init n f + mk_list f n let get_keys ( x : statistics ) = let n = (get_size x) in let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in - Array.init n f + mk_list f n let get ( x : statistics ) ( key : string ) = let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in - Array.fold_left f None (get_entries x) + List.fold_left f None (get_entries x) end let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) @@ -3070,16 +3076,16 @@ struct let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - let assert_ ( x : solver ) ( constraints : Boolean.bool_expr array ) = + let assert_ ( x : solver ) ( constraints : Boolean.bool_expr list ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in - ignore (Array.map f constraints) + ignore (List.map f constraints) - let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr array ) ( ps : Boolean.bool_expr array ) = - if ((Array.length cs) != (Array.length ps)) then + let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr list ) ( ps : Boolean.bool_expr list ) = + if ((List.length cs) != (List.length ps)) then raise (Z3native.Exception "Argument size mismatch") else - let f i e = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) (Boolean.gno (Array.get ps i))) in - ignore (Array.iteri f cs) + let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno a) (Boolean.gno b)) in + ignore (List.iter2 f cs ps) let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) @@ -3092,15 +3098,15 @@ struct let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in - Array.init n f + mk_list f n - let check ( x : solver ) ( assumptions : Boolean.bool_expr array) = + let check ( x : solver ) ( assumptions : Boolean.bool_expr list ) = let r = - if ((Array.length assumptions) == 0) then + if ((List.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else let f x = (ptr_of_expr (Boolean.expr_of_bool_expr x)) in - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (Array.length assumptions) (Array.map f assumptions)) + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) in match r with | L_TRUE -> SATISFIABLE @@ -3125,7 +3131,7 @@ struct let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in - Array.init n f + mk_list f n let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) @@ -3173,9 +3179,9 @@ struct let get_param_descrs ( x : fixedpoint ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr array ) = + let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr list ) = let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in - ignore (Array.map f constraints) ; + ignore (List.map f constraints) ; () let register_relation ( x : fixedpoint ) ( f : func_decl ) = @@ -3186,8 +3192,8 @@ struct | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) - let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int array ) = - Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (Array.length args) args + let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = + Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with @@ -3195,9 +3201,9 @@ struct | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN - let query_r ( x : fixedpoint ) ( relations : func_decl array ) = + let query_r ( x : fixedpoint ) ( relations : func_decl list ) = let f x = ptr_of_ast (ast_of_func_decl x) in - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (Array.length relations) (Array.map f relations))) with + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (List.length relations) (Array.of_list (List.map f relations)))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -3236,25 +3242,24 @@ struct let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol array ) = - let f2 x = (Symbol.gno x) in - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (Array.length kinds) (Array.map f2 kinds) + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) - let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr array ) = + let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr list ) = let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (Array.length queries) (Array.map f queries) + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) let get_rules ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - Array.init n f + mk_list f n let get_assertions ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - Array.init n f + mk_list f n let mk_fixedpoint ( ctx : context ) = create ctx end @@ -3282,102 +3287,102 @@ end module SMT = struct - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr array ) ( formula : Boolean.bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr list ) ( formula : Boolean.bool_expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (Array.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.map f assumptions)) + (List.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.of_list (List.map f assumptions))) (Boolean.gno formula) - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = - let csn = (Array.length sort_names) in - let cs = (Array.length sorts) in - let cdn = (Array.length decl_names) in - let cd = (Array.length decls) in + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else Z3native.parse_smtlib_string (context_gno ctx) str cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) + (Symbol.symbol_lton sort_names) + (sort_lton sorts) cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)) + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = - let csn = (Array.length sort_names) in - let cs = (Array.length sorts) in - let cdn = (Array.length decl_names) in - let cd = (Array.length decls) in + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else Z3native.parse_smtlib_file (context_gno ctx) file_name cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) + (Symbol.symbol_lton sort_names) + (sort_lton sorts) cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)) + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in - Array.init n f + mk_list f n let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in - Array.init n f + mk_list f n let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) let get_smtlib_decls ( ctx : context ) = let n = (get_num_smtlib_decls ctx) in let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in - Array.init n f + mk_list f n let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in - Array.init n f + mk_list f n - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = - let csn = (Array.length sort_names) in - let cs = (Array.length sorts) in - let cdn = (Array.length decl_names) in - let cd = (Array.length decls) in + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) + (Symbol.symbol_lton sort_names) + (sort_lton sorts) cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)))) + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol array ) ( sorts : sort array ) ( decl_names : Symbol.symbol array ) ( decls : func_decl array ) = - let csn = (Array.length sort_names) in - let cs = (Array.length sorts) in - let cdn = (Array.length decl_names) in - let cd = (Array.length decls) in + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name cs - (let f x = Symbol.gno x in (Array.map f sort_names)) - (let f x = Sort.gno x in (Array.map f sorts)) + (Symbol.symbol_lton sort_names) + (sort_lton sorts) cd - (let f x = Symbol.gno x in (Array.map f decl_names)) - (let f x = FuncDecl.gno x in (Array.map f decls)))) + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) end diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 49a78f724..9f451c45f 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -106,11 +106,11 @@ sig (** Creates a new symbol using a string. *) val mk_string : context -> string -> symbol - (** Create an array of symbols. *) - val mk_ints : context -> int array -> symbol array + (** Create a list of symbols. *) + val mk_ints : context -> int list -> symbol list - (** Create an array of symbols. *) - val mk_strings : context -> string array -> symbol array + (** Create a list of symbols. *) + val mk_strings : context -> string list -> symbol list end (** The abstract syntax tree (AST) module *) @@ -175,7 +175,7 @@ sig val get_size : ast_map -> int (** The keys stored in the map. *) - val get_keys : ast_map -> ASTVector.ast_vector + val get_keys : ast_map -> ast list (** Retrieves a string representation of the map.*) val to_string : ast_map -> string @@ -331,13 +331,13 @@ sig end (** Creates a new function declaration. *) - val mk_func_decl : context -> Symbol.symbol -> Sort.sort array -> Sort.sort -> func_decl + val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl (** Creates a new function declaration. *) - val mk_func_decl_s : context -> string -> Sort.sort array -> Sort.sort -> func_decl + val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl (** Creates a fresh function declaration with a name prefixed with a prefix string. *) - val mk_fresh_func_decl : context -> string -> Sort.sort array -> Sort.sort -> func_decl + val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl (** Creates a new constant function declaration. *) val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl @@ -368,7 +368,7 @@ sig val get_domain_size : func_decl -> int (** The domain of the function declaration *) - val get_domain : func_decl -> Sort.sort array + val get_domain : func_decl -> Sort.sort list (** The range of the function declaration *) val get_range : func_decl -> Sort.sort @@ -386,7 +386,7 @@ sig val get_parameters : func_decl -> Parameter.parameter list (** Create expression that applies function to arguments. *) - val apply : func_decl -> Expr.expr array -> Expr.expr + val apply : func_decl -> Expr.expr list -> Expr.expr end (** Parameter sets (of Solvers, Tactics, ...) @@ -408,7 +408,7 @@ sig val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind (** Retrieve all names of parameters. *) - val get_names : param_descrs -> Symbol.symbol array + val get_names : param_descrs -> Symbol.symbol list (** The size of the ParamDescrs. *) val get_size : param_descrs -> int @@ -477,18 +477,18 @@ sig val get_num_args : Expr.expr -> int (** The arguments of the expression. *) - val get_args : Expr.expr -> Expr.expr array + val get_args : Expr.expr -> Expr.expr list (** Update the arguments of the expression using an array of expressions. The number of new arguments should coincide with the current number of arguments. *) - val update : Expr.expr -> Expr.expr array -> expr + val update : Expr.expr -> Expr.expr list -> expr (** 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]. *) - val substitute : Expr.expr -> Expr.expr array -> Expr.expr array -> expr + val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr (** Substitute every occurrence of from in the expression with to. {!substitute} *) @@ -497,7 +497,7 @@ sig (** Substitute the free variables in the expression with the expressions in the expr array For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) - val substitute_vars : Expr.expr -> Expr.expr array -> expr + val substitute_vars : Expr.expr -> Expr.expr list -> expr (** Translates (copies) the term to another context. @return A copy of the term which is associated with the other context *) @@ -582,7 +582,7 @@ sig val mk_fresh_const : context -> string -> Sort.sort -> expr (** Create a new function application. *) - val mk_app : context -> FuncDecl.func_decl -> Expr.expr array -> expr + val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr (** Create a numeral of a given sort. @return A Term with the goven value and sort *) @@ -627,7 +627,7 @@ sig val mk_eq : context -> Expr.expr -> Expr.expr -> bool_expr (** Creates a distinct term. *) - val mk_distinct : context -> Expr.expr array -> bool_expr + val mk_distinct : context -> Expr.expr list -> bool_expr (** Mk an expression representing not(a). *) val mk_not : context -> bool_expr -> bool_expr @@ -645,10 +645,10 @@ sig val mk_xor : context -> bool_expr -> bool_expr -> bool_expr (** Create an expression representing the AND of args *) - val mk_and : context -> bool_expr array -> bool_expr + val mk_and : context -> bool_expr list -> bool_expr (** Create an expression representing the OR of args *) - val mk_or : context -> bool_expr array -> bool_expr + val mk_or : context -> bool_expr list -> bool_expr end (** Quantifier expressions *) @@ -675,7 +675,7 @@ sig val get_num_terms : pattern -> int (** The terms in the pattern. *) - val get_terms : pattern -> Expr.expr array + val get_terms : pattern -> Expr.expr list (** A string representation of the pattern. *) val to_string : pattern -> string @@ -713,22 +713,22 @@ sig val get_num_patterns : quantifier -> int (** The patterns. *) - val get_patterns : quantifier -> Pattern.pattern array + val get_patterns : quantifier -> Pattern.pattern list (** The number of no-patterns. *) val get_num_no_patterns : quantifier -> int (** The no-patterns. *) - val get_no_patterns : quantifier -> Pattern.pattern array + val get_no_patterns : quantifier -> Pattern.pattern list (** The number of bound variables. *) val get_num_bound : quantifier -> int (** The symbols for the bound variables. *) - val get_bound_variable_names : quantifier -> Symbol.symbol array + val get_bound_variable_names : quantifier -> Symbol.symbol list (** The sorts of the bound variables. *) - val get_bound_variable_sorts : quantifier -> Sort.sort array + val get_bound_variable_sorts : quantifier -> Sort.sort list (** The body of the quantifier. *) val get_body : quantifier -> Boolean.bool_expr @@ -737,25 +737,25 @@ sig val mk_bound : context -> int -> Sort.sort -> Expr.expr (** Create a quantifier pattern. *) - val mk_pattern : context -> Expr.expr array -> Pattern.pattern + val mk_pattern : context -> Expr.expr list -> Pattern.pattern (** Create a universal Quantifier. *) - val mk_forall : context -> Sort.sort array -> Symbol.symbol array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + val mk_forall : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier (** Create a universal Quantifier. *) - val mk_forall_const : context -> Expr.expr array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + val mk_forall_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier (** Create an existential Quantifier. *) - val mk_exists : context -> Sort.sort array -> Symbol.symbol array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + val mk_exists : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier (** Create an existential Quantifier. *) - val mk_exists_const : context -> Expr.expr array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + val mk_exists_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier (** Create a Quantifier. *) - val mk_quantifier : context -> Sort.sort array -> Symbol.symbol array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + val mk_quantifier : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier (** Create a Quantifier. *) - val mk_quantifier : context -> bool -> Expr.expr array -> Expr.expr -> int option -> Pattern.pattern array -> Expr.expr array -> Symbol.symbol option -> Symbol.symbol option -> quantifier + val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier end (** Functions to manipulate Array expressions *) @@ -857,7 +857,7 @@ sig {!Array_.mk_sort} {!mk_select} {!mk_store} *) - val mk_map : context -> FuncDecl.func_decl -> array_expr array -> array_expr + val mk_map : context -> FuncDecl.func_decl -> array_expr list -> array_expr (** Access the array default value. @@ -904,10 +904,10 @@ sig val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr (** Take the union of a list of sets. *) - val mk_union : context -> Expr.expr array -> Expr.expr + val mk_union : context -> Expr.expr list -> Expr.expr (** Take the intersection of a list of sets. *) - val mk_intersection : context -> Expr.expr array -> Expr.expr + val mk_intersection : context -> Expr.expr list -> Expr.expr (** Take the difference between two sets. *) val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -1037,7 +1037,7 @@ sig val get_arity : relation_sort -> int (** The sorts of the columns of the relation sort. *) - val get_column_sorts : relation_sort -> relation_sort array + val get_column_sorts : relation_sort -> relation_sort list end (** Functions to manipulate Datatype expressions *) @@ -1066,43 +1066,43 @@ sig val get_tester_decl : constructor -> FuncDecl.func_decl (** The function declarations of the accessors *) - val get_accessor_decls : constructor -> FuncDecl.func_decl array + val get_accessor_decls : constructor -> FuncDecl.func_decl list end (** Create a datatype 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. *) - val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> Constructor.constructor + val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor (** Create a datatype 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. *) - val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> int array -> Constructor.constructor + val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor (** Create a new datatype sort. *) - val mk_sort : context -> Symbol.symbol -> Constructor.constructor array -> datatype_sort + val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> datatype_sort (** Create a new datatype sort. *) - val mk_sort_s : context -> string -> Constructor.constructor array -> datatype_sort + val mk_sort_s : context -> string -> Constructor.constructor list -> datatype_sort (** Create mutually recursive datatypes. *) - val mk_sorts : context -> Symbol.symbol array -> Constructor.constructor array array -> datatype_sort array + val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> datatype_sort list (** Create mutually recursive data-types. *) - val mk_sorts_s : context -> string array -> Constructor.constructor array array -> datatype_sort array + val mk_sorts_s : context -> string list -> Constructor.constructor list list -> datatype_sort list (** The number of constructors of the datatype sort. *) val get_num_constructors : datatype_sort -> int (** The constructors. *) - val get_constructors : datatype_sort -> FuncDecl.func_decl array + val get_constructors : datatype_sort -> FuncDecl.func_decl list (** The recognizers. *) - val get_recognizers : datatype_sort -> FuncDecl.func_decl array + val get_recognizers : datatype_sort -> FuncDecl.func_decl list (** The constructor accessors. *) - val get_accessors : datatype_sort -> FuncDecl.func_decl array array + val get_accessors : datatype_sort -> FuncDecl.func_decl list list end (** Functions to manipulate Enumeration expressions *) @@ -1113,16 +1113,16 @@ sig val sort_of_enum_sort : enum_sort -> Sort.sort (** Create a new enumeration sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol array -> enum_sort + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> enum_sort (** Create a new enumeration sort. *) - val mk_sort_s : context -> string -> string array -> enum_sort + val mk_sort_s : context -> string -> string list -> enum_sort (** The function declarations of the constants in the enumeration. *) - val get_const_decls : enum_sort -> FuncDecl.func_decl array + val get_const_decls : enum_sort -> FuncDecl.func_decl list (** The test predicates for the constants in the enumeration. *) - val get_tester_decls : enum_sort -> FuncDecl.func_decl array + val get_tester_decls : enum_sort -> FuncDecl.func_decl list end (** Functions to manipulate List expressions *) @@ -1168,7 +1168,7 @@ sig val sort_of_tuple_sort : tuple_sort -> Sort.sort (** Create a new tuple sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol array -> Sort.sort array -> tuple_sort + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> tuple_sort (** The constructor function of the tuple. *) val get_mk_decl : tuple_sort -> FuncDecl.func_decl @@ -1177,7 +1177,7 @@ sig val get_num_fields : tuple_sort -> int (** The field declarations. *) - val get_field_decls : tuple_sort -> FuncDecl.func_decl array + val get_field_decls : tuple_sort -> FuncDecl.func_decl list end (** Functions to manipulate arithmetic expressions *) @@ -1407,13 +1407,13 @@ sig val is_algebraic_number : Expr.expr -> bool (** Create an expression representing t[0] + t[1] + .... *) - val mk_add : context -> arith_expr array -> arith_expr + val mk_add : context -> arith_expr list -> arith_expr (** Create an expression representing t[0] * t[1] * .... *) - val mk_mul : context -> arith_expr array -> arith_expr + val mk_mul : context -> arith_expr list -> arith_expr (** Create an expression representing t[0] - t[1] - .... *) - val mk_sub : context -> arith_expr array -> arith_expr + val mk_sub : context -> arith_expr list -> arith_expr (** Create an expression representing -t. *) val mk_unary_minus : context -> arith_expr -> arith_expr @@ -2332,7 +2332,7 @@ sig val is_garbage : goal -> bool (** Adds the constraints to the given goal. *) - val assert_ : goal -> Boolean.bool_expr array -> unit + val assert_ : goal -> Boolean.bool_expr list -> unit (** Indicates whether the goal contains `false'. *) val is_inconsistent : goal -> bool @@ -2348,7 +2348,7 @@ sig val get_size : goal -> int (** The formulas in the goal. *) - val get_formulas : goal -> Boolean.bool_expr array + val get_formulas : goal -> Boolean.bool_expr list (** The number of formulas, subformulas and terms in the goal. *) val get_num_exprs : goal -> int @@ -2407,7 +2407,7 @@ sig (** The arguments of the function entry. *) - val get_args : func_entry -> Expr.expr array + val get_args : func_entry -> Expr.expr list (** A string representation of the function entry. *) @@ -2418,7 +2418,7 @@ sig val get_num_entries : func_interp -> int (** The entries in the function interpretation *) - val get_entries : func_interp -> FuncEntry.func_entry array + val get_entries : func_interp -> FuncEntry.func_entry list (** The (symbolic) `else' value of the function interpretation. *) val get_else : func_interp -> Expr.expr @@ -2446,16 +2446,16 @@ sig val get_num_consts : model -> int (** The function declarations of the constants in the model. *) - val get_const_decls : model -> FuncDecl.func_decl array + val get_const_decls : model -> FuncDecl.func_decl list (** The number of function interpretations in the model. *) val get_num_funcs : model -> int (** The function declarations of the function interpretations in the model. *) - val get_func_decls : model -> FuncDecl.func_decl array + val get_func_decls : model -> FuncDecl.func_decl list (** All symbols that have an interpretation in the model. *) - val get_decls : model -> FuncDecl.func_decl array + val get_decls : model -> FuncDecl.func_decl list (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) exception ModelEvaluationFailedException of string @@ -2481,12 +2481,12 @@ sig the "universe" of the sort. {!get_num_sorts} {!sort_universe} *) - val get_sorts : model -> Sort.sort array + val get_sorts : model -> Sort.sort list (** The finite set of distinct values that represent the interpretation of a sort. {!get_sorts} - @returns An array of expressions, where each is an element of the universe of the sort *) - val sort_universe : model -> Sort.sort -> AST.ASTVector.ast_vector array + @returns A list of expressions, where each is an element of the universe of the sort *) + val sort_universe : model -> Sort.sort -> AST.ast list (** Conversion of models to strings. A string representation of the model. *) @@ -2514,7 +2514,7 @@ sig val get_num_probes : context -> int (** The names of all supported Probes. *) - val get_probe_names : context -> string array + val get_probe_names : context -> string list (** Returns a string containing a description of the probe with the given name. *) val get_probe_description : context -> string -> string @@ -2579,7 +2579,7 @@ sig val get_num_subgoals : apply_result -> int (** Retrieves the subgoals from the apply_result. *) - val get_subgoals : apply_result -> Goal.goal array + val get_subgoals : apply_result -> Goal.goal list (** Retrieves a subgoal from the apply_result. *) val get_subgoal : apply_result -> int -> Goal.goal @@ -2606,7 +2606,7 @@ sig val get_num_tactics : context -> int (** The names of all supported tactics. *) - val get_tactic_names : context -> string array + val get_tactic_names : context -> string list (** Returns a string containing a description of the tactic with the given name. *) val get_tactic_description : context -> string -> string @@ -2616,7 +2616,7 @@ sig (** Create a tactic that applies one tactic to a Goal and then another one to every subgoal produced by the first one. *) - val and_then : context -> tactic -> tactic -> tactic array -> tactic + val and_then : context -> tactic -> tactic -> tactic list -> tactic (** Create a tactic that first applies one tactic to a Goal and if it fails then returns the result of another tactic applied to the Goal. *) @@ -2662,7 +2662,7 @@ sig val with_ : context -> tactic -> Params.params -> tactic (** Create a tactic that applies the given tactics in parallel. *) - val par_or : context -> tactic array -> tactic + val par_or : context -> tactic list -> tactic (** Create a tactic that applies a tactic to a given goal and then another tactic to every subgoal produced by the first one. The subgoals are processed in parallel. *) @@ -2722,10 +2722,10 @@ sig val get_size : statistics -> int (** The data entries. *) - val get_entries : statistics -> Entry.statistics_entry array + val get_entries : statistics -> Entry.statistics_entry list (** The statistical counters. *) - val get_keys : statistics -> string array + val get_keys : statistics -> string list (** The value of a particular statistical counter. *) val get : statistics -> string -> Entry.statistics_entry option @@ -2759,7 +2759,7 @@ sig val reset : solver -> unit (** Assert a constraint (or multiple) into the solver. *) - val assert_ : solver -> Boolean.bool_expr array -> unit + val assert_ : solver -> Boolean.bool_expr list -> unit (** * Assert multiple constraints (cs) into the solver, and track them (in the * unsat) core @@ -2772,7 +2772,7 @@ sig * of the Boolean variables provided using {!assert_and_track} * and the Boolean literals * provided using {!check} with assumptions. *) - val assert_and_track_a : solver -> Boolean.bool_expr array -> Boolean.bool_expr array -> unit + val assert_and_track_a : solver -> Boolean.bool_expr list -> Boolean.bool_expr list -> unit (** * Assert a constraint (c) into the solver, and track it (in the unsat) core * using the Boolean constant p. @@ -2790,14 +2790,14 @@ sig val get_num_assertions : solver -> int (** The set of asserted formulas. *) - val get_assertions : solver -> Boolean.bool_expr array + val get_assertions : solver -> Boolean.bool_expr list (** Checks whether the assertions in the solver are consistent or not. {!Model} {!get_unsat_core} {!Proof} *) - val check : solver -> Boolean.bool_expr array -> status + val check : solver -> Boolean.bool_expr list -> status (** The model of the last Check. @@ -2816,7 +2816,7 @@ sig 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. *) - val get_unsat_core : solver -> AST.ASTVector.ast_vector array + val get_unsat_core : solver -> AST.ast list (** A brief justification of why the last call to Check returned UNKNOWN. *) val get_reason_unknown : solver -> string @@ -2863,7 +2863,7 @@ sig val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs (** Assert a constraints into the fixedpoint solver. *) - val assert_ : fixedpoint -> Boolean.bool_expr array -> unit + val assert_ : fixedpoint -> Boolean.bool_expr list -> unit (** Register predicate as recursive relation. *) val register_relation : fixedpoint -> FuncDecl.func_decl -> unit @@ -2872,7 +2872,7 @@ sig val add_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol option -> unit (** Add table fact to the fixedpoint solver. *) - val add_fact : fixedpoint -> FuncDecl.func_decl -> int array -> unit + val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit (** Query the fixedpoint solver. A query is a conjunction of constraints. The constraints may include the recursively defined relations. @@ -2884,7 +2884,7 @@ sig 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. *) - val query_r : fixedpoint -> FuncDecl.func_decl array -> Solver.status + val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status (** Creates a backtracking point. {!pop} *) @@ -2920,16 +2920,16 @@ sig val to_string : fixedpoint -> string (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol array -> unit + val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol list -> unit (** Convert benchmark given as set of axioms, rules and queries to a string. *) - val to_string_q : fixedpoint -> Boolean.bool_expr array -> string + val to_string_q : fixedpoint -> Boolean.bool_expr list -> string (** Retrieve set of rules added to fixedpoint context. *) - val get_rules : fixedpoint -> Boolean.bool_expr array + val get_rules : fixedpoint -> Boolean.bool_expr list (** Retrieve set of assertions added to fixedpoint context. *) - val get_assertions : fixedpoint -> Boolean.bool_expr array + val get_assertions : fixedpoint -> Boolean.bool_expr list (** Create a Fixedpoint context. *) val mk_fixedpoint : context -> fixedpoint @@ -2985,7 +2985,7 @@ sig (** Convert a benchmark into an SMT-LIB formatted string. @return A string representation of the benchmark. *) - val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr array -> Boolean.bool_expr -> string + val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr list -> Boolean.bool_expr -> string (** Parse the given string using the SMT-LIB parser. @@ -2994,45 +2994,45 @@ sig don't need to match the names of the sorts and declarations in the arrays in the fourth and sixth argument. This is a useful feature since we can use arbitrary names to reference sorts and declarations. *) - val parse_smtlib_string : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> unit + val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit (** Parse the given file using the SMT-LIB parser. {!parse_smtlib_string} *) - val parse_smtlib_file : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> unit + val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_formulas : context -> int (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_formulas : context -> Boolean.bool_expr array + val get_smtlib_formulas : context -> Boolean.bool_expr list (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_assumptions : context -> int (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_assumptions : context -> Boolean.bool_expr array + val get_smtlib_assumptions : context -> Boolean.bool_expr list (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_decls : context -> int (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_decls : context -> FuncDecl.func_decl array + val get_smtlib_decls : context -> FuncDecl.func_decl list (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_sorts : context -> int (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_sorts : context -> Sort.sort array + val get_smtlib_sorts : context -> Sort.sort list (** Parse the given string using the SMT-LIB2 parser. {!parse_smtlib_string} @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - val parse_smtlib2_string : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> Boolean.bool_expr + val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr (** Parse the given file using the SMT-LIB2 parser. {!parse_smtlib2_string} *) - val parse_smtlib2_file : context -> string -> Symbol.symbol array -> Sort.sort array -> Symbol.symbol array -> FuncDecl.func_decl array -> Boolean.bool_expr + val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr end (** Set a global (or module) parameter, which is shared by all Z3 contexts. From d293b579f376045db72bd30569583bd2cbd2ba41 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 21 Feb 2013 13:25:31 +0000 Subject: [PATCH 183/248] ML API: flat & rich layer in place. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 40 +- src/api/ml/z3.ml | 1458 ++++------------ src/api/ml/z3.mli | 460 ++--- src/api/ml/z3_rich.ml | 3400 +++++++++++++++++++++++++++++++++++++ src/api/ml/z3_rich.mli | 3072 +++++++++++++++++++++++++++++++++ 5 files changed, 7040 insertions(+), 1390 deletions(-) create mode 100644 src/api/ml/z3_rich.ml create mode 100644 src/api/ml/z3_rich.mli diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 31f31d566..823a08fe2 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -26,20 +26,14 @@ exception TestFailedException of string *) let model_converter_test ( ctx : context ) = Printf.printf "ModelConverterTest\n"; - let xr = (arith_expr_of_expr - (Expr.mk_const ctx (Symbol.mk_string ctx "x") - (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in - let yr = (arith_expr_of_expr - (Expr.mk_const ctx (Symbol.mk_string ctx "y") - (sort_of_arith_sort (arith_sort_of_real_sort (Real.mk_sort ctx))))) in + let xr = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Real.mk_sort ctx)) in + let yr = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Real.mk_sort ctx)) in let g4 = (mk_goal ctx true false false ) in - (Goal.assert_ g4 [ (mk_gt ctx xr - (arith_expr_of_real_expr (real_expr_of_rat_num - (Real.mk_numeral_nd ctx 10 1)))) ]) ; + (Goal.assert_ g4 [ (mk_gt ctx xr (Real.mk_numeral_nd ctx 10 1)) ]) ; (Goal.assert_ g4 [ (mk_eq ctx - (expr_of_arith_expr yr) - (expr_of_arith_expr (Arithmetic.mk_add ctx [ xr; (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1))) ]) ) ) ] ) ; - (Goal.assert_ g4 [ (mk_gt ctx yr (arith_expr_of_real_expr (real_expr_of_rat_num (Real.mk_numeral_nd ctx 1 1)))) ]) ; + yr + (Arithmetic.mk_add ctx [ xr; (Real.mk_numeral_nd ctx 1 1) ])) ]) ; + (Goal.assert_ g4 [ (mk_gt ctx yr (Real.mk_numeral_nd ctx 1 1)) ]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in if ((get_num_subgoals ar) == 1 && @@ -83,7 +77,7 @@ let basic_tests ( ctx : context ) = let fname = (mk_string ctx "f") in let x = (mk_string ctx "x") in let y = (mk_string ctx "y") in - let bs = (sort_of_bool_sort (Boolean.mk_sort ctx)) in + let bs = (Boolean.mk_sort ctx) in let domain = [ bs; bs ] in let f = (FuncDecl.mk_func_decl ctx fname domain bs) in let fapp = (mk_app ctx f @@ -123,10 +117,8 @@ let basic_tests ( ctx : context ) = Printf.printf "Test passed.\n" ); (Goal.assert_ g [ (mk_eq ctx - (mk_numeral_int ctx 1 - (sort_of_bitvec_sort (BitVector.mk_sort ctx 32))) - (mk_numeral_int ctx 2 - (sort_of_bitvec_sort (BitVector.mk_sort ctx 32)))) ] ) + (mk_numeral_int ctx 1 (BitVector.mk_sort ctx 32)) + (mk_numeral_int ctx 2 (BitVector.mk_sort ctx 32))) ] ) ; ( let ar = (Tactic.apply (mk_tactic ctx "smt") g None) in @@ -157,10 +149,10 @@ let basic_tests ( ctx : context ) = ); ( let g3 = (mk_goal ctx true true false) in - let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in - let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx)))) in - (Goal.assert_ g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) ]) ; - (Goal.assert_ g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (sort_of_arith_sort (arith_sort_of_int_sort (Integer.mk_sort ctx))))) ]) ; + let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Integer.mk_sort ctx)) in + let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Integer.mk_sort ctx)) in + (Goal.assert_ g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (Integer.mk_sort ctx))) ]) ; + (Goal.assert_ g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (Integer.mk_sort ctx))) ]) ; let constr = (mk_eq ctx xc yc) in (Goal.assert_ g3 [ constr ] ) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in @@ -228,9 +220,9 @@ let _ = let rs = (Real.mk_sort ctx) in Printf.printf "int symbol: %s\n" (Symbol.to_string is); Printf.printf "string symbol: %s\n" (Symbol.to_string ss); - Printf.printf "bool sort: %s\n" (Sort.to_string (sort_of_bool_sort bs)); - Printf.printf "int sort: %s\n" (Sort.to_string (sort_of_arith_sort (arith_sort_of_int_sort ints))); - Printf.printf "real sort: %s\n" (Sort.to_string (sort_of_arith_sort (arith_sort_of_real_sort rs))); + Printf.printf "bool sort: %s\n" (Sort.to_string bs); + Printf.printf "int sort: %s\n" (Sort.to_string ints); + Printf.printf "real sort: %s\n" (Sort.to_string rs); basic_tests ctx ; Printf.printf "Disposing...\n"; Gc.full_major () diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 56d319c1a..0676f1a39 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -133,52 +133,34 @@ let mk_context ( cfg : ( string * string ) list ) = module Symbol = struct - (* Symbol types *) - type int_symbol = z3_native_object - type string_symbol = z3_native_object - - type symbol = - | S_Int of int_symbol - | S_Str of string_symbol - + type symbol = z3_native_object let create_i ( ctx : context ) ( no : Z3native.ptr ) = - let res : int_symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in + let res : symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + let create_s ( ctx : context ) ( no : Z3native.ptr ) = - let res : string_symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in + let res : symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in (z3obj_sno res ctx no) ; (z3obj_create res) ; res let create ( ctx : context ) ( no : Z3native.ptr ) = match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> S_Int (create_i ctx no) - | STRING_SYMBOL -> S_Str (create_s ctx no) + | INT_SYMBOL -> (create_i ctx no) + | STRING_SYMBOL -> (create_s ctx no) - let gc ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gc n) - | S_Str(n) -> (z3obj_gc n) - - let gnc ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gnc n) - | S_Str(n) -> (z3obj_gnc n) - - let gno ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gno n) - | S_Str(n) -> (z3obj_gno n) + let gc ( x : symbol ) = (z3obj_gc x) + let gnc ( x : symbol ) = (z3obj_gnc x) + let gno ( x : symbol ) = (z3obj_gno x) let symbol_lton ( a : symbol list ) = let f ( e : symbol ) = (gno e) in @@ -187,18 +169,18 @@ struct let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL - let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) - let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) + let get_int (o : symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) + let get_string (o : symbol ) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) let to_string ( o : symbol ) = match (kind o) with | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) let mk_int ( ctx : context ) ( i : int ) = - S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) + (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) let mk_string ( ctx : context ) ( s : string ) = - S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) + (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) let mk_ints ( ctx : context ) ( names : int list ) = let f elem = mk_int ( ctx : context ) elem in @@ -353,7 +335,6 @@ open AST module Sort = struct type sort = Sort of AST.ast - type uninterpreted_sort = UninterpretedSort of sort let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> let q = (z3_native_object_of_ast_ptr ctx no) in @@ -373,14 +354,7 @@ struct | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") let ast_of_sort s = match s with Sort(x) -> x - let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x - - let uninterpreted_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - UninterpretedSort(s) - + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) @@ -409,7 +383,7 @@ struct dec_ref = Z3native.dec_ref } in (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; (z3obj_create res) ; - UninterpretedSort(Sort(res)) + Sort(res) let mk_uninterpreted_s ( ctx : context ) ( s : string ) = mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) @@ -713,9 +687,9 @@ and Expr : sig type expr = Expr of AST.ast val expr_of_ptr : context -> Z3native.ptr -> expr - val c_of_expr : expr -> context - val nc_of_expr : expr -> Z3native.ptr - val ptr_of_expr : expr -> Z3native.ptr + val gc : expr -> context + val gnc : expr -> Z3native.ptr + val gno : expr -> Z3native.ptr val expr_lton : expr list -> Z3native.ptr array val ast_of_expr : expr -> AST.ast val expr_of_ast : AST.ast -> expr @@ -762,9 +736,9 @@ sig end = struct type expr = Expr of AST.ast - let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) - let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) - let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) + let gc e = match e with Expr(a) -> (z3obj_gc a) + let gnc e = match e with Expr(a) -> (z3obj_gnc a) + let gno e = match e with Expr(a) -> (z3obj_gno a) let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then @@ -802,60 +776,60 @@ end = struct expr_of_ptr ctx o let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> expr_of_ptr (c_of_expr x) (Z3native.simplify (nc_of_expr x) (ptr_of_expr x)) - | Some pp -> expr_of_ptr (c_of_expr x) (Z3native.simplify_ex (nc_of_expr x) (ptr_of_expr x) (z3obj_gno pp)) + | None -> expr_of_ptr (Expr.gc x) (Z3native.simplify (gnc x) (gno x)) + | Some pp -> expr_of_ptr (Expr.gc x) (Z3native.simplify_ex (gnc x) (gno x) (z3obj_gno pp)) let get_simplify_help ( ctx : context ) = Z3native.simplify_get_help (context_gno ctx) let get_simplify_parameter_descrs ( ctx : context ) = Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (c_of_expr x) (Z3native.get_app_decl (nc_of_expr x) (ptr_of_expr x)) + let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (gnc x) (gno x)) - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (nc_of_expr x) (ptr_of_expr x)) + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) - let get_num_args ( x : expr ) = Z3native.get_app_num_args (nc_of_expr x) (ptr_of_expr x) + let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = expr_of_ptr (c_of_expr x) (Z3native.get_app_arg (nc_of_expr x) (ptr_of_expr x) i) in + let f i = expr_of_ptr (Expr.gc x) (Z3native.get_app_arg (gnc x) (gno x) i) in mk_list f n let update ( x : expr ) ( args : expr list ) = if (List.length args <> (get_num_args x)) then raise (Z3native.Exception "Number of arguments does not match") else - expr_of_ptr (c_of_expr x) (Z3native.update_term (nc_of_expr x) (ptr_of_expr x) (List.length args) (expr_lton args)) + expr_of_ptr (Expr.gc x) (Z3native.update_term (gnc x) (gno x) (List.length args) (expr_lton args)) let substitute ( x : expr ) from to_ = if (List.length from) <> (List.length to_) then raise (Z3native.Exception "Argument sizes do not match") else - expr_of_ptr (c_of_expr x) (Z3native.substitute (nc_of_expr x) (ptr_of_expr x) (List.length from) (expr_lton from) (expr_lton to_)) + expr_of_ptr (Expr.gc x) (Z3native.substitute (gnc x) (gno x) (List.length from) (expr_lton from) (expr_lton to_)) let substitute_one ( x : expr ) from to_ = substitute ( x : expr ) [ from ] [ to_ ] let substitute_vars ( x : expr ) to_ = - expr_of_ptr (c_of_expr x) (Z3native.substitute_vars (nc_of_expr x) (ptr_of_expr x) (List.length to_) (expr_lton to_)) + expr_of_ptr (Expr.gc x) (Z3native.substitute_vars (gnc x) (gno x) (List.length to_) (expr_lton to_)) let translate ( x : expr ) to_ctx = - if (c_of_expr x) == to_ctx then + if (Expr.gc x) == to_ctx then x else - expr_of_ptr to_ctx (Z3native.translate (nc_of_expr x) (ptr_of_expr x) (context_gno to_ctx)) + expr_of_ptr to_ctx (Z3native.translate (gnc x) (gno x) (context_gno to_ctx)) - let to_string ( x : expr ) = Z3native.ast_to_string (nc_of_expr x) (ptr_of_expr x) + let to_string ( x : expr ) = Z3native.ast_to_string (gnc x) (gno x) - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (nc_of_expr x) (ptr_of_expr x)) + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (gnc x) (gno x)) - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (nc_of_expr x) (ptr_of_expr x) + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) - let get_sort ( x : expr ) = sort_of_ptr (c_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)) + let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (gnc x) (gno x)) let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (nc_of_expr x) - (Z3native.mk_bool_sort (nc_of_expr x)) - (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x))) + (Z3native.is_eq_sort (gnc x) + (Z3native.mk_bool_sort (gnc x)) + (Z3native.get_sort (gnc x) (gno x))) let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && (get_num_args x) == 0 && @@ -901,86 +875,52 @@ open Expr module Boolean = struct - type bool_sort = BoolSort of Sort.sort - type bool_expr = BoolExpr of Expr.expr - - let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let a = (AST.ast_of_ptr ctx no) in - BoolExpr(Expr.Expr(a)) - - let bool_expr_of_expr e = - match e with Expr.Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolExpr(e) - - let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - BoolSort(sort_of_ptr ctx no) - - let sort_of_bool_sort s = match s with BoolSort(x) -> x - - let bool_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolSort(s) - - let expr_of_bool_expr e = match e with BoolExpr(x) -> x - - let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.c_of_expr e) - let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.nc_of_expr e) - let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.ptr_of_expr e) - let mk_sort ( ctx : context ) = - BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) + (sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - let s = (match (mk_sort ctx) with BoolSort(q) -> q) in - BoolExpr(Expr.mk_const ctx name s) + (Expr.mk_const ctx name (mk_sort ctx)) let mk_const_s ( ctx : context ) ( name : string ) = mk_const ctx (Symbol.mk_string ctx name) let mk_true ( ctx : context ) = - bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) + expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) let mk_false ( ctx : context ) = - bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) + expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) let mk_val ( ctx : context ) ( value : bool ) = if value then mk_true ctx else mk_false ctx let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (ptr_of_expr x) (ptr_of_expr y)) + expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) let mk_distinct ( ctx : context ) ( args : expr list ) = - bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) + expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) - let mk_not ( ctx : context ) ( a : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) + let mk_not ( ctx : context ) ( a : expr ) = + expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) - let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + let mk_ite ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( t3 : expr ) = + expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) - let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + let mk_iff ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) - let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + let mk_implies ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) - let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + let mk_xor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - let mk_and ( ctx : context ) ( args : bool_expr list ) = - let f x = (ptr_of_expr (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) + let mk_and ( ctx : context ) ( args : expr list ) = + let f x = (Expr.gno (x)) in + expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) - let mk_or ( ctx : context ) ( args : bool_expr list ) = - let f x = (ptr_of_expr (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) + let mk_or ( ctx : context ) ( args : expr list ) = + let f x = (Expr.gno (x)) in + expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) end @@ -998,9 +938,9 @@ struct else Quantifier(e) - let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (c_of_expr e) - let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (nc_of_expr e) - let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (ptr_of_expr e) + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) + let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) + let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) module Pattern = struct @@ -1031,7 +971,7 @@ struct if not (AST.is_var (match x with Expr.Expr(a) -> a)) then raise (Z3native.Exception "Term is not a bound variable.") else - Z3native.get_index_value (nc_of_expr x) (ptr_of_expr x) + Z3native.get_index_value (Expr.gnc x) (Expr.gno x) let is_universal ( x : quantifier ) = Z3native.is_quantifier_forall (gnc x) (gno x) @@ -1067,7 +1007,7 @@ struct mk_list f n let get_body ( x : quantifier ) = - Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) + expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) @@ -1087,7 +1027,7 @@ struct (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (List.length sorts) (sort_lton sorts) (Symbol.symbol_lton names) - (ptr_of_expr body))) + (Expr.gno body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) @@ -1097,7 +1037,7 @@ struct (List.length nopatterns) (expr_lton nopatterns) (List.length sorts) (sort_lton sorts) (Symbol.symbol_lton names) - (ptr_of_expr body))) + (Expr.gno body))) let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then @@ -1105,7 +1045,7 @@ struct (match weight with | None -> 1 | Some(x) -> x) (List.length bound_constants) (expr_lton bound_constants) (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (ptr_of_expr body))) + (Expr.gno body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true (match weight with | None -> 1 | Some(x) -> x) @@ -1114,7 +1054,7 @@ struct (List.length bound_constants) (expr_lton bound_constants) (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (List.length nopatterns) (expr_lton nopatterns) - (ptr_of_expr body))) + (Expr.gno body))) let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (List.length sorts) != (List.length names) then @@ -1125,7 +1065,7 @@ struct (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (List.length sorts) (sort_lton sorts) (Symbol.symbol_lton names) - (ptr_of_expr body))) + (Expr.gno body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) @@ -1135,7 +1075,7 @@ struct (List.length nopatterns) (expr_lton nopatterns) (List.length sorts) (sort_lton sorts) (Symbol.symbol_lton names) - (ptr_of_expr body))) + (Expr.gno body))) let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then @@ -1143,7 +1083,7 @@ struct (match weight with | None -> 1 | Some(x) -> x) (List.length bound_constants) (expr_lton bound_constants) (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (ptr_of_expr body))) + (Expr.gno body))) else Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false (match weight with | None -> 1 | Some(x) -> x) @@ -1152,7 +1092,7 @@ struct (List.length bound_constants) (expr_lton bound_constants) (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) (List.length nopatterns) (expr_lton nopatterns) - (ptr_of_expr body))) + (Expr.gno body))) let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = if (universal) then @@ -1170,46 +1110,8 @@ end module Array_ = struct - type array_sort = ArraySort of sort - type array_expr = ArrayExpr of expr - - let array_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (expr_of_ptr ctx no) in - ArrayExpr(e) - - let array_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - ArraySort(s) - - let sort_of_array_sort s = match s with ArraySort(x) -> x - - let array_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArraySort(s) - - let array_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArrayExpr(e) - - let expr_of_array_expr e = match e with ArrayExpr(x) -> x - - let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gno s) - - let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gc e) - let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) - let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) - let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = - array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) + sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) @@ -1218,48 +1120,40 @@ struct let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) let is_array ( x : expr ) = - (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == ARRAY_SORT) + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) - let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) - let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) + let get_domain ( x : sort ) = Sort.sort_of_ptr (Sort.gc x) (Z3native.get_array_sort_domain (Sort.gnc x) (Sort.gno x)) + let get_range ( x : sort ) = Sort.sort_of_ptr (Sort.gc x) (Z3native.get_array_sort_range (Sort.gnc x) (Sort.gno x)) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = - ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) + (Expr.mk_const ctx name (mk_sort ctx domain range)) let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = mk_const ctx (Symbol.mk_string ctx name) domain range - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (ptr_of_expr i)) + let mk_select ( ctx : context ) ( a : expr ) ( i : expr ) = + expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (Expr.gno a) (Expr.gno i)) - let mk_store ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = - array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (ptr_of_expr i) (ptr_of_expr v)) + let mk_store ( ctx : context ) ( a : expr ) ( i : expr ) ( v : expr ) = + expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (Expr.gno a) (Expr.gno i) (Expr.gno v)) let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (ptr_of_expr v)) + expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) - let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr list ) = - let m x = (ptr_of_expr (expr_of_array_expr x)) in - array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) + let mk_map ( ctx : context ) ( f : func_decl ) ( args : expr list ) = + let m x = (Expr.gno x) in + expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) - let mk_term_array ( ctx : context ) ( arg : array_expr ) = - array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) + let mk_term_array ( ctx : context ) ( arg : expr ) = + expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (Expr.gno arg)) end module Set = struct - type set_sort = SetSort of sort - - let set_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - SetSort(s) - - let sort_of_set_sort s = match s with SetSort(x) -> x - let mk_sort ( ctx : context ) ( ty : sort ) = - set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) + sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) @@ -1275,10 +1169,10 @@ struct expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) + expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (ptr_of_expr set) (ptr_of_expr element)) + expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) let mk_union ( ctx : context ) ( args : expr list ) = expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) @@ -1287,53 +1181,37 @@ struct expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) + expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) let mk_complement ( ctx : context ) ( arg : expr ) = - expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (ptr_of_expr arg)) + expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (ptr_of_expr elem) (ptr_of_expr set)) + expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (ptr_of_expr arg1) (ptr_of_expr arg2)) + expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) end module FiniteDomain = struct - type finite_domain_sort = FiniteDomainSort of sort - - let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x - - let finite_domain_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - FiniteDomainSort(s) - - let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) - let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) - let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in - FiniteDomainSort(s) + (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = mk_sort ctx (Symbol.mk_string ctx name) size - let is_finite_domain ( x : expr ) = - let nc = (nc_of_expr x) in - (Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == FINITE_DOMAIN_SORT) + let nc = (Expr.gnc x) in + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) - let get_size ( x : finite_domain_sort ) = - let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in + let get_size ( x : sort ) = + let (r, v) = (Z3native.get_finite_domain_sort_size (Sort.gnc x) (Sort.gno x)) in if r then v else raise (Z3native.Exception "Conversion failed.") end @@ -1341,29 +1219,10 @@ end module Relation = struct - type relation_sort = RelationSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - RelationSort(s) - - let sort_of_relation_sort s = match s with RelationSort(x) -> x - - let relation_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RelationSort(s) - - let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) - let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) - let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) - - let is_relation ( x : expr ) = - let nc = (nc_of_expr x) in - ((Z3native.is_app (nc_of_expr x) (ptr_of_expr x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (ptr_of_expr x))) == RELATION_SORT)) + let nc = (Expr.gnc x) in + ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) @@ -1379,48 +1238,17 @@ struct let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) - let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) + let get_arity ( x : sort ) = Z3native.get_relation_arity (Sort.gnc x) (Sort.gno x) - let get_column_sorts ( x : relation_sort ) = + let get_column_sorts ( x : sort ) = let n = get_arity x in - let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in + let f i = (sort_of_ptr (Sort.gc x) (Z3native.get_relation_column (Sort.gnc x) (Sort.gno x) i)) in mk_list f n - end module Datatype = struct - type datatype_sort = DatatypeSort of sort - type datatype_expr = DatatypeExpr of expr - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - DatatypeSort(s) - - let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x - - let datatype_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeSort(s) - - let datatype_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeExpr(e) - - let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x - - let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) - module Constructor = struct type constructor = z3_native_object @@ -1517,24 +1345,24 @@ struct ) c - let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) + let get_num_constructors ( x : sort ) = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) - let get_constructors ( x : datatype_sort ) = + let get_constructors ( x : sort ) = let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i) in mk_list f n - let get_recognizers ( x : datatype_sort ) = + let get_recognizers ( x : sort ) = let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) i) in mk_list f n - let get_accessors ( x : datatype_sort ) = + let get_accessors ( x : sort ) = let n = (get_num_constructors x) in let f i = ( - let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let fd = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i) in let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in - let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in + let g j = func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) i j) in mk_list g ds ) in mk_list f n @@ -1543,467 +1371,133 @@ end module Enumeration = struct - type enum_sort = EnumSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl list ) ( tdecls : Z3native.z3_func_decl list ) = - let s = (sort_of_ptr ctx no) in - let res = EnumSort(s) in - res - - let sort_of_enum_sort s = match s with EnumSort(x) -> x - - let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = - let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in - sort_of_ptr ctx a (list_of_array b) (list_of_array c) + let (a, _, _) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in + sort_of_ptr ctx a let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) - let get_const_decls ( x : enum_sort ) = - let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in - let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in + let get_const_decls ( x : sort ) = + let n = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) in + let f i = (func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) i)) in mk_list f n - let get_tester_decls ( x : enum_sort ) = - let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in - let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in + let get_tester_decls ( x : sort ) = + let n = Z3native.get_datatype_sort_num_constructors (Sort.gnc x) (Sort.gno x) in + let f i = (func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) i)) in mk_list f n end module List_ = -struct - type list_sort = ListSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - let res = ListSort(s) in - res - - let sort_of_list_sort s = match s with ListSort(x) -> x - - let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) - +struct let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in - sort_of_ptr ctx r a b c d e f + let (r, _, _, _, _, _, _) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in + sort_of_ptr ctx r let mk_list_s ( ctx : context ) (name : string) elem_sort = mk_sort ctx (Symbol.mk_string ctx name) elem_sort - let get_nil_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) + let get_nil_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) 0) - let get_is_nil_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) + let get_is_nil_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) 0) - let get_cons_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) + let get_cons_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor (Sort.gnc x) (Sort.gno x) 1) - let get_is_cons_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) + let get_is_cons_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_recognizer (Sort.gnc x) (Sort.gno x) 1) - let get_head_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) + let get_head_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) 1 0) - let get_tail_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) + let get_tail_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_datatype_sort_constructor_accessor (Sort.gnc x) (Sort.gno x) 1 1) - let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [] + let nil ( x : sort ) = expr_of_func_app (Sort.gc x) (get_nil_decl x) [] end module Tuple = struct - type tuple_sort = TupleSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - TupleSort(s) - - let sort_of_tuple_sort s = match s with TupleSort(x) -> x - - let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in sort_of_ptr ctx r - let get_mk_decl ( x : tuple_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) + let get_mk_decl ( x : sort ) = + func_decl_of_ptr (Sort.gc x) (Z3native.get_tuple_sort_mk_decl (Sort.gnc x) (Sort.gno x)) - let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) + let get_num_fields ( x : sort ) = Z3native.get_tuple_sort_num_fields (Sort.gnc x) (Sort.gno x) - let get_field_decls ( x : tuple_sort ) = + let get_field_decls ( x : sort ) = let n = get_num_fields x in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in + let f i = func_decl_of_ptr (Sort.gc x) (Z3native.get_tuple_sort_field_decl (Sort.gnc x) (Sort.gno x) i) in mk_list f n end -module rec Arithmetic : -sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val sort_of_arith_sort : arith_sort -> Sort.sort - val arith_sort_of_sort : Sort.sort -> arith_sort - val expr_of_arith_expr : arith_expr -> Expr.expr - val arith_expr_of_expr : Expr.expr -> arith_expr +module Arithmetic = +struct - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val int_expr_of_ptr : context -> Z3native.ptr -> int_expr - val int_num_of_ptr : context -> Z3native.ptr -> int_num - - val arith_sort_of_int_sort : Integer.int_sort -> arith_sort - val int_sort_of_arith_sort : arith_sort -> int_sort - val arith_expr_of_int_expr : int_expr -> arith_expr - val int_expr_of_int_num : int_num -> int_expr - val int_expr_of_arith_expr : arith_expr -> int_expr - val int_num_of_int_expr : int_expr -> int_num - - val mk_sort : context -> int_sort - val get_int : int_num -> int - val to_string : int_num -> string - val mk_int_const : context -> Symbol.symbol -> int_expr - val mk_int_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> int_expr - val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_int_numeral_s : context -> string -> int_num - val mk_int_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> Real.real_expr - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val real_expr_of_ptr : context -> Z3native.ptr -> real_expr - val rat_num_of_ptr : context -> Z3native.ptr -> rat_num - - val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort - val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort - val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr - val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr - val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr - val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num - - val mk_sort : context -> real_sort - val get_numerator : rat_num -> Integer.int_num - val get_denominator : rat_num -> Integer.int_num - val to_decimal_string : rat_num -> int -> string - val to_string : rat_num -> string - val mk_real_const : context -> Symbol.symbol -> real_expr - val mk_real_const_s : context -> string -> real_expr - val mk_numeral_nd : context -> int -> int -> rat_num - val mk_numeral_s : context -> string -> rat_num - val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - val mk_real2int : context -> real_expr -> Integer.int_expr - end - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : algebraic_num -> arith_expr - val algebraic_num_of_arith_expr : arith_expr -> algebraic_num - - val to_upper : algebraic_num -> int -> Real.rat_num - val to_lower : algebraic_num -> int -> Real.rat_num - val to_decimal_string : algebraic_num -> int -> string - val to_string : algebraic_num -> string - end - - val is_int : Expr.expr -> bool - val is_arithmetic_numeral : Expr.expr -> bool - val is_le : Expr.expr -> bool - val is_ge : Expr.expr -> bool - val is_lt : Expr.expr -> bool - val is_gt : Expr.expr -> bool - val is_add : Expr.expr -> bool - val is_sub : Expr.expr -> bool - val is_uminus : Expr.expr -> bool - val is_mul : Expr.expr -> bool - val is_div : Expr.expr -> bool - val is_idiv : Expr.expr -> bool - val is_remainder : Expr.expr -> bool - val is_modulus : Expr.expr -> bool - val is_inttoreal : Expr.expr -> bool - val is_real_to_int : Expr.expr -> bool - val is_real_is_int : Expr.expr -> bool - val is_real : Expr.expr -> bool - val is_int_numeral : Expr.expr -> bool - val is_rat_num : Expr.expr -> bool - val is_algebraic_number : Expr.expr -> bool - val mk_add : context -> arith_expr list -> arith_expr - val mk_mul : context -> arith_expr list -> arith_expr - val mk_sub : context -> arith_expr list -> arith_expr - val mk_unary_minus : context -> arith_expr -> arith_expr - val mk_div : context -> arith_expr -> arith_expr -> arith_expr - val mk_power : context -> arith_expr -> arith_expr -> arith_expr - val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr -end = struct - type arith_sort = ArithSort of sort - type arith_expr = ArithExpr of expr - - let arith_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithExpr(e) - - let arith_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - arith_expr_of_expr (expr_of_ptr ctx no) - - let sort_of_arith_sort s = match s with ArithSort(x) -> x - let expr_of_arith_expr e = match e with ArithExpr(x) -> x - - let arith_sort_of_sort s = match s with Sort(a) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithSort(s) - - let arith_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - arith_sort_of_sort (sort_of_ptr ctx no) - - let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gno s) - let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (c_of_expr e) - let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (nc_of_expr e) - let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (ptr_of_expr e) - - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val int_expr_of_ptr : context -> Z3native.ptr -> int_expr - val int_num_of_ptr : context -> Z3native.ptr -> int_num - - val arith_sort_of_int_sort : Integer.int_sort -> arith_sort - val int_sort_of_arith_sort : arith_sort -> int_sort - val arith_expr_of_int_expr : int_expr -> arith_expr - val int_expr_of_int_num : int_num -> int_expr - val int_expr_of_arith_expr : arith_expr -> int_expr - val int_num_of_int_expr : int_expr -> int_num - - val mk_sort : context -> int_sort - val get_int : int_num -> int - val to_string : int_num -> string - val mk_int_const : context -> Symbol.symbol -> int_expr - val mk_int_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> int_expr - val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_int_numeral_s : context -> string -> int_num - val mk_int_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> Real.real_expr - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end = struct - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - let int_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntExpr(e) - - let int_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) - - let int_num_of_int_expr e = - match e with IntExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - IntNum(e) - - let int_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_num_of_int_expr (int_expr_of_ptr ctx no) - - let arith_sort_of_int_sort s = match s with IntSort(x) -> x - let arith_expr_of_int_expr e = match e with IntExpr(x) -> x - let int_expr_of_int_num e = match e with IntNum(x) -> x - - let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntSort(s) - - let int_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_sort_of_arith_sort (arith_sort_of_sort (Sort.sort_of_ptr ctx no)) - - let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) - let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) - let sgno ( x : int_sort ) = match (x) with IntSort(s) -> (sgno s) - let egc ( x : int_expr ) = match (x) with IntExpr(e) -> (egc e) - let egnc ( x : int_expr ) = match (x) with IntExpr(e) -> (egnc e) - let egno ( x : int_expr ) = match (x) with IntExpr(e) -> (egno e) - let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) - let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) - let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - + module Integer = + struct let mk_sort ( ctx : context ) = - int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) + sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) - let get_int ( x : int_num ) = - let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + let get_int ( x : expr ) = + let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = - IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) + Expr.mk_const ctx name (mk_sort ctx) let mk_int_const_s ( ctx : context ) ( name : string ) = mk_int_const ctx (Symbol.mk_string ctx name) - let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + let mk_mod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + let mk_rem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) let mk_int_numeral_s ( ctx : context ) ( v : string ) = - int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) let mk_int_numeral_i ( ctx : context ) ( v : int ) = - int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) - let mk_int2real ( ctx : context ) ( t : int_expr ) = - Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) + let mk_int2real ( ctx : context ) ( t : expr ) = + (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (Expr.gno t))) - let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) + let mk_int2bv ( ctx : context ) ( n : int ) ( t : expr ) = + (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (Expr.gno t))) end - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val real_expr_of_ptr : context -> Z3native.ptr -> real_expr - val rat_num_of_ptr : context -> Z3native.ptr -> rat_num - - val arith_sort_of_real_sort : real_sort -> arith_sort - val real_sort_of_arith_sort : arith_sort -> real_sort - val arith_expr_of_real_expr : real_expr -> arith_expr - val real_expr_of_rat_num : rat_num -> real_expr - val real_expr_of_arith_expr : arith_expr -> real_expr - val rat_num_of_real_expr : real_expr -> rat_num - - val mk_sort : context -> real_sort - val get_numerator : rat_num -> Integer.int_num - val get_denominator : rat_num -> Integer.int_num - val to_decimal_string : rat_num -> int -> string - val to_string : rat_num -> string - val mk_real_const : context -> Symbol.symbol -> real_expr - val mk_real_const_s : context -> string -> real_expr - val mk_numeral_nd : context -> int -> int -> rat_num - val mk_numeral_s : context -> string -> rat_num - val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - val mk_real2int : context -> real_expr -> Integer.int_expr - end = struct - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - let arith_sort_of_real_sort s = match s with RealSort(x) -> x - let arith_expr_of_real_expr e = match e with RealExpr(x) -> x - let real_expr_of_rat_num e = match e with RatNum(x) -> x - - let real_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealExpr(e) - - let real_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) - - let rat_num_of_real_expr e = - match e with RealExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - RatNum(e) - - let rat_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - rat_num_of_real_expr (real_expr_of_ptr ctx no) - - let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealSort(s) - - let real_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) - - let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) - let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) - let sgno ( x : real_sort ) = match (x) with RealSort(s) -> (sgno s) - let egc ( x : real_expr ) = match (x) with RealExpr(e) -> (egc e) - let egnc ( x : real_expr ) = match (x) with RealExpr(e) -> (egnc e) - let egno ( x : real_expr ) = match (x) with RealExpr(e) -> (egno e) - let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) - let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) - let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - - + module Real = + struct let mk_sort ( ctx : context ) = - real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) + sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) - let get_numerator ( x : rat_num ) = - Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + let get_numerator ( x : expr ) = + expr_of_ptr (Expr.gc x) (Z3native.get_numerator (Expr.gnc x) (Expr.gno x)) - let get_denominator ( x : rat_num ) = - Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + let get_denominator ( x : expr ) = + expr_of_ptr (Expr.gc x) (Z3native.get_denominator (Expr.gnc x) (Expr.gno x)) - let to_decimal_string ( x : rat_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + let to_decimal_string ( x : expr ) ( precision : int ) = + Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = - RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) + Expr.mk_const ctx name (mk_sort ctx) let mk_real_const_s ( ctx : context ) ( name : string ) = mk_real_const ctx (Symbol.mk_string ctx name) @@ -2012,67 +1506,38 @@ end = struct if (den == 0) then raise (Z3native.Exception "Denominator is zero") else - rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) + expr_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) let mk_numeral_s ( ctx : context ) ( v : string ) = - rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) let mk_numeral_i ( ctx : context ) ( v : int ) = - rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) - let mk_is_integer ( ctx : context ) ( t : real_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) + let mk_is_integer ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (Expr.gno t))) - let mk_real2int ( ctx : context ) ( t : real_expr ) = - Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) + let mk_real2int ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (Expr.gno t))) end - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : algebraic_num -> arith_expr - val algebraic_num_of_arith_expr : arith_expr -> algebraic_num - - val to_upper : algebraic_num -> int -> Real.rat_num - val to_lower : algebraic_num -> int -> Real.rat_num - val to_decimal_string : algebraic_num -> int -> string - val to_string : algebraic_num -> string - end = struct - type algebraic_num = AlgebraicNum of arith_expr - - let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x - - let algebraic_num_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - AlgebraicNum(e) - - let algebraic_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) - - let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) - let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) - let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - - - let to_upper ( x : algebraic_num ) ( precision : int ) = - Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + module AlgebraicNumber = + struct + let to_upper ( x : expr ) ( precision : int ) = + expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_upper (Expr.gnc x) (Expr.gno x) precision) - let to_lower ( x : algebraic_num ) precision = - Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + let to_lower ( x : expr ) precision = + expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_lower (Expr.gnc x) (Expr.gno x) precision) - let to_decimal_string ( x : algebraic_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + let to_decimal_string ( x : expr ) ( precision : int ) = + Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) end let is_int ( x : expr ) = - (Z3native.is_numeral_ast (nc_of_expr x) (nc_of_expr x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == INT_SORT) + (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) @@ -2107,224 +1572,55 @@ end = struct let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (nc_of_expr x)))) == REAL_SORT) + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (nc_of_expr x) (nc_of_expr x) + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) - let mk_add ( ctx : context ) ( t : arith_expr list ) = - let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + let mk_add ( ctx : context ) ( t : expr list ) = + let f x = (Expr.gno x) in + (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_mul ( ctx : context ) ( t : arith_expr list ) = - let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + let mk_mul ( ctx : context ) ( t : expr list ) = + let f x = (Expr.gno x) in + (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_sub ( ctx : context ) ( t : arith_expr list ) = - let f x = (ptr_of_expr (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + let mk_sub ( ctx : context ) ( t : expr list ) = + let f x = (Expr.gno x) in + (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) + let mk_unary_minus ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (Expr.gno t))) - let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) + let mk_div ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) + let mk_power ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) + let mk_lt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) + let mk_le ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) + let mk_gt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) + let mk_ge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) end -and BitVector : -sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort - val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort - val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr - val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr - val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr - val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num - - val mk_sort : context -> int -> bitvec_sort - val is_bv : Expr.expr -> bool - val is_bv_numeral : Expr.expr -> bool - val is_bv_bit1 : Expr.expr -> bool - val is_bv_bit0 : Expr.expr -> bool - val is_bv_uminus : Expr.expr -> bool - val is_bv_add : Expr.expr -> bool - val is_bv_sub : Expr.expr -> bool - val is_bv_mul : Expr.expr -> bool - val is_bv_sdiv : Expr.expr -> bool - val is_bv_udiv : Expr.expr -> bool - val is_bv_SRem : Expr.expr -> bool - val is_bv_urem : Expr.expr -> bool - val is_bv_smod : Expr.expr -> bool - val is_bv_sdiv0 : Expr.expr -> bool - val is_bv_udiv0 : Expr.expr -> bool - val is_bv_srem0 : Expr.expr -> bool - val is_bv_urem0 : Expr.expr -> bool - val is_bv_smod0 : Expr.expr -> bool - val is_bv_ule : Expr.expr -> bool - val is_bv_sle : Expr.expr -> bool - val is_bv_uge : Expr.expr -> bool - val is_bv_sge : Expr.expr -> bool - val is_bv_ult : Expr.expr -> bool - val is_bv_slt : Expr.expr -> bool - val is_bv_ugt : Expr.expr -> bool - val is_bv_sgt : Expr.expr -> bool - val is_bv_and : Expr.expr -> bool - val is_bv_or : Expr.expr -> bool - val is_bv_not : Expr.expr -> bool - val is_bv_xor : Expr.expr -> bool - val is_bv_nand : Expr.expr -> bool - val is_bv_nor : Expr.expr -> bool - val is_bv_xnor : Expr.expr -> bool - val is_bv_concat : Expr.expr -> bool - val is_bv_signextension : Expr.expr -> bool - val is_bv_zeroextension : Expr.expr -> bool - val is_bv_extract : Expr.expr -> bool - val is_bv_repeat : Expr.expr -> bool - val is_bv_reduceor : Expr.expr -> bool - val is_bv_reduceand : Expr.expr -> bool - val is_bv_comp : Expr.expr -> bool - val is_bv_shiftleft : Expr.expr -> bool - val is_bv_shiftrightlogical : Expr.expr -> bool - val is_bv_shiftrightarithmetic : Expr.expr -> bool - val is_bv_rotateleft : Expr.expr -> bool - val is_bv_rotateright : Expr.expr -> bool - val is_bv_rotateleftextended : Expr.expr -> bool - val is_bv_rotaterightextended : Expr.expr -> bool - val is_int_to_bv : Expr.expr -> bool - val is_bv_to_int : Expr.expr -> bool - val is_bv_carry : Expr.expr -> bool - val is_bv_xor3 : Expr.expr -> bool - val get_size : bitvec_sort -> int - val get_int : bitvec_num -> int - val to_string : bitvec_num -> string - val mk_const : context -> Symbol.symbol -> int -> bitvec_expr - val mk_const_s : context -> string -> int -> bitvec_expr - val mk_not : context -> bitvec_expr -> Expr.expr - val mk_redand : context -> bitvec_expr -> Expr.expr - val mk_redor : context -> bitvec_expr -> Expr.expr - val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_neg : context -> bitvec_expr -> bitvec_expr - val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr - val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr - val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr - val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr - val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr - val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr - val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr - val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr - val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_numeral : context -> string -> int -> bitvec_num -end = struct - type bitvec_sort = BitVecSort of sort - type bitvec_expr = BitVecExpr of expr - type bitvec_num = BitVecNum of bitvec_expr - - let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x - - let bitvec_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecSort(s) - - let bitvec_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_sort_of_sort (sort_of_ptr ctx no) - - let bitvec_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecExpr(e) - - let bitvec_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_expr_of_expr (expr_of_ptr ctx no) - - let bitvec_num_of_bitvec_expr e = - match e with BitVecExpr(Expr(a)) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecNum(e) - - let bitvec_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_num_of_bitvec_expr (bitvec_expr_of_expr (expr_of_ptr ctx no)) - - let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x - let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x - - - let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) - let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) - let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) - let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (c_of_expr e) - let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (nc_of_expr e) - let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (ptr_of_expr e) - let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) - let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) - let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - - +module BitVector = +struct let mk_sort ( ctx : context ) size = - bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) + sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) let is_bv ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (nc_of_expr x) (Z3native.get_sort (nc_of_expr x) (ptr_of_expr x)))) == BV_SORT) + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) @@ -2376,112 +1672,112 @@ end = struct let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) - let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) - let get_int ( x : bitvec_num ) = - let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + let get_size (x : sort ) = Z3native.get_bv_sort_size (Sort.gnc x) (Sort.gno x) + let get_int ( x : expr ) = + let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) + Expr.mk_const ctx name (mk_sort ctx size) let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = mk_const ctx (Symbol.mk_string ctx name) size - let mk_not ( ctx : context ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) - let mk_redand ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) - let mk_redor ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) - let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) - let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) - let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) - let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) - let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) - let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) - let mk_neg ( ctx : context ) ( t : bitvec_expr) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) - let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) - let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) - let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) - let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) - let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) - let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) - let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) - let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) - let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) - let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) - let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) - let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) - let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) - let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) - let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) - let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) - let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) - let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) - let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) - let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) - let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) - let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) - let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) - let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) - let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) - let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) - let mk_ext_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) - let mk_ext_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) - let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = - Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) - let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) - let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) - let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) - let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) - let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) + let mk_not ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (Expr.gno t)) + let mk_redand ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (Expr.gno t)) + let mk_redor ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (Expr.gno t)) + let mk_and ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_or ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_xor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_nand ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_nor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_xnor ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_neg ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (Expr.gno t)) + let mk_add ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_sub ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_mul ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_udiv ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_sdiv ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_urem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_srem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_smod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_ult ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_slt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_ule ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sle ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_uge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sge ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_ugt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sgt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_concat ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (Expr.gno t)) + let mk_sign_ext ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (Expr.gno t)) + let mk_zero_ext ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (Expr.gno t)) + let mk_repeat ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (Expr.gno t)) + let mk_shl ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_lshr ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_ashr ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_rotate_left ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (Expr.gno t)) + let mk_rotate_right ( ctx : context ) ( i : int ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (Expr.gno t)) + let mk_ext_rotate_left ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_ext_rotate_right ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_bv2int ( ctx : context ) ( t : expr ) ( signed : bool ) = + expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (Expr.gno t) signed) + let mk_add_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = + (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) + let mk_add_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sub_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_sub_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = + (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) + let mk_sdiv_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + let mk_neg_no_overflow ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (Expr.gno t))) + let mk_mul_no_overflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) ( signed : bool) = + (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) + let mk_mul_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = - bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx size))) end @@ -2556,8 +1852,8 @@ struct let is_garbage ( x : goal ) = (get_precision x) == GOAL_UNDER_OVER - let assert_ ( x : goal ) ( constraints : Boolean.bool_expr list ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in + let assert_ ( x : goal ) ( constraints : expr list ) = + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e) in ignore (List.map f constraints) ; () @@ -2572,7 +1868,7 @@ struct let get_formulas ( x : goal ) = let n = get_size x in - let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) + let f i = ((expr_of_ptr (z3obj_gc x) (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in mk_list f n @@ -2749,7 +2045,7 @@ struct exception ModelEvaluationFailedException of string let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (ptr_of_expr t) completion) in + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in if not r then raise (ModelEvaluationFailedException "evaluation failed") else @@ -3076,19 +2372,19 @@ struct let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - let assert_ ( x : solver ) ( constraints : Boolean.bool_expr list ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in + let assert_ ( x : solver ) ( constraints : expr list ) = + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in ignore (List.map f constraints) - let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr list ) ( ps : Boolean.bool_expr list ) = + let assert_and_track_a ( x : solver ) ( cs : expr list ) ( ps : expr list ) = if ((List.length cs) != (List.length ps)) then raise (Z3native.Exception "Argument size mismatch") else - let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno a) (Boolean.gno b)) in + let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Expr.gno a) (Expr.gno b)) in ignore (List.iter2 f cs ps) - let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) + let assert_and_track ( x : solver ) ( c : expr ) ( p : expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Expr.gno c) (Expr.gno p) let get_num_assertions ( x : solver ) = let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in @@ -3097,15 +2393,15 @@ struct let get_assertions ( x : solver ) = let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in + let f i = (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in mk_list f n - let check ( x : solver ) ( assumptions : Boolean.bool_expr list ) = + let check ( x : solver ) ( assumptions : expr list ) = let r = if ((List.length assumptions) == 0) then lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) else - let f x = (ptr_of_expr (Boolean.expr_of_bool_expr x)) in + let f x = (Expr.gno x) in lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) in match r with @@ -3179,24 +2475,24 @@ struct let get_param_descrs ( x : fixedpoint ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr list ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in + let assert_ ( x : fixedpoint ) ( constraints : expr list ) = + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in ignore (List.map f constraints) ; () let register_relation ( x : fixedpoint ) ( f : func_decl ) = Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) - let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = + let add_rule ( x : fixedpoint ) ( rule : expr ) ( name : Symbol.symbol option ) = match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) (Symbol.gno y) let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) - let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with + let query ( x : fixedpoint ) ( query : expr ) = + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Expr.gno query))) with | L_TRUE -> Solver.SATISFIABLE | L_FALSE -> Solver.UNSATISFIABLE | _ -> Solver.UNKNOWN @@ -3214,8 +2510,8 @@ struct let pop ( x : fixedpoint ) = Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) - let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) + let update_rule ( x : fixedpoint ) ( rule : expr ) ( name : Symbol.symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Expr.gno rule) (Symbol.gno name) let get_answer ( x : fixedpoint ) = let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in @@ -3238,27 +2534,27 @@ struct Some (expr_of_ptr (z3obj_gc x) q) let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (ptr_of_expr property) + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) - let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr list ) = - let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in + let to_string_q ( x : fixedpoint ) ( queries : expr list ) = + let f x = Expr.gno x in Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) let get_rules ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in mk_list f n let get_assertions ( x : fixedpoint ) = let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in mk_list f n let mk_fixedpoint ( ctx : context ) = create ctx @@ -3287,10 +2583,10 @@ end module SMT = struct - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr list ) ( formula : Boolean.bool_expr ) = + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : expr list ) ( formula : expr ) = Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (List.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.of_list (List.map f assumptions))) - (Boolean.gno formula) + (List.length assumptions) (let f x = Expr.gno (x) in (Array.of_list (List.map f assumptions))) + (Expr.gno formula) let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = let csn = (List.length sort_names) in @@ -3328,14 +2624,14 @@ struct let get_smtlib_formulas ( ctx : context ) = let n = (get_num_smtlib_formulas ctx ) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in + let f i =(expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in mk_list f n let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) let get_smtlib_assumptions ( ctx : context ) = let n = (get_num_smtlib_assumptions ctx ) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in + let f i = (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in mk_list f n let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) @@ -3360,14 +2656,14 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) - + (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = let csn = (List.length sort_names) in let cs = (List.length sorts) in @@ -3376,13 +2672,13 @@ struct if (csn != cs || cdn != cd) then raise (Z3native.Exception "Argument size mismatch") else - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) + (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) end diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 9f451c45f..908b3023d 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -70,14 +70,7 @@ end (** Symbols are used to name several term and type constructors *) module Symbol : sig - (** Numbered Symbols *) - type int_symbol - - (** Named Symbols *) - type string_symbol - - (** Symbols *) - type symbol = S_Int of int_symbol | S_Str of string_symbol + type symbol (** The kind of the symbol (int or string) *) val kind : symbol -> Z3enums.symbol_kind @@ -89,10 +82,10 @@ sig val is_string_symbol : symbol -> bool (** The int value of the symbol. *) - val get_int : int_symbol -> int + val get_int : symbol -> int (** The string value of the symbol. *) - val get_string : string_symbol -> string + val get_string : symbol -> string (** A string representation of the symbol. *) val to_string : symbol -> string @@ -251,15 +244,9 @@ end (** The Sort module implements type information for ASTs *) module Sort : sig - (** Sorts *) type sort = Sort of AST.ast - (** Uninterpreted Sorts *) - type uninterpreted_sort = UninterpretedSort of sort - val ast_of_sort : sort -> AST.ast - val sort_of_uninterpreted_sort : uninterpreted_sort -> sort - val uninterpreted_sort_of_sort : sort -> uninterpreted_sort (** Comparison operator. @return True if the two sorts are from the same context @@ -279,10 +266,10 @@ sig val to_string : sort -> string (** Create a new uninterpreted sort. *) - val mk_uninterpreted : context -> Symbol.symbol -> uninterpreted_sort + val mk_uninterpreted : context -> Symbol.symbol -> sort (** Create a new uninterpreted sort. *) - val mk_uninterpreted_s : context -> string -> uninterpreted_sort + val mk_uninterpreted_s : context -> string -> sort end (** Function declarations *) @@ -597,58 +584,50 @@ end (** Boolean expressions *) module Boolean : sig - type bool_sort = BoolSort of Sort.sort - type bool_expr = BoolExpr of Expr.expr - - val expr_of_bool_expr : bool_expr -> Expr.expr - val sort_of_bool_sort : bool_sort -> Sort.sort - val bool_sort_of_sort : Sort.sort -> bool_sort - val bool_expr_of_expr : Expr.expr -> bool_expr - (** Create a Boolean sort *) - val mk_sort : context -> bool_sort + val mk_sort : context -> Sort.sort (** Create a Boolean constant. *) - val mk_const : context -> Symbol.symbol -> bool_expr + val mk_const : context -> Symbol.symbol -> Expr.expr (** Create a Boolean constant. *) - val mk_const_s : context -> string -> bool_expr + val mk_const_s : context -> string -> Expr.expr (** The true Term. *) - val mk_true : context -> bool_expr + val mk_true : context -> Expr.expr (** The false Term. *) - val mk_false : context -> bool_expr + val mk_false : context -> Expr.expr (** Creates a Boolean value. *) - val mk_val : context -> bool -> bool_expr + val mk_val : context -> bool -> Expr.expr (** Creates the equality between two expr's. *) - val mk_eq : context -> Expr.expr -> Expr.expr -> bool_expr + val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr (** Creates a distinct term. *) - val mk_distinct : context -> Expr.expr list -> bool_expr + val mk_distinct : context -> Expr.expr list -> Expr.expr (** Mk an expression representing not(a). *) - val mk_not : context -> bool_expr -> bool_expr + val mk_not : context -> Expr.expr -> Expr.expr (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) - val mk_ite : context -> bool_expr -> bool_expr -> bool_expr -> bool_expr + val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 iff t2. *) - val mk_iff : context -> bool_expr -> bool_expr -> bool_expr + val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 -> t2. *) - val mk_implies : context -> bool_expr -> bool_expr -> bool_expr + val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 xor t2. *) - val mk_xor : context -> bool_expr -> bool_expr -> bool_expr + val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing the AND of args *) - val mk_and : context -> bool_expr list -> bool_expr + val mk_and : context -> Expr.expr list -> Expr.expr (** Create an expression representing the OR of args *) - val mk_or : context -> bool_expr list -> bool_expr + val mk_or : context -> Expr.expr list -> Expr.expr end (** Quantifier expressions *) @@ -731,7 +710,7 @@ sig val get_bound_variable_sorts : quantifier -> Sort.sort list (** The body of the quantifier. *) - val get_body : quantifier -> Boolean.bool_expr + val get_body : quantifier -> Expr.expr (** Creates a new bound variable. *) val mk_bound : context -> int -> Sort.sort -> Expr.expr @@ -761,17 +740,8 @@ end (** Functions to manipulate Array expressions *) module Array_ : sig - type array_sort = ArraySort of Sort.sort - type array_expr = ArrayExpr of Expr.expr - - val sort_of_array_sort : array_sort -> Sort.sort - val array_sort_of_sort : Sort.sort -> array_sort - val expr_of_array_expr : array_expr -> Expr.expr - - val array_expr_of_expr : Expr.expr -> array_expr - (** Create a new array sort. *) - val mk_sort : context -> Sort.sort -> Sort.sort -> array_sort + val mk_sort : context -> Sort.sort -> Sort.sort -> Sort.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). @@ -802,16 +772,16 @@ sig val is_array : Expr.expr -> bool (** The domain of the array sort. *) - val get_domain : array_sort -> Sort.sort + val get_domain : Sort.sort -> Sort.sort (** The range of the array sort. *) - val get_range : array_sort -> Sort.sort + val get_range : Sort.sort -> Sort.sort (** Create an array constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> array_expr + val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> Expr.expr (** Create an array constant. *) - val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> array_expr + val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> Expr.expr (** Array read. @@ -823,7 +793,7 @@ sig The sort of the result is range. {!Array_.mk_sort} {!mk_store} *) - val mk_select : context -> array_expr -> Expr.expr -> array_expr + val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr (** Array update. @@ -839,7 +809,7 @@ sig respect to i may be a different value). {!Array_.mk_sort} {!mk_select} *) - val mk_store : context -> array_expr -> Expr.expr -> Expr.expr -> array_expr + val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr (** Create a constant array. @@ -847,7 +817,7 @@ sig produces the value v. {!Array_.mk_sort} {!mk_select} *) - val mk_const_array : context -> Sort.sort -> Expr.expr -> array_expr + val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr (** Maps f on the argument arrays. @@ -857,24 +827,20 @@ sig {!Array_.mk_sort} {!mk_select} {!mk_store} *) - val mk_map : context -> FuncDecl.func_decl -> array_expr list -> array_expr + val mk_map : context -> FuncDecl.func_decl -> Expr.expr list -> Expr.expr (** Access the array default value. Produces the default range value, for arrays that can be represented as finite maps with a default range value. *) - val mk_term_array : context -> array_expr -> array_expr + val mk_term_array : context -> Expr.expr -> Expr.expr end (** Functions to manipulate Set expressions *) module Set : sig - type set_sort = SetSort of Sort.sort - - val sort_of_set_sort : set_sort -> Sort.sort - (** Create a set type. *) - val mk_sort : context -> Sort.sort -> set_sort + val mk_sort : context -> Sort.sort -> Sort.sort (** Indicates whether the term is set union *) val is_union : Expr.expr -> bool @@ -925,16 +891,11 @@ end (** Functions to manipulate Finite Domain expressions *) module FiniteDomain : sig - type finite_domain_sort = FiniteDomainSort of Sort.sort - - val sort_of_finite_domain_sort : finite_domain_sort -> Sort.sort - val finite_domain_sort_of_sort : Sort.sort -> finite_domain_sort + (** Create a new finite domain sort. *) + val mk_sort : context -> Symbol.symbol -> int -> Sort.sort (** Create a new finite domain sort. *) - val mk_sort : context -> Symbol.symbol -> int -> finite_domain_sort - - (** Create a new finite domain sort. *) - val mk_sort_s : context -> string -> int -> finite_domain_sort + val mk_sort_s : context -> string -> int -> Sort.sort (** Indicates whether the term is of an array sort. *) val is_finite_domain : Expr.expr -> bool @@ -943,18 +904,13 @@ sig val is_lt : Expr.expr -> bool (** The size of the finite domain sort. *) - val get_size : finite_domain_sort -> int + val get_size : Sort.sort -> int end (** Functions to manipulate Relation expressions *) module Relation : sig - type relation_sort = RelationSort of Sort.sort - - val sort_of_relation_sort : relation_sort -> Sort.sort - val relation_sort_of_sort : Sort.sort -> relation_sort - (** Indicates whether the term is of a relation sort. *) val is_relation : Expr.expr -> bool @@ -1034,23 +990,15 @@ sig val is_clone : Expr.expr -> bool (** The arity of the relation sort. *) - val get_arity : relation_sort -> int + val get_arity : Sort.sort -> int (** The sorts of the columns of the relation sort. *) - val get_column_sorts : relation_sort -> relation_sort list + val get_column_sorts : Sort.sort -> Sort.sort list end (** Functions to manipulate Datatype expressions *) module Datatype : sig - type datatype_sort = DatatypeSort of Sort.sort - type datatype_expr = DatatypeExpr of Expr.expr - - val sort_of_datatype_sort : datatype_sort -> Sort.sort - val datatype_sort_of_sort : Sort.sort -> datatype_sort - val expr_of_datatype_expr : datatype_expr -> Expr.expr - val datatype_expr_of_expr : Expr.expr -> datatype_expr - (** Datatype Constructors *) module Constructor : sig @@ -1080,160 +1028,129 @@ sig val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor (** Create a new datatype sort. *) - val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> datatype_sort + val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> Sort.sort (** Create a new datatype sort. *) - val mk_sort_s : context -> string -> Constructor.constructor list -> datatype_sort + val mk_sort_s : context -> string -> Constructor.constructor list -> Sort.sort (** Create mutually recursive datatypes. *) - val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> datatype_sort list + val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> Sort.sort list (** Create mutually recursive data-types. *) - val mk_sorts_s : context -> string list -> Constructor.constructor list list -> datatype_sort list + val mk_sorts_s : context -> string list -> Constructor.constructor list list -> Sort.sort list (** The number of constructors of the datatype sort. *) - val get_num_constructors : datatype_sort -> int + val get_num_constructors : Sort.sort -> int (** The constructors. *) - val get_constructors : datatype_sort -> FuncDecl.func_decl list + val get_constructors : Sort.sort -> FuncDecl.func_decl list (** The recognizers. *) - val get_recognizers : datatype_sort -> FuncDecl.func_decl list + val get_recognizers : Sort.sort -> FuncDecl.func_decl list (** The constructor accessors. *) - val get_accessors : datatype_sort -> FuncDecl.func_decl list list + val get_accessors : Sort.sort -> FuncDecl.func_decl list list end (** Functions to manipulate Enumeration expressions *) module Enumeration : sig - type enum_sort = EnumSort of Sort.sort - - val sort_of_enum_sort : enum_sort -> Sort.sort + (** Create a new enumeration sort. *) + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort (** Create a new enumeration sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> enum_sort - - (** Create a new enumeration sort. *) - val mk_sort_s : context -> string -> string list -> enum_sort + val mk_sort_s : context -> string -> string list -> Sort.sort (** The function declarations of the constants in the enumeration. *) - val get_const_decls : enum_sort -> FuncDecl.func_decl list + val get_const_decls : Sort.sort -> FuncDecl.func_decl list (** The test predicates for the constants in the enumeration. *) - val get_tester_decls : enum_sort -> FuncDecl.func_decl list + val get_tester_decls : Sort.sort -> FuncDecl.func_decl list end (** Functions to manipulate List expressions *) module List_ : sig - type list_sort = ListSort of Sort.sort - - val sort_of_list_sort : list_sort -> Sort.sort + (** Create a new list sort. *) + val mk_sort : context -> Symbol.symbol -> Sort.sort -> Sort.sort (** Create a new list sort. *) - val mk_sort : context -> Symbol.symbol -> Sort.sort -> list_sort - - (** Create a new list sort. *) - val mk_list_s : context -> string -> Sort.sort -> list_sort + val mk_list_s : context -> string -> Sort.sort -> Sort.sort (** The declaration of the nil function of this list sort. *) - val get_nil_decl : list_sort -> FuncDecl.func_decl + val get_nil_decl : Sort.sort -> FuncDecl.func_decl (** The declaration of the isNil function of this list sort. *) - val get_is_nil_decl : list_sort -> FuncDecl.func_decl + val get_is_nil_decl : Sort.sort -> FuncDecl.func_decl (** The declaration of the cons function of this list sort. *) - val get_cons_decl : list_sort -> FuncDecl.func_decl + val get_cons_decl : Sort.sort -> FuncDecl.func_decl (** The declaration of the isCons function of this list sort. *) - val get_is_cons_decl : list_sort -> FuncDecl.func_decl + val get_is_cons_decl : Sort.sort -> FuncDecl.func_decl (** The declaration of the head function of this list sort. *) - val get_head_decl : list_sort -> FuncDecl.func_decl + val get_head_decl : Sort.sort -> FuncDecl.func_decl (** The declaration of the tail function of this list sort. *) - val get_tail_decl : list_sort -> FuncDecl.func_decl + val get_tail_decl : Sort.sort -> FuncDecl.func_decl (** The empty list. *) - val nil : list_sort -> Expr.expr + val nil : Sort.sort -> Expr.expr end (** Functions to manipulate Tuple expressions *) module Tuple : sig - type tuple_sort = TupleSort of Sort.sort - - val sort_of_tuple_sort : tuple_sort -> Sort.sort - (** Create a new tuple sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> tuple_sort + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> Sort.sort (** The constructor function of the tuple. *) - val get_mk_decl : tuple_sort -> FuncDecl.func_decl + val get_mk_decl : Sort.sort -> FuncDecl.func_decl (** The number of fields in the tuple. *) - val get_num_fields : tuple_sort -> int + val get_num_fields : Sort.sort -> int (** The field declarations. *) - val get_field_decls : tuple_sort -> FuncDecl.func_decl list + val get_field_decls : Sort.sort -> FuncDecl.func_decl list end (** Functions to manipulate arithmetic expressions *) module rec Arithmetic : sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val sort_of_arith_sort : Arithmetic.arith_sort -> Sort.sort - val arith_sort_of_sort : Sort.sort -> Arithmetic.arith_sort - val expr_of_arith_expr : Arithmetic.arith_expr -> Expr.expr - val arith_expr_of_expr : Expr.expr -> Arithmetic.arith_expr - (** Integer Arithmetic *) module rec Integer : sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val arith_sort_of_int_sort : Arithmetic.Integer.int_sort -> Arithmetic.arith_sort - val int_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Integer.int_sort - val arith_expr_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.arith_expr - val int_expr_of_int_num : Arithmetic.Integer.int_num -> Arithmetic.Integer.int_expr - val int_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Integer.int_expr - val int_num_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.Integer.int_num - (** Create a new integer sort. *) - val mk_sort : context -> int_sort + val mk_sort : context -> Sort.sort (** Retrieve the int value. *) - val get_int : int_num -> int + val get_int : Expr.expr -> int (** Returns a string representation of the numeral. *) - val to_string : int_num -> string + val to_string : Expr.expr -> string (** Creates an integer constant. *) - val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const : context -> Symbol.symbol -> Expr.expr (** Creates an integer constant. *) - val mk_int_const_s : context -> string -> int_expr + val mk_int_const_s : context -> string -> Expr.expr (** Create an expression representing t1 mod t2. The arguments must have int type. *) - val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_mod : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 rem t2. The arguments must have int type. *) - val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an integer numeral. *) - val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_s : context -> string -> Expr.expr (** Create an integer numeral. @return A Term with the given value and sort Integer *) - val mk_int_numeral_i : context -> int -> int_num + val mk_int_numeral_i : context -> int -> Expr.expr (** Coerce an integer to a real. @@ -1243,7 +1160,7 @@ sig 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. *) - val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2real : context -> Expr.expr -> Expr.expr (** Create an n-bit bit-vector from an integer argument. @@ -1253,94 +1170,78 @@ sig when solving constraints with this function. The argument must be of integer sort. *) - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + val mk_int2bv : context -> int -> Expr.expr -> Expr.expr end (** Real Arithmetic *) and Real : sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort - val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort - val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr - val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr - val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr - val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num - (** Create a real sort. *) - val mk_sort : context -> real_sort + val mk_sort : context -> Sort.sort (** The numerator of a rational numeral. *) - val get_numerator : rat_num -> Integer.int_num + val get_numerator : Expr.expr-> Expr.expr (** The denominator of a rational numeral. *) - val get_denominator : rat_num -> Integer.int_num + val get_denominator : Expr.expr-> Expr.expr (** Returns a string representation in decimal notation. The result has at most as many decimal places as indicated by the int argument.*) - val to_decimal_string : rat_num -> int -> string + val to_decimal_string : Expr.expr-> int -> string (** Returns a string representation of the numeral. *) - val to_string : rat_num -> string + val to_string : Expr.expr-> string (** Creates a real constant. *) - val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const : context -> Symbol.symbol -> Expr.expr (** Creates a real constant. *) - val mk_real_const_s : context -> string -> real_expr + val mk_real_const_s : context -> string -> Expr.expr (** Create a real numeral from a fraction. @return A Term with rational value and sort Real {!mk_numeral_s} *) - val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_nd : context -> int -> int -> Expr.expr (** Create a real numeral. @return A Term with the given value and sort Real *) - val mk_numeral_s : context -> string -> rat_num + val mk_numeral_s : context -> string -> Expr.expr (** Create a real numeral. @return A Term with the given value and sort Real *) - val mk_numeral_i : context -> int -> rat_num + val mk_numeral_i : context -> int -> Expr.expr (** Creates an expression that checks whether a real number is an integer. *) - val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_is_integer : context -> Expr.expr -> Expr.expr (** 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. *) - val mk_real2int : context -> real_expr -> Integer.int_expr + val mk_real2int : context -> Expr.expr -> Expr.expr end (** Algebraic Numbers *) and AlgebraicNumber : sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : Arithmetic.AlgebraicNumber.algebraic_num -> Arithmetic.arith_expr - val algebraic_num_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.AlgebraicNumber.algebraic_num - (** Return a upper bound for a given real algebraic number. The interval isolating the number is smaller than 1/10^precision. {!is_algebraic_number} @return A numeral Expr of sort Real *) - val to_upper : algebraic_num -> int -> Real.rat_num + val to_upper : Expr.expr -> int -> Expr.expr (** Return a lower bound for the given real algebraic number. The interval isolating the number is smaller than 1/10^precision. {!is_algebraic_number} @return A numeral Expr of sort Real *) - val to_lower : algebraic_num -> int -> Real.rat_num + val to_lower : Expr.expr -> int -> Expr.expr (** Returns a string representation in decimal notation. The result has at most as many decimal places as the int argument provided.*) - val to_decimal_string : algebraic_num -> int -> string + val to_decimal_string : Expr.expr -> int -> string (** Returns a string representation of the numeral. *) - val to_string : algebraic_num -> string + val to_string : Expr.expr -> string end (** Indicates whether the term is of integer sort. *) @@ -1407,52 +1308,41 @@ sig val is_algebraic_number : Expr.expr -> bool (** Create an expression representing t[0] + t[1] + .... *) - val mk_add : context -> arith_expr list -> arith_expr + val mk_add : context -> Expr.expr list -> Expr.expr (** Create an expression representing t[0] * t[1] * .... *) - val mk_mul : context -> arith_expr list -> arith_expr + val mk_mul : context -> Expr.expr list -> Expr.expr (** Create an expression representing t[0] - t[1] - .... *) - val mk_sub : context -> arith_expr list -> arith_expr + val mk_sub : context -> Expr.expr list -> Expr.expr (** Create an expression representing -t. *) - val mk_unary_minus : context -> arith_expr -> arith_expr + val mk_unary_minus : context -> Expr.expr -> Expr.expr (** Create an expression representing t1 / t2. *) - val mk_div : context -> arith_expr -> arith_expr -> arith_expr + val mk_div : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 ^ t2. *) - val mk_power : context -> arith_expr -> arith_expr -> arith_expr + val mk_power : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 < t2 *) - val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_lt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 <= t2 *) - val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_le : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 > t2 *) - val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_gt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing t1 >= t2 *) - val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_ge : context -> Expr.expr -> Expr.expr -> Expr.expr end (** Functions to manipulate bit-vector expressions *) and BitVector : sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort - val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort - val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr - val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr - val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr - val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num - (** Create a new bit-vector sort. *) - val mk_sort : context -> int -> bitvec_sort + val mk_sort : context -> int -> Sort.sort (** Indicates whether the terms is of bit-vector sort. *) val is_bv : Expr.expr -> bool @@ -1624,71 +1514,71 @@ sig val is_bv_xor3 : Expr.expr -> bool (** The size of a bit-vector sort. *) - val get_size : bitvec_sort -> int + val get_size : Sort.sort -> int (** Retrieve the int value. *) - val get_int : bitvec_num -> int + val get_int : Expr.expr -> int (** Returns a string representation of the numeral. *) - val to_string : bitvec_num -> string + val to_string : Expr.expr -> string (** Creates a bit-vector constant. *) - val mk_const : context -> Symbol.symbol -> int -> bitvec_expr + val mk_const : context -> Symbol.symbol -> int -> Expr.expr (** Creates a bit-vector constant. *) - val mk_const_s : context -> string -> int -> bitvec_expr + val mk_const_s : context -> string -> int -> Expr.expr (** Bitwise negation. The argument must have a bit-vector sort. *) - val mk_not : context -> bitvec_expr -> Expr.expr + val mk_not : context -> Expr.expr -> Expr.expr (** Take conjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) - val mk_redand : context -> bitvec_expr -> Expr.expr + val mk_redand : context -> Expr.expr -> Expr.expr (** Take disjunction of bits in a vector,vector of length 1. The argument must have a bit-vector sort. *) - val mk_redor : context -> bitvec_expr -> Expr.expr + val mk_redor : context -> Expr.expr -> Expr.expr (** Bitwise conjunction. The arguments must have a bit-vector sort. *) - val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_and : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise disjunction. The arguments must have a bit-vector sort. *) - val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_or : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise XOR. The arguments must have a bit-vector sort. *) - val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise NAND. The arguments must have a bit-vector sort. *) - val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nand : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise NOR. The arguments must have a bit-vector sort. *) - val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise XNOR. The arguments must have a bit-vector sort. *) - val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xnor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Standard two's complement unary minus. The arguments must have a bit-vector sort. *) - val mk_neg : context -> bitvec_expr -> bitvec_expr + val mk_neg : context -> Expr.expr -> Expr.expr (** Two's complement addition. The arguments must have the same bit-vector sort. *) - val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_add : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement subtraction. The arguments must have the same bit-vector sort. *) - val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sub : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement multiplication. The arguments must have the same bit-vector sort. *) - val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_mul : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned division. @@ -1697,7 +1587,7 @@ sig different from zero. If t2 is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) - val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_udiv : context -> Expr.expr -> Expr.expr -> Expr.expr (** Signed division. @@ -1709,14 +1599,14 @@ sig If t2 is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) - val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sdiv : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. *) - val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_urem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Signed remainder. @@ -1725,53 +1615,53 @@ sig If t2 is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) - val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_srem : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. *) - val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_smod : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned less-than The arguments must have the same bit-vector sort. *) - val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ult : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed less-than The arguments must have the same bit-vector sort. *) - val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_slt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned less-than or equal to. The arguments must have the same bit-vector sort. *) - val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ule : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed less-than or equal to. The arguments must have the same bit-vector sort. *) - val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sle : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned greater than or equal to. The arguments must have the same bit-vector sort. *) - val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_uge : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed greater than or equal to. The arguments must have the same bit-vector sort. *) - val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sge : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned greater-than. The arguments must have the same bit-vector sort. *) - val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ugt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed greater-than. The arguments must have the same bit-vector sort. *) - val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sgt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bit-vector concatenation. @@ -1779,30 +1669,30 @@ sig @return The result is a bit-vector of size n1+n2, where n1 (n2) is the size of t1 (t2). *) - val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_concat : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bit-vector extraction. Extract the bits between two limits from a bitvector of size m to yield a new bitvector of size n, where n = high - low + 1. *) - val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + val mk_extract : context -> int -> int -> Expr.expr -> Expr.expr (** 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. *) - val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_sign_ext : context -> int -> Expr.expr -> Expr.expr (** 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. *) - val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_zero_ext : context -> int -> Expr.expr -> Expr.expr (** Bit-vector repetition. *) - val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + val mk_repeat : context -> int -> Expr.expr -> Expr.expr (** Shift left. @@ -1811,7 +1701,7 @@ sig 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.*) - val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_shl : context -> Expr.expr -> Expr.expr -> Expr.expr (** Logical shift right @@ -1822,7 +1712,7 @@ sig programming language or assembly architecture you are modeling. The arguments must have a bit-vector sort. *) - val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_lshr : context -> Expr.expr -> Expr.expr -> Expr.expr (** Arithmetic shift right @@ -1835,23 +1725,23 @@ sig programming language or assembly architecture you are modeling. The arguments must have a bit-vector sort. *) - val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ashr : context -> Expr.expr -> Expr.expr -> Expr.expr (** Rotate Left. Rotate bits of \c t to the left \c i times. *) - val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr + val mk_rotate_left : context -> int -> Expr.expr -> Expr.expr (** Rotate Right. Rotate bits of \c t to the right \c i times.*) - val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr + val mk_rotate_right : context -> int -> Expr.expr -> Expr.expr (** Rotate Left. Rotate bits of the second argument to the left.*) - val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_left : context -> Expr.expr -> Expr.expr -> Expr.expr (** Rotate Right. Rotate bits of the second argument to the right. *) - val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_right : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an integer from the bit-vector argument @@ -1863,50 +1753,50 @@ sig 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.*) - val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + val mk_bv2int : context -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise addition does not overflow. The arguments must be of bit-vector sort. *) - val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_add_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise addition does not underflow. The arguments must be of bit-vector sort. *) - val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_add_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise subtraction does not overflow. The arguments must be of bit-vector sort. *) - val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise subtraction does not underflow. The arguments must be of bit-vector sort. *) - val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_sub_no_underflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise signed division does not overflow. The arguments must be of bit-vector sort. *) - val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sdiv_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise negation does not overflow. The arguments must be of bit-vector sort. *) - val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + val mk_neg_no_overflow : context -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise multiplication does not overflow. The arguments must be of bit-vector sort. *) - val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_mul_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise multiplication does not underflow. The arguments must be of bit-vector sort. *) - val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_mul_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a bit-vector numeral. *) - val mk_numeral : context -> string -> int -> bitvec_num + val mk_numeral : context -> string -> int -> Expr.expr end (** Functions to manipulate proof expressions *) @@ -2332,7 +2222,7 @@ sig val is_garbage : goal -> bool (** Adds the constraints to the given goal. *) - val assert_ : goal -> Boolean.bool_expr list -> unit + val assert_ : goal -> Expr.expr list -> unit (** Indicates whether the goal contains `false'. *) val is_inconsistent : goal -> bool @@ -2348,7 +2238,7 @@ sig val get_size : goal -> int (** The formulas in the goal. *) - val get_formulas : goal -> Boolean.bool_expr list + val get_formulas : goal -> Expr.expr list (** The number of formulas, subformulas and terms in the goal. *) val get_num_exprs : goal -> int @@ -2759,7 +2649,7 @@ sig val reset : solver -> unit (** Assert a constraint (or multiple) into the solver. *) - val assert_ : solver -> Boolean.bool_expr list -> unit + val assert_ : solver -> Expr.expr list -> unit (** * Assert multiple constraints (cs) into the solver, and track them (in the * unsat) core @@ -2772,7 +2662,7 @@ sig * of the Boolean variables provided using {!assert_and_track} * and the Boolean literals * provided using {!check} with assumptions. *) - val assert_and_track_a : solver -> Boolean.bool_expr list -> Boolean.bool_expr list -> unit + val assert_and_track_a : solver -> Expr.expr list -> Expr.expr list -> unit (** * Assert a constraint (c) into the solver, and track it (in the unsat) core * using the Boolean constant p. @@ -2784,20 +2674,20 @@ sig * of the Boolean variables provided using {!assert_and_track} * and the Boolean literals * provided using {!check} with assumptions. *) - val assert_and_track : solver -> Boolean.bool_expr -> Boolean.bool_expr -> unit + val assert_and_track : solver -> Expr.expr -> Expr.expr -> unit (** The number of assertions in the solver. *) val get_num_assertions : solver -> int (** The set of asserted formulas. *) - val get_assertions : solver -> Boolean.bool_expr list + val get_assertions : solver -> Expr.expr list (** Checks whether the assertions in the solver are consistent or not. {!Model} {!get_unsat_core} {!Proof} *) - val check : solver -> Boolean.bool_expr list -> status + val check : solver -> Expr.expr list -> status (** The model of the last Check. @@ -2863,13 +2753,13 @@ sig val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs (** Assert a constraints into the fixedpoint solver. *) - val assert_ : fixedpoint -> Boolean.bool_expr list -> unit + val assert_ : fixedpoint -> Expr.expr list -> unit (** Register predicate as recursive relation. *) val register_relation : fixedpoint -> FuncDecl.func_decl -> unit (** Add rule into the fixedpoint solver. *) - val add_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol option -> unit + val add_rule : fixedpoint -> Expr.expr -> Symbol.symbol option -> unit (** Add table fact to the fixedpoint solver. *) val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit @@ -2878,7 +2768,7 @@ sig 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. *) - val query : fixedpoint -> Boolean.bool_expr -> Solver.status + val query : fixedpoint -> Expr.expr -> Solver.status (** Query the fixedpoint solver. A query is an array of relations. @@ -2897,7 +2787,7 @@ sig val pop : fixedpoint -> unit (** Update named rule into in the fixedpoint solver. *) - val update_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol -> unit + val update_rule : fixedpoint -> Expr.expr -> Symbol.symbol -> unit (** Retrieve satisfying instance or instances of solver, or definitions for the recursive predicates that show unsatisfiability. *) @@ -2923,13 +2813,13 @@ sig val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol list -> unit (** Convert benchmark given as set of axioms, rules and queries to a string. *) - val to_string_q : fixedpoint -> Boolean.bool_expr list -> string + val to_string_q : fixedpoint -> Expr.expr list -> string (** Retrieve set of rules added to fixedpoint context. *) - val get_rules : fixedpoint -> Boolean.bool_expr list + val get_rules : fixedpoint -> Expr.expr list (** Retrieve set of assertions added to fixedpoint context. *) - val get_assertions : fixedpoint -> Boolean.bool_expr list + val get_assertions : fixedpoint -> Expr.expr list (** Create a Fixedpoint context. *) val mk_fixedpoint : context -> fixedpoint @@ -2985,7 +2875,7 @@ sig (** Convert a benchmark into an SMT-LIB formatted string. @return A string representation of the benchmark. *) - val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr list -> Boolean.bool_expr -> string + val benchmark_to_smtstring : context -> string -> string -> string -> string -> Expr.expr list -> Expr.expr -> string (** Parse the given string using the SMT-LIB parser. @@ -3004,13 +2894,13 @@ sig val get_num_smtlib_formulas : context -> int (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_formulas : context -> Boolean.bool_expr list + val get_smtlib_formulas : context -> Expr.expr list (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_assumptions : context -> int (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_assumptions : context -> Boolean.bool_expr list + val get_smtlib_assumptions : context -> Expr.expr list (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) val get_num_smtlib_decls : context -> int @@ -3028,11 +2918,11 @@ sig {!parse_smtlib_string} @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr + val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr (** Parse the given file using the SMT-LIB2 parser. {!parse_smtlib2_string} *) - val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr + val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr end (** Set a global (or module) parameter, which is shared by all Z3 contexts. diff --git a/src/api/ml/z3_rich.ml b/src/api/ml/z3_rich.ml new file mode 100644 index 000000000..052ca5e22 --- /dev/null +++ b/src/api/ml/z3_rich.ml @@ -0,0 +1,3400 @@ +(** + The Z3 ML/Ocaml Interface. + + Copyright (C) 2012 Microsoft Corporation + @author CM Wintersteiger (cwinter) 2012-12-17 +*) + +open Z3enums + +(* Some helpers. *) +let null = Z3native.mk_null() +let is_null o = (Z3native.is_null o) + + +(* Internal types *) +type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } +type context = z3_native_context + +type z3_native_object = { + m_ctx : context ; + mutable m_n_obj : Z3native.ptr ; + inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; + dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } + + +(** Internal stuff *) +module Internal = +struct + let dispose_context ctx = + if ctx.m_n_obj_cnt == 0 then ( + (Z3native.del_context ctx.m_n_ctx) + ) else ( + Printf.printf "ERROR: NOT DISPOSING CONTEXT (because it still has %d objects alive)\n" ctx.m_n_obj_cnt; + ) + + let create_context settings = + let cfg = Z3native.mk_config in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = Z3native.mk_context_rc cfg in + Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + Z3native.set_internal_error_handler v ; + let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in + let f = fun o -> dispose_context o in + Gc.finalise f res; + res + + let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) + let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) + let context_gno ctx = ctx.m_n_ctx + + + let z3obj_gc o = o.m_ctx + let z3obj_gnc o = (context_gno o.m_ctx) + + let z3obj_gno o = o.m_n_obj + let z3obj_sno o ctx no = + (context_add1 ctx) ; + o.inc_ref (context_gno ctx) no ; + ( + if not (is_null o.m_n_obj) then + o.dec_ref (context_gno ctx) o.m_n_obj ; + (context_sub1 ctx) + ) ; + o.m_n_obj <- no + + let z3obj_dispose o = + if not (is_null o.m_n_obj) then + ( + o.dec_ref (z3obj_gnc o) o.m_n_obj ; + (context_sub1 (z3obj_gc o)) + ) ; + o.m_n_obj <- null + + let z3obj_create o = + let f = fun o -> (z3obj_dispose o) in + Gc.finalise f o + + let z3obj_nil_ref x y = () + + let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> + let res : z3_native_object = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res +end + +open Internal + +module Log = +struct + let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) + let close = Z3native.close_log + let append s = Z3native.append_log s +end + + +module Version = +struct + let major = let (x, _, _, _) = Z3native.get_version in x + let minor = let (_, x, _, _) = Z3native.get_version in x + let build = let (_, _, x, _) = Z3native.get_version in x + let revision = let (_, _, _, x) = Z3native.get_version in x + let to_string = + let (mj, mn, bld, rev) = Z3native.get_version in + string_of_int mj ^ "." ^ + string_of_int mn ^ "." ^ + string_of_int bld ^ "." ^ + string_of_int rev ^ "." +end + + +let mk_list ( f : int -> 'a ) ( n : int ) = + let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = + if (i >= n) then + tail + else + (mk_list' f (i+1) n ((f i) :: tail)) + in + mk_list' f 0 n [] + +let list_of_array ( x : _ array ) = + let f i = (Array.get x i) in + mk_list f (Array.length x) + +let mk_context ( cfg : ( string * string ) list ) = + create_context cfg + + +module Symbol = +struct + (* Symbol types *) + type int_symbol = z3_native_object + type string_symbol = z3_native_object + + type symbol = + | S_Int of int_symbol + | S_Str of string_symbol + + + let create_i ( ctx : context ) ( no : Z3native.ptr ) = + let res : int_symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let create_s ( ctx : context ) ( no : Z3native.ptr ) = + let res : string_symbol = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let create ( ctx : context ) ( no : Z3native.ptr ) = + match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with + | INT_SYMBOL -> S_Int (create_i ctx no) + | STRING_SYMBOL -> S_Str (create_s ctx no) + + let gc ( x : symbol ) = + match x with + | S_Int(n) -> (z3obj_gc n) + | S_Str(n) -> (z3obj_gc n) + + let gnc ( x : symbol ) = + match x with + | S_Int(n) -> (z3obj_gnc n) + | S_Str(n) -> (z3obj_gnc n) + + let gno ( x : symbol ) = + match x with + | S_Int(n) -> (z3obj_gno n) + | S_Str(n) -> (z3obj_gno n) + + let symbol_lton ( a : symbol list ) = + let f ( e : symbol ) = (gno e) in + Array.of_list (List.map f a) + + let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) + let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL + let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL + let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) + let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) + let to_string ( o : symbol ) = + match (kind o) with + | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) + | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) + + let mk_int ( ctx : context ) ( i : int ) = + S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) + + let mk_string ( ctx : context ) ( s : string ) = + S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) + + let mk_ints ( ctx : context ) ( names : int list ) = + let f elem = mk_int ( ctx : context ) elem in + (List.map f names) + + let mk_strings ( ctx : context ) ( names : string list ) = + let f elem = mk_string ( ctx : context ) elem in + (List.map f names) +end + + +module AST = +struct + type ast = z3_native_object + + let context_of_ast ( x : ast ) = (z3obj_gc x) + let nc_of_ast ( x : ast ) = (z3obj_gnc x) + let ptr_of_ast ( x : ast ) = (z3obj_gno x) + + let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> + match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with + | FUNC_DECL_AST + | SORT_AST + | QUANTIFIER_AST + | APP_AST + | NUMERAL_AST + | VAR_AST -> z3_native_object_of_ast_ptr ctx no + | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") + + module ASTVector = + struct + type ast_vector = z3_native_object + + let ast_vector_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_vector = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_vector_inc_ref ; + dec_ref = Z3native.ast_vector_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let get_size ( x : ast_vector ) = + Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) + + let get ( x : ast_vector ) ( i : int ) = + ast_of_ptr (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) + + let set ( x : ast_vector ) ( i : int ) ( value : ast ) = + Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) + + let resize ( x : ast_vector ) ( new_size : int ) = + Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size + + let push ( x : ast_vector ) ( a : ast ) = + Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) + + let translate ( x : ast_vector ) ( to_ctx : context ) = + ast_vector_of_ptr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + + let to_string ( x : ast_vector ) = + Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) + end + + module ASTMap = + struct + type ast_map = z3_native_object + + let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_map = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_map_inc_ref ; + dec_ref = Z3native.ast_map_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let contains ( x : ast_map ) ( key : ast ) = + Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) + + let find ( x : ast_map ) ( key : ast ) = + ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) + + let insert ( x : ast_map ) ( key : ast ) ( value : ast) = + Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) + + let erase ( x : ast_map ) ( key : ast ) = + Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) + + let reset ( x : ast_map ) = + Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) + + let get_size ( x : ast_map ) = + Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) + + let get_keys ( x : ast_map ) = + let av = ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in + let f i = (ASTVector.get av i) in + mk_list f (ASTVector.get_size av) + + let to_string ( x : ast_map ) = + Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) + end + + let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) + let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) + let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) + + let is_expr ( x : ast ) = + match get_ast_kind ( x : ast ) with + | APP_AST + | NUMERAL_AST + | QUANTIFIER_AST + | VAR_AST -> true + | _ -> false + + let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST + let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST + let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST + let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST + + let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) + let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) + + + let ( = ) ( a : ast ) ( b : ast ) = (a == b) || + if (z3obj_gnc a) != (z3obj_gnc b) then + false + else + Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) + + let compare a b = + if (get_id a) < (get_id b) then -1 else + if (get_id a) > (get_id b) then 1 else + 0 + + let ( < ) (a : ast) (b : ast) = (compare a b) + + let translate ( x : ast ) ( to_ctx : context ) = + if (z3obj_gnc x) == (context_gno to_ctx) then + x + else + ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + + let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr + let unwrap_ast ( x : ast ) = (z3obj_gno x) +end + +open AST + + +module Sort = +struct + type sort = Sort of AST.ast + type uninterpreted_sort = UninterpretedSort of sort + + let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> + let q = (z3_native_object_of_ast_ptr ctx no) in + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then + raise (Z3native.Exception "Invalid coercion") + else + match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with + | ARRAY_SORT + | BOOL_SORT + | BV_SORT + | DATATYPE_SORT + | INT_SORT + | REAL_SORT + | UNINTERPRETED_SORT + | FINITE_DOMAIN_SORT + | RELATION_SORT -> Sort(q) + | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") + + let ast_of_sort s = match s with Sort(x) -> x + let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x + + let uninterpreted_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + UninterpretedSort(s) + + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) + let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) + let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) + + let sort_lton ( a : sort list ) = + let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in + Array.of_list (List.map f a) + + let ( = ) : sort -> sort -> bool = fun a b -> + (a == b) || + if (gnc a) != (gnc b) then + false + else + (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) + + + let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) + let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) + let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) + let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) + + let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; + (z3obj_create res) ; + UninterpretedSort(Sort(res)) + + let mk_uninterpreted_s ( ctx : context ) ( s : string ) = + mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) +end + +open Sort + + +module rec FuncDecl : +sig + type func_decl = FuncDecl of AST.ast + val ast_of_func_decl : FuncDecl.func_decl -> AST.ast + val func_decl_of_ptr : context -> Z3native.ptr -> func_decl + val gc : func_decl -> context + val gnc : func_decl -> Z3native.ptr + val gno : func_decl -> Z3native.ptr + module Parameter : + sig + type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + val get_kind : parameter -> Z3enums.parameter_kind + val get_int : parameter -> int + val get_float : parameter -> float + val get_symbol : parameter -> Symbol.symbol + val get_sort : parameter -> Sort.sort + val get_ast : parameter -> AST.ast + val get_func_decl : parameter -> func_decl + val get_rational : parameter -> string + end + val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl + val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl + val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl + val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl + val mk_const_decl_s : context -> string -> Sort.sort -> func_decl + val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl + val ( = ) : func_decl -> func_decl -> bool + val to_string : func_decl -> string + val get_id : func_decl -> int + val get_arity : func_decl -> int + val get_domain_size : func_decl -> int + val get_domain : func_decl -> Sort.sort list + val get_range : func_decl -> Sort.sort + val get_decl_kind : func_decl -> Z3enums.decl_kind + val get_name : func_decl -> Symbol.symbol + val get_num_parameters : func_decl -> int + val get_parameters : func_decl -> Parameter.parameter list + val apply : func_decl -> Expr.expr list -> Expr.expr +end = struct + type func_decl = FuncDecl of AST.ast + + let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> + if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + FuncDecl(z3_native_object_of_ast_ptr ctx no) + + let ast_of_func_decl f = match f with FuncDecl(x) -> x + + let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (List.length domain) (sort_lton domain) (Sort.gno range))) ; + (z3obj_create res) ; + FuncDecl(res) + + let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort list ) ( range : sort ) = + let res = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.inc_ref ; + dec_ref = Z3native.dec_ref } in + (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (List.length domain) (sort_lton domain) (Sort.gno range))) ; + (z3obj_create res) ; + FuncDecl(res) + + let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) + let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) + let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) + + module Parameter = + struct + type parameter = + | P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + let get_kind ( x : parameter ) = + (match x with + | P_Int(_) -> PARAMETER_INT + | P_Dbl(_) -> PARAMETER_DOUBLE + | P_Sym(_) -> PARAMETER_SYMBOL + | P_Srt(_) -> PARAMETER_SORT + | P_Ast(_) -> PARAMETER_AST + | P_Fdl(_) -> PARAMETER_FUNC_DECL + | P_Rat(_) -> PARAMETER_RATIONAL) + + let get_int ( x : parameter ) = + match x with + | P_Int(x) -> x + | _ -> raise (Z3native.Exception "parameter is not an int") + + let get_float ( x : parameter ) = + match x with + | P_Dbl(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a double") + + let get_symbol ( x : parameter ) = + match x with + | P_Sym(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a symbol") + + let get_sort ( x : parameter ) = + match x with + | P_Srt(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a sort") + + let get_ast ( x : parameter ) = + match x with + | P_Ast(x) -> x + | _ -> raise (Z3native.Exception "parameter is not an ast") + + let get_func_decl ( x : parameter ) = + match x with + | P_Fdl(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a func_decl") + + let get_rational ( x : parameter ) = + match x with + | P_Rat(x) -> x + | _ -> raise (Z3native.Exception "parameter is not a rational string") + end + + let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = + create_ndr ctx name domain range + + let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort list ) ( range : sort ) = + mk_func_decl ctx (Symbol.mk_string ctx name) domain range + + let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort list ) ( range : sort ) = + create_pdr ctx prefix domain range + + let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + create_ndr ctx name [] range + + let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = + create_ndr ctx (Symbol.mk_string ctx name) [] range + + let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = + create_pdr ctx prefix [] range + + + let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || + if (gnc a) != (gnc b) then + false + else + (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) + + let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) + + let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) + + let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) + + let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) + + let get_domain ( x : func_decl ) = + let n = (get_domain_size x) in + let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in + mk_list f n + + let get_range ( x : func_decl ) = + sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) + + let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) + + let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) + + let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) + + let get_parameters ( x : func_decl ) = + let n = (get_num_parameters x) in + let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with + | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) + | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) + | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) + | PARAMETER_SORT -> Parameter.P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) + | PARAMETER_AST -> Parameter.P_Ast (AST.ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) + | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) + | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) + ) in + mk_list f n + + let apply ( x : func_decl ) ( args : Expr.expr list ) = Expr.expr_of_func_app (gc x) x args +end + + +and Params : +sig + type params = z3_native_object + module ParamDescrs : + sig + type param_descrs + val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs + val validate : param_descrs -> params -> unit + val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind + val get_names : param_descrs -> Symbol.symbol list + val get_size : param_descrs -> int + val to_string : param_descrs -> string + end + val add_bool : params -> Symbol.symbol -> bool -> unit + val add_int : params -> Symbol.symbol -> int -> unit + val add_double : params -> Symbol.symbol -> float -> unit + val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit + val add_s_bool : params -> string -> bool -> unit + val add_s_int : params -> string -> int -> unit + val add_s_double : params -> string -> float -> unit + val add_s_symbol : params -> string -> Symbol.symbol -> unit + val mk_params : context -> params + val to_string : params -> string +end = struct + type params = z3_native_object + + module ParamDescrs = + struct + type param_descrs = z3_native_object + + let param_descrs_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let res : param_descrs = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.param_descrs_inc_ref ; + dec_ref = Z3native.param_descrs_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let validate ( x : param_descrs ) ( p : params ) = + Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) + + let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = + (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) + + let get_names ( x : param_descrs ) = + let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in + let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) + let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) + end + + let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = + Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value + + let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = + Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value + + let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = + Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value + + let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = + Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) + + let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = + add_bool x (Symbol.mk_string (z3obj_gc x) name) value + + let add_s_int ( x : params) ( name : string ) ( value : int ) = + add_int x (Symbol.mk_string (z3obj_gc x) name) value + + let add_s_double ( x : params ) ( name : string ) ( value : float ) = + add_double x (Symbol.mk_string (z3obj_gc x) name) value + + let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = + add_symbol x (Symbol.mk_string (z3obj_gc x) name) value + + let mk_params ( ctx : context ) = + let res : params = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.params_inc_ref ; + dec_ref = Z3native.params_dec_ref } in + (z3obj_sno res ctx (Z3native.mk_params (context_gno ctx))) ; + (z3obj_create res) ; + res + + let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) +end + +(** General expressions (terms) *) +and Expr : +sig + type expr = Expr of AST.ast + val expr_of_ptr : context -> Z3native.ptr -> expr + val gc : expr -> context + val gnc : expr -> Z3native.ptr + val gno : expr -> Z3native.ptr + val expr_lton : expr list -> Z3native.ptr array + val ast_of_expr : expr -> AST.ast + val expr_of_ast : AST.ast -> expr + val expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr + val simplify : expr -> Params.params option -> expr + val get_simplify_help : context -> string + val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs + val get_func_decl : expr -> FuncDecl.func_decl + val get_bool_value : expr -> Z3enums.lbool + val get_num_args : expr -> int + val get_args : expr -> expr list + val update : expr -> expr list -> expr + val substitute : expr -> expr list -> expr list -> expr + val substitute_one : expr -> expr -> expr -> expr + val substitute_vars : expr -> expr list -> expr + val translate : expr -> context -> expr + val to_string : expr -> string + val is_numeral : expr -> bool + val is_well_sorted : expr -> bool + val get_sort : expr -> Sort.sort + val is_bool : expr -> bool + val is_const : expr -> bool + val is_true : expr -> bool + val is_false : expr -> bool + val is_eq : expr -> bool + val is_distinct : expr -> bool + val is_ite : expr -> bool + val is_and : expr -> bool + val is_or : expr -> bool + val is_iff : expr -> bool + val is_xor : expr -> bool + val is_not : expr -> bool + val is_implies : expr -> bool + val is_label : expr -> bool + val is_label_lit : expr -> bool + val is_oeq : expr -> bool + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + val mk_const_s : context -> string -> Sort.sort -> expr + val mk_const_f : context -> FuncDecl.func_decl -> expr + val mk_fresh_const : context -> string -> Sort.sort -> expr + val mk_app : context -> FuncDecl.func_decl -> expr list -> expr + val mk_numeral_string : context -> string -> Sort.sort -> expr + val mk_numeral_int : context -> int -> Sort.sort -> expr +end = struct + type expr = Expr of AST.ast + + let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) + let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) + let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) + + let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> + if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then + Expr(z3_native_object_of_ast_ptr ctx no) + else + let s = Z3native.get_sort (context_gno ctx) no in + let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in + if (Z3native.is_algebraic_number (context_gno ctx) no) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + if (Z3native.is_numeral_ast (context_gno ctx) no) then + if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + Expr(z3_native_object_of_ast_ptr ctx no) + else + raise (Z3native.Exception "Unsupported numeral object") + else + Expr(z3_native_object_of_ast_ptr ctx no) + + let expr_of_ast a = + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Expr(a) + + let ast_of_expr e = match e with Expr(a) -> a + + let expr_lton ( a : expr list ) = + let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in + Array.of_list (List.map f a) + + let expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr = fun ctx f args -> + match f with FuncDecl.FuncDecl(fa) -> + let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (List.length args) (expr_lton args) in + expr_of_ptr ctx o + + let simplify ( x : expr ) ( p : Params.params option ) = match p with + | None -> expr_of_ptr (Expr.gc x) (Z3native.simplify (Expr.gnc x) (Expr.gno x)) + | Some pp -> expr_of_ptr (Expr.gc x) (Z3native.simplify_ex (Expr.gnc x) (Expr.gno x) (z3obj_gno pp)) + + let get_simplify_help ( ctx : context ) = + Z3native.simplify_get_help (context_gno ctx) + + let get_simplify_parameter_descrs ( ctx : context ) = + Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) + let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (Expr.gnc x) (Expr.gno x)) + + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (Expr.gnc x) (Expr.gno x)) + + let get_num_args ( x : expr ) = Z3native.get_app_num_args (Expr.gnc x) (Expr.gno x) + + let get_args ( x : expr ) = let n = (get_num_args x) in + let f i = expr_of_ptr (Expr.gc x) (Z3native.get_app_arg (Expr.gnc x) (Expr.gno x) i) in + mk_list f n + + let update ( x : expr ) ( args : expr list ) = + if (List.length args <> (get_num_args x)) then + raise (Z3native.Exception "Number of arguments does not match") + else + expr_of_ptr (Expr.gc x) (Z3native.update_term (Expr.gnc x) (Expr.gno x) (List.length args) (expr_lton args)) + + let substitute ( x : expr ) from to_ = + if (List.length from) <> (List.length to_) then + raise (Z3native.Exception "Argument sizes do not match") + else + expr_of_ptr (Expr.gc x) (Z3native.substitute (Expr.gnc x) (Expr.gno x) (List.length from) (expr_lton from) (expr_lton to_)) + + let substitute_one ( x : expr ) from to_ = + substitute ( x : expr ) [ from ] [ to_ ] + + let substitute_vars ( x : expr ) to_ = + expr_of_ptr (Expr.gc x) (Z3native.substitute_vars (Expr.gnc x) (Expr.gno x) (List.length to_) (expr_lton to_)) + + let translate ( x : expr ) to_ctx = + if (Expr.gc x) == to_ctx then + x + else + expr_of_ptr to_ctx (Z3native.translate (Expr.gnc x) (Expr.gno x) (context_gno to_ctx)) + + let to_string ( x : expr ) = Z3native.ast_to_string (Expr.gnc x) (Expr.gno x) + + let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) + + let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (Expr.gnc x) (Expr.gno x) + + let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)) + + let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + (Z3native.is_eq_sort (Expr.gnc x) + (Z3native.mk_bool_sort (Expr.gnc x)) + (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) + + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + (get_num_args x) == 0 && + (FuncDecl.get_domain_size (get_func_decl x)) == 0 + + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) + let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) + let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) + let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) + let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) + let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) + let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) + let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) + let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) + let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) + let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) + let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) + let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) + + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = + expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) + + let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = + mk_const ctx (Symbol.mk_string ctx name) range + + let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [] + + let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = + expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) + + let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr list ) = expr_of_func_app ctx f args + + let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) + + let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) +end + +open FuncDecl +open Expr + +module Boolean = +struct + type bool_sort = BoolSort of Sort.sort + type bool_expr = BoolExpr of Expr.expr + + let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let a = (AST.ast_of_ptr ctx no) in + BoolExpr(Expr.Expr(a)) + + let bool_expr_of_expr e = + match e with Expr.Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolExpr(e) + + let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + BoolSort(sort_of_ptr ctx no) + + let sort_of_bool_sort s = match s with BoolSort(x) -> x + + let bool_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BoolSort(s) + + let expr_of_bool_expr e = match e with BoolExpr(x) -> x + + let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.c_of_expr e) + let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.nc_of_expr e) + let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.ptr_of_expr e) + + let mk_sort ( ctx : context ) = + BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) + + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = + let s = (match (mk_sort ctx) with BoolSort(q) -> q) in + BoolExpr(Expr.mk_const ctx name s) + + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) + + let mk_true ( ctx : context ) = + bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) + + let mk_false ( ctx : context ) = + bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) + + let mk_val ( ctx : context ) ( value : bool ) = + if value then mk_true ctx else mk_false ctx + + let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = + bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + + let mk_distinct ( ctx : context ) ( args : expr list ) = + bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) + + let mk_not ( ctx : context ) ( a : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) + + let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) + + let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) + + let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) + + let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = + bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) + + let mk_and ( ctx : context ) ( args : bool_expr list ) = + let f x = (Expr.gno (expr_of_bool_expr x)) in + bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) + + let mk_or ( ctx : context ) ( args : bool_expr list ) = + let f x = (Expr.gno (expr_of_bool_expr x)) in + bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) +end + + +module Quantifier = +struct + type quantifier = Quantifier of expr + + let expr_of_quantifier e = match e with Quantifier(x) -> x + + let quantifier_of_expr e = + match e with Expr.Expr(a) -> + let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.QUANTIFIER_AST) then + raise (Z3native.Exception "Invalid coercion") + else + Quantifier(e) + + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) + let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) + let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) + + module Pattern = + struct + type pattern = Pattern of ast + + let ast_of_pattern e = match e with Pattern(x) -> x + + let pattern_of_ast a = + (* CMW: Unchecked ok? *) + Pattern(a) + + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) + let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) + let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) + + let get_num_terms ( x : pattern ) = + Z3native.get_pattern_num_terms (gnc x) (gno x) + + let get_terms ( x : pattern ) = + let n = (get_num_terms x) in + let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in + mk_list f n + + let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) + end + + let get_index ( x : expr ) = + if not (AST.is_var (match x with Expr.Expr(a) -> a)) then + raise (Z3native.Exception "Term is not a bound variable.") + else + Z3native.get_index_value (Expr.gnc x) (Expr.gno x) + + let is_universal ( x : quantifier ) = + Z3native.is_quantifier_forall (gnc x) (gno x) + + let is_existential ( x : quantifier ) = not (is_universal x) + + let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) + + let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) + + let get_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in + mk_list f n + + let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) + + let get_no_patterns ( x : quantifier ) = + let n = (get_num_patterns x) in + let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in + mk_list f n + + let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) + + let get_bound_variable_names ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in + mk_list f n + + let get_bound_variable_sorts ( x : quantifier ) = + let n = (get_num_bound x) in + let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in + mk_list f n + + let get_body ( x : quantifier ) = + Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) + + let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = + expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) + + let mk_pattern ( ctx : context ) ( terms : expr list ) = + if (List.length terms) == 0 then + raise (Z3native.Exception "Cannot create a pattern from zero terms") + else + Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (List.length terms) (expr_lton terms))) + + let mk_forall ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (List.length sorts) != (List.length names) then + raise (Z3native.Exception "Number of sorts does not match number of names") + else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) + (Expr.gno body))) + else + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) + (Expr.gno body))) + + let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (Expr.gno body))) + else + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (Expr.gno body))) + + let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (List.length sorts) != (List.length names) then + raise (Z3native.Exception "Number of sorts does not match number of names") + else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) + (Expr.gno body))) + else + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (List.length sorts) (sort_lton sorts) + (Symbol.symbol_lton names) + (Expr.gno body))) + + let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (Expr.gno body))) + else + Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false + (match weight with | None -> 1 | Some(x) -> x) + (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) + (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) + (List.length bound_constants) (expr_lton bound_constants) + (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) + (List.length nopatterns) (expr_lton nopatterns) + (Expr.gno body))) + + let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (universal) then + (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) + else + (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) + + let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = + if (universal) then + mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id + else + mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id +end + + +module Array_ = +struct + type array_sort = ArraySort of sort + type array_expr = ArrayExpr of expr + + let array_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let e = (expr_of_ptr ctx no) in + ArrayExpr(e) + + let array_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + ArraySort(s) + + let sort_of_array_sort s = match s with ArraySort(x) -> x + + let array_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArraySort(s) + + let array_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.ARRAY_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArrayExpr(e) + + let expr_of_array_expr e = match e with ArrayExpr(x) -> x + + let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gno s) + + let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gc e) + let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) + let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) + + let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = + array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) + + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) + let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) + let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) + let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) + let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + let is_array ( x : expr ) = + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) + + let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) + let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) + + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = + ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) + + let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = + mk_const ctx (Symbol.mk_string ctx name) domain range + + let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = + array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (Expr.gno i)) + + let mk_store ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = + array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (Expr.gno i) (Expr.gno v)) + + let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = + array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) + + let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr list ) = + let m x = (Expr.gno (expr_of_array_expr x)) in + array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) + + let mk_term_array ( ctx : context ) ( arg : array_expr ) = + array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) +end + + +module Set = +struct + type set_sort = SetSort of sort + + let set_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + SetSort(s) + + let sort_of_set_sort s = match s with SetSort(x) -> x + + let mk_sort ( ctx : context ) ( ty : sort ) = + set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) + + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + + + let mk_empty ( ctx : context ) ( domain : sort ) = + (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) + + let mk_full ( ctx : context ) ( domain : sort ) = + expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) + + let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = + expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) + + let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = + expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) + + let mk_union ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) + + let mk_intersection ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) + + let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = + expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) + + let mk_complement ( ctx : context ) ( arg : expr ) = + expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) + + let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = + expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) + + let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = + expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) + +end + + +module FiniteDomain = +struct + type finite_domain_sort = FiniteDomainSort of sort + + let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x + + let finite_domain_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + FiniteDomainSort(s) + + let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) + let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) + let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in + FiniteDomainSort(s) + + let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = + mk_sort ctx (Symbol.mk_string ctx name) size + + + let is_finite_domain ( x : expr ) = + let nc = (Expr.gnc x) in + (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) + + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + + let get_size ( x : finite_domain_sort ) = + let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in + if r then v + else raise (Z3native.Exception "Conversion failed.") +end + + +module Relation = +struct + type relation_sort = RelationSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + RelationSort(s) + + let sort_of_relation_sort s = match s with RelationSort(x) -> x + + let relation_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RelationSort(s) + + let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) + let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) + let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) + + + let is_relation ( x : expr ) = + let nc = (Expr.gnc x) in + ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && + (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) + + let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) + let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) + let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) + let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) + let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) + let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + + let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) + + let get_column_sorts ( x : relation_sort ) = + let n = get_arity x in + let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in + mk_list f n + +end + + +module Datatype = +struct + type datatype_sort = DatatypeSort of sort + type datatype_expr = DatatypeExpr of expr + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + DatatypeSort(s) + + let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x + + let datatype_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeSort(s) + + let datatype_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.DATATYPE_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + DatatypeExpr(e) + + let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x + + let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) + + module Constructor = + struct + type constructor = z3_native_object + + let _sizes = Hashtbl.create 0 + + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let n = (List.length field_names) in + if n != (List.length sorts) then + raise (Z3native.Exception "Number of field names does not match number of sorts") + else + if n != (List.length sort_refs) then + raise (Z3native.Exception "Number of field names does not match number of sort refs") + else + let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) + (Symbol.gno recognizer) + n + (Symbol.symbol_lton field_names) + (sort_lton sorts) + (Array.of_list sort_refs)) in + let no : constructor = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + (z3obj_sno no ctx ptr) ; + (z3obj_create no) ; + let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in + Gc.finalise f no ; + Hashtbl.add _sizes no n ; + no + + let get_num_fields ( x : constructor ) = Hashtbl.find _sizes x + + let get_constructor_decl ( x : constructor ) = + let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in + func_decl_of_ptr (z3obj_gc x) a + + let get_tester_decl ( x : constructor ) = + let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in + func_decl_of_ptr (z3obj_gc x) b + + let get_accessor_decls ( x : constructor ) = + let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in + let f i = func_decl_of_ptr (z3obj_gc x) (Array.get c i) in + mk_list f (Array.length c) + + end + + module ConstructorList = + struct + type constructor_list = z3_native_object + + let create ( ctx : context ) ( c : Constructor.constructor list ) = + let res : constructor_list = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = z3obj_nil_ref ; + dec_ref = z3obj_nil_ref} in + let f x =(z3obj_gno x) in + (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (List.length c) (Array.of_list (List.map f c)))) ; + (z3obj_create res) ; + let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in + Gc.finalise f res; + res + end + + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + Constructor.create ctx name recognizer field_names sorts sort_refs + + + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = + let f x = (z3obj_gno x) in + let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (List.length constructors) (Array.of_list (List.map f constructors))) in + sort_of_ptr ctx x + + let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor list ) = + mk_sort ctx (Symbol.mk_string ctx name) constructors + + let mk_sorts ( ctx : context ) ( names : Symbol.symbol list ) ( c : Constructor.constructor list list ) = + let n = (List.length names) in + let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in + let cla = (Array.of_list (List.map f c)) in + let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.symbol_lton names) cla) in + let g i = (sort_of_ptr ctx (Array.get r i)) in + mk_list g (Array.length r) + + let mk_sorts_s ( ctx : context ) ( names : string list ) ( c : Constructor.constructor list list ) = + mk_sorts ctx + ( + let f e = (Symbol.mk_string ctx e) in + List.map f names + ) + c + + let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) + + let get_constructors ( x : datatype_sort ) = + let n = (get_num_constructors x) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + mk_list f n + + let get_recognizers ( x : datatype_sort ) = + let n = (get_num_constructors x) in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in + mk_list f n + + let get_accessors ( x : datatype_sort ) = + let n = (get_num_constructors x) in + let f i = ( + let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in + let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in + let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in + mk_list g ds + ) in + mk_list f n +end + + +module Enumeration = +struct + type enum_sort = EnumSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl list ) ( tdecls : Z3native.z3_func_decl list ) = + let s = (sort_of_ptr ctx no) in + let res = EnumSort(s) in + res + + let sort_of_enum_sort s = match s with EnumSort(x) -> x + + let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = + let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in + sort_of_ptr ctx a (list_of_array b) (list_of_array c) + + let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = + mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) + + let get_const_decls ( x : enum_sort ) = + let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in + let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in + mk_list f n + + let get_tester_decls ( x : enum_sort ) = + let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in + let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in + mk_list f n + +end + + +module List_ = +struct + type list_sort = ListSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + let res = ListSort(s) in + res + + let sort_of_list_sort s = match s with ListSort(x) -> x + + let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = + let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in + sort_of_ptr ctx r a b c d e f + + let mk_list_s ( ctx : context ) (name : string) elem_sort = + mk_sort ctx (Symbol.mk_string ctx name) elem_sort + + let get_nil_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) + + let get_is_nil_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) + + let get_cons_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) + + let get_is_cons_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) + + let get_head_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) + + let get_tail_decl ( x : list_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) + + let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [] +end + + +module Tuple = +struct + type tuple_sort = TupleSort of sort + + let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let s = (sort_of_ptr ctx no) in + TupleSort(s) + + let sort_of_tuple_sort s = match s with TupleSort(x) -> x + + let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) + + let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = + let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in + sort_of_ptr ctx r + + let get_mk_decl ( x : tuple_sort ) = + func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) + + let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) + + let get_field_decls ( x : tuple_sort ) = + let n = get_num_fields x in + let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in + mk_list f n +end + + +module rec Arithmetic : +sig + type arith_sort = ArithSort of Sort.sort + type arith_expr = ArithExpr of Expr.expr + + val sort_of_arith_sort : arith_sort -> Sort.sort + val arith_sort_of_sort : Sort.sort -> arith_sort + val expr_of_arith_expr : arith_expr -> Expr.expr + val arith_expr_of_expr : Expr.expr -> arith_expr + + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val int_expr_of_ptr : context -> Z3native.ptr -> int_expr + val int_num_of_ptr : context -> Z3native.ptr -> int_num + + val arith_sort_of_int_sort : Integer.int_sort -> arith_sort + val int_sort_of_arith_sort : arith_sort -> int_sort + val arith_expr_of_int_expr : int_expr -> arith_expr + val int_expr_of_int_num : int_num -> int_expr + val int_expr_of_arith_expr : arith_expr -> int_expr + val int_num_of_int_expr : int_expr -> int_num + + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val real_expr_of_ptr : context -> Z3native.ptr -> real_expr + val rat_num_of_ptr : context -> Z3native.ptr -> rat_num + + val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort + val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort + val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr + val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr + val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr + val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num + + val mk_sort : context -> real_sort + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr + end + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : algebraic_num -> arith_expr + val algebraic_num_of_arith_expr : arith_expr -> algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end + + val is_int : Expr.expr -> bool + val is_arithmetic_numeral : Expr.expr -> bool + val is_le : Expr.expr -> bool + val is_ge : Expr.expr -> bool + val is_lt : Expr.expr -> bool + val is_gt : Expr.expr -> bool + val is_add : Expr.expr -> bool + val is_sub : Expr.expr -> bool + val is_uminus : Expr.expr -> bool + val is_mul : Expr.expr -> bool + val is_div : Expr.expr -> bool + val is_idiv : Expr.expr -> bool + val is_remainder : Expr.expr -> bool + val is_modulus : Expr.expr -> bool + val is_inttoreal : Expr.expr -> bool + val is_real_to_int : Expr.expr -> bool + val is_real_is_int : Expr.expr -> bool + val is_real : Expr.expr -> bool + val is_int_numeral : Expr.expr -> bool + val is_rat_num : Expr.expr -> bool + val is_algebraic_number : Expr.expr -> bool + val mk_add : context -> arith_expr list -> arith_expr + val mk_mul : context -> arith_expr list -> arith_expr + val mk_sub : context -> arith_expr list -> arith_expr + val mk_unary_minus : context -> arith_expr -> arith_expr + val mk_div : context -> arith_expr -> arith_expr -> arith_expr + val mk_power : context -> arith_expr -> arith_expr -> arith_expr + val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr +end = struct + type arith_sort = ArithSort of sort + type arith_expr = ArithExpr of expr + + let arith_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithExpr(e) + + let arith_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + arith_expr_of_expr (expr_of_ptr ctx no) + + let sort_of_arith_sort s = match s with ArithSort(x) -> x + let expr_of_arith_expr e = match e with ArithExpr(x) -> x + + let arith_sort_of_sort s = match s with Sort(a) -> + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in + if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + ArithSort(s) + + let arith_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + arith_sort_of_sort (sort_of_ptr ctx no) + + let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) + let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gnc s) + let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gno s) + let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gc e) + let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) + let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) + + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val int_expr_of_ptr : context -> Z3native.ptr -> int_expr + val int_num_of_ptr : context -> Z3native.ptr -> int_num + + val arith_sort_of_int_sort : Integer.int_sort -> arith_sort + val int_sort_of_arith_sort : arith_sort -> int_sort + val arith_expr_of_int_expr : int_expr -> arith_expr + val int_expr_of_int_num : int_num -> int_expr + val int_expr_of_arith_expr : arith_expr -> int_expr + val int_num_of_int_expr : int_expr -> int_num + + val mk_sort : context -> int_sort + val get_int : int_num -> int + val to_string : int_num -> string + val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_int_const_s : context -> string -> int_expr + val mk_mod : context -> int_expr -> int_expr -> int_expr + val mk_rem : context -> int_expr -> int_expr -> int_expr + val mk_int_numeral_s : context -> string -> int_num + val mk_int_numeral_i : context -> int -> int_num + val mk_int2real : context -> int_expr -> Real.real_expr + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end = struct + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + let int_expr_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntExpr(e) + + let int_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) + + let int_num_of_int_expr e = + match e with IntExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + IntNum(e) + + let int_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_num_of_int_expr (int_expr_of_ptr ctx no) + + let arith_sort_of_int_sort s = match s with IntSort(x) -> x + let arith_expr_of_int_expr e = match e with IntExpr(x) -> x + let int_expr_of_int_num e = match e with IntNum(x) -> x + + let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + IntSort(s) + + let int_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + int_sort_of_arith_sort (arith_sort_of_sort (Sort.sort_of_ptr ctx no)) + + let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) + let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) + let sgno ( x : int_sort ) = match (x) with IntSort(s) -> (sgno s) + let egc ( x : int_expr ) = match (x) with IntExpr(e) -> (egc e) + let egnc ( x : int_expr ) = match (x) with IntExpr(e) -> (egnc e) + let egno ( x : int_expr ) = match (x) with IntExpr(e) -> (egno e) + let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) + let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) + let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) + + let mk_sort ( ctx : context ) = + int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) + + let get_int ( x : int_num ) = + let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + if r then v + else raise (Z3native.Exception "Conversion failed.") + + let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + + let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) + + let mk_int_const_s ( ctx : context ) ( name : string ) = + mk_int_const ctx (Symbol.mk_string ctx name) + + let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) + + let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = + int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) + + let mk_int_numeral_s ( ctx : context ) ( v : string ) = + int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + + let mk_int_numeral_i ( ctx : context ) ( v : int ) = + int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + + let mk_int2real ( ctx : context ) ( t : int_expr ) = + Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) + + let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = + BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) + end + + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val real_expr_of_ptr : context -> Z3native.ptr -> real_expr + val rat_num_of_ptr : context -> Z3native.ptr -> rat_num + + val arith_sort_of_real_sort : real_sort -> arith_sort + val real_sort_of_arith_sort : arith_sort -> real_sort + val arith_expr_of_real_expr : real_expr -> arith_expr + val real_expr_of_rat_num : rat_num -> real_expr + val real_expr_of_arith_expr : arith_expr -> real_expr + val rat_num_of_real_expr : real_expr -> rat_num + + val mk_sort : context -> real_sort + val get_numerator : rat_num -> Integer.int_num + val get_denominator : rat_num -> Integer.int_num + val to_decimal_string : rat_num -> int -> string + val to_string : rat_num -> string + val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_real_const_s : context -> string -> real_expr + val mk_numeral_nd : context -> int -> int -> rat_num + val mk_numeral_s : context -> string -> rat_num + val mk_numeral_i : context -> int -> rat_num + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + val mk_real2int : context -> real_expr -> Integer.int_expr + end = struct + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + let arith_sort_of_real_sort s = match s with RealSort(x) -> x + let arith_expr_of_real_expr e = match e with RealExpr(x) -> x + let real_expr_of_rat_num e = match e with RatNum(x) -> x + + let real_expr_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealExpr(e) + + let real_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) + + let rat_num_of_real_expr e = + match e with RealExpr(ArithExpr(Expr(a))) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + RatNum(e) + + let rat_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + rat_num_of_real_expr (real_expr_of_ptr ctx no) + + let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + RealSort(s) + + let real_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) + + let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) + let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) + let sgno ( x : real_sort ) = match (x) with RealSort(s) -> (sgno s) + let egc ( x : real_expr ) = match (x) with RealExpr(e) -> (egc e) + let egnc ( x : real_expr ) = match (x) with RealExpr(e) -> (egnc e) + let egno ( x : real_expr ) = match (x) with RealExpr(e) -> (egno e) + let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) + let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) + let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) + + + let mk_sort ( ctx : context ) = + real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) + + let get_numerator ( x : rat_num ) = + Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) + + let get_denominator ( x : rat_num ) = + Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) + + let to_decimal_string ( x : rat_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + + let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + + let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) + + let mk_real_const_s ( ctx : context ) ( name : string ) = + mk_real_const ctx (Symbol.mk_string ctx name) + + let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = + if (den == 0) then + raise (Z3native.Exception "Denominator is zero") + else + rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) + + let mk_numeral_s ( ctx : context ) ( v : string ) = + rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) + + let mk_numeral_i ( ctx : context ) ( v : int ) = + rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) + + let mk_is_integer ( ctx : context ) ( t : real_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) + + let mk_real2int ( ctx : context ) ( t : real_expr ) = + Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) + end + + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : algebraic_num -> arith_expr + val algebraic_num_of_arith_expr : arith_expr -> algebraic_num + + val to_upper : algebraic_num -> int -> Real.rat_num + val to_lower : algebraic_num -> int -> Real.rat_num + val to_decimal_string : algebraic_num -> int -> string + val to_string : algebraic_num -> string + end = struct + type algebraic_num = AlgebraicNum of arith_expr + + let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x + + let algebraic_num_of_arith_expr e = + match e with ArithExpr(Expr(a)) -> + if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + AlgebraicNum(e) + + let algebraic_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) + + let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) + let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) + let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) + + + let to_upper ( x : algebraic_num ) ( precision : int ) = + Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) + + let to_lower ( x : algebraic_num ) precision = + Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) + + let to_decimal_string ( x : algebraic_num ) ( precision : int ) = + Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision + + let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + end + + let is_int ( x : expr ) = + (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) + + let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + + let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + + let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + + let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + + let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + + let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + + let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + + let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + + let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + + let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + + let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + + let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + + let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + + let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + + let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + + let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + + let is_real ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) + + let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) + + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) + + let mk_add ( ctx : context ) ( t : arith_expr list ) = + let f x = (Expr.gno (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + + let mk_mul ( ctx : context ) ( t : arith_expr list ) = + let f x = (Expr.gno (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + + let mk_sub ( ctx : context ) ( t : arith_expr list ) = + let f x = (Expr.gno (expr_of_arith_expr x)) in + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + + let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) + + let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) + + let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) + + let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) + + let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) + + let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) + + let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) +end + + +and BitVector : +sig + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort + val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort + val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr + val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr + val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr + val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num + + val mk_sort : context -> int -> bitvec_sort + val is_bv : Expr.expr -> bool + val is_bv_numeral : Expr.expr -> bool + val is_bv_bit1 : Expr.expr -> bool + val is_bv_bit0 : Expr.expr -> bool + val is_bv_uminus : Expr.expr -> bool + val is_bv_add : Expr.expr -> bool + val is_bv_sub : Expr.expr -> bool + val is_bv_mul : Expr.expr -> bool + val is_bv_sdiv : Expr.expr -> bool + val is_bv_udiv : Expr.expr -> bool + val is_bv_SRem : Expr.expr -> bool + val is_bv_urem : Expr.expr -> bool + val is_bv_smod : Expr.expr -> bool + val is_bv_sdiv0 : Expr.expr -> bool + val is_bv_udiv0 : Expr.expr -> bool + val is_bv_srem0 : Expr.expr -> bool + val is_bv_urem0 : Expr.expr -> bool + val is_bv_smod0 : Expr.expr -> bool + val is_bv_ule : Expr.expr -> bool + val is_bv_sle : Expr.expr -> bool + val is_bv_uge : Expr.expr -> bool + val is_bv_sge : Expr.expr -> bool + val is_bv_ult : Expr.expr -> bool + val is_bv_slt : Expr.expr -> bool + val is_bv_ugt : Expr.expr -> bool + val is_bv_sgt : Expr.expr -> bool + val is_bv_and : Expr.expr -> bool + val is_bv_or : Expr.expr -> bool + val is_bv_not : Expr.expr -> bool + val is_bv_xor : Expr.expr -> bool + val is_bv_nand : Expr.expr -> bool + val is_bv_nor : Expr.expr -> bool + val is_bv_xnor : Expr.expr -> bool + val is_bv_concat : Expr.expr -> bool + val is_bv_signextension : Expr.expr -> bool + val is_bv_zeroextension : Expr.expr -> bool + val is_bv_extract : Expr.expr -> bool + val is_bv_repeat : Expr.expr -> bool + val is_bv_reduceor : Expr.expr -> bool + val is_bv_reduceand : Expr.expr -> bool + val is_bv_comp : Expr.expr -> bool + val is_bv_shiftleft : Expr.expr -> bool + val is_bv_shiftrightlogical : Expr.expr -> bool + val is_bv_shiftrightarithmetic : Expr.expr -> bool + val is_bv_rotateleft : Expr.expr -> bool + val is_bv_rotateright : Expr.expr -> bool + val is_bv_rotateleftextended : Expr.expr -> bool + val is_bv_rotaterightextended : Expr.expr -> bool + val is_int_to_bv : Expr.expr -> bool + val is_bv_to_int : Expr.expr -> bool + val is_bv_carry : Expr.expr -> bool + val is_bv_xor3 : Expr.expr -> bool + val get_size : bitvec_sort -> int + val get_int : bitvec_num -> int + val to_string : bitvec_num -> string + val mk_const : context -> Symbol.symbol -> int -> bitvec_expr + val mk_const_s : context -> string -> int -> bitvec_expr + val mk_not : context -> bitvec_expr -> Expr.expr + val mk_redand : context -> bitvec_expr -> Expr.expr + val mk_redor : context -> bitvec_expr -> Expr.expr + val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_neg : context -> bitvec_expr -> bitvec_expr + val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr + val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + val mk_numeral : context -> string -> int -> bitvec_num +end = struct + type bitvec_sort = BitVecSort of sort + type bitvec_expr = BitVecExpr of expr + type bitvec_num = BitVecNum of bitvec_expr + + let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x + + let bitvec_sort_of_sort s = match s with Sort(a) -> + if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecSort(s) + + let bitvec_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + bitvec_sort_of_sort (sort_of_ptr ctx no) + + let bitvec_expr_of_expr e = + match e with Expr(a) -> + let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in + let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in + if (q != Z3enums.BV_SORT) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecExpr(e) + + let bitvec_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + bitvec_expr_of_expr (expr_of_ptr ctx no) + + let bitvec_num_of_bitvec_expr e = + match e with BitVecExpr(Expr(a)) -> + if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then + raise (Z3native.Exception "Invalid coercion") + else + BitVecNum(e) + + let bitvec_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + bitvec_num_of_bitvec_expr (bitvec_expr_of_expr (expr_of_ptr ctx no)) + + let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x + let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x + + + let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) + let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) + let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) + let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gc e) + let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gnc e) + let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gno e) + let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) + let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) + let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) + + + let mk_sort ( ctx : context ) size = + bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) + let is_bv ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) + let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) + let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) + let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) + let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) + let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) + let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) + let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) + let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) + let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) + let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) + let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) + let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) + let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) + let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) + let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) + let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) + let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) + let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) + let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) + let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) + let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) + let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) + let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) + let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) + let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) + let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) + let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) + let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) + let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) + let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) + let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) + let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) + let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) + let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) + let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) + let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) + let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) + let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) + let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) + let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) + let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) + let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) + let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) + let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) + let get_int ( x : bitvec_num ) = + let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in + if r then v + else raise (Z3native.Exception "Conversion failed.") + let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = + BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) + let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = + mk_const ctx (Symbol.mk_string ctx name) size + let mk_not ( ctx : context ) ( t : bitvec_expr ) = + expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) + let mk_redand ( ctx : context ) ( t : bitvec_expr) = + expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) + let mk_redor ( ctx : context ) ( t : bitvec_expr) = + expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) + let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) + let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) + let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) + let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) + let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) + let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) + let mk_neg ( ctx : context ) ( t : bitvec_expr) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) + let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) + let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) + let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) + let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) + let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) + let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) + let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) + let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) + let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) + let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) + let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) + let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) + let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) + let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) + let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) + let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) + let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) + let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) + let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) + let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) + let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) + let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) + let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) + let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) + let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) + let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) + let mk_ext_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) + let mk_ext_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) + let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = + Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) + let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) + let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) + let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) + let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) + let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) + let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) + let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) + let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) + let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = + bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) +end + + +module Proof = +struct + let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) + let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) + let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) + let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) + let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) + let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) + let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) + let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) + let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) + let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) + let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) + let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) + let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) + let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) + let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) + let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) + let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) + let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) + let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) + let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) + let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) + let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) + let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) + let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) +end + + +module Goal = +struct + type goal = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : goal = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.goal_inc_ref ; + dec_ref = Z3native.goal_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let get_precision ( x : goal ) = + goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) + + let is_precise ( x : goal ) = + (get_precision x) == GOAL_PRECISE + + let is_underapproximation ( x : goal ) = + (get_precision x) == GOAL_UNDER + + let is_overapproximation ( x : goal ) = + (get_precision x) == GOAL_OVER + + let is_garbage ( x : goal ) = + (get_precision x) == GOAL_UNDER_OVER + + let assert_ ( x : goal ) ( constraints : Boolean.bool_expr list ) = + let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in + ignore (List.map f constraints) ; + () + + let is_inconsistent ( x : goal ) = + Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) + + let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) + + let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) + + let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) + + let get_formulas ( x : goal ) = + let n = get_size x in + let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) + (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in + mk_list f n + + let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) + + let is_decided_sat ( x : goal ) = + Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) + + let is_decided_unsat ( x : goal ) = + Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) + + let translate ( x : goal ) ( to_ctx : context ) = + create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + + let simplify ( x : goal ) ( p : Params.params option ) = + let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in + Z3native.tactic_inc_ref (z3obj_gnc x) tn ; + let arn = match p with + | None -> Z3native.tactic_apply (z3obj_gnc x) tn (z3obj_gno x) + | Some(pn) -> Z3native.tactic_apply_ex (z3obj_gnc x) tn (z3obj_gno x) (z3obj_gno pn) + in + Z3native.apply_result_inc_ref (z3obj_gnc x) arn ; + let sg = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) arn in + let res = if sg == 0 then + raise (Z3native.Exception "No subgoals") + else + Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in + Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; + Z3native.tactic_dec_ref (z3obj_gnc x) tn ; + create (z3obj_gc x) res + + let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = + create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) + + let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) +end + + +module Model = +struct + type model = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : model = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.model_inc_ref ; + dec_ref = Z3native.model_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + module FuncInterp = + struct + type func_interp = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : func_interp = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.func_interp_inc_ref ; + dec_ref = Z3native.func_interp_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + module FuncEntry = + struct + type func_entry = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : func_entry = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.func_entry_inc_ref ; + dec_ref = Z3native.func_entry_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let get_value ( x : func_entry ) = + expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) + + let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) + + let get_args ( x : func_entry ) = + let n = (get_num_args x) in + let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in + mk_list f n + + let to_string ( x : func_entry ) = + let a = (get_args x) in + let f c p = (p ^ (Expr.to_string c) ^ ", ") in + "[" ^ List.fold_right f a ((Expr.to_string (get_value x)) ^ "]") + end + + let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) + + let get_entries ( x : func_interp ) = + let n = (get_num_entries x) in + let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in + mk_list f n + + let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) + + let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) + + let to_string ( x : func_interp ) = + let f c p = ( + let n = (FuncEntry.get_num_args c) in + p ^ + let g c p = (p ^ (Expr.to_string c) ^ ", ") in + (if n > 1 then "[" else "") ^ + (List.fold_right + g + (FuncEntry.get_args c) + ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) + ) in + List.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") + end + + let get_const_interp ( x : model ) ( f : func_decl ) = + if (FuncDecl.get_arity f) != 0 || + (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then + raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") + else + let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in + if (Z3native.is_null np) then + None + else + Some (expr_of_ptr (z3obj_gc x) np) + + let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) + + + let rec get_func_interp ( x : model ) ( f : func_decl ) = + let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in + if (FuncDecl.get_arity f) == 0 then + let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in + if (Z3native.is_null n) then + None + else + match sk with + | ARRAY_SORT -> + if not (Z3native.is_as_array (z3obj_gnc x) n) then + raise (Z3native.Exception "Argument was not an array constant") + else + let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in + get_func_interp x (func_decl_of_ptr (z3obj_gc x) fd) + | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); + else + let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in + if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) + + (** The number of constants that have an interpretation in the model. *) + let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) + + let get_const_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) + + let get_func_decls ( x : model ) = + let n = (get_num_consts x) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get_decls ( x : model ) = + let n_funcs = (get_num_funcs x) in + let n_consts = (get_num_consts x ) in + let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in + let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in + (mk_list f n_funcs) @ (mk_list g n_consts) + + exception ModelEvaluationFailedException of string + + let eval ( x : model ) ( t : expr ) ( completion : bool ) = + let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in + if not r then + raise (ModelEvaluationFailedException "evaluation failed") + else + expr_of_ptr (z3obj_gc x) v + + let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = + eval x t completion + + let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) + + let get_sorts ( x : model ) = + let n = (get_num_sorts x) in + let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in + mk_list f n + + let sort_universe ( x : model ) ( s : sort ) = + let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n = (AST.ASTVector.get_size n_univ) in + let f i = (AST.ASTVector.get n_univ i) in + mk_list f n + + let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) +end + + +module Probe = +struct + type probe = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : probe = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.probe_inc_ref ; + dec_ref = Z3native.probe_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + + let apply ( x : probe ) ( g : Goal.goal ) = + Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) + + let get_num_probes ( ctx : context ) = + Z3native.get_num_probes (context_gno ctx) + + let get_probe_names ( ctx : context ) = + let n = (get_num_probes ctx) in + let f i = (Z3native.get_probe_name (context_gno ctx) i) in + mk_list f n + + let get_probe_description ( ctx : context ) ( name : string ) = + Z3native.probe_get_descr (context_gno ctx) name + + let mk_probe ( ctx : context ) ( name : string ) = + (create ctx (Z3native.mk_probe (context_gno ctx) name)) + + let const ( ctx : context ) ( v : float ) = + (create ctx (Z3native.probe_const (context_gno ctx) v)) + + let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = + (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) + + let not_ ( ctx : context ) ( p : probe ) = + (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) +end + + +module Tactic = +struct + type tactic = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : tactic = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.tactic_inc_ref ; + dec_ref = Z3native.tactic_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + module ApplyResult = + struct + type apply_result = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : apply_result = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.apply_result_inc_ref ; + dec_ref = Z3native.apply_result_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let get_num_subgoals ( x : apply_result ) = + Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) + + let get_subgoals ( x : apply_result ) = + let n = (get_num_subgoals x) in + let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get_subgoal ( x : apply_result ) ( i : int ) = + Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) + + let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = + Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) + + let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) + end + + let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) + + let get_param_descrs ( x : tactic ) = + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + + let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = + match p with + | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) + | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) + + let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) + + let get_tactic_names ( ctx : context ) = + let n = (get_num_tactics ctx ) in + let f i = (Z3native.get_tactic_name (context_gno ctx) i) in + mk_list f n + + let get_tactic_description ( ctx : context ) ( name : string ) = + Z3native.tactic_get_descr (context_gno ctx) name + + let mk_tactic ( ctx : context ) ( name : string ) = + create ctx (Z3native.mk_tactic (context_gno ctx) name) + + let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic list ) = + let f p c = (match p with + | None -> (Some (z3obj_gno c)) + | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in + match (List.fold_left f None ts) with + | None -> + create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + | Some(x) -> + let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in + create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) + + let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = + create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + + let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = + create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) + + let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = + create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) + + let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = + create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) + + let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = + create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) + + let skip ( ctx : context ) = + create ctx (Z3native.tactic_skip (context_gno ctx)) + + let fail ( ctx : context ) = + create ctx (Z3native.tactic_fail (context_gno ctx)) + + let fail_if ( ctx : context ) ( p : Probe.probe ) = + create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) + + let fail_if_not_decided ( ctx : context ) = + create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) + + let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) + + let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = + using_params ctx t p + + let par_or ( ctx : context ) ( t : tactic list ) = + let f e = (z3obj_gno e) in + create ctx (Z3native.tactic_par_or (context_gno ctx) (List.length t) (Array.of_list (List.map f t))) + + let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = + create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) + + let interrupt ( ctx : context ) = + Z3native.interrupt (context_gno ctx) +end + + +module Solver = +struct + type solver = z3_native_object + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : solver = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.solver_inc_ref ; + dec_ref = Z3native.solver_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + let string_of_status ( s : status) = match s with + | UNSATISFIABLE -> "unsatisfiable" + | SATISFIABLE -> "satisfiable" + | _ -> "unknown" + + module Statistics = + struct + type statistics = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : statistics = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.stats_inc_ref ; + dec_ref = Z3native.stats_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + + + module Entry = + struct + type statistics_entry = { + mutable m_key : string; + mutable m_is_int : bool ; + mutable m_is_float : bool ; + mutable m_int : int ; + mutable m_float : float } + + let create_si k v = + let res : statistics_entry = { + m_key = k ; + m_is_int = true ; + m_is_float = false ; + m_int = v ; + m_float = 0.0 + } in + res + + let create_sd k v = + let res : statistics_entry = { + m_key = k ; + m_is_int = false ; + m_is_float = true ; + m_int = 0 ; + m_float = v + } in + res + + + let get_key (x : statistics_entry) = x.m_key + let get_int (x : statistics_entry) = x.m_int + let get_float (x : statistics_entry) = x.m_float + let is_int (x : statistics_entry) = x.m_is_int + let is_float (x : statistics_entry) = x.m_is_float + let to_string_value (x : statistics_entry) = + if (is_int x) then + string_of_int (get_int x) + else if (is_float x) then + string_of_float (get_float x) + else + raise (Z3native.Exception "Unknown statistical entry type") + let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) + end + + let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) + + let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) + + let get_entries ( x : statistics ) = + let n = (get_size x ) in + let f i = ( + let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in + if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then + (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) + else + (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) + ) in + mk_list f n + + let get_keys ( x : statistics ) = + let n = (get_size x) in + let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in + mk_list f n + + let get ( x : statistics ) ( key : string ) = + let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in + List.fold_left f None (get_entries x) + end + + let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) + + let set_parameters ( x : solver ) ( p : Params.params )= + Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) + + let get_param_descrs ( x : solver ) = + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + + let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) + + let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) + + let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n + + let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) + + let assert_ ( x : solver ) ( constraints : Boolean.bool_expr list ) = + let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in + ignore (List.map f constraints) + + let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr list ) ( ps : Boolean.bool_expr list ) = + if ((List.length cs) != (List.length ps)) then + raise (Z3native.Exception "Argument size mismatch") + else + let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno a) (Boolean.gno b)) in + ignore (List.iter2 f cs ps) + + let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = + Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) + + let get_num_assertions ( x : solver ) = + let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + (AST.ASTVector.get_size a) + + let get_assertions ( x : solver ) = + let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVector.get_size a) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in + mk_list f n + + let check ( x : solver ) ( assumptions : Boolean.bool_expr list ) = + let r = + if ((List.length assumptions) == 0) then + lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) + else + let f x = (Expr.gno (Boolean.expr_of_bool_expr x)) in + lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) + in + match r with + | L_TRUE -> SATISFIABLE + | L_FALSE -> UNSATISFIABLE + | _ -> UNKNOWN + + let get_model ( x : solver ) = + let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in + if (Z3native.is_null q) then + None + else + Some (Model.create (z3obj_gc x) q) + + let get_proof ( x : solver ) = + let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in + if (Z3native.is_null q) then + None + else + Some (expr_of_ptr (z3obj_gc x) q) + + let get_unsat_core ( x : solver ) = + let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let n = (AST.ASTVector.get_size cn) in + let f i = (AST.ASTVector.get cn i) in + mk_list f n + + let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) + + let get_statistics ( x : solver ) = + (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) + + let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = + match logic with + | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) + | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) + + let mk_solver_s ( ctx : context ) ( logic : string ) = + mk_solver ctx (Some (Symbol.mk_string ctx logic)) + + let mk_simple_solver ( ctx : context ) = + (create ctx (Z3native.mk_simple_solver (context_gno ctx))) + + let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = + (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) + + let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) +end + + +module Fixedpoint = +struct + type fixedpoint = z3_native_object + + let create ( ctx : context ) = + let res : fixedpoint = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.fixedpoint_inc_ref ; + dec_ref = Z3native.fixedpoint_dec_ref } in + (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; + (z3obj_create res) ; + res + + + let get_help ( x : fixedpoint ) = + Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) + + let set_params ( x : fixedpoint ) ( p : Params.params )= + Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) + + let get_param_descrs ( x : fixedpoint ) = + Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) + + let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr list ) = + let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in + ignore (List.map f constraints) ; + () + + let register_relation ( x : fixedpoint ) ( f : func_decl ) = + Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) + + let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = + match name with + | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null + | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) + + let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = + Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) + + let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = + match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN + + let query_r ( x : fixedpoint ) ( relations : func_decl list ) = + let f x = ptr_of_ast (ast_of_func_decl x) in + match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (List.length relations) (Array.of_list (List.map f relations)))) with + | L_TRUE -> Solver.SATISFIABLE + | L_FALSE -> Solver.UNSATISFIABLE + | _ -> Solver.UNKNOWN + + let push ( x : fixedpoint ) = + Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) + + let pop ( x : fixedpoint ) = + Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) + + let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = + Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) + + let get_answer ( x : fixedpoint ) = + let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in + if (Z3native.is_null q) then + None + else + Some (expr_of_ptr (z3obj_gc x) q) + + let get_reason_unknown ( x : fixedpoint ) = + Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) + + let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = + Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) + + let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = + let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in + if (Z3native.is_null q) then + None + else + Some (expr_of_ptr (z3obj_gc x) q) + + let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = + Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) + + let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] + + let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = + Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) + + let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr list ) = + let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in + Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) + + let get_rules ( x : fixedpoint ) = + let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVector.get_size v) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + mk_list f n + + let get_assertions ( x : fixedpoint ) = + let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let n = (AST.ASTVector.get_size v) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in + mk_list f n + + let mk_fixedpoint ( ctx : context ) = create ctx +end + +module Options = +struct + + let update_param_value ( ctx : context ) ( id : string) ( value : string )= + Z3native.update_param_value (context_gno ctx) id value + + let get_param_value ( ctx : context ) ( id : string ) = + let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in + if not r then + None + else + Some v + + let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = + Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) + + let toggle_warning_messages ( enabled: bool ) = + Z3native.toggle_warning_messages enabled +end + + +module SMT = +struct + let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr list ) ( formula : Boolean.bool_expr ) = + Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes + (List.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.of_list (List.map f assumptions))) + (Boolean.gno formula) + + let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Z3native.parse_smtlib_string (context_gno ctx) str + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) + + let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Z3native.parse_smtlib_file (context_gno ctx) file_name + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) + + let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) + + let get_smtlib_formulas ( ctx : context ) = + let n = (get_num_smtlib_formulas ctx ) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in + mk_list f n + + let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) + + let get_smtlib_assumptions ( ctx : context ) = + let n = (get_num_smtlib_assumptions ctx ) in + let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in + mk_list f n + + let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) + + let get_smtlib_decls ( ctx : context ) = + let n = (get_num_smtlib_decls ctx) in + let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in + mk_list f n + + let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) + + let get_smtlib_sorts ( ctx : context ) = + let n = (get_num_smtlib_sorts ctx) in + let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in + mk_list f n + + let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) + + let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = + let csn = (List.length sort_names) in + let cs = (List.length sorts) in + let cdn = (List.length decl_names) in + let cd = (List.length decls) in + if (csn != cs || cdn != cd) then + raise (Z3native.Exception "Argument size mismatch") + else + Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name + cs + (Symbol.symbol_lton sort_names) + (sort_lton sorts) + cd + (Symbol.symbol_lton decl_names) + (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) +end + + +let set_global_param ( id : string ) ( value : string ) = + (Z3native.global_param_set id value) + +let get_global_param ( id : string ) = + let (r, v) = (Z3native.global_param_get id) in + if not r then + None + else + Some v + +let global_param_reset_all = + Z3native.global_param_reset_all diff --git a/src/api/ml/z3_rich.mli b/src/api/ml/z3_rich.mli new file mode 100644 index 000000000..8b6681e11 --- /dev/null +++ b/src/api/ml/z3_rich.mli @@ -0,0 +1,3072 @@ +(** + The Z3 ML/Ocaml Interface. + + Copyright (C) 2012 Microsoft Corporation + @author CM Wintersteiger (cwinter) 2012-12-17 + + NOTE: This is the *rich* version of the interface, using more + type information directly in the type system. Coercion functions + are provided to tran coerce on type into another where applicable. +*) + +(** Context objects. + + Most interactions with Z3 are interpreted in some context; many users will only + require one such object, but power users may require more than one. To start using + Z3, do + + + let ctx = (mk_context []) in + (...) + + + where a list of pairs of strings may be passed to set options on + the context, e.g., like so: + + + let cfg = [("model", "true"); ("...", "...")] in + let ctx = (mk_context cfg) in + (...) + +*) +type context + +(** Create a context object *) +val mk_context : (string * string) list -> context + + +(** 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. *) +module Log : +sig + (** Open an interaction log file. + @return True if opening the log file succeeds, false otherwise. *) + (* CMW: "open" seems to be a reserved keyword? *) + val open_ : string -> bool + + (** Closes the interaction log. *) + val close : unit + + (** Appends a user-provided string to the interaction log. *) + val append : string -> unit +end + +(** Version information *) +module Version : +sig + (** The major version. *) + val major : int + + (** The minor version. *) + val minor : int + + (** The build version. *) + val build : int + + (** The revision. *) + val revision : int + + (** A string representation of the version information. *) + val to_string : string +end + +(** Symbols are used to name several term and type constructors *) +module Symbol : +sig + (** Numbered Symbols *) + type int_symbol + + (** Named Symbols *) + type string_symbol + + (** Symbols *) + type symbol = S_Int of int_symbol | S_Str of string_symbol + + (** The kind of the symbol (int or string) *) + val kind : symbol -> Z3enums.symbol_kind + + (** Indicates whether the symbol is of Int kind *) + val is_int_symbol : symbol -> bool + + (** Indicates whether the symbol is of string kind. *) + val is_string_symbol : symbol -> bool + + (** The int value of the symbol. *) + val get_int : int_symbol -> int + + (** The string value of the symbol. *) + val get_string : string_symbol -> string + + (** A string representation of the symbol. *) + val to_string : symbol -> string + + (** 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. *) + val mk_int : context -> int -> symbol + + (** Creates a new symbol using a string. *) + val mk_string : context -> string -> symbol + + (** Create a list of symbols. *) + val mk_ints : context -> int list -> symbol list + + (** Create a list of symbols. *) + val mk_strings : context -> string list -> symbol list +end + +(** The abstract syntax tree (AST) module *) +module AST : +sig + type ast + + (** Vectors of ASTs *) + module ASTVector : + sig + type ast_vector + + (** The size of the vector *) + val get_size : ast_vector -> int + + (** + Retrieves the i-th object in the vector. + @return An AST *) + val get : ast_vector -> int -> ast + + (** Sets the i-th object in the vector. *) + val set : ast_vector -> int -> ast -> unit + + (** Resize the vector to a new size. *) + val resize : ast_vector -> int -> unit + + (** Add an ast to the back of the vector. The size + is increased by 1. *) + val push : ast_vector -> ast -> unit + + (** Translates all ASTs in the vector to another context. + @return A new ASTVector *) + val translate : ast_vector -> context -> ast_vector + + (** Retrieves a string representation of the vector. *) + val to_string : ast_vector -> string + end + + (** Map from AST to AST *) + module ASTMap : + sig + type ast_map + + (** Checks whether the map contains a key. + @return True if the key in the map, false otherwise. *) + val contains : ast_map -> ast -> bool + + (** Finds the value associated with the key. + This function signs an error when the key is not a key in the map. *) + val find : ast_map -> ast -> ast + + (** Stores or replaces a new key/value pair in the map. *) + val insert : ast_map -> ast -> ast -> unit + + (** Erases the key from the map.*) + val erase : ast_map -> ast -> unit + + (** Removes all keys from the map. *) + val reset : ast_map -> unit + + (** The size of the map *) + val get_size : ast_map -> int + + (** The keys stored in the map. *) + val get_keys : ast_map -> ast list + + (** Retrieves a string representation of the map.*) + val to_string : ast_map -> string + end + + (** The AST's hash code. + @return A hash code *) + val get_hash_code : ast -> int + + (** A unique identifier for the AST (unique among all ASTs). *) + val get_id : ast -> int + + (** The kind of the AST. *) + val get_ast_kind : ast -> Z3enums.ast_kind + + (** Indicates whether the AST is an Expr *) + val is_expr : ast -> bool + + (** Indicates whether the AST is a bound variable*) + val is_var : ast -> bool + + (** Indicates whether the AST is a Quantifier *) + val is_quantifier : ast -> bool + + (** Indicates whether the AST is a Sort *) + val is_sort : ast -> bool + + (** Indicates whether the AST is a func_decl *) + val is_func_decl : ast -> bool + + (** A string representation of the AST. *) + val to_string : ast -> string + + (** A string representation of the AST in s-expression notation. *) + val to_sexpr : ast -> string + + (** Comparison operator. + @return True if the two ast's are from the same context + and represent the same sort; false otherwise. *) + val ( = ) : ast -> ast -> bool + + (** Object Comparison. + @return Negative if the first ast should be sorted before the second, positive if after else zero. *) + val compare : ast -> ast -> int + + (** Operator < *) + val ( < ) : ast -> ast -> int + + (** Translates (copies) the AST to another context. + @return A copy of the AST which is associated with the other context. *) + val translate : ast -> context -> ast + + (** Wraps an AST. + + This function is used for transitions between native and + managed objects. Note that the native ast that is passed must be a + native object obtained from Z3 (e.g., through {!unwrap_ast}) + and that it must have a correct reference count (see e.g., + Z3native.inc_ref). *) + val wrap_ast : context -> Z3native.z3_ast -> ast + + (** 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., + Z3native.inc_ref). + {!wrap_ast} *) + val unwrap_ast : ast -> Z3native.ptr +end + +(** The Sort module implements type information for ASTs *) +module Sort : +sig + (** Sorts *) + type sort = Sort of AST.ast + + (** Uninterpreted Sorts *) + type uninterpreted_sort = UninterpretedSort of sort + + val ast_of_sort : sort -> AST.ast + val sort_of_uninterpreted_sort : uninterpreted_sort -> sort + val uninterpreted_sort_of_sort : sort -> uninterpreted_sort + + (** Comparison operator. + @return True if the two sorts are from the same context + and represent the same sort; false otherwise. *) + val ( = ) : sort -> sort -> bool + + (** Returns a unique identifier for the sort. *) + val get_id : sort -> int + + (** The kind of the sort. *) + val get_sort_kind : sort -> Z3enums.sort_kind + + (** The name of the sort *) + val get_name : sort -> Symbol.symbol + + (** A string representation of the sort. *) + val to_string : sort -> string + + (** Create a new uninterpreted sort. *) + val mk_uninterpreted : context -> Symbol.symbol -> uninterpreted_sort + + (** Create a new uninterpreted sort. *) + val mk_uninterpreted_s : context -> string -> uninterpreted_sort +end + +(** Function declarations *) +module rec FuncDecl : +sig + type func_decl = FuncDecl of AST.ast + + val ast_of_func_decl : FuncDecl.func_decl -> AST.ast + + (** Parameters of Func_Decls *) + module Parameter : + sig + (** Parameters of func_decls *) + type parameter = + P_Int of int + | P_Dbl of float + | P_Sym of Symbol.symbol + | P_Srt of Sort.sort + | P_Ast of AST.ast + | P_Fdl of func_decl + | P_Rat of string + + (** The kind of the parameter. *) + val get_kind : parameter -> Z3enums.parameter_kind + + (** The int value of the parameter.*) + val get_int : parameter -> int + + (** The double value of the parameter.*) + val get_float : parameter -> float + + (** The Symbol.Symbol value of the parameter.*) + val get_symbol : parameter -> Symbol.symbol + + (** The Sort value of the parameter.*) + val get_sort : parameter -> Sort.sort + + (** The AST value of the parameter.*) + val get_ast : parameter -> AST.ast + + (** The FunctionDeclaration value of the parameter.*) + val get_func_decl : parameter -> func_decl + + (** The rational string value of the parameter.*) + val get_rational : parameter -> string + end + + (** Creates a new function declaration. *) + val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl + + (** Creates a new function declaration. *) + val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl + (** Creates a fresh function declaration with a name prefixed with a prefix string. *) + + val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl + + (** Creates a new constant function declaration. *) + val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl + + (** Creates a new constant function declaration. *) + val mk_const_decl_s : context -> string -> Sort.sort -> func_decl + + (** Creates a fresh constant function declaration with a name prefixed with a prefix string. + {!mk_func_decl} + {!mk_func_decl} *) + val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl + + (** Comparison operator. + @return True if a and b are from the same context and represent the same func_decl; false otherwise. *) + val ( = ) : func_decl -> func_decl -> bool + + (** A string representations of the function declaration. *) + val to_string : func_decl -> string + + (** Returns a unique identifier for the function declaration. *) + val get_id : func_decl -> int + + (** The arity of the function declaration *) + val get_arity : func_decl -> int + + (** The size of the domain of the function declaration + {!get_arity} *) + val get_domain_size : func_decl -> int + + (** The domain of the function declaration *) + val get_domain : func_decl -> Sort.sort list + + (** The range of the function declaration *) + val get_range : func_decl -> Sort.sort + + (** The kind of the function declaration. *) + val get_decl_kind : func_decl -> Z3enums.decl_kind + + (** The name of the function declaration*) + val get_name : func_decl -> Symbol.symbol + + (** The number of parameters of the function declaration *) + val get_num_parameters : func_decl -> int + + (** The parameters of the function declaration *) + val get_parameters : func_decl -> Parameter.parameter list + + (** Create expression that applies function to arguments. *) + val apply : func_decl -> Expr.expr list -> Expr.expr +end + +(** Parameter sets (of Solvers, Tactics, ...) + + A Params objects represents a configuration in the form of Symbol.symbol/value pairs. *) +and Params : +sig + type params + + (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) + module ParamDescrs : + sig + type param_descrs + + (** Validate a set of parameters. *) + val validate : param_descrs -> params -> unit + + (** Retrieve kind of parameter. *) + val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind + + (** Retrieve all names of parameters. *) + val get_names : param_descrs -> Symbol.symbol list + + (** The size of the ParamDescrs. *) + val get_size : param_descrs -> int + + (** Retrieves a string representation of the ParamDescrs. *) + val to_string : param_descrs -> string + end + + (** Adds a parameter setting. *) + val add_bool : params -> Symbol.symbol -> bool -> unit + + (** Adds a parameter setting. *) + val add_int : params -> Symbol.symbol -> int -> unit + + (** Adds a parameter setting. *) + val add_double : params -> Symbol.symbol -> float -> unit + + (** Adds a parameter setting. *) + val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit + + (** Adds a parameter setting. *) + val add_s_bool : params -> string -> bool -> unit + + (** Adds a parameter setting. *) + val add_s_int : params -> string -> int -> unit + + (** Adds a parameter setting. *) + val add_s_double : params -> string -> float -> unit + + (** Adds a parameter setting. *) + val add_s_symbol : params -> string -> Symbol.symbol -> unit + + (** Creates a new parameter set *) + val mk_params : context -> params + + (** A string representation of the parameter set. *) + val to_string : params -> string +end + +(** General Expressions (terms) *) +and Expr : +sig + type expr = Expr of AST.ast + + val ast_of_expr : Expr.expr -> AST.ast + val expr_of_ast : AST.ast -> Expr.expr + + (** Returns a simplified version of the expression. + {!get_simplify_help} *) + val simplify : Expr.expr -> Params.params option -> expr + + (** A string describing all available parameters to Expr.Simplify. *) + val get_simplify_help : context -> string + + (** Retrieves parameter descriptions for simplifier. *) + val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs + + (** The function declaration of the function that is applied in this expression. *) + val get_func_decl : Expr.expr -> FuncDecl.func_decl + + (** Indicates whether the expression is the true or false expression + or something else (L_UNDEF). *) + val get_bool_value : Expr.expr -> Z3enums.lbool + + (** The number of arguments of the expression. *) + val get_num_args : Expr.expr -> int + + (** The arguments of the expression. *) + val get_args : Expr.expr -> Expr.expr list + + (** Update the arguments of the expression using an array of expressions. + The number of new arguments should coincide with the current number of arguments. *) + val update : Expr.expr -> Expr.expr list -> expr + + (** 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]. *) + val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr + + (** Substitute every occurrence of from in the expression with to. + {!substitute} *) + val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr + + (** Substitute the free variables in the expression with the expressions in the expr array + + For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) + val substitute_vars : Expr.expr -> Expr.expr list -> expr + + (** Translates (copies) the term to another context. + @return A copy of the term which is associated with the other context *) + val translate : Expr.expr -> context -> expr + + (** Returns a string representation of the expression. *) + val to_string : Expr.expr -> string + + (** Indicates whether the term is a numeral *) + val is_numeral : Expr.expr -> bool + + (** Indicates whether the term is well-sorted. + @return True if the term is well-sorted, false otherwise. *) + val is_well_sorted : Expr.expr -> bool + + (** The Sort of the term. *) + val get_sort : Expr.expr -> Sort.sort + + (** Indicates whether the term has Boolean sort. *) + val is_bool : Expr.expr -> bool + + (** Indicates whether the term represents a constant. *) + val is_const : Expr.expr -> bool + + (** Indicates whether the term is the constant true. *) + val is_true : Expr.expr -> bool + + (** Indicates whether the term is the constant false. *) + val is_false : Expr.expr -> bool + + (** Indicates whether the term is an equality predicate. *) + val is_eq : Expr.expr -> bool + + (** Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). *) + val is_distinct : Expr.expr -> bool + + (** Indicates whether the term is a ternary if-then-else term *) + val is_ite : Expr.expr -> bool + + (** Indicates whether the term is an n-ary conjunction *) + val is_and : Expr.expr -> bool + + (** Indicates whether the term is an n-ary disjunction *) + val is_or : Expr.expr -> bool + + (** Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) *) + val is_iff : Expr.expr -> bool + + (** Indicates whether the term is an exclusive or *) + val is_xor : Expr.expr -> bool + + (** Indicates whether the term is a negation *) + val is_not : Expr.expr -> bool + + (** Indicates whether the term is an implication *) + val is_implies : Expr.expr -> bool + + (** 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. *) + val is_label : Expr.expr -> bool + + (** 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. + let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) *) + val is_label_lit : Expr.expr -> bool + + (** 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. *) + val is_oeq : Expr.expr -> bool + + (** Creates a new constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + + (** Creates a new constant. *) + val mk_const_s : context -> string -> Sort.sort -> expr + + (** Creates a constant from the func_decl. *) + val mk_const_f : context -> FuncDecl.func_decl -> expr + + (** Creates a fresh constant with a name prefixed with a string. *) + val mk_fresh_const : context -> string -> Sort.sort -> expr + + (** Create a new function application. *) + val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr + + (** Create a numeral of a given sort. + @return A Term with the goven value and sort *) + val mk_numeral_string : context -> string -> Sort.sort -> expr + + (** Create a numeral 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. + @return A Term with the given value and sort *) + val mk_numeral_int : context -> int -> Sort.sort -> expr +end + +(** Boolean expressions *) +module Boolean : +sig + type bool_sort = BoolSort of Sort.sort + type bool_expr = BoolExpr of Expr.expr + + val expr_of_bool_expr : bool_expr -> Expr.expr + val sort_of_bool_sort : bool_sort -> Sort.sort + val bool_sort_of_sort : Sort.sort -> bool_sort + val bool_expr_of_expr : Expr.expr -> bool_expr + + (** Create a Boolean sort *) + val mk_sort : context -> bool_sort + + (** Create a Boolean constant. *) + val mk_const : context -> Symbol.symbol -> bool_expr + + (** Create a Boolean constant. *) + val mk_const_s : context -> string -> bool_expr + + (** The true Term. *) + val mk_true : context -> bool_expr + + (** The false Term. *) + val mk_false : context -> bool_expr + + (** Creates a Boolean value. *) + val mk_val : context -> bool -> bool_expr + + (** Creates the equality between two expr's. *) + val mk_eq : context -> Expr.expr -> Expr.expr -> bool_expr + + (** Creates a distinct term. *) + val mk_distinct : context -> Expr.expr list -> bool_expr + + (** Mk an expression representing not(a). *) + val mk_not : context -> bool_expr -> bool_expr + + (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) + val mk_ite : context -> bool_expr -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 iff t2. *) + val mk_iff : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 -> t2. *) + val mk_implies : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing t1 xor t2. *) + val mk_xor : context -> bool_expr -> bool_expr -> bool_expr + + (** Create an expression representing the AND of args *) + val mk_and : context -> bool_expr list -> bool_expr + + (** Create an expression representing the OR of args *) + val mk_or : context -> bool_expr list -> bool_expr +end + +(** Quantifier expressions *) +module Quantifier : +sig + type quantifier = Quantifier of Expr.expr + + val expr_of_quantifier : quantifier -> Expr.expr + val quantifier_of_expr : Expr.expr -> quantifier + + (** Quantifier patterns + + 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. *) + module Pattern : + sig + type pattern = Pattern of AST.ast + + val ast_of_pattern : pattern -> AST.ast + val pattern_of_ast : AST.ast -> pattern + + (** The number of terms in the pattern. *) + val get_num_terms : pattern -> int + + (** The terms in the pattern. *) + val get_terms : pattern -> Expr.expr list + + (** A string representation of the pattern. *) + val to_string : pattern -> string + end + + + (** 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 : expr ) appears, the higher is its + index. *) + val get_index : Expr.expr -> int + + (** Indicates whether the quantifier is universal. *) + val is_universal : quantifier -> bool + + (** Indicates whether the quantifier is existential. *) + val is_existential : quantifier -> bool + + (** The weight of the quantifier. *) + val get_weight : quantifier -> int + + (** The number of patterns. *) + val get_num_patterns : quantifier -> int + + (** The patterns. *) + val get_patterns : quantifier -> Pattern.pattern list + + (** The number of no-patterns. *) + val get_num_no_patterns : quantifier -> int + + (** The no-patterns. *) + val get_no_patterns : quantifier -> Pattern.pattern list + + (** The number of bound variables. *) + val get_num_bound : quantifier -> int + + (** The symbols for the bound variables. *) + val get_bound_variable_names : quantifier -> Symbol.symbol list + + (** The sorts of the bound variables. *) + val get_bound_variable_sorts : quantifier -> Sort.sort list + + (** The body of the quantifier. *) + val get_body : quantifier -> Boolean.bool_expr + + (** Creates a new bound variable. *) + val mk_bound : context -> int -> Sort.sort -> Expr.expr + + (** Create a quantifier pattern. *) + val mk_pattern : context -> Expr.expr list -> Pattern.pattern + + (** Create a universal Quantifier. *) + val mk_forall : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a universal Quantifier. *) + val mk_forall_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create an existential Quantifier. *) + val mk_exists : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create an existential Quantifier. *) + val mk_exists_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a Quantifier. *) + val mk_quantifier : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** Create a Quantifier. *) + val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier +end + +(** Functions to manipulate Array expressions *) +module Array_ : +sig + type array_sort = ArraySort of Sort.sort + type array_expr = ArrayExpr of Expr.expr + + val sort_of_array_sort : array_sort -> Sort.sort + val array_sort_of_sort : Sort.sort -> array_sort + val expr_of_array_expr : array_expr -> Expr.expr + + val array_expr_of_expr : Expr.expr -> array_expr + + (** Create a new array sort. *) + val mk_sort : context -> Sort.sort -> Sort.sort -> 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. *) + val is_store : Expr.expr -> bool + + (** Indicates whether the term is an array select. *) + val is_select : Expr.expr -> bool + + (** 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. *) + val is_constant_array : Expr.expr -> bool + + (** Indicates whether the term is a default array. + For example default(const(v)) = v. The function is unary. *) + val is_default_array : Expr.expr -> bool + + (** 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. *) + val is_array_map : Expr.expr -> bool + + (** 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. *) + val is_as_array : Expr.expr -> bool + + (** Indicates whether the term is of an array sort. *) + val is_array : Expr.expr -> bool + + (** The domain of the array sort. *) + val get_domain : array_sort -> Sort.sort + + (** The range of the array sort. *) + val get_range : array_sort -> Sort.sort + + (** Create an array constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> array_expr + + (** Create an array constant. *) + val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> array_expr + + (** 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. + {!Array_.mk_sort} + {!mk_store} *) + val mk_select : context -> array_expr -> Expr.expr -> array_expr + + (** 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). + {!Array_.mk_sort} + {!mk_select} *) + val mk_store : context -> array_expr -> Expr.expr -> Expr.expr -> array_expr + + (** Create a constant array. + + The resulting term is an array, such that a selecton an arbitrary index + produces the value v. + {!Array_.mk_sort} + {!mk_select} *) + val mk_const_array : context -> Sort.sort -> Expr.expr -> array_expr + + (** 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]. + {!Array_.mk_sort} + {!mk_select} + {!mk_store} *) + val mk_map : context -> FuncDecl.func_decl -> array_expr list -> array_expr + + (** Access the array default value. + + Produces the default range value, for arrays that can be represented as + finite maps with a default range value. *) + val mk_term_array : context -> array_expr -> array_expr +end + +(** Functions to manipulate Set expressions *) +module Set : +sig + type set_sort = SetSort of Sort.sort + + val sort_of_set_sort : set_sort -> Sort.sort + + (** Create a set type. *) + val mk_sort : context -> Sort.sort -> set_sort + + (** Indicates whether the term is set union *) + val is_union : Expr.expr -> bool + + (** Indicates whether the term is set intersection *) + val is_intersect : Expr.expr -> bool + + (** Indicates whether the term is set difference *) + val is_difference : Expr.expr -> bool + + (** Indicates whether the term is set complement *) + val is_complement : Expr.expr -> bool + + (** Indicates whether the term is set subset *) + val is_subset : Expr.expr -> bool + + (** Create an empty set. *) + val mk_empty : context -> Sort.sort -> Expr.expr + + (** Create the full set. *) + val mk_full : context -> Sort.sort -> Expr.expr + + (** Add an element to the set. *) + val mk_set_add : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Remove an element from a set. *) + val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Take the union of a list of sets. *) + val mk_union : context -> Expr.expr list -> Expr.expr + + (** Take the intersection of a list of sets. *) + val mk_intersection : context -> Expr.expr list -> Expr.expr + + (** Take the difference between two sets. *) + val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Take the complement of a set. *) + val mk_complement : context -> Expr.expr -> Expr.expr + + (** Check for set membership. *) + val mk_membership : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Check for subsetness of sets. *) + val mk_subset : context -> Expr.expr -> Expr.expr -> Expr.expr +end + +(** Functions to manipulate Finite Domain expressions *) +module FiniteDomain : +sig + type finite_domain_sort = FiniteDomainSort of Sort.sort + + val sort_of_finite_domain_sort : finite_domain_sort -> Sort.sort + val finite_domain_sort_of_sort : Sort.sort -> finite_domain_sort + + (** Create a new finite domain sort. *) + val mk_sort : context -> Symbol.symbol -> int -> finite_domain_sort + + (** Create a new finite domain sort. *) + val mk_sort_s : context -> string -> int -> finite_domain_sort + + (** Indicates whether the term is of an array sort. *) + val is_finite_domain : Expr.expr -> bool + + (** Indicates whether the term is a less than predicate over a finite domain. *) + val is_lt : Expr.expr -> bool + + (** The size of the finite domain sort. *) + val get_size : finite_domain_sort -> int +end + + +(** Functions to manipulate Relation expressions *) +module Relation : +sig + type relation_sort = RelationSort of Sort.sort + + val sort_of_relation_sort : relation_sort -> Sort.sort + val relation_sort_of_sort : Sort.sort -> relation_sort + + (** Indicates whether the term is of a relation sort. *) + val is_relation : Expr.expr -> bool + + (** 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. *) + val is_store : Expr.expr -> bool + + (** Indicates whether the term is an empty relation *) + val is_empty : Expr.expr -> bool + + (** Indicates whether the term is a test for the emptiness of a relation *) + val is_is_empty : Expr.expr -> bool + + (** Indicates whether the term is a relational join *) + val is_join : Expr.expr -> bool + + (** Indicates whether the term is the union or convex hull of two relations. + The function takes two arguments. *) + val is_union : Expr.expr -> bool + + (** Indicates whether the term is the widening of two relations + The function takes two arguments. *) + val is_widen : Expr.expr -> bool + + (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). + The function takes one argument. *) + val is_project : Expr.expr -> bool + + (** 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. *) + val is_filter : Expr.expr -> bool + + (** 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. *) + val is_negation_filter : Expr.expr -> bool + + (** 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. *) + val is_rename : Expr.expr -> bool + + (** Indicates whether the term is the complement of a relation *) + val is_complement : Expr.expr -> bool + + (** 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. *) + val is_select : Expr.expr -> bool + + (** 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 {!is_union} + to perform destructive updates to the first argument. *) + val is_clone : Expr.expr -> bool + + (** The arity of the relation sort. *) + val get_arity : relation_sort -> int + + (** The sorts of the columns of the relation sort. *) + val get_column_sorts : relation_sort -> relation_sort list +end + +(** Functions to manipulate Datatype expressions *) +module Datatype : +sig + type datatype_sort = DatatypeSort of Sort.sort + type datatype_expr = DatatypeExpr of Expr.expr + + val sort_of_datatype_sort : datatype_sort -> Sort.sort + val datatype_sort_of_sort : Sort.sort -> datatype_sort + val expr_of_datatype_expr : datatype_expr -> Expr.expr + val datatype_expr_of_expr : Expr.expr -> datatype_expr + + (** Datatype Constructors *) + module Constructor : + sig + type constructor + + (** The number of fields of the constructor. *) + val get_num_fields : constructor -> int + + (** The function declaration of the constructor. *) + val get_constructor_decl : constructor -> FuncDecl.func_decl + + (** The function declaration of the tester. *) + val get_tester_decl : constructor -> FuncDecl.func_decl + + (** The function declarations of the accessors *) + val get_accessor_decls : constructor -> FuncDecl.func_decl list + end + + (** Create a datatype 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. *) + val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + + (** Create a datatype 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. *) + val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + + (** Create a new datatype sort. *) + val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> datatype_sort + + (** Create a new datatype sort. *) + val mk_sort_s : context -> string -> Constructor.constructor list -> datatype_sort + + (** Create mutually recursive datatypes. *) + val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> datatype_sort list + + (** Create mutually recursive data-types. *) + val mk_sorts_s : context -> string list -> Constructor.constructor list list -> datatype_sort list + + + (** The number of constructors of the datatype sort. *) + val get_num_constructors : datatype_sort -> int + + (** The constructors. *) + val get_constructors : datatype_sort -> FuncDecl.func_decl list + + (** The recognizers. *) + val get_recognizers : datatype_sort -> FuncDecl.func_decl list + + (** The constructor accessors. *) + val get_accessors : datatype_sort -> FuncDecl.func_decl list list +end + +(** Functions to manipulate Enumeration expressions *) +module Enumeration : +sig + type enum_sort = EnumSort of Sort.sort + + val sort_of_enum_sort : enum_sort -> Sort.sort + + (** Create a new enumeration sort. *) + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> enum_sort + + (** Create a new enumeration sort. *) + val mk_sort_s : context -> string -> string list -> enum_sort + + (** The function declarations of the constants in the enumeration. *) + val get_const_decls : enum_sort -> FuncDecl.func_decl list + + (** The test predicates for the constants in the enumeration. *) + val get_tester_decls : enum_sort -> FuncDecl.func_decl list +end + +(** Functions to manipulate List expressions *) +module List_ : +sig + type list_sort = ListSort of Sort.sort + + val sort_of_list_sort : list_sort -> Sort.sort + + (** Create a new list sort. *) + val mk_sort : context -> Symbol.symbol -> Sort.sort -> list_sort + + (** Create a new list sort. *) + val mk_list_s : context -> string -> Sort.sort -> list_sort + + (** The declaration of the nil function of this list sort. *) + val get_nil_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the isNil function of this list sort. *) + val get_is_nil_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the cons function of this list sort. *) + val get_cons_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the isCons function of this list sort. *) + val get_is_cons_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the head function of this list sort. *) + val get_head_decl : list_sort -> FuncDecl.func_decl + + (** The declaration of the tail function of this list sort. *) + val get_tail_decl : list_sort -> FuncDecl.func_decl + + (** The empty list. *) + val nil : list_sort -> Expr.expr +end + +(** Functions to manipulate Tuple expressions *) +module Tuple : +sig + type tuple_sort = TupleSort of Sort.sort + + val sort_of_tuple_sort : tuple_sort -> Sort.sort + + (** Create a new tuple sort. *) + val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> tuple_sort + + (** The constructor function of the tuple. *) + val get_mk_decl : tuple_sort -> FuncDecl.func_decl + + (** The number of fields in the tuple. *) + val get_num_fields : tuple_sort -> int + + (** The field declarations. *) + val get_field_decls : tuple_sort -> FuncDecl.func_decl list +end + +(** Functions to manipulate arithmetic expressions *) +module rec Arithmetic : +sig + type arith_sort = ArithSort of Sort.sort + type arith_expr = ArithExpr of Expr.expr + + val sort_of_arith_sort : Arithmetic.arith_sort -> Sort.sort + val arith_sort_of_sort : Sort.sort -> Arithmetic.arith_sort + val expr_of_arith_expr : Arithmetic.arith_expr -> Expr.expr + val arith_expr_of_expr : Expr.expr -> Arithmetic.arith_expr + + (** Integer Arithmetic *) + module rec Integer : + sig + type int_sort = IntSort of arith_sort + type int_expr = IntExpr of arith_expr + type int_num = IntNum of int_expr + + val arith_sort_of_int_sort : Arithmetic.Integer.int_sort -> Arithmetic.arith_sort + val int_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Integer.int_sort + val arith_expr_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.arith_expr + val int_expr_of_int_num : Arithmetic.Integer.int_num -> Arithmetic.Integer.int_expr + val int_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Integer.int_expr + val int_num_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.Integer.int_num + + (** Create a new integer sort. *) + val mk_sort : context -> int_sort + + (** Retrieve the int value. *) + val get_int : int_num -> int + + (** Returns a string representation of the numeral. *) + val to_string : int_num -> string + + (** Creates an integer constant. *) + val mk_int_const : context -> Symbol.symbol -> int_expr + + (** Creates an integer constant. *) + val mk_int_const_s : context -> string -> int_expr + + (** Create an expression representing t1 mod t2. + The arguments must have int type. *) + val mk_mod : context -> int_expr -> int_expr -> int_expr + + (** Create an expression representing t1 rem t2. + The arguments must have int type. *) + val mk_rem : context -> int_expr -> int_expr -> int_expr + + (** Create an integer numeral. *) + val mk_int_numeral_s : context -> string -> int_num + + (** Create an integer numeral. + @return A Term with the given value and sort Integer *) + val mk_int_numeral_i : context -> int -> int_num + + (** 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. *) + val mk_int2real : context -> int_expr -> Real.real_expr + + (** Create an n-bit bit-vector from an 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. *) + val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr + end + + (** Real Arithmetic *) + and Real : + sig + type real_sort = RealSort of arith_sort + type real_expr = RealExpr of arith_expr + type rat_num = RatNum of real_expr + + val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort + val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort + val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr + val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr + val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr + val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num + + (** Create a real sort. *) + val mk_sort : context -> real_sort + + (** The numerator of a rational numeral. *) + val get_numerator : rat_num -> Integer.int_num + + (** The denominator of a rational numeral. *) + val get_denominator : rat_num -> Integer.int_num + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as indicated by the int argument.*) + val to_decimal_string : rat_num -> int -> string + + (** Returns a string representation of the numeral. *) + val to_string : rat_num -> string + + (** Creates a real constant. *) + val mk_real_const : context -> Symbol.symbol -> real_expr + + (** Creates a real constant. *) + val mk_real_const_s : context -> string -> real_expr + + (** Create a real numeral from a fraction. + @return A Term with rational value and sort Real + {!mk_numeral_s} *) + val mk_numeral_nd : context -> int -> int -> rat_num + + (** Create a real numeral. + @return A Term with the given value and sort Real *) + val mk_numeral_s : context -> string -> rat_num + + (** Create a real numeral. + @return A Term with the given value and sort Real *) + val mk_numeral_i : context -> int -> rat_num + + (** Creates an expression that checks whether a real number is an integer. *) + val mk_is_integer : context -> real_expr -> Boolean.bool_expr + + (** 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. *) + val mk_real2int : context -> real_expr -> Integer.int_expr + end + + (** Algebraic Numbers *) + and AlgebraicNumber : + sig + type algebraic_num = AlgebraicNum of arith_expr + + val arith_expr_of_algebraic_num : Arithmetic.AlgebraicNumber.algebraic_num -> Arithmetic.arith_expr + val algebraic_num_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.AlgebraicNumber.algebraic_num + + (** Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) + val to_upper : algebraic_num -> int -> Real.rat_num + + (** Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) + val to_lower : algebraic_num -> int -> Real.rat_num + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as the int argument provided.*) + val to_decimal_string : algebraic_num -> int -> string + + (** Returns a string representation of the numeral. *) + val to_string : algebraic_num -> string + end + + (** Indicates whether the term is of integer sort. *) + val is_int : Expr.expr -> bool + + (** Indicates whether the term is an arithmetic numeral. *) + val is_arithmetic_numeral : Expr.expr -> bool + + (** Indicates whether the term is a less-than-or-equal *) + val is_le : Expr.expr -> bool + + (** Indicates whether the term is a greater-than-or-equal *) + val is_ge : Expr.expr -> bool + + (** Indicates whether the term is a less-than *) + val is_lt : Expr.expr -> bool + + (** Indicates whether the term is a greater-than *) + val is_gt : Expr.expr -> bool + + (** Indicates whether the term is addition (binary) *) + val is_add : Expr.expr -> bool + + (** Indicates whether the term is subtraction (binary) *) + val is_sub : Expr.expr -> bool + + (** Indicates whether the term is a unary minus *) + val is_uminus : Expr.expr -> bool + + (** Indicates whether the term is multiplication (binary) *) + val is_mul : Expr.expr -> bool + + (** Indicates whether the term is division (binary) *) + val is_div : Expr.expr -> bool + + (** Indicates whether the term is integer division (binary) *) + val is_idiv : Expr.expr -> bool + + (** Indicates whether the term is remainder (binary) *) + val is_remainder : Expr.expr -> bool + + (** Indicates whether the term is modulus (binary) *) + val is_modulus : Expr.expr -> bool + + (** Indicates whether the term is a coercion of integer to real (unary) *) + val is_inttoreal : Expr.expr -> bool + + (** Indicates whether the term is a coercion of real to integer (unary) *) + val is_real_to_int : Expr.expr -> bool + + (** Indicates whether the term is a check that tests whether a real is integral (unary) *) + val is_real_is_int : Expr.expr -> bool + + (** Indicates whether the term is of sort real. *) + val is_real : Expr.expr -> bool + + (** Indicates whether the term is an integer numeral. *) + val is_int_numeral : Expr.expr -> bool + + (** Indicates whether the term is a real numeral. *) + val is_rat_num : Expr.expr -> bool + + (** Indicates whether the term is an algebraic number *) + val is_algebraic_number : Expr.expr -> bool + + (** Create an expression representing t[0] + t[1] + .... *) + val mk_add : context -> arith_expr list -> arith_expr + + (** Create an expression representing t[0] * t[1] * .... *) + val mk_mul : context -> arith_expr list -> arith_expr + + (** Create an expression representing t[0] - t[1] - .... *) + val mk_sub : context -> arith_expr list -> arith_expr + + (** Create an expression representing -t. *) + val mk_unary_minus : context -> arith_expr -> arith_expr + + (** Create an expression representing t1 / t2. *) + val mk_div : context -> arith_expr -> arith_expr -> arith_expr + + (** Create an expression representing t1 ^ t2. *) + val mk_power : context -> arith_expr -> arith_expr -> arith_expr + + (** Create an expression representing t1 < t2 *) + val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 <= t2 *) + val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 > t2 *) + val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr + + (** Create an expression representing t1 >= t2 *) + val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr +end + +(** Functions to manipulate bit-vector expressions *) +and BitVector : +sig + type bitvec_sort = BitVecSort of Sort.sort + type bitvec_expr = BitVecExpr of Expr.expr + type bitvec_num = BitVecNum of bitvec_expr + + val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort + val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort + val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr + val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr + val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr + val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num + + (** Create a new bit-vector sort. *) + val mk_sort : context -> int -> bitvec_sort + + (** Indicates whether the terms is of bit-vector sort. *) + val is_bv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector numeral *) + val is_bv_numeral : Expr.expr -> bool + + (** Indicates whether the term is a one-bit bit-vector with value one *) + val is_bv_bit1 : Expr.expr -> bool + + (** Indicates whether the term is a one-bit bit-vector with value zero *) + val is_bv_bit0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unary minus *) + val is_bv_uminus : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector addition (binary) *) + val is_bv_add : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector subtraction (binary) *) + val is_bv_sub : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector multiplication (binary) *) + val is_bv_mul : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed division (binary) *) + val is_bv_sdiv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned division (binary) *) + val is_bv_udiv : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed remainder (binary) *) + val is_bv_SRem : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) + val is_bv_urem : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed modulus *) + val is_bv_smod : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed division by zero *) + val is_bv_sdiv0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned division by zero *) + val is_bv_udiv0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed remainder by zero *) + val is_bv_srem0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector unsigned remainder by zero *) + val is_bv_urem0 : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector signed modulus by zero *) + val is_bv_smod0 : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) + val is_bv_ule : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector less-than-or-equal *) + val is_bv_sle : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) + val is_bv_uge : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) + val is_bv_sge : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector less-than *) + val is_bv_ult : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector less-than *) + val is_bv_slt : Expr.expr -> bool + + (** Indicates whether the term is an unsigned bit-vector greater-than *) + val is_bv_ugt : Expr.expr -> bool + + (** Indicates whether the term is a signed bit-vector greater-than *) + val is_bv_sgt : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise AND *) + val is_bv_and : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise OR *) + val is_bv_or : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NOT *) + val is_bv_not : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise XOR *) + val is_bv_xor : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NAND *) + val is_bv_nand : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise NOR *) + val is_bv_nor : Expr.expr -> bool + + (** Indicates whether the term is a bit-wise XNOR *) + val is_bv_xnor : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector concatenation (binary) *) + val is_bv_concat : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector sign extension *) + val is_bv_signextension : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector zero extension *) + val is_bv_zeroextension : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector extraction *) + val is_bv_extract : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector repetition *) + val is_bv_repeat : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector reduce OR *) + val is_bv_reduceor : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector reduce AND *) + val is_bv_reduceand : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector comparison *) + val is_bv_comp : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector shift left *) + val is_bv_shiftleft : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector logical shift right *) + val is_bv_shiftrightlogical : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector arithmetic shift left *) + val is_bv_shiftrightarithmetic : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector rotate left *) + val is_bv_rotateleft : Expr.expr -> bool + + (** Indicates whether the term is a bit-vector rotate right *) + val is_bv_rotateright : Expr.expr -> bool + + (** 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. *) + val is_bv_rotateleftextended : Expr.expr -> bool + + (** 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. *) + val is_bv_rotaterightextended : Expr.expr -> bool + + (** 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. *) + + (** 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. *) + val is_int_to_bv : Expr.expr -> bool + + (** 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. *) + val is_bv_to_int : Expr.expr -> bool + + (** 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))) *) + val is_bv_carry : Expr.expr -> bool + + (** 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) *) + val is_bv_xor3 : Expr.expr -> bool + + (** The size of a bit-vector sort. *) + val get_size : bitvec_sort -> int + + (** Retrieve the int value. *) + val get_int : bitvec_num -> int + + (** Returns a string representation of the numeral. *) + val to_string : bitvec_num -> string + + (** Creates a bit-vector constant. *) + val mk_const : context -> Symbol.symbol -> int -> bitvec_expr + + (** Creates a bit-vector constant. *) + val mk_const_s : context -> string -> int -> bitvec_expr + + (** Bitwise negation. + The argument must have a bit-vector sort. *) + val mk_not : context -> bitvec_expr -> Expr.expr + + (** Take conjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. *) + val mk_redand : context -> bitvec_expr -> Expr.expr + + (** Take disjunction of bits in a vector,vector of length 1. + The argument must have a bit-vector sort. *) + val mk_redor : context -> bitvec_expr -> Expr.expr + + (** Bitwise conjunction. + The arguments must have a bit-vector sort. *) + val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise disjunction. + The arguments must have a bit-vector sort. *) + val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise XOR. + The arguments must have a bit-vector sort. *) + val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise NAND. + The arguments must have a bit-vector sort. *) + val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise NOR. + The arguments must have a bit-vector sort. *) + val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bitwise XNOR. + The arguments must have a bit-vector sort. *) + val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Standard two's complement unary minus. + The arguments must have a bit-vector sort. *) + val mk_neg : context -> bitvec_expr -> bitvec_expr + + (** Two's complement addition. + The arguments must have the same bit-vector sort. *) + val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Two's complement subtraction. + The arguments must have the same bit-vector sort. *) + val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Two's complement multiplication. + The arguments must have the same bit-vector sort. *) + val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Unsigned less-than + + The arguments must have the same bit-vector sort. *) + val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed less-than + + The arguments must have the same bit-vector sort. *) + val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned less-than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed less-than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned greater than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed greater than or equal to. + + The arguments must have the same bit-vector sort. *) + val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Unsigned greater-than. + + The arguments must have the same bit-vector sort. *) + val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Two's complement signed greater-than. + + The arguments must have the same bit-vector sort. *) + val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** 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). *) + val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Bit-vector extraction. + + Extract the bits between two limits from a bitvector of + size m to yield a new bitvector of size n, where + n = high - low + 1. *) + val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr + + (** Bit-vector repetition. *) + val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr + + (** Shift left. + + It is equivalent to multiplication by 2^x where \c x is the value of third 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.*) + val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Logical shift right + + It is equivalent to unsigned division by 2^x where \c x is the value of the third 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. *) + val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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. *) + val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Rotate Left. + Rotate bits of \c t to the left \c i times. *) + val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr + + (** Rotate Right. + Rotate bits of \c t to the right \c i times.*) + val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr + + (** Rotate Left. + Rotate bits of the second argument to the left.*) + val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** Rotate Right. + Rotate bits of the second argument to the right. *) + val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr + + (** 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 the argument. + 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.*) + val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr + + (** Create a predicate that checks that the bit-wise addition does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise addition does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise subtraction does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise subtraction does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise signed division does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise negation does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise multiplication does not overflow. + + The arguments must be of bit-vector sort. *) + val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr + + (** Create a predicate that checks that the bit-wise multiplication does not underflow. + + The arguments must be of bit-vector sort. *) + val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr + + (** Create a bit-vector numeral. *) + val mk_numeral : context -> string -> int -> bitvec_num +end + +(** Functions to manipulate proof expressions *) +module Proof : +sig + (** Indicates whether the term is a Proof for the expression 'true'. *) + val is_true : Expr.expr -> bool + + (** Indicates whether the term is a proof for a fact asserted by the user. *) + val is_asserted : Expr.expr -> bool + + (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) + val is_goal : Expr.expr -> bool + + (** 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). *) + val is_modus_ponens : Expr.expr -> bool + + (** 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'. *) + val is_reflexivity : Expr.expr -> bool + + (** 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. *) + val is_symmetry : Expr.expr -> bool + + (** 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) *) + val is_transitivity : Expr.expr -> bool + + (** 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. *) + val is_Transitivity_star : Expr.expr -> bool + + (** 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. *) + val is_monotonicity : Expr.expr -> bool + + (** 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)) *) + val is_quant_intro : Expr.expr -> bool + + (** 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. *) + val is_distributivity : Expr.expr -> bool + + (** 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 *) + val is_and_elimination : Expr.expr -> bool + + (** 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) *) + val is_or_elimination : Expr.expr -> bool + + (** 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 : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) *) + val is_rewrite : Expr.expr -> bool + + (** 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) *) + val is_rewrite_star : Expr.expr -> bool + + (** 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. *) + val is_pull_quant : Expr.expr -> bool + + (** 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 *) + val is_pull_quant_star : Expr.expr -> bool + + (** 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 *) + val is_push_quant : Expr.expr -> bool + + (** 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. *) + val is_elim_unused_vars : Expr.expr -> bool + + (** Indicates whether the term is a proof for destructive equality resolution + + A proof for destructive equality resolution: + (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. + + This proof object has no antecedents. + + Several variables can be eliminated simultaneously. *) + val is_der : Expr.expr -> bool + + (** Indicates whether the term is a proof for quantifier instantiation + + A proof of (or (not (forall (x) (P x))) (P a)) *) + val is_quant_inst : Expr.expr -> bool + + (** Indicates whether the term is a hypthesis marker. + Mark a hypothesis in a natural deduction style proof. *) + val is_hypothesis : Expr.expr -> bool + + (** 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. *) + val is_lemma : Expr.expr -> bool + + (** 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') *) + val is_unit_resolution : Expr.expr -> bool + + (** Indicates whether the term is a proof by iff-true + + T1: p + [iff-true T1]: (iff p true) *) + val is_iff_true : Expr.expr -> bool + + (** Indicates whether the term is a proof by iff-false + + T1: (not p) + [iff-false T1]: (iff p false) *) + val is_iff_false : Expr.expr -> bool + + (** 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. *) + val is_commutativity : Expr.expr -> bool + + (** 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). *) + val is_def_axiom : Expr.expr -> bool + + (** 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) *) + val is_def_intro : Expr.expr -> bool + + (** 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. *) + val is_apply_def : Expr.expr -> bool + + (** Indicates whether the term is a proof iff-oeq + + T1: (iff p q) + [iff~ T1]: (~ p q) *) + val is_iff_oeq : Expr.expr -> bool + + (** 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'. *) + val is_nnf_pos : Expr.expr -> bool + + (** 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'))) *) + val is_nnf_neg : Expr.expr -> bool + + (** 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. *) + val is_nnf_star : Expr.expr -> bool + + (** 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. *) + val is_cnf_star : Expr.expr -> bool + + (** Indicates whether the term is a proof for a Skolemization step + + Proof for: + + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + + This proof object has no antecedents. *) + val is_skolemize : Expr.expr -> bool + + (** 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 *) + val is_modus_ponens_oeq : Expr.expr -> bool + + (** 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. *) + val is_theory_lemma : Expr.expr -> bool +end + +(** Goals + + A goal (aka problem). A goal is essentially a + of formulas, that can be solved and/or transformed using + tactics and solvers. *) +module Goal : +sig + type goal + + (** 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. *) + val get_precision : goal -> Z3enums.goal_prec + + (** Indicates whether the goal is precise. *) + val is_precise : goal -> bool + + (** Indicates whether the goal is an under-approximation. *) + val is_underapproximation : goal -> bool + + (** Indicates whether the goal is an over-approximation. *) + val is_overapproximation : goal -> bool + + (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) + val is_garbage : goal -> bool + + (** Adds the constraints to the given goal. *) + val assert_ : goal -> Boolean.bool_expr list -> unit + + (** Indicates whether the goal contains `false'. *) + val is_inconsistent : goal -> bool + + (** The depth of the goal. + This tracks how many transformations were applied to it. *) + val get_depth : goal -> int + + (** Erases all formulas from the given goal. *) + val reset : goal -> unit + + (** The number of formulas in the goal. *) + val get_size : goal -> int + + (** The formulas in the goal. *) + val get_formulas : goal -> Boolean.bool_expr list + + (** The number of formulas, subformulas and terms in the goal. *) + val get_num_exprs : goal -> int + + (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) + val is_decided_sat : goal -> bool + + (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) + val is_decided_unsat : goal -> bool + + (** Translates (copies) the Goal to another context.. *) + val translate : goal -> context -> goal + + (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) + val simplify : goal -> Params.params option -> goal + + (** Creates a new Goal. + + Note that the Context must have been created with proof generation support if + the fourth argument is set to true here. *) + val mk_goal : context -> bool -> bool -> bool -> goal + + (** A string representation of the Goal. *) + val to_string : goal -> string +end + +(** Models + + A Model contains interpretations (assignments) of constants and functions. *) +module Model : +sig + type model + + (** Function interpretations + + A function interpretation is represented as a finite map and an 'else'. + Each entry in the finite map represents the value of a function given a set of arguments. *) + module FuncInterp : + sig + type func_interp + + (** Function interpretations entries + + An Entry object represents an element in the finite map used to a function interpretation. *) + module FuncEntry : + sig + type func_entry + + (** Return the (symbolic) value of this entry. + *) + val get_value : func_entry -> Expr.expr + + (** The number of arguments of the entry. + *) + val get_num_args : func_entry -> int + + (** The arguments of the function entry. + *) + val get_args : func_entry -> Expr.expr list + + (** A string representation of the function entry. + *) + val to_string : func_entry -> string + end + + (** The number of entries in the function interpretation. *) + val get_num_entries : func_interp -> int + + (** The entries in the function interpretation *) + val get_entries : func_interp -> FuncEntry.func_entry list + + (** The (symbolic) `else' value of the function interpretation. *) + val get_else : func_interp -> Expr.expr + + (** The arity of the function interpretation *) + val get_arity : func_interp -> int + + (** A string representation of the function interpretation. *) + val to_string : func_interp -> string + end + + (** Retrieves the interpretation (the assignment) of a func_decl in the model. + An expression if the function has an interpretation in the model, null otherwise. *) + val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option + + (** Retrieves the interpretation (the assignment) of an expression in the model. + An expression if the constant has an interpretation in the model, null otherwise. *) + val get_const_interp_e : model -> Expr.expr -> Expr.expr option + + (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. + A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option + + (** The number of constant interpretations in the model. *) + val get_num_consts : model -> int + + (** The function declarations of the constants in the model. *) + val get_const_decls : model -> FuncDecl.func_decl list + + (** The number of function interpretations in the model. *) + val get_num_funcs : model -> int + + (** The function declarations of the function interpretations in the model. *) + val get_func_decls : model -> FuncDecl.func_decl list + + (** All symbols that have an interpretation in the model. *) + val get_decls : model -> FuncDecl.func_decl list + + (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) + exception ModelEvaluationFailedException of string + + (** Evaluates an expression in the current model. + + This function may fail if the argument contains quantifiers, + is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. + In this case a ModelEvaluationFailedException is thrown. + *) + val eval : model -> Expr.expr -> bool -> Expr.expr + + (** Alias for eval. *) + val evaluate : model -> Expr.expr -> bool -> Expr.expr + + (** The number of uninterpreted sorts that the model has an interpretation for. *) + val get_num_sorts : model -> int + + (** 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. + {!get_num_sorts} + {!sort_universe} *) + val get_sorts : model -> Sort.sort list + + (** The finite set of distinct values that represent the interpretation of a sort. + {!get_sorts} + @returns A list of expressions, where each is an element of the universe of the sort *) + val sort_universe : model -> Sort.sort -> AST.ast list + + (** Conversion of models to strings. + A string representation of the model. *) + val to_string : model -> string +end + +(** Probes + + 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. +*) +module Probe : +sig + type probe + + (** Execute the probe over the goal. + A probe always produce a double value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) + val apply : probe -> Goal.goal -> float + + (** The number of supported Probes. *) + val get_num_probes : context -> int + + (** The names of all supported Probes. *) + val get_probe_names : context -> string list + + (** Returns a string containing a description of the probe with the given name. *) + val get_probe_description : context -> string -> string + + (** Creates a new Probe. *) + val mk_probe : context -> string -> probe + + (** Create a probe that always evaluates to a float value. *) + val const : context -> float -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is less than the value returned by second argument *) + val lt : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is greater than the value returned by second argument *) + val gt : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is less than or equal the value returned by second argument *) + val le : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is greater than or equal the value returned by second argument *) + val ge : context -> probe -> probe -> probe + + + (** Create a probe that evaluates to "true" when the value returned by the first argument + is equal the value returned by second argument *) + val eq : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when both of two probes evaluate to "true". *) + val and_ : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when either of two probes evaluates to "true". *) + val or_ : context -> probe -> probe -> probe + + (** Create a probe that evaluates to "true" when another probe does not evaluate to "true". *) + val not_ : context -> probe -> probe +end + +(** Tactics + + Tactics are the basic building block for creating custom solvers for specific problem domains. + The complete list of tactics may be obtained using Context.get_num_tactics + and Context.get_tactic_names. + It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. +*) +module Tactic : +sig + type tactic + + (** Tactic application results + + ApplyResult objects represent the result of an application of a + tactic to a goal. It contains the subgoals that were produced. *) + module ApplyResult : + sig + type apply_result + + (** The number of Subgoals. *) + val get_num_subgoals : apply_result -> int + + (** Retrieves the subgoals from the apply_result. *) + val get_subgoals : apply_result -> Goal.goal list + + (** Retrieves a subgoal from the apply_result. *) + val get_subgoal : apply_result -> int -> Goal.goal + + (** Convert a model for a subgoal into a model for the original + goal g, that the ApplyResult was obtained from. + #return A model for g *) + val convert_model : apply_result -> int -> Model.model -> Model.model + + (** A string representation of the ApplyResult. *) + val to_string : apply_result -> string + end + + (** A string containing a description of parameters accepted by the tactic. *) + val get_help : tactic -> string + + (** Retrieves parameter descriptions for Tactics. *) + val get_param_descrs : tactic -> Params.ParamDescrs.param_descrs + + (** Apply the tactic to the goal. *) + val apply : tactic -> Goal.goal -> Params.params option -> ApplyResult.apply_result + + (** The number of supported tactics. *) + val get_num_tactics : context -> int + + (** The names of all supported tactics. *) + val get_tactic_names : context -> string list + + (** Returns a string containing a description of the tactic with the given name. *) + val get_tactic_description : context -> string -> string + + (** Creates a new Tactic. *) + val mk_tactic : context -> string -> tactic + + (** Create a tactic that applies one tactic to a Goal and + then another one to every subgoal produced by the first one. *) + val and_then : context -> tactic -> tactic -> tactic list -> tactic + + (** Create a tactic that first applies one tactic to a Goal and + if it fails then returns the result of another tactic applied to the Goal. *) + val or_else : context -> tactic -> tactic -> tactic + + (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). + + If the tactic does not terminate within the timeout, then it fails. *) + val try_for : context -> tactic -> int -> tactic + + (** Create a tactic that applies one tactic to a given goal if the probe + evaluates to true. + + If the probe evaluates to false, then the new tactic behaves like the skip tactic. *) + val when_ : context -> Probe.probe -> tactic -> tactic + + (** Create a tactic that applies a tactic to a given goal if the probe + evaluates to true and another tactic otherwise. *) + val cond : context -> Probe.probe -> tactic -> tactic -> tactic + + (** Create a tactic that keeps applying one tactic until the goal is not + modified anymore or the maximum number of iterations is reached. *) + val repeat : context -> tactic -> int -> tactic + + (** Create a tactic that just returns the given goal. *) + val skip : context -> tactic + + (** Create a tactic always fails. *) + val fail : context -> tactic + + (** Create a tactic that fails if the probe evaluates to false. *) + val fail_if : context -> Probe.probe -> tactic + + (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) + or trivially unsatisfiable (i.e., contains `false'). *) + val fail_if_not_decided : context -> tactic + + (** Create a tactic that applies a tactic using the given set of parameters. *) + val using_params : context -> tactic -> Params.params -> tactic + + (** Create a tactic that applies a tactic using the given set of parameters. + Alias for UsingParams*) + val with_ : context -> tactic -> Params.params -> tactic + + (** Create a tactic that applies the given tactics in parallel. *) + val par_or : context -> tactic list -> tactic + + (** Create a tactic that applies a tactic to a given goal and then another tactic + to every subgoal produced by the first one. The subgoals are processed in parallel. *) + val par_and_then : context -> tactic -> tactic -> tactic + + (** Interrupt the execution of a Z3 procedure. + This procedure can be used to interrupt: solvers, simplifiers and tactics. *) + val interrupt : context -> unit +end + +(** Solvers *) +module Solver : +sig + type solver + type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE + + val string_of_status : status -> string + + (** Objects that track statistical information about solvers. *) + module Statistics : + sig + type statistics + + (** Statistical data is organized into pairs of \[Key, Entry\], where every + Entry is either a floating point or integer value. + *) + module Entry : + sig + type statistics_entry + + (** The key of the entry. *) + val get_key : statistics_entry -> string + + (** The int-value of the entry. *) + val get_int : statistics_entry -> int + + (** The float-value of the entry. *) + val get_float : statistics_entry -> float + + (** True if the entry is uint-valued. *) + val is_int : statistics_entry -> bool + + (** True if the entry is double-valued. *) + val is_float : statistics_entry -> bool + + (** The string representation of the the entry's value. *) + val to_string_value : statistics_entry -> string + + (** The string representation of the entry (key and value) *) + val to_string : statistics_entry -> string + end + + (** A string representation of the statistical data. *) + val to_string : statistics -> string + + (** The number of statistical data. *) + val get_size : statistics -> int + + (** The data entries. *) + val get_entries : statistics -> Entry.statistics_entry list + + (** The statistical counters. *) + val get_keys : statistics -> string list + + (** The value of a particular statistical counter. *) + val get : statistics -> string -> Entry.statistics_entry option + end + + (** A string that describes all available solver parameters. *) + val get_help : solver -> string + + (** Sets the solver parameters. *) + val set_parameters : solver -> Params.params -> unit + + (** Retrieves parameter descriptions for solver. *) + val get_param_descrs : solver -> Params.ParamDescrs.param_descrs + + (** The current number of backtracking points (scopes). + {!pop} + {!push} *) + val get_num_scopes : solver -> int + + (** Creates a backtracking point. + {!pop} *) + val push : solver -> unit + + (** Backtracks a number of backtracking points. + Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} + {!push} *) + val pop : solver -> int -> unit + + (** Resets the Solver. + This removes all assertions from the solver. *) + val reset : solver -> unit + + (** Assert a constraint (or multiple) into the solver. *) + val assert_ : solver -> Boolean.bool_expr list -> unit + + (** * Assert multiple constraints (cs) into the solver, and track them (in the + * unsat) core + * using the Boolean constants in ps. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) + val assert_and_track_a : solver -> Boolean.bool_expr list -> Boolean.bool_expr list -> unit + + (** * Assert a constraint (c) into the solver, and track it (in the unsat) core + * using the Boolean constant p. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) + val assert_and_track : solver -> Boolean.bool_expr -> Boolean.bool_expr -> unit + + (** The number of assertions in the solver. *) + val get_num_assertions : solver -> int + + (** The set of asserted formulas. *) + val get_assertions : solver -> Boolean.bool_expr list + + (** Checks whether the assertions in the solver are consistent or not. + + {!Model} + {!get_unsat_core} + {!Proof} *) + val check : solver -> Boolean.bool_expr list -> status + + (** The model of the last Check. + + The result is None if Check was not invoked before, + if its results was not SATISFIABLE, or if model production is not enabled. *) + val get_model : solver -> Model.model option + + (** 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. *) + val get_proof : solver -> Expr.expr option + + (** 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. *) + val get_unsat_core : solver -> AST.ast list + + (** A brief justification of why the last call to Check returned UNKNOWN. *) + val get_reason_unknown : solver -> string + + (** Solver statistics. *) + val get_statistics : solver -> Statistics.statistics + + (** 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. *) + val mk_solver : context -> Symbol.symbol option -> solver + + (** Creates a new (incremental) solver. + {!mk_solver} *) + val mk_solver_s : context -> string -> solver + + (** Creates a new (incremental) solver. *) + val mk_simple_solver : context -> solver + + (** 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. *) + val mk_solver_t : context -> Tactic.tactic -> solver + + (** A string representation of the solver. *) + val to_string : solver -> string +end + +(** Fixedpoint solving *) +module Fixedpoint : +sig + type fixedpoint + + (** A string that describes all available fixedpoint solver parameters. *) + val get_help : fixedpoint -> string + + (** Sets the fixedpoint solver parameters. *) + val set_params : fixedpoint -> Params.params -> unit + + (** Retrieves parameter descriptions for Fixedpoint solver. *) + val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs + + (** Assert a constraints into the fixedpoint solver. *) + val assert_ : fixedpoint -> Boolean.bool_expr list -> unit + + (** Register predicate as recursive relation. *) + val register_relation : fixedpoint -> FuncDecl.func_decl -> unit + + (** Add rule into the fixedpoint solver. *) + val add_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol option -> unit + + (** Add table fact to the fixedpoint solver. *) + val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit + + (** 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. *) + val query : fixedpoint -> Boolean.bool_expr -> Solver.status + + (** 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. *) + val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status + + (** Creates a backtracking point. + {!pop} *) + val push : fixedpoint -> unit + + (** Backtrack one backtracking point. + + Note that an exception is thrown if Pop is called without a corresponding Push + {!push} *) + val pop : fixedpoint -> unit + + (** Update named rule into in the fixedpoint solver. *) + val update_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol -> unit + + (** Retrieve satisfying instance or instances of solver, + or definitions for the recursive predicates that show unsatisfiability. *) + val get_answer : fixedpoint -> Expr.expr option + + (** Retrieve explanation why fixedpoint engine returned status Unknown. *) + val get_reason_unknown : fixedpoint -> string + + (** Retrieve the number of levels explored for a given predicate. *) + val get_num_levels : fixedpoint -> FuncDecl.func_decl -> int + + (** Retrieve the cover of a predicate. *) + val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option + + (** Add property about the predicate. + The property is added at level. *) + val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit + + (** Retrieve internal string representation of fixedpoint object. *) + val to_string : fixedpoint -> string + + (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) + val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol list -> unit + + (** Convert benchmark given as set of axioms, rules and queries to a string. *) + val to_string_q : fixedpoint -> Boolean.bool_expr list -> string + + (** Retrieve set of rules added to fixedpoint context. *) + val get_rules : fixedpoint -> Boolean.bool_expr list + + (** Retrieve set of assertions added to fixedpoint context. *) + val get_assertions : fixedpoint -> Boolean.bool_expr list + + (** Create a Fixedpoint context. *) + val mk_fixedpoint : context -> fixedpoint +end + +(** Global and context options + + Note: This module contains functions that set parameters/options for context + objects as well as functions that set options that are used globally, across + contexts.*) +module Options : +sig + (** 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. + {!get_param_value} *) + val update_param_value : context -> string -> string -> unit + + (** Get a configuration parameter. + + Returns None if the parameter value does not exist. + {!update_param_value} *) + val get_param_value : context -> string -> string option + + (** 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + {!AST.to_string} + {!Quantifier.Pattern.to_string} + {!FuncDecl.to_string} + {!Sort.to_string} *) + val set_print_mode : context -> Z3enums.ast_print_mode -> unit + + (** Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) + val toggle_warning_messages : bool -> unit +end + +(** Functions for handling SMT and SMT2 expressions and files *) +module SMT : +sig + (** Convert a benchmark into an SMT-LIB formatted string. + + @return A string representation of the benchmark. *) + val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr list -> Boolean.bool_expr -> string + + (** 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 in the third and fifth argument + don't need to match the names of the sorts and declarations in the arrays in the fourth + and sixth argument. This is a useful feature since we can use arbitrary names to + reference sorts and declarations. *) + val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit + + (** Parse the given file using the SMT-LIB parser. + {!parse_smtlib_string} *) + val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit + + (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_formulas : context -> int + + (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_formulas : context -> Boolean.bool_expr list + + (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_assumptions : context -> int + + (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_assumptions : context -> Boolean.bool_expr list + + (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_decls : context -> int + + (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_decls : context -> FuncDecl.func_decl list + + (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_num_smtlib_sorts : context -> int + + (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + val get_smtlib_sorts : context -> Sort.sort list + + (** Parse the given string using the SMT-LIB2 parser. + + {!parse_smtlib_string} + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) + val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr + + (** Parse the given file using the SMT-LIB2 parser. + {!parse_smtlib2_string} *) + val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr +end + +(** Set a global (or module) parameter, which is shared by all Z3 contexts. + + When a Z3 module is initialized it will use the value of these parameters + when Z3_params objects are not provided. + The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. + The character '.' is a delimiter (more later). + The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. + Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". + This function can be used to set parameters for a specific Z3 module. + This can be done by using .. + For example: + (set_global_param "pp.decimal" "true") + will set the parameter "decimal" in the module "pp" to true. +*) +val set_global_param : string -> string -> unit + +(** Get a global (or module) parameter. + + Returns None if the parameter does not exist. + The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. + This function cannot be invoked simultaneously from different threads without synchronization. + The result string stored in param_value is stored in a shared location. +*) +val get_global_param : string -> string option + +(** Restore the value of all global (and module) parameters. + + This command will not affect already created objects (such as tactics and solvers) + {!set_global_param} +*) +val global_param_reset_all : unit From eea13a087f0caec61ec1ef3235944921a07b97e3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 21 Feb 2013 14:17:35 +0000 Subject: [PATCH 184/248] ML API savegame Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 124 +++++++++++++++++++------------------- src/api/ml/z3.ml | 18 +++--- src/api/ml/z3.mli | 23 ++++--- src/api/ml/z3_rich.ml | 43 +++++++------ src/api/ml/z3_rich.mli | 13 ++-- 5 files changed, 107 insertions(+), 114 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 823a08fe2..f7a4cbc00 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -162,70 +162,68 @@ let basic_tests ( ctx : context ) = else Printf.printf "Test passed.\n" ) ; - model_converter_test ctx -(* - // Real num/den test. - RatNum rn = ctx.MkReal(42, 43); - Expr inum = rn.Numerator; - Expr iden = rn.Denominator; - Console.WriteLine("Numerator: " + inum + " Denominator: " + iden); - if (inum.ToString() != "42" || iden.ToString() != "43") - throw new TestFailedException(); - - if (rn.ToDecimalString(3) != "0.976?") - throw new TestFailedException(); - - BigIntCheck(ctx, ctx.MkReal("-1231231232/234234333")); - BigIntCheck(ctx, ctx.MkReal("-123123234234234234231232/234234333")); - BigIntCheck(ctx, ctx.MkReal("-234234333")); - BigIntCheck(ctx, ctx.MkReal("234234333/2")); - - - string bn = "1234567890987654321"; - - if (ctx.MkInt(bn).BigInteger.ToString() != bn) - throw new TestFailedException(); - - if (ctx.MkBV(bn, 128).BigInteger.ToString() != bn) - throw new TestFailedException(); - - if (ctx.MkBV(bn, 32).BigInteger.ToString() == bn) - throw new TestFailedException(); - - // Error handling test. - try - { - IntExpr i = ctx.MkInt("1/2"); - throw new TestFailedException(); // unreachable - } - catch (Z3Exception) - { - } - } -*) + model_converter_test ctx ; + (* Real num/den test. *) + let rn = Real.mk_numeral_nd ctx 42 43 in + let inum = (get_numerator rn) in + let iden = get_denominator rn in + Printf.printf "Numerator: %s Denominator: %s\n" (Real.to_string inum) (Real.to_string iden) ; + if ((Real.to_string inum) <> "42" or (Real.to_string iden) <> "43") then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ; + if ((to_decimal_string rn 3) <> "0.976?") then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ; + if (to_decimal_string (Real.mk_numeral_s ctx "-1231231232/234234333") 5 <> "-5.25640?") then + raise (TestFailedException "") + else if (to_decimal_string (Real.mk_numeral_s ctx "-123123234234234234231232/234234333") 5 <> "-525641278361333.28170?") then + raise (TestFailedException "") + else if (to_decimal_string (Real.mk_numeral_s ctx "-234234333") 5 <> "-234234333") then + raise (TestFailedException "") + else if (to_decimal_string (Real.mk_numeral_s ctx "234234333/2") 5 <> "117117166.5") then + raise (TestFailedException "") + ; + (* Error handling test. *) + try ( + let i = Integer.mk_numeral_s ctx "1/2" in + raise (TestFailedException "") (* unreachable *) + ) + with Z3native.Exception(_) -> ( + Printf.printf "Exception caught, OK.\n" + ) let _ = - if not (Log.open_ "z3.log") then - raise (TestFailedException "Log couldn't be opened.") - else - ( - Printf.printf "Running Z3 version %s\n" Version.to_string ; - let cfg = [("model", "true"); ("proof", "false")] in - let ctx = (mk_context cfg) in - let is = (Symbol.mk_int ctx 42) in - let ss = (Symbol.mk_string ctx "mySymbol") in - let bs = (Boolean.mk_sort ctx) in - let ints = (Integer.mk_sort ctx) in - let rs = (Real.mk_sort ctx) in - Printf.printf "int symbol: %s\n" (Symbol.to_string is); - Printf.printf "string symbol: %s\n" (Symbol.to_string ss); - Printf.printf "bool sort: %s\n" (Sort.to_string bs); - Printf.printf "int sort: %s\n" (Sort.to_string ints); - Printf.printf "real sort: %s\n" (Sort.to_string rs); - basic_tests ctx ; - Printf.printf "Disposing...\n"; - Gc.full_major () - ); - Printf.printf "Exiting.\n"; + try ( + if not (Log.open_ "z3.log") then + raise (TestFailedException "Log couldn't be opened.") + else + ( + Printf.printf "Running Z3 version %s\n" Version.to_string ; + let cfg = [("model", "true"); ("proof", "false")] in + let ctx = (mk_context cfg) in + let is = (Symbol.mk_int ctx 42) in + let ss = (Symbol.mk_string ctx "mySymbol") in + let bs = (Boolean.mk_sort ctx) in + let ints = (Integer.mk_sort ctx) in + let rs = (Real.mk_sort ctx) in + Printf.printf "int symbol: %s\n" (Symbol.to_string is); + Printf.printf "string symbol: %s\n" (Symbol.to_string ss); + Printf.printf "bool sort: %s\n" (Sort.to_string bs); + Printf.printf "int sort: %s\n" (Sort.to_string ints); + Printf.printf "real sort: %s\n" (Sort.to_string rs); + basic_tests ctx ; + Printf.printf "Disposing...\n"; + Gc.full_major () + ); + Printf.printf "Exiting.\n" ; + exit 0 + ) with Z3native.Exception(msg) -> ( + Printf.printf "Z3 EXCEPTION: %s\n" msg ; + exit 1 + ) ;; diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 0676f1a39..e62732924 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -11,7 +11,6 @@ open Z3enums let null = Z3native.mk_null() let is_null o = (Z3native.is_null o) - (* Internal types *) type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } type context = z3_native_context @@ -21,7 +20,6 @@ type z3_native_object = { mutable m_n_obj : Z3native.ptr ; inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - (** Internal stuff *) module Internal = @@ -1455,11 +1453,11 @@ struct let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) - let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = Expr.mk_const ctx name (mk_sort ctx) - let mk_int_const_s ( ctx : context ) ( name : string ) = - mk_int_const ctx (Symbol.mk_string ctx name) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) let mk_mod ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) @@ -1467,10 +1465,10 @@ struct let mk_rem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) - let mk_int_numeral_s ( ctx : context ) ( v : string ) = + let mk_numeral_s ( ctx : context ) ( v : string ) = expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx))) - let mk_int_numeral_i ( ctx : context ) ( v : int ) = + let mk_numeral_i ( ctx : context ) ( v : int ) = expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno (mk_sort ctx))) let mk_int2real ( ctx : context ) ( t : expr ) = @@ -1496,11 +1494,11 @@ struct let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) - let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = Expr.mk_const ctx name (mk_sort ctx) - let mk_real_const_s ( ctx : context ) ( name : string ) = - mk_real_const ctx (Symbol.mk_string ctx name) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = if (den == 0) then diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 908b3023d..d7e179cd4 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -30,7 +30,6 @@ type context (** Create a context object *) val mk_context : (string * string) list -> context - (** 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. *) @@ -1117,10 +1116,10 @@ sig end (** Functions to manipulate arithmetic expressions *) -module rec Arithmetic : +module Arithmetic : sig (** Integer Arithmetic *) - module rec Integer : + module Integer : sig (** Create a new integer sort. *) val mk_sort : context -> Sort.sort @@ -1132,10 +1131,10 @@ sig val to_string : Expr.expr -> string (** Creates an integer constant. *) - val mk_int_const : context -> Symbol.symbol -> Expr.expr + val mk_const : context -> Symbol.symbol -> Expr.expr (** Creates an integer constant. *) - val mk_int_const_s : context -> string -> Expr.expr + val mk_const_s : context -> string -> Expr.expr (** Create an expression representing t1 mod t2. The arguments must have int type. *) @@ -1146,11 +1145,11 @@ sig val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an integer numeral. *) - val mk_int_numeral_s : context -> string -> Expr.expr + val mk_numeral_s : context -> string -> Expr.expr (** Create an integer numeral. @return A Term with the given value and sort Integer *) - val mk_int_numeral_i : context -> int -> Expr.expr + val mk_numeral_i : context -> int -> Expr.expr (** Coerce an integer to a real. @@ -1174,7 +1173,7 @@ sig end (** Real Arithmetic *) - and Real : + module Real : sig (** Create a real sort. *) val mk_sort : context -> Sort.sort @@ -1193,10 +1192,10 @@ sig val to_string : Expr.expr-> string (** Creates a real constant. *) - val mk_real_const : context -> Symbol.symbol -> Expr.expr + val mk_const : context -> Symbol.symbol -> Expr.expr (** Creates a real constant. *) - val mk_real_const_s : context -> string -> Expr.expr + val mk_const_s : context -> string -> Expr.expr (** Create a real numeral from a fraction. @return A Term with rational value and sort Real @@ -1222,7 +1221,7 @@ sig end (** Algebraic Numbers *) - and AlgebraicNumber : + module AlgebraicNumber : sig (** Return a upper bound for a given real algebraic number. The interval isolating the number is smaller than 1/10^precision. @@ -1339,7 +1338,7 @@ sig end (** Functions to manipulate bit-vector expressions *) -and BitVector : +module BitVector : sig (** Create a new bit-vector sort. *) val mk_sort : context -> int -> Sort.sort diff --git a/src/api/ml/z3_rich.ml b/src/api/ml/z3_rich.ml index 052ca5e22..0c2f95b6b 100644 --- a/src/api/ml/z3_rich.ml +++ b/src/api/ml/z3_rich.ml @@ -1,4 +1,4 @@ -(** +\(** The Z3 ML/Ocaml Interface. Copyright (C) 2012 Microsoft Corporation @@ -11,7 +11,6 @@ open Z3enums let null = Z3native.mk_null() let is_null o = (Z3native.is_null o) - (* Internal types *) type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } type context = z3_native_context @@ -1679,12 +1678,12 @@ sig val mk_sort : context -> int_sort val get_int : int_num -> int val to_string : int_num -> string - val mk_int_const : context -> Symbol.symbol -> int_expr - val mk_int_const_s : context -> string -> int_expr + val mk_const : context -> Symbol.symbol -> int_expr + val mk_const_s : context -> string -> int_expr val mk_mod : context -> int_expr -> int_expr -> int_expr val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_int_numeral_s : context -> string -> int_num - val mk_int_numeral_i : context -> int -> int_num + val mk_numeral_s : context -> string -> int_num + val mk_numeral_i : context -> int -> int_num val mk_int2real : context -> int_expr -> Real.real_expr val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr end @@ -1709,8 +1708,8 @@ sig val get_denominator : rat_num -> Integer.int_num val to_decimal_string : rat_num -> int -> string val to_string : rat_num -> string - val mk_real_const : context -> Symbol.symbol -> real_expr - val mk_real_const_s : context -> string -> real_expr + val mk_const : context -> Symbol.symbol -> real_expr + val mk_const_s : context -> string -> real_expr val mk_numeral_nd : context -> int -> int -> rat_num val mk_numeral_s : context -> string -> rat_num val mk_numeral_i : context -> int -> rat_num @@ -1816,12 +1815,12 @@ end = struct val mk_sort : context -> int_sort val get_int : int_num -> int val to_string : int_num -> string - val mk_int_const : context -> Symbol.symbol -> int_expr - val mk_int_const_s : context -> string -> int_expr + val mk_const : context -> Symbol.symbol -> int_expr + val mk_const_s : context -> string -> int_expr val mk_mod : context -> int_expr -> int_expr -> int_expr val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_int_numeral_s : context -> string -> int_num - val mk_int_numeral_i : context -> int -> int_num + val mk_numeral_s : context -> string -> int_num + val mk_numeral_i : context -> int -> int_num val mk_int2real : context -> int_expr -> Real.real_expr val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr end = struct @@ -1884,11 +1883,11 @@ end = struct let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - let mk_int_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) - let mk_int_const_s ( ctx : context ) ( name : string ) = - mk_int_const ctx (Symbol.mk_string ctx name) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) @@ -1896,10 +1895,10 @@ end = struct let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) - let mk_int_numeral_s ( ctx : context ) ( v : string ) = + let mk_numeral_s ( ctx : context ) ( v : string ) = int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - let mk_int_numeral_i ( ctx : context ) ( v : int ) = + let mk_numeral_i ( ctx : context ) ( v : int ) = int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) let mk_int2real ( ctx : context ) ( t : int_expr ) = @@ -1930,8 +1929,8 @@ end = struct val get_denominator : rat_num -> Integer.int_num val to_decimal_string : rat_num -> int -> string val to_string : rat_num -> string - val mk_real_const : context -> Symbol.symbol -> real_expr - val mk_real_const_s : context -> string -> real_expr + val mk_const : context -> Symbol.symbol -> real_expr + val mk_const_s : context -> string -> real_expr val mk_numeral_nd : context -> int -> int -> rat_num val mk_numeral_s : context -> string -> rat_num val mk_numeral_i : context -> int -> rat_num @@ -2002,11 +2001,11 @@ end = struct let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - let mk_real_const ( ctx : context ) ( name : Symbol.symbol ) = + let mk_const ( ctx : context ) ( name : Symbol.symbol ) = RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) - let mk_real_const_s ( ctx : context ) ( name : string ) = - mk_real_const ctx (Symbol.mk_string ctx name) + let mk_const_s ( ctx : context ) ( name : string ) = + mk_const ctx (Symbol.mk_string ctx name) let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = if (den == 0) then diff --git a/src/api/ml/z3_rich.mli b/src/api/ml/z3_rich.mli index 8b6681e11..f2ecd326d 100644 --- a/src/api/ml/z3_rich.mli +++ b/src/api/ml/z3_rich.mli @@ -34,7 +34,6 @@ type context (** Create a context object *) val mk_context : (string * string) list -> context - (** 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. *) @@ -1219,10 +1218,10 @@ sig val to_string : int_num -> string (** Creates an integer constant. *) - val mk_int_const : context -> Symbol.symbol -> int_expr + val mk_const : context -> Symbol.symbol -> int_expr (** Creates an integer constant. *) - val mk_int_const_s : context -> string -> int_expr + val mk_const_s : context -> string -> int_expr (** Create an expression representing t1 mod t2. The arguments must have int type. *) @@ -1233,11 +1232,11 @@ sig val mk_rem : context -> int_expr -> int_expr -> int_expr (** Create an integer numeral. *) - val mk_int_numeral_s : context -> string -> int_num + val mk_numeral_s : context -> string -> int_num (** Create an integer numeral. @return A Term with the given value and sort Integer *) - val mk_int_numeral_i : context -> int -> int_num + val mk_numeral_i : context -> int -> int_num (** Coerce an integer to a real. @@ -1291,10 +1290,10 @@ sig val to_string : rat_num -> string (** Creates a real constant. *) - val mk_real_const : context -> Symbol.symbol -> real_expr + val mk_const : context -> Symbol.symbol -> real_expr (** Creates a real constant. *) - val mk_real_const_s : context -> string -> real_expr + val mk_const_s : context -> string -> real_expr (** Create a real numeral from a fraction. @return A Term with rational value and sort Real From 050629536ab7e195bb1fe076e77e8c4043d563bb Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 21 Feb 2013 18:53:29 +0000 Subject: [PATCH 185/248] ML API: bugfix Signed-off-by: Christoph M. Wintersteiger --- examples/ml/Makefile | 4 ++-- scripts/update_api.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/ml/Makefile b/examples/ml/Makefile index a7f8e6ee0..818f0cacc 100644 --- a/examples/ml/Makefile +++ b/examples/ml/Makefile @@ -3,5 +3,5 @@ # in the top-level build directory. all: - OCAML_COMPAT=c C:/ocamlw32/bin/ocamlc -g -annot -o ml_example.byte -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cma ml_example.ml - C:/ocamlw32/bin/ocamlopt -g -annot -o ml_example -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cmxa ml_example.ml + source /cygdrive/c/cwinter/.msenv32 ; OCAML_COMPAT=c C:/ocamlw32/bin/ocamlc -g -custom -cclib '-L../../bld_dbg -lz3' -annot -o ml_example.byte -I ../../bld_dbg/api/ml z3.cma ml_example.ml + source /cygdrive/c/cwinter/.msenv32 ; C:/ocamlw32/bin/ocamlopt -g -annot -o ml_example -cclib '-L../../bld_dbg -lz3' -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cmxa ml_example.ml diff --git a/scripts/update_api.py b/scripts/update_api.py index a0b7e6250..44d871348 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1339,9 +1339,10 @@ def mk_ml(): ml_wrapper.write(' // upon errors, but the actual error handling is done by throwing exceptions in the\n') ml_wrapper.write(' // wrappers below.\n') ml_wrapper.write('}\n\n') - ml_wrapper.write('void n_set_internal_error_handler(Z3_context c)\n') + ml_wrapper.write('void n_set_internal_error_handler(value a0)\n') ml_wrapper.write('{\n') - ml_wrapper.write(' Z3_set_error_handler(c, MLErrorHandler);\n') + ml_wrapper.write(' Z3_context _a0 = * (Z3_context*) Data_custom_val(a0);\n') + ml_wrapper.write(' Z3_set_error_handler(_a0, MLErrorHandler);\n') ml_wrapper.write('}\n\n') for name, result, params in _dotnet_decls: ip = inparams(params) From c1e29dabe7858fbbf9eb112028c010d18f4b666c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 26 Feb 2013 19:45:45 +0000 Subject: [PATCH 186/248] ML API: renamed assert_ to add Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 24 ++++++++++++------------ src/api/ml/z3.ml | 8 ++++---- src/api/ml/z3.mli | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index f7a4cbc00..c9ed1d948 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -29,11 +29,11 @@ let model_converter_test ( ctx : context ) = let xr = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Real.mk_sort ctx)) in let yr = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Real.mk_sort ctx)) in let g4 = (mk_goal ctx true false false ) in - (Goal.assert_ g4 [ (mk_gt ctx xr (Real.mk_numeral_nd ctx 10 1)) ]) ; - (Goal.assert_ g4 [ (mk_eq ctx + (Goal.add g4 [ (mk_gt ctx xr (Real.mk_numeral_nd ctx 10 1)) ]) ; + (Goal.add g4 [ (mk_eq ctx yr (Arithmetic.mk_add ctx [ xr; (Real.mk_numeral_nd ctx 1 1) ])) ]) ; - (Goal.assert_ g4 [ (mk_gt ctx yr (Real.mk_numeral_nd ctx 1 1)) ]) ; + (Goal.add g4 [ (mk_gt ctx yr (Real.mk_numeral_nd ctx 1 1)) ]) ; ( let ar = (Tactic.apply (mk_tactic ctx "simplify") g4 None) in if ((get_num_subgoals ar) == 1 && @@ -53,7 +53,7 @@ let model_converter_test ( ctx : context ) = Printf.printf "Test passed.\n" ; let solver = (mk_solver ctx None) in - let f e = (Solver.assert_ solver [ e ]) in + let f e = (Solver.add solver [ e ]) in ignore (List.map f (get_formulas (get_subgoal ar 0))) ; let q = (check solver []) in if q != SATISFIABLE then @@ -88,12 +88,12 @@ let basic_tests ( ctx : context ) = let trivial_eq = (mk_eq ctx fapp fapp) in let nontrivial_eq = (mk_eq ctx fapp fapp2) in let g = (mk_goal ctx true false false) in - (Goal.assert_ g [ trivial_eq ]) ; - (Goal.assert_ g [ nontrivial_eq ]) ; + (Goal.add g [ trivial_eq ]) ; + (Goal.add g [ nontrivial_eq ]) ; Printf.printf "%s\n" ("Goal: " ^ (Goal.to_string g)) ; ( let solver = (mk_solver ctx None) in - (List.iter (fun a -> (Solver.assert_ solver [ a ])) (get_formulas g)) ; + (List.iter (fun a -> (Solver.add solver [ a ])) (get_formulas g)) ; if (check solver []) != SATISFIABLE then raise (TestFailedException "") else @@ -116,7 +116,7 @@ let basic_tests ( ctx : context ) = else Printf.printf "Test passed.\n" ); - (Goal.assert_ g [ (mk_eq ctx + (Goal.add g [ (mk_eq ctx (mk_numeral_int ctx 1 (BitVector.mk_sort ctx 32)) (mk_numeral_int ctx 2 (BitVector.mk_sort ctx 32))) ] ) ; @@ -139,7 +139,7 @@ let basic_tests ( ctx : context ) = ); ( let g2 = (mk_goal ctx true true false) in - (Goal.assert_ g2 [ (Boolean.mk_false ctx) ]) ; + (Goal.add g2 [ (Boolean.mk_false ctx) ]) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g2 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then @@ -151,10 +151,10 @@ let basic_tests ( ctx : context ) = let g3 = (mk_goal ctx true true false) in let xc = (Expr.mk_const ctx (Symbol.mk_string ctx "x") (Integer.mk_sort ctx)) in let yc = (Expr.mk_const ctx (Symbol.mk_string ctx "y") (Integer.mk_sort ctx)) in - (Goal.assert_ g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (Integer.mk_sort ctx))) ]) ; - (Goal.assert_ g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (Integer.mk_sort ctx))) ]) ; + (Goal.add g3 [ (mk_eq ctx xc (mk_numeral_int ctx 1 (Integer.mk_sort ctx))) ]) ; + (Goal.add g3 [ (mk_eq ctx yc (mk_numeral_int ctx 2 (Integer.mk_sort ctx))) ]) ; let constr = (mk_eq ctx xc yc) in - (Goal.assert_ g3 [ constr ] ) ; + (Goal.add g3 [ constr ] ) ; let ar = (Tactic.apply (mk_tactic ctx "smt") g3 None) in if ((get_num_subgoals ar) == 1 && (not (is_decided_unsat (get_subgoal ar 0)))) then diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index e62732924..8eb5427bb 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1850,7 +1850,7 @@ struct let is_garbage ( x : goal ) = (get_precision x) == GOAL_UNDER_OVER - let assert_ ( x : goal ) ( constraints : expr list ) = + let add ( x : goal ) ( constraints : expr list ) = let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e) in ignore (List.map f constraints) ; () @@ -2370,11 +2370,11 @@ struct let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - let assert_ ( x : solver ) ( constraints : expr list ) = + let add ( x : solver ) ( constraints : expr list ) = let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in ignore (List.map f constraints) - let assert_and_track_a ( x : solver ) ( cs : expr list ) ( ps : expr list ) = + let assert_and_track_l ( x : solver ) ( cs : expr list ) ( ps : expr list ) = if ((List.length cs) != (List.length ps)) then raise (Z3native.Exception "Argument size mismatch") else @@ -2473,7 +2473,7 @@ struct let get_param_descrs ( x : fixedpoint ) = Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - let assert_ ( x : fixedpoint ) ( constraints : expr list ) = + let add ( x : fixedpoint ) ( constraints : expr list ) = let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Expr.gno e)) in ignore (List.map f constraints) ; () diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index d7e179cd4..cde99a90d 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -2221,7 +2221,7 @@ sig val is_garbage : goal -> bool (** Adds the constraints to the given goal. *) - val assert_ : goal -> Expr.expr list -> unit + val add : goal -> Expr.expr list -> unit (** Indicates whether the goal contains `false'. *) val is_inconsistent : goal -> bool @@ -2648,7 +2648,7 @@ sig val reset : solver -> unit (** Assert a constraint (or multiple) into the solver. *) - val assert_ : solver -> Expr.expr list -> unit + val add : solver -> Expr.expr list -> unit (** * Assert multiple constraints (cs) into the solver, and track them (in the * unsat) core @@ -2661,7 +2661,7 @@ sig * of the Boolean variables provided using {!assert_and_track} * and the Boolean literals * provided using {!check} with assumptions. *) - val assert_and_track_a : solver -> Expr.expr list -> Expr.expr list -> unit + val assert_and_track_l : solver -> Expr.expr list -> Expr.expr list -> unit (** * Assert a constraint (c) into the solver, and track it (in the unsat) core * using the Boolean constant p. @@ -2752,7 +2752,7 @@ sig val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs (** Assert a constraints into the fixedpoint solver. *) - val assert_ : fixedpoint -> Expr.expr list -> unit + val add : fixedpoint -> Expr.expr list -> unit (** Register predicate as recursive relation. *) val register_relation : fixedpoint -> FuncDecl.func_decl -> unit From aaa835484f5db085b3e8bac7df6e15ba7bd7f0b3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 3 Jun 2013 18:51:40 +0100 Subject: [PATCH 187/248] Updates to ML API. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 43 ++++++++-------- src/api/ml/z3.mli | 126 ++++++++++++++++++++++++---------------------- 2 files changed, 86 insertions(+), 83 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 8eb5427bb..4a8fbaa0a 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -323,8 +323,8 @@ struct else ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + let unwrap_ast ( x : ast ) = (z3obj_gno x) let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr - let unwrap_ast ( x : ast ) = (z3obj_gno x) end open AST @@ -678,6 +678,19 @@ end = struct res let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) + + let update_param_value ( ctx : context ) ( id : string) ( value : string )= + Z3native.update_param_value (context_gno ctx) id value + + let get_param_value ( ctx : context ) ( id : string ) = + let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in + if not r then + None + else + Some v + + let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = + Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) end (** General expressions (terms) *) @@ -1106,7 +1119,7 @@ struct end -module Array_ = +module Array = struct let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) @@ -1389,7 +1402,7 @@ struct end -module List_ = +module List = struct let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = let (r, _, _, _, _, _, _) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in @@ -2558,26 +2571,6 @@ struct let mk_fixedpoint ( ctx : context ) = create ctx end -module Options = -struct - - let update_param_value ( ctx : context ) ( id : string) ( value : string )= - Z3native.update_param_value (context_gno ctx) id value - - let get_param_value ( ctx : context ) ( id : string ) = - let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in - if not r then - None - else - Some v - - let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = - Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) - - let toggle_warning_messages ( enabled: bool ) = - Z3native.toggle_warning_messages enabled -end - module SMT = struct @@ -2692,3 +2685,7 @@ let get_global_param ( id : string ) = let global_param_reset_all = Z3native.global_param_reset_all + +let toggle_warning_messages ( enabled: bool ) = + Z3native.toggle_warning_messages enabled + diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index cde99a90d..1c4c4e922 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -27,7 +27,20 @@ *) type context -(** Create a context object *) +(** Create a context object + The following parameters can be set: + + - proof (Boolean) Enable proof generation + - debug_ref_count (Boolean) Enable debug support for Z3_ast reference counting + - trace (Boolean) Tracing support for VCC + - trace_file_name (String) Trace out file for VCC traces + - timeout (unsigned) default timeout (in milliseconds) used for solvers + - well_sorted_check type checker + - auto_config use heuristics to automatically select solver and configure it + - model model generation for solvers, this parameter can be overwritten when creating a solver + - model_validate validate models produced by solvers + - unsat_core unsat-core generation for solvers, this parameter can be overwritten when creating a solver +*) val mk_context : (string * string) list -> context (** Interaction logging for Z3 @@ -220,15 +233,6 @@ sig @return A copy of the AST which is associated with the other context. *) val translate : ast -> context -> ast - (** Wraps an AST. - - This function is used for transitions between native and - managed objects. Note that the native ast that is passed must be a - native object obtained from Z3 (e.g., through {!unwrap_ast}) - and that it must have a correct reference count (see e.g., - Z3native.inc_ref). *) - val wrap_ast : context -> Z3native.z3_ast -> ast - (** Unwraps an AST. This function is used for transitions between native and managed objects. It returns the native pointer to the AST. Note that @@ -238,6 +242,15 @@ sig Z3native.inc_ref). {!wrap_ast} *) val unwrap_ast : ast -> Z3native.ptr + + (** Wraps an AST. + + This function is used for transitions between native and + managed objects. Note that the native ast that is passed must be a + native object obtained from Z3 (e.g., through {!unwrap_ast}) + and that it must have a correct reference count (see e.g., + Z3native.inc_ref). *) + val wrap_ast : context -> Z3native.z3_ast -> ast end (** The Sort module implements type information for ASTs *) @@ -432,6 +445,36 @@ sig (** A string representation of the parameter set. *) val to_string : params -> string + + (** Update a mutable configuration parameter. + + The list of all configuration parameters can be obtained using the Z3 executable: + z3.exe -p + Only a few configuration parameters are mutable once the context is created. + An exception is thrown when trying to modify an immutable parameter. + {!get_param_value} *) + val update_param_value : context -> string -> string -> unit + + (** Get a configuration parameter. + + Returns None if the parameter value does not exist. + {!update_param_value} *) + val get_param_value : context -> string -> string option + + (** 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + {!AST.to_string} + {!Quantifier.Pattern.to_string} + {!FuncDecl.to_string} + {!Sort.to_string} *) + val set_print_mode : context -> Z3enums.ast_print_mode -> unit end (** General Expressions (terms) *) @@ -737,7 +780,7 @@ sig end (** Functions to manipulate Array expressions *) -module Array_ : +module Array : sig (** Create a new array sort. *) val mk_sort : context -> Sort.sort -> Sort.sort -> Sort.sort @@ -790,7 +833,7 @@ sig The node a must have an array sort [domain -> range], and i must have the sort domain. The sort of the result is range. - {!Array_.mk_sort} + {!Array.mk_sort} {!mk_store} *) val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -806,7 +849,7 @@ sig 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). - {!Array_.mk_sort} + {!Array.mk_sort} {!mk_select} *) val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr @@ -814,7 +857,7 @@ sig The resulting term is an array, such that a selecton an arbitrary index produces the value v. - {!Array_.mk_sort} + {!Array.mk_sort} {!mk_select} *) val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr @@ -823,7 +866,7 @@ sig 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]. - {!Array_.mk_sort} + {!Array.mk_sort} {!mk_select} {!mk_store} *) val mk_map : context -> FuncDecl.func_decl -> Expr.expr list -> Expr.expr @@ -1069,7 +1112,7 @@ sig end (** Functions to manipulate List expressions *) -module List_ : +module List : sig (** Create a new list sort. *) val mk_sort : context -> Symbol.symbol -> Sort.sort -> Sort.sort @@ -2824,50 +2867,6 @@ sig val mk_fixedpoint : context -> fixedpoint end -(** Global and context options - - Note: This module contains functions that set parameters/options for context - objects as well as functions that set options that are used globally, across - contexts.*) -module Options : -sig - (** 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. - {!get_param_value} *) - val update_param_value : context -> string -> string -> unit - - (** Get a configuration parameter. - - Returns None if the parameter value does not exist. - {!update_param_value} *) - val get_param_value : context -> string -> string option - - (** 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 PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - {!AST.to_string} - {!Quantifier.Pattern.to_string} - {!FuncDecl.to_string} - {!Sort.to_string} *) - val set_print_mode : context -> Z3enums.ast_print_mode -> unit - - (** Enable/disable printing of warning messages to the console. - - Note that this function is static and effects the behaviour of - all contexts globally. *) - val toggle_warning_messages : bool -> unit -end - (** Functions for handling SMT and SMT2 expressions and files *) module SMT : sig @@ -2954,4 +2953,11 @@ val get_global_param : string -> string option This command will not affect already created objects (such as tactics and solvers) {!set_global_param} *) + val global_param_reset_all : unit + + (** Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) + val toggle_warning_messages : bool -> unit From b81bae76b2ae554e4521cf65c5b71b4e3cfc0b58 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 3 Jun 2013 19:12:00 +0100 Subject: [PATCH 188/248] ML API: refactoring Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 74 +++++++++++------------------ src/api/ml/z3.mli | 115 +++++++++++++++++++--------------------------- 2 files changed, 73 insertions(+), 116 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 4a8fbaa0a..081433f1f 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -7,6 +7,8 @@ open Z3enums +exception Error = Z3native.Exception + (* Some helpers. *) let null = Z3native.mk_null() let is_null o = (Z3native.is_null o) @@ -283,7 +285,7 @@ struct Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) end - let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) + let hash ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) @@ -304,7 +306,7 @@ struct let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - let ( = ) ( a : ast ) ( b : ast ) = (a == b) || + let equal ( a : ast ) ( b : ast ) = (a == b) || if (z3obj_gnc a) != (z3obj_gnc b) then false else @@ -314,8 +316,6 @@ struct if (get_id a) < (get_id b) then -1 else if (get_id a) > (get_id b) then 1 else 0 - - let ( < ) (a : ast) (b : ast) = (compare a b) let translate ( x : ast ) ( to_ctx : context ) = if (z3obj_gnc x) == (context_gno to_ctx) then @@ -361,7 +361,7 @@ struct let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in Array.of_list (List.map f a) - let ( = ) : sort -> sort -> bool = fun a b -> + let equal : sort -> sort -> bool = fun a b -> (a == b) || if (gnc a) != (gnc b) then false @@ -424,7 +424,7 @@ sig val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl val mk_const_decl_s : context -> string -> Sort.sort -> func_decl val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl - val ( = ) : func_decl -> func_decl -> bool + val equal : func_decl -> func_decl -> bool val to_string : func_decl -> string val get_id : func_decl -> int val get_arity : func_decl -> int @@ -498,7 +498,7 @@ end = struct let get_float ( x : parameter ) = match x with | P_Dbl(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a double") + | _ -> raise (Z3native.Exception "parameter is not a float") let get_symbol ( x : parameter ) = match x with @@ -545,7 +545,7 @@ end = struct create_pdr ctx prefix [] range - let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || + let equal ( a : func_decl ) ( b : func_decl ) = (a == b) || if (gnc a) != (gnc b) then false else @@ -605,12 +605,8 @@ sig end val add_bool : params -> Symbol.symbol -> bool -> unit val add_int : params -> Symbol.symbol -> int -> unit - val add_double : params -> Symbol.symbol -> float -> unit + val add_float : params -> Symbol.symbol -> float -> unit val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - val add_s_bool : params -> string -> bool -> unit - val add_s_int : params -> string -> int -> unit - val add_s_double : params -> string -> float -> unit - val add_s_symbol : params -> string -> Symbol.symbol -> unit val mk_params : context -> params val to_string : params -> string end = struct @@ -650,24 +646,12 @@ end = struct let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = + let add_float ( x : params ) ( name : Symbol.symbol ) ( value : float ) = Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) - let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = - add_bool x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_int ( x : params) ( name : string ) ( value : int ) = - add_int x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_double ( x : params ) ( name : string ) ( value : float ) = - add_double x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = - add_symbol x (Symbol.mk_string (z3obj_gc x) name) value - let mk_params ( ctx : context ) = let res : params = { m_ctx = ctx ; m_n_obj = null ; @@ -734,8 +718,6 @@ sig val is_xor : expr -> bool val is_not : expr -> bool val is_implies : expr -> bool - val is_label : expr -> bool - val is_label_lit : expr -> bool val is_oeq : expr -> bool val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val mk_const_s : context -> string -> Sort.sort -> expr @@ -857,8 +839,6 @@ end = struct let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = @@ -1530,20 +1510,20 @@ struct let mk_real2int ( ctx : context ) ( t : expr ) = (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (Expr.gno t))) - end - module AlgebraicNumber = - struct - let to_upper ( x : expr ) ( precision : int ) = - expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_upper (Expr.gnc x) (Expr.gno x) precision) - - let to_lower ( x : expr ) precision = - expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_lower (Expr.gnc x) (Expr.gno x) precision) - - let to_decimal_string ( x : expr ) ( precision : int ) = - Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + module AlgebraicNumber = + struct + let to_upper ( x : expr ) ( precision : int ) = + expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_upper (Expr.gnc x) (Expr.gno x) precision) + + let to_lower ( x : expr ) precision = + expr_of_ptr (Expr.gc x) (Z3native.get_algebraic_number_lower (Expr.gnc x) (Expr.gno x) precision) + + let to_decimal_string ( x : expr ) ( precision : int ) = + Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision + + let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + end end let is_int ( x : expr ) = @@ -2052,13 +2032,11 @@ struct let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in (mk_list f n_funcs) @ (mk_list g n_consts) - - exception ModelEvaluationFailedException of string - + let eval ( x : model ) ( t : expr ) ( completion : bool ) = let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in if not r then - raise (ModelEvaluationFailedException "evaluation failed") + None else expr_of_ptr (z3obj_gc x) v @@ -2353,7 +2331,7 @@ struct if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.create_sd k (Z3native.stats_get_float_value (z3obj_gnc x) (z3obj_gno x) i)) ) in mk_list f n diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 1c4c4e922..570ff8717 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -5,6 +5,11 @@ @author CM Wintersteiger (cwinter) 2012-12-17 *) +(** General Z3 exceptions + + Many functions in this API may throw an exception; if they do, it is this one.*) +exception Error + (** Context objects. Most interactions with Z3 are interpreted in some context; many users will only @@ -188,7 +193,7 @@ sig (** The AST's hash code. @return A hash code *) - val get_hash_code : ast -> int + val hash : ast -> int (** A unique identifier for the AST (unique among all ASTs). *) val get_id : ast -> int @@ -220,15 +225,12 @@ sig (** Comparison operator. @return True if the two ast's are from the same context and represent the same sort; false otherwise. *) - val ( = ) : ast -> ast -> bool + val equal : ast -> ast -> bool (** Object Comparison. @return Negative if the first ast should be sorted before the second, positive if after else zero. *) val compare : ast -> ast -> int - (** Operator < *) - val ( < ) : ast -> ast -> int - (** Translates (copies) the AST to another context. @return A copy of the AST which is associated with the other context. *) val translate : ast -> context -> ast @@ -263,7 +265,7 @@ sig (** Comparison operator. @return True if the two sorts are from the same context and represent the same sort; false otherwise. *) - val ( = ) : sort -> sort -> bool + val equal : sort -> sort -> bool (** Returns a unique identifier for the sort. *) val get_id : sort -> int @@ -310,7 +312,7 @@ sig (** The int value of the parameter.*) val get_int : parameter -> int - (** The double value of the parameter.*) + (** The float value of the parameter.*) val get_float : parameter -> float (** The Symbol.Symbol value of the parameter.*) @@ -351,7 +353,7 @@ sig (** Comparison operator. @return True if a and b are from the same context and represent the same func_decl; false otherwise. *) - val ( = ) : func_decl -> func_decl -> bool + val equal : func_decl -> func_decl -> bool (** A string representations of the function declaration. *) val to_string : func_decl -> string @@ -423,23 +425,11 @@ sig val add_int : params -> Symbol.symbol -> int -> unit (** Adds a parameter setting. *) - val add_double : params -> Symbol.symbol -> float -> unit + val add_float : params -> Symbol.symbol -> float -> unit (** Adds a parameter setting. *) val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - (** Adds a parameter setting. *) - val add_s_bool : params -> string -> bool -> unit - - (** Adds a parameter setting. *) - val add_s_int : params -> string -> int -> unit - - (** Adds a parameter setting. *) - val add_s_double : params -> string -> float -> unit - - (** Adds a parameter setting. *) - val add_s_symbol : params -> string -> Symbol.symbol -> unit - (** Creates a new parameter set *) val mk_params : context -> params @@ -583,16 +573,7 @@ sig (** Indicates whether the term is an implication *) val is_implies : Expr.expr -> bool - - (** 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. *) - val is_label : Expr.expr -> bool - - (** 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. - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) *) - val is_label_lit : Expr.expr -> bool - + (** 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. *) @@ -1261,29 +1242,29 @@ sig The semantics of this function follows the SMT-LIB standard for the function to_int. The argument must be of real sort. *) val mk_real2int : context -> Expr.expr -> Expr.expr - end - - (** Algebraic Numbers *) - module AlgebraicNumber : - sig - (** Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) - val to_upper : Expr.expr -> int -> Expr.expr - - (** Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) - val to_lower : Expr.expr -> int -> Expr.expr - - (** Returns a string representation in decimal notation. - The result has at most as many decimal places as the int argument provided.*) - val to_decimal_string : Expr.expr -> int -> string - - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr -> string + + (** Algebraic Numbers *) + module AlgebraicNumber : + sig + (** Return a upper bound for a given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) + val to_upper : Expr.expr -> int -> Expr.expr + + (** Return a lower bound for the given real algebraic number. + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) + val to_lower : Expr.expr -> int -> Expr.expr + + (** Returns a string representation in decimal notation. + The result has at most as many decimal places as the int argument provided.*) + val to_decimal_string : Expr.expr -> int -> string + + (** Returns a string representation of the numeral. *) + val to_string : Expr.expr -> string + end end (** Indicates whether the term is of integer sort. *) @@ -2389,19 +2370,16 @@ sig (** All symbols that have an interpretation in the model. *) val get_decls : model -> FuncDecl.func_decl list - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) - exception ModelEvaluationFailedException of string - (** Evaluates an expression in the current model. This function may fail if the argument contains quantifiers, is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. In this case a ModelEvaluationFailedException is thrown. *) - val eval : model -> Expr.expr -> bool -> Expr.expr + val eval : model -> Expr.expr -> bool -> Expr.expr option (** Alias for eval. *) - val evaluate : model -> Expr.expr -> bool -> Expr.expr + val evaluate : model -> Expr.expr -> bool -> Expr.expr option (** The number of uninterpreted sorts that the model has an interpretation for. *) val get_num_sorts : model -> int @@ -2438,7 +2416,7 @@ sig type probe (** Execute the probe over the goal. - A probe always produce a double value. + A probe always produce a float value. "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) val apply : probe -> Goal.goal -> float @@ -2637,7 +2615,7 @@ sig (** True if the entry is uint-valued. *) val is_int : statistics_entry -> bool - (** True if the entry is double-valued. *) + (** True if the entry is float-valued. *) val is_float : statistics_entry -> bool (** The string representation of the the entry's value. *) @@ -2954,10 +2932,11 @@ val get_global_param : string -> string option {!set_global_param} *) -val global_param_reset_all : unit - - (** Enable/disable printing of warning messages to the console. - - Note that this function is static and effects the behaviour of - all contexts globally. *) - val toggle_warning_messages : bool -> unit +val global_param_reset_all : unit -> unit + +(** Enable/disable printing of warning messages to the console. + + Note that this function is static and effects the behaviour of + all contexts globally. *) +val toggle_warning_messages : bool -> unit + From e40b69d97f2f75477c671cbb7551f3f7272ff224 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 4 Jun 2013 16:46:47 +0100 Subject: [PATCH 189/248] ML API: removing rich layer for now. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3_rich.ml | 3399 ---------------------------------------- src/api/ml/z3_rich.mli | 3071 ------------------------------------ 2 files changed, 6470 deletions(-) delete mode 100644 src/api/ml/z3_rich.ml delete mode 100644 src/api/ml/z3_rich.mli diff --git a/src/api/ml/z3_rich.ml b/src/api/ml/z3_rich.ml deleted file mode 100644 index 0c2f95b6b..000000000 --- a/src/api/ml/z3_rich.ml +++ /dev/null @@ -1,3399 +0,0 @@ -\(** - The Z3 ML/Ocaml Interface. - - Copyright (C) 2012 Microsoft Corporation - @author CM Wintersteiger (cwinter) 2012-12-17 -*) - -open Z3enums - -(* Some helpers. *) -let null = Z3native.mk_null() -let is_null o = (Z3native.is_null o) - -(* Internal types *) -type z3_native_context = { m_n_ctx : Z3native.z3_context; m_n_obj_cnt: int; } -type context = z3_native_context - -type z3_native_object = { - m_ctx : context ; - mutable m_n_obj : Z3native.ptr ; - inc_ref : Z3native.z3_context -> Z3native.ptr -> unit; - dec_ref : Z3native.z3_context -> Z3native.ptr -> unit } - - -(** Internal stuff *) -module Internal = -struct - let dispose_context ctx = - if ctx.m_n_obj_cnt == 0 then ( - (Z3native.del_context ctx.m_n_ctx) - ) else ( - Printf.printf "ERROR: NOT DISPOSING CONTEXT (because it still has %d objects alive)\n" ctx.m_n_obj_cnt; - ) - - let create_context settings = - let cfg = Z3native.mk_config in - let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in - (List.iter f settings) ; - let v = Z3native.mk_context_rc cfg in - Z3native.del_config(cfg) ; - Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; - Z3native.set_internal_error_handler v ; - let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in - let f = fun o -> dispose_context o in - Gc.finalise f res; - res - - let context_add1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt + 1) - let context_sub1 ctx = ignore (ctx.m_n_obj_cnt = ctx.m_n_obj_cnt - 1) - let context_gno ctx = ctx.m_n_ctx - - - let z3obj_gc o = o.m_ctx - let z3obj_gnc o = (context_gno o.m_ctx) - - let z3obj_gno o = o.m_n_obj - let z3obj_sno o ctx no = - (context_add1 ctx) ; - o.inc_ref (context_gno ctx) no ; - ( - if not (is_null o.m_n_obj) then - o.dec_ref (context_gno ctx) o.m_n_obj ; - (context_sub1 ctx) - ) ; - o.m_n_obj <- no - - let z3obj_dispose o = - if not (is_null o.m_n_obj) then - ( - o.dec_ref (z3obj_gnc o) o.m_n_obj ; - (context_sub1 (z3obj_gc o)) - ) ; - o.m_n_obj <- null - - let z3obj_create o = - let f = fun o -> (z3obj_dispose o) in - Gc.finalise f o - - let z3obj_nil_ref x y = () - - let z3_native_object_of_ast_ptr : context -> Z3native.ptr -> z3_native_object = fun ctx no -> - let res : z3_native_object = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res -end - -open Internal - -module Log = -struct - let open_ filename = ((lbool_of_int (Z3native.open_log filename)) == L_TRUE) - let close = Z3native.close_log - let append s = Z3native.append_log s -end - - -module Version = -struct - let major = let (x, _, _, _) = Z3native.get_version in x - let minor = let (_, x, _, _) = Z3native.get_version in x - let build = let (_, _, x, _) = Z3native.get_version in x - let revision = let (_, _, _, x) = Z3native.get_version in x - let to_string = - let (mj, mn, bld, rev) = Z3native.get_version in - string_of_int mj ^ "." ^ - string_of_int mn ^ "." ^ - string_of_int bld ^ "." ^ - string_of_int rev ^ "." -end - - -let mk_list ( f : int -> 'a ) ( n : int ) = - let rec mk_list' ( f : int -> 'a ) ( i : int ) ( n : int ) ( tail : 'a list ) : 'a list = - if (i >= n) then - tail - else - (mk_list' f (i+1) n ((f i) :: tail)) - in - mk_list' f 0 n [] - -let list_of_array ( x : _ array ) = - let f i = (Array.get x i) in - mk_list f (Array.length x) - -let mk_context ( cfg : ( string * string ) list ) = - create_context cfg - - -module Symbol = -struct - (* Symbol types *) - type int_symbol = z3_native_object - type string_symbol = z3_native_object - - type symbol = - | S_Int of int_symbol - | S_Str of string_symbol - - - let create_i ( ctx : context ) ( no : Z3native.ptr ) = - let res : int_symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let create_s ( ctx : context ) ( no : Z3native.ptr ) = - let res : string_symbol = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let create ( ctx : context ) ( no : Z3native.ptr ) = - match (symbol_kind_of_int (Z3native.get_symbol_kind (context_gno ctx) no)) with - | INT_SYMBOL -> S_Int (create_i ctx no) - | STRING_SYMBOL -> S_Str (create_s ctx no) - - let gc ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gc n) - | S_Str(n) -> (z3obj_gc n) - - let gnc ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gnc n) - | S_Str(n) -> (z3obj_gnc n) - - let gno ( x : symbol ) = - match x with - | S_Int(n) -> (z3obj_gno n) - | S_Str(n) -> (z3obj_gno n) - - let symbol_lton ( a : symbol list ) = - let f ( e : symbol ) = (gno e) in - Array.of_list (List.map f a) - - let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) - let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL - let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL - let get_int (o : int_symbol) = Z3native.get_symbol_int (z3obj_gnc o) (z3obj_gno o) - let get_string (o : string_symbol) = Z3native.get_symbol_string (z3obj_gnc o) (z3obj_gno o) - let to_string ( o : symbol ) = - match (kind o) with - | INT_SYMBOL -> (string_of_int (Z3native.get_symbol_int (gnc o) (gno o))) - | STRING_SYMBOL -> (Z3native.get_symbol_string (gnc o) (gno o)) - - let mk_int ( ctx : context ) ( i : int ) = - S_Int (create_i ctx (Z3native.mk_int_symbol (context_gno ctx) i)) - - let mk_string ( ctx : context ) ( s : string ) = - S_Str (create_s ctx (Z3native.mk_string_symbol (context_gno ctx) s)) - - let mk_ints ( ctx : context ) ( names : int list ) = - let f elem = mk_int ( ctx : context ) elem in - (List.map f names) - - let mk_strings ( ctx : context ) ( names : string list ) = - let f elem = mk_string ( ctx : context ) elem in - (List.map f names) -end - - -module AST = -struct - type ast = z3_native_object - - let context_of_ast ( x : ast ) = (z3obj_gc x) - let nc_of_ast ( x : ast ) = (z3obj_gnc x) - let ptr_of_ast ( x : ast ) = (z3obj_gno x) - - let rec ast_of_ptr : context -> Z3native.ptr -> ast = fun ctx no -> - match (ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) with - | FUNC_DECL_AST - | SORT_AST - | QUANTIFIER_AST - | APP_AST - | NUMERAL_AST - | VAR_AST -> z3_native_object_of_ast_ptr ctx no - | UNKNOWN_AST -> raise (Z3native.Exception "Cannot create asts of type unknown") - - module ASTVector = - struct - type ast_vector = z3_native_object - - let ast_vector_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let res : ast_vector = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.ast_vector_inc_ref ; - dec_ref = Z3native.ast_vector_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_size ( x : ast_vector ) = - Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) - - let get ( x : ast_vector ) ( i : int ) = - ast_of_ptr (z3obj_gc x) (Z3native.ast_vector_get (z3obj_gnc x) (z3obj_gno x) i) - - let set ( x : ast_vector ) ( i : int ) ( value : ast ) = - Z3native.ast_vector_set (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno value) - - let resize ( x : ast_vector ) ( new_size : int ) = - Z3native.ast_vector_resize (z3obj_gnc x) (z3obj_gno x) new_size - - let push ( x : ast_vector ) ( a : ast ) = - Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) - - let translate ( x : ast_vector ) ( to_ctx : context ) = - ast_vector_of_ptr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let to_string ( x : ast_vector ) = - Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) - end - - module ASTMap = - struct - type ast_map = z3_native_object - - let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let res : ast_map = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.ast_map_inc_ref ; - dec_ref = Z3native.ast_map_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let contains ( x : ast_map ) ( key : ast ) = - Z3native.ast_map_contains (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - - let find ( x : ast_map ) ( key : ast ) = - ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) - - let insert ( x : ast_map ) ( key : ast ) ( value : ast) = - Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) - - let erase ( x : ast_map ) ( key : ast ) = - Z3native.ast_map_erase (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) - - let reset ( x : ast_map ) = - Z3native.ast_map_reset (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : ast_map ) = - Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) - - let get_keys ( x : ast_map ) = - let av = ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in - let f i = (ASTVector.get av i) in - mk_list f (ASTVector.get_size av) - - let to_string ( x : ast_map ) = - Z3native.ast_map_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let get_hash_code ( x : ast ) = Z3native.get_ast_hash (z3obj_gnc x) (z3obj_gno x) - let get_id ( x : ast ) = Z3native.get_ast_id (z3obj_gnc x) (z3obj_gno x) - let get_ast_kind ( x : ast ) = (ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc x) (z3obj_gno x))) - - let is_expr ( x : ast ) = - match get_ast_kind ( x : ast ) with - | APP_AST - | NUMERAL_AST - | QUANTIFIER_AST - | VAR_AST -> true - | _ -> false - - let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST - let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST - let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST - let is_func_decl ( x : ast ) = (get_ast_kind x) == FUNC_DECL_AST - - let to_string ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - let to_sexpr ( x : ast ) = Z3native.ast_to_string (z3obj_gnc x) (z3obj_gno x) - - - let ( = ) ( a : ast ) ( b : ast ) = (a == b) || - if (z3obj_gnc a) != (z3obj_gnc b) then - false - else - Z3native.is_eq_ast (z3obj_gnc a) (z3obj_gno a) (z3obj_gno b) - - let compare a b = - if (get_id a) < (get_id b) then -1 else - if (get_id a) > (get_id b) then 1 else - 0 - - let ( < ) (a : ast) (b : ast) = (compare a b) - - let translate ( x : ast ) ( to_ctx : context ) = - if (z3obj_gnc x) == (context_gno to_ctx) then - x - else - ast_of_ptr to_ctx (Z3native.translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let wrap_ast ( ctx : context ) ( ptr : Z3native.ptr ) = ast_of_ptr ctx ptr - let unwrap_ast ( x : ast ) = (z3obj_gno x) -end - -open AST - - -module Sort = -struct - type sort = Sort of AST.ast - type uninterpreted_sort = UninterpretedSort of sort - - let sort_of_ptr : context -> Z3native.ptr -> sort = fun ctx no -> - let q = (z3_native_object_of_ast_ptr ctx no) in - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.SORT_AST) then - raise (Z3native.Exception "Invalid coercion") - else - match (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) no)) with - | ARRAY_SORT - | BOOL_SORT - | BV_SORT - | DATATYPE_SORT - | INT_SORT - | REAL_SORT - | UNINTERPRETED_SORT - | FINITE_DOMAIN_SORT - | RELATION_SORT -> Sort(q) - | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") - - let ast_of_sort s = match s with Sort(x) -> x - let sort_of_uninterpreted_sort s = match s with UninterpretedSort(x) -> x - - let uninterpreted_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.UNINTERPRETED_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - UninterpretedSort(s) - - let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) - let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) - let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) - - let sort_lton ( a : sort list ) = - let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in - Array.of_list (List.map f a) - - let ( = ) : sort -> sort -> bool = fun a b -> - (a == b) || - if (gnc a) != (gnc b) then - false - else - (Z3native.is_eq_sort (gnc a) (gno a) (gno b)) - - - let get_id ( x : sort ) = Z3native.get_sort_id (gnc x) (gno x) - let get_sort_kind ( x : sort ) = (sort_kind_of_int (Z3native.get_sort_kind (gnc x) (gno x))) - let get_name ( x : sort ) = (Symbol.create (gc x) (Z3native.get_sort_name (gnc x) (gno x))) - let to_string ( x : sort ) = Z3native.sort_to_string (gnc x) (gno x) - - let mk_uninterpreted ( ctx : context ) ( s : Symbol.symbol ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_uninterpreted_sort (context_gno ctx) (Symbol.gno s))) ; - (z3obj_create res) ; - UninterpretedSort(Sort(res)) - - let mk_uninterpreted_s ( ctx : context ) ( s : string ) = - mk_uninterpreted ctx (Symbol.mk_string ( ctx : context ) s) -end - -open Sort - - -module rec FuncDecl : -sig - type func_decl = FuncDecl of AST.ast - val ast_of_func_decl : FuncDecl.func_decl -> AST.ast - val func_decl_of_ptr : context -> Z3native.ptr -> func_decl - val gc : func_decl -> context - val gnc : func_decl -> Z3native.ptr - val gno : func_decl -> Z3native.ptr - module Parameter : - sig - type parameter = - P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - val get_kind : parameter -> Z3enums.parameter_kind - val get_int : parameter -> int - val get_float : parameter -> float - val get_symbol : parameter -> Symbol.symbol - val get_sort : parameter -> Sort.sort - val get_ast : parameter -> AST.ast - val get_func_decl : parameter -> func_decl - val get_rational : parameter -> string - end - val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl - val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl - val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl - val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl - val mk_const_decl_s : context -> string -> Sort.sort -> func_decl - val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl - val ( = ) : func_decl -> func_decl -> bool - val to_string : func_decl -> string - val get_id : func_decl -> int - val get_arity : func_decl -> int - val get_domain_size : func_decl -> int - val get_domain : func_decl -> Sort.sort list - val get_range : func_decl -> Sort.sort - val get_decl_kind : func_decl -> Z3enums.decl_kind - val get_name : func_decl -> Symbol.symbol - val get_num_parameters : func_decl -> int - val get_parameters : func_decl -> Parameter.parameter list - val apply : func_decl -> Expr.expr list -> Expr.expr -end = struct - type func_decl = FuncDecl of AST.ast - - let func_decl_of_ptr : context -> Z3native.ptr -> func_decl = fun ctx no -> - if ((Z3enums.ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no)) != Z3enums.FUNC_DECL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - FuncDecl(z3_native_object_of_ast_ptr ctx no) - - let ast_of_func_decl f = match f with FuncDecl(x) -> x - - let create_ndr ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_func_decl (context_gno ctx) (Symbol.gno name) (List.length domain) (sort_lton domain) (Sort.gno range))) ; - (z3obj_create res) ; - FuncDecl(res) - - let create_pdr ( ctx : context) ( prefix : string ) ( domain : sort list ) ( range : sort ) = - let res = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.inc_ref ; - dec_ref = Z3native.dec_ref } in - (z3obj_sno res ctx (Z3native.mk_fresh_func_decl (context_gno ctx) prefix (List.length domain) (sort_lton domain) (Sort.gno range))) ; - (z3obj_create res) ; - FuncDecl(res) - - let gc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gc a) - let gnc ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gnc a) - let gno ( x : func_decl ) = match x with FuncDecl(a) -> (z3obj_gno a) - - module Parameter = - struct - type parameter = - | P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - let get_kind ( x : parameter ) = - (match x with - | P_Int(_) -> PARAMETER_INT - | P_Dbl(_) -> PARAMETER_DOUBLE - | P_Sym(_) -> PARAMETER_SYMBOL - | P_Srt(_) -> PARAMETER_SORT - | P_Ast(_) -> PARAMETER_AST - | P_Fdl(_) -> PARAMETER_FUNC_DECL - | P_Rat(_) -> PARAMETER_RATIONAL) - - let get_int ( x : parameter ) = - match x with - | P_Int(x) -> x - | _ -> raise (Z3native.Exception "parameter is not an int") - - let get_float ( x : parameter ) = - match x with - | P_Dbl(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a double") - - let get_symbol ( x : parameter ) = - match x with - | P_Sym(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a symbol") - - let get_sort ( x : parameter ) = - match x with - | P_Srt(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a sort") - - let get_ast ( x : parameter ) = - match x with - | P_Ast(x) -> x - | _ -> raise (Z3native.Exception "parameter is not an ast") - - let get_func_decl ( x : parameter ) = - match x with - | P_Fdl(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a func_decl") - - let get_rational ( x : parameter ) = - match x with - | P_Rat(x) -> x - | _ -> raise (Z3native.Exception "parameter is not a rational string") - end - - let mk_func_decl ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort list ) ( range : sort ) = - create_ndr ctx name domain range - - let mk_func_decl_s ( ctx : context ) ( name : string ) ( domain : sort list ) ( range : sort ) = - mk_func_decl ctx (Symbol.mk_string ctx name) domain range - - let mk_fresh_func_decl ( ctx : context ) ( prefix : string ) ( domain : sort list ) ( range : sort ) = - create_pdr ctx prefix domain range - - let mk_const_decl ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - create_ndr ctx name [] range - - let mk_const_decl_s ( ctx : context ) ( name : string ) ( range : sort ) = - create_ndr ctx (Symbol.mk_string ctx name) [] range - - let mk_fresh_const_decl ( ctx : context ) ( prefix : string ) ( range : sort ) = - create_pdr ctx prefix [] range - - - let ( = ) ( a : func_decl ) ( b : func_decl ) = (a == b) || - if (gnc a) != (gnc b) then - false - else - (Z3native.is_eq_func_decl (gnc a) (gno a) (gno b)) - - let to_string ( x : func_decl ) = Z3native.func_decl_to_string (gnc x) (gno x) - - let get_id ( x : func_decl ) = Z3native.get_func_decl_id (gnc x) (gno x) - - let get_arity ( x : func_decl ) = Z3native.get_arity (gnc x) (gno x) - - let get_domain_size ( x : func_decl ) = Z3native.get_domain_size (gnc x) (gno x) - - let get_domain ( x : func_decl ) = - let n = (get_domain_size x) in - let f i = sort_of_ptr (gc x) (Z3native.get_domain (gnc x) (gno x) i) in - mk_list f n - - let get_range ( x : func_decl ) = - sort_of_ptr (gc x) (Z3native.get_range (gnc x) (gno x)) - - let get_decl_kind ( x : func_decl ) = (decl_kind_of_int (Z3native.get_decl_kind (gnc x) (gno x))) - - let get_name ( x : func_decl ) = (Symbol.create (gc x) (Z3native.get_decl_name (gnc x) (gno x))) - - let get_num_parameters ( x : func_decl ) = (Z3native.get_decl_num_parameters (gnc x) (gno x)) - - let get_parameters ( x : func_decl ) = - let n = (get_num_parameters x) in - let f i = (match (parameter_kind_of_int (Z3native.get_decl_parameter_kind (gnc x) (gno x) i)) with - | PARAMETER_INT -> Parameter.P_Int (Z3native.get_decl_int_parameter (gnc x) (gno x) i) - | PARAMETER_DOUBLE -> Parameter.P_Dbl (Z3native.get_decl_double_parameter (gnc x) (gno x) i) - | PARAMETER_SYMBOL-> Parameter.P_Sym (Symbol.create (gc x) (Z3native.get_decl_symbol_parameter (gnc x) (gno x) i)) - | PARAMETER_SORT -> Parameter.P_Srt (sort_of_ptr (gc x) (Z3native.get_decl_sort_parameter (gnc x) (gno x) i)) - | PARAMETER_AST -> Parameter.P_Ast (AST.ast_of_ptr (gc x) (Z3native.get_decl_ast_parameter (gnc x) (gno x) i)) - | PARAMETER_FUNC_DECL -> Parameter.P_Fdl (func_decl_of_ptr (gc x) (Z3native.get_decl_func_decl_parameter (gnc x) (gno x) i)) - | PARAMETER_RATIONAL -> Parameter.P_Rat (Z3native.get_decl_rational_parameter (gnc x) (gno x) i) - ) in - mk_list f n - - let apply ( x : func_decl ) ( args : Expr.expr list ) = Expr.expr_of_func_app (gc x) x args -end - - -and Params : -sig - type params = z3_native_object - module ParamDescrs : - sig - type param_descrs - val param_descrs_of_ptr : context -> Z3native.ptr -> param_descrs - val validate : param_descrs -> params -> unit - val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind - val get_names : param_descrs -> Symbol.symbol list - val get_size : param_descrs -> int - val to_string : param_descrs -> string - end - val add_bool : params -> Symbol.symbol -> bool -> unit - val add_int : params -> Symbol.symbol -> int -> unit - val add_double : params -> Symbol.symbol -> float -> unit - val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - val add_s_bool : params -> string -> bool -> unit - val add_s_int : params -> string -> int -> unit - val add_s_double : params -> string -> float -> unit - val add_s_symbol : params -> string -> Symbol.symbol -> unit - val mk_params : context -> params - val to_string : params -> string -end = struct - type params = z3_native_object - - module ParamDescrs = - struct - type param_descrs = z3_native_object - - let param_descrs_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let res : param_descrs = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.param_descrs_inc_ref ; - dec_ref = Z3native.param_descrs_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let validate ( x : param_descrs ) ( p : params ) = - Z3native.params_validate (z3obj_gnc x) (z3obj_gno p) (z3obj_gno x) - - let get_kind ( x : param_descrs ) ( name : Symbol.symbol ) = - (param_kind_of_int (Z3native.param_descrs_get_kind (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name))) - - let get_names ( x : param_descrs ) = - let n = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) in - let f i = Symbol.create (z3obj_gc x) (Z3native.param_descrs_get_name (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_size ( x : param_descrs ) = Z3native.param_descrs_size (z3obj_gnc x) (z3obj_gno x) - let to_string ( x : param_descrs ) = Z3native.param_descrs_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let add_bool ( x : params ) ( name : Symbol.symbol ) ( value : bool ) = - Z3native.params_set_bool (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_int ( x : params ) (name : Symbol.symbol ) ( value : int ) = - Z3native.params_set_uint (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_double ( x : params ) ( name : Symbol.symbol ) ( value : float ) = - Z3native.params_set_double (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) value - - let add_symbol ( x : params ) ( name : Symbol.symbol ) ( value : Symbol.symbol ) = - Z3native.params_set_symbol (z3obj_gnc x) (z3obj_gno x) (Symbol.gno name) (Symbol.gno value) - - let add_s_bool ( x : params ) ( name : string ) ( value : bool ) = - add_bool x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_int ( x : params) ( name : string ) ( value : int ) = - add_int x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_double ( x : params ) ( name : string ) ( value : float ) = - add_double x (Symbol.mk_string (z3obj_gc x) name) value - - let add_s_symbol ( x : params ) ( name : string ) ( value : Symbol.symbol ) = - add_symbol x (Symbol.mk_string (z3obj_gc x) name) value - - let mk_params ( ctx : context ) = - let res : params = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.params_inc_ref ; - dec_ref = Z3native.params_dec_ref } in - (z3obj_sno res ctx (Z3native.mk_params (context_gno ctx))) ; - (z3obj_create res) ; - res - - let to_string ( x : params ) = Z3native.params_to_string (z3obj_gnc x) (z3obj_gno x) -end - -(** General expressions (terms) *) -and Expr : -sig - type expr = Expr of AST.ast - val expr_of_ptr : context -> Z3native.ptr -> expr - val gc : expr -> context - val gnc : expr -> Z3native.ptr - val gno : expr -> Z3native.ptr - val expr_lton : expr list -> Z3native.ptr array - val ast_of_expr : expr -> AST.ast - val expr_of_ast : AST.ast -> expr - val expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr - val simplify : expr -> Params.params option -> expr - val get_simplify_help : context -> string - val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs - val get_func_decl : expr -> FuncDecl.func_decl - val get_bool_value : expr -> Z3enums.lbool - val get_num_args : expr -> int - val get_args : expr -> expr list - val update : expr -> expr list -> expr - val substitute : expr -> expr list -> expr list -> expr - val substitute_one : expr -> expr -> expr -> expr - val substitute_vars : expr -> expr list -> expr - val translate : expr -> context -> expr - val to_string : expr -> string - val is_numeral : expr -> bool - val is_well_sorted : expr -> bool - val get_sort : expr -> Sort.sort - val is_bool : expr -> bool - val is_const : expr -> bool - val is_true : expr -> bool - val is_false : expr -> bool - val is_eq : expr -> bool - val is_distinct : expr -> bool - val is_ite : expr -> bool - val is_and : expr -> bool - val is_or : expr -> bool - val is_iff : expr -> bool - val is_xor : expr -> bool - val is_not : expr -> bool - val is_implies : expr -> bool - val is_label : expr -> bool - val is_label_lit : expr -> bool - val is_oeq : expr -> bool - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - val mk_const_s : context -> string -> Sort.sort -> expr - val mk_const_f : context -> FuncDecl.func_decl -> expr - val mk_fresh_const : context -> string -> Sort.sort -> expr - val mk_app : context -> FuncDecl.func_decl -> expr list -> expr - val mk_numeral_string : context -> string -> Sort.sort -> expr - val mk_numeral_int : context -> int -> Sort.sort -> expr -end = struct - type expr = Expr of AST.ast - - let c_of_expr e = match e with Expr(a) -> (z3obj_gc a) - let nc_of_expr e = match e with Expr(a) -> (z3obj_gnc a) - let ptr_of_expr e = match e with Expr(a) -> (z3obj_gno a) - - let expr_of_ptr : context -> Z3native.ptr -> expr = fun ctx no -> - if ast_kind_of_int (Z3native.get_ast_kind (context_gno ctx) no) == QUANTIFIER_AST then - Expr(z3_native_object_of_ast_ptr ctx no) - else - let s = Z3native.get_sort (context_gno ctx) no in - let sk = (sort_kind_of_int (Z3native.get_sort_kind (context_gno ctx) s)) in - if (Z3native.is_algebraic_number (context_gno ctx) no) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - if (Z3native.is_numeral_ast (context_gno ctx) no) then - if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then - Expr(z3_native_object_of_ast_ptr ctx no) - else - raise (Z3native.Exception "Unsupported numeral object") - else - Expr(z3_native_object_of_ast_ptr ctx no) - - let expr_of_ast a = - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.APP_AST && q != VAR_AST && q != QUANTIFIER_AST && q != NUMERAL_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Expr(a) - - let ast_of_expr e = match e with Expr(a) -> a - - let expr_lton ( a : expr list ) = - let f ( e : expr ) = match e with Expr(a) -> (AST.ptr_of_ast a) in - Array.of_list (List.map f a) - - let expr_of_func_app : context -> FuncDecl.func_decl -> expr list -> expr = fun ctx f args -> - match f with FuncDecl.FuncDecl(fa) -> - let o = Z3native.mk_app (context_gno ctx) (AST.ptr_of_ast fa) (List.length args) (expr_lton args) in - expr_of_ptr ctx o - - let simplify ( x : expr ) ( p : Params.params option ) = match p with - | None -> expr_of_ptr (Expr.gc x) (Z3native.simplify (Expr.gnc x) (Expr.gno x)) - | Some pp -> expr_of_ptr (Expr.gc x) (Z3native.simplify_ex (Expr.gnc x) (Expr.gno x) (z3obj_gno pp)) - - let get_simplify_help ( ctx : context ) = - Z3native.simplify_get_help (context_gno ctx) - - let get_simplify_parameter_descrs ( ctx : context ) = - Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (Expr.gnc x) (Expr.gno x)) - - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (Expr.gnc x) (Expr.gno x)) - - let get_num_args ( x : expr ) = Z3native.get_app_num_args (Expr.gnc x) (Expr.gno x) - - let get_args ( x : expr ) = let n = (get_num_args x) in - let f i = expr_of_ptr (Expr.gc x) (Z3native.get_app_arg (Expr.gnc x) (Expr.gno x) i) in - mk_list f n - - let update ( x : expr ) ( args : expr list ) = - if (List.length args <> (get_num_args x)) then - raise (Z3native.Exception "Number of arguments does not match") - else - expr_of_ptr (Expr.gc x) (Z3native.update_term (Expr.gnc x) (Expr.gno x) (List.length args) (expr_lton args)) - - let substitute ( x : expr ) from to_ = - if (List.length from) <> (List.length to_) then - raise (Z3native.Exception "Argument sizes do not match") - else - expr_of_ptr (Expr.gc x) (Z3native.substitute (Expr.gnc x) (Expr.gno x) (List.length from) (expr_lton from) (expr_lton to_)) - - let substitute_one ( x : expr ) from to_ = - substitute ( x : expr ) [ from ] [ to_ ] - - let substitute_vars ( x : expr ) to_ = - expr_of_ptr (Expr.gc x) (Z3native.substitute_vars (Expr.gnc x) (Expr.gno x) (List.length to_) (expr_lton to_)) - - let translate ( x : expr ) to_ctx = - if (Expr.gc x) == to_ctx then - x - else - expr_of_ptr to_ctx (Z3native.translate (Expr.gnc x) (Expr.gno x) (context_gno to_ctx)) - - let to_string ( x : expr ) = Z3native.ast_to_string (Expr.gnc x) (Expr.gno x) - - let is_numeral ( x : expr ) = (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) - - let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (Expr.gnc x) (Expr.gno x) - - let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)) - - let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (Expr.gnc x) - (Z3native.mk_bool_sort (Expr.gnc x)) - (Z3native.get_sort (Expr.gnc x) (Expr.gno x))) - - let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (get_num_args x) == 0 && - (FuncDecl.get_domain_size (get_func_decl x)) == 0 - - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - let is_label ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL) - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) - let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = - expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) - - let mk_const_s ( ctx : context ) ( name : string ) ( range : sort ) = - mk_const ctx (Symbol.mk_string ctx name) range - - let mk_const_f ( ctx : context ) ( f : FuncDecl.func_decl ) = Expr.expr_of_func_app ctx f [] - - let mk_fresh_const ( ctx : context ) ( prefix : string ) ( range : sort ) = - expr_of_ptr ctx (Z3native.mk_fresh_const (context_gno ctx) prefix (Sort.gno range)) - - let mk_app ( ctx : context ) ( f : FuncDecl.func_decl ) ( args : expr list ) = expr_of_func_app ctx f args - - let mk_numeral_string ( ctx : context ) ( v : string ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno ty)) - - let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) -end - -open FuncDecl -open Expr - -module Boolean = -struct - type bool_sort = BoolSort of Sort.sort - type bool_expr = BoolExpr of Expr.expr - - let bool_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let a = (AST.ast_of_ptr ctx no) in - BoolExpr(Expr.Expr(a)) - - let bool_expr_of_expr e = - match e with Expr.Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolExpr(e) - - let bool_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - BoolSort(sort_of_ptr ctx no) - - let sort_of_bool_sort s = match s with BoolSort(x) -> x - - let bool_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BOOL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BoolSort(s) - - let expr_of_bool_expr e = match e with BoolExpr(x) -> x - - let gc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.c_of_expr e) - let gnc ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.nc_of_expr e) - let gno ( x : bool_expr ) = match x with BoolExpr(e) -> (Expr.ptr_of_expr e) - - let mk_sort ( ctx : context ) = - BoolSort(sort_of_ptr ctx (Z3native.mk_bool_sort (context_gno ctx))) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - let s = (match (mk_sort ctx) with BoolSort(q) -> q) in - BoolExpr(Expr.mk_const ctx name s) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_true ( ctx : context ) = - bool_expr_of_ptr ctx (Z3native.mk_true (context_gno ctx)) - - let mk_false ( ctx : context ) = - bool_expr_of_ptr ctx (Z3native.mk_false (context_gno ctx)) - - let mk_val ( ctx : context ) ( value : bool ) = - if value then mk_true ctx else mk_false ctx - - let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - bool_expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) - - let mk_distinct ( ctx : context ) ( args : expr list ) = - bool_expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) - - let mk_not ( ctx : context ) ( a : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) - - let mk_ite ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) ( t3 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_ite (context_gno ctx) (gno t1) (gno t2) (gno t3)) - - let mk_iff ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_iff (context_gno ctx) (gno t1) (gno t2)) - - let mk_implies ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_implies (context_gno ctx) (gno t1) (gno t2)) - - let mk_xor ( ctx : context ) ( t1 : bool_expr ) ( t2 : bool_expr ) = - bool_expr_of_ptr ctx (Z3native.mk_xor (context_gno ctx) (gno t1) (gno t2)) - - let mk_and ( ctx : context ) ( args : bool_expr list ) = - let f x = (Expr.gno (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_and (context_gno ctx) (List.length args) (Array.of_list (List.map f args))) - - let mk_or ( ctx : context ) ( args : bool_expr list ) = - let f x = (Expr.gno (expr_of_bool_expr x)) in - bool_expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) -end - - -module Quantifier = -struct - type quantifier = Quantifier of expr - - let expr_of_quantifier e = match e with Quantifier(x) -> x - - let quantifier_of_expr e = - match e with Expr.Expr(a) -> - let q = (Z3enums.ast_kind_of_int (Z3native.get_ast_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.QUANTIFIER_AST) then - raise (Z3native.Exception "Invalid coercion") - else - Quantifier(e) - - let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) - let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) - let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) - - module Pattern = - struct - type pattern = Pattern of ast - - let ast_of_pattern e = match e with Pattern(x) -> x - - let pattern_of_ast a = - (* CMW: Unchecked ok? *) - Pattern(a) - - let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) - let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) - let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) - - let get_num_terms ( x : pattern ) = - Z3native.get_pattern_num_terms (gnc x) (gno x) - - let get_terms ( x : pattern ) = - let n = (get_num_terms x) in - let f i = (expr_of_ptr (gc x) (Z3native.get_pattern (gnc x) (gno x) i)) in - mk_list f n - - let to_string ( x : pattern ) = Z3native.pattern_to_string (gnc x) (gno x) - end - - let get_index ( x : expr ) = - if not (AST.is_var (match x with Expr.Expr(a) -> a)) then - raise (Z3native.Exception "Term is not a bound variable.") - else - Z3native.get_index_value (Expr.gnc x) (Expr.gno x) - - let is_universal ( x : quantifier ) = - Z3native.is_quantifier_forall (gnc x) (gno x) - - let is_existential ( x : quantifier ) = not (is_universal x) - - let get_weight ( x : quantifier ) = Z3native.get_quantifier_weight (gnc x) (gno x) - - let get_num_patterns ( x : quantifier ) = Z3native.get_quantifier_num_patterns (gnc x) (gno x) - - let get_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_pattern_ast (gnc x) (gno x) i)) in - mk_list f n - - let get_num_no_patterns ( x : quantifier ) = Z3native.get_quantifier_num_no_patterns (gnc x) (gno x) - - let get_no_patterns ( x : quantifier ) = - let n = (get_num_patterns x) in - let f i = Pattern.Pattern (z3_native_object_of_ast_ptr (gc x) (Z3native.get_quantifier_no_pattern_ast (gnc x) (gno x) i)) in - mk_list f n - - let get_num_bound ( x : quantifier ) = Z3native.get_quantifier_num_bound (gnc x) (gno x) - - let get_bound_variable_names ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (Symbol.create (gc x) (Z3native.get_quantifier_bound_name (gnc x) (gno x) i)) in - mk_list f n - - let get_bound_variable_sorts ( x : quantifier ) = - let n = (get_num_bound x) in - let f i = (sort_of_ptr (gc x) (Z3native.get_quantifier_bound_sort (gnc x) (gno x) i)) in - mk_list f n - - let get_body ( x : quantifier ) = - Boolean.bool_expr_of_ptr (gc x) (Z3native.get_quantifier_body (gnc x) (gno x)) - - let mk_bound ( ctx : context ) ( index : int ) ( ty : sort ) = - expr_of_ptr ctx (Z3native.mk_bound (context_gno ctx) index (Sort.gno ty)) - - let mk_pattern ( ctx : context ) ( terms : expr list ) = - if (List.length terms) == 0 then - raise (Z3native.Exception "Cannot create a pattern from zero terms") - else - Pattern.Pattern(z3_native_object_of_ast_ptr ctx (Z3native.mk_pattern (context_gno ctx) (List.length terms) (expr_lton terms))) - - let mk_forall ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (List.length sorts) != (List.length names) then - raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - - let mk_forall_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) true - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (Expr.gno body))) - - let mk_exists ( ctx : context ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (List.length sorts) != (List.length names) then - raise (Z3native.Exception "Number of sorts does not match number of names") - else if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (List.length sorts) (sort_lton sorts) - (Symbol.symbol_lton names) - (Expr.gno body))) - - let mk_exists_const ( ctx : context ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if ((List.length nopatterns) == 0 && quantifier_id == None && skolem_id == None) then - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (Expr.gno body))) - else - Quantifier(expr_of_ptr ctx (Z3native.mk_quantifier_const_ex (context_gno ctx) false - (match weight with | None -> 1 | Some(x) -> x) - (match quantifier_id with | None -> null | Some(x) -> (Symbol.gno x)) - (match skolem_id with | None -> null | Some(x) -> (Symbol.gno x)) - (List.length bound_constants) (expr_lton bound_constants) - (List.length patterns) (let f x = (AST.ptr_of_ast (Pattern.ast_of_pattern x)) in (Array.of_list (List.map f patterns))) - (List.length nopatterns) (expr_lton nopatterns) - (Expr.gno body))) - - let mk_quantifier ( ctx : context ) ( universal : bool ) ( sorts : sort list ) ( names : Symbol.symbol list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (universal) then - (mk_forall ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - else - (mk_exists ctx sorts names body weight patterns nopatterns quantifier_id skolem_id) - - let mk_quantifier ( ctx : context ) ( universal : bool ) ( bound_constants : expr list ) ( body : expr ) ( weight : int option ) ( patterns : Pattern.pattern list ) ( nopatterns : expr list ) ( quantifier_id : Symbol.symbol option ) ( skolem_id : Symbol.symbol option ) = - if (universal) then - mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id - else - mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id -end - - -module Array_ = -struct - type array_sort = ArraySort of sort - type array_expr = ArrayExpr of expr - - let array_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let e = (expr_of_ptr ctx no) in - ArrayExpr(e) - - let array_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - ArraySort(s) - - let sort_of_array_sort s = match s with ArraySort(x) -> x - - let array_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArraySort(s) - - let array_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.ARRAY_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArrayExpr(e) - - let expr_of_array_expr e = match e with ArrayExpr(x) -> x - - let sgc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : array_sort ) = match (x) with ArraySort(Sort(s)) -> (z3obj_gno s) - - let egc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gc e) - let egnc ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gnc e) - let egno ( x : array_expr ) = match (x) with ArrayExpr(Expr(e)) -> (z3obj_gno e) - - let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = - array_sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) - - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) - let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) - let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) - let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) - let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) - let is_array ( x : expr ) = - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) - - let get_domain ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_domain (sgnc x) (sgno x)) - let get_range ( x : array_sort ) = Sort.sort_of_ptr (sgc x) (Z3native.get_array_sort_range (sgnc x) (sgno x)) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( domain : sort ) ( range : sort ) = - ArrayExpr(Expr.mk_const ctx name (match (mk_sort ctx domain range) with ArraySort(s) -> s)) - - let mk_const_s ( ctx : context ) ( name : string ) ( domain : sort ) ( range : sort ) = - mk_const ctx (Symbol.mk_string ctx name) domain range - - let mk_select ( ctx : context ) ( a : array_expr ) ( i : expr ) = - array_expr_of_ptr ctx (Z3native.mk_select (context_gno ctx) (egno a) (Expr.gno i)) - - let mk_store ( ctx : context ) ( a : array_expr ) ( i : expr ) ( v : expr ) = - array_expr_of_ptr ctx (Z3native.mk_store (context_gno ctx) (egno a) (Expr.gno i) (Expr.gno v)) - - let mk_const_array ( ctx : context ) ( domain : sort ) ( v : expr ) = - array_expr_of_ptr ctx (Z3native.mk_const_array (context_gno ctx) (Sort.gno domain) (Expr.gno v)) - - let mk_map ( ctx : context ) ( f : func_decl ) ( args : array_expr list ) = - let m x = (Expr.gno (expr_of_array_expr x)) in - array_expr_of_ptr ctx (Z3native.mk_map (context_gno ctx) (FuncDecl.gno f) (List.length args) (Array.of_list (List.map m args))) - - let mk_term_array ( ctx : context ) ( arg : array_expr ) = - array_expr_of_ptr ctx (Z3native.mk_array_default (context_gno ctx) (egno arg)) -end - - -module Set = -struct - type set_sort = SetSort of sort - - let set_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - SetSort(s) - - let sort_of_set_sort s = match s with SetSort(x) -> x - - let mk_sort ( ctx : context ) ( ty : sort ) = - set_sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) - - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) - let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) - let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) - let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) - - - let mk_empty ( ctx : context ) ( domain : sort ) = - (expr_of_ptr ctx (Z3native.mk_empty_set (context_gno ctx) (Sort.gno domain))) - - let mk_full ( ctx : context ) ( domain : sort ) = - expr_of_ptr ctx (Z3native.mk_full_set (context_gno ctx) (Sort.gno domain)) - - let mk_set_add ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_add (context_gno ctx) (Expr.gno set) (Expr.gno element)) - - let mk_del ( ctx : context ) ( set : expr ) ( element : expr ) = - expr_of_ptr ctx (Z3native.mk_set_del (context_gno ctx) (Expr.gno set) (Expr.gno element)) - - let mk_union ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_set_union (context_gno ctx) (List.length args) (expr_lton args)) - - let mk_intersection ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_set_intersect (context_gno ctx) (List.length args) (expr_lton args)) - - let mk_difference ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_difference (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) - - let mk_complement ( ctx : context ) ( arg : expr ) = - expr_of_ptr ctx (Z3native.mk_set_complement (context_gno ctx) (Expr.gno arg)) - - let mk_membership ( ctx : context ) ( elem : expr ) ( set : expr ) = - expr_of_ptr ctx (Z3native.mk_set_member (context_gno ctx) (Expr.gno elem) (Expr.gno set)) - - let mk_subset ( ctx : context ) ( arg1 : expr ) ( arg2 : expr ) = - expr_of_ptr ctx (Z3native.mk_set_subset (context_gno ctx) (Expr.gno arg1) (Expr.gno arg2)) - -end - - -module FiniteDomain = -struct - type finite_domain_sort = FiniteDomainSort of sort - - let sort_of_finite_domain_sort s = match s with FiniteDomainSort(x) -> x - - let finite_domain_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.FINITE_DOMAIN_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - FiniteDomainSort(s) - - let gc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gc s) - let gnc ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s)) -> (z3obj_gnc s) - let gno ( x : finite_domain_sort ) = match (x) with FiniteDomainSort(Sort(s))-> (z3obj_gno s) - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - let s = (sort_of_ptr ctx (Z3native.mk_finite_domain_sort (context_gno ctx) (Symbol.gno name) size)) in - FiniteDomainSort(s) - - let mk_sort_s ( ctx : context ) ( name : string ) ( size : int ) = - mk_sort ctx (Symbol.mk_string ctx name) size - - - let is_finite_domain ( x : expr ) = - let nc = (Expr.gnc x) in - (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) - - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) - - let get_size ( x : finite_domain_sort ) = - let (r, v) = (Z3native.get_finite_domain_sort_size (gnc x) (gno x)) in - if r then v - else raise (Z3native.Exception "Conversion failed.") -end - - -module Relation = -struct - type relation_sort = RelationSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - RelationSort(s) - - let sort_of_relation_sort s = match s with RelationSort(x) -> x - - let relation_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.RELATION_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RelationSort(s) - - let gc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gc s) - let gnc ( x : relation_sort ) = match (x) with RelationSort(Sort(s)) -> (z3obj_gnc s) - let gno ( x : relation_sort ) = match (x) with RelationSort(Sort(s))-> (z3obj_gno s) - - - let is_relation ( x : expr ) = - let nc = (Expr.gnc x) in - ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && - (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) - - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) - let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) - let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) - let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) - let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) - let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) - let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) - let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) - let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) - let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) - - let get_arity ( x : relation_sort ) = Z3native.get_relation_arity (gnc x) (gno x) - - let get_column_sorts ( x : relation_sort ) = - let n = get_arity x in - let f i = (sort_of_ptr (gc x) (Z3native.get_relation_column (gnc x) (gno x) i)) in - mk_list f n - -end - - -module Datatype = -struct - type datatype_sort = DatatypeSort of sort - type datatype_expr = DatatypeExpr of expr - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - DatatypeSort(s) - - let sort_of_datatype_sort s = match s with DatatypeSort(x) -> x - - let datatype_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeSort(s) - - let datatype_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.DATATYPE_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - DatatypeExpr(e) - - let expr_of_datatype_expr e = match e with DatatypeExpr(x) -> x - - let sgc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : datatype_sort ) = match (x) with DatatypeSort(Sort(s))-> (z3obj_gno s) - - module Constructor = - struct - type constructor = z3_native_object - - let _sizes = Hashtbl.create 0 - - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = - let n = (List.length field_names) in - if n != (List.length sorts) then - raise (Z3native.Exception "Number of field names does not match number of sorts") - else - if n != (List.length sort_refs) then - raise (Z3native.Exception "Number of field names does not match number of sort refs") - else - let ptr = (Z3native.mk_constructor (context_gno ctx) (Symbol.gno name) - (Symbol.gno recognizer) - n - (Symbol.symbol_lton field_names) - (sort_lton sorts) - (Array.of_list sort_refs)) in - let no : constructor = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref} in - (z3obj_sno no ctx ptr) ; - (z3obj_create no) ; - let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in - Gc.finalise f no ; - Hashtbl.add _sizes no n ; - no - - let get_num_fields ( x : constructor ) = Hashtbl.find _sizes x - - let get_constructor_decl ( x : constructor ) = - let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - func_decl_of_ptr (z3obj_gc x) a - - let get_tester_decl ( x : constructor ) = - let (_, b, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - func_decl_of_ptr (z3obj_gc x) b - - let get_accessor_decls ( x : constructor ) = - let (_, _, c) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in - let f i = func_decl_of_ptr (z3obj_gc x) (Array.get c i) in - mk_list f (Array.length c) - - end - - module ConstructorList = - struct - type constructor_list = z3_native_object - - let create ( ctx : context ) ( c : Constructor.constructor list ) = - let res : constructor_list = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = z3obj_nil_ref ; - dec_ref = z3obj_nil_ref} in - let f x =(z3obj_gno x) in - (z3obj_sno res ctx (Z3native.mk_constructor_list (context_gno ctx) (List.length c) (Array.of_list (List.map f c)))) ; - (z3obj_create res) ; - let f = fun o -> Z3native.del_constructor_list (z3obj_gnc o) (z3obj_gno o) in - Gc.finalise f res; - res - end - - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = - Constructor.create ctx name recognizer field_names sorts sort_refs - - - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = - mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = - let f x = (z3obj_gno x) in - let (x,_) = (Z3native.mk_datatype (context_gno ctx) (Symbol.gno name) (List.length constructors) (Array.of_list (List.map f constructors))) in - sort_of_ptr ctx x - - let mk_sort_s ( ctx : context ) ( name : string ) ( constructors : Constructor.constructor list ) = - mk_sort ctx (Symbol.mk_string ctx name) constructors - - let mk_sorts ( ctx : context ) ( names : Symbol.symbol list ) ( c : Constructor.constructor list list ) = - let n = (List.length names) in - let f e = (AST.ptr_of_ast (ConstructorList.create ctx e)) in - let cla = (Array.of_list (List.map f c)) in - let (r, a) = (Z3native.mk_datatypes (context_gno ctx) n (Symbol.symbol_lton names) cla) in - let g i = (sort_of_ptr ctx (Array.get r i)) in - mk_list g (Array.length r) - - let mk_sorts_s ( ctx : context ) ( names : string list ) ( c : Constructor.constructor list list ) = - mk_sorts ctx - ( - let f e = (Symbol.mk_string ctx e) in - List.map f names - ) - c - - let get_num_constructors ( x : datatype_sort ) = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) - - let get_constructors ( x : datatype_sort ) = - let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in - mk_list f n - - let get_recognizers ( x : datatype_sort ) = - let n = (get_num_constructors x) in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i) in - mk_list f n - - let get_accessors ( x : datatype_sort ) = - let n = (get_num_constructors x) in - let f i = ( - let fd = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i) in - let ds = Z3native.get_domain_size (FuncDecl.gnc fd) (FuncDecl.gno fd) in - let g j = func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) i j) in - mk_list g ds - ) in - mk_list f n -end - - -module Enumeration = -struct - type enum_sort = EnumSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( cdecls : Z3native.z3_func_decl list ) ( tdecls : Z3native.z3_func_decl list ) = - let s = (sort_of_ptr ctx no) in - let res = EnumSort(s) in - res - - let sort_of_enum_sort s = match s with EnumSort(x) -> x - - let sgc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : enum_sort ) = match (x) with EnumSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : enum_sort ) = match (x) with EnumSort(Sort(s))-> (z3obj_gno s) - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( enum_names : Symbol.symbol list ) = - let (a, b, c) = (Z3native.mk_enumeration_sort (context_gno ctx) (Symbol.gno name) (List.length enum_names) (Symbol.symbol_lton enum_names)) in - sort_of_ptr ctx a (list_of_array b) (list_of_array c) - - let mk_sort_s ( ctx : context ) ( name : string ) ( enum_names : string list ) = - mk_sort ctx (Symbol.mk_string ctx name) (Symbol.mk_strings ctx enum_names) - - let get_const_decls ( x : enum_sort ) = - let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in - let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) i)) in - mk_list f n - - let get_tester_decls ( x : enum_sort ) = - let n = Z3native.get_datatype_sort_num_constructors (sgnc x) (sgno x) in - let f i = (func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) i)) in - mk_list f n - -end - - -module List_ = -struct - type list_sort = ListSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) ( nildecl : Z3native.ptr ) ( is_nildecl : Z3native.ptr ) ( consdecl : Z3native.ptr ) ( is_consdecl : Z3native.ptr ) ( headdecl : Z3native.ptr ) ( taildecl : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - let res = ListSort(s) in - res - - let sort_of_list_sort s = match s with ListSort(x) -> x - - let sgc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : list_sort ) = match (x) with ListSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : list_sort ) = match (x) with ListSort(Sort(s))-> (z3obj_gno s) - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = - let (r, a, b, c, d, e, f) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in - sort_of_ptr ctx r a b c d e f - - let mk_list_s ( ctx : context ) (name : string) elem_sort = - mk_sort ctx (Symbol.mk_string ctx name) elem_sort - - let get_nil_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 0) - - let get_is_nil_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 0) - - let get_cons_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor (sgnc x) (sgno x) 1) - - let get_is_cons_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_recognizer (sgnc x) (sgno x) 1) - - let get_head_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 0) - - let get_tail_decl ( x : list_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_datatype_sort_constructor_accessor (sgnc x) (sgno x) 1 1) - - let nil ( x : list_sort ) = expr_of_func_app (sgc x) (get_nil_decl x) [] -end - - -module Tuple = -struct - type tuple_sort = TupleSort of sort - - let sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - let s = (sort_of_ptr ctx no) in - TupleSort(s) - - let sort_of_tuple_sort s = match s with TupleSort(x) -> x - - let sgc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : tuple_sort ) = match (x) with TupleSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : tuple_sort ) = match (x) with TupleSort(Sort(s))-> (z3obj_gno s) - - let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( field_sorts : sort list ) = - let (r, _, _) = (Z3native.mk_tuple_sort (context_gno ctx) (Symbol.gno name) (List.length field_names) (Symbol.symbol_lton field_names) (sort_lton field_sorts)) in - sort_of_ptr ctx r - - let get_mk_decl ( x : tuple_sort ) = - func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_mk_decl (sgnc x) (sgno x)) - - let get_num_fields ( x : tuple_sort ) = Z3native.get_tuple_sort_num_fields (sgnc x) (sgno x) - - let get_field_decls ( x : tuple_sort ) = - let n = get_num_fields x in - let f i = func_decl_of_ptr (sgc x) (Z3native.get_tuple_sort_field_decl (sgnc x) (sgno x) i) in - mk_list f n -end - - -module rec Arithmetic : -sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val sort_of_arith_sort : arith_sort -> Sort.sort - val arith_sort_of_sort : Sort.sort -> arith_sort - val expr_of_arith_expr : arith_expr -> Expr.expr - val arith_expr_of_expr : Expr.expr -> arith_expr - - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val int_expr_of_ptr : context -> Z3native.ptr -> int_expr - val int_num_of_ptr : context -> Z3native.ptr -> int_num - - val arith_sort_of_int_sort : Integer.int_sort -> arith_sort - val int_sort_of_arith_sort : arith_sort -> int_sort - val arith_expr_of_int_expr : int_expr -> arith_expr - val int_expr_of_int_num : int_num -> int_expr - val int_expr_of_arith_expr : arith_expr -> int_expr - val int_num_of_int_expr : int_expr -> int_num - - val mk_sort : context -> int_sort - val get_int : int_num -> int - val to_string : int_num -> string - val mk_const : context -> Symbol.symbol -> int_expr - val mk_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> int_expr - val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_numeral_s : context -> string -> int_num - val mk_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> Real.real_expr - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val real_expr_of_ptr : context -> Z3native.ptr -> real_expr - val rat_num_of_ptr : context -> Z3native.ptr -> rat_num - - val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort - val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort - val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr - val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr - val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr - val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num - - val mk_sort : context -> real_sort - val get_numerator : rat_num -> Integer.int_num - val get_denominator : rat_num -> Integer.int_num - val to_decimal_string : rat_num -> int -> string - val to_string : rat_num -> string - val mk_const : context -> Symbol.symbol -> real_expr - val mk_const_s : context -> string -> real_expr - val mk_numeral_nd : context -> int -> int -> rat_num - val mk_numeral_s : context -> string -> rat_num - val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - val mk_real2int : context -> real_expr -> Integer.int_expr - end - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : algebraic_num -> arith_expr - val algebraic_num_of_arith_expr : arith_expr -> algebraic_num - - val to_upper : algebraic_num -> int -> Real.rat_num - val to_lower : algebraic_num -> int -> Real.rat_num - val to_decimal_string : algebraic_num -> int -> string - val to_string : algebraic_num -> string - end - - val is_int : Expr.expr -> bool - val is_arithmetic_numeral : Expr.expr -> bool - val is_le : Expr.expr -> bool - val is_ge : Expr.expr -> bool - val is_lt : Expr.expr -> bool - val is_gt : Expr.expr -> bool - val is_add : Expr.expr -> bool - val is_sub : Expr.expr -> bool - val is_uminus : Expr.expr -> bool - val is_mul : Expr.expr -> bool - val is_div : Expr.expr -> bool - val is_idiv : Expr.expr -> bool - val is_remainder : Expr.expr -> bool - val is_modulus : Expr.expr -> bool - val is_inttoreal : Expr.expr -> bool - val is_real_to_int : Expr.expr -> bool - val is_real_is_int : Expr.expr -> bool - val is_real : Expr.expr -> bool - val is_int_numeral : Expr.expr -> bool - val is_rat_num : Expr.expr -> bool - val is_algebraic_number : Expr.expr -> bool - val mk_add : context -> arith_expr list -> arith_expr - val mk_mul : context -> arith_expr list -> arith_expr - val mk_sub : context -> arith_expr list -> arith_expr - val mk_unary_minus : context -> arith_expr -> arith_expr - val mk_div : context -> arith_expr -> arith_expr -> arith_expr - val mk_power : context -> arith_expr -> arith_expr -> arith_expr - val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr -end = struct - type arith_sort = ArithSort of sort - type arith_expr = ArithExpr of expr - - let arith_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithExpr(e) - - let arith_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - arith_expr_of_expr (expr_of_ptr ctx no) - - let sort_of_arith_sort s = match s with ArithSort(x) -> x - let expr_of_arith_expr e = match e with ArithExpr(x) -> x - - let arith_sort_of_sort s = match s with Sort(a) -> - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) in - if (q != Z3enums.INT_SORT && q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - ArithSort(s) - - let arith_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - arith_sort_of_sort (sort_of_ptr ctx no) - - let sgc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gc s) - let sgnc ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gnc s) - let sgno ( x : arith_sort ) = match (x) with ArithSort(Sort(s)) -> (z3obj_gno s) - let egc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gc e) - let egnc ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gnc e) - let egno ( x : arith_expr ) = match (x) with ArithExpr(e) -> (Expr.gno e) - - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val int_expr_of_ptr : context -> Z3native.ptr -> int_expr - val int_num_of_ptr : context -> Z3native.ptr -> int_num - - val arith_sort_of_int_sort : Integer.int_sort -> arith_sort - val int_sort_of_arith_sort : arith_sort -> int_sort - val arith_expr_of_int_expr : int_expr -> arith_expr - val int_expr_of_int_num : int_num -> int_expr - val int_expr_of_arith_expr : arith_expr -> int_expr - val int_num_of_int_expr : int_expr -> int_num - - val mk_sort : context -> int_sort - val get_int : int_num -> int - val to_string : int_num -> string - val mk_const : context -> Symbol.symbol -> int_expr - val mk_const_s : context -> string -> int_expr - val mk_mod : context -> int_expr -> int_expr -> int_expr - val mk_rem : context -> int_expr -> int_expr -> int_expr - val mk_numeral_s : context -> string -> int_num - val mk_numeral_i : context -> int -> int_num - val mk_int2real : context -> int_expr -> Real.real_expr - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end = struct - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - let int_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntExpr(e) - - let int_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) - - let int_num_of_int_expr e = - match e with IntExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - IntNum(e) - - let int_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_num_of_int_expr (int_expr_of_ptr ctx no) - - let arith_sort_of_int_sort s = match s with IntSort(x) -> x - let arith_expr_of_int_expr e = match e with IntExpr(x) -> x - let int_expr_of_int_num e = match e with IntNum(x) -> x - - let int_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.INT_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - IntSort(s) - - let int_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - int_sort_of_arith_sort (arith_sort_of_sort (Sort.sort_of_ptr ctx no)) - - let sgc ( x : int_sort ) = match (x) with IntSort(s) -> (sgc s) - let sgnc ( x : int_sort ) = match (x) with IntSort(s) -> (sgnc s) - let sgno ( x : int_sort ) = match (x) with IntSort(s) -> (sgno s) - let egc ( x : int_expr ) = match (x) with IntExpr(e) -> (egc e) - let egnc ( x : int_expr ) = match (x) with IntExpr(e) -> (egnc e) - let egno ( x : int_expr ) = match (x) with IntExpr(e) -> (egno e) - let ngc ( x : int_num ) = match (x) with IntNum(e) -> (egc e) - let ngnc ( x : int_num ) = match (x) with IntNum(e) -> (egnc e) - let ngno ( x : int_num ) = match (x) with IntNum(e) -> (egno e) - - let mk_sort ( ctx : context ) = - int_sort_of_ptr ctx (Z3native.mk_int_sort (context_gno ctx)) - - let get_int ( x : int_num ) = - let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in - if r then v - else raise (Z3native.Exception "Conversion failed.") - - let to_string ( x : int_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - IntExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with IntSort(ArithSort(s)) -> s))) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_mod ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - int_expr_of_ptr ctx (Z3native.mk_mod (context_gno ctx) (egno t1) (egno t2)) - - let mk_rem ( ctx : context ) ( t1 : int_expr ) ( t2 : int_expr ) = - int_expr_of_ptr ctx (Z3native.mk_rem (context_gno ctx) (egno t1) (egno t2)) - - let mk_numeral_s ( ctx : context ) ( v : string ) = - int_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - - let mk_numeral_i ( ctx : context ) ( v : int ) = - int_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) - - let mk_int2real ( ctx : context ) ( t : int_expr ) = - Real.real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2real (context_gno ctx) (egno t)))) - - let mk_int2bv ( ctx : context ) ( n : int ) ( t : int_expr ) = - BitVector.bitvec_expr_of_expr (Expr.expr_of_ptr ctx (Z3native.mk_int2bv (context_gno ctx) n (egno t))) - end - - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val real_expr_of_ptr : context -> Z3native.ptr -> real_expr - val rat_num_of_ptr : context -> Z3native.ptr -> rat_num - - val arith_sort_of_real_sort : real_sort -> arith_sort - val real_sort_of_arith_sort : arith_sort -> real_sort - val arith_expr_of_real_expr : real_expr -> arith_expr - val real_expr_of_rat_num : rat_num -> real_expr - val real_expr_of_arith_expr : arith_expr -> real_expr - val rat_num_of_real_expr : real_expr -> rat_num - - val mk_sort : context -> real_sort - val get_numerator : rat_num -> Integer.int_num - val get_denominator : rat_num -> Integer.int_num - val to_decimal_string : rat_num -> int -> string - val to_string : rat_num -> string - val mk_const : context -> Symbol.symbol -> real_expr - val mk_const_s : context -> string -> real_expr - val mk_numeral_nd : context -> int -> int -> rat_num - val mk_numeral_s : context -> string -> rat_num - val mk_numeral_i : context -> int -> rat_num - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - val mk_real2int : context -> real_expr -> Integer.int_expr - end = struct - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - let arith_sort_of_real_sort s = match s with RealSort(x) -> x - let arith_expr_of_real_expr e = match e with RealExpr(x) -> x - let real_expr_of_rat_num e = match e with RatNum(x) -> x - - let real_expr_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealExpr(e) - - let real_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - real_expr_of_arith_expr (arith_expr_of_expr (Expr.expr_of_ptr ctx no)) - - let rat_num_of_real_expr e = - match e with RealExpr(ArithExpr(Expr(a))) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - RatNum(e) - - let rat_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - rat_num_of_real_expr (real_expr_of_ptr ctx no) - - let real_sort_of_arith_sort s = match s with ArithSort(Sort(a)) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.REAL_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - RealSort(s) - - let real_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - real_sort_of_arith_sort (arith_sort_of_sort (sort_of_ptr ctx no)) - - let sgc ( x : real_sort ) = match (x) with RealSort(s) -> (sgc s) - let sgnc ( x : real_sort ) = match (x) with RealSort(s) -> (sgnc s) - let sgno ( x : real_sort ) = match (x) with RealSort(s) -> (sgno s) - let egc ( x : real_expr ) = match (x) with RealExpr(e) -> (egc e) - let egnc ( x : real_expr ) = match (x) with RealExpr(e) -> (egnc e) - let egno ( x : real_expr ) = match (x) with RealExpr(e) -> (egno e) - let ngc ( x : rat_num ) = match (x) with RatNum(e) -> (egc e) - let ngnc ( x : rat_num ) = match (x) with RatNum(e) -> (egnc e) - let ngno ( x : rat_num ) = match (x) with RatNum(e) -> (egno e) - - - let mk_sort ( ctx : context ) = - real_sort_of_ptr ctx (Z3native.mk_real_sort (context_gno ctx)) - - let get_numerator ( x : rat_num ) = - Integer.int_num_of_ptr (ngc x) (Z3native.get_numerator (ngnc x) (ngno x)) - - let get_denominator ( x : rat_num ) = - Integer.int_num_of_ptr (ngc x) (Z3native.get_denominator (ngnc x) (ngno x)) - - let to_decimal_string ( x : rat_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision - - let to_string ( x : rat_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - - let mk_const ( ctx : context ) ( name : Symbol.symbol ) = - RealExpr(ArithExpr(Expr.mk_const ctx name (match (mk_sort ctx) with RealSort(ArithSort(s)) -> s))) - - let mk_const_s ( ctx : context ) ( name : string ) = - mk_const ctx (Symbol.mk_string ctx name) - - let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = - if (den == 0) then - raise (Z3native.Exception "Denominator is zero") - else - rat_num_of_ptr ctx (Z3native.mk_real (context_gno ctx) num den) - - let mk_numeral_s ( ctx : context ) ( v : string ) = - rat_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (mk_sort ctx))) - - let mk_numeral_i ( ctx : context ) ( v : int ) = - rat_num_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (sgno (mk_sort ctx))) - - let mk_is_integer ( ctx : context ) ( t : real_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_is_int (context_gno ctx) (egno t))) - - let mk_real2int ( ctx : context ) ( t : real_expr ) = - Integer.int_expr_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_real2int (context_gno ctx) (egno t)))) - end - - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : algebraic_num -> arith_expr - val algebraic_num_of_arith_expr : arith_expr -> algebraic_num - - val to_upper : algebraic_num -> int -> Real.rat_num - val to_lower : algebraic_num -> int -> Real.rat_num - val to_decimal_string : algebraic_num -> int -> string - val to_string : algebraic_num -> string - end = struct - type algebraic_num = AlgebraicNum of arith_expr - - let arith_expr_of_algebraic_num e = match e with AlgebraicNum(x) -> x - - let algebraic_num_of_arith_expr e = - match e with ArithExpr(Expr(a)) -> - if (not (Z3native.is_algebraic_number (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - AlgebraicNum(e) - - let algebraic_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - algebraic_num_of_arith_expr (arith_expr_of_expr (expr_of_ptr ctx no)) - - let ngc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egc e) - let ngnc ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egnc e) - let ngno ( x : algebraic_num ) = match (x) with AlgebraicNum(e) -> (egno e) - - - let to_upper ( x : algebraic_num ) ( precision : int ) = - Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_upper (ngnc x) (ngno x) precision) - - let to_lower ( x : algebraic_num ) precision = - Real.rat_num_of_ptr (ngc x) (Z3native.get_algebraic_number_lower (ngnc x) (ngno x) precision) - - let to_decimal_string ( x : algebraic_num ) ( precision : int ) = - Z3native.get_numeral_decimal_string (ngnc x) (ngno x) precision - - let to_string ( x : algebraic_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - end - - let is_int ( x : expr ) = - (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) - - let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - - let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - - let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - - let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - - let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - - let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - - let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - - let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - - let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - - let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - - let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - - let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - - let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - - let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - - let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) - - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) - let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) - - let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) - - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) - - let mk_add ( ctx : context ) ( t : arith_expr list ) = - let f x = (Expr.gno (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_mul ( ctx : context ) ( t : arith_expr list ) = - let f x = (Expr.gno (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_mul (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_sub ( ctx : context ) ( t : arith_expr list ) = - let f x = (Expr.gno (expr_of_arith_expr x)) in - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) - - let mk_unary_minus ( ctx : context ) ( t : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (egno t))) - - let mk_div ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (egno t1) (egno t2))) - - let mk_power ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - arith_expr_of_expr (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (egno t1) (egno t2))) - - let mk_lt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (egno t1) (egno t2))) - - let mk_le ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_le (context_gno ctx) (egno t1) (egno t2))) - - let mk_gt ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_gt (context_gno ctx) (egno t1) (egno t2))) - - let mk_ge ( ctx : context ) ( t1 : arith_expr ) ( t2 : arith_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_ge (context_gno ctx) (egno t1) (egno t2))) -end - - -and BitVector : -sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort - val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort - val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr - val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr - val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr - val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num - - val mk_sort : context -> int -> bitvec_sort - val is_bv : Expr.expr -> bool - val is_bv_numeral : Expr.expr -> bool - val is_bv_bit1 : Expr.expr -> bool - val is_bv_bit0 : Expr.expr -> bool - val is_bv_uminus : Expr.expr -> bool - val is_bv_add : Expr.expr -> bool - val is_bv_sub : Expr.expr -> bool - val is_bv_mul : Expr.expr -> bool - val is_bv_sdiv : Expr.expr -> bool - val is_bv_udiv : Expr.expr -> bool - val is_bv_SRem : Expr.expr -> bool - val is_bv_urem : Expr.expr -> bool - val is_bv_smod : Expr.expr -> bool - val is_bv_sdiv0 : Expr.expr -> bool - val is_bv_udiv0 : Expr.expr -> bool - val is_bv_srem0 : Expr.expr -> bool - val is_bv_urem0 : Expr.expr -> bool - val is_bv_smod0 : Expr.expr -> bool - val is_bv_ule : Expr.expr -> bool - val is_bv_sle : Expr.expr -> bool - val is_bv_uge : Expr.expr -> bool - val is_bv_sge : Expr.expr -> bool - val is_bv_ult : Expr.expr -> bool - val is_bv_slt : Expr.expr -> bool - val is_bv_ugt : Expr.expr -> bool - val is_bv_sgt : Expr.expr -> bool - val is_bv_and : Expr.expr -> bool - val is_bv_or : Expr.expr -> bool - val is_bv_not : Expr.expr -> bool - val is_bv_xor : Expr.expr -> bool - val is_bv_nand : Expr.expr -> bool - val is_bv_nor : Expr.expr -> bool - val is_bv_xnor : Expr.expr -> bool - val is_bv_concat : Expr.expr -> bool - val is_bv_signextension : Expr.expr -> bool - val is_bv_zeroextension : Expr.expr -> bool - val is_bv_extract : Expr.expr -> bool - val is_bv_repeat : Expr.expr -> bool - val is_bv_reduceor : Expr.expr -> bool - val is_bv_reduceand : Expr.expr -> bool - val is_bv_comp : Expr.expr -> bool - val is_bv_shiftleft : Expr.expr -> bool - val is_bv_shiftrightlogical : Expr.expr -> bool - val is_bv_shiftrightarithmetic : Expr.expr -> bool - val is_bv_rotateleft : Expr.expr -> bool - val is_bv_rotateright : Expr.expr -> bool - val is_bv_rotateleftextended : Expr.expr -> bool - val is_bv_rotaterightextended : Expr.expr -> bool - val is_int_to_bv : Expr.expr -> bool - val is_bv_to_int : Expr.expr -> bool - val is_bv_carry : Expr.expr -> bool - val is_bv_xor3 : Expr.expr -> bool - val get_size : bitvec_sort -> int - val get_int : bitvec_num -> int - val to_string : bitvec_num -> string - val mk_const : context -> Symbol.symbol -> int -> bitvec_expr - val mk_const_s : context -> string -> int -> bitvec_expr - val mk_not : context -> bitvec_expr -> Expr.expr - val mk_redand : context -> bitvec_expr -> Expr.expr - val mk_redor : context -> bitvec_expr -> Expr.expr - val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_neg : context -> bitvec_expr -> bitvec_expr - val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr - val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr - val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr - val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr - val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr - val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr - val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr - val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr - val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - val mk_numeral : context -> string -> int -> bitvec_num -end = struct - type bitvec_sort = BitVecSort of sort - type bitvec_expr = BitVecExpr of expr - type bitvec_num = BitVecNum of bitvec_expr - - let sort_of_bitvec_sort s = match s with BitVecSort(x) -> x - - let bitvec_sort_of_sort s = match s with Sort(a) -> - if ((Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) (z3obj_gno a))) != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecSort(s) - - let bitvec_sort_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_sort_of_sort (sort_of_ptr ctx no) - - let bitvec_expr_of_expr e = - match e with Expr(a) -> - let s = Z3native.get_sort (z3obj_gnc a) (z3obj_gno a) in - let q = (Z3enums.sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc a) s)) in - if (q != Z3enums.BV_SORT) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecExpr(e) - - let bitvec_expr_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_expr_of_expr (expr_of_ptr ctx no) - - let bitvec_num_of_bitvec_expr e = - match e with BitVecExpr(Expr(a)) -> - if (not (Z3native.is_numeral_ast (z3obj_gnc a) (z3obj_gno a))) then - raise (Z3native.Exception "Invalid coercion") - else - BitVecNum(e) - - let bitvec_num_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = - bitvec_num_of_bitvec_expr (bitvec_expr_of_expr (expr_of_ptr ctx no)) - - let expr_of_bitvec_expr e = match e with BitVecExpr(x) -> x - let bitvec_expr_of_bitvec_num e = match e with BitVecNum(x) -> x - - - let sgc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gc s) - let sgnc ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gnc s) - let sgno ( x : bitvec_sort ) = match (x) with BitVecSort(s) -> (Sort.gno s) - let egc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gc e) - let egnc ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gnc e) - let egno ( x : bitvec_expr ) = match (x) with BitVecExpr(e) -> (Expr.gno e) - let ngc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egc e) - let ngnc ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egnc e) - let ngno ( x : bitvec_num ) = match (x) with BitVecNum(e) -> (egno e) - - - let mk_sort ( ctx : context ) size = - bitvec_sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) - let is_bv ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) - let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) - let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) - let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) - let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) - let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) - let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) - let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) - let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) - let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) - let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) - let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) - let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) - let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) - let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) - let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) - let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) - let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) - let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) - let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) - let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) - let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) - let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) - let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) - let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) - let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) - let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) - let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) - let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) - let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) - let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) - let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) - let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) - let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) - let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) - let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) - let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) - let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) - let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) - let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) - let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) - let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) - let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) - let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) - let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) - let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) - let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) - let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) - let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) - let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) - let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) - let get_size (x : bitvec_sort ) = Z3native.get_bv_sort_size (sgnc x) (sgno x) - let get_int ( x : bitvec_num ) = - let (r, v) = Z3native.get_numeral_int (ngnc x) (ngno x) in - if r then v - else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : bitvec_num ) = Z3native.get_numeral_string (ngnc x) (ngno x) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = - BitVecExpr(Expr.mk_const ctx name (match (BitVector.mk_sort ctx size) with BitVecSort(s) -> s)) - let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = - mk_const ctx (Symbol.mk_string ctx name) size - let mk_not ( ctx : context ) ( t : bitvec_expr ) = - expr_of_ptr ctx (Z3native.mk_bvnot (context_gno ctx) (egno t)) - let mk_redand ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvredand (context_gno ctx) (egno t)) - let mk_redor ( ctx : context ) ( t : bitvec_expr) = - expr_of_ptr ctx (Z3native.mk_bvredor (context_gno ctx) (egno t)) - let mk_and ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvand (context_gno ctx) (egno t1) (egno t2)) - let mk_or ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvor (context_gno ctx) (egno t1) (egno t2)) - let mk_xor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvxor (context_gno ctx) (egno t1) (egno t2)) - let mk_nand ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvnand (context_gno ctx) (egno t1) (egno t2)) - let mk_nor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvnor (context_gno ctx) (egno t1) (egno t2)) - let mk_xnor ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvxnor (context_gno ctx) (egno t1) (egno t2)) - let mk_neg ( ctx : context ) ( t : bitvec_expr) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvneg (context_gno ctx) (egno t)) - let mk_add ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvadd (context_gno ctx) (egno t1) (egno t2)) - let mk_sub ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsub (context_gno ctx) (egno t1) (egno t2)) - let mk_mul ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvmul (context_gno ctx) (egno t1) (egno t2)) - let mk_udiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvudiv (context_gno ctx) (egno t1) (egno t2)) - let mk_sdiv ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsdiv (context_gno ctx) (egno t1) (egno t2)) - let mk_urem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvurem (context_gno ctx) (egno t1) (egno t2)) - let mk_srem ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsrem (context_gno ctx) (egno t1) (egno t2)) - let mk_smod ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvsmod (context_gno ctx) (egno t1) (egno t2)) - let mk_ult ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvult (context_gno ctx) (egno t1) (egno t2))) - let mk_slt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvslt (context_gno ctx) (egno t1) (egno t2))) - let mk_ule ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvule (context_gno ctx) (egno t1) (egno t2))) - let mk_sle ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsle (context_gno ctx) (egno t1) (egno t2))) - let mk_uge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvuge (context_gno ctx) (egno t1) (egno t2))) - let mk_sge ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsge (context_gno ctx) (egno t1) (egno t2))) - let mk_ugt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvugt (context_gno ctx) (egno t1) (egno t2))) - let mk_sgt ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsgt (context_gno ctx) (egno t1) (egno t2))) - let mk_concat ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_concat (context_gno ctx) (egno t1) (egno t2)) - let mk_extract ( ctx : context ) ( high : int ) ( low : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_extract (context_gno ctx) high low (egno t)) - let mk_sign_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_sign_ext (context_gno ctx) i (egno t)) - let mk_zero_ext ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_zero_ext (context_gno ctx) i (egno t)) - let mk_repeat ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_repeat (context_gno ctx) i (egno t)) - let mk_shl ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvshl (context_gno ctx) (egno t1) (egno t2)) - let mk_lshr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvlshr (context_gno ctx) (egno t1) (egno t2)) - let mk_ashr ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_bvashr (context_gno ctx) (egno t1) (egno t2)) - let mk_rotate_left ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_rotate_left (context_gno ctx) i (egno t)) - let mk_rotate_right ( ctx : context ) ( i : int ) ( t : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_rotate_right (context_gno ctx) i (egno t)) - let mk_ext_rotate_left ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_left (context_gno ctx) (egno t1) (egno t2)) - let mk_ext_rotate_right ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - bitvec_expr_of_ptr ctx (Z3native.mk_ext_rotate_right (context_gno ctx) (egno t1) (egno t2)) - let mk_bv2int ( ctx : context ) ( t : bitvec_expr ) ( signed : bool ) = - Arithmetic.Integer.int_expr_of_ptr ctx (Z3native.mk_bv2int (context_gno ctx) (egno t) signed) - let mk_add_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_add_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvadd_no_underflow (context_gno ctx) (egno t1) (egno t2))) - let mk_sub_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_overflow (context_gno ctx) (egno t1) (egno t2))) - let mk_sub_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsub_no_underflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_sdiv_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvsdiv_no_overflow (context_gno ctx) (egno t1) (egno t2))) - let mk_neg_no_overflow ( ctx : context ) ( t : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvneg_no_overflow (context_gno ctx) (egno t))) - let mk_mul_no_overflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) ( signed : bool) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (egno t1) (egno t2) signed)) - let mk_mul_no_underflow ( ctx : context ) ( t1 : bitvec_expr ) ( t2 : bitvec_expr ) = - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (egno t1) (egno t2))) - let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = - bitvec_num_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (sgno (BitVector.mk_sort ctx size))) -end - - -module Proof = -struct - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) - let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) - let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) - let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) - let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) - let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) - let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) - let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) - let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) - let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) - let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) - let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) - let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) - let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) - let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) - let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) - let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) - let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) - let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) - let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) - let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) - let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) - let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) - let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) - let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) - let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) - let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) - let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) - let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) - let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) - let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) - let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) - let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) - let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) - let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) - let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) - let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) - let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) -end - - -module Goal = -struct - type goal = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : goal = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.goal_inc_ref ; - dec_ref = Z3native.goal_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_precision ( x : goal ) = - goal_prec_of_int (Z3native.goal_precision (z3obj_gnc x) (z3obj_gno x)) - - let is_precise ( x : goal ) = - (get_precision x) == GOAL_PRECISE - - let is_underapproximation ( x : goal ) = - (get_precision x) == GOAL_UNDER - - let is_overapproximation ( x : goal ) = - (get_precision x) == GOAL_OVER - - let is_garbage ( x : goal ) = - (get_precision x) == GOAL_UNDER_OVER - - let assert_ ( x : goal ) ( constraints : Boolean.bool_expr list ) = - let f e = Z3native.goal_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e) in - ignore (List.map f constraints) ; - () - - let is_inconsistent ( x : goal ) = - Z3native.goal_inconsistent (z3obj_gnc x) (z3obj_gno x) - - let get_depth ( x : goal ) = Z3native.goal_depth (z3obj_gnc x) (z3obj_gno x) - - let reset ( x : goal ) = Z3native.goal_reset (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : goal ) = Z3native.goal_size (z3obj_gnc x) (z3obj_gno x) - - let get_formulas ( x : goal ) = - let n = get_size x in - let f i = (Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) - (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in - mk_list f n - - let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) - - let is_decided_sat ( x : goal ) = - Z3native.goal_is_decided_sat (z3obj_gnc x) (z3obj_gno x) - - let is_decided_unsat ( x : goal ) = - Z3native.goal_is_decided_unsat (z3obj_gnc x) (z3obj_gno x) - - let translate ( x : goal ) ( to_ctx : context ) = - create to_ctx (Z3native.goal_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) - - let simplify ( x : goal ) ( p : Params.params option ) = - let tn = Z3native.mk_tactic (z3obj_gnc x) "simplify" in - Z3native.tactic_inc_ref (z3obj_gnc x) tn ; - let arn = match p with - | None -> Z3native.tactic_apply (z3obj_gnc x) tn (z3obj_gno x) - | Some(pn) -> Z3native.tactic_apply_ex (z3obj_gnc x) tn (z3obj_gno x) (z3obj_gno pn) - in - Z3native.apply_result_inc_ref (z3obj_gnc x) arn ; - let sg = Z3native.apply_result_get_num_subgoals (z3obj_gnc x) arn in - let res = if sg == 0 then - raise (Z3native.Exception "No subgoals") - else - Z3native.apply_result_get_subgoal (z3obj_gnc x) arn 0 in - Z3native.apply_result_dec_ref (z3obj_gnc x) arn ; - Z3native.tactic_dec_ref (z3obj_gnc x) tn ; - create (z3obj_gc x) res - - let mk_goal ( ctx : context ) ( models : bool ) ( unsat_cores : bool ) ( proofs : bool ) = - create ctx (Z3native.mk_goal (context_gno ctx) models unsat_cores proofs) - - let to_string ( x : goal ) = Z3native.goal_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Model = -struct - type model = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : model = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.model_inc_ref ; - dec_ref = Z3native.model_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module FuncInterp = - struct - type func_interp = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : func_interp = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.func_interp_inc_ref ; - dec_ref = Z3native.func_interp_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module FuncEntry = - struct - type func_entry = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : func_entry = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.func_entry_inc_ref ; - dec_ref = Z3native.func_entry_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_value ( x : func_entry ) = - expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_value (z3obj_gnc x) (z3obj_gno x)) - - let get_num_args ( x : func_entry ) = Z3native.func_entry_get_num_args (z3obj_gnc x) (z3obj_gno x) - - let get_args ( x : func_entry ) = - let n = (get_num_args x) in - let f i = (expr_of_ptr (z3obj_gc x) (Z3native.func_entry_get_arg (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let to_string ( x : func_entry ) = - let a = (get_args x) in - let f c p = (p ^ (Expr.to_string c) ^ ", ") in - "[" ^ List.fold_right f a ((Expr.to_string (get_value x)) ^ "]") - end - - let get_num_entries ( x: func_interp ) = Z3native.func_interp_get_num_entries (z3obj_gnc x) (z3obj_gno x) - - let get_entries ( x : func_interp ) = - let n = (get_num_entries x) in - let f i = (FuncEntry.create (z3obj_gc x) (Z3native.func_interp_get_entry (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let get_else ( x : func_interp ) = expr_of_ptr (z3obj_gc x) (Z3native.func_interp_get_else (z3obj_gnc x) (z3obj_gno x)) - - let get_arity ( x : func_interp ) = Z3native.func_interp_get_arity (z3obj_gnc x) (z3obj_gno x) - - let to_string ( x : func_interp ) = - let f c p = ( - let n = (FuncEntry.get_num_args c) in - p ^ - let g c p = (p ^ (Expr.to_string c) ^ ", ") in - (if n > 1 then "[" else "") ^ - (List.fold_right - g - (FuncEntry.get_args c) - ((if n > 1 then "]" else "") ^ " -> " ^ (Expr.to_string (FuncEntry.get_value c)) ^ ", ")) - ) in - List.fold_right f (get_entries x) ("else -> " ^ (Expr.to_string (get_else x)) ^ "]") - end - - let get_const_interp ( x : model ) ( f : func_decl ) = - if (FuncDecl.get_arity f) != 0 || - (sort_kind_of_int (Z3native.get_sort_kind (FuncDecl.gnc f) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) == ARRAY_SORT then - raise (Z3native.Exception "Non-zero arity functions and arrays have FunctionInterpretations as a model. Use FuncInterp.") - else - let np = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in - if (Z3native.is_null np) then - None - else - Some (expr_of_ptr (z3obj_gc x) np) - - let get_const_interp_e ( x : model ) ( a : expr ) = get_const_interp x (Expr.get_func_decl a) - - - let rec get_func_interp ( x : model ) ( f : func_decl ) = - let sk = (sort_kind_of_int (Z3native.get_sort_kind (z3obj_gnc x) (Z3native.get_range (FuncDecl.gnc f) (FuncDecl.gno f)))) in - if (FuncDecl.get_arity f) == 0 then - let n = Z3native.model_get_const_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) in - if (Z3native.is_null n) then - None - else - match sk with - | ARRAY_SORT -> - if not (Z3native.is_as_array (z3obj_gnc x) n) then - raise (Z3native.Exception "Argument was not an array constant") - else - let fd = Z3native.get_as_array_func_decl (z3obj_gnc x) n in - get_func_interp x (func_decl_of_ptr (z3obj_gc x) fd) - | _ -> raise (Z3native.Exception "Constant functions do not have a function interpretation; use ConstInterp"); - else - let n = (Z3native.model_get_func_interp (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f)) in - if (Z3native.is_null n) then None else Some (FuncInterp.create (z3obj_gc x) n) - - (** The number of constants that have an interpretation in the model. *) - let get_num_consts ( x : model ) = Z3native.model_get_num_consts (z3obj_gnc x) (z3obj_gno x) - - let get_const_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) - - let get_func_decls ( x : model ) = - let n = (get_num_consts x) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_decls ( x : model ) = - let n_funcs = (get_num_funcs x) in - let n_consts = (get_num_consts x ) in - let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in - let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in - (mk_list f n_funcs) @ (mk_list g n_consts) - - exception ModelEvaluationFailedException of string - - let eval ( x : model ) ( t : expr ) ( completion : bool ) = - let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in - if not r then - raise (ModelEvaluationFailedException "evaluation failed") - else - expr_of_ptr (z3obj_gc x) v - - let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = - eval x t completion - - let get_num_sorts ( x : model ) = Z3native.model_get_num_sorts (z3obj_gnc x) (z3obj_gno x) - - let get_sorts ( x : model ) = - let n = (get_num_sorts x) in - let f i = (sort_of_ptr (z3obj_gc x) (Z3native.model_get_sort (z3obj_gnc x) (z3obj_gno x) i)) in - mk_list f n - - let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in - let n = (AST.ASTVector.get_size n_univ) in - let f i = (AST.ASTVector.get n_univ i) in - mk_list f n - - let to_string ( x : model ) = Z3native.model_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Probe = -struct - type probe = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : probe = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.probe_inc_ref ; - dec_ref = Z3native.probe_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - - let apply ( x : probe ) ( g : Goal.goal ) = - Z3native.probe_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) - - let get_num_probes ( ctx : context ) = - Z3native.get_num_probes (context_gno ctx) - - let get_probe_names ( ctx : context ) = - let n = (get_num_probes ctx) in - let f i = (Z3native.get_probe_name (context_gno ctx) i) in - mk_list f n - - let get_probe_description ( ctx : context ) ( name : string ) = - Z3native.probe_get_descr (context_gno ctx) name - - let mk_probe ( ctx : context ) ( name : string ) = - (create ctx (Z3native.mk_probe (context_gno ctx) name)) - - let const ( ctx : context ) ( v : float ) = - (create ctx (Z3native.probe_const (context_gno ctx) v)) - - let lt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_lt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let gt ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_gt (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let le ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_le (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let ge ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_ge (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let eq ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_eq (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let and_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_and (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let or_ ( ctx : context ) ( p1 : probe ) ( p2 : probe ) = - (create ctx (Z3native.probe_or (context_gno ctx) (z3obj_gno p1) (z3obj_gno p2))) - - let not_ ( ctx : context ) ( p : probe ) = - (create ctx (Z3native.probe_not (context_gno ctx) (z3obj_gno p))) -end - - -module Tactic = -struct - type tactic = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : tactic = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.tactic_inc_ref ; - dec_ref = Z3native.tactic_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - module ApplyResult = - struct - type apply_result = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : apply_result = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.apply_result_inc_ref ; - dec_ref = Z3native.apply_result_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let get_num_subgoals ( x : apply_result ) = - Z3native.apply_result_get_num_subgoals (z3obj_gnc x) (z3obj_gno x) - - let get_subgoals ( x : apply_result ) = - let n = (get_num_subgoals x) in - let f i = Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get_subgoal ( x : apply_result ) ( i : int ) = - Goal.create (z3obj_gc x) (Z3native.apply_result_get_subgoal (z3obj_gnc x) (z3obj_gno x) i) - - let convert_model ( x : apply_result ) ( i : int ) ( m : Model.model ) = - Model.create (z3obj_gc x) (Z3native.apply_result_convert_model (z3obj_gnc x) (z3obj_gno x) i (z3obj_gno m)) - - let to_string ( x : apply_result ) = Z3native.apply_result_to_string (z3obj_gnc x) (z3obj_gno x) - end - - let get_help ( x : tactic ) = Z3native.tactic_get_help (z3obj_gnc x) (z3obj_gno x) - - let get_param_descrs ( x : tactic ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.tactic_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let apply ( x : tactic ) ( g : Goal.goal ) ( p : Params.params option ) = - match p with - | None -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g))) - | Some (pn) -> (ApplyResult.create (z3obj_gc x) (Z3native.tactic_apply_ex (z3obj_gnc x) (z3obj_gno x) (z3obj_gno g) (z3obj_gno pn))) - - let get_num_tactics ( ctx : context ) = Z3native.get_num_tactics (context_gno ctx) - - let get_tactic_names ( ctx : context ) = - let n = (get_num_tactics ctx ) in - let f i = (Z3native.get_tactic_name (context_gno ctx) i) in - mk_list f n - - let get_tactic_description ( ctx : context ) ( name : string ) = - Z3native.tactic_get_descr (context_gno ctx) name - - let mk_tactic ( ctx : context ) ( name : string ) = - create ctx (Z3native.mk_tactic (context_gno ctx) name) - - let and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) ( ts : tactic list ) = - let f p c = (match p with - | None -> (Some (z3obj_gno c)) - | Some(x) -> (Some (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno c) x))) in - match (List.fold_left f None ts) with - | None -> - create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - | Some(x) -> - let o = (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t2) x) in - create ctx (Z3native.tactic_and_then (context_gno ctx) (z3obj_gno t1) o) - - let or_else ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_or_else (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - - let try_for ( ctx : context ) ( t : tactic ) ( ms : int ) = - create ctx (Z3native.tactic_try_for (context_gno ctx) (z3obj_gno t) ms) - - let when_ ( ctx : context ) ( p : Probe.probe ) ( t : tactic ) = - create ctx (Z3native.tactic_when (context_gno ctx) (z3obj_gno p) (z3obj_gno t)) - - let cond ( ctx : context ) ( p : Probe.probe ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_cond (context_gno ctx) (z3obj_gno p) (z3obj_gno t1) (z3obj_gno t2)) - - let repeat ( ctx : context ) ( t : tactic ) ( max : int ) = - create ctx (Z3native.tactic_repeat (context_gno ctx) (z3obj_gno t) max) - - let skip ( ctx : context ) = - create ctx (Z3native.tactic_skip (context_gno ctx)) - - let fail ( ctx : context ) = - create ctx (Z3native.tactic_fail (context_gno ctx)) - - let fail_if ( ctx : context ) ( p : Probe.probe ) = - create ctx (Z3native.tactic_fail_if (context_gno ctx) (z3obj_gno p)) - - let fail_if_not_decided ( ctx : context ) = - create ctx (Z3native.tactic_fail_if_not_decided (context_gno ctx)) - - let using_params ( ctx : context ) ( t : tactic ) ( p : Params.params ) = - create ctx (Z3native.tactic_using_params (context_gno ctx) (z3obj_gno t) (z3obj_gno p)) - - let with_ ( ctx : context ) ( t : tactic ) ( p : Params.params ) = - using_params ctx t p - - let par_or ( ctx : context ) ( t : tactic list ) = - let f e = (z3obj_gno e) in - create ctx (Z3native.tactic_par_or (context_gno ctx) (List.length t) (Array.of_list (List.map f t))) - - let par_and_then ( ctx : context ) ( t1 : tactic ) ( t2 : tactic ) = - create ctx (Z3native.tactic_par_and_then (context_gno ctx) (z3obj_gno t1) (z3obj_gno t2)) - - let interrupt ( ctx : context ) = - Z3native.interrupt (context_gno ctx) -end - - -module Solver = -struct - type solver = z3_native_object - type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : solver = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.solver_inc_ref ; - dec_ref = Z3native.solver_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - let string_of_status ( s : status) = match s with - | UNSATISFIABLE -> "unsatisfiable" - | SATISFIABLE -> "satisfiable" - | _ -> "unknown" - - module Statistics = - struct - type statistics = z3_native_object - - let create ( ctx : context ) ( no : Z3native.ptr ) = - let res : statistics = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.stats_inc_ref ; - dec_ref = Z3native.stats_dec_ref } in - (z3obj_sno res ctx no) ; - (z3obj_create res) ; - res - - - module Entry = - struct - type statistics_entry = { - mutable m_key : string; - mutable m_is_int : bool ; - mutable m_is_float : bool ; - mutable m_int : int ; - mutable m_float : float } - - let create_si k v = - let res : statistics_entry = { - m_key = k ; - m_is_int = true ; - m_is_float = false ; - m_int = v ; - m_float = 0.0 - } in - res - - let create_sd k v = - let res : statistics_entry = { - m_key = k ; - m_is_int = false ; - m_is_float = true ; - m_int = 0 ; - m_float = v - } in - res - - - let get_key (x : statistics_entry) = x.m_key - let get_int (x : statistics_entry) = x.m_int - let get_float (x : statistics_entry) = x.m_float - let is_int (x : statistics_entry) = x.m_is_int - let is_float (x : statistics_entry) = x.m_is_float - let to_string_value (x : statistics_entry) = - if (is_int x) then - string_of_int (get_int x) - else if (is_float x) then - string_of_float (get_float x) - else - raise (Z3native.Exception "Unknown statistical entry type") - let to_string ( x : statistics_entry ) = (get_key x) ^ ": " ^ (to_string_value x) - end - - let to_string ( x : statistics ) = Z3native.stats_to_string (z3obj_gnc x) (z3obj_gno x) - - let get_size ( x : statistics ) = Z3native.stats_size (z3obj_gnc x) (z3obj_gno x) - - let get_entries ( x : statistics ) = - let n = (get_size x ) in - let f i = ( - let k = Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i in - if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then - (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) - else - (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) - ) in - mk_list f n - - let get_keys ( x : statistics ) = - let n = (get_size x) in - let f i = (Z3native.stats_get_key (z3obj_gnc x) (z3obj_gno x) i) in - mk_list f n - - let get ( x : statistics ) ( key : string ) = - let f p c = (if ((Entry.get_key c) == key) then (Some c) else p) in - List.fold_left f None (get_entries x) - end - - let get_help ( x : solver ) = Z3native.solver_get_help (z3obj_gnc x) (z3obj_gno x) - - let set_parameters ( x : solver ) ( p : Params.params )= - Z3native.solver_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - - let get_param_descrs ( x : solver ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.solver_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let get_num_scopes ( x : solver ) = Z3native.solver_get_num_scopes (z3obj_gnc x) (z3obj_gno x) - - let push ( x : solver ) = Z3native.solver_push (z3obj_gnc x) (z3obj_gno x) - - let pop ( x : solver ) ( n : int ) = Z3native.solver_pop (z3obj_gnc x) (z3obj_gno x) n - - let reset ( x : solver ) = Z3native.solver_reset (z3obj_gnc x) (z3obj_gno x) - - let assert_ ( x : solver ) ( constraints : Boolean.bool_expr list ) = - let f e = (Z3native.solver_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in - ignore (List.map f constraints) - - let assert_and_track_a ( x : solver ) ( cs : Boolean.bool_expr list ) ( ps : Boolean.bool_expr list ) = - if ((List.length cs) != (List.length ps)) then - raise (Z3native.Exception "Argument size mismatch") - else - let f a b = (Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno a) (Boolean.gno b)) in - ignore (List.iter2 f cs ps) - - let assert_and_track ( x : solver ) ( c : Boolean.bool_expr ) ( p : Boolean.bool_expr ) = - Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Boolean.gno c) (Boolean.gno p) - - let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - (AST.ASTVector.get_size a) - - let get_assertions ( x : solver ) = - let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size a) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in - mk_list f n - - let check ( x : solver ) ( assumptions : Boolean.bool_expr list ) = - let r = - if ((List.length assumptions) == 0) then - lbool_of_int (Z3native.solver_check (z3obj_gnc x) (z3obj_gno x)) - else - let f x = (Expr.gno (Boolean.expr_of_bool_expr x)) in - lbool_of_int (Z3native.solver_check_assumptions (z3obj_gnc x) (z3obj_gno x) (List.length assumptions) (Array.of_list (List.map f assumptions))) - in - match r with - | L_TRUE -> SATISFIABLE - | L_FALSE -> UNSATISFIABLE - | _ -> UNKNOWN - - let get_model ( x : solver ) = - let q = Z3native.solver_get_model (z3obj_gnc x) (z3obj_gno x) in - if (Z3native.is_null q) then - None - else - Some (Model.create (z3obj_gc x) q) - - let get_proof ( x : solver ) = - let q = Z3native.solver_get_proof (z3obj_gnc x) (z3obj_gno x) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in - let n = (AST.ASTVector.get_size cn) in - let f i = (AST.ASTVector.get cn i) in - mk_list f n - - let get_reason_unknown ( x : solver ) = Z3native.solver_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - - let get_statistics ( x : solver ) = - (Statistics.create (z3obj_gc x) (Z3native.solver_get_statistics (z3obj_gnc x) (z3obj_gno x))) - - let mk_solver ( ctx : context ) ( logic : Symbol.symbol option ) = - match logic with - | None -> (create ctx (Z3native.mk_solver (context_gno ctx))) - | Some (x) -> (create ctx (Z3native.mk_solver_for_logic (context_gno ctx) (Symbol.gno x))) - - let mk_solver_s ( ctx : context ) ( logic : string ) = - mk_solver ctx (Some (Symbol.mk_string ctx logic)) - - let mk_simple_solver ( ctx : context ) = - (create ctx (Z3native.mk_simple_solver (context_gno ctx))) - - let mk_solver_t ( ctx : context ) ( t : Tactic.tactic ) = - (create ctx (Z3native.mk_solver_from_tactic (context_gno ctx) (z3obj_gno t))) - - let to_string ( x : solver ) = Z3native.solver_to_string (z3obj_gnc x) (z3obj_gno x) -end - - -module Fixedpoint = -struct - type fixedpoint = z3_native_object - - let create ( ctx : context ) = - let res : fixedpoint = { m_ctx = ctx ; - m_n_obj = null ; - inc_ref = Z3native.fixedpoint_inc_ref ; - dec_ref = Z3native.fixedpoint_dec_ref } in - (z3obj_sno res ctx (Z3native.mk_fixedpoint (context_gno ctx))) ; - (z3obj_create res) ; - res - - - let get_help ( x : fixedpoint ) = - Z3native.fixedpoint_get_help (z3obj_gnc x) (z3obj_gno x) - - let set_params ( x : fixedpoint ) ( p : Params.params )= - Z3native.fixedpoint_set_params (z3obj_gnc x) (z3obj_gno x) (z3obj_gno p) - - let get_param_descrs ( x : fixedpoint ) = - Params.ParamDescrs.param_descrs_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_param_descrs (z3obj_gnc x) (z3obj_gno x)) - - let assert_ ( x : fixedpoint ) ( constraints : Boolean.bool_expr list ) = - let f e = (Z3native.fixedpoint_assert (z3obj_gnc x) (z3obj_gno x) (Boolean.gno e)) in - ignore (List.map f constraints) ; - () - - let register_relation ( x : fixedpoint ) ( f : func_decl ) = - Z3native.fixedpoint_register_relation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) - - let add_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol option ) = - match name with - | None -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) null - | Some(y) -> Z3native.fixedpoint_add_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno y) - - let add_fact ( x : fixedpoint ) ( pred : func_decl ) ( args : int list ) = - Z3native.fixedpoint_add_fact (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno pred) (List.length args) (Array.of_list args) - - let query ( x : fixedpoint ) ( query : Boolean.bool_expr ) = - match (lbool_of_int (Z3native.fixedpoint_query (z3obj_gnc x) (z3obj_gno x) (Boolean.gno query))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN - - let query_r ( x : fixedpoint ) ( relations : func_decl list ) = - let f x = ptr_of_ast (ast_of_func_decl x) in - match (lbool_of_int (Z3native.fixedpoint_query_relations (z3obj_gnc x) (z3obj_gno x) (List.length relations) (Array.of_list (List.map f relations)))) with - | L_TRUE -> Solver.SATISFIABLE - | L_FALSE -> Solver.UNSATISFIABLE - | _ -> Solver.UNKNOWN - - let push ( x : fixedpoint ) = - Z3native.fixedpoint_push (z3obj_gnc x) (z3obj_gno x) - - let pop ( x : fixedpoint ) = - Z3native.fixedpoint_pop (z3obj_gnc x) (z3obj_gno x) - - let update_rule ( x : fixedpoint ) ( rule : Boolean.bool_expr ) ( name : Symbol.symbol ) = - Z3native.fixedpoint_update_rule (z3obj_gnc x) (z3obj_gno x) (Boolean.gno rule) (Symbol.gno name) - - let get_answer ( x : fixedpoint ) = - let q = (Z3native.fixedpoint_get_answer (z3obj_gnc x) (z3obj_gno x)) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let get_reason_unknown ( x : fixedpoint ) = - Z3native.fixedpoint_get_reason_unknown (z3obj_gnc x) (z3obj_gno x) - - let get_num_levels ( x : fixedpoint ) ( predicate : func_decl ) = - Z3native.fixedpoint_get_num_levels (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno predicate) - - let get_cover_delta ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) = - let q = (Z3native.fixedpoint_get_cover_delta (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate)) in - if (Z3native.is_null q) then - None - else - Some (expr_of_ptr (z3obj_gc x) q) - - let add_cover ( x : fixedpoint ) ( level : int ) ( predicate : func_decl ) ( property : expr ) = - Z3native.fixedpoint_add_cover (z3obj_gnc x) (z3obj_gno x) level (FuncDecl.gno predicate) (Expr.gno property) - - let to_string ( x : fixedpoint ) = Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) 0 [||] - - let set_predicate_representation ( x : fixedpoint ) ( f : func_decl ) ( kinds : Symbol.symbol list ) = - Z3native.fixedpoint_set_predicate_representation (z3obj_gnc x) (z3obj_gno x) (FuncDecl.gno f) (List.length kinds) (Symbol.symbol_lton kinds) - - let to_string_q ( x : fixedpoint ) ( queries : Boolean.bool_expr list ) = - let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in - Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) - - let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - mk_list f n - - let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in - let n = (AST.ASTVector.get_size v) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in - mk_list f n - - let mk_fixedpoint ( ctx : context ) = create ctx -end - -module Options = -struct - - let update_param_value ( ctx : context ) ( id : string) ( value : string )= - Z3native.update_param_value (context_gno ctx) id value - - let get_param_value ( ctx : context ) ( id : string ) = - let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in - if not r then - None - else - Some v - - let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = - Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) - - let toggle_warning_messages ( enabled: bool ) = - Z3native.toggle_warning_messages enabled -end - - -module SMT = -struct - let benchmark_to_smtstring ( ctx : context ) ( name : string ) ( logic : string ) ( status : string ) ( attributes : string ) ( assumptions : Boolean.bool_expr list ) ( formula : Boolean.bool_expr ) = - Z3native.benchmark_to_smtlib_string (context_gno ctx) name logic status attributes - (List.length assumptions) (let f x = ptr_of_expr (Boolean.expr_of_bool_expr x) in (Array.of_list (List.map f assumptions))) - (Boolean.gno formula) - - let parse_smtlib_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Z3native.parse_smtlib_string (context_gno ctx) str - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) - - let parse_smtlib_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Z3native.parse_smtlib_file (context_gno ctx) file_name - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))) - - let get_num_smtlib_formulas ( ctx : context ) = Z3native.get_smtlib_num_formulas (context_gno ctx) - - let get_smtlib_formulas ( ctx : context ) = - let n = (get_num_smtlib_formulas ctx ) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_formula (context_gno ctx) i)) in - mk_list f n - - let get_num_smtlib_assumptions ( ctx : context ) = Z3native.get_smtlib_num_assumptions (context_gno ctx) - - let get_smtlib_assumptions ( ctx : context ) = - let n = (get_num_smtlib_assumptions ctx ) in - let f i = Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.get_smtlib_assumption (context_gno ctx) i)) in - mk_list f n - - let get_num_smtlib_decls ( ctx : context ) = Z3native.get_smtlib_num_decls (context_gno ctx) - - let get_smtlib_decls ( ctx : context ) = - let n = (get_num_smtlib_decls ctx) in - let f i = func_decl_of_ptr ctx (Z3native.get_smtlib_decl (context_gno ctx) i) in - mk_list f n - - let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) - - let get_smtlib_sorts ( ctx : context ) = - let n = (get_num_smtlib_sorts ctx) in - let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in - mk_list f n - - let parse_smtlib2_string ( ctx : context ) ( str : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) str - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) - - let parse_smtlib2_file ( ctx : context ) ( file_name : string ) ( sort_names : Symbol.symbol list ) ( sorts : sort list ) ( decl_names : Symbol.symbol list ) ( decls : func_decl list ) = - let csn = (List.length sort_names) in - let cs = (List.length sorts) in - let cdn = (List.length decl_names) in - let cd = (List.length decls) in - if (csn != cs || cdn != cd) then - raise (Z3native.Exception "Argument size mismatch") - else - Boolean.bool_expr_of_expr (expr_of_ptr ctx (Z3native.parse_smtlib2_string (context_gno ctx) file_name - cs - (Symbol.symbol_lton sort_names) - (sort_lton sorts) - cd - (Symbol.symbol_lton decl_names) - (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) -end - - -let set_global_param ( id : string ) ( value : string ) = - (Z3native.global_param_set id value) - -let get_global_param ( id : string ) = - let (r, v) = (Z3native.global_param_get id) in - if not r then - None - else - Some v - -let global_param_reset_all = - Z3native.global_param_reset_all diff --git a/src/api/ml/z3_rich.mli b/src/api/ml/z3_rich.mli deleted file mode 100644 index f2ecd326d..000000000 --- a/src/api/ml/z3_rich.mli +++ /dev/null @@ -1,3071 +0,0 @@ -(** - The Z3 ML/Ocaml Interface. - - Copyright (C) 2012 Microsoft Corporation - @author CM Wintersteiger (cwinter) 2012-12-17 - - NOTE: This is the *rich* version of the interface, using more - type information directly in the type system. Coercion functions - are provided to tran coerce on type into another where applicable. -*) - -(** Context objects. - - Most interactions with Z3 are interpreted in some context; many users will only - require one such object, but power users may require more than one. To start using - Z3, do - - - let ctx = (mk_context []) in - (...) - - - where a list of pairs of strings may be passed to set options on - the context, e.g., like so: - - - let cfg = [("model", "true"); ("...", "...")] in - let ctx = (mk_context cfg) in - (...) - -*) -type context - -(** Create a context object *) -val mk_context : (string * string) list -> context - -(** 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. *) -module Log : -sig - (** Open an interaction log file. - @return True if opening the log file succeeds, false otherwise. *) - (* CMW: "open" seems to be a reserved keyword? *) - val open_ : string -> bool - - (** Closes the interaction log. *) - val close : unit - - (** Appends a user-provided string to the interaction log. *) - val append : string -> unit -end - -(** Version information *) -module Version : -sig - (** The major version. *) - val major : int - - (** The minor version. *) - val minor : int - - (** The build version. *) - val build : int - - (** The revision. *) - val revision : int - - (** A string representation of the version information. *) - val to_string : string -end - -(** Symbols are used to name several term and type constructors *) -module Symbol : -sig - (** Numbered Symbols *) - type int_symbol - - (** Named Symbols *) - type string_symbol - - (** Symbols *) - type symbol = S_Int of int_symbol | S_Str of string_symbol - - (** The kind of the symbol (int or string) *) - val kind : symbol -> Z3enums.symbol_kind - - (** Indicates whether the symbol is of Int kind *) - val is_int_symbol : symbol -> bool - - (** Indicates whether the symbol is of string kind. *) - val is_string_symbol : symbol -> bool - - (** The int value of the symbol. *) - val get_int : int_symbol -> int - - (** The string value of the symbol. *) - val get_string : string_symbol -> string - - (** A string representation of the symbol. *) - val to_string : symbol -> string - - (** 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. *) - val mk_int : context -> int -> symbol - - (** Creates a new symbol using a string. *) - val mk_string : context -> string -> symbol - - (** Create a list of symbols. *) - val mk_ints : context -> int list -> symbol list - - (** Create a list of symbols. *) - val mk_strings : context -> string list -> symbol list -end - -(** The abstract syntax tree (AST) module *) -module AST : -sig - type ast - - (** Vectors of ASTs *) - module ASTVector : - sig - type ast_vector - - (** The size of the vector *) - val get_size : ast_vector -> int - - (** - Retrieves the i-th object in the vector. - @return An AST *) - val get : ast_vector -> int -> ast - - (** Sets the i-th object in the vector. *) - val set : ast_vector -> int -> ast -> unit - - (** Resize the vector to a new size. *) - val resize : ast_vector -> int -> unit - - (** Add an ast to the back of the vector. The size - is increased by 1. *) - val push : ast_vector -> ast -> unit - - (** Translates all ASTs in the vector to another context. - @return A new ASTVector *) - val translate : ast_vector -> context -> ast_vector - - (** Retrieves a string representation of the vector. *) - val to_string : ast_vector -> string - end - - (** Map from AST to AST *) - module ASTMap : - sig - type ast_map - - (** Checks whether the map contains a key. - @return True if the key in the map, false otherwise. *) - val contains : ast_map -> ast -> bool - - (** Finds the value associated with the key. - This function signs an error when the key is not a key in the map. *) - val find : ast_map -> ast -> ast - - (** Stores or replaces a new key/value pair in the map. *) - val insert : ast_map -> ast -> ast -> unit - - (** Erases the key from the map.*) - val erase : ast_map -> ast -> unit - - (** Removes all keys from the map. *) - val reset : ast_map -> unit - - (** The size of the map *) - val get_size : ast_map -> int - - (** The keys stored in the map. *) - val get_keys : ast_map -> ast list - - (** Retrieves a string representation of the map.*) - val to_string : ast_map -> string - end - - (** The AST's hash code. - @return A hash code *) - val get_hash_code : ast -> int - - (** A unique identifier for the AST (unique among all ASTs). *) - val get_id : ast -> int - - (** The kind of the AST. *) - val get_ast_kind : ast -> Z3enums.ast_kind - - (** Indicates whether the AST is an Expr *) - val is_expr : ast -> bool - - (** Indicates whether the AST is a bound variable*) - val is_var : ast -> bool - - (** Indicates whether the AST is a Quantifier *) - val is_quantifier : ast -> bool - - (** Indicates whether the AST is a Sort *) - val is_sort : ast -> bool - - (** Indicates whether the AST is a func_decl *) - val is_func_decl : ast -> bool - - (** A string representation of the AST. *) - val to_string : ast -> string - - (** A string representation of the AST in s-expression notation. *) - val to_sexpr : ast -> string - - (** Comparison operator. - @return True if the two ast's are from the same context - and represent the same sort; false otherwise. *) - val ( = ) : ast -> ast -> bool - - (** Object Comparison. - @return Negative if the first ast should be sorted before the second, positive if after else zero. *) - val compare : ast -> ast -> int - - (** Operator < *) - val ( < ) : ast -> ast -> int - - (** Translates (copies) the AST to another context. - @return A copy of the AST which is associated with the other context. *) - val translate : ast -> context -> ast - - (** Wraps an AST. - - This function is used for transitions between native and - managed objects. Note that the native ast that is passed must be a - native object obtained from Z3 (e.g., through {!unwrap_ast}) - and that it must have a correct reference count (see e.g., - Z3native.inc_ref). *) - val wrap_ast : context -> Z3native.z3_ast -> ast - - (** 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., - Z3native.inc_ref). - {!wrap_ast} *) - val unwrap_ast : ast -> Z3native.ptr -end - -(** The Sort module implements type information for ASTs *) -module Sort : -sig - (** Sorts *) - type sort = Sort of AST.ast - - (** Uninterpreted Sorts *) - type uninterpreted_sort = UninterpretedSort of sort - - val ast_of_sort : sort -> AST.ast - val sort_of_uninterpreted_sort : uninterpreted_sort -> sort - val uninterpreted_sort_of_sort : sort -> uninterpreted_sort - - (** Comparison operator. - @return True if the two sorts are from the same context - and represent the same sort; false otherwise. *) - val ( = ) : sort -> sort -> bool - - (** Returns a unique identifier for the sort. *) - val get_id : sort -> int - - (** The kind of the sort. *) - val get_sort_kind : sort -> Z3enums.sort_kind - - (** The name of the sort *) - val get_name : sort -> Symbol.symbol - - (** A string representation of the sort. *) - val to_string : sort -> string - - (** Create a new uninterpreted sort. *) - val mk_uninterpreted : context -> Symbol.symbol -> uninterpreted_sort - - (** Create a new uninterpreted sort. *) - val mk_uninterpreted_s : context -> string -> uninterpreted_sort -end - -(** Function declarations *) -module rec FuncDecl : -sig - type func_decl = FuncDecl of AST.ast - - val ast_of_func_decl : FuncDecl.func_decl -> AST.ast - - (** Parameters of Func_Decls *) - module Parameter : - sig - (** Parameters of func_decls *) - type parameter = - P_Int of int - | P_Dbl of float - | P_Sym of Symbol.symbol - | P_Srt of Sort.sort - | P_Ast of AST.ast - | P_Fdl of func_decl - | P_Rat of string - - (** The kind of the parameter. *) - val get_kind : parameter -> Z3enums.parameter_kind - - (** The int value of the parameter.*) - val get_int : parameter -> int - - (** The double value of the parameter.*) - val get_float : parameter -> float - - (** The Symbol.Symbol value of the parameter.*) - val get_symbol : parameter -> Symbol.symbol - - (** The Sort value of the parameter.*) - val get_sort : parameter -> Sort.sort - - (** The AST value of the parameter.*) - val get_ast : parameter -> AST.ast - - (** The FunctionDeclaration value of the parameter.*) - val get_func_decl : parameter -> func_decl - - (** The rational string value of the parameter.*) - val get_rational : parameter -> string - end - - (** Creates a new function declaration. *) - val mk_func_decl : context -> Symbol.symbol -> Sort.sort list -> Sort.sort -> func_decl - - (** Creates a new function declaration. *) - val mk_func_decl_s : context -> string -> Sort.sort list -> Sort.sort -> func_decl - (** Creates a fresh function declaration with a name prefixed with a prefix string. *) - - val mk_fresh_func_decl : context -> string -> Sort.sort list -> Sort.sort -> func_decl - - (** Creates a new constant function declaration. *) - val mk_const_decl : context -> Symbol.symbol -> Sort.sort -> func_decl - - (** Creates a new constant function declaration. *) - val mk_const_decl_s : context -> string -> Sort.sort -> func_decl - - (** Creates a fresh constant function declaration with a name prefixed with a prefix string. - {!mk_func_decl} - {!mk_func_decl} *) - val mk_fresh_const_decl : context -> string -> Sort.sort -> func_decl - - (** Comparison operator. - @return True if a and b are from the same context and represent the same func_decl; false otherwise. *) - val ( = ) : func_decl -> func_decl -> bool - - (** A string representations of the function declaration. *) - val to_string : func_decl -> string - - (** Returns a unique identifier for the function declaration. *) - val get_id : func_decl -> int - - (** The arity of the function declaration *) - val get_arity : func_decl -> int - - (** The size of the domain of the function declaration - {!get_arity} *) - val get_domain_size : func_decl -> int - - (** The domain of the function declaration *) - val get_domain : func_decl -> Sort.sort list - - (** The range of the function declaration *) - val get_range : func_decl -> Sort.sort - - (** The kind of the function declaration. *) - val get_decl_kind : func_decl -> Z3enums.decl_kind - - (** The name of the function declaration*) - val get_name : func_decl -> Symbol.symbol - - (** The number of parameters of the function declaration *) - val get_num_parameters : func_decl -> int - - (** The parameters of the function declaration *) - val get_parameters : func_decl -> Parameter.parameter list - - (** Create expression that applies function to arguments. *) - val apply : func_decl -> Expr.expr list -> Expr.expr -end - -(** Parameter sets (of Solvers, Tactics, ...) - - A Params objects represents a configuration in the form of Symbol.symbol/value pairs. *) -and Params : -sig - type params - - (** ParamDescrs describe sets of parameters (of Solvers, Tactics, ...) *) - module ParamDescrs : - sig - type param_descrs - - (** Validate a set of parameters. *) - val validate : param_descrs -> params -> unit - - (** Retrieve kind of parameter. *) - val get_kind : param_descrs -> Symbol.symbol -> Z3enums.param_kind - - (** Retrieve all names of parameters. *) - val get_names : param_descrs -> Symbol.symbol list - - (** The size of the ParamDescrs. *) - val get_size : param_descrs -> int - - (** Retrieves a string representation of the ParamDescrs. *) - val to_string : param_descrs -> string - end - - (** Adds a parameter setting. *) - val add_bool : params -> Symbol.symbol -> bool -> unit - - (** Adds a parameter setting. *) - val add_int : params -> Symbol.symbol -> int -> unit - - (** Adds a parameter setting. *) - val add_double : params -> Symbol.symbol -> float -> unit - - (** Adds a parameter setting. *) - val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit - - (** Adds a parameter setting. *) - val add_s_bool : params -> string -> bool -> unit - - (** Adds a parameter setting. *) - val add_s_int : params -> string -> int -> unit - - (** Adds a parameter setting. *) - val add_s_double : params -> string -> float -> unit - - (** Adds a parameter setting. *) - val add_s_symbol : params -> string -> Symbol.symbol -> unit - - (** Creates a new parameter set *) - val mk_params : context -> params - - (** A string representation of the parameter set. *) - val to_string : params -> string -end - -(** General Expressions (terms) *) -and Expr : -sig - type expr = Expr of AST.ast - - val ast_of_expr : Expr.expr -> AST.ast - val expr_of_ast : AST.ast -> Expr.expr - - (** Returns a simplified version of the expression. - {!get_simplify_help} *) - val simplify : Expr.expr -> Params.params option -> expr - - (** A string describing all available parameters to Expr.Simplify. *) - val get_simplify_help : context -> string - - (** Retrieves parameter descriptions for simplifier. *) - val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs - - (** The function declaration of the function that is applied in this expression. *) - val get_func_decl : Expr.expr -> FuncDecl.func_decl - - (** Indicates whether the expression is the true or false expression - or something else (L_UNDEF). *) - val get_bool_value : Expr.expr -> Z3enums.lbool - - (** The number of arguments of the expression. *) - val get_num_args : Expr.expr -> int - - (** The arguments of the expression. *) - val get_args : Expr.expr -> Expr.expr list - - (** Update the arguments of the expression using an array of expressions. - The number of new arguments should coincide with the current number of arguments. *) - val update : Expr.expr -> Expr.expr list -> expr - - (** 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]. *) - val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr - - (** Substitute every occurrence of from in the expression with to. - {!substitute} *) - val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr - - (** Substitute the free variables in the expression with the expressions in the expr array - - For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) - val substitute_vars : Expr.expr -> Expr.expr list -> expr - - (** Translates (copies) the term to another context. - @return A copy of the term which is associated with the other context *) - val translate : Expr.expr -> context -> expr - - (** Returns a string representation of the expression. *) - val to_string : Expr.expr -> string - - (** Indicates whether the term is a numeral *) - val is_numeral : Expr.expr -> bool - - (** Indicates whether the term is well-sorted. - @return True if the term is well-sorted, false otherwise. *) - val is_well_sorted : Expr.expr -> bool - - (** The Sort of the term. *) - val get_sort : Expr.expr -> Sort.sort - - (** Indicates whether the term has Boolean sort. *) - val is_bool : Expr.expr -> bool - - (** Indicates whether the term represents a constant. *) - val is_const : Expr.expr -> bool - - (** Indicates whether the term is the constant true. *) - val is_true : Expr.expr -> bool - - (** Indicates whether the term is the constant false. *) - val is_false : Expr.expr -> bool - - (** Indicates whether the term is an equality predicate. *) - val is_eq : Expr.expr -> bool - - (** Indicates whether the term is an n-ary distinct predicate (every argument is mutually distinct). *) - val is_distinct : Expr.expr -> bool - - (** Indicates whether the term is a ternary if-then-else term *) - val is_ite : Expr.expr -> bool - - (** Indicates whether the term is an n-ary conjunction *) - val is_and : Expr.expr -> bool - - (** Indicates whether the term is an n-ary disjunction *) - val is_or : Expr.expr -> bool - - (** Indicates whether the term is an if-and-only-if (Boolean equivalence, binary) *) - val is_iff : Expr.expr -> bool - - (** Indicates whether the term is an exclusive or *) - val is_xor : Expr.expr -> bool - - (** Indicates whether the term is a negation *) - val is_not : Expr.expr -> bool - - (** Indicates whether the term is an implication *) - val is_implies : Expr.expr -> bool - - (** 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. *) - val is_label : Expr.expr -> bool - - (** 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. - let is_label_lit ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_LABEL_LIT) *) - val is_label_lit : Expr.expr -> bool - - (** 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. *) - val is_oeq : Expr.expr -> bool - - (** Creates a new constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - - (** Creates a new constant. *) - val mk_const_s : context -> string -> Sort.sort -> expr - - (** Creates a constant from the func_decl. *) - val mk_const_f : context -> FuncDecl.func_decl -> expr - - (** Creates a fresh constant with a name prefixed with a string. *) - val mk_fresh_const : context -> string -> Sort.sort -> expr - - (** Create a new function application. *) - val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr - - (** Create a numeral of a given sort. - @return A Term with the goven value and sort *) - val mk_numeral_string : context -> string -> Sort.sort -> expr - - (** Create a numeral 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. - @return A Term with the given value and sort *) - val mk_numeral_int : context -> int -> Sort.sort -> expr -end - -(** Boolean expressions *) -module Boolean : -sig - type bool_sort = BoolSort of Sort.sort - type bool_expr = BoolExpr of Expr.expr - - val expr_of_bool_expr : bool_expr -> Expr.expr - val sort_of_bool_sort : bool_sort -> Sort.sort - val bool_sort_of_sort : Sort.sort -> bool_sort - val bool_expr_of_expr : Expr.expr -> bool_expr - - (** Create a Boolean sort *) - val mk_sort : context -> bool_sort - - (** Create a Boolean constant. *) - val mk_const : context -> Symbol.symbol -> bool_expr - - (** Create a Boolean constant. *) - val mk_const_s : context -> string -> bool_expr - - (** The true Term. *) - val mk_true : context -> bool_expr - - (** The false Term. *) - val mk_false : context -> bool_expr - - (** Creates a Boolean value. *) - val mk_val : context -> bool -> bool_expr - - (** Creates the equality between two expr's. *) - val mk_eq : context -> Expr.expr -> Expr.expr -> bool_expr - - (** Creates a distinct term. *) - val mk_distinct : context -> Expr.expr list -> bool_expr - - (** Mk an expression representing not(a). *) - val mk_not : context -> bool_expr -> bool_expr - - (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) - val mk_ite : context -> bool_expr -> bool_expr -> bool_expr -> bool_expr - - (** Create an expression representing t1 iff t2. *) - val mk_iff : context -> bool_expr -> bool_expr -> bool_expr - - (** Create an expression representing t1 -> t2. *) - val mk_implies : context -> bool_expr -> bool_expr -> bool_expr - - (** Create an expression representing t1 xor t2. *) - val mk_xor : context -> bool_expr -> bool_expr -> bool_expr - - (** Create an expression representing the AND of args *) - val mk_and : context -> bool_expr list -> bool_expr - - (** Create an expression representing the OR of args *) - val mk_or : context -> bool_expr list -> bool_expr -end - -(** Quantifier expressions *) -module Quantifier : -sig - type quantifier = Quantifier of Expr.expr - - val expr_of_quantifier : quantifier -> Expr.expr - val quantifier_of_expr : Expr.expr -> quantifier - - (** Quantifier patterns - - 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. *) - module Pattern : - sig - type pattern = Pattern of AST.ast - - val ast_of_pattern : pattern -> AST.ast - val pattern_of_ast : AST.ast -> pattern - - (** The number of terms in the pattern. *) - val get_num_terms : pattern -> int - - (** The terms in the pattern. *) - val get_terms : pattern -> Expr.expr list - - (** A string representation of the pattern. *) - val to_string : pattern -> string - end - - - (** 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 : expr ) appears, the higher is its - index. *) - val get_index : Expr.expr -> int - - (** Indicates whether the quantifier is universal. *) - val is_universal : quantifier -> bool - - (** Indicates whether the quantifier is existential. *) - val is_existential : quantifier -> bool - - (** The weight of the quantifier. *) - val get_weight : quantifier -> int - - (** The number of patterns. *) - val get_num_patterns : quantifier -> int - - (** The patterns. *) - val get_patterns : quantifier -> Pattern.pattern list - - (** The number of no-patterns. *) - val get_num_no_patterns : quantifier -> int - - (** The no-patterns. *) - val get_no_patterns : quantifier -> Pattern.pattern list - - (** The number of bound variables. *) - val get_num_bound : quantifier -> int - - (** The symbols for the bound variables. *) - val get_bound_variable_names : quantifier -> Symbol.symbol list - - (** The sorts of the bound variables. *) - val get_bound_variable_sorts : quantifier -> Sort.sort list - - (** The body of the quantifier. *) - val get_body : quantifier -> Boolean.bool_expr - - (** Creates a new bound variable. *) - val mk_bound : context -> int -> Sort.sort -> Expr.expr - - (** Create a quantifier pattern. *) - val mk_pattern : context -> Expr.expr list -> Pattern.pattern - - (** Create a universal Quantifier. *) - val mk_forall : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a universal Quantifier. *) - val mk_forall_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create an existential Quantifier. *) - val mk_exists : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create an existential Quantifier. *) - val mk_exists_const : context -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a Quantifier. *) - val mk_quantifier : context -> Sort.sort list -> Symbol.symbol list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - - (** Create a Quantifier. *) - val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier -end - -(** Functions to manipulate Array expressions *) -module Array_ : -sig - type array_sort = ArraySort of Sort.sort - type array_expr = ArrayExpr of Expr.expr - - val sort_of_array_sort : array_sort -> Sort.sort - val array_sort_of_sort : Sort.sort -> array_sort - val expr_of_array_expr : array_expr -> Expr.expr - - val array_expr_of_expr : Expr.expr -> array_expr - - (** Create a new array sort. *) - val mk_sort : context -> Sort.sort -> Sort.sort -> 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. *) - val is_store : Expr.expr -> bool - - (** Indicates whether the term is an array select. *) - val is_select : Expr.expr -> bool - - (** 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. *) - val is_constant_array : Expr.expr -> bool - - (** Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. *) - val is_default_array : Expr.expr -> bool - - (** 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. *) - val is_array_map : Expr.expr -> bool - - (** 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. *) - val is_as_array : Expr.expr -> bool - - (** Indicates whether the term is of an array sort. *) - val is_array : Expr.expr -> bool - - (** The domain of the array sort. *) - val get_domain : array_sort -> Sort.sort - - (** The range of the array sort. *) - val get_range : array_sort -> Sort.sort - - (** Create an array constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> array_expr - - (** Create an array constant. *) - val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> array_expr - - (** 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. - {!Array_.mk_sort} - {!mk_store} *) - val mk_select : context -> array_expr -> Expr.expr -> array_expr - - (** 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). - {!Array_.mk_sort} - {!mk_select} *) - val mk_store : context -> array_expr -> Expr.expr -> Expr.expr -> array_expr - - (** Create a constant array. - - The resulting term is an array, such that a selecton an arbitrary index - produces the value v. - {!Array_.mk_sort} - {!mk_select} *) - val mk_const_array : context -> Sort.sort -> Expr.expr -> array_expr - - (** 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]. - {!Array_.mk_sort} - {!mk_select} - {!mk_store} *) - val mk_map : context -> FuncDecl.func_decl -> array_expr list -> array_expr - - (** Access the array default value. - - Produces the default range value, for arrays that can be represented as - finite maps with a default range value. *) - val mk_term_array : context -> array_expr -> array_expr -end - -(** Functions to manipulate Set expressions *) -module Set : -sig - type set_sort = SetSort of Sort.sort - - val sort_of_set_sort : set_sort -> Sort.sort - - (** Create a set type. *) - val mk_sort : context -> Sort.sort -> set_sort - - (** Indicates whether the term is set union *) - val is_union : Expr.expr -> bool - - (** Indicates whether the term is set intersection *) - val is_intersect : Expr.expr -> bool - - (** Indicates whether the term is set difference *) - val is_difference : Expr.expr -> bool - - (** Indicates whether the term is set complement *) - val is_complement : Expr.expr -> bool - - (** Indicates whether the term is set subset *) - val is_subset : Expr.expr -> bool - - (** Create an empty set. *) - val mk_empty : context -> Sort.sort -> Expr.expr - - (** Create the full set. *) - val mk_full : context -> Sort.sort -> Expr.expr - - (** Add an element to the set. *) - val mk_set_add : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Remove an element from a set. *) - val mk_del : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Take the union of a list of sets. *) - val mk_union : context -> Expr.expr list -> Expr.expr - - (** Take the intersection of a list of sets. *) - val mk_intersection : context -> Expr.expr list -> Expr.expr - - (** Take the difference between two sets. *) - val mk_difference : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Take the complement of a set. *) - val mk_complement : context -> Expr.expr -> Expr.expr - - (** Check for set membership. *) - val mk_membership : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Check for subsetness of sets. *) - val mk_subset : context -> Expr.expr -> Expr.expr -> Expr.expr -end - -(** Functions to manipulate Finite Domain expressions *) -module FiniteDomain : -sig - type finite_domain_sort = FiniteDomainSort of Sort.sort - - val sort_of_finite_domain_sort : finite_domain_sort -> Sort.sort - val finite_domain_sort_of_sort : Sort.sort -> finite_domain_sort - - (** Create a new finite domain sort. *) - val mk_sort : context -> Symbol.symbol -> int -> finite_domain_sort - - (** Create a new finite domain sort. *) - val mk_sort_s : context -> string -> int -> finite_domain_sort - - (** Indicates whether the term is of an array sort. *) - val is_finite_domain : Expr.expr -> bool - - (** Indicates whether the term is a less than predicate over a finite domain. *) - val is_lt : Expr.expr -> bool - - (** The size of the finite domain sort. *) - val get_size : finite_domain_sort -> int -end - - -(** Functions to manipulate Relation expressions *) -module Relation : -sig - type relation_sort = RelationSort of Sort.sort - - val sort_of_relation_sort : relation_sort -> Sort.sort - val relation_sort_of_sort : Sort.sort -> relation_sort - - (** Indicates whether the term is of a relation sort. *) - val is_relation : Expr.expr -> bool - - (** 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. *) - val is_store : Expr.expr -> bool - - (** Indicates whether the term is an empty relation *) - val is_empty : Expr.expr -> bool - - (** Indicates whether the term is a test for the emptiness of a relation *) - val is_is_empty : Expr.expr -> bool - - (** Indicates whether the term is a relational join *) - val is_join : Expr.expr -> bool - - (** Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. *) - val is_union : Expr.expr -> bool - - (** Indicates whether the term is the widening of two relations - The function takes two arguments. *) - val is_widen : Expr.expr -> bool - - (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. *) - val is_project : Expr.expr -> bool - - (** 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. *) - val is_filter : Expr.expr -> bool - - (** 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. *) - val is_negation_filter : Expr.expr -> bool - - (** 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. *) - val is_rename : Expr.expr -> bool - - (** Indicates whether the term is the complement of a relation *) - val is_complement : Expr.expr -> bool - - (** 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. *) - val is_select : Expr.expr -> bool - - (** 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 {!is_union} - to perform destructive updates to the first argument. *) - val is_clone : Expr.expr -> bool - - (** The arity of the relation sort. *) - val get_arity : relation_sort -> int - - (** The sorts of the columns of the relation sort. *) - val get_column_sorts : relation_sort -> relation_sort list -end - -(** Functions to manipulate Datatype expressions *) -module Datatype : -sig - type datatype_sort = DatatypeSort of Sort.sort - type datatype_expr = DatatypeExpr of Expr.expr - - val sort_of_datatype_sort : datatype_sort -> Sort.sort - val datatype_sort_of_sort : Sort.sort -> datatype_sort - val expr_of_datatype_expr : datatype_expr -> Expr.expr - val datatype_expr_of_expr : Expr.expr -> datatype_expr - - (** Datatype Constructors *) - module Constructor : - sig - type constructor - - (** The number of fields of the constructor. *) - val get_num_fields : constructor -> int - - (** The function declaration of the constructor. *) - val get_constructor_decl : constructor -> FuncDecl.func_decl - - (** The function declaration of the tester. *) - val get_tester_decl : constructor -> FuncDecl.func_decl - - (** The function declarations of the accessors *) - val get_accessor_decls : constructor -> FuncDecl.func_decl list - end - - (** Create a datatype 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. *) - val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor - - (** Create a datatype 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. *) - val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor - - (** Create a new datatype sort. *) - val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> datatype_sort - - (** Create a new datatype sort. *) - val mk_sort_s : context -> string -> Constructor.constructor list -> datatype_sort - - (** Create mutually recursive datatypes. *) - val mk_sorts : context -> Symbol.symbol list -> Constructor.constructor list list -> datatype_sort list - - (** Create mutually recursive data-types. *) - val mk_sorts_s : context -> string list -> Constructor.constructor list list -> datatype_sort list - - - (** The number of constructors of the datatype sort. *) - val get_num_constructors : datatype_sort -> int - - (** The constructors. *) - val get_constructors : datatype_sort -> FuncDecl.func_decl list - - (** The recognizers. *) - val get_recognizers : datatype_sort -> FuncDecl.func_decl list - - (** The constructor accessors. *) - val get_accessors : datatype_sort -> FuncDecl.func_decl list list -end - -(** Functions to manipulate Enumeration expressions *) -module Enumeration : -sig - type enum_sort = EnumSort of Sort.sort - - val sort_of_enum_sort : enum_sort -> Sort.sort - - (** Create a new enumeration sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> enum_sort - - (** Create a new enumeration sort. *) - val mk_sort_s : context -> string -> string list -> enum_sort - - (** The function declarations of the constants in the enumeration. *) - val get_const_decls : enum_sort -> FuncDecl.func_decl list - - (** The test predicates for the constants in the enumeration. *) - val get_tester_decls : enum_sort -> FuncDecl.func_decl list -end - -(** Functions to manipulate List expressions *) -module List_ : -sig - type list_sort = ListSort of Sort.sort - - val sort_of_list_sort : list_sort -> Sort.sort - - (** Create a new list sort. *) - val mk_sort : context -> Symbol.symbol -> Sort.sort -> list_sort - - (** Create a new list sort. *) - val mk_list_s : context -> string -> Sort.sort -> list_sort - - (** The declaration of the nil function of this list sort. *) - val get_nil_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the isNil function of this list sort. *) - val get_is_nil_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the cons function of this list sort. *) - val get_cons_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the isCons function of this list sort. *) - val get_is_cons_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the head function of this list sort. *) - val get_head_decl : list_sort -> FuncDecl.func_decl - - (** The declaration of the tail function of this list sort. *) - val get_tail_decl : list_sort -> FuncDecl.func_decl - - (** The empty list. *) - val nil : list_sort -> Expr.expr -end - -(** Functions to manipulate Tuple expressions *) -module Tuple : -sig - type tuple_sort = TupleSort of Sort.sort - - val sort_of_tuple_sort : tuple_sort -> Sort.sort - - (** Create a new tuple sort. *) - val mk_sort : context -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> tuple_sort - - (** The constructor function of the tuple. *) - val get_mk_decl : tuple_sort -> FuncDecl.func_decl - - (** The number of fields in the tuple. *) - val get_num_fields : tuple_sort -> int - - (** The field declarations. *) - val get_field_decls : tuple_sort -> FuncDecl.func_decl list -end - -(** Functions to manipulate arithmetic expressions *) -module rec Arithmetic : -sig - type arith_sort = ArithSort of Sort.sort - type arith_expr = ArithExpr of Expr.expr - - val sort_of_arith_sort : Arithmetic.arith_sort -> Sort.sort - val arith_sort_of_sort : Sort.sort -> Arithmetic.arith_sort - val expr_of_arith_expr : Arithmetic.arith_expr -> Expr.expr - val arith_expr_of_expr : Expr.expr -> Arithmetic.arith_expr - - (** Integer Arithmetic *) - module rec Integer : - sig - type int_sort = IntSort of arith_sort - type int_expr = IntExpr of arith_expr - type int_num = IntNum of int_expr - - val arith_sort_of_int_sort : Arithmetic.Integer.int_sort -> Arithmetic.arith_sort - val int_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Integer.int_sort - val arith_expr_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.arith_expr - val int_expr_of_int_num : Arithmetic.Integer.int_num -> Arithmetic.Integer.int_expr - val int_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Integer.int_expr - val int_num_of_int_expr : Arithmetic.Integer.int_expr -> Arithmetic.Integer.int_num - - (** Create a new integer sort. *) - val mk_sort : context -> int_sort - - (** Retrieve the int value. *) - val get_int : int_num -> int - - (** Returns a string representation of the numeral. *) - val to_string : int_num -> string - - (** Creates an integer constant. *) - val mk_const : context -> Symbol.symbol -> int_expr - - (** Creates an integer constant. *) - val mk_const_s : context -> string -> int_expr - - (** Create an expression representing t1 mod t2. - The arguments must have int type. *) - val mk_mod : context -> int_expr -> int_expr -> int_expr - - (** Create an expression representing t1 rem t2. - The arguments must have int type. *) - val mk_rem : context -> int_expr -> int_expr -> int_expr - - (** Create an integer numeral. *) - val mk_numeral_s : context -> string -> int_num - - (** Create an integer numeral. - @return A Term with the given value and sort Integer *) - val mk_numeral_i : context -> int -> int_num - - (** 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. *) - val mk_int2real : context -> int_expr -> Real.real_expr - - (** Create an n-bit bit-vector from an 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. *) - val mk_int2bv : context -> int -> int_expr -> BitVector.bitvec_expr - end - - (** Real Arithmetic *) - and Real : - sig - type real_sort = RealSort of arith_sort - type real_expr = RealExpr of arith_expr - type rat_num = RatNum of real_expr - - val arith_sort_of_real_sort : Arithmetic.Real.real_sort -> Arithmetic.arith_sort - val real_sort_of_arith_sort : Arithmetic.arith_sort -> Arithmetic.Real.real_sort - val arith_expr_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.arith_expr - val real_expr_of_rat_num : Arithmetic.Real.rat_num -> Arithmetic.Real.real_expr - val real_expr_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.Real.real_expr - val rat_num_of_real_expr : Arithmetic.Real.real_expr -> Arithmetic.Real.rat_num - - (** Create a real sort. *) - val mk_sort : context -> real_sort - - (** The numerator of a rational numeral. *) - val get_numerator : rat_num -> Integer.int_num - - (** The denominator of a rational numeral. *) - val get_denominator : rat_num -> Integer.int_num - - (** Returns a string representation in decimal notation. - The result has at most as many decimal places as indicated by the int argument.*) - val to_decimal_string : rat_num -> int -> string - - (** Returns a string representation of the numeral. *) - val to_string : rat_num -> string - - (** Creates a real constant. *) - val mk_const : context -> Symbol.symbol -> real_expr - - (** Creates a real constant. *) - val mk_const_s : context -> string -> real_expr - - (** Create a real numeral from a fraction. - @return A Term with rational value and sort Real - {!mk_numeral_s} *) - val mk_numeral_nd : context -> int -> int -> rat_num - - (** Create a real numeral. - @return A Term with the given value and sort Real *) - val mk_numeral_s : context -> string -> rat_num - - (** Create a real numeral. - @return A Term with the given value and sort Real *) - val mk_numeral_i : context -> int -> rat_num - - (** Creates an expression that checks whether a real number is an integer. *) - val mk_is_integer : context -> real_expr -> Boolean.bool_expr - - (** 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. *) - val mk_real2int : context -> real_expr -> Integer.int_expr - end - - (** Algebraic Numbers *) - and AlgebraicNumber : - sig - type algebraic_num = AlgebraicNum of arith_expr - - val arith_expr_of_algebraic_num : Arithmetic.AlgebraicNumber.algebraic_num -> Arithmetic.arith_expr - val algebraic_num_of_arith_expr : Arithmetic.arith_expr -> Arithmetic.AlgebraicNumber.algebraic_num - - (** Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) - val to_upper : algebraic_num -> int -> Real.rat_num - - (** Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) - val to_lower : algebraic_num -> int -> Real.rat_num - - (** Returns a string representation in decimal notation. - The result has at most as many decimal places as the int argument provided.*) - val to_decimal_string : algebraic_num -> int -> string - - (** Returns a string representation of the numeral. *) - val to_string : algebraic_num -> string - end - - (** Indicates whether the term is of integer sort. *) - val is_int : Expr.expr -> bool - - (** Indicates whether the term is an arithmetic numeral. *) - val is_arithmetic_numeral : Expr.expr -> bool - - (** Indicates whether the term is a less-than-or-equal *) - val is_le : Expr.expr -> bool - - (** Indicates whether the term is a greater-than-or-equal *) - val is_ge : Expr.expr -> bool - - (** Indicates whether the term is a less-than *) - val is_lt : Expr.expr -> bool - - (** Indicates whether the term is a greater-than *) - val is_gt : Expr.expr -> bool - - (** Indicates whether the term is addition (binary) *) - val is_add : Expr.expr -> bool - - (** Indicates whether the term is subtraction (binary) *) - val is_sub : Expr.expr -> bool - - (** Indicates whether the term is a unary minus *) - val is_uminus : Expr.expr -> bool - - (** Indicates whether the term is multiplication (binary) *) - val is_mul : Expr.expr -> bool - - (** Indicates whether the term is division (binary) *) - val is_div : Expr.expr -> bool - - (** Indicates whether the term is integer division (binary) *) - val is_idiv : Expr.expr -> bool - - (** Indicates whether the term is remainder (binary) *) - val is_remainder : Expr.expr -> bool - - (** Indicates whether the term is modulus (binary) *) - val is_modulus : Expr.expr -> bool - - (** Indicates whether the term is a coercion of integer to real (unary) *) - val is_inttoreal : Expr.expr -> bool - - (** Indicates whether the term is a coercion of real to integer (unary) *) - val is_real_to_int : Expr.expr -> bool - - (** Indicates whether the term is a check that tests whether a real is integral (unary) *) - val is_real_is_int : Expr.expr -> bool - - (** Indicates whether the term is of sort real. *) - val is_real : Expr.expr -> bool - - (** Indicates whether the term is an integer numeral. *) - val is_int_numeral : Expr.expr -> bool - - (** Indicates whether the term is a real numeral. *) - val is_rat_num : Expr.expr -> bool - - (** Indicates whether the term is an algebraic number *) - val is_algebraic_number : Expr.expr -> bool - - (** Create an expression representing t[0] + t[1] + .... *) - val mk_add : context -> arith_expr list -> arith_expr - - (** Create an expression representing t[0] * t[1] * .... *) - val mk_mul : context -> arith_expr list -> arith_expr - - (** Create an expression representing t[0] - t[1] - .... *) - val mk_sub : context -> arith_expr list -> arith_expr - - (** Create an expression representing -t. *) - val mk_unary_minus : context -> arith_expr -> arith_expr - - (** Create an expression representing t1 / t2. *) - val mk_div : context -> arith_expr -> arith_expr -> arith_expr - - (** Create an expression representing t1 ^ t2. *) - val mk_power : context -> arith_expr -> arith_expr -> arith_expr - - (** Create an expression representing t1 < t2 *) - val mk_lt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - - (** Create an expression representing t1 <= t2 *) - val mk_le : context -> arith_expr -> arith_expr -> Boolean.bool_expr - - (** Create an expression representing t1 > t2 *) - val mk_gt : context -> arith_expr -> arith_expr -> Boolean.bool_expr - - (** Create an expression representing t1 >= t2 *) - val mk_ge : context -> arith_expr -> arith_expr -> Boolean.bool_expr -end - -(** Functions to manipulate bit-vector expressions *) -and BitVector : -sig - type bitvec_sort = BitVecSort of Sort.sort - type bitvec_expr = BitVecExpr of Expr.expr - type bitvec_num = BitVecNum of bitvec_expr - - val sort_of_bitvec_sort : BitVector.bitvec_sort -> Sort.sort - val bitvec_sort_of_sort : Sort.sort -> BitVector.bitvec_sort - val expr_of_bitvec_expr : BitVector.bitvec_expr -> Expr.expr - val bitvec_expr_of_bitvec_num : BitVector.bitvec_num -> BitVector.bitvec_expr - val bitvec_expr_of_expr : Expr.expr -> BitVector.bitvec_expr - val bitvec_num_of_bitvec_expr : BitVector.bitvec_expr -> BitVector.bitvec_num - - (** Create a new bit-vector sort. *) - val mk_sort : context -> int -> bitvec_sort - - (** Indicates whether the terms is of bit-vector sort. *) - val is_bv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector numeral *) - val is_bv_numeral : Expr.expr -> bool - - (** Indicates whether the term is a one-bit bit-vector with value one *) - val is_bv_bit1 : Expr.expr -> bool - - (** Indicates whether the term is a one-bit bit-vector with value zero *) - val is_bv_bit0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unary minus *) - val is_bv_uminus : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector addition (binary) *) - val is_bv_add : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector subtraction (binary) *) - val is_bv_sub : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector multiplication (binary) *) - val is_bv_mul : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed division (binary) *) - val is_bv_sdiv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned division (binary) *) - val is_bv_udiv : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed remainder (binary) *) - val is_bv_SRem : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned remainder (binary) *) - val is_bv_urem : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed modulus *) - val is_bv_smod : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed division by zero *) - val is_bv_sdiv0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned division by zero *) - val is_bv_udiv0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed remainder by zero *) - val is_bv_srem0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector unsigned remainder by zero *) - val is_bv_urem0 : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector signed modulus by zero *) - val is_bv_smod0 : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector less-than-or-equal *) - val is_bv_ule : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector less-than-or-equal *) - val is_bv_sle : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector greater-than-or-equal *) - val is_bv_uge : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector greater-than-or-equal *) - val is_bv_sge : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector less-than *) - val is_bv_ult : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector less-than *) - val is_bv_slt : Expr.expr -> bool - - (** Indicates whether the term is an unsigned bit-vector greater-than *) - val is_bv_ugt : Expr.expr -> bool - - (** Indicates whether the term is a signed bit-vector greater-than *) - val is_bv_sgt : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise AND *) - val is_bv_and : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise OR *) - val is_bv_or : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NOT *) - val is_bv_not : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise XOR *) - val is_bv_xor : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NAND *) - val is_bv_nand : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise NOR *) - val is_bv_nor : Expr.expr -> bool - - (** Indicates whether the term is a bit-wise XNOR *) - val is_bv_xnor : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector concatenation (binary) *) - val is_bv_concat : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector sign extension *) - val is_bv_signextension : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector zero extension *) - val is_bv_zeroextension : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector extraction *) - val is_bv_extract : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector repetition *) - val is_bv_repeat : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector reduce OR *) - val is_bv_reduceor : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector reduce AND *) - val is_bv_reduceand : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector comparison *) - val is_bv_comp : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector shift left *) - val is_bv_shiftleft : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector logical shift right *) - val is_bv_shiftrightlogical : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector arithmetic shift left *) - val is_bv_shiftrightarithmetic : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector rotate left *) - val is_bv_rotateleft : Expr.expr -> bool - - (** Indicates whether the term is a bit-vector rotate right *) - val is_bv_rotateright : Expr.expr -> bool - - (** 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. *) - val is_bv_rotateleftextended : Expr.expr -> bool - - (** 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. *) - val is_bv_rotaterightextended : Expr.expr -> bool - - (** 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. *) - - (** 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. *) - val is_int_to_bv : Expr.expr -> bool - - (** 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. *) - val is_bv_to_int : Expr.expr -> bool - - (** 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))) *) - val is_bv_carry : Expr.expr -> bool - - (** 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) *) - val is_bv_xor3 : Expr.expr -> bool - - (** The size of a bit-vector sort. *) - val get_size : bitvec_sort -> int - - (** Retrieve the int value. *) - val get_int : bitvec_num -> int - - (** Returns a string representation of the numeral. *) - val to_string : bitvec_num -> string - - (** Creates a bit-vector constant. *) - val mk_const : context -> Symbol.symbol -> int -> bitvec_expr - - (** Creates a bit-vector constant. *) - val mk_const_s : context -> string -> int -> bitvec_expr - - (** Bitwise negation. - The argument must have a bit-vector sort. *) - val mk_not : context -> bitvec_expr -> Expr.expr - - (** Take conjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) - val mk_redand : context -> bitvec_expr -> Expr.expr - - (** Take disjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) - val mk_redor : context -> bitvec_expr -> Expr.expr - - (** Bitwise conjunction. - The arguments must have a bit-vector sort. *) - val mk_and : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise disjunction. - The arguments must have a bit-vector sort. *) - val mk_or : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise XOR. - The arguments must have a bit-vector sort. *) - val mk_xor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise NAND. - The arguments must have a bit-vector sort. *) - val mk_nand : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise NOR. - The arguments must have a bit-vector sort. *) - val mk_nor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bitwise XNOR. - The arguments must have a bit-vector sort. *) - val mk_xnor : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Standard two's complement unary minus. - The arguments must have a bit-vector sort. *) - val mk_neg : context -> bitvec_expr -> bitvec_expr - - (** Two's complement addition. - The arguments must have the same bit-vector sort. *) - val mk_add : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Two's complement subtraction. - The arguments must have the same bit-vector sort. *) - val mk_sub : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Two's complement multiplication. - The arguments must have the same bit-vector sort. *) - val mk_mul : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_udiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_sdiv : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_urem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_srem : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_smod : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Unsigned less-than - - The arguments must have the same bit-vector sort. *) - val mk_ult : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Two's complement signed less-than - - The arguments must have the same bit-vector sort. *) - val mk_slt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Unsigned less-than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_ule : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Two's complement signed less-than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_sle : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Unsigned greater than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_uge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Two's complement signed greater than or equal to. - - The arguments must have the same bit-vector sort. *) - val mk_sge : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Unsigned greater-than. - - The arguments must have the same bit-vector sort. *) - val mk_ugt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Two's complement signed greater-than. - - The arguments must have the same bit-vector sort. *) - val mk_sgt : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** 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). *) - val mk_concat : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Bit-vector extraction. - - Extract the bits between two limits from a bitvector of - size m to yield a new bitvector of size n, where - n = high - low + 1. *) - val mk_extract : context -> int -> int -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_sign_ext : context -> int -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_zero_ext : context -> int -> bitvec_expr -> bitvec_expr - - (** Bit-vector repetition. *) - val mk_repeat : context -> int -> bitvec_expr -> bitvec_expr - - (** Shift left. - - It is equivalent to multiplication by 2^x where \c x is the value of third 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.*) - val mk_shl : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Logical shift right - - It is equivalent to unsigned division by 2^x where \c x is the value of the third 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. *) - val mk_lshr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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. *) - val mk_ashr : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Rotate Left. - Rotate bits of \c t to the left \c i times. *) - val mk_rotate_left : context -> int -> bitvec_expr -> bitvec_expr - - (** Rotate Right. - Rotate bits of \c t to the right \c i times.*) - val mk_rotate_right : context -> int -> bitvec_expr -> bitvec_expr - - (** Rotate Left. - Rotate bits of the second argument to the left.*) - val mk_ext_rotate_left : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** Rotate Right. - Rotate bits of the second argument to the right. *) - val mk_ext_rotate_right : context -> bitvec_expr -> bitvec_expr -> bitvec_expr - - (** 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 the argument. - 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.*) - val mk_bv2int : context -> bitvec_expr -> bool -> Arithmetic.Integer.int_expr - - (** Create a predicate that checks that the bit-wise addition does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_add_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise addition does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_add_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise subtraction does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_sub_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise subtraction does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_sub_no_underflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise signed division does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_sdiv_no_overflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise negation does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_neg_no_overflow : context -> bitvec_expr -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise multiplication does not overflow. - - The arguments must be of bit-vector sort. *) - val mk_mul_no_overflow : context -> bitvec_expr -> bitvec_expr -> bool -> Boolean.bool_expr - - (** Create a predicate that checks that the bit-wise multiplication does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_mul_no_underflow : context -> bitvec_expr -> bitvec_expr -> Boolean.bool_expr - - (** Create a bit-vector numeral. *) - val mk_numeral : context -> string -> int -> bitvec_num -end - -(** Functions to manipulate proof expressions *) -module Proof : -sig - (** Indicates whether the term is a Proof for the expression 'true'. *) - val is_true : Expr.expr -> bool - - (** Indicates whether the term is a proof for a fact asserted by the user. *) - val is_asserted : Expr.expr -> bool - - (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) - val is_goal : Expr.expr -> bool - - (** 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). *) - val is_modus_ponens : Expr.expr -> bool - - (** 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'. *) - val is_reflexivity : Expr.expr -> bool - - (** 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. *) - val is_symmetry : Expr.expr -> bool - - (** 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) *) - val is_transitivity : Expr.expr -> bool - - (** 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. *) - val is_Transitivity_star : Expr.expr -> bool - - (** 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. *) - val is_monotonicity : Expr.expr -> bool - - (** 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)) *) - val is_quant_intro : Expr.expr -> bool - - (** 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. *) - val is_distributivity : Expr.expr -> bool - - (** 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 *) - val is_and_elimination : Expr.expr -> bool - - (** 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) *) - val is_or_elimination : Expr.expr -> bool - - (** 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 : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) *) - val is_rewrite : Expr.expr -> bool - - (** 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) *) - val is_rewrite_star : Expr.expr -> bool - - (** 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. *) - val is_pull_quant : Expr.expr -> bool - - (** 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 *) - val is_pull_quant_star : Expr.expr -> bool - - (** 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 *) - val is_push_quant : Expr.expr -> bool - - (** 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. *) - val is_elim_unused_vars : Expr.expr -> bool - - (** Indicates whether the term is a proof for destructive equality resolution - - A proof for destructive equality resolution: - (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. - - This proof object has no antecedents. - - Several variables can be eliminated simultaneously. *) - val is_der : Expr.expr -> bool - - (** Indicates whether the term is a proof for quantifier instantiation - - A proof of (or (not (forall (x) (P x))) (P a)) *) - val is_quant_inst : Expr.expr -> bool - - (** Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. *) - val is_hypothesis : Expr.expr -> bool - - (** 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. *) - val is_lemma : Expr.expr -> bool - - (** 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') *) - val is_unit_resolution : Expr.expr -> bool - - (** Indicates whether the term is a proof by iff-true - - T1: p - [iff-true T1]: (iff p true) *) - val is_iff_true : Expr.expr -> bool - - (** Indicates whether the term is a proof by iff-false - - T1: (not p) - [iff-false T1]: (iff p false) *) - val is_iff_false : Expr.expr -> bool - - (** 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. *) - val is_commutativity : Expr.expr -> bool - - (** 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). *) - val is_def_axiom : Expr.expr -> bool - - (** 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) *) - val is_def_intro : Expr.expr -> bool - - (** 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. *) - val is_apply_def : Expr.expr -> bool - - (** Indicates whether the term is a proof iff-oeq - - T1: (iff p q) - [iff~ T1]: (~ p q) *) - val is_iff_oeq : Expr.expr -> bool - - (** 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'. *) - val is_nnf_pos : Expr.expr -> bool - - (** 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'))) *) - val is_nnf_neg : Expr.expr -> bool - - (** 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. *) - val is_nnf_star : Expr.expr -> bool - - (** 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. *) - val is_cnf_star : Expr.expr -> bool - - (** Indicates whether the term is a proof for a Skolemization step - - Proof for: - - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) - - This proof object has no antecedents. *) - val is_skolemize : Expr.expr -> bool - - (** 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 *) - val is_modus_ponens_oeq : Expr.expr -> bool - - (** 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. *) - val is_theory_lemma : Expr.expr -> bool -end - -(** Goals - - A goal (aka problem). A goal is essentially a - of formulas, that can be solved and/or transformed using - tactics and solvers. *) -module Goal : -sig - type goal - - (** 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. *) - val get_precision : goal -> Z3enums.goal_prec - - (** Indicates whether the goal is precise. *) - val is_precise : goal -> bool - - (** Indicates whether the goal is an under-approximation. *) - val is_underapproximation : goal -> bool - - (** Indicates whether the goal is an over-approximation. *) - val is_overapproximation : goal -> bool - - (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) - val is_garbage : goal -> bool - - (** Adds the constraints to the given goal. *) - val assert_ : goal -> Boolean.bool_expr list -> unit - - (** Indicates whether the goal contains `false'. *) - val is_inconsistent : goal -> bool - - (** The depth of the goal. - This tracks how many transformations were applied to it. *) - val get_depth : goal -> int - - (** Erases all formulas from the given goal. *) - val reset : goal -> unit - - (** The number of formulas in the goal. *) - val get_size : goal -> int - - (** The formulas in the goal. *) - val get_formulas : goal -> Boolean.bool_expr list - - (** The number of formulas, subformulas and terms in the goal. *) - val get_num_exprs : goal -> int - - (** Indicates whether the goal is empty, and it is precise or the product of an under approximation. *) - val is_decided_sat : goal -> bool - - (** Indicates whether the goal contains `false', and it is precise or the product of an over approximation. *) - val is_decided_unsat : goal -> bool - - (** Translates (copies) the Goal to another context.. *) - val translate : goal -> context -> goal - - (** Simplifies the goal. Essentially invokes the `simplify' tactic on the goal. *) - val simplify : goal -> Params.params option -> goal - - (** Creates a new Goal. - - Note that the Context must have been created with proof generation support if - the fourth argument is set to true here. *) - val mk_goal : context -> bool -> bool -> bool -> goal - - (** A string representation of the Goal. *) - val to_string : goal -> string -end - -(** Models - - A Model contains interpretations (assignments) of constants and functions. *) -module Model : -sig - type model - - (** Function interpretations - - A function interpretation is represented as a finite map and an 'else'. - Each entry in the finite map represents the value of a function given a set of arguments. *) - module FuncInterp : - sig - type func_interp - - (** Function interpretations entries - - An Entry object represents an element in the finite map used to a function interpretation. *) - module FuncEntry : - sig - type func_entry - - (** Return the (symbolic) value of this entry. - *) - val get_value : func_entry -> Expr.expr - - (** The number of arguments of the entry. - *) - val get_num_args : func_entry -> int - - (** The arguments of the function entry. - *) - val get_args : func_entry -> Expr.expr list - - (** A string representation of the function entry. - *) - val to_string : func_entry -> string - end - - (** The number of entries in the function interpretation. *) - val get_num_entries : func_interp -> int - - (** The entries in the function interpretation *) - val get_entries : func_interp -> FuncEntry.func_entry list - - (** The (symbolic) `else' value of the function interpretation. *) - val get_else : func_interp -> Expr.expr - - (** The arity of the function interpretation *) - val get_arity : func_interp -> int - - (** A string representation of the function interpretation. *) - val to_string : func_interp -> string - end - - (** Retrieves the interpretation (the assignment) of a func_decl in the model. - An expression if the function has an interpretation in the model, null otherwise. *) - val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option - - (** Retrieves the interpretation (the assignment) of an expression in the model. - An expression if the constant has an interpretation in the model, null otherwise. *) - val get_const_interp_e : model -> Expr.expr -> Expr.expr option - - (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) - val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option - - (** The number of constant interpretations in the model. *) - val get_num_consts : model -> int - - (** The function declarations of the constants in the model. *) - val get_const_decls : model -> FuncDecl.func_decl list - - (** The number of function interpretations in the model. *) - val get_num_funcs : model -> int - - (** The function declarations of the function interpretations in the model. *) - val get_func_decls : model -> FuncDecl.func_decl list - - (** All symbols that have an interpretation in the model. *) - val get_decls : model -> FuncDecl.func_decl list - - (** A ModelEvaluationFailedException is thrown when an expression cannot be evaluated by the model. *) - exception ModelEvaluationFailedException of string - - (** Evaluates an expression in the current model. - - This function may fail if the argument contains quantifiers, - is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. - In this case a ModelEvaluationFailedException is thrown. - *) - val eval : model -> Expr.expr -> bool -> Expr.expr - - (** Alias for eval. *) - val evaluate : model -> Expr.expr -> bool -> Expr.expr - - (** The number of uninterpreted sorts that the model has an interpretation for. *) - val get_num_sorts : model -> int - - (** 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. - {!get_num_sorts} - {!sort_universe} *) - val get_sorts : model -> Sort.sort list - - (** The finite set of distinct values that represent the interpretation of a sort. - {!get_sorts} - @returns A list of expressions, where each is an element of the universe of the sort *) - val sort_universe : model -> Sort.sort -> AST.ast list - - (** Conversion of models to strings. - A string representation of the model. *) - val to_string : model -> string -end - -(** Probes - - 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. -*) -module Probe : -sig - type probe - - (** Execute the probe over the goal. - A probe always produce a double value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) - val apply : probe -> Goal.goal -> float - - (** The number of supported Probes. *) - val get_num_probes : context -> int - - (** The names of all supported Probes. *) - val get_probe_names : context -> string list - - (** Returns a string containing a description of the probe with the given name. *) - val get_probe_description : context -> string -> string - - (** Creates a new Probe. *) - val mk_probe : context -> string -> probe - - (** Create a probe that always evaluates to a float value. *) - val const : context -> float -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is less than the value returned by second argument *) - val lt : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is greater than the value returned by second argument *) - val gt : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is less than or equal the value returned by second argument *) - val le : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is greater than or equal the value returned by second argument *) - val ge : context -> probe -> probe -> probe - - - (** Create a probe that evaluates to "true" when the value returned by the first argument - is equal the value returned by second argument *) - val eq : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when both of two probes evaluate to "true". *) - val and_ : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when either of two probes evaluates to "true". *) - val or_ : context -> probe -> probe -> probe - - (** Create a probe that evaluates to "true" when another probe does not evaluate to "true". *) - val not_ : context -> probe -> probe -end - -(** Tactics - - Tactics are the basic building block for creating custom solvers for specific problem domains. - The complete list of tactics may be obtained using Context.get_num_tactics - and Context.get_tactic_names. - It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. -*) -module Tactic : -sig - type tactic - - (** Tactic application results - - ApplyResult objects represent the result of an application of a - tactic to a goal. It contains the subgoals that were produced. *) - module ApplyResult : - sig - type apply_result - - (** The number of Subgoals. *) - val get_num_subgoals : apply_result -> int - - (** Retrieves the subgoals from the apply_result. *) - val get_subgoals : apply_result -> Goal.goal list - - (** Retrieves a subgoal from the apply_result. *) - val get_subgoal : apply_result -> int -> Goal.goal - - (** Convert a model for a subgoal into a model for the original - goal g, that the ApplyResult was obtained from. - #return A model for g *) - val convert_model : apply_result -> int -> Model.model -> Model.model - - (** A string representation of the ApplyResult. *) - val to_string : apply_result -> string - end - - (** A string containing a description of parameters accepted by the tactic. *) - val get_help : tactic -> string - - (** Retrieves parameter descriptions for Tactics. *) - val get_param_descrs : tactic -> Params.ParamDescrs.param_descrs - - (** Apply the tactic to the goal. *) - val apply : tactic -> Goal.goal -> Params.params option -> ApplyResult.apply_result - - (** The number of supported tactics. *) - val get_num_tactics : context -> int - - (** The names of all supported tactics. *) - val get_tactic_names : context -> string list - - (** Returns a string containing a description of the tactic with the given name. *) - val get_tactic_description : context -> string -> string - - (** Creates a new Tactic. *) - val mk_tactic : context -> string -> tactic - - (** Create a tactic that applies one tactic to a Goal and - then another one to every subgoal produced by the first one. *) - val and_then : context -> tactic -> tactic -> tactic list -> tactic - - (** Create a tactic that first applies one tactic to a Goal and - if it fails then returns the result of another tactic applied to the Goal. *) - val or_else : context -> tactic -> tactic -> tactic - - (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). - - If the tactic does not terminate within the timeout, then it fails. *) - val try_for : context -> tactic -> int -> tactic - - (** Create a tactic that applies one tactic to a given goal if the probe - evaluates to true. - - If the probe evaluates to false, then the new tactic behaves like the skip tactic. *) - val when_ : context -> Probe.probe -> tactic -> tactic - - (** Create a tactic that applies a tactic to a given goal if the probe - evaluates to true and another tactic otherwise. *) - val cond : context -> Probe.probe -> tactic -> tactic -> tactic - - (** Create a tactic that keeps applying one tactic until the goal is not - modified anymore or the maximum number of iterations is reached. *) - val repeat : context -> tactic -> int -> tactic - - (** Create a tactic that just returns the given goal. *) - val skip : context -> tactic - - (** Create a tactic always fails. *) - val fail : context -> tactic - - (** Create a tactic that fails if the probe evaluates to false. *) - val fail_if : context -> Probe.probe -> tactic - - (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). *) - val fail_if_not_decided : context -> tactic - - (** Create a tactic that applies a tactic using the given set of parameters. *) - val using_params : context -> tactic -> Params.params -> tactic - - (** Create a tactic that applies a tactic using the given set of parameters. - Alias for UsingParams*) - val with_ : context -> tactic -> Params.params -> tactic - - (** Create a tactic that applies the given tactics in parallel. *) - val par_or : context -> tactic list -> tactic - - (** Create a tactic that applies a tactic to a given goal and then another tactic - to every subgoal produced by the first one. The subgoals are processed in parallel. *) - val par_and_then : context -> tactic -> tactic -> tactic - - (** Interrupt the execution of a Z3 procedure. - This procedure can be used to interrupt: solvers, simplifiers and tactics. *) - val interrupt : context -> unit -end - -(** Solvers *) -module Solver : -sig - type solver - type status = UNSATISFIABLE | UNKNOWN | SATISFIABLE - - val string_of_status : status -> string - - (** Objects that track statistical information about solvers. *) - module Statistics : - sig - type statistics - - (** Statistical data is organized into pairs of \[Key, Entry\], where every - Entry is either a floating point or integer value. - *) - module Entry : - sig - type statistics_entry - - (** The key of the entry. *) - val get_key : statistics_entry -> string - - (** The int-value of the entry. *) - val get_int : statistics_entry -> int - - (** The float-value of the entry. *) - val get_float : statistics_entry -> float - - (** True if the entry is uint-valued. *) - val is_int : statistics_entry -> bool - - (** True if the entry is double-valued. *) - val is_float : statistics_entry -> bool - - (** The string representation of the the entry's value. *) - val to_string_value : statistics_entry -> string - - (** The string representation of the entry (key and value) *) - val to_string : statistics_entry -> string - end - - (** A string representation of the statistical data. *) - val to_string : statistics -> string - - (** The number of statistical data. *) - val get_size : statistics -> int - - (** The data entries. *) - val get_entries : statistics -> Entry.statistics_entry list - - (** The statistical counters. *) - val get_keys : statistics -> string list - - (** The value of a particular statistical counter. *) - val get : statistics -> string -> Entry.statistics_entry option - end - - (** A string that describes all available solver parameters. *) - val get_help : solver -> string - - (** Sets the solver parameters. *) - val set_parameters : solver -> Params.params -> unit - - (** Retrieves parameter descriptions for solver. *) - val get_param_descrs : solver -> Params.ParamDescrs.param_descrs - - (** The current number of backtracking points (scopes). - {!pop} - {!push} *) - val get_num_scopes : solver -> int - - (** Creates a backtracking point. - {!pop} *) - val push : solver -> unit - - (** Backtracks a number of backtracking points. - Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} - {!push} *) - val pop : solver -> int -> unit - - (** Resets the Solver. - This removes all assertions from the solver. *) - val reset : solver -> unit - - (** Assert a constraint (or multiple) into the solver. *) - val assert_ : solver -> Boolean.bool_expr list -> unit - - (** * Assert multiple constraints (cs) into the solver, and track them (in the - * unsat) core - * using the Boolean constants in ps. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) - val assert_and_track_a : solver -> Boolean.bool_expr list -> Boolean.bool_expr list -> unit - - (** * Assert a constraint (c) into the solver, and track it (in the unsat) core - * using the Boolean constant p. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) - val assert_and_track : solver -> Boolean.bool_expr -> Boolean.bool_expr -> unit - - (** The number of assertions in the solver. *) - val get_num_assertions : solver -> int - - (** The set of asserted formulas. *) - val get_assertions : solver -> Boolean.bool_expr list - - (** Checks whether the assertions in the solver are consistent or not. - - {!Model} - {!get_unsat_core} - {!Proof} *) - val check : solver -> Boolean.bool_expr list -> status - - (** The model of the last Check. - - The result is None if Check was not invoked before, - if its results was not SATISFIABLE, or if model production is not enabled. *) - val get_model : solver -> Model.model option - - (** 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. *) - val get_proof : solver -> Expr.expr option - - (** 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. *) - val get_unsat_core : solver -> AST.ast list - - (** A brief justification of why the last call to Check returned UNKNOWN. *) - val get_reason_unknown : solver -> string - - (** Solver statistics. *) - val get_statistics : solver -> Statistics.statistics - - (** 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. *) - val mk_solver : context -> Symbol.symbol option -> solver - - (** Creates a new (incremental) solver. - {!mk_solver} *) - val mk_solver_s : context -> string -> solver - - (** Creates a new (incremental) solver. *) - val mk_simple_solver : context -> solver - - (** 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. *) - val mk_solver_t : context -> Tactic.tactic -> solver - - (** A string representation of the solver. *) - val to_string : solver -> string -end - -(** Fixedpoint solving *) -module Fixedpoint : -sig - type fixedpoint - - (** A string that describes all available fixedpoint solver parameters. *) - val get_help : fixedpoint -> string - - (** Sets the fixedpoint solver parameters. *) - val set_params : fixedpoint -> Params.params -> unit - - (** Retrieves parameter descriptions for Fixedpoint solver. *) - val get_param_descrs : fixedpoint -> Params.ParamDescrs.param_descrs - - (** Assert a constraints into the fixedpoint solver. *) - val assert_ : fixedpoint -> Boolean.bool_expr list -> unit - - (** Register predicate as recursive relation. *) - val register_relation : fixedpoint -> FuncDecl.func_decl -> unit - - (** Add rule into the fixedpoint solver. *) - val add_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol option -> unit - - (** Add table fact to the fixedpoint solver. *) - val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit - - (** 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. *) - val query : fixedpoint -> Boolean.bool_expr -> Solver.status - - (** 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. *) - val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status - - (** Creates a backtracking point. - {!pop} *) - val push : fixedpoint -> unit - - (** Backtrack one backtracking point. - - Note that an exception is thrown if Pop is called without a corresponding Push - {!push} *) - val pop : fixedpoint -> unit - - (** Update named rule into in the fixedpoint solver. *) - val update_rule : fixedpoint -> Boolean.bool_expr -> Symbol.symbol -> unit - - (** Retrieve satisfying instance or instances of solver, - or definitions for the recursive predicates that show unsatisfiability. *) - val get_answer : fixedpoint -> Expr.expr option - - (** Retrieve explanation why fixedpoint engine returned status Unknown. *) - val get_reason_unknown : fixedpoint -> string - - (** Retrieve the number of levels explored for a given predicate. *) - val get_num_levels : fixedpoint -> FuncDecl.func_decl -> int - - (** Retrieve the cover of a predicate. *) - val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option - - (** Add property about the predicate. - The property is added at level. *) - val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit - - (** Retrieve internal string representation of fixedpoint object. *) - val to_string : fixedpoint -> string - - (** Instrument the Datalog engine on which table representation to use for recursive predicate. *) - val set_predicate_representation : fixedpoint -> FuncDecl.func_decl -> Symbol.symbol list -> unit - - (** Convert benchmark given as set of axioms, rules and queries to a string. *) - val to_string_q : fixedpoint -> Boolean.bool_expr list -> string - - (** Retrieve set of rules added to fixedpoint context. *) - val get_rules : fixedpoint -> Boolean.bool_expr list - - (** Retrieve set of assertions added to fixedpoint context. *) - val get_assertions : fixedpoint -> Boolean.bool_expr list - - (** Create a Fixedpoint context. *) - val mk_fixedpoint : context -> fixedpoint -end - -(** Global and context options - - Note: This module contains functions that set parameters/options for context - objects as well as functions that set options that are used globally, across - contexts.*) -module Options : -sig - (** 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. - {!get_param_value} *) - val update_param_value : context -> string -> string -> unit - - (** Get a configuration parameter. - - Returns None if the parameter value does not exist. - {!update_param_value} *) - val get_param_value : context -> string -> string option - - (** 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 PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - {!AST.to_string} - {!Quantifier.Pattern.to_string} - {!FuncDecl.to_string} - {!Sort.to_string} *) - val set_print_mode : context -> Z3enums.ast_print_mode -> unit - - (** Enable/disable printing of warning messages to the console. - - Note that this function is static and effects the behaviour of - all contexts globally. *) - val toggle_warning_messages : bool -> unit -end - -(** Functions for handling SMT and SMT2 expressions and files *) -module SMT : -sig - (** Convert a benchmark into an SMT-LIB formatted string. - - @return A string representation of the benchmark. *) - val benchmark_to_smtstring : context -> string -> string -> string -> string -> Boolean.bool_expr list -> Boolean.bool_expr -> string - - (** 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 in the third and fifth argument - don't need to match the names of the sorts and declarations in the arrays in the fourth - and sixth argument. This is a useful feature since we can use arbitrary names to - reference sorts and declarations. *) - val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit - - (** Parse the given file using the SMT-LIB parser. - {!parse_smtlib_string} *) - val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit - - (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_num_smtlib_formulas : context -> int - - (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_formulas : context -> Boolean.bool_expr list - - (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_num_smtlib_assumptions : context -> int - - (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_assumptions : context -> Boolean.bool_expr list - - (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_num_smtlib_decls : context -> int - - (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_decls : context -> FuncDecl.func_decl list - - (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_num_smtlib_sorts : context -> int - - (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) - val get_smtlib_sorts : context -> Sort.sort list - - (** Parse the given string using the SMT-LIB2 parser. - - {!parse_smtlib_string} - @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) - val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr - - (** Parse the given file using the SMT-LIB2 parser. - {!parse_smtlib2_string} *) - val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Boolean.bool_expr -end - -(** Set a global (or module) parameter, which is shared by all Z3 contexts. - - When a Z3 module is initialized it will use the value of these parameters - when Z3_params objects are not provided. - The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'. - The character '.' is a delimiter (more later). - The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'. - Thus, the following parameter names are considered equivalent: "pp.decimal-precision" and "PP.DECIMAL_PRECISION". - This function can be used to set parameters for a specific Z3 module. - This can be done by using .. - For example: - (set_global_param "pp.decimal" "true") - will set the parameter "decimal" in the module "pp" to true. -*) -val set_global_param : string -> string -> unit - -(** Get a global (or module) parameter. - - Returns None if the parameter does not exist. - The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. - This function cannot be invoked simultaneously from different threads without synchronization. - The result string stored in param_value is stored in a shared location. -*) -val get_global_param : string -> string option - -(** Restore the value of all global (and module) parameters. - - This command will not affect already created objects (such as tactics and solvers) - {!set_global_param} -*) -val global_param_reset_all : unit From 544a74f03493c73eea98f0414a927401294fd692 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 4 Jun 2013 18:00:48 +0100 Subject: [PATCH 190/248] ML API: bug and build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 28 ++++++++++++++++------------ scripts/update_api.py | 5 ++++- src/api/ml/z3.ml | 27 +++++++++++++++++---------- src/api/ml/z3.mli | 6 +++--- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 4082bb2b8..d4221c05e 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1350,26 +1350,30 @@ class MLComponent(Component): mk_dir(os.path.join(BUILD_DIR, sub_dir)) api_src = get_component(API_COMPONENT).to_src_dir for f in filter(lambda f: f.endswith('.ml'), os.listdir(self.src_dir)): - out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) - str = '\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f) - if IS_WINDOWS: str = str.replace('/','\\') + out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) + str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) + out.write(str) + for f in filter(lambda f: f.endswith('.mli'), os.listdir(self.src_dir)): + out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) + str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) for f in filter(lambda f: f.endswith('.c'), os.listdir(self.src_dir)): - out.write('%s/%s: %s/%s\n' % (sub_dir,f,src_dir,f)) - str = '\t%s %s/%s %s/%s\n' % (CP_CMD,src_dir,f,sub_dir,f) - if IS_WINDOWS: str = str.replace('/','\\') + out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) + str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! prev = '' for m in modules: - out.write('%s/%s.mli: %s/%s.ml %s\n' % (sub_dir,m,sub_dir,m,prev)) - out.write('\t%s -I %s -i -c %s/%s.ml > %s/%s.mli\n' % (OCAMLC,sub_dir,sub_dir,m,sub_dir,m)) - prev = prev + ' ' + sub_dir + '/' + m + '.mli' + fn = os.path.join(self.src_dir, ('%s.mli' % m)) + if not os.path.exists(fn): + out.write('%s.mli: %s.ml %s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),prev)) + out.write('\t%s -I %s -i -c %s.ml > %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir, m),os.path.join(sub_dir, m))) + prev = prev + ' ' + os.path.join(sub_dir, m) + '.mli' cmis = '' for m in modules: - out.write('%s/%s.cmi: %s/%s.mli\n' % (sub_dir,m,sub_dir,m)) - out.write('\t%s -I %s -c %s/%s.mli\n' % (OCAMLC,sub_dir,sub_dir,m)) - cmis = cmis + ' ' + sub_dir + '/' + m + '.cmi' + out.write('%s.cmi: %s.mli\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m))) + out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) + cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') diff --git a/scripts/update_api.py b/scripts/update_api.py index 44d871348..77a5bf7f2 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1185,7 +1185,8 @@ def mk_ml(): ip = inparams(params) op = outparams(params) if len(ip) == 0: - ml_native.write(' unit -> ') + ml_native.write(' unit -> ') + ml_i.write(' unit -> ') for p in ip: ml_native.write('%s -> ' % param2ml(p)) ml_i.write('%s -> ' % param2ml(p)) @@ -1233,6 +1234,8 @@ def mk_ml(): ml_native.write(' ') ml_native.write('a%d' % i) i = i + 1 + if len(ip) == 0: + ml_native.write('()') ml_native.write(' = \n') ml_native.write(' ') if result == VOID and len(op) == 0: diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 081433f1f..8b783d25d 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -34,7 +34,7 @@ struct ) let create_context settings = - let cfg = Z3native.mk_config in + let cfg = Z3native.mk_config () in let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in (List.iter f settings) ; let v = Z3native.mk_context_rc cfg in @@ -101,12 +101,12 @@ end module Version = struct - let major = let (x, _, _, _) = Z3native.get_version in x - let minor = let (_, x, _, _) = Z3native.get_version in x - let build = let (_, _, x, _) = Z3native.get_version in x - let revision = let (_, _, _, x) = Z3native.get_version in x + let major = let (x, _, _, _) = Z3native.get_version () in x + let minor = let (_, x, _, _) = Z3native.get_version () in x + let build = let (_, _, x, _) = Z3native.get_version () in x + let revision = let (_, _, _, x) = Z3native.get_version () in x let to_string = - let (mj, mn, bld, rev) = Z3native.get_version in + let (mj, mn, bld, rev) = Z3native.get_version () in string_of_int mj ^ "." ^ string_of_int mn ^ "." ^ string_of_int bld ^ "." ^ @@ -609,6 +609,10 @@ sig val add_symbol : params -> Symbol.symbol -> Symbol.symbol -> unit val mk_params : context -> params val to_string : params -> string + + val update_param_value : context -> string -> string -> unit + val get_param_value : context -> string -> string option + val set_print_mode : context -> Z3enums.ast_print_mode -> unit end = struct type params = z3_native_object @@ -1099,7 +1103,7 @@ struct end -module Array = +module Z3Array = struct let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) @@ -1382,7 +1386,7 @@ struct end -module List = +module Z3List = struct let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( elem_sort : sort ) = let (r, _, _, _, _, _, _) = (Z3native.mk_list_sort (context_gno ctx) (Symbol.gno name) (Sort.gno elem_sort)) in @@ -2038,7 +2042,7 @@ struct if not r then None else - expr_of_ptr (z3obj_gc x) v + Some(expr_of_ptr (z3obj_gc x) v) let evaluate ( x : model ) ( t : expr ) ( completion : bool ) = eval x t completion @@ -2331,7 +2335,7 @@ struct if (Z3native.stats_is_uint (z3obj_gnc x) (z3obj_gno x) i) then (Entry.create_si k (Z3native.stats_get_uint_value (z3obj_gnc x) (z3obj_gno x) i)) else - (Entry.create_sd k (Z3native.stats_get_float_value (z3obj_gnc x) (z3obj_gno x) i)) + (Entry.create_sd k (Z3native.stats_get_double_value (z3obj_gnc x) (z3obj_gno x) i)) ) in mk_list f n @@ -2667,3 +2671,6 @@ let global_param_reset_all = let toggle_warning_messages ( enabled: bool ) = Z3native.toggle_warning_messages enabled + +module Array = Z3Array +module List = Z3List diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 570ff8717..3f83ef6b2 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -8,7 +8,7 @@ (** General Z3 exceptions Many functions in this API may throw an exception; if they do, it is this one.*) -exception Error +exception Error of string (** Context objects. @@ -55,11 +55,11 @@ module Log : sig (** Open an interaction log file. @return True if opening the log file succeeds, false otherwise. *) - (* CMW: "open" seems to be a reserved keyword? *) + (* CMW: "open" is a reserved keyword. *) val open_ : string -> bool (** Closes the interaction log. *) - val close : unit + val close : unit -> unit (** Appends a user-provided string to the interaction log. *) val append : string -> unit From 983a0fb16f7a7c0600e93b2213e7b61c58da5ac9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 21 Oct 2013 11:22:42 +0100 Subject: [PATCH 191/248] ML bindings: list/array are now called z3array/z3list to avoid confusion. Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 4 ---- src/api/ml/z3.mli | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 8b783d25d..ed815d720 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -2670,7 +2670,3 @@ let global_param_reset_all = let toggle_warning_messages ( enabled: bool ) = Z3native.toggle_warning_messages enabled - - -module Array = Z3Array -module List = Z3List diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 3f83ef6b2..ff1898185 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -761,7 +761,7 @@ sig end (** Functions to manipulate Array expressions *) -module Array : +module Z3Array : sig (** Create a new array sort. *) val mk_sort : context -> Sort.sort -> Sort.sort -> Sort.sort @@ -1093,7 +1093,7 @@ sig end (** Functions to manipulate List expressions *) -module List : +module Z3List : sig (** Create a new list sort. *) val mk_sort : context -> Symbol.symbol -> Sort.sort -> Sort.sort From b889b225a0d59a9abd4927417de91384f033a0c6 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 21 Oct 2013 11:25:02 +0100 Subject: [PATCH 192/248] ML cleanup; makefile removed. The example is built by running make examples in the build directory. Signed-off-by: Christoph M. Wintersteiger --- examples/ml/Makefile | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 examples/ml/Makefile diff --git a/examples/ml/Makefile b/examples/ml/Makefile deleted file mode 100644 index 818f0cacc..000000000 --- a/examples/ml/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# This is a temporary support file for emacs annotations. -# It does not compile the Z3 ML example; this will be built -# in the top-level build directory. - -all: - source /cygdrive/c/cwinter/.msenv32 ; OCAML_COMPAT=c C:/ocamlw32/bin/ocamlc -g -custom -cclib '-L../../bld_dbg -lz3' -annot -o ml_example.byte -I ../../bld_dbg/api/ml z3.cma ml_example.ml - source /cygdrive/c/cwinter/.msenv32 ; C:/ocamlw32/bin/ocamlopt -g -annot -o ml_example -cclib '-L../../bld_dbg -lz3' -I ../../bld_dbg -I ../../bld_dbg/api/ml z3.cmxa ml_example.ml From c32e1304872f584a69f3ae6b8e410d88e30db7e3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 28 Oct 2013 12:17:58 +0000 Subject: [PATCH 193/248] ML API: bugfix for native function with more than 5 parameters. Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index 77a5bf7f2..dd1e46c4f 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1211,9 +1211,11 @@ def mk_ml(): ml_i.write(')') ml_native.write('\n') ml_i.write('\n') - ml_native.write(' = "n_%s"\n' % ml_method_name(name)) if len(ip) > 5: - ml_native.write(' "n_%s_bytecode"\n' % ml_method_name(name)) + ml_native.write(' = "n_%s_bytecode"\n' % ml_method_name(name)) + ml_native.write(' "n_%s"\n' % ml_method_name(name)) + else: + ml_native.write(' = "n_%s"\n' % ml_method_name(name)) ml_native.write('\n') ml_native.write(' end\n\n') ml_i.write('\n(**/**)\n'); From 54b7f8eec3b17ed012324d7a34c8846de32cb560 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 2 Apr 2014 19:08:59 +0100 Subject: [PATCH 194/248] ML API bugfix (Codeplex issue 102) Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 43 ++++++ src/api/ml/z3.ml | 289 +++++++++++++++++++------------------- src/api/ml/z3.mli | 3 + 3 files changed, 192 insertions(+), 143 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index c9ed1d948..0dd227784 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -196,6 +196,48 @@ let basic_tests ( ctx : context ) = Printf.printf "Exception caught, OK.\n" ) +(** + A basic example of how to use quantifiers. +**) +let quantifierExample1 ( ctx : context ) = + Printf.printf "QuantifierExample\n" ; + let is = (Integer.mk_sort ctx) in + let types = [ is; is; is ] in + let names = [ (Symbol.mk_string ctx "x_0"); + (Symbol.mk_string ctx "x_1"); + (Symbol.mk_string ctx "x_2") ] in + let vars = [ (Quantifier.mk_bound ctx 2 (List.nth types 0)); + (Quantifier.mk_bound ctx 2 (List.nth types 1)); + (Quantifier.mk_bound ctx 2 (List.nth types 2)) ] in + let xs = [ (Integer.mk_const ctx (List.nth names 0)); + (Integer.mk_const ctx (List.nth names 1)); + (Integer.mk_const ctx (List.nth names 2)) ] in + + let body_vars = (Boolean.mk_and ctx + [ (mk_eq ctx + (Arithmetic.mk_add ctx [ (List.nth vars 0) ; (Integer.mk_numeral_i ctx 1)]) + (Integer.mk_numeral_i ctx 2)) ; + (mk_eq ctx + (Arithmetic.mk_add ctx [ (List.nth vars 1); (Integer.mk_numeral_i ctx 2)]) + (Arithmetic.mk_add ctx [ (List.nth vars 2); (Integer.mk_numeral_i ctx 3)])) ]) in + let body_const = (Boolean.mk_and ctx + [ (mk_eq ctx + (Arithmetic.mk_add ctx [ (List.nth xs 0); (Integer.mk_numeral_i ctx 1)]) + (Integer.mk_numeral_i ctx 2)) ; + (mk_eq ctx + (Arithmetic.mk_add ctx [ (List.nth xs 1); (Integer.mk_numeral_i ctx 2)]) + (Arithmetic.mk_add ctx [ (List.nth xs 2); (Integer.mk_numeral_i ctx 3)])) ]) in + + let x = (Quantifier.mk_forall ctx types names body_vars (Some 1) [] [] (Some (Symbol.mk_string ctx "Q1")) (Some (Symbol.mk_string ctx "skid1"))) in + Printf.printf "Quantifier X: %s\n" (Quantifier.to_string x) ; + let y = (Quantifier.mk_forall_const ctx xs body_const (Some 1) [] [] (Some (Symbol.mk_string ctx "Q2")) (Some (Symbol.mk_string ctx "skid2"))) in + Printf.printf "Quantifier Y: %s\n" (Quantifier.to_string y) ; + if (is_true (Quantifier.expr_of_quantifier x)) then + raise (TestFailedException "") (* unreachable *) + else if (is_false (Quantifier.expr_of_quantifier x)) then + raise (TestFailedException "") (* unreachable *) + else if (is_const (Quantifier.expr_of_quantifier x)) then + raise (TestFailedException "") (* unreachable *) let _ = try ( @@ -217,6 +259,7 @@ let _ = Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); basic_tests ctx ; + quantifierExample1 ctx ; Printf.printf "Disposing...\n"; Gc.full_major () ); diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index ed815d720..d91d3ca8d 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -297,6 +297,7 @@ struct | VAR_AST -> true | _ -> false + let is_app ( x : ast ) = (get_ast_kind x) == APP_AST let is_var ( x : ast ) = (get_ast_kind x) == VAR_AST let is_quantifier ( x : ast ) = (get_ast_kind x) == QUANTIFIER_AST let is_sort ( x : ast ) = (get_ast_kind x) == SORT_AST @@ -828,22 +829,22 @@ end = struct (Z3native.mk_bool_sort (gnc x)) (Z3native.get_sort (gnc x) (gno x))) - let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_app a)) && (get_num_args x) == 0 && (FuncDecl.get_domain_size (get_func_decl x)) == 0 - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - let is_false ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - let is_eq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - let is_distinct ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - let is_ite ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - let is_and ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - let is_or ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - let is_iff ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - let is_xor ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - let is_not ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - let is_implies ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - let is_oeq ( x : expr ) = (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) + let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) + let is_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) + let is_eq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) + let is_distinct ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) + let is_ite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) + let is_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) + let is_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) + let is_iff ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) + let is_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) + let is_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) + let is_implies ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) + let is_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) @@ -1100,6 +1101,8 @@ struct mk_forall_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id else mk_exists_const ctx bound_constants body weight patterns nopatterns quantifier_id skolem_id + + let to_string ( x : quantifier ) = (Expr.to_string (expr_of_quantifier x)) end @@ -1108,12 +1111,12 @@ struct let mk_sort ( ctx : context ) ( domain : sort ) ( range : sort ) = sort_of_ptr ctx (Z3native.mk_array_sort (context_gno ctx) (Sort.gno domain) (Sort.gno range)) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) - let is_constant_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) - let is_default_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) - let is_array_map ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) - let is_as_array ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) + let is_store ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_STORE) + let is_select ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SELECT) + let is_constant_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONST_ARRAY) + let is_default_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_DEFAULT) + let is_array_map ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ARRAY_MAP) + let is_as_array ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_AS_ARRAY) let is_array ( x : expr ) = (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == ARRAY_SORT) @@ -1150,11 +1153,11 @@ struct let mk_sort ( ctx : context ) ( ty : sort ) = sort_of_ptr ctx (Z3native.mk_set_sort (context_gno ctx) (Sort.gno ty)) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) - let is_intersect ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) - let is_difference ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) - let is_subset ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) + let is_union ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_UNION) + let is_intersect ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_INTERSECT) + let is_difference ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_DIFFERENCE) + let is_complement ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_COMPLEMENT) + let is_subset ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SET_SUBSET) let mk_empty ( ctx : context ) ( domain : sort ) = @@ -1203,7 +1206,7 @@ struct (Z3native.is_app (Expr.gnc x) (Expr.gno x)) && (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == FINITE_DOMAIN_SORT) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) + let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FD_LT) let get_size ( x : sort ) = let (r, v) = (Z3native.get_finite_domain_sort_size (Sort.gnc x) (Sort.gno x)) in @@ -1219,19 +1222,19 @@ struct ((Z3native.is_app (Expr.gnc x) (Expr.gno x)) && (sort_kind_of_int (Z3native.get_sort_kind nc (Z3native.get_sort nc (Expr.gno x))) == RELATION_SORT)) - let is_store ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) - let is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) - let is_is_empty ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) - let is_join ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) - let is_union ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) - let is_widen ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) - let is_project ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) - let is_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) - let is_negation_filter ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) - let is_rename ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) - let is_complement ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) - let is_select ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) - let is_clone ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) + let is_store ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_STORE) + let is_empty ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_EMPTY) + let is_is_empty ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_IS_EMPTY) + let is_join ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_JOIN) + let is_union ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_UNION) + let is_widen ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_WIDEN) + let is_project ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_PROJECT) + let is_filter ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_FILTER) + let is_negation_filter ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_NEGATION_FILTER) + let is_rename ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_RENAME) + let is_complement ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_COMPLEMENT) + let is_select ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_SELECT) + let is_clone ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_RA_CLONE) let get_arity ( x : sort ) = Z3native.get_relation_arity (Sort.gnc x) (Sort.gno x) @@ -1534,37 +1537,37 @@ struct (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) - let is_arithmetic_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + let is_arithmetic_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - let is_le ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + let is_le ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - let is_ge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + let is_ge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - let is_lt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - let is_gt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + let is_gt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - let is_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + let is_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - let is_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + let is_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - let is_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + let is_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - let is_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + let is_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - let is_div ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + let is_div ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - let is_idiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + let is_idiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - let is_remainder ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + let is_remainder ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - let is_modulus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + let is_modulus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - let is_inttoreal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + let is_inttoreal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - let is_real_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + let is_real_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - let is_real_is_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + let is_real_is_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) let is_real ( x : expr ) = ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) @@ -1616,57 +1619,57 @@ struct sort_of_ptr ctx (Z3native.mk_bv_sort (context_gno ctx) size) let is_bv ( x : expr ) = ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == BV_SORT) - let is_bv_numeral ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) - let is_bv_bit1 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) - let is_bv_bit0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) - let is_bv_uminus ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) - let is_bv_add ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) - let is_bv_sub ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) - let is_bv_mul ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) - let is_bv_sdiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) - let is_bv_udiv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) - let is_bv_SRem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) - let is_bv_urem ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) - let is_bv_smod ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) - let is_bv_sdiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) - let is_bv_udiv0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) - let is_bv_srem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) - let is_bv_urem0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) - let is_bv_smod0 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) - let is_bv_ule ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) - let is_bv_sle ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) - let is_bv_uge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) - let is_bv_sge ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) - let is_bv_ult ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) - let is_bv_slt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) - let is_bv_ugt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) - let is_bv_sgt ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) - let is_bv_and ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) - let is_bv_or ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) - let is_bv_not ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) - let is_bv_xor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) - let is_bv_nand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) - let is_bv_nor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) - let is_bv_xnor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) - let is_bv_concat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) - let is_bv_signextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) - let is_bv_zeroextension ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) - let is_bv_extract ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) - let is_bv_repeat ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) - let is_bv_reduceor ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) - let is_bv_reduceand ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) - let is_bv_comp ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) - let is_bv_shiftleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) - let is_bv_shiftrightlogical ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) - let is_bv_shiftrightarithmetic ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) - let is_bv_rotateleft ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) - let is_bv_rotateright ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) - let is_bv_rotateleftextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) - let is_bv_rotaterightextended ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) - let is_int_to_bv ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) - let is_bv_to_int ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) - let is_bv_carry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) - let is_bv_xor3 ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) + let is_bv_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNUM) + let is_bv_bit1 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT1) + let is_bv_bit0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BIT0) + let is_bv_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNEG) + let is_bv_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BADD) + let is_bv_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSUB) + let is_bv_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BMUL) + let is_bv_sdiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV) + let is_bv_udiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV) + let is_bv_SRem ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM) + let is_bv_urem ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM) + let is_bv_smod ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD) + let is_bv_sdiv0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSDIV0) + let is_bv_udiv0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUDIV0) + let is_bv_srem0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSREM0) + let is_bv_urem0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BUREM0) + let is_bv_smod0 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSMOD0) + let is_bv_ule ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULEQ) + let is_bv_sle ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLEQ) + let is_bv_uge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGEQ) + let is_bv_sge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGEQ) + let is_bv_ult ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ULT) + let is_bv_slt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SLT) + let is_bv_ugt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UGT) + let is_bv_sgt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SGT) + let is_bv_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BAND) + let is_bv_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BOR) + let is_bv_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOT) + let is_bv_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXOR) + let is_bv_nand ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNAND) + let is_bv_nor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BNOR) + let is_bv_xnor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BXNOR) + let is_bv_concat ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CONCAT) + let is_bv_signextension ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SIGN_EXT) + let is_bv_zeroextension ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ZERO_EXT) + let is_bv_extract ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXTRACT) + let is_bv_repeat ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REPEAT) + let is_bv_reduceor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDOR) + let is_bv_reduceand ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BREDAND) + let is_bv_comp ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BCOMP) + let is_bv_shiftleft ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BSHL) + let is_bv_shiftrightlogical ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BLSHR) + let is_bv_shiftrightarithmetic ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BASHR) + let is_bv_rotateleft ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_LEFT) + let is_bv_rotateright ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) + let is_bv_rotateleftextended ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) + let is_bv_rotaterightextended ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) + let is_int_to_bv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_bv_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_bv_carry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) + let is_bv_xor3 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) let get_size (x : sort ) = Z3native.get_bv_sort_size (Sort.gnc x) (Sort.gno x) let get_int ( x : expr ) = let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in @@ -1778,44 +1781,44 @@ end module Proof = struct - let is_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) - let is_asserted ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) - let is_goal ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) - let is_modus_ponens ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) - let is_reflexivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) - let is_symmetry ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) - let is_transitivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) - let is_Transitivity_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) - let is_monotonicity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) - let is_quant_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) - let is_distributivity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) - let is_and_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) - let is_or_elimination ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) - let is_rewrite ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) - let is_rewrite_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) - let is_pull_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) - let is_pull_quant_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) - let is_push_quant ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) - let is_elim_unused_vars ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) - let is_der ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) - let is_quant_inst ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) - let is_hypothesis ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) - let is_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) - let is_unit_resolution ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) - let is_iff_true ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) - let is_iff_false ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) - let is_commutativity ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) - let is_def_axiom ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) - let is_def_intro ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) - let is_apply_def ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) - let is_iff_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) - let is_nnf_pos ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) - let is_nnf_neg ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) - let is_nnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) - let is_cnf_star ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) - let is_skolemize ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) - let is_modus_ponens_oeq ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) - let is_theory_lemma ( x : expr ) = (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) + let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) + let is_asserted ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) + let is_goal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_modus_ponens ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) + let is_reflexivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) + let is_symmetry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) + let is_transitivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY) + let is_Transitivity_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRANSITIVITY_STAR) + let is_monotonicity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MONOTONICITY) + let is_quant_intro ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INTRO) + let is_distributivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DISTRIBUTIVITY) + let is_and_elimination ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_AND_ELIM) + let is_or_elimination ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NOT_OR_ELIM) + let is_rewrite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE) + let is_rewrite_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REWRITE_STAR) + let is_pull_quant ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT) + let is_pull_quant_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PULL_QUANT_STAR) + let is_push_quant ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_PUSH_QUANT) + let is_elim_unused_vars ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ELIM_UNUSED_VARS) + let is_der ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DER) + let is_quant_inst ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_QUANT_INST) + let is_hypothesis ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_HYPOTHESIS) + let is_lemma ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_LEMMA) + let is_unit_resolution ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_UNIT_RESOLUTION) + let is_iff_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_TRUE) + let is_iff_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_FALSE) + let is_commutativity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_COMMUTATIVITY) (* *) + let is_def_axiom ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_AXIOM) + let is_def_intro ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_DEF_INTRO) + let is_apply_def ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_APPLY_DEF) + let is_iff_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_IFF_OEQ) + let is_nnf_pos ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_POS) + let is_nnf_neg ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_NEG) + let is_nnf_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_NNF_STAR) + let is_cnf_star ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_CNF_STAR) + let is_skolemize ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SKOLEMIZE) + let is_modus_ponens_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS_OEQ) + let is_theory_lemma ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TH_LEMMA) end diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index ff1898185..5c9c56dbf 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -758,6 +758,9 @@ sig (** Create a Quantifier. *) val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier + + (** A string representation of the quantifier. *) + val to_string : quantifier -> string end (** Functions to manipulate Array expressions *) From ee22d4054201afd40c9a7bf05fe9fb8ca808639f Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 2 Apr 2014 19:18:43 +0100 Subject: [PATCH 195/248] ML API bugfix Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index d91d3ca8d..5f8d96d2a 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -793,7 +793,7 @@ end = struct mk_list f n let update ( x : expr ) ( args : expr list ) = - if (List.length args <> (get_num_args x)) then + if ((AST.is_app (ast_of_expr x)) && (List.length args <> (get_num_args x))) then raise (Z3native.Exception "Number of arguments does not match") else expr_of_ptr (Expr.gc x) (Z3native.update_term (gnc x) (gno x) (List.length args) (expr_lton args)) From 9dc802199503f8f120cb8bf1f5202238ba0e0383 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:17:22 +0100 Subject: [PATCH 196/248] Added facilities for ocamlfind in the ML API build Signed-off-by: Christoph M. Wintersteiger --- examples/ml/README | 12 +++++++++++- scripts/mk_util.py | 31 ++++++++++++++++++++++++++++--- src/api/ml/README | 6 +++++- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/examples/ml/README b/examples/ml/README index 3e1eb0d1c..f934aac80 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -1,4 +1,4 @@ -### This is work-in-progress and does not work yet. +### This is work-in-progress. Small example using the Z3 ML bindings. To build the example execute @@ -12,3 +12,13 @@ or LD_LIBRARY_PATH=. ./ml_example.byte for the byte-code version. +If Z3 was installed into the ocamlfind package repository (see src/api/ml/README), +then we can compile this example as follows: + +ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg -verbose +ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg -verbose + +Note that the resulting binaries depend on the shared z3 library, which needs to be +in the PATH (Windows), LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX). If Z3 was +installed into ocamlfind, the path that should be added is +`ocamlfind printconf destdir`/Z3 \ No newline at end of file diff --git a/scripts/mk_util.py b/scripts/mk_util.py index d4221c05e..f6f95cf7d 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1338,7 +1338,25 @@ class MLComponent(Component): Component.__init__(self, name, path, deps) if lib_name == None: lib_name = name - self.lib_name = lib_name + self.lib_name = lib_name + + def mk_ml_meta(self, ml_meta_in, ml_meta_out, major, minor, build, revision): + ver_pat = re.compile('version = "VERSION"*') + fin = open(ml_meta_in, 'r') + fout = open(ml_meta_out, 'w') + num_updates = 0 + for line in fin: + if ver_pat.match(line): + fout.write('version = "%s.%s.%s.%s"\n' % (major, minor, build, revision)) + num_updates = num_updates + 1 + else: + fout.write(line) + assert num_updates == 1, "unexpected number of version number updates" + fin.close() + fout.close() + if VERBOSE: + print("Updated '%s'" % ml_meta_out) + def mk_makefile(self, out): if is_ml_enabled(): @@ -1377,7 +1395,7 @@ class MLComponent(Component): out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') - out.write('api/ml/z3.cmxa: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) out.write('\n') @@ -1385,7 +1403,7 @@ class MLComponent(Component): if DEBUG_MODE: out.write('-g ') out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) - out.write('api/ml/z3.cma: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) out.write('\n') @@ -1395,6 +1413,13 @@ class MLComponent(Component): out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') out.write('\n') + # Generate META file and package installation commands + self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) + out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') + out.write('\tocamlfind remove Z3\n') + out.write('\tocamlfind install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.lib api/ml/libz3ml.lib libz3.lib libz3.dll\n') + out.write('\n') + def main_component(self): return is_ml_enabled() diff --git a/src/api/ml/README b/src/api/ml/README index beee7d864..f697e5ff4 100644 --- a/src/api/ml/README +++ b/src/api/ml/README @@ -5,4 +5,8 @@ We are currently working on a brand new ML API. On Windows, there are no less than four different ports of OCaml. The Z3 build system assumes that either the win32 or the win64 port is installed. This means that OCaml will use `cl' as the underlying C compiler and not the cygwin or -mingw compilers. \ No newline at end of file +mingw compilers. + +By default, a make target called `ocamlfind_install' is added. This installs Z3 +into the ocamlfind package repository such that programs can be compiled via +ocamlfind. \ No newline at end of file From eb72afabfbf89c49be25bd5d1843d6297280b8ef Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:32:06 +0100 Subject: [PATCH 197/248] ML API `or' is deprecated, changed to `||' Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 5f8d96d2a..c037a9263 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -748,7 +748,7 @@ end = struct Expr(z3_native_object_of_ast_ptr ctx no) else if (Z3native.is_numeral_ast (context_gno ctx) no) then - if (sk == INT_SORT or sk == REAL_SORT or sk == BV_SORT) then + if (sk == INT_SORT || sk == REAL_SORT || sk == BV_SORT) then Expr(z3_native_object_of_ast_ptr ctx no) else raise (Z3native.Exception "Unsupported numeral object") From 0465ad3ce6cdccf4e4be9c90954b683c44ec539e Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:33:52 +0100 Subject: [PATCH 198/248] ML example; `or' is deprecated, changed to `||' Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 0dd227784..25862b2d7 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -168,7 +168,7 @@ let basic_tests ( ctx : context ) = let inum = (get_numerator rn) in let iden = get_denominator rn in Printf.printf "Numerator: %s Denominator: %s\n" (Real.to_string inum) (Real.to_string iden) ; - if ((Real.to_string inum) <> "42" or (Real.to_string iden) <> "43") then + if ((Real.to_string inum) <> "42" || (Real.to_string iden) <> "43") then raise (TestFailedException "") else Printf.printf "Test passed.\n" From 133890be23c0d02186622fb3781ff6c987b6efae Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:38:29 +0100 Subject: [PATCH 199/248] ML API build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index f6f95cf7d..46229b20c 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1417,7 +1417,10 @@ class MLComponent(Component): self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') out.write('\tocamlfind remove Z3\n') - out.write('\tocamlfind install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.lib api/ml/libz3ml.lib libz3.lib libz3.dll\n') + out.write('\tocamlfind install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)') + if IS_WINDOWS: + out.write(' libz3$(LIB_EXT)') + out.write('\n') out.write('\n') From f319a77a4c6c1f8c1620b34424bcbad9931b636c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 15 Apr 2014 18:49:05 +0100 Subject: [PATCH 200/248] ML API build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 46229b20c..418149dbe 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1415,13 +1415,14 @@ class MLComponent(Component): out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) - out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') - out.write('\tocamlfind remove Z3\n') - out.write('\tocamlfind install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)') - if IS_WINDOWS: - out.write(' libz3$(LIB_EXT)') - out.write('\n') - out.write('\n') + if OCAMLFIND != '': + out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') + out.write('\t%s remove Z3\n' % (OCAMLFIND)) + out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) + if IS_WINDOWS: + out.write(' libz3$(LIB_EXT)') + out.write('\n') + out.write('\n') def main_component(self): From 3d9ad51aae97db8a8b2c5ef15163a2c46871ea8c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 12:55:23 +0100 Subject: [PATCH 201/248] ML API refactoring Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 72 ++++++++----------- src/api/ml/z3.mli | 180 +++++++++++++++++++++++----------------------- 2 files changed, 119 insertions(+), 133 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index c037a9263..051a54696 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1,5 +1,5 @@ (** - The Z3 ML/Ocaml Interface. + The Z3 ML/OCaml Interface. Copyright (C) 2012 Microsoft Corporation @author CM Wintersteiger (cwinter) 2012-12-17 @@ -698,7 +698,6 @@ sig val get_simplify_help : context -> string val get_simplify_parameter_descrs : context -> Params.ParamDescrs.param_descrs val get_func_decl : expr -> FuncDecl.func_decl - val get_bool_value : expr -> Z3enums.lbool val get_num_args : expr -> int val get_args : expr -> expr list val update : expr -> expr list -> expr @@ -710,20 +709,7 @@ sig val is_numeral : expr -> bool val is_well_sorted : expr -> bool val get_sort : expr -> Sort.sort - val is_bool : expr -> bool val is_const : expr -> bool - val is_true : expr -> bool - val is_false : expr -> bool - val is_eq : expr -> bool - val is_distinct : expr -> bool - val is_ite : expr -> bool - val is_and : expr -> bool - val is_or : expr -> bool - val is_iff : expr -> bool - val is_xor : expr -> bool - val is_not : expr -> bool - val is_implies : expr -> bool - val is_oeq : expr -> bool val mk_const : context -> Symbol.symbol -> Sort.sort -> expr val mk_const_s : context -> string -> Sort.sort -> expr val mk_const_f : context -> FuncDecl.func_decl -> expr @@ -782,9 +768,7 @@ end = struct let get_simplify_parameter_descrs ( ctx : context ) = Params.ParamDescrs.param_descrs_of_ptr ctx (Z3native.simplify_get_param_descrs (context_gno ctx)) - let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (gnc x) (gno x)) - - let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) + let get_func_decl ( x : expr ) = FuncDecl.func_decl_of_ptr (Expr.gc x) (Z3native.get_app_decl (gnc x) (gno x)) let get_num_args ( x : expr ) = Z3native.get_app_num_args (gnc x) (gno x) @@ -823,29 +807,11 @@ end = struct let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (gnc x) (gno x)) - - let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && - (Z3native.is_eq_sort (gnc x) - (Z3native.mk_bool_sort (gnc x)) - (Z3native.get_sort (gnc x) (gno x))) - + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_app a)) && (get_num_args x) == 0 && (FuncDecl.get_domain_size (get_func_decl x)) == 0 - let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) - let is_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) - let is_eq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) - let is_distinct ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) - let is_ite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) - let is_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) - let is_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) - let is_iff ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) - let is_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) - let is_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) - let is_implies ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) - let is_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OEQ) - let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) @@ -888,12 +854,6 @@ struct let mk_val ( ctx : context ) ( value : bool ) = if value then mk_true ctx else mk_false ctx - - let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = - expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) - - let mk_distinct ( ctx : context ) ( args : expr list ) = - expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) let mk_not ( ctx : context ) ( a : expr ) = expr_of_ptr ctx (Z3native.mk_not (context_gno ctx) (gno a)) @@ -917,6 +877,31 @@ struct let mk_or ( ctx : context ) ( args : expr list ) = let f x = (Expr.gno (x)) in expr_of_ptr ctx (Z3native.mk_or (context_gno ctx) (List.length args) (Array.of_list(List.map f args))) + + let mk_eq ( ctx : context ) ( x : expr ) ( y : expr ) = + expr_of_ptr ctx (Z3native.mk_eq (context_gno ctx) (Expr.gno x) (Expr.gno y)) + + let mk_distinct ( ctx : context ) ( args : expr list ) = + expr_of_ptr ctx (Z3native.mk_distinct (context_gno ctx) (List.length args) (expr_lton args)) + + let get_bool_value ( x : expr ) = lbool_of_int (Z3native.get_bool_value (gnc x) (gno x)) + + let is_bool ( x : expr ) = (match x with Expr(a) -> (AST.is_expr a)) && + (Z3native.is_eq_sort (gnc x) + (Z3native.mk_bool_sort (gnc x)) + (Z3native.get_sort (gnc x) (gno x))) + + let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_TRUE) + let is_false ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_FALSE) + let is_eq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_EQ) + let is_distinct ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_DISTINCT) + let is_ite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_ITE) + let is_and ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_AND) + let is_or ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_OR) + let is_iff ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IFF) + let is_xor ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_XOR) + let is_not ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_NOT) + let is_implies ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (get_func_decl x) == OP_IMPLIES) end @@ -1784,6 +1769,7 @@ struct let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) let is_asserted ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_ASSERTED) let is_goal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_GOAL) + let is_oeq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_OEQ) let is_modus_ponens ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_MODUS_PONENS) let is_reflexivity ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_REFLEXIVITY) let is_symmetry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_SYMMETRY) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 5c9c56dbf..c554d7564 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1,5 +1,5 @@ (** - The Z3 ML/Ocaml Interface. + The Z3 ML/OCaml Interface. Copyright (C) 2012 Microsoft Corporation @author CM Wintersteiger (cwinter) 2012-12-17 @@ -488,10 +488,6 @@ sig (** The function declaration of the function that is applied in this expression. *) val get_func_decl : Expr.expr -> FuncDecl.func_decl - (** Indicates whether the expression is the true or false expression - or something else (L_UNDEF). *) - val get_bool_value : Expr.expr -> Z3enums.lbool - (** The number of arguments of the expression. *) val get_num_args : Expr.expr -> int @@ -535,11 +531,88 @@ sig (** The Sort of the term. *) val get_sort : Expr.expr -> Sort.sort - (** Indicates whether the term has Boolean sort. *) - val is_bool : Expr.expr -> bool - (** Indicates whether the term represents a constant. *) val is_const : Expr.expr -> bool + + (** Creates a new constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> expr + + (** Creates a new constant. *) + val mk_const_s : context -> string -> Sort.sort -> expr + + (** Creates a constant from the func_decl. *) + val mk_const_f : context -> FuncDecl.func_decl -> expr + + (** Creates a fresh constant with a name prefixed with a string. *) + val mk_fresh_const : context -> string -> Sort.sort -> expr + + (** Create a new function application. *) + val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr + + (** Create a numeral of a given sort. + @return A Term with the given value and sort *) + val mk_numeral_string : context -> string -> Sort.sort -> expr + + (** Create a numeral 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. + @return A Term with the given value and sort *) + val mk_numeral_int : context -> int -> Sort.sort -> expr +end + +(** Boolean expressions; Propositional logic and equality *) +module Boolean : +sig + (** Create a Boolean sort *) + val mk_sort : context -> Sort.sort + + (** Create a Boolean constant. *) + val mk_const : context -> Symbol.symbol -> Expr.expr + + (** Create a Boolean constant. *) + val mk_const_s : context -> string -> Expr.expr + + (** The true Term. *) + val mk_true : context -> Expr.expr + + (** The false Term. *) + val mk_false : context -> Expr.expr + + (** Creates a Boolean value. *) + val mk_val : context -> bool -> Expr.expr + + (** Mk an expression representing not(a). *) + val mk_not : context -> Expr.expr -> Expr.expr + + (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) + val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 iff t2. *) + val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 -> t2. *) + val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing t1 xor t2. *) + val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create an expression representing the AND of args *) + val mk_and : context -> Expr.expr list -> Expr.expr + + (** Create an expression representing the OR of args *) + val mk_or : context -> Expr.expr list -> Expr.expr + + (** Creates the equality between two expr's. *) + val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Creates a distinct term. *) + val mk_distinct : context -> Expr.expr list -> Expr.expr + + (** Indicates whether the expression is the true or false expression + or something else (L_UNDEF). *) + val get_bool_value : Expr.expr -> Z3enums.lbool + + (** Indicates whether the term has Boolean sort. *) + val is_bool : Expr.expr -> bool (** Indicates whether the term is the constant true. *) val is_true : Expr.expr -> bool @@ -573,84 +646,6 @@ sig (** Indicates whether the term is an implication *) val is_implies : Expr.expr -> bool - - (** 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. *) - val is_oeq : Expr.expr -> bool - - (** Creates a new constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - - (** Creates a new constant. *) - val mk_const_s : context -> string -> Sort.sort -> expr - - (** Creates a constant from the func_decl. *) - val mk_const_f : context -> FuncDecl.func_decl -> expr - - (** Creates a fresh constant with a name prefixed with a string. *) - val mk_fresh_const : context -> string -> Sort.sort -> expr - - (** Create a new function application. *) - val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr - - (** Create a numeral of a given sort. - @return A Term with the goven value and sort *) - val mk_numeral_string : context -> string -> Sort.sort -> expr - - (** Create a numeral 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. - @return A Term with the given value and sort *) - val mk_numeral_int : context -> int -> Sort.sort -> expr -end - -(** Boolean expressions *) -module Boolean : -sig - (** Create a Boolean sort *) - val mk_sort : context -> Sort.sort - - (** Create a Boolean constant. *) - val mk_const : context -> Symbol.symbol -> Expr.expr - - (** Create a Boolean constant. *) - val mk_const_s : context -> string -> Expr.expr - - (** The true Term. *) - val mk_true : context -> Expr.expr - - (** The false Term. *) - val mk_false : context -> Expr.expr - - (** Creates a Boolean value. *) - val mk_val : context -> bool -> Expr.expr - - (** Creates the equality between two expr's. *) - val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Creates a distinct term. *) - val mk_distinct : context -> Expr.expr list -> Expr.expr - - (** Mk an expression representing not(a). *) - val mk_not : context -> Expr.expr -> Expr.expr - - (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) - val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing t1 iff t2. *) - val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing t1 -> t2. *) - val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing t1 xor t2. *) - val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create an expression representing the AND of args *) - val mk_and : context -> Expr.expr list -> Expr.expr - - (** Create an expression representing the OR of args *) - val mk_or : context -> Expr.expr list -> Expr.expr end (** Quantifier expressions *) @@ -817,7 +812,7 @@ sig The node a must have an array sort [domain -> range], and i must have the sort domain. The sort of the result is range. - {!Array.mk_sort} + {!Z3Array.mk_sort} {!mk_store} *) val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -833,7 +828,7 @@ sig 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). - {!Array.mk_sort} + {!Z3Array.mk_sort} {!mk_select} *) val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr @@ -841,7 +836,7 @@ sig The resulting term is an array, such that a selecton an arbitrary index produces the value v. - {!Array.mk_sort} + {!Z3Array.mk_sort} {!mk_select} *) val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr @@ -850,7 +845,7 @@ sig 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]. - {!Array.mk_sort} + {!Z3Array.mk_sort} {!mk_select} {!mk_store} *) val mk_map : context -> FuncDecl.func_decl -> Expr.expr list -> Expr.expr @@ -1837,6 +1832,11 @@ sig (** Indicates whether the term is a proof for a fact (tagged as goal) asserted by the user. *) val is_goal : Expr.expr -> bool + (** 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. *) + val is_oeq : Expr.expr -> bool + (** 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. From 555a3883b9544dc6603b2067e96f3b009c97e3f9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 13:05:22 +0100 Subject: [PATCH 202/248] ML example doc fix Signed-off-by: Christoph M. Wintersteiger --- examples/ml/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ml/README b/examples/ml/README index f934aac80..a14cbeb63 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -15,8 +15,8 @@ for the byte-code version. If Z3 was installed into the ocamlfind package repository (see src/api/ml/README), then we can compile this example as follows: -ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg -verbose -ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg -verbose +ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg +ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg Note that the resulting binaries depend on the shared z3 library, which needs to be in the PATH (Windows), LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX). If Z3 was From 4687aa208de1071e0516f11a8811153187a016d9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 13:05:50 +0100 Subject: [PATCH 203/248] ML API refactoring (z3native.c -> z3native_stubs.c) Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 6 +++--- scripts/update_api.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 418149dbe..ab13bb943 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1392,9 +1392,9 @@ class MLComponent(Component): out.write('%s.cmi: %s.mli\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m))) out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native.c $(CXX_OUT_FLAG)api/ml/z3native$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) - out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native$(OBJ_EXT)\n') + out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) + out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) diff --git a/scripts/update_api.py b/scripts/update_api.py index dd1e46c4f..0ed9b29ca 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1148,7 +1148,7 @@ def mk_ml(): ml_dir = get_component('ml').src_dir ml_nativef = os.path.join(ml_dir, 'z3native.ml') ml_nativefi = os.path.join(ml_dir, 'z3native.mli') - ml_wrapperf = os.path.join(ml_dir, 'z3native.c') + ml_wrapperf = os.path.join(ml_dir, 'z3native_stubs.c') ml_native = open(ml_nativef, 'w') ml_i = open(ml_nativefi, 'w') ml_native.write('(* Automatically generated file *)\n\n') From ec0b12ecd16742edf1fcfaee41eedd832e952f15 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 13:06:29 +0100 Subject: [PATCH 204/248] ML API refactoring (z3native.c -> z3native_stubs.c) Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 648013ca1..3cd2d3ef3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ *~ *.pyc +*.pyo +# Ignore callgrind files +callgrind.out.* # .hpp files are automatically generated *.hpp .z3-trace @@ -42,7 +45,6 @@ bld_rel_x64/* # Auto generated files. config.log config.status -configure install_tactic.cpp mem_initializer.cpp gparams_register_modules.cpp @@ -54,6 +56,8 @@ src/api/api_log_macros.cpp src/api/dll/api_dll.def src/api/dotnet/Enumerations.cs src/api/dotnet/Native.cs +src/api/dotnet/Properties/AssemblyInfo.cs +src/api/dotnet/Microsoft.Z3.xml src/api/python/z3consts.py src/api/python/z3core.py src/ast/pattern/database.h @@ -61,21 +65,7 @@ src/util/version.h src/api/java/Native.cpp src/api/java/Native.java src/api/java/enumerations/*.java -*.bak -doc/api -doc/code -src/api/ml/z3_native.c -src/api/ml/z3_native.ml -src/api/ml/native.c -src/api/ml/z3.ml -src/api/ml/enumerations.ml -src/api/ml/z3native.c src/api/ml/z3native_stubs.c src/api/ml/z3native.ml src/api/ml/z3enums.ml src/api/ml/z3.mllib -src/api/ml/z3_native.c -src/api/ml/z3_native.ml -src/api/ml/native.c -src/api/ml/z3.ml -src/api/ml/enumerations.ml From 409a40a5627290a04ab6a60df25f58580c87b01c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 14:18:46 +0100 Subject: [PATCH 205/248] ML API: Added get_bit_int and get_ratio Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 4 +- src/api/ml/z3.ml | 101 +++++++++++++++++++++++++-------------------- src/api/ml/z3.mli | 12 ++++-- 3 files changed, 67 insertions(+), 50 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index ab13bb943..8dcf3dda6 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1553,7 +1553,7 @@ class MLExampleComponent(ExampleComponent): out.write('\t%s ' % OCAMLC) if DEBUG_MODE: out.write('-g ') - out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" z3.cma') + out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" nums.cma z3.cma') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') @@ -1564,7 +1564,7 @@ class MLExampleComponent(ExampleComponent): out.write('\t%s ' % OCAMLOPT) if DEBUG_MODE: out.write('-g ') - out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" z3.cmxa') + out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" nums.cmxa z3.cmxa') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 051a54696..dda8807c9 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1425,6 +1425,50 @@ end module Arithmetic = struct + let is_int ( x : expr ) = + (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) + + let is_arithmetic_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) + + let is_le ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) + + let is_ge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) + + let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) + + let is_gt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) + + let is_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) + + let is_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) + + let is_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) + + let is_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) + + let is_div ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) + + let is_idiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) + + let is_remainder ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) + + let is_modulus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) + + let is_inttoreal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + + let is_real_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + + let is_real_is_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) + + let is_real ( x : expr ) = + ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) + + let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) + + let is_rat_numeral ( x : expr ) = (Expr.is_numeral x) && (is_real x) + + let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) module Integer = struct @@ -1435,6 +1479,12 @@ struct let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in if r then v else raise (Z3native.Exception "Conversion failed.") + + let get_big_int ( x : expr ) = + if (is_int_numeral x) then + let s = to_string(x) in + (Big_int.big_int_of_string s) + else raise (Z3native.Exception "Conversion failed.") let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) @@ -1474,6 +1524,12 @@ struct let get_denominator ( x : expr ) = expr_of_ptr (Expr.gc x) (Z3native.get_denominator (Expr.gnc x) (Expr.gno x)) + let get_ratio ( x : expr ) = + if (is_rat_numeral x) then + let s = to_string(x) in + (Ratio.ratio_of_string s) + else raise (Z3native.Exception "Conversion failed.") + let to_decimal_string ( x : expr ) ( precision : int ) = Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision @@ -1518,51 +1574,6 @@ struct end end - let is_int ( x : expr ) = - (Z3native.is_numeral_ast (Expr.gnc x) (Expr.gno x)) && - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == INT_SORT) - - let is_arithmetic_numeral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ANUM) - - let is_le ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LE) - - let is_ge ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GE) - - let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_LT) - - let is_gt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_GT) - - let is_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ADD) - - let is_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_SUB) - - let is_uminus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_UMINUS) - - let is_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MUL) - - let is_div ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_DIV) - - let is_idiv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IDIV) - - let is_remainder ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_REM) - - let is_modulus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - - let is_inttoreal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - - let is_real_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) - - let is_real_is_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) - - let is_real ( x : expr ) = - ((sort_kind_of_int (Z3native.get_sort_kind (Expr.gnc x) (Z3native.get_sort (Expr.gnc x) (Expr.gno x)))) == REAL_SORT) - - let is_int_numeral ( x : expr ) = (Expr.is_numeral x) && (is_int x) - - let is_rat_num ( x : expr ) = (Expr.is_numeral x) && (is_real x) - - let is_algebraic_number ( x : expr ) = Z3native.is_algebraic_number (Expr.gnc x) (Expr.gno x) - let mk_add ( ctx : context ) ( t : expr list ) = let f x = (Expr.gno x) in (expr_of_ptr ctx (Z3native.mk_add (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index c554d7564..4122f40f2 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1149,6 +1149,9 @@ sig (** Retrieve the int value. *) val get_int : Expr.expr -> int + (** Get a big_int from an integer numeral *) + val get_big_int : Expr.expr -> Big_int.big_int + (** Returns a string representation of the numeral. *) val to_string : Expr.expr -> string @@ -1201,10 +1204,13 @@ sig val mk_sort : context -> Sort.sort (** The numerator of a rational numeral. *) - val get_numerator : Expr.expr-> Expr.expr + val get_numerator : Expr.expr -> Expr.expr (** The denominator of a rational numeral. *) - val get_denominator : Expr.expr-> Expr.expr + val get_denominator : Expr.expr -> Expr.expr + + (** Get a ratio from a real numeral *) + val get_ratio : Expr.expr -> Ratio.ratio (** Returns a string representation in decimal notation. The result has at most as many decimal places as indicated by the int argument.*) @@ -1323,7 +1329,7 @@ sig val is_int_numeral : Expr.expr -> bool (** Indicates whether the term is a real numeral. *) - val is_rat_num : Expr.expr -> bool + val is_rat_numeral : Expr.expr -> bool (** Indicates whether the term is an algebraic number *) val is_algebraic_number : Expr.expr -> bool From 65ab6d537307c1680844fe1db6cd68e7146f9b66 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 15:33:07 +0100 Subject: [PATCH 206/248] ML API: build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8dcf3dda6..f57763ff1 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1393,7 +1393,7 @@ class MLComponent(Component): out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CXX) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) + out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): From 05af33ac7d4f0a7eb63d343ee39bf653563a4e46 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 16:10:18 +0100 Subject: [PATCH 207/248] ML API: ocamlfind installation fixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/README | 4 ++-- scripts/mk_util.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/ml/README b/examples/ml/README index a14cbeb63..31d4b8e2e 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -15,8 +15,8 @@ for the byte-code version. If Z3 was installed into the ocamlfind package repository (see src/api/ml/README), then we can compile this example as follows: -ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg -ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg +ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg ml_example.ml +ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg ml_example.ml Note that the resulting binaries depend on the shared z3 library, which needs to be in the PATH (Windows), LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX). If Z3 was diff --git a/scripts/mk_util.py b/scripts/mk_util.py index f57763ff1..a0c9213c9 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1419,6 +1419,9 @@ class MLComponent(Component): out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) + for m in modules: + out.write(' %s.cmi' % (os.path.join(sub_dir, m))) + out.write(' %s.cmx' % (os.path.join(sub_dir, m))) if IS_WINDOWS: out.write(' libz3$(LIB_EXT)') out.write('\n') From 59371416050c6a2c38d8b893f65f09887114c73e Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 16:10:29 +0100 Subject: [PATCH 208/248] ML API: bugfix Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index 0ed9b29ca..8ce652ed5 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1254,7 +1254,7 @@ def mk_ml(): ml_native.write(' a%d' % i) i = i + 1 ml_native.write(') in\n') - if len(params) > 0 and param_type(params[0]) == CONTEXT: + if name not in Unwrapped and len(params) > 0 and param_type(params[0]) == CONTEXT: ml_native.write(' let err = (error_code_of_int (ML2C.n_get_error_code a0)) in \n') ml_native.write(' if err <> OK then\n') ml_native.write(' raise (Exception (ML2C.n_get_error_msg_ex a0 (int_of_error_code err)))\n') From cc4010591989908ab2f54a2a7fec7f5ec1ca1840 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 16:12:55 +0100 Subject: [PATCH 209/248] ML API doc fix Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 4122f40f2..8a88a91bb 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -2404,7 +2404,7 @@ sig (** The finite set of distinct values that represent the interpretation of a sort. {!get_sorts} - @returns A list of expressions, where each is an element of the universe of the sort *) + @return A list of expressions, where each is an element of the universe of the sort *) val sort_universe : model -> Sort.sort -> AST.ast list (** Conversion of models to strings. From 83690a8fe3a64cc45f16a444f7b82e0d1c27f9fe Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 16 Apr 2014 16:16:40 +0100 Subject: [PATCH 210/248] ML API doc fixes Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.mli | 220 +++++++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 8a88a91bb..ff45fb0f2 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -241,7 +241,7 @@ sig 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., - Z3native.inc_ref). + [Z3native.inc_ref]). {!wrap_ast} *) val unwrap_ast : ast -> Z3native.ptr @@ -251,7 +251,7 @@ sig managed objects. Note that the native ast that is passed must be a native object obtained from Z3 (e.g., through {!unwrap_ast}) and that it must have a correct reference count (see e.g., - Z3native.inc_ref). *) + [Z3native.inc_ref]). *) val wrap_ast : context -> Z3native.z3_ast -> ast end @@ -439,7 +439,7 @@ sig (** Update a mutable configuration parameter. The list of all configuration parameters can be obtained using the Z3 executable: - z3.exe -p + [z3.exe -p] Only a few configuration parameters are mutable once the context is created. An exception is thrown when trying to modify an immutable parameter. {!get_param_value} *) @@ -479,7 +479,7 @@ sig {!get_simplify_help} *) val simplify : Expr.expr -> Params.params option -> expr - (** A string describing all available parameters to Expr.Simplify. *) + (** A string describing all available parameters to [Expr.Simplify]. *) val get_simplify_help : context -> string (** Retrieves parameter descriptions for simplifier. *) @@ -498,20 +498,20 @@ sig The number of new arguments should coincide with the current number of arguments. *) val update : Expr.expr -> Expr.expr list -> expr - (** Substitute every occurrence of from[i] in the expression with to[i], for i smaller than num_exprs. + (** 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]. *) + 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]]. *) val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr - (** Substitute every occurrence of from in the expression with to. + (** Substitute every occurrence of [from] in the expression with [to]. {!substitute} *) val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr (** Substitute the free variables in the expression with the expressions in the expr array - For every i smaller than num_exprs, the variable with de-Bruijn index i is replaced with term to[i]. *) + For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term [to[i]]. *) val substitute_vars : Expr.expr -> Expr.expr list -> expr (** Translates (copies) the term to another context. @@ -554,7 +554,7 @@ sig val mk_numeral_string : context -> string -> Sort.sort -> expr (** Create a numeral 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. + It is slightly faster than [MakeNumeral] since it is not necessary to parse a string. @return A Term with the given value and sort *) val mk_numeral_int : context -> int -> Sort.sort -> expr end @@ -580,19 +580,19 @@ sig (** Creates a Boolean value. *) val mk_val : context -> bool -> Expr.expr - (** Mk an expression representing not(a). *) + (** Mk an expression representing [not(a)]. *) val mk_not : context -> Expr.expr -> Expr.expr - (** Create an expression representing an if-then-else: ite(t1, t2, t3). *) + (** Create an expression representing an if-then-else: [ite(t1, t2, t3)]. *) val mk_ite : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 iff t2. *) + (** Create an expression representing [t1 iff t2]. *) val mk_iff : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 -> t2. *) + (** Create an expression representing [t1 -> t2]. *) val mk_implies : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 xor t2. *) + (** Create an expression representing [t1 xor t2]. *) val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing the AND of args *) @@ -604,7 +604,7 @@ sig (** Creates the equality between two expr's. *) val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Creates a distinct term. *) + (** Creates a [distinct] term. *) val mk_distinct : context -> Expr.expr list -> Expr.expr (** Indicates whether the expression is the true or false expression @@ -806,45 +806,45 @@ sig (** Array read. - The argument a is the array and i is the index + 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. + The node [a] must have an array sort [[domain -> range]], + and [i] must have the sort [domain]. + The sort of the result is [range]. {!Z3Array.mk_sort} {!mk_store} *) val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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 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). + 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). {!Z3Array.mk_sort} {!mk_select} *) val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr (** Create a constant array. - The resulting term is an array, such that a selecton an arbitrary index - produces the value v. + The resulting term is an array, such that a [select]on an arbitrary index + produces the value [v]. {!Z3Array.mk_sort} {!mk_select} *) val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr (** 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]. + 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]]. {!Z3Array.mk_sort} {!mk_select} {!mk_store} *) @@ -938,8 +938,8 @@ sig (** 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. *) + 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. *) val is_store : Expr.expr -> bool (** Indicates whether the term is an empty relation *) @@ -997,8 +997,8 @@ sig (** 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. *) + The function takes [n+1] arguments, where the first argument is a relation, + and the remaining [n] arguments correspond to a record. *) val is_select : Expr.expr -> bool (** Indicates whether the term is a relational clone (copy) @@ -1161,11 +1161,11 @@ sig (** Creates an integer constant. *) val mk_const_s : context -> string -> Expr.expr - (** Create an expression representing t1 mod t2. + (** Create an expression representing [t1 mod t2]. The arguments must have int type. *) val mk_mod : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 rem t2. + (** Create an expression representing [t1 rem t2]. The arguments must have int type. *) val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -1181,8 +1181,8 @@ sig 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. + 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. *) val mk_int2real : context -> Expr.expr -> Expr.expr @@ -1334,34 +1334,34 @@ sig (** Indicates whether the term is an algebraic number *) val is_algebraic_number : Expr.expr -> bool - (** Create an expression representing t[0] + t[1] + .... *) + (** Create an expression representing [t[0] + t[1] + ...]. *) val mk_add : context -> Expr.expr list -> Expr.expr - (** Create an expression representing t[0] * t[1] * .... *) + (** Create an expression representing [t[0] * t[1] * ...]. *) val mk_mul : context -> Expr.expr list -> Expr.expr - (** Create an expression representing t[0] - t[1] - .... *) + (** Create an expression representing [t[0] - t[1] - ...]. *) val mk_sub : context -> Expr.expr list -> Expr.expr - (** Create an expression representing -t. *) + (** Create an expression representing [-t]. *) val mk_unary_minus : context -> Expr.expr -> Expr.expr - (** Create an expression representing t1 / t2. *) + (** Create an expression representing [t1 / t2]. *) val mk_div : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 ^ t2. *) + (** Create an expression representing [t1 ^ t2]. *) val mk_power : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 < t2 *) + (** Create an expression representing [t1 < t2] *) val mk_lt : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 <= t2 *) + (** Create an expression representing [t1 <= t2] *) val mk_le : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 > t2 *) + (** Create an expression representing [t1 > t2] *) val mk_gt : context -> Expr.expr -> Expr.expr -> Expr.expr - (** Create an expression representing t1 >= t2 *) + (** Create an expression representing [t1 >= t2] *) val mk_ge : context -> Expr.expr -> Expr.expr -> Expr.expr end @@ -1610,8 +1610,8 @@ sig (** 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 + 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. *) val mk_udiv : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -1620,33 +1620,33 @@ sig 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 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. + - 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. + If [t2] is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) val mk_sdiv : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. + 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. *) val mk_urem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Signed remainder. - It is defined as t1 - (t1 /s t2) * t2, where /s represents signed division. + 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. + If [t2] is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) val mk_srem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed remainder (sign follows divisor). - If t2 is zero, then the result is undefined. + If [t2] is zero, then the result is undefined. The arguments must have the same bit-vector sort. *) val mk_smod : context -> Expr.expr -> Expr.expr -> Expr.expr @@ -1694,27 +1694,27 @@ sig 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). *) + The result is a bit-vector of size [n1+n2], where [n1] ([n2]) + is the size of [t1] ([t2]). *) val mk_concat : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bit-vector extraction. Extract the bits between two limits from a bitvector of - size m to yield a new bitvector of size n, where - n = high - low + 1. *) + size [m] to yield a new bitvector of size [n], where + [n = high - low + 1]. *) val mk_extract : context -> int -> int -> Expr.expr -> Expr.expr (** 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. *) + size [m+i], where \c m is the size of the given bit-vector. *) val mk_sign_ext : context -> int -> Expr.expr -> Expr.expr (** 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 + bitvector of size [m+i], where \c m is the size of the given bit-vector. *) val mk_zero_ext : context -> int -> Expr.expr -> Expr.expr @@ -1723,7 +1723,7 @@ sig (** Shift left. - It is equivalent to multiplication by 2^x where \c x is the value of third argument. + It is equivalent to multiplication by [2^x] where \c x is the value of third argument. NB. The semantics of shift operations varies between environments. This definition does not necessarily capture directly the semantics of the @@ -1732,7 +1732,7 @@ sig (** Logical shift right - It is equivalent to unsigned division by 2^x where \c x is the value of the third argument. + It is equivalent to unsigned division by [2^x] where \c x is the value of the third argument. NB. The semantics of shift operations varies between environments. This definition does not necessarily capture directly the semantics of the @@ -1773,7 +1773,7 @@ sig (** 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 + So the result is non-negative and in the range [[0..2^N-1]], where N are the number of bits in the argument. If \c is_signed is true, \c t1 is treated as a signed bit-vector. @@ -2353,15 +2353,15 @@ sig end (** Retrieves the interpretation (the assignment) of a func_decl in the model. - An expression if the function has an interpretation in the model, null otherwise. *) + @return An expression if the function has an interpretation in the model, null otherwise. *) val get_const_interp : model -> FuncDecl.func_decl -> Expr.expr option (** Retrieves the interpretation (the assignment) of an expression in the model. - An expression if the constant has an interpretation in the model, null otherwise. *) + @return An expression if the constant has an interpretation in the model, null otherwise. *) val get_const_interp_e : model -> Expr.expr -> Expr.expr option (** Retrieves the interpretation (the assignment) of a non-constant func_decl in the model. - A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) + @return A FunctionInterpretation if the function has an interpretation in the model, null otherwise. *) val get_func_interp : model -> FuncDecl.func_decl -> FuncInterp.func_interp option (** The number of constant interpretations in the model. *) @@ -2383,11 +2383,11 @@ sig This function may fail if the argument contains quantifiers, is partial (MODEL_PARTIAL enabled), or if it is not well-sorted. - In this case a ModelEvaluationFailedException is thrown. + In this case a [ModelEvaluationFailedException] is thrown. *) val eval : model -> Expr.expr -> bool -> Expr.expr option - (** Alias for eval. *) + (** Alias for [eval]. *) val evaluate : model -> Expr.expr -> bool -> Expr.expr option (** The number of uninterpreted sorts that the model has an interpretation for. *) @@ -2408,7 +2408,7 @@ sig val sort_universe : model -> Sort.sort -> AST.ast list (** Conversion of models to strings. - A string representation of the model. *) + @return A string representation of the model. *) val to_string : model -> string end @@ -2416,17 +2416,17 @@ end 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. + 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. *) module Probe : sig type probe (** Execute the probe over the goal. - A probe always produce a float value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) + @return A probe always produce a float value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) val apply : probe -> Goal.goal -> float (** The number of supported Probes. *) @@ -2478,9 +2478,9 @@ end (** Tactics Tactics are the basic building block for creating custom solvers for specific problem domains. - The complete list of tactics may be obtained using Context.get_num_tactics - and Context.get_tactic_names. - It may also be obtained using the command (help-tactics) in the SMT 2.0 front-end. + The complete list of tactics may be obtained using [Context.get_num_tactics] + and [Context.get_tactic_names]. + It may also be obtained using the command [(help-tactics)] in the SMT 2.0 front-end. *) module Tactic : sig @@ -2504,8 +2504,8 @@ sig val get_subgoal : apply_result -> int -> Goal.goal (** Convert a model for a subgoal into a model for the original - goal g, that the ApplyResult was obtained from. - #return A model for g *) + goal [g], that the ApplyResult was obtained from. + #return A model for [g] *) val convert_model : apply_result -> int -> Model.model -> Model.model (** A string representation of the ApplyResult. *) @@ -2549,7 +2549,7 @@ sig (** Create a tactic that applies one tactic to a given goal if the probe evaluates to true. - If the probe evaluates to false, then the new tactic behaves like the skip tactic. *) + If the probe evaluates to false, then the new tactic behaves like the [skip] tactic. *) val when_ : context -> Probe.probe -> tactic -> tactic (** Create a tactic that applies a tactic to a given goal if the probe @@ -2577,7 +2577,7 @@ sig val using_params : context -> tactic -> Params.params -> tactic (** Create a tactic that applies a tactic using the given set of parameters. - Alias for UsingParams*) + Alias for [UsingParams]*) val with_ : context -> tactic -> Params.params -> tactic (** Create a tactic that applies the given tactics in parallel. *) @@ -2718,26 +2718,26 @@ sig {!Proof} *) val check : solver -> Expr.expr list -> status - (** The model of the last Check. + (** The model of the last [Check]. - The result is None if Check was not invoked before, - if its results was not SATISFIABLE, or if model production is not enabled. *) + The result is [None] if [Check] was not invoked before, + if its results was not [SATISFIABLE], or if model production is not enabled. *) val get_model : solver -> Model.model option - (** The proof of the last Check. + (** 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. *) + The result is [null] if [Check] was not invoked before, + if its results was not [UNSATISFIABLE], or if proof production is disabled. *) val get_proof : solver -> Expr.expr option - (** The unsat core of the last Check. + (** 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. *) + 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. *) val get_unsat_core : solver -> AST.ast list - (** A brief justification of why the last call to Check returned UNKNOWN. *) + (** A brief justification of why the last call to [Check] returned [UNKNOWN]. *) val get_reason_unknown : solver -> string (** Solver statistics. *) @@ -2759,7 +2759,7 @@ sig (** Creates a solver that is implemented using the given tactic. - The solver supports the commands Push and Pop, but it + The solver supports the commands [Push] and [Pop], but it will always solve each check from scratch. *) val mk_solver_t : context -> Tactic.tactic -> solver @@ -2811,7 +2811,7 @@ sig (** Backtrack one backtracking point. - Note that an exception is thrown if Pop is called without a corresponding Push + Note that an exception is thrown if Pop is called without a corresponding [Push] {!push} *) val pop : fixedpoint -> unit @@ -2875,28 +2875,28 @@ sig {!parse_smtlib_string} *) val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit - (** The number of SMTLIB formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The number of SMTLIB formulas parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_num_smtlib_formulas : context -> int - (** The formulas parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The formulas parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_smtlib_formulas : context -> Expr.expr list - (** The number of SMTLIB assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The number of SMTLIB assumptions parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_num_smtlib_assumptions : context -> int - (** The assumptions parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The assumptions parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_smtlib_assumptions : context -> Expr.expr list - (** The number of SMTLIB declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The number of SMTLIB declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_num_smtlib_decls : context -> int - (** The declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_smtlib_decls : context -> FuncDecl.func_decl list - (** The number of SMTLIB sorts parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The number of SMTLIB sorts parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_num_smtlib_sorts : context -> int - (** The sort declarations parsed by the last call to ParseSMTLIBString or ParseSMTLIBFile. *) + (** The sort declarations parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) val get_smtlib_sorts : context -> Sort.sort list (** Parse the given string using the SMT-LIB2 parser. From e7345f5ea809049d56705635208ffac8b93ab87a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 17 Apr 2014 15:06:32 +0100 Subject: [PATCH 211/248] ML API bugfix Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index dda8807c9..e2fa01478 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1482,7 +1482,7 @@ struct let get_big_int ( x : expr ) = if (is_int_numeral x) then - let s = to_string(x) in + let s = (Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x)) in (Big_int.big_int_of_string s) else raise (Z3native.Exception "Conversion failed.") @@ -1526,7 +1526,7 @@ struct let get_ratio ( x : expr ) = if (is_rat_numeral x) then - let s = to_string(x) in + let s = (Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x)) in (Ratio.ratio_of_string s) else raise (Z3native.Exception "Conversion failed.") From a73a66b79c64971109ab3425654a8299ff1332bf Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 22 Apr 2014 11:49:47 +0100 Subject: [PATCH 212/248] ML API bugfix Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index e2fa01478..dafd255f8 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -119,7 +119,7 @@ let mk_list ( f : int -> 'a ) ( n : int ) = if (i >= n) then tail else - (mk_list' f (i+1) n ((f i) :: tail)) + (f i) :: (mk_list' f (i+1) n tail) in mk_list' f 0 n [] From 9160925c28fbcc3586dc15dad249096f06bec148 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 23 Apr 2014 15:15:59 +0100 Subject: [PATCH 213/248] ML API: added Expr.equal and Expr.compare Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 6 ++++++ src/api/ml/z3.mli | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index dafd255f8..3f40b288c 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -717,6 +717,8 @@ sig val mk_app : context -> FuncDecl.func_decl -> expr list -> expr val mk_numeral_string : context -> string -> Sort.sort -> expr val mk_numeral_int : context -> int -> Sort.sort -> expr + val equal : expr -> expr -> bool + val compare : expr -> expr -> int end = struct type expr = Expr of AST.ast @@ -830,6 +832,10 @@ end = struct let mk_numeral_int ( ctx : context ) ( v : int ) ( ty : sort ) = expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) + + let equal ( a : expr ) ( b : expr ) = AST.equal (ast_of_expr a) (ast_of_expr b) + + let compare a b = AST.compare (ast_of_expr a) (ast_of_expr b) end open FuncDecl diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index ff45fb0f2..84f230d95 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -554,9 +554,17 @@ sig val mk_numeral_string : context -> string -> Sort.sort -> expr (** Create a numeral 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. - @return A Term with the given value and sort *) + It is slightly faster than [MakeNumeral] since it is not necessary to parse a string. + @return A Term with the given value and sort *) val mk_numeral_int : context -> int -> Sort.sort -> expr + + (** Comparison operator. + @return True if the two expr's are equal; false otherwise. *) + val equal : expr -> expr -> bool + + (** Object Comparison. + @return Negative if the first expr should be sorted before the second, positive if after, else zero. *) + val compare : expr -> expr -> int end (** Boolean expressions; Propositional logic and equality *) From 5e2a7e06fd21ce14e3ff33042fbec7562307d3a4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Wed, 23 Apr 2014 15:25:08 +0100 Subject: [PATCH 214/248] ML API: added constructors for ast_map and ast_vector Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 31 ++++++++++++++++++++++--------- src/api/ml/z3.mli | 20 ++++++++++++-------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 3f40b288c..b48681b87 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -214,7 +214,7 @@ struct struct type ast_vector = z3_native_object - let ast_vector_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; inc_ref = Z3native.ast_vector_inc_ref ; @@ -223,6 +223,8 @@ struct (z3obj_create res) ; res + let mk_ast_vector ( ctx : context ) = (create ctx (Z3native.mk_ast_vector (context_gno ctx))) + let get_size ( x : ast_vector ) = Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) @@ -239,7 +241,7 @@ struct Z3native.ast_vector_push (z3obj_gnc x) (z3obj_gno x) (z3obj_gno a) let translate ( x : ast_vector ) ( to_ctx : context ) = - ast_vector_of_ptr to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) + create to_ctx (Z3native.ast_vector_translate (z3obj_gnc x) (z3obj_gno x) (context_gno to_ctx)) let to_string ( x : ast_vector ) = Z3native.ast_vector_to_string (z3obj_gnc x) (z3obj_gno x) @@ -248,7 +250,18 @@ struct module ASTMap = struct type ast_map = z3_native_object + + let create ( ctx : context ) ( no : Z3native.ptr ) = + let res : ast_map = { m_ctx = ctx ; + m_n_obj = null ; + inc_ref = Z3native.ast_map_inc_ref ; + dec_ref = Z3native.ast_map_dec_ref } in + (z3obj_sno res ctx no) ; + (z3obj_create res) ; + res + let mk_ast_map ( ctx : context ) = (create ctx (Z3native.mk_ast_map (context_gno ctx))) + let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_map = { m_ctx = ctx ; m_n_obj = null ; @@ -277,7 +290,7 @@ struct Z3native.ast_map_size (z3obj_gnc x) (z3obj_gno x) let get_keys ( x : ast_map ) = - let av = ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in + let av = ASTVector.create (z3obj_gc x) (Z3native.ast_map_keys (z3obj_gnc x) (z3obj_gno x)) in let f i = (ASTVector.get av i) in mk_list f (ASTVector.get_size av) @@ -2061,7 +2074,7 @@ struct mk_list f n let sort_universe ( x : model ) ( s : sort ) = - let n_univ = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in + let n_univ = AST.ASTVector.create (z3obj_gc x) (Z3native.model_get_sort_universe (z3obj_gnc x) (z3obj_gno x) (Sort.gno s)) in let n = (AST.ASTVector.get_size n_univ) in let f i = (AST.ASTVector.get n_univ i) in mk_list f n @@ -2386,11 +2399,11 @@ struct Z3native.solver_assert_and_track (z3obj_gnc x) (z3obj_gno x) (Expr.gno c) (Expr.gno p) let get_num_assertions ( x : solver ) = - let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in (AST.ASTVector.get_size a) let get_assertions ( x : solver ) = - let a = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in + let a = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_assertions (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size a) in let f i = (expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get a i))) in mk_list f n @@ -2423,7 +2436,7 @@ struct Some (expr_of_ptr (z3obj_gc x) q) let get_unsat_core ( x : solver ) = - let cn = AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in + let cn = AST.ASTVector.create (z3obj_gc x) (Z3native.solver_get_unsat_core (z3obj_gnc x) (z3obj_gno x)) in let n = (AST.ASTVector.get_size cn) in let f i = (AST.ASTVector.get cn i) in mk_list f n @@ -2545,13 +2558,13 @@ struct Z3native.fixedpoint_to_string (z3obj_gnc x) (z3obj_gno x) (List.length queries) (Array.of_list (List.map f queries)) let get_rules ( x : fixedpoint ) = - let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_rules (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in mk_list f n let get_assertions ( x : fixedpoint ) = - let v = (AST.ASTVector.ast_vector_of_ptr (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in + let v = (AST.ASTVector.create (z3obj_gc x) (Z3native.fixedpoint_get_assertions (z3obj_gnc x) (z3obj_gno x))) in let n = (AST.ASTVector.get_size v) in let f i =(expr_of_ptr (z3obj_gc x) (z3obj_gno (AST.ASTVector.get v i))) in mk_list f n diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 84f230d95..4347c7431 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -107,10 +107,9 @@ sig (** A string representation of the symbol. *) val to_string : symbol -> string - (** 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. *) + (** 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. *) val mk_int : context -> int -> symbol (** Creates a new symbol using a string. *) @@ -132,12 +131,14 @@ sig module ASTVector : sig type ast_vector + + (** Create an empty AST vector *) + val mk_ast_vector : context -> ast_vector (** The size of the vector *) val get_size : ast_vector -> int - (** - Retrieves the i-th object in the vector. + (** Retrieves the i-th object in the vector. @return An AST *) val get : ast_vector -> int -> ast @@ -162,7 +163,10 @@ sig (** Map from AST to AST *) module ASTMap : sig - type ast_map + type ast_map + + (** Create an empty mapping from AST to AST *) + val mk_ast_map : context -> ast_map (** Checks whether the map contains a key. @return True if the key in the map, false otherwise. *) @@ -2297,7 +2301,7 @@ sig (** Creates a new Goal. - Note that the Context must have been created with proof generation support if + Note that the Context must have been created with proof generation support if the fourth argument is set to true here. *) val mk_goal : context -> bool -> bool -> bool -> goal From a8f703e0344812ee94b037bda9a17802415ff03d Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 24 Jul 2014 18:50:11 +0100 Subject: [PATCH 215/248] ML API bugfix. Thanks to Martin Neuhaeusser for reporting this one! Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index b48681b87..bdcf1a26b 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -2045,7 +2045,7 @@ struct let get_num_funcs ( x : model ) = Z3native.model_get_num_funcs (z3obj_gnc x) (z3obj_gno x) let get_func_decls ( x : model ) = - let n = (get_num_consts x) in + let n = (get_num_funcs x) in let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in mk_list f n From 7ec8c81c3369613a3baf5272b1973344997a9927 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 24 Jul 2014 18:59:03 +0100 Subject: [PATCH 216/248] ML API fix for datatype construction (Issue #121). Thanks to Elarnon for reporting this one! Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 12 ++++++++---- src/api/ml/z3.mli | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index bdcf1a26b..f34ce0ca7 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -374,6 +374,10 @@ struct let sort_lton ( a : sort list ) = let f ( e : sort ) = match e with Sort(a) -> (AST.ptr_of_ast a) in Array.of_list (List.map f a) + + let sort_option_lton ( a : sort option list ) = + let f ( e : sort option ) = match e with None -> null | Some(Sort(a)) -> (AST.ptr_of_ast a) in + Array.of_list (List.map f a) let equal : sort -> sort -> bool = fun a b -> (a == b) || @@ -1257,7 +1261,7 @@ struct let _sizes = Hashtbl.create 0 - let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = let n = (List.length field_names) in if n != (List.length sorts) then raise (Z3native.Exception "Number of field names does not match number of sorts") @@ -1269,7 +1273,7 @@ struct (Symbol.gno recognizer) n (Symbol.symbol_lton field_names) - (sort_lton sorts) + (sort_option_lton sorts) (Array.of_list sort_refs)) in let no : constructor = { m_ctx = ctx ; m_n_obj = null ; @@ -1316,11 +1320,11 @@ struct res end - let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let mk_constructor ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = Constructor.create ctx name recognizer field_names sorts sort_refs - let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort list ) ( sort_refs : int list ) = + let mk_constructor_s ( ctx : context ) ( name : string ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = mk_constructor ctx (Symbol.mk_string ctx name) recognizer field_names sorts sort_refs let mk_sort ( ctx : context ) ( name : Symbol.symbol ) ( constructors : Constructor.constructor list ) = diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 4347c7431..1342bb4bc 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1053,12 +1053,12 @@ sig (** Create a datatype 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. *) - val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor (** Create a datatype 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. *) - val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort list -> int list -> Constructor.constructor + val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor (** Create a new datatype sort. *) val mk_sort : context -> Symbol.symbol -> Constructor.constructor list -> Sort.sort From 84b7644305c64475c0aedb72f202c384342a6155 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 24 Jul 2014 19:16:16 +0100 Subject: [PATCH 217/248] ML API bugfix (Issue #119). Thanks to user Elarnon for reporting this! Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index 8ce652ed5..fba194bac 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -1464,7 +1464,7 @@ def mk_ml(): for p in params: if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) - ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) + ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s_val, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) elif is_out_param(p): ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) i = i + 1 From 94a8c271d4fb3c47086dacc27ae789e80867d951 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 24 Jul 2014 19:29:06 +0100 Subject: [PATCH 218/248] ML API bugfix for datatype module (Issue #120). Thanks to user Elarnon for reporting this! Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/z3.ml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index f34ce0ca7..013101398 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -277,7 +277,7 @@ struct let find ( x : ast_map ) ( key : ast ) = ast_of_ptr (z3obj_gc x) (Z3native.ast_map_find (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key)) - let insert ( x : ast_map ) ( key : ast ) ( value : ast) = + let insert ( x : ast_map ) ( key : ast ) ( value : ast ) = Z3native.ast_map_insert (z3obj_gnc x) (z3obj_gno x) (z3obj_gno key) (z3obj_gno value) let erase ( x : ast_map ) ( key : ast ) = @@ -1259,7 +1259,13 @@ struct struct type constructor = z3_native_object - let _sizes = Hashtbl.create 0 + module FieldNumTable = Hashtbl.Make(struct + type t = AST.ast + let equal x y = AST.compare x y = 0 + let hash = AST.hash + end) + + let _field_nums = FieldNumTable.create 0 let create ( ctx : context ) ( name : Symbol.symbol ) ( recognizer : Symbol.symbol ) ( field_names : Symbol.symbol list ) ( sorts : sort option list ) ( sort_refs : int list ) = let n = (List.length field_names) in @@ -1283,10 +1289,10 @@ struct (z3obj_create no) ; let f = fun o -> Z3native.del_constructor (z3obj_gnc o) (z3obj_gno o) in Gc.finalise f no ; - Hashtbl.add _sizes no n ; + FieldNumTable.add _field_nums no n ; no - let get_num_fields ( x : constructor ) = Hashtbl.find _sizes x + let get_num_fields ( x : constructor ) = FieldNumTable.find _field_nums x let get_constructor_decl ( x : constructor ) = let (a, _, _) = (Z3native.query_constructor (z3obj_gnc x) (z3obj_gno x) (get_num_fields x)) in From fa4dab48522f4d9e96f4f7456cc57c9208cf622f Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 14 Aug 2014 18:58:52 +0100 Subject: [PATCH 219/248] ML API: added .cmxs to the distribution. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index a0c9213c9..bf1f5e471 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1402,7 +1402,12 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + out.write('\t%s ' % (OCAMLOPT)) + if DEBUG_MODE: + out.write('-g ') + out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) @@ -1410,15 +1415,15 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L../.. -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) - out.write('ml: api/ml/z3.cmxa api/ml/z3.cma\n') + out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa\n') + out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs\n') out.write('\t%s remove Z3\n' % (OCAMLFIND)) - out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) + out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) for m in modules: out.write(' %s.cmi' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) From fe0b579426cdb98ebe6f24324eb98fc0b8cddb0c Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:02:00 +0100 Subject: [PATCH 220/248] ML API: bugfixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index bf1f5e471..784d47cee 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1402,12 +1402,12 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib -lz3ml -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + out.write('-shared -o %s %s -linkall\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) @@ -1415,7 +1415,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib -lz3ml -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands From a1bb307dd18bb02ba375e570805b36bbe5107f15 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:09:01 +0100 Subject: [PATCH 221/248] ML API: bugfixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 784d47cee..3e9bd8eb2 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1402,7 +1402,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib -lz3ml -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-Lapi/ml -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: @@ -1415,7 +1415,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib -lz3ml -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-Lapi/ml -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands From 7bd8dda766fa01a23b83367b27335d744af0c9e8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:18:40 +0100 Subject: [PATCH 222/248] ML API: bugfixes --- scripts/mk_util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 3e9bd8eb2..ef01ccc10 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1402,12 +1402,12 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-Lapi/ml -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L%s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir,sub_dir)) out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-shared -o %s %s -linkall\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + out.write('-shared -cclib "-L%s -lz3ml" -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir,'z3.cmxa'))) out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) @@ -1415,7 +1415,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-Lapi/ml -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L%s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands From 8cd74a825d8c148566848835924dccb15c3982f6 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 19 Aug 2014 19:32:33 +0100 Subject: [PATCH 223/248] ML API: Undoing earlier changes. Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index ef01ccc10..bf1f5e471 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1402,12 +1402,12 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L%s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('\t%s ' % (OCAMLOPT)) if DEBUG_MODE: out.write('-g ') - out.write('-shared -cclib "-L%s -lz3ml" -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir,'z3.cmxa'))) + out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) @@ -1415,7 +1415,7 @@ class MLComponent(Component): out.write('\t%s ' % (OCAMLC)) if DEBUG_MODE: out.write('-g ') - out.write('-cclib "-L%s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir,sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) out.write('\n') # Generate META file and package installation commands From 42f12ed75216d891550b879a987ef5e9036ee47a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 2 Dec 2014 19:39:13 +0000 Subject: [PATCH 224/248] ML API: added interpolation, bugfixes. Signed-off-by: Christoph M. Wintersteiger --- scripts/update_api.py | 10 +- src/api/ml/z3.ml | 121 ++-- src/api/ml/z3.mli | 1386 +++++++++++++++++++++-------------------- 3 files changed, 806 insertions(+), 711 deletions(-) diff --git a/scripts/update_api.py b/scripts/update_api.py index fba194bac..4669b78fc 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -334,6 +334,8 @@ def param2ml(p): return "ptr" elif k == IN_ARRAY or k == INOUT_ARRAY or k == OUT_ARRAY: return "%s array" % type2ml(param_type(p)) + elif k == OUT_MANAGED_ARRAY: + return "%s array" % type2ml(param_type(p)); else: return type2ml(param_type(p)) @@ -1067,7 +1069,7 @@ def ml_method_name(name): return name[3:] # Remove Z3_ def is_out_param(p): - if param_kind(p) == OUT or param_kind(p) == INOUT or param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: + if param_kind(p) == OUT or param_kind(p) == INOUT or param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY or param_kind(p) == OUT_MANAGED_ARRAY: return True else: return False @@ -1411,6 +1413,8 @@ def mk_ml(): type2str(param_type(param)), type2str(param_type(param)), param_array_capacity_pos(param))) + elif k == OUT_MANAGED_ARRAY: + ml_wrapper.write(' %s * _a%s = 0;\n' % (type2str(param_type(param)), i)) elif k == IN_ARRAY or k == INOUT_ARRAY: t = param_type(param) ts = type2str(t) @@ -1449,7 +1453,7 @@ def mk_ml(): else: ml_wrapper.write(', ') k = param_kind(param) - if k == OUT or k == INOUT: + if k == OUT or k == INOUT or k == OUT_MANAGED_ARRAY: ml_wrapper.write('&_a%s' % i) else: ml_wrapper.write('_a%i' % i) @@ -1465,6 +1469,8 @@ def mk_ml(): if param_kind(p) == OUT_ARRAY or param_kind(p) == INOUT_ARRAY: ml_wrapper.write(' _a%s_val = caml_alloc(_a%s, 0);\n' % (i, param_array_capacity_pos(p))) ml_wrapper.write(' for (_i = 0; _i < _a%s; _i++) { value t; %s Store_field(_a%s_val, _i, t); }\n' % (param_array_capacity_pos(p), ml_set_wrap(param_type(p), 't', '_a' + str(i) + '[_i]'), i)) + elif param_kind(p) == OUT_MANAGED_ARRAY: + ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) elif is_out_param(p): ml_wrapper.write(' %s\n' % ml_set_wrap(param_type(p), "_a" + str(i) + "_val", "_a" + str(i) )) i = i + 1 diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 013101398..2b54a1113 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -165,7 +165,7 @@ struct let symbol_lton ( a : symbol list ) = let f ( e : symbol ) = (gno e) in Array.of_list (List.map f a) - + let kind ( o : symbol ) = (symbol_kind_of_int (Z3native.get_symbol_kind (gnc o) (gno o))) let is_int_symbol ( o : symbol ) = (kind o) == INT_SYMBOL let is_string_symbol ( o : symbol ) = (kind o) == STRING_SYMBOL @@ -213,7 +213,7 @@ struct module ASTVector = struct type ast_vector = z3_native_object - + let create ( ctx : context ) ( no : Z3native.ptr ) = let res : ast_vector = { m_ctx = ctx ; m_n_obj = null ; @@ -224,7 +224,7 @@ struct res let mk_ast_vector ( ctx : context ) = (create ctx (Z3native.mk_ast_vector (context_gno ctx))) - + let get_size ( x : ast_vector ) = Z3native.ast_vector_size (z3obj_gnc x) (z3obj_gno x) @@ -259,7 +259,7 @@ struct (z3obj_sno res ctx no) ; (z3obj_create res) ; res - + let mk_ast_map ( ctx : context ) = (create ctx (Z3native.mk_ast_map (context_gno ctx))) let astmap_of_ptr ( ctx : context ) ( no : Z3native.ptr ) = @@ -330,7 +330,7 @@ struct if (get_id a) < (get_id b) then -1 else if (get_id a) > (get_id b) then 1 else 0 - + let translate ( x : ast ) ( to_ctx : context ) = if (z3obj_gnc x) == (context_gno to_ctx) then x @@ -366,7 +366,7 @@ struct | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") let ast_of_sort s = match s with Sort(x) -> x - + let gc ( x : sort ) = (match x with Sort(a) -> (z3obj_gc a)) let gnc ( x : sort ) = (match x with Sort(a) -> (z3obj_gnc a)) let gno ( x : sort ) = (match x with Sort(a) -> (z3obj_gno a)) @@ -378,7 +378,7 @@ struct let sort_option_lton ( a : sort option list ) = let f ( e : sort option ) = match e with None -> null | Some(Sort(a)) -> (AST.ptr_of_ast a) in Array.of_list (List.map f a) - + let equal : sort -> sort -> bool = fun a b -> (a == b) || if (gnc a) != (gnc b) then @@ -629,7 +629,6 @@ sig val to_string : params -> string val update_param_value : context -> string -> string -> unit - val get_param_value : context -> string -> string option val set_print_mode : context -> Z3enums.ast_print_mode -> unit end = struct type params = z3_native_object @@ -688,13 +687,6 @@ end = struct let update_param_value ( ctx : context ) ( id : string) ( value : string )= Z3native.update_param_value (context_gno ctx) id value - let get_param_value ( ctx : context ) ( id : string ) = - let (r, v) = (Z3native.get_param_value (context_gno ctx) id) in - if not r then - None - else - Some v - let set_print_mode ( ctx : context ) ( value : ast_print_mode ) = Z3native.set_ast_print_mode (context_gno ctx) (int_of_ast_print_mode value) end @@ -826,11 +818,11 @@ end = struct let is_well_sorted ( x : expr ) = Z3native.is_well_sorted (gnc x) (gno x) let get_sort ( x : expr ) = sort_of_ptr (Expr.gc x) (Z3native.get_sort (gnc x) (gno x)) - + let is_const ( x : expr ) = (match x with Expr(a) -> (AST.is_app a)) && (get_num_args x) == 0 && (FuncDecl.get_domain_size (get_func_decl x)) == 0 - + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( range : sort ) = expr_of_ptr ctx (Z3native.mk_const (context_gno ctx) (Symbol.gno name) (Sort.gno range)) @@ -851,7 +843,7 @@ end = struct expr_of_ptr ctx (Z3native.mk_int (context_gno ctx) v (Sort.gno ty)) let equal ( a : expr ) ( b : expr ) = AST.equal (ast_of_expr a) (ast_of_expr b) - + let compare a b = AST.compare (ast_of_expr a) (ast_of_expr b) end @@ -941,7 +933,7 @@ struct raise (Z3native.Exception "Invalid coercion") else Quantifier(e) - + let gc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gc e) let gnc ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gnc e) let gno ( x : quantifier ) = match (x) with Quantifier(e) -> (Expr.gno e) @@ -949,13 +941,13 @@ struct module Pattern = struct type pattern = Pattern of ast - + let ast_of_pattern e = match e with Pattern(x) -> x let pattern_of_ast a = - (* CMW: Unchecked ok? *) + (* CMW: Unchecked ok? *) Pattern(a) - + let gc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gc a) let gnc ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gnc a) let gno ( x : pattern ) = match (x) with Pattern(a) -> (z3obj_gno a) @@ -1258,11 +1250,11 @@ struct module Constructor = struct type constructor = z3_native_object - + module FieldNumTable = Hashtbl.Make(struct - type t = AST.ast - let equal x y = AST.compare x y = 0 - let hash = AST.hash + type t = AST.ast + let equal x y = AST.compare x y = 0 + let hash = AST.hash end) let _field_nums = FieldNumTable.create 0 @@ -1291,7 +1283,7 @@ struct Gc.finalise f no ; FieldNumTable.add _field_nums no n ; no - + let get_num_fields ( x : constructor ) = FieldNumTable.find _field_nums x let get_constructor_decl ( x : constructor ) = @@ -1613,16 +1605,16 @@ struct let mk_sub ( ctx : context ) ( t : expr list ) = let f x = (Expr.gno x) in - (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) + (expr_of_ptr ctx (Z3native.mk_sub (context_gno ctx) (List.length t) (Array.of_list (List.map f t)))) let mk_unary_minus ( ctx : context ) ( t : expr ) = - (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (Expr.gno t))) + (expr_of_ptr ctx (Z3native.mk_unary_minus (context_gno ctx) (Expr.gno t))) let mk_div ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + (expr_of_ptr ctx (Z3native.mk_div (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) let mk_power ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = - (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) + (expr_of_ptr ctx (Z3native.mk_power (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) let mk_lt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = (expr_of_ptr ctx (Z3native.mk_lt (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) @@ -1893,7 +1885,7 @@ struct let get_formulas ( x : goal ) = let n = get_size x in let f i = ((expr_of_ptr (z3obj_gc x) - (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in + (Z3native.goal_formula (z3obj_gnc x) (z3obj_gno x) i))) in mk_list f n let get_num_exprs ( x : goal ) = Z3native.goal_num_exprs (z3obj_gnc x) (z3obj_gno x) @@ -2065,7 +2057,7 @@ struct let f i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_func_decl (z3obj_gnc x) (z3obj_gno x) i) in let g i = func_decl_of_ptr (z3obj_gc x) (Z3native.model_get_const_decl (z3obj_gnc x) (z3obj_gno x) i) in (mk_list f n_funcs) @ (mk_list g n_consts) - + let eval ( x : model ) ( t : expr ) ( completion : bool ) = let (r, v) = (Z3native.model_eval (z3obj_gnc x) (z3obj_gno x) (Expr.gno t) completion) in if not r then @@ -2316,7 +2308,7 @@ struct mutable m_is_float : bool ; mutable m_int : int ; mutable m_float : float } - + let create_si k v = let res : statistics_entry = { m_key = k ; @@ -2644,7 +2636,7 @@ struct mk_list f n let get_num_smtlib_sorts ( ctx : context ) = Z3native.get_smtlib_num_sorts (context_gno ctx) - + let get_smtlib_sorts ( ctx : context ) = let n = (get_num_smtlib_sorts ctx) in let f i = (sort_of_ptr ctx (Z3native.get_smtlib_sort (context_gno ctx) i)) in @@ -2683,6 +2675,65 @@ struct (let f x = FuncDecl.gno x in (Array.of_list (List.map f decls))))) end +module Interpolation = +struct + let mk_interpolant ( ctx : context ) ( a : expr ) = + (expr_of_ptr ctx (Z3native.mk_interpolant (context_gno ctx) (Expr.gno a))) + + let mk_interpolation_context ( settings : ( string * string ) list ) = + let cfg = Z3native.mk_config () in + let f e = (Z3native.set_param_value cfg (fst e) (snd e)) in + (List.iter f settings) ; + let v = Z3native.mk_interpolation_context cfg in + Z3native.del_config(cfg) ; + Z3native.set_ast_print_mode v (int_of_ast_print_mode PRINT_SMTLIB2_COMPLIANT) ; + Z3native.set_internal_error_handler v ; + let res = { m_n_ctx = v; m_n_obj_cnt = 0 } in + let f = fun o -> dispose_context o in + Gc.finalise f res; + res + + let get_interpolant ( ctx : context ) ( pf : expr ) ( pat: expr ) ( p : Params.params ) = + (ASTVector.create ctx (Z3native.get_interpolant (context_gno ctx) (Expr.gno pf) (Expr.gno pat) (z3obj_gno p))) + + let compute_interpolant ( ctx : context ) ( pat : expr ) ( p : Params.params ) = + let (r, interp, model) = (Z3native.compute_interpolant (context_gno ctx) (Expr.gno pat) (z3obj_gno p)) in + match (lbool_of_int r) with + | L_TRUE -> ((ASTVector.create ctx interp), (Model.create ctx model)) + | _ -> raise (Z3native.Exception "Error computing interpolant.") + + let get_interpolation_profile ( ctx : context ) = + (Z3native.interpolation_profile (context_gno ctx)) + + let read_interpolation_problem ( ctx : context ) ( filename : string ) = + let (r, num, cnsts, parents, error, num_theory, theory) = (Z3native.read_interpolation_problem (context_gno ctx) filename) in + match r with + | 0 -> raise (Z3native.Exception "Interpolation problem could not be read.") + | _ -> + let f1 i = (expr_of_ptr ctx (Array.get cnsts i)) in + let f2 i = (Array.get parents i) in + let f3 i = (expr_of_ptr ctx (Array.get theory i)) in + ((mk_list f1 num), + (mk_list f2 num), + (mk_list f3 num_theory)) + + let check_interpolant ( ctx : context ) ( num : int ) ( cnsts : Expr.expr list ) ( parents : int list ) ( interps : Expr.expr list ) ( num_theory : int ) ( theory : Expr.expr list ) = + let (r, str) = (Z3native.check_interpolant (context_gno ctx) + num + (let f x = Expr.gno x in (Array.of_list (List.map f cnsts))) + (Array.of_list parents) + (let f x = Expr.gno x in (Array.of_list (List.map f interps))) + num_theory + (let f x = Expr.gno x in (Array.of_list (List.map f theory)))) in + match (lbool_of_int r) with + | L_UNDEF -> raise (Z3native.Exception "Interpolant could not be verified.") + | L_FALSE -> raise (Z3native.Exception "Interpolant could not be verified.") + | _ -> () + + let write_interpolation_problem ( ctx : context ) ( num : int ) ( cnsts : Expr.expr list ) ( parents : int list ) ( filename : string ) ( num_theory : int ) ( theory : Expr.expr list ) = + (Z3native.write_interpolation_problem (context_gno ctx) num (expr_lton cnsts) (Array.of_list parents) filename num_theory (expr_lton theory)) ; + () +end let set_global_param ( id : string ) ( value : string ) = (Z3native.global_param_set id value) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index 1342bb4bc..b2f0939d0 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -149,11 +149,11 @@ sig val resize : ast_vector -> int -> unit (** Add an ast to the back of the vector. The size - is increased by 1. *) + is increased by 1. *) val push : ast_vector -> ast -> unit (** Translates all ASTs in the vector to another context. - @return A new ASTVector *) + @return A new ASTVector *) val translate : ast_vector -> context -> ast_vector (** Retrieves a string representation of the vector. *) @@ -196,7 +196,7 @@ sig end (** The AST's hash code. - @return A hash code *) + @return A hash code *) val hash : ast -> int (** A unique identifier for the AST (unique among all ASTs). *) @@ -227,34 +227,34 @@ sig val to_sexpr : ast -> string (** Comparison operator. - @return True if the two ast's are from the same context - and represent the same sort; false otherwise. *) + @return True if the two ast's are from the same context + and represent the same sort; false otherwise. *) val equal : ast -> ast -> bool (** Object Comparison. - @return Negative if the first ast should be sorted before the second, positive if after else zero. *) + @return Negative if the first ast should be sorted before the second, positive if after else zero. *) val compare : ast -> ast -> int (** Translates (copies) the AST to another context. - @return A copy of the AST which is associated with the other context. *) + @return A copy of the AST which is associated with the other context. *) val translate : ast -> context -> ast (** 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., - [Z3native.inc_ref]). - {!wrap_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., + [Z3native.inc_ref]). + {!wrap_ast} *) val unwrap_ast : ast -> Z3native.ptr (** Wraps an AST. - This function is used for transitions between native and - managed objects. Note that the native ast that is passed must be a - native object obtained from Z3 (e.g., through {!unwrap_ast}) - and that it must have a correct reference count (see e.g., + This function is used for transitions between native and + managed objects. Note that the native ast that is passed must be a + native object obtained from Z3 (e.g., through {!unwrap_ast}) + and that it must have a correct reference count (see e.g., [Z3native.inc_ref]). *) val wrap_ast : context -> Z3native.z3_ast -> ast end @@ -267,8 +267,8 @@ sig val ast_of_sort : sort -> AST.ast (** Comparison operator. - @return True if the two sorts are from the same context - and represent the same sort; false otherwise. *) + @return True if the two sorts are from the same context + and represent the same sort; false otherwise. *) val equal : sort -> sort -> bool (** Returns a unique identifier for the sort. *) @@ -441,33 +441,26 @@ sig val to_string : params -> string (** Update a mutable configuration parameter. - - The list of all configuration parameters can be obtained using the Z3 executable: - [z3.exe -p] - Only a few configuration parameters are mutable once the context is created. - An exception is thrown when trying to modify an immutable parameter. - {!get_param_value} *) + + The list of all configuration parameters can be obtained using the Z3 executable: + [z3.exe -p] + Only a few configuration parameters are mutable once the context is created. + An exception is thrown when trying to modify an immutable parameter. *) val update_param_value : context -> string -> string -> unit - - (** Get a configuration parameter. - - Returns None if the parameter value does not exist. - {!update_param_value} *) - val get_param_value : context -> string -> string option - + (** 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 PRINT_SMTLIB_FULL. - To print shared common subexpressions only once, - use the PRINT_LOW_LEVEL mode. - To print in way that conforms to SMT-LIB standards and uses let - expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. - {!AST.to_string} - {!Quantifier.Pattern.to_string} - {!FuncDecl.to_string} - {!Sort.to_string} *) + + 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 PRINT_SMTLIB_FULL. + To print shared common subexpressions only once, + use the PRINT_LOW_LEVEL mode. + To print in way that conforms to SMT-LIB standards and uses let + expressions to share common sub-expressions use PRINT_SMTLIB_COMPLIANT. + {!AST.to_string} + {!Quantifier.Pattern.to_string} + {!FuncDecl.to_string} + {!Sort.to_string} *) val set_print_mode : context -> Z3enums.ast_print_mode -> unit end @@ -480,7 +473,7 @@ sig val expr_of_ast : AST.ast -> Expr.expr (** Returns a simplified version of the expression. - {!get_simplify_help} *) + {!get_simplify_help} *) val simplify : Expr.expr -> Params.params option -> expr (** A string describing all available parameters to [Expr.Simplify]. *) @@ -503,23 +496,23 @@ sig val update : Expr.expr -> Expr.expr list -> expr (** 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]]. *) + + 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]]. *) val substitute : Expr.expr -> Expr.expr list -> Expr.expr list -> expr (** Substitute every occurrence of [from] in the expression with [to]. - {!substitute} *) + {!substitute} *) val substitute_one : Expr.expr -> Expr.expr -> Expr.expr -> expr (** Substitute the free variables in the expression with the expressions in the expr array - For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term [to[i]]. *) + For every [i] smaller than [num_exprs], the variable with de-Bruijn index [i] is replaced with term [to[i]]. *) val substitute_vars : Expr.expr -> Expr.expr list -> expr (** Translates (copies) the term to another context. - @return A copy of the term which is associated with the other context *) + @return A copy of the term which is associated with the other context *) val translate : Expr.expr -> context -> expr (** Returns a string representation of the expression. *) @@ -529,7 +522,7 @@ sig val is_numeral : Expr.expr -> bool (** Indicates whether the term is well-sorted. - @return True if the term is well-sorted, false otherwise. *) + @return True if the term is well-sorted, false otherwise. *) val is_well_sorted : Expr.expr -> bool (** The Sort of the term. *) @@ -537,26 +530,26 @@ sig (** Indicates whether the term represents a constant. *) val is_const : Expr.expr -> bool - + (** Creates a new constant. *) val mk_const : context -> Symbol.symbol -> Sort.sort -> expr - + (** Creates a new constant. *) val mk_const_s : context -> string -> Sort.sort -> expr - + (** Creates a constant from the func_decl. *) val mk_const_f : context -> FuncDecl.func_decl -> expr - + (** Creates a fresh constant with a name prefixed with a string. *) val mk_fresh_const : context -> string -> Sort.sort -> expr - + (** Create a new function application. *) val mk_app : context -> FuncDecl.func_decl -> Expr.expr list -> expr - + (** Create a numeral of a given sort. - @return A Term with the given value and sort *) + @return A Term with the given value and sort *) val mk_numeral_string : context -> string -> Sort.sort -> expr - + (** Create a numeral 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. @return A Term with the given value and sort *) @@ -692,21 +685,21 @@ sig (** 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 : expr ) appears, the higher is its - index. *) + + 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 : expr ) appears, the higher is its + index. *) val get_index : Expr.expr -> int (** Indicates whether the quantifier is universal. *) @@ -723,19 +716,19 @@ sig (** The patterns. *) val get_patterns : quantifier -> Pattern.pattern list - - (** The number of no-patterns. *) + + (** The number of no-patterns. *) val get_num_no_patterns : quantifier -> int (** The no-patterns. *) val get_no_patterns : quantifier -> Pattern.pattern list - (** The number of bound variables. *) - val get_num_bound : quantifier -> int - - (** The symbols for the bound variables. *) + (** The number of bound variables. *) + val get_num_bound : quantifier -> int + + (** The symbols for the bound variables. *) val get_bound_variable_names : quantifier -> Symbol.symbol list - + (** The sorts of the bound variables. *) val get_bound_variable_sorts : quantifier -> Sort.sort list @@ -767,7 +760,7 @@ sig val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier (** A string representation of the quantifier. *) - val to_string : quantifier -> string + val to_string : quantifier -> string end (** Functions to manipulate Array expressions *) @@ -777,28 +770,28 @@ sig val mk_sort : context -> Sort.sort -> Sort.sort -> Sort.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. *) + It satisfies select(store(a,i,v),j) = if i = j then v else select(a,j). + Array store takes at least 3 arguments. *) val is_store : Expr.expr -> bool (** Indicates whether the term is an array select. *) val is_select : Expr.expr -> bool (** 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. *) + For example, select(const(v),i) = v holds for every v and i. The function is unary. *) val is_constant_array : Expr.expr -> bool (** Indicates whether the term is a default array. - For example default(const(v)) = v. The function is unary. *) + For example default(const(v)) = v. The function is unary. *) val is_default_array : Expr.expr -> bool (** 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. *) + It satisfies map[f](a1,..,a_n)[i] = f(a1[i],...,a_n[i]) for every i. *) val is_array_map : Expr.expr -> bool (** 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. *) + An as-array term is n array value that behaves as the function graph of the + function passed as parameter. *) val is_as_array : Expr.expr -> bool (** Indicates whether the term is of an array sort. *) @@ -806,66 +799,66 @@ sig (** The domain of the array sort. *) val get_domain : Sort.sort -> Sort.sort - + (** The range of the array sort. *) val get_range : Sort.sort -> Sort.sort - + (** Create an array constant. *) val mk_const : context -> Symbol.symbol -> Sort.sort -> Sort.sort -> Expr.expr - + (** Create an array constant. *) val mk_const_s : context -> string -> Sort.sort -> Sort.sort -> Expr.expr - + (** 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]. - {!Z3Array.mk_sort} - {!mk_store} *) + + 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]. + {!Z3Array.mk_sort} + {!mk_store} *) val mk_select : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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). - {!Z3Array.mk_sort} - {!mk_select} *) + + 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). + {!Z3Array.mk_sort} + {!mk_select} *) val mk_store : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr (** Create a constant array. - - The resulting term is an array, such that a [select]on an arbitrary index - produces the value [v]. - {!Z3Array.mk_sort} - {!mk_select} *) + + The resulting term is an array, such that a [select]on an arbitrary index + produces the value [v]. + {!Z3Array.mk_sort} + {!mk_select} *) val mk_const_array : context -> Sort.sort -> Expr.expr -> Expr.expr (** 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]]. - {!Z3Array.mk_sort} - {!mk_select} - {!mk_store} *) + + 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]]. + {!Z3Array.mk_sort} + {!mk_select} + {!mk_store} *) val mk_map : context -> FuncDecl.func_decl -> Expr.expr list -> Expr.expr (** Access the array default value. - - Produces the default range value, for arrays that can be represented as - finite maps with a default range value. *) + + Produces the default range value, for arrays that can be represented as + finite maps with a default range value. *) val mk_term_array : context -> Expr.expr -> Expr.expr end @@ -948,10 +941,10 @@ sig val is_relation : Expr.expr -> bool (** 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. *) + + 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. *) val is_store : Expr.expr -> bool (** Indicates whether the term is an empty relation *) @@ -964,62 +957,62 @@ sig val is_join : Expr.expr -> bool (** Indicates whether the term is the union or convex hull of two relations. - The function takes two arguments. *) + The function takes two arguments. *) val is_union : Expr.expr -> bool (** Indicates whether the term is the widening of two relations - The function takes two arguments. *) + The function takes two arguments. *) val is_widen : Expr.expr -> bool (** Indicates whether the term is a projection of columns (provided as numbers in the parameters). - The function takes one argument. *) + The function takes one argument. *) val is_project : Expr.expr -> bool (** 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. *) + + 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. *) val is_filter : Expr.expr -> bool (** 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 : expr ) in pos, such that there is no y in neg that agrees with - ( x : expr ) on the columns c1, d1, .., cN, dN. *) + + 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 : expr ) in pos, such that there is no y in neg that agrees with + ( x : expr ) on the columns c1, d1, .., cN, dN. *) val is_negation_filter : Expr.expr -> bool (** 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. *) + + The function takes one argument. + The parameters contain the renaming as a cycle. *) val is_rename : Expr.expr -> bool (** Indicates whether the term is the complement of a relation *) val is_complement : Expr.expr -> bool (** 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. *) + + 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. *) val is_select : Expr.expr -> bool (** 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 {!is_union} - to perform destructive updates to the first argument. *) + + 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 {!is_union} + to perform destructive updates to the first argument. *) val is_clone : Expr.expr -> bool (** The arity of the relation sort. *) @@ -1039,25 +1032,25 @@ sig (** The number of fields of the constructor. *) val get_num_fields : constructor -> int - + (** The function declaration of the constructor. *) val get_constructor_decl : constructor -> FuncDecl.func_decl (** The function declaration of the tester. *) val get_tester_decl : constructor -> FuncDecl.func_decl - + (** The function declarations of the accessors *) val get_accessor_decls : constructor -> FuncDecl.func_decl list end (** Create a datatype 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. *) + 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. *) val mk_constructor : context -> Symbol.symbol -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor (** Create a datatype 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. *) + 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. *) val mk_constructor_s : context -> string -> Symbol.symbol -> Symbol.symbol list -> Sort.sort option list -> int list -> Constructor.constructor (** Create a new datatype sort. *) @@ -1078,7 +1071,7 @@ sig (** The constructors. *) val get_constructors : Sort.sort -> FuncDecl.func_decl list - + (** The recognizers. *) val get_recognizers : Sort.sort -> FuncDecl.func_decl list @@ -1174,38 +1167,38 @@ sig val mk_const_s : context -> string -> Expr.expr (** Create an expression representing [t1 mod t2]. - The arguments must have int type. *) + The arguments must have int type. *) val mk_mod : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing [t1 rem t2]. - The arguments must have int type. *) + The arguments must have int type. *) val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an integer numeral. *) val mk_numeral_s : context -> string -> Expr.expr (** Create an integer numeral. - @return A Term with the given value and sort Integer *) + @return A Term with the given value and sort Integer *) val mk_numeral_i : context -> int -> Expr.expr (** 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. *) + + + 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. *) val mk_int2real : context -> Expr.expr -> Expr.expr (** Create an n-bit bit-vector from an 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. *) + + + 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. *) val mk_int2bv : context -> int -> Expr.expr -> Expr.expr end @@ -1238,16 +1231,16 @@ sig val mk_const_s : context -> string -> Expr.expr (** Create a real numeral from a fraction. - @return A Term with rational value and sort Real - {!mk_numeral_s} *) + @return A Term with rational value and sort Real + {!mk_numeral_s} *) val mk_numeral_nd : context -> int -> int -> Expr.expr (** Create a real numeral. - @return A Term with the given value and sort Real *) + @return A Term with the given value and sort Real *) val mk_numeral_s : context -> string -> Expr.expr (** Create a real numeral. - @return A Term with the given value and sort Real *) + @return A Term with the given value and sort Real *) val mk_numeral_i : context -> int -> Expr.expr (** Creates an expression that checks whether a real number is an integer. *) @@ -1255,8 +1248,8 @@ sig (** 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. *) + The semantics of this function follows the SMT-LIB standard for the function to_int. + The argument must be of real sort. *) val mk_real2int : context -> Expr.expr -> Expr.expr (** Algebraic Numbers *) @@ -1522,34 +1515,34 @@ sig val is_bv_rotateright : Expr.expr -> bool (** 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. *) + Similar to Z3_OP_ROTATE_LEFT, but it is a binary operator instead of a parametric one. *) val is_bv_rotateleftextended : Expr.expr -> bool (** 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. *) + Similar to Z3_OP_ROTATE_RIGHT, but it is a binary operator instead of a parametric one. *) val is_bv_rotaterightextended : Expr.expr -> bool - + (** 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. *) + This function is not supported by the decision procedures. Only the most + rudimentary simplification rules are applied to this function. *) (** 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. *) + This function is not supported by the decision procedures. Only the most + rudimentary simplification rules are applied to this function. *) val is_int_to_bv : Expr.expr -> bool (** 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. *) + This function is not supported by the decision procedures. Only the most + rudimentary simplification rules are applied to this function. *) val is_bv_to_int : Expr.expr -> bool (** 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))) *) + 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))) *) val is_bv_carry : Expr.expr -> bool - + (** 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) *) + The meaning is given by the equivalence (xor3 l1 l2 l3) <=> (xor (xor l1 l2) l3) *) val is_bv_xor3 : Expr.expr -> bool (** The size of a bit-vector sort. *) @@ -1557,7 +1550,7 @@ sig (** Retrieve the int value. *) val get_int : Expr.expr -> int - + (** Returns a string representation of the numeral. *) val to_string : Expr.expr -> string @@ -1568,146 +1561,145 @@ sig val mk_const_s : context -> string -> int -> Expr.expr (** Bitwise negation. - The argument must have a bit-vector sort. *) + The argument must have a bit-vector sort. *) val mk_not : context -> Expr.expr -> Expr.expr (** Take conjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) + The argument must have a bit-vector sort. *) val mk_redand : context -> Expr.expr -> Expr.expr (** Take disjunction of bits in a vector,vector of length 1. - The argument must have a bit-vector sort. *) + The argument must have a bit-vector sort. *) val mk_redor : context -> Expr.expr -> Expr.expr (** Bitwise conjunction. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_and : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise disjunction. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_or : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise XOR. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_xor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise NAND. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_nand : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise NOR. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_nor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bitwise XNOR. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_xnor : context -> Expr.expr -> Expr.expr -> Expr.expr (** Standard two's complement unary minus. - The arguments must have a bit-vector sort. *) + The arguments must have a bit-vector sort. *) val mk_neg : context -> Expr.expr -> Expr.expr (** Two's complement addition. - The arguments must have the same bit-vector sort. *) + The arguments must have the same bit-vector sort. *) val mk_add : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement subtraction. - The arguments must have the same bit-vector sort. *) + The arguments must have the same bit-vector sort. *) val mk_sub : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement multiplication. - The arguments must have the same bit-vector sort. *) + The arguments must have the same bit-vector sort. *) val mk_mul : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. *) + + 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. *) val mk_udiv : context -> Expr.expr -> Expr.expr -> Expr.expr (** Signed division. - - It is defined in the following way: + + 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 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]. + - 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. *) + If [t2] is zero, then the result is undefined. + The arguments must have the same bit-vector sort. *) val mk_sdiv : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. *) + + 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. *) val mk_urem : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. + + 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. *) + If [t2] is zero, then the result is undefined. + The arguments must have the same bit-vector sort. *) val mk_srem : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. *) + + If [t2] is zero, then the result is undefined. + The arguments must have the same bit-vector sort. *) val mk_smod : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned less-than - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_ult : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed less-than - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_slt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned less-than or equal to. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_ule : context -> Expr.expr -> Expr.expr -> Expr.expr - + (** Two's complement signed less-than or equal to. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_sle : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned greater than or equal to. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_uge : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed greater than or equal to. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_sge : context -> Expr.expr -> Expr.expr -> Expr.expr (** Unsigned greater-than. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_ugt : context -> Expr.expr -> Expr.expr -> Expr.expr (** Two's complement signed greater-than. - - The arguments must have the same bit-vector sort. *) + + The arguments must have the same bit-vector sort. *) val mk_sgt : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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]). *) + + 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]). *) val mk_concat : context -> Expr.expr -> Expr.expr -> Expr.expr (** Bit-vector extraction. @@ -1719,17 +1711,17 @@ sig (** 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. *) + 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. *) val mk_sign_ext : context -> int -> Expr.expr -> Expr.expr (** 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. *) + 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. *) val mk_zero_ext : context -> int -> Expr.expr -> Expr.expr - + (** Bit-vector repetition. *) val mk_repeat : context -> int -> Expr.expr -> Expr.expr @@ -1743,27 +1735,27 @@ sig val mk_shl : context -> Expr.expr -> Expr.expr -> Expr.expr (** Logical shift right - - It is equivalent to unsigned division by [2^x] where \c x is the value of the third argument. + + It is equivalent to unsigned division by [2^x] where \c x is the value of the third 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. + 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. *) + The arguments must have a bit-vector sort. *) val mk_lshr : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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. + + 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. + 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. *) + The arguments must have a bit-vector sort. *) val mk_ashr : context -> Expr.expr -> Expr.expr -> Expr.expr (** Rotate Left. @@ -1783,7 +1775,7 @@ sig val mk_ext_rotate_right : context -> Expr.expr -> Expr.expr -> Expr.expr (** 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 the argument. @@ -1795,45 +1787,45 @@ sig val mk_bv2int : context -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise addition does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_add_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise addition does not underflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_add_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise subtraction does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_sub_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise subtraction does not underflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_sub_no_underflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise signed division does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_sdiv_no_overflow : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise negation does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_neg_no_overflow : context -> Expr.expr -> Expr.expr (** Create a predicate that checks that the bit-wise multiplication does not overflow. - - The arguments must be of bit-vector sort. *) + + The arguments must be of bit-vector sort. *) val mk_mul_no_overflow : context -> Expr.expr -> Expr.expr -> bool -> Expr.expr (** Create a predicate that checks that the bit-wise multiplication does not underflow. - - The arguments must be of bit-vector sort. *) - val mk_mul_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr + The arguments must be of bit-vector sort. *) + val mk_mul_no_underflow : context -> Expr.expr -> Expr.expr -> Expr.expr + (** Create a bit-vector numeral. *) val mk_numeral : context -> string -> int -> Expr.expr end @@ -1851,389 +1843,389 @@ sig val is_goal : Expr.expr -> bool (** 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. *) + This binary predicate is used in proof terms. + It captures equisatisfiability and equivalence modulo renamings. *) val is_oeq : Expr.expr -> bool (** 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). *) + + 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). *) val is_modus_ponens : Expr.expr -> bool (** 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'. *) + 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'. *) val is_reflexivity : Expr.expr -> bool (** 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. *) + + 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. *) val is_symmetry : Expr.expr -> bool (** 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) *) + + 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) *) val is_transitivity : Expr.expr -> bool (** 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. *) + + 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. *) val is_Transitivity_star : Expr.expr -> bool (** 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. *) + + 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. *) val is_monotonicity : Expr.expr -> bool (** 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)) *) + + 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)) *) val is_quant_intro : Expr.expr -> bool (** 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. *) + + 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. *) val is_distributivity : Expr.expr -> bool (** 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 *) + + 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 *) val is_and_elimination : Expr.expr -> bool (** 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) *) + + 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) *) val is_or_elimination : Expr.expr -> bool (** 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 : expr ) 0) x) - (= (+ ( x : expr ) 1 2) (+ 3 x)) - (iff (or ( x : expr ) false) x) *) + + 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 : expr ) 0) x) + (= (+ ( x : expr ) 1 2) (+ 3 x)) + (iff (or ( x : expr ) false) x) *) val is_rewrite : Expr.expr -> bool (** 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) *) + + 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) *) val is_rewrite_star : Expr.expr -> bool (** 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. *) + + A proof for (iff (f (forall (x) q(x)) r) (forall (x) (f (q x) r))). This proof object has no antecedents. *) val is_pull_quant : Expr.expr -> bool (** 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 *) + + 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 *) val is_pull_quant_star : Expr.expr -> bool (** 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 *) + + 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 *) val is_push_quant : Expr.expr -> bool (** 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. *) + + 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. *) val is_elim_unused_vars : Expr.expr -> bool (** Indicates whether the term is a proof for destructive equality resolution - - A proof for destructive equality resolution: - (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) - if ( x : expr ) does not occur in t. - - This proof object has no antecedents. - - Several variables can be eliminated simultaneously. *) + + A proof for destructive equality resolution: + (iff (forall (x) (or (not (= ( x : expr ) t)) P[x])) P[t]) + if ( x : expr ) does not occur in t. + + This proof object has no antecedents. + + Several variables can be eliminated simultaneously. *) val is_der : Expr.expr -> bool - + (** Indicates whether the term is a proof for quantifier instantiation - - A proof of (or (not (forall (x) (P x))) (P a)) *) + + A proof of (or (not (forall (x) (P x))) (P a)) *) val is_quant_inst : Expr.expr -> bool (** Indicates whether the term is a hypthesis marker. - Mark a hypothesis in a natural deduction style proof. *) + Mark a hypothesis in a natural deduction style proof. *) val is_hypothesis : Expr.expr -> bool (** 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. *) + + 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. *) val is_lemma : Expr.expr -> bool (** 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') *) + + 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') *) val is_unit_resolution : Expr.expr -> bool (** Indicates whether the term is a proof by iff-true - - T1: p - [iff-true T1]: (iff p true) *) + + T1: p + [iff-true T1]: (iff p true) *) val is_iff_true : Expr.expr -> bool (** Indicates whether the term is a proof by iff-false - - T1: (not p) - [iff-false T1]: (iff p false) *) + + T1: (not p) + [iff-false T1]: (iff p false) *) val is_iff_false : Expr.expr -> bool (** 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. *) + + [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. *) val is_commutativity : Expr.expr -> bool (** 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). *) + + 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). *) val is_def_axiom : Expr.expr -> bool (** 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) *) + + 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) *) val is_def_intro : Expr.expr -> bool (** 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. *) + + [apply-def T1]: F ~ n + F is 'equivalent' to n, given that T1 is a proof that + n is a name for F. *) val is_apply_def : Expr.expr -> bool (** Indicates whether the term is a proof iff-oeq - - T1: (iff p q) - [iff~ T1]: (~ p q) *) + + T1: (iff p q) + [iff~ T1]: (~ p q) *) val is_iff_oeq : Expr.expr -> bool (** 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'. *) + + 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'. *) val is_nnf_pos : Expr.expr -> bool (** 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'))) *) + + 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'))) *) val is_nnf_neg : Expr.expr -> bool (** 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. *) + + 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. *) val is_nnf_star : Expr.expr -> bool (** 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. *) + + 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. *) val is_cnf_star : Expr.expr -> bool (** Indicates whether the term is a proof for a Skolemization step - - Proof for: - - [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) - [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) - - This proof object has no antecedents. *) + + Proof for: + + [sk]: (~ (not (forall ( x : expr ) (p ( x : expr ) y))) (not (p (sk y) y))) + [sk]: (~ (exists ( x : expr ) (p ( x : expr ) y)) (p (sk y) y)) + + This proof object has no antecedents. *) val is_skolemize : Expr.expr -> bool (** 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 *) + + Modus ponens style rule for equi-satisfiability. + T1: p + T2: (~ p q) + [mp~ T1 T2]: q *) val is_modus_ponens_oeq : Expr.expr -> bool (** 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. *) + + 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. *) val is_theory_lemma : Expr.expr -> bool end @@ -2265,12 +2257,12 @@ sig (** Indicates whether the goal is garbage (i.e., the product of over- and under-approximations). *) val is_garbage : goal -> bool - (** Adds the constraints to the given goal. *) + (** Adds the constraints to the given goal. *) val add : goal -> Expr.expr list -> unit - + (** Indicates whether the goal contains `false'. *) val is_inconsistent : goal -> bool - + (** The depth of the goal. This tracks how many transformations were applied to it. *) val get_depth : goal -> int @@ -2300,7 +2292,7 @@ sig val simplify : goal -> Params.params option -> goal (** Creates a new Goal. - + Note that the Context must have been created with proof generation support if the fourth argument is set to true here. *) val mk_goal : context -> bool -> bool -> bool -> goal @@ -2323,7 +2315,7 @@ sig module FuncInterp : sig type func_interp - + (** Function interpretations entries An Entry object represents an element in the finite map used to a function interpretation. *) @@ -2418,7 +2410,7 @@ sig {!get_sorts} @return A list of expressions, where each is an element of the universe of the sort *) val sort_universe : model -> Sort.sort -> AST.ast list - + (** Conversion of models to strings. @return A string representation of the model. *) val to_string : model -> string @@ -2437,8 +2429,8 @@ sig type probe (** Execute the probe over the goal. - @return A probe always produce a float value. - "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) + @return A probe always produce a float value. + "Boolean" probes return 0.0 for false, and a value different from 0.0 for true. *) val apply : probe -> Goal.goal -> float (** The number of supported Probes. *) @@ -2546,21 +2538,21 @@ sig val mk_tactic : context -> string -> tactic (** Create a tactic that applies one tactic to a Goal and - then another one to every subgoal produced by the first one. *) + then another one to every subgoal produced by the first one. *) val and_then : context -> tactic -> tactic -> tactic list -> tactic (** Create a tactic that first applies one tactic to a Goal and - if it fails then returns the result of another tactic applied to the Goal. *) + if it fails then returns the result of another tactic applied to the Goal. *) val or_else : context -> tactic -> tactic -> tactic (** Create a tactic that applies one tactic to a goal for some time (in milliseconds). - - If the tactic does not terminate within the timeout, then it fails. *) + + If the tactic does not terminate within the timeout, then it fails. *) val try_for : context -> tactic -> int -> tactic (** Create a tactic that applies one tactic to a given goal if the probe evaluates to true. - + If the probe evaluates to false, then the new tactic behaves like the [skip] tactic. *) val when_ : context -> Probe.probe -> tactic -> tactic @@ -2569,7 +2561,7 @@ sig val cond : context -> Probe.probe -> tactic -> tactic -> tactic (** Create a tactic that keeps applying one tactic until the goal is not - modified anymore or the maximum number of iterations is reached. *) + modified anymore or the maximum number of iterations is reached. *) val repeat : context -> tactic -> int -> tactic (** Create a tactic that just returns the given goal. *) @@ -2582,14 +2574,14 @@ sig val fail_if : context -> Probe.probe -> tactic (** Create a tactic that fails if the goal is not triviall satisfiable (i.e., empty) - or trivially unsatisfiable (i.e., contains `false'). *) + or trivially unsatisfiable (i.e., contains `false'). *) val fail_if_not_decided : context -> tactic (** Create a tactic that applies a tactic using the given set of parameters. *) val using_params : context -> tactic -> Params.params -> tactic (** Create a tactic that applies a tactic using the given set of parameters. - Alias for [UsingParams]*) + Alias for [UsingParams]*) val with_ : context -> tactic -> Params.params -> tactic (** Create a tactic that applies the given tactics in parallel. *) @@ -2600,7 +2592,7 @@ sig val par_and_then : context -> tactic -> tactic -> tactic (** Interrupt the execution of a Z3 procedure. - This procedure can be used to interrupt: solvers, simplifiers and tactics. *) + This procedure can be used to interrupt: solvers, simplifiers and tactics. *) val interrupt : context -> unit end @@ -2618,8 +2610,8 @@ sig type statistics (** Statistical data is organized into pairs of \[Key, Entry\], where every - Entry is either a floating point or integer value. - *) + Entry is either a floating point or integer value. + *) module Entry : sig type statistics_entry @@ -2641,7 +2633,7 @@ sig (** The string representation of the the entry's value. *) val to_string_value : statistics_entry -> string - + (** The string representation of the entry (key and value) *) val to_string : statistics_entry -> string end @@ -2672,49 +2664,49 @@ sig val get_param_descrs : solver -> Params.ParamDescrs.param_descrs (** The current number of backtracking points (scopes). - {!pop} - {!push} *) + {!pop} + {!push} *) val get_num_scopes : solver -> int (** Creates a backtracking point. - {!pop} *) + {!pop} *) val push : solver -> unit (** Backtracks a number of backtracking points. - Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} - {!push} *) + Note that an exception is thrown if the integer is not smaller than {!get_num_scopes} + {!push} *) val pop : solver -> int -> unit (** Resets the Solver. - This removes all assertions from the solver. *) + This removes all assertions from the solver. *) val reset : solver -> unit (** Assert a constraint (or multiple) into the solver. *) val add : solver -> Expr.expr list -> unit (** * Assert multiple constraints (cs) into the solver, and track them (in the - * unsat) core - * using the Boolean constants in ps. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) + * unsat) core + * using the Boolean constants in ps. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) val assert_and_track_l : solver -> Expr.expr list -> Expr.expr list -> unit (** * Assert a constraint (c) into the solver, and track it (in the unsat) core - * using the Boolean constant p. - * - * This API is an alternative to {!check} with assumptions for - * extracting unsat cores. - * Both APIs can be used in the same solver. The unsat core will contain a - * combination - * of the Boolean variables provided using {!assert_and_track} - * and the Boolean literals - * provided using {!check} with assumptions. *) + * using the Boolean constant p. + * + * This API is an alternative to {!check} with assumptions for + * extracting unsat cores. + * Both APIs can be used in the same solver. The unsat core will contain a + * combination + * of the Boolean variables provided using {!assert_and_track} + * and the Boolean literals + * provided using {!check} with assumptions. *) val assert_and_track : solver -> Expr.expr -> Expr.expr -> unit (** The number of assertions in the solver. *) @@ -2724,29 +2716,29 @@ sig val get_assertions : solver -> Expr.expr list (** Checks whether the assertions in the solver are consistent or not. - - {!Model} - {!get_unsat_core} - {!Proof} *) + + {!Model} + {!get_unsat_core} + {!Proof} *) val check : solver -> Expr.expr list -> status (** The model of the last [Check]. - - The result is [None] if [Check] was not invoked before, - if its results was not [SATISFIABLE], or if model production is not enabled. *) + + The result is [None] if [Check] was not invoked before, + if its results was not [SATISFIABLE], or if model production is not enabled. *) val get_model : solver -> Model.model option (** 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. *) + + The result is [null] if [Check] was not invoked before, + if its results was not [UNSATISFIABLE], or if proof production is disabled. *) val get_proof : solver -> Expr.expr option (** 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. *) + + 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. *) val get_unsat_core : solver -> AST.ast list (** A brief justification of why the last call to [Check] returned [UNKNOWN]. *) @@ -2756,23 +2748,23 @@ sig val get_statistics : solver -> Statistics.statistics (** 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. *) + + 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. *) val mk_solver : context -> Symbol.symbol option -> solver (** Creates a new (incremental) solver. - {!mk_solver} *) + {!mk_solver} *) val mk_solver_s : context -> string -> solver (** Creates a new (incremental) solver. *) val mk_simple_solver : context -> solver (** 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. *) + + The solver supports the commands [Push] and [Pop], but it + will always solve each check from scratch. *) val mk_solver_t : context -> Tactic.tactic -> solver (** A string representation of the solver. *) @@ -2806,32 +2798,32 @@ sig val add_fact : fixedpoint -> FuncDecl.func_decl -> int list -> unit (** 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. *) + 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. *) val query : fixedpoint -> Expr.expr -> Solver.status (** 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. *) + 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. *) val query_r : fixedpoint -> FuncDecl.func_decl list -> Solver.status (** Creates a backtracking point. - {!pop} *) + {!pop} *) val push : fixedpoint -> unit (** Backtrack one backtracking point. - Note that an exception is thrown if Pop is called without a corresponding [Push] - {!push} *) + Note that an exception is thrown if Pop is called without a corresponding [Push] + {!push} *) val pop : fixedpoint -> unit (** Update named rule into in the fixedpoint solver. *) val update_rule : fixedpoint -> Expr.expr -> Symbol.symbol -> unit (** Retrieve satisfying instance or instances of solver, - or definitions for the recursive predicates that show unsatisfiability. *) + or definitions for the recursive predicates that show unsatisfiability. *) val get_answer : fixedpoint -> Expr.expr option (** Retrieve explanation why fixedpoint engine returned status Unknown. *) @@ -2844,7 +2836,7 @@ sig val get_cover_delta : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr option (** Add property about the predicate. - The property is added at level. *) + The property is added at level. *) val add_cover : fixedpoint -> int -> FuncDecl.func_decl -> Expr.expr -> unit (** Retrieve internal string representation of fixedpoint object. *) @@ -2871,7 +2863,7 @@ module SMT : sig (** Convert a benchmark into an SMT-LIB formatted string. - @return A string representation of the benchmark. *) + @return A string representation of the benchmark. *) val benchmark_to_smtstring : context -> string -> string -> string -> string -> Expr.expr list -> Expr.expr -> string (** Parse the given string using the SMT-LIB parser. @@ -2884,7 +2876,7 @@ sig val parse_smtlib_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit (** Parse the given file using the SMT-LIB parser. - {!parse_smtlib_string} *) + {!parse_smtlib_string} *) val parse_smtlib_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> unit (** The number of SMTLIB formulas parsed by the last call to [ParseSMTLIBString] or [ParseSMTLIBFile]. *) @@ -2913,15 +2905,61 @@ sig (** Parse the given string using the SMT-LIB2 parser. - {!parse_smtlib_string} - @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) + {!parse_smtlib_string} + @return A conjunction of assertions in the scope (up to push/pop) at the end of the string. *) val parse_smtlib2_string : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr (** Parse the given file using the SMT-LIB2 parser. - {!parse_smtlib2_string} *) + {!parse_smtlib2_string} *) val parse_smtlib2_file : context -> string -> Symbol.symbol list -> Sort.sort list -> Symbol.symbol list -> FuncDecl.func_decl list -> Expr.expr end +(** Interpolation *) +module Interpolation : +sig + + (** Create an AST node marking a formula position for interpolation. + The expression must have Boolean sort. *) + val mk_interpolant : context -> Expr.expr -> Expr.expr + + (** The interpolation context is suitable for generation of interpolants. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val mk_interpolation_context : (string * string) list -> context + + (** Gets an interpolant. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val get_interpolant : context -> Expr.expr -> Expr.expr -> Params.params -> AST.ASTVector.ast_vector + + (** Computes an interpolant. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val compute_interpolant : context -> Expr.expr -> Params.params -> (AST.ASTVector.ast_vector * Model.model) + + (** Retrieves an interpolation profile. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val get_interpolation_profile : context -> string + + (** Read an interpolation problem from file. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val read_interpolation_problem : context -> string -> (Expr.expr list * int list * Expr.expr list) + + (** Check the correctness of an interpolant. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val check_interpolant : context -> int -> Expr.expr list -> int list -> Expr.expr list -> int -> Expr.expr list -> unit + + (** Write an interpolation problem to file suitable for reading with + Z3_read_interpolation_problem. + For more information on interpolation please refer + too the C/C++ API, which is well documented. *) + val write_interpolation_problem : context -> int -> Expr.expr list -> int list -> string -> int -> Expr.expr list -> unit + +end + (** Set a global (or module) parameter, which is shared by all Z3 contexts. When a Z3 module is initialized it will use the value of these parameters @@ -2939,9 +2977,9 @@ end val set_global_param : string -> string -> unit (** Get a global (or module) parameter. - + Returns None if the parameter does not exist. - The caller must invoke #Z3_global_param_del_value to delete the value returned at \c param_value. + The caller must invoke #Z3_global_param_del_value to delete the value returned at param_value. This function cannot be invoked simultaneously from different threads without synchronization. The result string stored in param_value is stored in a shared location. *) From 5092ceec7d04476e668d26690a54a38c8f246111 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 2 Dec 2014 20:21:30 +0000 Subject: [PATCH 225/248] ML API: build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index bf1f5e471..ad60fa1e1 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1379,6 +1379,10 @@ class MLComponent(Component): out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) + for f in filter(lambda f: f=='META', os.listdir(self.src_dir)): + out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) + str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) + out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! prev = '' for m in modules: @@ -1421,7 +1425,7 @@ class MLComponent(Component): # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs\n') + out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/META\n') out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) for m in modules: From b85c3e12f4fbf2b3f16531972577b07acaae1d51 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 2 Dec 2014 20:31:16 +0000 Subject: [PATCH 226/248] ML API build fix --- scripts/mk_util.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index ad60fa1e1..d42e6af29 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1379,10 +1379,6 @@ class MLComponent(Component): out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) - for f in filter(lambda f: f=='META', os.listdir(self.src_dir)): - out.write('%s: %s\n' % (os.path.join(sub_dir,f),os.path.join(src_dir,f))) - str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) - out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! prev = '' for m in modules: From 93d74129508b159aeeeb687fb9780257df44ced4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Tue, 2 Dec 2014 22:00:58 +0000 Subject: [PATCH 227/248] ML API build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index d42e6af29..b1b3445ec 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1392,9 +1392,14 @@ class MLComponent(Component): out.write('%s.cmi: %s.mli\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m))) out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('api/ml/z3native_stubs$(OBJ_EXT): %s/z3native_stubs.c\n' % (sub_dir)); out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) + out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') + out.write('api/ml/libz3mldyn$(SO_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) + out.write('\t$(SLINK) $(SLINK_OUT_FLAG)api/ml/libz3ml$(SO_EXT) $(SLINK_FLAGS) -I %s -I %s api/ml/z3native_stubs$(OBJ_EXT) %s$(LIB_EXT)\n' % (OCAML_LIB, api_src, get_component(Z3_DLL_COMPONENT).dll_name)) + out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) for mlfile in get_ml_files(self.src_dir): out.write(' %s' % os.path.join(sub_dir, mlfile)) From 40c6be0baa6010a628408d5959ee385d4fa11d66 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 13:45:49 +0000 Subject: [PATCH 228/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 98 ++++++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 38 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index b1b3445ec..5e412c892 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1384,58 +1384,80 @@ class MLComponent(Component): for m in modules: fn = os.path.join(self.src_dir, ('%s.mli' % m)) if not os.path.exists(fn): - out.write('%s.mli: %s.ml %s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),prev)) + out.write('%s.mli: %s.ml%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),prev)) out.write('\t%s -I %s -i -c %s.ml > %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir, m),os.path.join(sub_dir, m))) prev = prev + ' ' + os.path.join(sub_dir, m) + '.mli' cmis = '' for m in modules: - out.write('%s.cmi: %s.mli\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m))) + out.write('%s.cmi: %s.mli%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m), cmis)) out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - out.write('api/ml/z3native_stubs$(OBJ_EXT): %s/z3native_stubs.c\n' % (sub_dir)); - out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) - out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') - out.write('api/ml/libz3mldyn$(SO_EXT): api/ml/z3native_stubs.c %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s/z3native_stubs.c $(CXX_OUT_FLAG)api/ml/z3native_stubs$(OBJ_EXT)\n' % (OCAML_LIB, api_src, sub_dir)) - out.write('\t$(SLINK) $(SLINK_OUT_FLAG)api/ml/libz3ml$(SO_EXT) $(SLINK_FLAGS) -I %s -I %s api/ml/z3native_stubs$(OBJ_EXT) %s$(LIB_EXT)\n' % (OCAML_LIB, api_src, get_component(Z3_DLL_COMPONENT).dll_name)) + + out.write('%s: %s %s\n' % + (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'), + os.path.join(sub_dir, 'z3native_stubs.c'), + get_component(Z3_DLL_COMPONENT).dll_name+'$(SO_EXT)')); + out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s $(CXX_OUT_FLAG)%s$(OBJ_EXT)\n' % + (OCAML_LIB, api_src, os.path.join(sub_dir, 'z3native_stubs.c'), os.path.join(sub_dir, 'z3native_stubs'))) - out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(sub_dir, mlfile)) - out.write('\n') - out.write('\t%s ' % (OCAMLOPT)) - if DEBUG_MODE: - out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) - out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - out.write('\t%s ' % (OCAMLOPT)) - if DEBUG_MODE: - out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(sub_dir, mlfile)) - out.write('\n') - out.write('\t%s ' % (OCAMLC)) - if DEBUG_MODE: - out.write('-g ') - out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) - out.write('ml: %s %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) - out.write('\n') + # out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + # out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') + + # out.write('api/ml/libz3ml$(SO_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) + # out.write('\t$(SLINK) $(SLINK_OUT_FLAG)api/ml/libz3ml$(SO_EXT) $(SLINK_FLAGS) -I %s -I %s api/ml/z3native_stubs$(OBJ_EXT) %s$(LIB_EXT)\n' % (OCAML_LIB, api_src, get_component(Z3_DLL_COMPONENT).dll_name)) + + + # out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + + # for mlfile in get_ml_files(self.src_dir): + # out.write(' %s' % os.path.join(sub_dir, mlfile)) + # out.write('\n') + # out.write('\t%s ' % (OCAMLOPT)) + # if DEBUG_MODE: + # out.write('-g ') + # out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + + # out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + # out.write('\t%s ' % (OCAMLOPT)) + # if DEBUG_MODE: + # out.write('-g ') + # out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) + # out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + # for mlfile in get_ml_files(self.src_dir): + # out.write(' %s' % os.path.join(sub_dir, mlfile)) + # out.write('\n') + # out.write('\t%s ' % (OCAMLC)) + # if DEBUG_MODE: + # out.write('-g ') + # out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + + out.write('%s:' % (os.path.join(sub_dir, "z3.cmxa"))) + for m in modules: + out.write(' %s.cmi' % (os.path.join(sub_dir, m))) + out.write(' %s.cmx' % (os.path.join(sub_dir, m))) + out.write(' %s.cmo' % (os.path.join(sub_dir, m))) + out.write('%s/z3native_stubs.o\n' % (sub_dir)) + out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) + for m in modules: + out.write(' ' + m) + out.write('z3native_stubs$(OBJ_EXT) ; cd -' ) + out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) + #out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('ocamlfind_install: api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/META\n') + out.write('\nocamlfind_install: api/ml/z3.cmxa api/ml/META\n') out.write('\t%s remove Z3\n' % (OCAMLFIND)) - out.write('\t%s install Z3 api/ml/META api/ml/z3.cma api/ml/z3.cmxa api/ml/z3.cmxs api/ml/z3$(LIB_EXT) api/ml/libz3ml$(LIB_EXT) libz3$(SO_EXT)' % (OCAMLFIND)) + out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) for m in modules: + out.write(' %s.cma' % (os.path.join(sub_dir, m))) + out.write(' %s.cmxa' % (os.path.join(sub_dir, m))) + out.write(' %s.cmxx' % (os.path.join(sub_dir, m))) out.write(' %s.cmi' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - if IS_WINDOWS: - out.write(' libz3$(LIB_EXT)') - out.write('\n') - out.write('\n') + out.write(' %s' % ((os.path.join(sub_dir, 'libz3$(LIB_EXT)')))) + out.write(' %s' % ((os.path.join(sub_dir, 'dllz3$(SO_EXT)')))) + out.write('\n\n') def main_component(self): From 2ee4409962405dbef86874398ad4197332b5cd73 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 13:51:17 +0000 Subject: [PATCH 229/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 5e412c892..bd60feaa8 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1440,8 +1440,9 @@ class MLComponent(Component): out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) for m in modules: out.write(' ' + m) - out.write('z3native_stubs$(OBJ_EXT) ; cd -' ) - out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) + out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') + out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) + # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) #out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) From ceabafa01cdbb66c6b6c465fd62e5c8c6f87d774 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 14:11:19 +0000 Subject: [PATCH 230/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index bd60feaa8..38cbb32f5 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1434,8 +1434,8 @@ class MLComponent(Component): out.write('%s:' % (os.path.join(sub_dir, "z3.cmxa"))) for m in modules: out.write(' %s.cmi' % (os.path.join(sub_dir, m))) - out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - out.write(' %s.cmo' % (os.path.join(sub_dir, m))) + # out.write(' %s.cmx' % (os.path.join(sub_dir, m))) + # out.write(' %s.cmo' % (os.path.join(sub_dir, m))) out.write('%s/z3native_stubs.o\n' % (sub_dir)) out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) for m in modules: @@ -1453,11 +1453,15 @@ class MLComponent(Component): for m in modules: out.write(' %s.cma' % (os.path.join(sub_dir, m))) out.write(' %s.cmxa' % (os.path.join(sub_dir, m))) - out.write(' %s.cmxx' % (os.path.join(sub_dir, m))) - out.write(' %s.cmi' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) + out.write(' %s.cmxs' % (os.path.join(sub_dir, m))) + out.write(' %s.cmi' % (os.path.join(sub_dir, m))) out.write(' %s' % ((os.path.join(sub_dir, 'libz3$(LIB_EXT)')))) - out.write(' %s' % ((os.path.join(sub_dir, 'dllz3$(SO_EXT)')))) + out.write(' %s' % ((os.path.join(sub_dir, 'dllz3')))) + if IS_WINDOWS: + out.write('.lib') + else: + out.write('.so') # .so also on OSX! out.write('\n\n') From 4c28085022419176c3b4cd4b8227a283ee024cae Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 14:14:14 +0000 Subject: [PATCH 231/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 38cbb32f5..24c9def9c 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1436,7 +1436,7 @@ class MLComponent(Component): out.write(' %s.cmi' % (os.path.join(sub_dir, m))) # out.write(' %s.cmx' % (os.path.join(sub_dir, m))) # out.write(' %s.cmo' % (os.path.join(sub_dir, m))) - out.write('%s/z3native_stubs.o\n' % (sub_dir)) + out.write(' %s/z3native_stubs.o\n' % (sub_dir)) out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) for m in modules: out.write(' ' + m) From 198c6ef930d3684fca1ed15aee7cd327bb653a7a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 14:18:03 +0000 Subject: [PATCH 232/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 24c9def9c..3f53266e2 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1439,7 +1439,7 @@ class MLComponent(Component): out.write(' %s/z3native_stubs.o\n' % (sub_dir)) out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) for m in modules: - out.write(' ' + m) + out.write(' %s.ml' % m) out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) From d47f143591f3fe7e9f0ada321841b292e393c3fc Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 15:03:10 +0000 Subject: [PATCH 233/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 3f53266e2..0625e9c68 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1436,28 +1436,28 @@ class MLComponent(Component): out.write(' %s.cmi' % (os.path.join(sub_dir, m))) # out.write(' %s.cmx' % (os.path.join(sub_dir, m))) # out.write(' %s.cmo' % (os.path.join(sub_dir, m))) - out.write(' %s/z3native_stubs.o\n' % (sub_dir)) - out.write('\tcd %s ; ocamlmklib -verbose -o z3' % (sub_dir)) + out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) + out.write('\tcd %s ; ocamlmklib -o z3ml' % (sub_dir)) for m in modules: out.write(' %s.ml' % m) out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') - out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) + out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) #out.write('\n') # Generate META file and package installation commands self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('\nocamlfind_install: api/ml/z3.cmxa api/ml/META\n') + out.write('\nocamlfind_install: %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'META'))) out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) for m in modules: out.write(' %s.cma' % (os.path.join(sub_dir, m))) out.write(' %s.cmxa' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - out.write(' %s.cmxs' % (os.path.join(sub_dir, m))) + #out.write(' %s.cmxs' % (os.path.join(sub_dir, m))) out.write(' %s.cmi' % (os.path.join(sub_dir, m))) - out.write(' %s' % ((os.path.join(sub_dir, 'libz3$(LIB_EXT)')))) - out.write(' %s' % ((os.path.join(sub_dir, 'dllz3')))) + out.write(' %s' % ((os.path.join(sub_dir, 'libz3ml$(LIB_EXT)')))) + out.write(' %s' % ((os.path.join(sub_dir, 'dllz3ml')))) if IS_WINDOWS: out.write('.lib') else: From ea9fc43544bdf2f9b24bbfca92a923561869d35f Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 15:38:15 +0000 Subject: [PATCH 234/248] ML API: build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 0625e9c68..ce8abd4ce 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1422,14 +1422,19 @@ class MLComponent(Component): # if DEBUG_MODE: # out.write('-g ') # out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - # out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cma'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - # for mlfile in get_ml_files(self.src_dir): - # out.write(' %s' % os.path.join(sub_dir, mlfile)) - # out.write('\n') - # out.write('\t%s ' % (OCAMLC)) - # if DEBUG_MODE: - # out.write('-g ') - # out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cma -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) + out.write('%s: %s %s$(SO_EXT) %s' % ( + os.path.join(sub_dir, 'z3.cma'), + os.path.join(sub_dir, 'libz3ml$(LIB_EXT)'), + get_component(Z3_DLL_COMPONENT).dll_name, cmis)) + for mlfile in get_ml_files(self.src_dir): + out.write(' %s' % os.path.join(sub_dir, mlfile)) + out.write('\n') + out.write('\t%s ' % (OCAMLC)) + if DEBUG_MODE: + out.write('-g ') + out.write('-I %s -a -o %s -linkall' % (sub_dir, os.path.join(sub_dir, 'z3.cma'))) + for m in modules: + out.write(' %s.ml' % (os.path.join(sub_dir, m))) out.write('%s:' % (os.path.join(sub_dir, "z3.cmxa"))) for m in modules: From 93a20d90740c2112fb5cac5f11ebbe2097503762 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 19:22:23 +0000 Subject: [PATCH 235/248] ML API: build fixes --- scripts/mk_util.py | 94 +++++++++++++++++----------------------------- src/api/ml/META | 6 +-- src/api/ml/z3.ml | 2 +- 3 files changed, 38 insertions(+), 64 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index ce8abd4ce..b674d106f 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1380,19 +1380,25 @@ class MLComponent(Component): str = '\t%s %s %s\n' % (CP_CMD,os.path.join(src_dir,f),os.path.join(sub_dir,f)) out.write(str) modules = ["z3enums", "z3native", "z3"] # dependencies in this order! - prev = '' + mls = '' + mlis = '' + cmis = '' + archives = '' + for m in modules: fn = os.path.join(self.src_dir, ('%s.mli' % m)) if not os.path.exists(fn): - out.write('%s.mli: %s.ml%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),prev)) + out.write('%s.mli: %s.ml%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),mlis)) out.write('\t%s -I %s -i -c %s.ml > %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir, m),os.path.join(sub_dir, m))) - prev = prev + ' ' + os.path.join(sub_dir, m) + '.mli' - cmis = '' - for m in modules: out.write('%s.cmi: %s.mli%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m), cmis)) out.write('\t%s -I %s -c %s.mli\n' % (OCAMLC,sub_dir,os.path.join(sub_dir,m))) + out.write('%s.cma: %s.ml %s.cmi%s\n' % (os.path.join(sub_dir,m),os.path.join(sub_dir,m),os.path.join(sub_dir,m), archives)) + out.write('\t%s -a -o %s.ml -o %s.cma\n' % (OCAMLC,os.path.join(sub_dir,m), os.path.join(sub_dir,m))) + mlis = mlis + ' ' + os.path.join(sub_dir, m) + '.mli' cmis = cmis + ' ' + os.path.join(sub_dir,m) + '.cmi' - + archives = archives + ' ' + os.path.join(sub_dir,m) + '.cma' + mls = mls + ' ' + os.path.join(sub_dir, m) + '.ml' + out.write('%s: %s %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'), os.path.join(sub_dir, 'z3native_stubs.c'), @@ -1400,73 +1406,43 @@ class MLComponent(Component): out.write('\t$(CC) $(CXXFLAGS) -I %s -I %s %s $(CXX_OUT_FLAG)%s$(OBJ_EXT)\n' % (OCAML_LIB, api_src, os.path.join(sub_dir, 'z3native_stubs.c'), os.path.join(sub_dir, 'z3native_stubs'))) - # out.write('api/ml/libz3ml$(LIB_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - # out.write('\t$(AR) $(AR_FLAGS) $(AR_OUTFLAG)api/ml/libz3ml$(LIB_EXT) api/ml/z3native_stubs$(OBJ_EXT)\n') - - # out.write('api/ml/libz3ml$(SO_EXT): api/ml/z3native_stubs$(OBJ_EXT) %s$(SO_EXT)\n' % get_component(Z3_DLL_COMPONENT).dll_name) - # out.write('\t$(SLINK) $(SLINK_OUT_FLAG)api/ml/libz3ml$(SO_EXT) $(SLINK_FLAGS) -I %s -I %s api/ml/z3native_stubs$(OBJ_EXT) %s$(LIB_EXT)\n' % (OCAML_LIB, api_src, get_component(Z3_DLL_COMPONENT).dll_name)) - - - # out.write('%s: api/ml/libz3ml$(LIB_EXT) %s$(SO_EXT) %s' % (os.path.join(sub_dir, 'z3.cmxa'), get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - - # for mlfile in get_ml_files(self.src_dir): - # out.write(' %s' % os.path.join(sub_dir, mlfile)) - # out.write('\n') - # out.write('\t%s ' % (OCAMLOPT)) - # if DEBUG_MODE: - # out.write('-g ') - # out.write('-cclib "-L %s -lz3ml" -I %s %s/z3enums.ml %s/z3native.ml %s/z3.ml -a -o api/ml/z3.cmxa -linkall\n' % (sub_dir, sub_dir,sub_dir,sub_dir,sub_dir)) - - # out.write('%s: %s\n' % (os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - # out.write('\t%s ' % (OCAMLOPT)) - # if DEBUG_MODE: - # out.write('-g ') - # out.write('-cclib "-L %s -lz3ml" -shared -o %s %s -linkall\n' % (sub_dir, os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cmxa'))) - out.write('%s: %s %s$(SO_EXT) %s' % ( - os.path.join(sub_dir, 'z3.cma'), - os.path.join(sub_dir, 'libz3ml$(LIB_EXT)'), - get_component(Z3_DLL_COMPONENT).dll_name, cmis)) - for mlfile in get_ml_files(self.src_dir): - out.write(' %s' % os.path.join(sub_dir, mlfile)) - out.write('\n') - out.write('\t%s ' % (OCAMLC)) - if DEBUG_MODE: - out.write('-g ') - out.write('-I %s -a -o %s -linkall' % (sub_dir, os.path.join(sub_dir, 'z3.cma'))) - for m in modules: - out.write(' %s.ml' % (os.path.join(sub_dir, m))) - - out.write('%s:' % (os.path.join(sub_dir, "z3.cmxa"))) - for m in modules: - out.write(' %s.cmi' % (os.path.join(sub_dir, m))) - # out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - # out.write(' %s.cmo' % (os.path.join(sub_dir, m))) + out.write('%s: %s %s %s$(SO_EXT)' % ( + os.path.join(sub_dir, "z3ml.cmxa"), + cmis, + archives, + get_component(Z3_DLL_COMPONENT).dll_name)) out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) - out.write('\tcd %s ; ocamlmklib -o z3ml' % (sub_dir)) + out.write('\tcd %s ; ocamlmklib -o z3ml -ldopt \'-L../.. -lz3\' ' % (sub_dir)) for m in modules: out.write(' %s.ml' % m) out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') - out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3.cmxa'))) - # , os.path.join(sub_dir, 'z3.cmxs'), os.path.join(sub_dir, 'z3.cma'))) - #out.write('\n') - # Generate META file and package installation commands + out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3ml.cmxa'))) self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': - out.write('\nocamlfind_install: %s %s\n' % (os.path.join(sub_dir, 'z3.cmxa'), os.path.join(sub_dir, 'META'))) + out.write('\nocamlfind_install: %s %s %s\n' % ( + get_component(Z3_DLL_COMPONENT).dll_name)+'$(SO_EXT)', + os.path.join(sub_dir, 'z3ml.cmxa'), + os.path.join(sub_dir, 'META'))) out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) for m in modules: out.write(' %s.cma' % (os.path.join(sub_dir, m))) - out.write(' %s.cmxa' % (os.path.join(sub_dir, m))) out.write(' %s.cmx' % (os.path.join(sub_dir, m))) - #out.write(' %s.cmxs' % (os.path.join(sub_dir, m))) out.write(' %s.cmi' % (os.path.join(sub_dir, m))) + out.write(' %s.cmo' % (os.path.join(sub_dir, m))) + out.write(' %s.ml' % (os.path.join(sub_dir, m))) + out.write(' %s.mli' % (os.path.join(sub_dir, m))) + out.write(' %s$(OBJ_EXT)' % (os.path.join(sub_dir, m))) + out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.a')))) + out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cma')))) + out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cmxa')))) out.write(' %s' % ((os.path.join(sub_dir, 'libz3ml$(LIB_EXT)')))) out.write(' %s' % ((os.path.join(sub_dir, 'dllz3ml')))) if IS_WINDOWS: out.write('.lib') else: out.write('.so') # .so also on OSX! + out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name) + '$(SO_EXT)')))) out.write('\n\n') @@ -1591,25 +1567,25 @@ class MLExampleComponent(ExampleComponent): def mk_makefile(self, out): if ML_ENABLED: - out.write('ml_example.byte: api/ml/z3.cma ') + out.write('ml_example.byte: api/ml/z3ml.cma ') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') out.write('\t%s ' % OCAMLC) if DEBUG_MODE: out.write('-g ') - out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" nums.cma z3.cma') + out.write('-custom -o ml_example.byte -I api/ml -cclib "-L. -lz3" nums.cma z3ml.cma') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') - out.write('ml_example$(EXE_EXT): api/ml/z3.cmxa ml_example.byte') + out.write('ml_example$(EXE_EXT): api/ml/z3ml.cmxa ml_example.byte') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') out.write('\t%s ' % OCAMLOPT) if DEBUG_MODE: out.write('-g ') - out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" nums.cmxa z3.cmxa') + out.write('-o ml_example$(EXE_EXT) -I api/ml -cclib "-L. -lz3" nums.cmxa z3ml.cmxa') for mlfile in get_ml_files(self.ex_dir): out.write(' %s/%s' % (self.to_ex_dir, mlfile)) out.write('\n') diff --git a/src/api/ml/META b/src/api/ml/META index 635de613c..8634b53b1 100644 --- a/src/api/ml/META +++ b/src/api/ml/META @@ -4,8 +4,6 @@ description = "Z3 Theorem Prover (OCaml API)" requires = "num" archive(byte) = "z3ml.cma" archive(native) = "z3ml.cmxa" -archive(byte,plugin) = "z3ml.cma" -archive(native,plugin) = "z3ml.cmxa" -archive(byte,toploop) = "z3ml.cma" -archive(native,toploop) = "z3ml.cmxa" +archive(byte, plugin) = "z3ml.cma" +archive(native, plugin) = "z3ml.cmxs" linkopts = "-cclib -lz3" diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 2b54a1113..350457525 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -110,7 +110,7 @@ struct string_of_int mj ^ "." ^ string_of_int mn ^ "." ^ string_of_int bld ^ "." ^ - string_of_int rev ^ "." + string_of_int rev end From 05f42b0073d50c20dff4a3fa229d09897ba580c5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Thu, 4 Dec 2014 19:42:03 +0000 Subject: [PATCH 236/248] ML API: build fixes? --- scripts/mk_util.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index b674d106f..4ccf23932 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1412,16 +1412,18 @@ class MLComponent(Component): archives, get_component(Z3_DLL_COMPONENT).dll_name)) out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) - out.write('\tcd %s ; ocamlmklib -o z3ml -ldopt \'-L../.. -lz3\' ' % (sub_dir)) + out.write('\tocamlmklib -o %s -I %s -ldopt \'-L. -lz3\' ' % ( + os.path.join(sub_dir, 'z3ml'), + sub_dir)) for m in modules: - out.write(' %s.ml' % m) - out.write(' z3native_stubs$(OBJ_EXT) ; cd -\n') + out.write(' %s' % (os.path.join(sub_dir, m+'.ml'))) + out.write(' z3native_stubs$(OBJ_EXT)\n') out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3ml.cmxa'))) self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': out.write('\nocamlfind_install: %s %s %s\n' % ( - get_component(Z3_DLL_COMPONENT).dll_name)+'$(SO_EXT)', - os.path.join(sub_dir, 'z3ml.cmxa'), + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)', + os.path.join(sub_dir, 'z3ml.cmxa'), os.path.join(sub_dir, 'META'))) out.write('\t%s remove Z3\n' % (OCAMLFIND)) out.write('\t%s install Z3 %s' % (OCAMLFIND, (os.path.join(sub_dir, 'META')))) @@ -1442,7 +1444,7 @@ class MLComponent(Component): out.write('.lib') else: out.write('.so') # .so also on OSX! - out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name) + '$(SO_EXT)')))) + out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)') out.write('\n\n') From 5c67b596857524db527fad2aa0361c948f434305 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 5 Dec 2014 16:40:40 +0000 Subject: [PATCH 237/248] ML API: Windows build fixes Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 4ccf23932..8c6d35a0a 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1412,12 +1412,10 @@ class MLComponent(Component): archives, get_component(Z3_DLL_COMPONENT).dll_name)) out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) - out.write('\tocamlmklib -o %s -I %s -ldopt \'-L. -lz3\' ' % ( - os.path.join(sub_dir, 'z3ml'), - sub_dir)) + out.write('\tocamlmklib -o %s -I %s -ldopt \"-L. -lz3\" ' % (os.path.join(sub_dir, 'z3ml'), sub_dir)) for m in modules: out.write(' %s' % (os.path.join(sub_dir, m+'.ml'))) - out.write(' z3native_stubs$(OBJ_EXT)\n') + out.write(' %s\n' % (os.path.join(sub_dir, 'z3native_stubs$(OBJ_EXT)'))) out.write('ml: %s\n' % (os.path.join(sub_dir, 'z3ml.cmxa'))) self.mk_ml_meta(os.path.join('src/api/ml/META'), os.path.join(BUILD_DIR, sub_dir, 'META'), VER_MAJOR, VER_MINOR, VER_BUILD, VER_REVISION) if OCAMLFIND != '': @@ -1435,13 +1433,13 @@ class MLComponent(Component): out.write(' %s.ml' % (os.path.join(sub_dir, m))) out.write(' %s.mli' % (os.path.join(sub_dir, m))) out.write(' %s$(OBJ_EXT)' % (os.path.join(sub_dir, m))) - out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.a')))) + out.write(' %s' % ((os.path.join(sub_dir, 'z3ml$(LIB_EXT)')))) out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cma')))) out.write(' %s' % ((os.path.join(sub_dir, 'z3ml.cmxa')))) out.write(' %s' % ((os.path.join(sub_dir, 'libz3ml$(LIB_EXT)')))) out.write(' %s' % ((os.path.join(sub_dir, 'dllz3ml')))) if IS_WINDOWS: - out.write('.lib') + out.write('.dll') else: out.write('.so') # .so also on OSX! out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)') @@ -1569,7 +1567,7 @@ class MLExampleComponent(ExampleComponent): def mk_makefile(self, out): if ML_ENABLED: - out.write('ml_example.byte: api/ml/z3ml.cma ') + out.write('ml_example.byte: api/ml/z3ml.cmxa ') for mlfile in get_ml_files(self.ex_dir): out.write(' %s' % os.path.join(self.to_ex_dir, mlfile)) out.write('\n') From 011b700c20aadf000fceb5da9b4630f8939b033a Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 6 Dec 2014 18:14:26 +0000 Subject: [PATCH 238/248] ML API: build fix --- src/api/ml/META | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/ml/META b/src/api/ml/META index 8634b53b1..635de613c 100644 --- a/src/api/ml/META +++ b/src/api/ml/META @@ -4,6 +4,8 @@ description = "Z3 Theorem Prover (OCaml API)" requires = "num" archive(byte) = "z3ml.cma" archive(native) = "z3ml.cmxa" -archive(byte, plugin) = "z3ml.cma" -archive(native, plugin) = "z3ml.cmxs" +archive(byte,plugin) = "z3ml.cma" +archive(native,plugin) = "z3ml.cmxa" +archive(byte,toploop) = "z3ml.cma" +archive(native,toploop) = "z3ml.cmxa" linkopts = "-cclib -lz3" From 10c153bfe46fa74d58995dc392ac1ef89de9bc76 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 6 Dec 2014 18:21:27 +0000 Subject: [PATCH 239/248] ML API: build fix --- examples/ml/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ml/README b/examples/ml/README index 31d4b8e2e..b7aa187fa 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -15,10 +15,10 @@ for the byte-code version. If Z3 was installed into the ocamlfind package repository (see src/api/ml/README), then we can compile this example as follows: -ocamlfind ocamlc -o ml_example.byte -custom -package Z3 -linkpkg ml_example.ml +ocamlfind ocamlc -o ml_example.byte -package Z3 -linkpkg ml_example.ml ocamlfind ocamlopt -o ml_example -package Z3 -linkpkg ml_example.ml Note that the resulting binaries depend on the shared z3 library, which needs to be in the PATH (Windows), LD_LIBRARY_PATH (Linux) or DYLD_LIBRARY_PATH (OSX). If Z3 was installed into ocamlfind, the path that should be added is -`ocamlfind printconf destdir`/Z3 \ No newline at end of file +`ocamlfind printconf destdir`/Z3 From bb310144175221fd1dd7d885d139ec65b14b03b0 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 6 Dec 2014 18:37:09 +0000 Subject: [PATCH 240/248] ML API: build fix Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 8c6d35a0a..86035b94b 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -1443,6 +1443,8 @@ class MLComponent(Component): else: out.write('.so') # .so also on OSX! out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(SO_EXT)') + if IS_WINDOWS: + out.write(' ' + get_component(Z3_DLL_COMPONENT).dll_name + '$(LIB_EXT)') out.write('\n\n') From e754aa1c1169b61904b3fce21aeb286ce641aec4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 16 Jan 2015 19:25:21 +0000 Subject: [PATCH 241/248] Minor adjustments after rebasing ml-ng onto unstable. Signed-off-by: Christoph M. Wintersteiger --- .gitignore | 5 +++++ scripts/mk_util.py | 9 ++++++--- src/api/ml/README-test-win | 23 ----------------------- 3 files changed, 11 insertions(+), 26 deletions(-) delete mode 100644 src/api/ml/README-test-win diff --git a/.gitignore b/.gitignore index 3cd2d3ef3..93194fc1b 100644 --- a/.gitignore +++ b/.gitignore @@ -68,4 +68,9 @@ src/api/java/enumerations/*.java src/api/ml/z3native_stubs.c src/api/ml/z3native.ml src/api/ml/z3enums.ml +src/api/ml/z3native.mli +src/api/ml/z3enums.mli src/api/ml/z3.mllib +*.bak +doc/api +doc/code diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 86035b94b..5f2b846a0 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -357,6 +357,7 @@ def check_ml(): rmf('hello.cmo') rmf('hello.cmx') rmf('a.out') + rmf('hello.o') find_ml_lib() find_ocaml_find() @@ -384,6 +385,8 @@ def find_ml_lib(): OCAML_LIB = line[:-1] if is_verbose(): print 'OCAML_LIB=%s' % OCAML_LIB + t.close() + rmf('output') return def is64(): @@ -1737,10 +1740,10 @@ def mk_config(): # End of Windows VS config.mk if is_verbose(): print('64-bit: %s' % is64()) - print('ML API: %s' % is_ml_enabled()) if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) + print('ML API: %s' % is_ml_enabled()) if is_ml_enabled(): print('OCaml Compiler: %s' % OCAMLC) print('OCaml Native: %s' % OCAMLOPT) @@ -1859,11 +1862,11 @@ def mk_config(): print('64-bit: %s' % is64()) if GPROF: print('gprof: enabled') - print('Python version: %s' % distutils.sysconfig.get_python_version()) - print('ML API: %s' % is_ml_enabled()) + print('Python version: %s' % distutils.sysconfig.get_python_version()) if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) + print('ML API: %s' % is_ml_enabled()) if is_ml_enabled(): print('Ocaml Compiler: %s' % OCAMLC) print('Ocaml Native: %s' % OCAMLOPT) diff --git a/src/api/ml/README-test-win b/src/api/ml/README-test-win deleted file mode 100644 index 0e8b73ccd..000000000 --- a/src/api/ml/README-test-win +++ /dev/null @@ -1,23 +0,0 @@ -This directory contains scripts to build the test application using -OCaml. You also need CamlIDL to be able to generate the OCaml API. - -- To download OCaml: - http://caml.inria.fr/ocaml/ - -- To download CamlIDL: - http://forge.ocamlcore.org/projects/camlidl/ - -- One must build the OCaml library before compiling the example. - Go to directory ../ocaml - -- Use 'build-test.cmd' to build the test application using the OCaml compiler. - -Remark: The OCaml and C compiler tool chains must be configured in your environment. -Running from the Visual Studio Command Prompt configures the Microsoft C compiler. - -- The script 'exec.cmd' adds the bin directory to the path. So, - test_mlapi.exe can find z3.dll. - - - - From c9fa77cc70e1d7cd0953743d12202f93fd3b9387 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 19 Jan 2015 15:29:50 +0000 Subject: [PATCH 242/248] ML API: fixed Python 3.4 issues in the build scripts Signed-off-by: Christoph M. Wintersteiger --- scripts/mk_util.py | 14 +++++++------- scripts/update_api.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 5f2b846a0..49ff79824 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -344,12 +344,12 @@ def check_ml(): t.add('print_string "Hello world!\n";;') t.commit() if is_verbose(): - print "Testing %s..." % OCAMLC + print ('Testing %s...' % OCAMLC) r = exec_cmd([OCAMLC, '-o', 'a.out', 'hello.ml']) if r != 0: raise MKException('Failed testing ocamlc compiler. Set environment variable OCAMLC with the path to the Ocaml compiler') if is_verbose(): - print "Testing %s..." % OCAMLOPT + print ('Testing %s...' % OCAMLOPT) r = exec_cmd([OCAMLOPT, '-o', 'a.out', 'hello.ml']) if r != 0: raise MKException('Failed testing ocamlopt compiler. Set environment variable OCAMLOPT with the path to the Ocaml native compiler. Note that ocamlopt may require flexlink to be in your path.') @@ -364,7 +364,7 @@ def check_ml(): def find_ocaml_find(): global OCAMLFIND if is_verbose(): - print "Testing %s..." % OCAMLFIND + print ('Testing %s...' % OCAMLFIND) r = exec_cmd([OCAMLFIND, 'printconf']) if r != 0: OCAMLFIND='' @@ -372,7 +372,7 @@ def find_ocaml_find(): def find_ml_lib(): global OCAML_LIB if is_verbose(): - print "Finding OCAML_LIB..." + print ('Finding OCAML_LIB...') t = TempFile('output') null = open(os.devnull, 'wb') try: @@ -384,7 +384,7 @@ def find_ml_lib(): for line in t: OCAML_LIB = line[:-1] if is_verbose(): - print 'OCAML_LIB=%s' % OCAML_LIB + print ('OCAML_LIB=%s' % OCAML_LIB) t.close() rmf('output') return @@ -2810,7 +2810,7 @@ def mk_z3consts_ml(api_files): linenum = linenum + 1 efile.write('end\n') if VERBOSE: - print "Generated '%s/z3enums.ml'" % ('%s' % gendir) + print ('Generated "%s/z3enums.ml"' % ('%s' % gendir)) efile = open('%s.mli' % os.path.join(gendir, "z3enums"), 'w') efile.write('(* Automatically generated file *)\n\n') efile.write('(** The enumeration types of Z3. *)\n\n') @@ -2880,7 +2880,7 @@ def mk_z3consts_ml(api_files): idx = idx + 1 linenum = linenum + 1 if VERBOSE: - print "Generated '%s/z3enums.mli'" % ('%s' % gendir) + print ('Generated "%s/z3enums.mli"' % ('%s' % gendir)) def mk_gui_str(id): return '4D2F40D8-E5F9-473B-B548-%012d' % id diff --git a/scripts/update_api.py b/scripts/update_api.py index 4669b78fc..a70214971 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -276,7 +276,7 @@ def param2dotnet(p): elif k == OUT_ARRAY: return "[Out] %s[]" % type2dotnet(param_type(p)) elif k == OUT_MANAGED_ARRAY: - return "[Out] out %s[]" % type2dotnet(param_type(p)) + return "[Out] out %s[]" % type2dotnet(param_type(p)) else: return type2dotnet(param_type(p)) @@ -1517,7 +1517,7 @@ def mk_ml(): ml_wrapper.write('}\n') ml_wrapper.write('#endif\n') if is_verbose(): - print "Generated '%s'" % ml_nativef + print ('Generated "%s"' % ml_nativef) # Collect API(...) commands from def def_APIs(): From ed0fa9324592293e97f8a0da267cc3eb384a1e03 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Mon, 19 Jan 2015 17:35:19 +0000 Subject: [PATCH 243/248] Minor adjustments after rebase Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 2 +- scripts/mk_util.py | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 25862b2d7..33334930e 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -190,7 +190,7 @@ let basic_tests ( ctx : context ) = (* Error handling test. *) try ( let i = Integer.mk_numeral_s ctx "1/2" in - raise (TestFailedException "") (* unreachable *) + raise (TestFailedException (to_string i)) (* unreachable *) ) with Z3native.Exception(_) -> ( Printf.printf "Exception caught, OK.\n" diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 49ff79824..30c305047 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -357,14 +357,13 @@ def check_ml(): rmf('hello.cmo') rmf('hello.cmx') rmf('a.out') - rmf('hello.o') find_ml_lib() find_ocaml_find() def find_ocaml_find(): global OCAMLFIND if is_verbose(): - print ('Testing %s...' % OCAMLFIND) + print ("Testing %s..." % OCAMLFIND) r = exec_cmd([OCAMLFIND, 'printconf']) if r != 0: OCAMLFIND='' @@ -1743,7 +1742,6 @@ def mk_config(): if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) - print('ML API: %s' % is_ml_enabled()) if is_ml_enabled(): print('OCaml Compiler: %s' % OCAMLC) print('OCaml Native: %s' % OCAMLOPT) @@ -1866,11 +1864,10 @@ def mk_config(): if is_java_enabled(): print('JNI Bindings: %s' % JNI_HOME) print('Java Compiler: %s' % JAVAC) - print('ML API: %s' % is_ml_enabled()) if is_ml_enabled(): - print('Ocaml Compiler: %s' % OCAMLC) - print('Ocaml Native: %s' % OCAMLOPT) - print('Ocaml Library: %s' % OCAML_LIB) + print('OCaml Compiler: %s' % OCAMLC) + print('OCaml Native: %s' % OCAMLOPT) + print('OCaml Library: %s' % OCAML_LIB) def mk_install(out): out.write('install: ') @@ -2437,9 +2434,6 @@ def mk_bindings(api_files): if is_java_enabled(): check_java() mk_z3consts_java(api_files) - if is_ml_enabled(): - check_ml() - mk_z3consts_ml(api_files) _execfile(os.path.join('scripts', 'update_api.py'), g) # HACK cp_z3py_to_build() if is_ml_enabled(): @@ -2808,7 +2802,6 @@ def mk_z3consts_ml(api_files): decls[words[1]] = idx idx = idx + 1 linenum = linenum + 1 - efile.write('end\n') if VERBOSE: print ('Generated "%s/z3enums.ml"' % ('%s' % gendir)) efile = open('%s.mli' % os.path.join(gendir, "z3enums"), 'w') From 65ccc9a8eadfb5fbebe95bd76c6323818d091398 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 23 Jan 2015 19:36:47 +0000 Subject: [PATCH 244/248] added FPA ML API Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 89 +++++++++- scripts/update_api.py | 2 +- src/api/ml/z3.ml | 210 ++++++++++++++++++++++- src/api/ml/z3.mli | 352 +++++++++++++++++++++++++++++++++++++- 4 files changed, 630 insertions(+), 23 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 33334930e..8a2d71d82 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -19,6 +19,7 @@ open Z3.Arithmetic.Integer open Z3.Arithmetic.Real open Z3.BitVector + exception TestFailedException of string (** @@ -73,7 +74,6 @@ let model_converter_test ( ctx : context ) = *) let basic_tests ( ctx : context ) = Printf.printf "BasicTests\n" ; -(* let qi = (mk_int ctx 1) in *) let fname = (mk_string ctx "f") in let x = (mk_string ctx "x") in let y = (mk_string ctx "y") in @@ -167,8 +167,8 @@ let basic_tests ( ctx : context ) = let rn = Real.mk_numeral_nd ctx 42 43 in let inum = (get_numerator rn) in let iden = get_denominator rn in - Printf.printf "Numerator: %s Denominator: %s\n" (Real.to_string inum) (Real.to_string iden) ; - if ((Real.to_string inum) <> "42" || (Real.to_string iden) <> "43") then + Printf.printf "Numerator: %s Denominator: %s\n" (Real.numeral_to_string inum) (Real.numeral_to_string iden) ; + if ((Real.numeral_to_string inum) <> "42" || (Real.numeral_to_string iden) <> "43") then raise (TestFailedException "") else Printf.printf "Test passed.\n" @@ -190,7 +190,7 @@ let basic_tests ( ctx : context ) = (* Error handling test. *) try ( let i = Integer.mk_numeral_s ctx "1/2" in - raise (TestFailedException (to_string i)) (* unreachable *) + raise (TestFailedException (numeral_to_string i)) (* unreachable *) ) with Z3native.Exception(_) -> ( Printf.printf "Exception caught, OK.\n" @@ -199,7 +199,7 @@ let basic_tests ( ctx : context ) = (** A basic example of how to use quantifiers. **) -let quantifierExample1 ( ctx : context ) = +let quantifier_example1 ( ctx : context ) = Printf.printf "QuantifierExample\n" ; let is = (Integer.mk_sort ctx) in let types = [ is; is; is ] in @@ -239,6 +239,82 @@ let quantifierExample1 ( ctx : context ) = else if (is_const (Quantifier.expr_of_quantifier x)) then raise (TestFailedException "") (* unreachable *) + +open Z3.FloatingPoint + +(** + A basic example of floating point arithmetic +**) +let fpa_example ( ctx : context ) = + Printf.printf "FPAExample\n" ; + let double_sort = (FloatingPoint.mk_sort_double ctx) in + let rm_sort = (FloatingPoint.RoundingMode.mk_sort ctx) in + + (** Show that there are x, y s.t. (x + y) = 42.0 (with rounding mode). *) + let s_rm = (mk_string ctx "rm") in + let rm = (mk_const ctx s_rm rm_sort) in + let s_x = (mk_string ctx "x") in + let s_y = (mk_string ctx "y") in + let x = (mk_const ctx s_x double_sort) in + let y = (mk_const ctx s_y double_sort)in + Printf.printf "A\n" ; + let n = (mk_numeral_f ctx 42.0 double_sort) in + Printf.printf "B\n" ; + let s_x_plus_y = (mk_string ctx "x_plus_y") in + let x_plus_y = (mk_const ctx s_x_plus_y double_sort) in + let c1 = (mk_eq ctx x_plus_y (mk_add ctx rm x y)) in + let args = [ c1 ; (mk_eq ctx x_plus_y n) ] in + let c2 = (Boolean.mk_and ctx args) in + let args2 = [ c2 ; (Boolean.mk_not ctx (mk_eq ctx rm (RoundingMode.mk_rtz ctx))) ] in + let c3 = (Boolean.mk_and ctx args2) in + let and_args = [ (Boolean.mk_not ctx (mk_is_zero ctx y)) ; + (Boolean.mk_not ctx (mk_is_nan ctx y)) ; + (Boolean.mk_not ctx (mk_is_infinite ctx y)) ] in + let args3 = [ c3 ; (Boolean.mk_and ctx and_args) ] in + let c4 = (Boolean.mk_and ctx args3) in + + (Printf.printf "c4: %s\n" (Expr.to_string c4)) + (* push(ctx); *) + (* Z3_assert_cnstr(ctx, c4); *) + (* check(ctx, Z3_L_TRUE); *) + (* Z3_pop(ctx, 1); *) + + (* // Show that the following are equal: *) + (* // (fp #b0 #b10000000001 #xc000000000000) *) + (* // ((_ to_fp 11 53) #x401c000000000000)) *) + (* // ((_ to_fp 11 53) RTZ 1.75 2))) *) + (* // ((_ to_fp 11 53) RTZ 7.0))) *) + + (* Z3_push(ctx); *) + (* c1 = Z3_mk_fpa_fp(ctx, *) + (* Z3_mk_numeral(ctx, "0", Z3_mk_bv_sort(ctx, 1)), *) + (* Z3_mk_numeral(ctx, "3377699720527872", Z3_mk_bv_sort(ctx, 52)), *) + (* Z3_mk_numeral(ctx, "1025", Z3_mk_bv_sort(ctx, 11))); *) + (* c2 = Z3_mk_fpa_to_fp_bv(ctx, *) + (* Z3_mk_numeral(ctx, "4619567317775286272", Z3_mk_bv_sort(ctx, 64)), *) + (* Z3_mk_fpa_sort(ctx, 11, 53)); *) + (* c3 = Z3_mk_fpa_to_fp_real_int(ctx, *) + (* Z3_mk_fpa_rtz(ctx), *) + (* Z3_mk_numeral(ctx, "1.75", Z3_mk_real_sort(ctx)), *) + (* Z3_mk_numeral(ctx, "2", Z3_mk_int_sort(ctx)), *) + (* Z3_mk_fpa_sort(ctx, 11, 53)); *) + (* c4 = Z3_mk_fpa_to_fp_real(ctx, *) + (* Z3_mk_fpa_rtz(ctx), *) + (* Z3_mk_numeral(ctx, "7.0", Z3_mk_real_sort(ctx)), *) + (* Z3_mk_fpa_sort(ctx, 11, 53)); *) + (* args3[0] = Z3_mk_eq(ctx, c1, c2); *) + (* args3[1] = Z3_mk_eq(ctx, c1, c3); *) + (* args3[2] = Z3_mk_eq(ctx, c1, c4); *) + (* c5 = Z3_mk_and(ctx, 3, args3); *) + + (* printf("c5: %s\n", Z3_ast_to_string(ctx, c5)); *) + (* Z3_assert_cnstr(ctx, c5); *) + (* check(ctx, Z3_L_TRUE); *) + (* Z3_pop(ctx, 1); *) + + (* Z3_del_context(ctx); *) + + let _ = try ( if not (Log.open_ "z3.log") then @@ -259,7 +335,8 @@ let _ = Printf.printf "int sort: %s\n" (Sort.to_string ints); Printf.printf "real sort: %s\n" (Sort.to_string rs); basic_tests ctx ; - quantifierExample1 ctx ; + quantifier_example1 ctx ; + fpa_example ctx ; Printf.printf "Disposing...\n"; Gc.full_major () ); diff --git a/scripts/update_api.py b/scripts/update_api.py index 79b34c315..889044d1f 100644 --- a/scripts/update_api.py +++ b/scripts/update_api.py @@ -159,7 +159,7 @@ Type2JavaW = { VOID : 'void', VOID_PTR : 'jlong', INT : 'jint', UINT : 'jint', I # Mapping to ML types Type2ML = { VOID : 'unit', VOID_PTR : 'VOIDP', INT : 'int', UINT : 'int', INT64 : 'int', UINT64 : 'int', DOUBLE : 'float', - STRING : 'string', STRING_PTR : 'char**', + FLOAT : 'float', STRING : 'string', STRING_PTR : 'char**', BOOL : 'bool', SYMBOL : 'z3_symbol', PRINT_MODE : 'int', ERROR_CODE : 'int' } next_type_id = FIRST_OBJ_ID diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 350457525..601da1cbc 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -362,7 +362,9 @@ struct | REAL_SORT | UNINTERPRETED_SORT | FINITE_DOMAIN_SORT - | RELATION_SORT -> Sort(q) + | RELATION_SORT + | FLOATING_POINT_SORT + | ROUNDING_MODE_SORT -> Sort(q) | UNKNOWN_SORT -> raise (Z3native.Exception "Unknown sort kind encountered") let ast_of_sort s = match s with Sort(x) -> x @@ -745,7 +747,8 @@ end = struct Expr(z3_native_object_of_ast_ptr ctx no) else if (Z3native.is_numeral_ast (context_gno ctx) no) then - if (sk == INT_SORT || sk == REAL_SORT || sk == BV_SORT) then + if (sk == INT_SORT || sk == REAL_SORT || sk == BV_SORT || + sk == FLOATING_POINT_SORT || sk == ROUNDING_MODE_SORT) then Expr(z3_native_object_of_ast_ptr ctx no) else raise (Z3native.Exception "Unsupported numeral object") @@ -1507,7 +1510,7 @@ struct (Big_int.big_int_of_string s) else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + let numeral_to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_const ( ctx : context ) ( name : Symbol.symbol ) = Expr.mk_const ctx name (mk_sort ctx) @@ -1554,7 +1557,7 @@ struct let to_decimal_string ( x : expr ) ( precision : int ) = Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + let numeral_to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_const ( ctx : context ) ( name : Symbol.symbol ) = Expr.mk_const ctx name (mk_sort ctx) @@ -1562,7 +1565,7 @@ struct let mk_const_s ( ctx : context ) ( name : string ) = mk_const ctx (Symbol.mk_string ctx name) - let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int) = + let mk_numeral_nd ( ctx : context ) ( num : int ) ( den : int ) = if (den == 0) then raise (Z3native.Exception "Denominator is zero") else @@ -1591,7 +1594,7 @@ struct let to_decimal_string ( x : expr ) ( precision : int ) = Z3native.get_numeral_decimal_string (Expr.gnc x) (Expr.gno x) precision - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + let numeral_to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) end end @@ -1692,7 +1695,7 @@ struct let (r, v) = Z3native.get_numeral_int (Expr.gnc x) (Expr.gno x) in if r then v else raise (Z3native.Exception "Conversion failed.") - let to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + let numeral_to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( size : int ) = Expr.mk_const ctx name (mk_sort ctx size) let mk_const_s ( ctx : context ) ( name : string ) ( size : int ) = @@ -1791,11 +1794,202 @@ struct (expr_of_ptr ctx (Z3native.mk_bvmul_no_overflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2) signed)) let mk_mul_no_underflow ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = (expr_of_ptr ctx (Z3native.mk_bvmul_no_underflow (context_gno ctx) (Expr.gno t1) (Expr.gno t2))) - let mk_numeral ( ctx : context ) ( v : string ) ( size : int) = + let mk_numeral ( ctx : context ) ( v : string ) ( size : int ) = expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno (mk_sort ctx size))) end +module FloatingPoint = +struct + module RoundingMode = + struct + let mk_sort ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_rounding_mode_sort (context_gno ctx))) + let is_fprm ( x : expr ) = + (Sort.get_sort_kind (Expr.get_sort(x))) == ROUNDING_MODE_SORT + let mk_round_nearest_ties_to_even ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_round_nearest_ties_to_even (context_gno ctx))) + let mk_rne ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_rne (context_gno ctx))) + let mk_round_nearest_ties_to_away ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_round_nearest_ties_to_away (context_gno ctx))) + let mk_rna ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_rna (context_gno ctx))) + let mk_round_toward_positive ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_round_toward_positive (context_gno ctx))) + let mk_rtp ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_rtp (context_gno ctx))) + let mk_round_toward_negative ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_round_toward_negative (context_gno ctx))) + let mk_rtn ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_rtn (context_gno ctx))) + let mk_round_toward_zero ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_round_toward_zero (context_gno ctx))) + let mk_rtz ( ctx : context ) = + (expr_of_ptr ctx (Z3native.mk_fpa_rtz (context_gno ctx))) + end + + let mk_sort ( ctx : context ) ( ebits : int ) ( sbits : int ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort (context_gno ctx) ebits sbits)) + let mk_sort_half ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort_half (context_gno ctx))) + let mk_sort_16 ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort_16 (context_gno ctx))) + let mk_sort_single ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort_single (context_gno ctx))) + let mk_sort_32 ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort_32 (context_gno ctx))) + let mk_sort_double ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort_double (context_gno ctx))) + let mk_sort_64 ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort_64 (context_gno ctx))) + let mk_sort_quadruple ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort_quadruple (context_gno ctx))) + let mk_sort_128 ( ctx : context ) = + (sort_of_ptr ctx (Z3native.mk_fpa_sort_128 (context_gno ctx))) + let mk_nan ( ctx : context ) ( s : sort ) = + (expr_of_ptr ctx (Z3native.mk_fpa_nan (context_gno ctx) (Sort.gno s))) + let mk_inf ( ctx : context ) ( s : sort ) ( negative : bool ) = + (expr_of_ptr ctx (Z3native.mk_fpa_inf (context_gno ctx) (Sort.gno s) negative)) + let mk_zero ( ctx : context ) ( s : sort ) ( negative : bool ) = + (expr_of_ptr ctx (Z3native.mk_fpa_zero (context_gno ctx) (Sort.gno s) negative)) + + let mk_fp ( ctx : context ) ( sign : expr ) ( exponent : expr ) ( significand : expr ) = + (expr_of_ptr ctx (Z3native.mk_fpa_fp (context_gno ctx) (Expr.gno sign) (Expr.gno exponent) (Expr.gno significand))) + let mk_numeral_f ( ctx : context ) ( value : float ) ( s : sort ) = + (expr_of_ptr ctx (Z3native.mk_fpa_numeral_double (context_gno ctx) value (Sort.gno s))) + let mk_numeral_i ( ctx : context ) ( value : int ) ( s : sort ) = + (expr_of_ptr ctx (Z3native.mk_fpa_numeral_int (context_gno ctx) value (Sort.gno s))) + let mk_numeral_i_u ( ctx : context ) ( sign : bool ) ( exponent : int ) ( significand : int ) ( s : sort ) = + (expr_of_ptr ctx (Z3native.mk_fpa_numeral_int64_uint64 (context_gno ctx) sign exponent significand (Sort.gno s))) + let mk_numeral_s ( ctx : context ) ( v : string ) ( s : sort ) = + (expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno s))) + + let is_fp ( x : expr ) = (Sort.get_sort_kind (Expr.get_sort x)) == FLOATING_POINT_SORT + let is_abs ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_ABS) + let is_neg ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_NEG) + let is_add ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_ADD) + let is_sub ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_SUB) + let is_mul ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_MUL) + let is_div ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_DIV) + let is_fma ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_FMA) + let is_sqrt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_SQRT) + let is_rem ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_REM) + let is_round_to_integral ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_ROUND_TO_INTEGRAL) + let is_min ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_MIN) + let is_max ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_MAX) + let is_leq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_LE) + let is_lt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_LT) + let is_geq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_GE) + let is_gt ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_GT) + let is_eq ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_EQ) + let is_is_normal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_IS_NORMAL) + let is_is_subnormal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_IS_SUBNORMAL) + let is_is_zero ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_IS_ZERO) + let is_is_infinite ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_IS_INF) + let is_is_nan ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_IS_NAN) + let is_is_negative ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_IS_NEGATIVE) + let is_is_positive ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_IS_POSITIVE) + let is_to_fp ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_TO_FP) + let is_to_fp_unsigned ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_TO_FP_UNSIGNED) + let is_to_ubv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_TO_UBV) + let is_to_sbv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_TO_SBV) + let is_to_real ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_TO_REAL) + let is_to_ieee_bv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_FPA_TO_IEEE_BV) + + let numeral_to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) + let mk_const ( ctx : context ) ( name : Symbol.symbol ) ( s : sort ) = + Expr.mk_const ctx name s + let mk_const_s ( ctx : context ) ( name : string ) ( s : sort ) = + mk_const ctx (Symbol.mk_string ctx name) s + + let mk_abs ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_abs (context_gno ctx) (Expr.gno t)) + let mk_neg ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_neg (context_gno ctx) (Expr.gno t)) + let mk_add ( ctx : context ) ( rm : expr ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_add (context_gno ctx) (Expr.gno rm) (Expr.gno t1) (Expr.gno t2)) + let mk_sub ( ctx : context ) ( rm : expr ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_sub (context_gno ctx) (Expr.gno rm) (Expr.gno t1) (Expr.gno t2)) + let mk_mul ( ctx : context ) ( rm : expr ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_mul (context_gno ctx) (Expr.gno rm) (Expr.gno t1) (Expr.gno t2)) + let mk_div ( ctx : context ) ( rm : expr ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_div (context_gno ctx) (Expr.gno rm) (Expr.gno t1) (Expr.gno t2)) + let mk_fma ( ctx : context ) ( rm : expr ) ( t1 : expr ) ( t2 : expr ) ( t3 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_fma (context_gno ctx) (Expr.gno rm) (Expr.gno t1) (Expr.gno t2) (Expr.gno t3)) + let mk_sqrt ( ctx : context ) ( rm : expr ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_sqrt (context_gno ctx) (Expr.gno rm) (Expr.gno t)) + let mk_rem ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_rem (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_round_to_integral ( ctx : context ) ( rm : expr ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_round_to_integral (context_gno ctx) (Expr.gno rm) (Expr.gno t)) + let mk_min ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_min (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_max ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_max (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_leq ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_leq (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_lt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_lt (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_geq ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_geq (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_gt ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_gt (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_eq ( ctx : context ) ( t1 : expr ) ( t2 : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_eq (context_gno ctx) (Expr.gno t1) (Expr.gno t2)) + let mk_is_normal ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_is_normal (context_gno ctx) (Expr.gno t)) + let mk_is_subnormal ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_is_subnormal (context_gno ctx) (Expr.gno t)) + let mk_is_zero ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_is_zero (context_gno ctx) (Expr.gno t)) + let mk_is_infinite ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_is_infinite (context_gno ctx) (Expr.gno t)) + let mk_is_nan ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_is_nan (context_gno ctx) (Expr.gno t)) + let mk_is_negative ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_is_negative (context_gno ctx) (Expr.gno t)) + let mk_is_positive ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_is_positive (context_gno ctx) (Expr.gno t)) + let mk_to_fp_bv ( ctx : context ) ( t : expr ) ( s : sort ) = + expr_of_ptr ctx (Z3native.mk_fpa_to_fp_bv (context_gno ctx) (Expr.gno t) (Sort.gno s)) + let mk_to_fp_float ( ctx : context ) ( rm : expr) ( t : expr ) ( s : sort ) = + expr_of_ptr ctx (Z3native.mk_fpa_to_fp_float (context_gno ctx) (Expr.gno rm) (Expr.gno t) (Sort.gno s)) + let mk_to_fp_real ( ctx : context ) ( rm : expr ) ( t : expr ) ( s : sort ) = + expr_of_ptr ctx (Z3native.mk_fpa_to_fp_real (context_gno ctx) (Expr.gno rm) (Expr.gno t) (Sort.gno s)) + let mk_to_fp_signed ( ctx : context ) ( rm : expr) ( t : expr ) ( s : sort ) = + expr_of_ptr ctx (Z3native.mk_fpa_to_fp_signed (context_gno ctx) (Expr.gno rm) (Expr.gno t) (Sort.gno s)) + let mk_to_fp_unsigned ( ctx : context ) ( rm : expr) ( t : expr ) ( s : sort ) = + expr_of_ptr ctx (Z3native.mk_fpa_to_fp_unsigned (context_gno ctx) (Expr.gno rm) (Expr.gno t) (Sort.gno s)) + let mk_to_fp_ubv ( ctx : context ) ( rm : expr) ( t : expr ) ( size : int ) = + expr_of_ptr ctx (Z3native.mk_fpa_to_ubv (context_gno ctx) (Expr.gno rm) (Expr.gno t) size) + let mk_to_fp_sbv ( ctx : context ) ( rm : expr) ( t : expr ) ( size : int ) = + expr_of_ptr ctx (Z3native.mk_fpa_to_sbv (context_gno ctx) (Expr.gno rm) (Expr.gno t) size) + let mk_to_fp_real ( ctx : context ) ( t : expr ) = + expr_of_ptr ctx (Z3native.mk_fpa_to_real (context_gno ctx) (Expr.gno t)) + + let get_ebits ( ctx : context ) ( s : sort ) = + (Z3native.fpa_get_ebits (context_gno ctx) (Sort.gno s)) + let get_sbits ( ctx : context ) ( s : sort ) = + (Z3native.fpa_get_sbits (context_gno ctx) (Sort.gno s)) + let get_numeral_sign ( ctx : context ) ( t : expr ) = + (Z3native.fpa_get_numeral_sign (context_gno ctx) (Expr.gno t)) + let get_numeral_significand_string ( ctx : context ) ( t : expr ) = + (Z3native.fpa_get_numeral_significand_string (context_gno ctx) (Expr.gno t)) + let get_numeral_exponent_string ( ctx : context ) ( t : expr ) = + (Z3native.fpa_get_numeral_exponent_string (context_gno ctx) (Expr.gno t)) + let get_numeral_exponent_int ( ctx : context ) ( t : expr ) = + (Z3native.fpa_get_numeral_exponent_int64 (context_gno ctx) (Expr.gno t)) + + let mk_to_ieee_bv ( ctx : context ) ( t : expr ) = + (expr_of_ptr ctx (Z3native.mk_fpa_to_ieee_bv (context_gno ctx) (Expr.gno t))) + let mk_to_fp_real_int ( ctx : context ) ( rm : expr ) ( exponent : expr ) ( significand : expr ) ( s : sort) = + (expr_of_ptr ctx (Z3native.mk_fpa_to_fp_real_int (context_gno ctx) (Expr.gno rm) (Expr.gno exponent) (Expr.gno significand) (Sort.gno s))) + + let numeral_to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) +end + + module Proof = struct let is_true ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_PR_TRUE) diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index b2f0939d0..ab2a14725 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -1157,8 +1157,8 @@ sig (** Get a big_int from an integer numeral *) val get_big_int : Expr.expr -> Big_int.big_int - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr -> string + (** Returns a string representation of a numeral. *) + val numeral_to_string : Expr.expr -> string (** Creates an integer constant. *) val mk_const : context -> Symbol.symbol -> Expr.expr @@ -1221,8 +1221,8 @@ sig The result has at most as many decimal places as indicated by the int argument.*) val to_decimal_string : Expr.expr-> int -> string - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr-> string + (** Returns a string representation of a numeral. *) + val numeral_to_string : Expr.expr-> string (** Creates a real constant. *) val mk_const : context -> Symbol.symbol -> Expr.expr @@ -1271,8 +1271,8 @@ sig The result has at most as many decimal places as the int argument provided.*) val to_decimal_string : Expr.expr -> int -> string - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr -> string + (** Returns a string representation of a numeral. *) + val numeral_to_string : Expr.expr -> string end end @@ -1551,8 +1551,8 @@ sig (** Retrieve the int value. *) val get_int : Expr.expr -> int - (** Returns a string representation of the numeral. *) - val to_string : Expr.expr -> string + (** Returns a string representation of a numeral. *) + val numeral_to_string : Expr.expr -> string (** Creates a bit-vector constant. *) val mk_const : context -> Symbol.symbol -> int -> Expr.expr @@ -1830,6 +1830,342 @@ sig val mk_numeral : context -> string -> int -> Expr.expr end +(** Floating-Point Arithmetic *) +module FloatingPoint : + sig + + (** Rounding Modes *) + module RoundingMode : + sig + (** Create the RoundingMode sort. *) + val mk_sort : context -> Sort.sort + + (** Indicates whether the terms is of floating-point rounding mode sort. *) + val is_fprm : Expr.expr -> bool + + (** Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode. *) + val mk_round_nearest_ties_to_even : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode. *) + val mk_rne : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode. *) + val mk_round_nearest_ties_to_away : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode. *) + val mk_rna : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode. *) + val mk_round_toward_positive : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode. *) + val mk_rtp : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode. *) + val mk_round_toward_negative : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode. *) + val mk_rtn : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the TowardZero rounding mode. *) + val mk_round_toward_zero : context -> Expr.expr + + (** Create a numeral of RoundingMode sort which represents the TowardZero rounding mode. *) + val mk_rtz : context -> Expr.expr + end + + (** Create a FloatingPoint sort. *) + val mk_sort : context -> int -> int -> Sort.sort + + (** Create the half-precision (16-bit) FloatingPoint sort.*) + val mk_sort_half : context -> Sort.sort + + (** Create the half-precision (16-bit) FloatingPoint sort. *) + val mk_sort_16 : context -> Sort.sort + + (** Create the single-precision (32-bit) FloatingPoint sort.*) + val mk_sort_single : context -> Sort.sort + + (** Create the single-precision (32-bit) FloatingPoint sort. *) + val mk_sort_32 : context -> Sort.sort + + (** Create the double-precision (64-bit) FloatingPoint sort. *) + val mk_sort_double : context -> Sort.sort + + (** Create the double-precision (64-bit) FloatingPoint sort. *) + val mk_sort_64 : context -> Sort.sort + + (** Create the quadruple-precision (128-bit) FloatingPoint sort. *) + val mk_sort_quadruple : context -> Sort.sort + + (** Create the quadruple-precision (128-bit) FloatingPoint sort. *) + val mk_sort_128 : context -> Sort.sort + + (** Create a floating-point NaN of a given FloatingPoint sort. *) + val mk_nan : context -> Sort.sort -> Expr.expr + + (** Create a floating-point infinity of a given FloatingPoint sort. *) + val mk_inf : context -> Sort.sort -> bool -> Expr.expr + + (** Create a floating-point zero of a given FloatingPoint sort. *) + val mk_zero : context -> Sort.sort -> bool -> Expr.expr + + (** Create an expression of FloatingPoint sort from three bit-vector expressions. + + This is the operator named `fp' in the SMT FP theory definition. + Note that \c sign is required to be a bit-vector of size 1. Significand and exponent + are required to be greater than 1 and 2 respectively. The FloatingPoint sort + of the resulting expression is automatically determined from the bit-vector sizes + of the arguments. *) + val mk_fp : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create a numeral of FloatingPoint sort from a float. + + This function is used to create numerals that fit in a float value. + It is slightly faster than #Z3_mk_numeral since it is not necessary to parse a string. *) + val mk_numeral_f : context -> float -> Sort.sort -> Expr.expr + + (** Create a numeral of FloatingPoint sort from a signed integer. *) + val mk_numeral_i : context -> int -> Sort.sort -> Expr.expr + + (** Create a numeral of FloatingPoint sort from a sign bit and two integers. *) + val mk_numeral_i_u : context -> bool -> int -> int -> Sort.sort -> Expr.expr + + (** Create a numeral of FloatingPoint sort from a string *) + val mk_numeral_s : context -> string -> Sort.sort -> Expr.expr + + (** Indicates whether the terms is of floating-point sort. *) + val is_fp : Expr.expr -> bool + + + (** Indicates whether an expression is a floating-point abs expression *) + val is_abs : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point neg expression *) + val is_neg : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point add expression *) + val is_add : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point sub expression *) + val is_sub : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point mul expression *) + val is_mul : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point div expression *) + val is_div : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point fma expression *) + val is_fma : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point sqrt expression *) + val is_sqrt : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point rem expression *) + val is_rem : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point round_to_integral expression *) + val is_round_to_integral : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point min expression *) + val is_min : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point max expression *) + val is_max : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point leq expression *) + val is_leq : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point lt expression *) + val is_lt : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point geqexpression *) + val is_geq : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point gt expression *) + val is_gt : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point eq expression *) + val is_eq : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_normal expression *) + val is_is_normal : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_subnormal expression *) + val is_is_subnormal : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_zero expression *) + val is_is_zero : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_infinite expression *) + val is_is_infinite : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_nan expression *) + val is_is_nan : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_negative expression *) + val is_is_negative : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_positive expression *) + val is_is_positive : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_fp expression *) + val is_to_fp : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_fp_unsigned expression *) + val is_to_fp_unsigned : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_ubv expression *) + val is_to_ubv : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_sbv expression *) + val is_to_sbv : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_real expression *) + val is_to_real : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_ieee_bv expression *) + val is_to_ieee_bv : Expr.expr -> bool + + + (** Returns a string representation of a numeral. *) + val numeral_to_string : Expr.expr -> string + + (** Creates a floating-point constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> Expr.expr + + (** Creates a floating-point constant. *) + val mk_const_s : context -> string -> Sort.sort -> Expr.expr + + (** Floating-point absolute value *) + val mk_abs : context -> Expr.expr -> Expr.expr + + (** Floating-point negation *) + val mk_neg : context -> Expr.expr -> Expr.expr + + (** Floating-point addition *) + val mk_add : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point subtraction *) + val mk_sub : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point multiplication *) + val mk_mul : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point division *) + val mk_div : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point fused multiply-add. *) + val mk_fma : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point square root *) + val mk_sqrt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point remainder *) + val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point roundToIntegral. + + Rounds a floating-point number to the closest integer, + again represented as a floating-point number. *) + val mk_round_to_integral : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Minimum of floating-point numbers. *) + val mk_min : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Maximum of floating-point numbers. *) + val mk_max : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point less than or equal. *) + val mk_leq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point less than. *) + val mk_lt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point greater than or equal. *) + val mk_geq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point greater than. *) + val mk_gt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point equality. *) + val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a normal floating-point number. *) + val mk_is_normal : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a subnormal floating-point number. *) + val mk_is_subnormal : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a floating-point number with zero value, i.e., +zero or -zero. *) + val mk_is_zero : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a floating-point number representing +oo or -oo. *) + val mk_is_infinite : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a NaN. *) + val mk_is_nan : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a negative floating-point number. *) + val mk_is_negative : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a positive floating-point number. *) + val mk_is_positive : context -> Expr.expr -> Expr.expr + + (** Conversion of a single IEEE 754-2008 bit-vector into a floating-point number. *) + val mk_to_fp_bv : context -> Expr.expr -> Sort.sort -> Expr.expr + + (** Conversion of a FloatingPoint term into another term of different FloatingPoint sort. *) + val mk_to_fp_float : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** Conversion of a term of real sort into a term of FloatingPoint sort. *) + val mk_to_fp_real : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort. *) + val mk_to_fp_signed : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort. *) + val mk_to_fp_unsigned : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** C1onversion of a floating-point term into an unsigned bit-vector. *) + val mk_to_fp_ubv : context -> Expr.expr -> Expr.expr -> int -> Expr.expr + + (** Conversion of a floating-point term into a signed bit-vector. *) + val mk_to_fp_sbv : context -> Expr.expr -> Expr.expr -> int -> Expr.expr + + (** Conversion of a floating-point term into a real-numbered term. *) + val mk_to_fp_real : context -> Expr.expr -> Expr.expr + + (** Retrieves the number of bits reserved for the exponent in a FloatingPoint sort. *) + val get_ebits : context -> Sort.sort -> int + + (** Retrieves the number of bits reserved for the significand in a FloatingPoint sort. *) + val get_sbits : context -> Sort.sort -> int + + (** Retrieves the sign of a floating-point literal. *) + val get_numeral_sign : context -> Expr.expr -> bool * int + + (** Return the significand value of a floating-point numeral as a string. *) + val get_numeral_significand_string : context -> Expr.expr -> string + + (** Return the exponent value of a floating-point numeral as a string *) + val get_numeral_exponent_string : context -> Expr.expr -> string + + (** Return the exponent value of a floating-point numeral as a signed integer *) + val get_numeral_exponent_int : context -> Expr.expr -> bool * int + + (** Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format. *) + val mk_to_ieee_bv : context -> Expr.expr -> Expr.expr + + (** Conversion of a real-sorted significand and an integer-sorted exponent into a term of FloatingPoint sort. *) + val mk_to_fp_real_int : context -> Expr.expr -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** The string representation of a numeral *) + val numeral_to_string : Expr.expr -> string + end + + (** Functions to manipulate proof expressions *) module Proof : sig From 5c7d0380d3c2d5fba59d0da2f62f870feaf279cc Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 24 Jan 2015 18:29:52 +0000 Subject: [PATCH 245/248] Fixes in the OCaml FPA API and example --- examples/ml/ml_example.ml | 93 ++--- scripts/mk_util.py | 2 +- src/api/ml/z3.ml | 25 +- src/api/ml/z3.mli | 754 +++++++++++++++++++------------------- 4 files changed, 436 insertions(+), 438 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 8a2d71d82..127a973aa 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -247,6 +247,8 @@ open Z3.FloatingPoint **) let fpa_example ( ctx : context ) = Printf.printf "FPAExample\n" ; + (* let str = ref "" in *) + (* (read_line ()) ; *) let double_sort = (FloatingPoint.mk_sort_double ctx) in let rm_sort = (FloatingPoint.RoundingMode.mk_sort ctx) in @@ -257,63 +259,64 @@ let fpa_example ( ctx : context ) = let s_y = (mk_string ctx "y") in let x = (mk_const ctx s_x double_sort) in let y = (mk_const ctx s_y double_sort)in - Printf.printf "A\n" ; - let n = (mk_numeral_f ctx 42.0 double_sort) in - Printf.printf "B\n" ; + let n = (FloatingPoint.mk_numeral_f ctx 42.0 double_sort) in let s_x_plus_y = (mk_string ctx "x_plus_y") in let x_plus_y = (mk_const ctx s_x_plus_y double_sort) in let c1 = (mk_eq ctx x_plus_y (mk_add ctx rm x y)) in let args = [ c1 ; (mk_eq ctx x_plus_y n) ] in let c2 = (Boolean.mk_and ctx args) in - let args2 = [ c2 ; (Boolean.mk_not ctx (mk_eq ctx rm (RoundingMode.mk_rtz ctx))) ] in + let args2 = [ c2 ; (Boolean.mk_not ctx (Boolean.mk_eq ctx rm (RoundingMode.mk_rtz ctx))) ] in let c3 = (Boolean.mk_and ctx args2) in let and_args = [ (Boolean.mk_not ctx (mk_is_zero ctx y)) ; (Boolean.mk_not ctx (mk_is_nan ctx y)) ; (Boolean.mk_not ctx (mk_is_infinite ctx y)) ] in let args3 = [ c3 ; (Boolean.mk_and ctx and_args) ] in - let c4 = (Boolean.mk_and ctx args3) in - - (Printf.printf "c4: %s\n" (Expr.to_string c4)) - (* push(ctx); *) - (* Z3_assert_cnstr(ctx, c4); *) - (* check(ctx, Z3_L_TRUE); *) - (* Z3_pop(ctx, 1); *) + let c4 = (Boolean.mk_and ctx args3) in + (Printf.printf "c4: %s\n" (Expr.to_string c4)) ; + ( + let solver = (mk_solver ctx None) in + (Solver.add solver [ c4 ]) ; + if (check solver []) != SATISFIABLE then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ); - (* // Show that the following are equal: *) - (* // (fp #b0 #b10000000001 #xc000000000000) *) - (* // ((_ to_fp 11 53) #x401c000000000000)) *) - (* // ((_ to_fp 11 53) RTZ 1.75 2))) *) - (* // ((_ to_fp 11 53) RTZ 7.0))) *) +(* Show that the following are equal: *) +(* (fp #b0 #b10000000001 #xc000000000000) *) +(* ((_ to_fp 11 53) #x401c000000000000)) *) +(* ((_ to_fp 11 53) RTZ 1.75 2))) *) +(* ((_ to_fp 11 53) RTZ 7.0))) *) - (* Z3_push(ctx); *) - (* c1 = Z3_mk_fpa_fp(ctx, *) - (* Z3_mk_numeral(ctx, "0", Z3_mk_bv_sort(ctx, 1)), *) - (* Z3_mk_numeral(ctx, "3377699720527872", Z3_mk_bv_sort(ctx, 52)), *) - (* Z3_mk_numeral(ctx, "1025", Z3_mk_bv_sort(ctx, 11))); *) - (* c2 = Z3_mk_fpa_to_fp_bv(ctx, *) - (* Z3_mk_numeral(ctx, "4619567317775286272", Z3_mk_bv_sort(ctx, 64)), *) - (* Z3_mk_fpa_sort(ctx, 11, 53)); *) - (* c3 = Z3_mk_fpa_to_fp_real_int(ctx, *) - (* Z3_mk_fpa_rtz(ctx), *) - (* Z3_mk_numeral(ctx, "1.75", Z3_mk_real_sort(ctx)), *) - (* Z3_mk_numeral(ctx, "2", Z3_mk_int_sort(ctx)), *) - (* Z3_mk_fpa_sort(ctx, 11, 53)); *) - (* c4 = Z3_mk_fpa_to_fp_real(ctx, *) - (* Z3_mk_fpa_rtz(ctx), *) - (* Z3_mk_numeral(ctx, "7.0", Z3_mk_real_sort(ctx)), *) - (* Z3_mk_fpa_sort(ctx, 11, 53)); *) - (* args3[0] = Z3_mk_eq(ctx, c1, c2); *) - (* args3[1] = Z3_mk_eq(ctx, c1, c3); *) - (* args3[2] = Z3_mk_eq(ctx, c1, c4); *) - (* c5 = Z3_mk_and(ctx, 3, args3); *) - - (* printf("c5: %s\n", Z3_ast_to_string(ctx, c5)); *) - (* Z3_assert_cnstr(ctx, c5); *) - (* check(ctx, Z3_L_TRUE); *) - (* Z3_pop(ctx, 1); *) - - (* Z3_del_context(ctx); *) - + let solver = (mk_solver ctx None) in + let c1 = (mk_fp ctx + (mk_numeral_string ctx "0" (BitVector.mk_sort ctx 1)) + (mk_numeral_string ctx "3377699720527872" (BitVector.mk_sort ctx 52)) + (mk_numeral_string ctx "1025" (BitVector.mk_sort ctx 11))) in + let c2 = (mk_to_fp_bv ctx + (mk_numeral_string ctx "4619567317775286272" (BitVector.mk_sort ctx 64)) + (mk_sort ctx 11 53)) in + let c3 = (mk_to_fp_int_real ctx + (RoundingMode.mk_rtz ctx) + (mk_numeral_string ctx "2" (Integer.mk_sort ctx)) + (mk_numeral_string ctx "1.75" (Real.mk_sort ctx)) + (FloatingPoint.mk_sort ctx 11 53)) in + let c4 = (mk_to_fp_real ctx (RoundingMode.mk_rtz ctx) + (mk_numeral_string ctx "7.0" (Real.mk_sort ctx)) + (FloatingPoint.mk_sort ctx 11 53)) in + let args3 = [ (mk_eq ctx c1 c2) ; + (mk_eq ctx c1 c3) ; + (mk_eq ctx c1 c4) ] in + let c5 = (Boolean.mk_and ctx args3) in + (Printf.printf "c5: %s\n" (Expr.to_string c5)) ; + ( + let solver = (mk_solver ctx None) in + (Solver.add solver [ c5 ]) ; + if (check solver []) != SATISFIABLE then + raise (TestFailedException "") + else + Printf.printf "Test passed.\n" + ) let _ = try ( diff --git a/scripts/mk_util.py b/scripts/mk_util.py index af0c59355..2ed420c20 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -546,7 +546,7 @@ def parse_options(): 'b:df:sxhmcvtnp:gj', ['build=', 'debug', 'silent', 'x64', 'help', 'makefiles', 'showcpp', 'vsproj', 'trace', 'nodotnet', 'staticlib', 'prefix=', 'gmp', 'foci2=', 'java', 'parallel=', 'gprof', - 'githash=', 'x86']) + 'githash=', 'x86', 'ml']) except: print("ERROR: Invalid command line option") display_help(1) diff --git a/src/api/ml/z3.ml b/src/api/ml/z3.ml index 601da1cbc..fe78b65a6 100644 --- a/src/api/ml/z3.ml +++ b/src/api/ml/z3.ml @@ -1479,9 +1479,9 @@ struct let is_modulus ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_MOD) - let is_inttoreal ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) + let is_int2real ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_REAL) - let is_real_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) + let is_real2int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_TO_INT) let is_real_is_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_IS_INT) @@ -1686,8 +1686,8 @@ struct let is_bv_rotateright ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_ROTATE_RIGHT) let is_bv_rotateleftextended ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_LEFT) let is_bv_rotaterightextended ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_EXT_ROTATE_RIGHT) - let is_int_to_bv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) - let is_bv_to_int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) + let is_int2bv ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_INT2BV) + let is_bv2int ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_BV2INT) let is_bv_carry ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_CARRY) let is_bv_xor3 ( x : expr ) = (AST.is_app (Expr.ast_of_expr x)) && (FuncDecl.get_decl_kind (Expr.get_func_decl x) == OP_XOR3) let get_size (x : sort ) = Z3native.get_bv_sort_size (Sort.gnc x) (Sort.gno x) @@ -1847,6 +1847,7 @@ struct (sort_of_ptr ctx (Z3native.mk_fpa_sort_quadruple (context_gno ctx))) let mk_sort_128 ( ctx : context ) = (sort_of_ptr ctx (Z3native.mk_fpa_sort_128 (context_gno ctx))) + let mk_nan ( ctx : context ) ( s : sort ) = (expr_of_ptr ctx (Z3native.mk_fpa_nan (context_gno ctx) (Sort.gno s))) let mk_inf ( ctx : context ) ( s : sort ) ( negative : bool ) = @@ -1857,11 +1858,11 @@ struct let mk_fp ( ctx : context ) ( sign : expr ) ( exponent : expr ) ( significand : expr ) = (expr_of_ptr ctx (Z3native.mk_fpa_fp (context_gno ctx) (Expr.gno sign) (Expr.gno exponent) (Expr.gno significand))) let mk_numeral_f ( ctx : context ) ( value : float ) ( s : sort ) = - (expr_of_ptr ctx (Z3native.mk_fpa_numeral_double (context_gno ctx) value (Sort.gno s))) + (expr_of_ptr ctx (Z3native.mk_fpa_numeral_double (context_gno ctx) value (Sort.gno s))) let mk_numeral_i ( ctx : context ) ( value : int ) ( s : sort ) = - (expr_of_ptr ctx (Z3native.mk_fpa_numeral_int (context_gno ctx) value (Sort.gno s))) + (expr_of_ptr ctx (Z3native.mk_fpa_numeral_int (context_gno ctx) value (Sort.gno s))) let mk_numeral_i_u ( ctx : context ) ( sign : bool ) ( exponent : int ) ( significand : int ) ( s : sort ) = - (expr_of_ptr ctx (Z3native.mk_fpa_numeral_int64_uint64 (context_gno ctx) sign exponent significand (Sort.gno s))) + (expr_of_ptr ctx (Z3native.mk_fpa_numeral_int64_uint64 (context_gno ctx) sign exponent significand (Sort.gno s))) let mk_numeral_s ( ctx : context ) ( v : string ) ( s : sort ) = (expr_of_ptr ctx (Z3native.mk_numeral (context_gno ctx) v (Sort.gno s))) @@ -1961,11 +1962,11 @@ struct expr_of_ptr ctx (Z3native.mk_fpa_to_fp_signed (context_gno ctx) (Expr.gno rm) (Expr.gno t) (Sort.gno s)) let mk_to_fp_unsigned ( ctx : context ) ( rm : expr) ( t : expr ) ( s : sort ) = expr_of_ptr ctx (Z3native.mk_fpa_to_fp_unsigned (context_gno ctx) (Expr.gno rm) (Expr.gno t) (Sort.gno s)) - let mk_to_fp_ubv ( ctx : context ) ( rm : expr) ( t : expr ) ( size : int ) = + let mk_to_ubv ( ctx : context ) ( rm : expr) ( t : expr ) ( size : int ) = expr_of_ptr ctx (Z3native.mk_fpa_to_ubv (context_gno ctx) (Expr.gno rm) (Expr.gno t) size) - let mk_to_fp_sbv ( ctx : context ) ( rm : expr) ( t : expr ) ( size : int ) = + let mk_to_sbv ( ctx : context ) ( rm : expr) ( t : expr ) ( size : int ) = expr_of_ptr ctx (Z3native.mk_fpa_to_sbv (context_gno ctx) (Expr.gno rm) (Expr.gno t) size) - let mk_to_fp_real ( ctx : context ) ( t : expr ) = + let mk_to_real ( ctx : context ) ( t : expr ) = expr_of_ptr ctx (Z3native.mk_fpa_to_real (context_gno ctx) (Expr.gno t)) let get_ebits ( ctx : context ) ( s : sort ) = @@ -1983,8 +1984,8 @@ struct let mk_to_ieee_bv ( ctx : context ) ( t : expr ) = (expr_of_ptr ctx (Z3native.mk_fpa_to_ieee_bv (context_gno ctx) (Expr.gno t))) - let mk_to_fp_real_int ( ctx : context ) ( rm : expr ) ( exponent : expr ) ( significand : expr ) ( s : sort) = - (expr_of_ptr ctx (Z3native.mk_fpa_to_fp_real_int (context_gno ctx) (Expr.gno rm) (Expr.gno exponent) (Expr.gno significand) (Sort.gno s))) + let mk_to_fp_int_real ( ctx : context ) ( rm : expr ) ( exponent : expr ) ( significand : expr ) ( s : sort ) = + (expr_of_ptr ctx (Z3native.mk_fpa_to_fp_int_real (context_gno ctx) (Expr.gno rm) (Expr.gno exponent) (Expr.gno significand) (Sort.gno s))) let numeral_to_string ( x : expr ) = Z3native.get_numeral_string (Expr.gnc x) (Expr.gno x) end diff --git a/src/api/ml/z3.mli b/src/api/ml/z3.mli index ab2a14725..aa526417e 100644 --- a/src/api/ml/z3.mli +++ b/src/api/ml/z3.mli @@ -139,7 +139,7 @@ sig val get_size : ast_vector -> int (** Retrieves the i-th object in the vector. - @return An AST *) + @return An AST *) val get : ast_vector -> int -> ast (** Sets the i-th object in the vector. *) @@ -149,11 +149,11 @@ sig val resize : ast_vector -> int -> unit (** Add an ast to the back of the vector. The size - is increased by 1. *) + is increased by 1. *) val push : ast_vector -> ast -> unit (** Translates all ASTs in the vector to another context. - @return A new ASTVector *) + @return A new ASTVector *) val translate : ast_vector -> context -> ast_vector (** Retrieves a string representation of the vector. *) @@ -169,11 +169,11 @@ sig val mk_ast_map : context -> ast_map (** Checks whether the map contains a key. - @return True if the key in the map, false otherwise. *) + @return True if the key in the map, false otherwise. *) val contains : ast_map -> ast -> bool (** Finds the value associated with the key. - This function signs an error when the key is not a key in the map. *) + This function signs an error when the key is not a key in the map. *) val find : ast_map -> ast -> ast (** Stores or replaces a new key/value pair in the map. *) @@ -302,14 +302,14 @@ sig sig (** Parameters of func_decls *) type parameter = - P_Int of int + P_Int of int | P_Dbl of float | P_Sym of Symbol.symbol | P_Srt of Sort.sort | P_Ast of AST.ast | P_Fdl of func_decl | P_Rat of string - + (** The kind of the parameter. *) val get_kind : parameter -> Z3enums.parameter_kind @@ -723,7 +723,7 @@ sig (** The no-patterns. *) val get_no_patterns : quantifier -> Pattern.pattern list - (** The number of bound variables. *) + (** The number of bound variables. *) val get_num_bound : quantifier -> int (** The symbols for the bound variables. *) @@ -759,7 +759,7 @@ sig (** Create a Quantifier. *) val mk_quantifier : context -> bool -> Expr.expr list -> Expr.expr -> int option -> Pattern.pattern list -> Expr.expr list -> Symbol.symbol option -> Symbol.symbol option -> quantifier - (** A string representation of the quantifier. *) + (** A string representation of the quantifier. *) val to_string : quantifier -> string end @@ -1167,38 +1167,36 @@ sig val mk_const_s : context -> string -> Expr.expr (** Create an expression representing [t1 mod t2]. - The arguments must have int type. *) + The arguments must have int type. *) val mk_mod : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an expression representing [t1 rem t2]. - The arguments must have int type. *) + The arguments must have int type. *) val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr (** Create an integer numeral. *) val mk_numeral_s : context -> string -> Expr.expr (** Create an integer numeral. - @return A Term with the given value and sort Integer *) + @return A Term with the given value and sort Integer *) val mk_numeral_i : context -> int -> Expr.expr - (** 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. *) + (** 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. *) val mk_int2real : context -> Expr.expr -> Expr.expr - (** Create an n-bit bit-vector from an 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. *) + (** Create an n-bit bit-vector from an 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. *) val mk_int2bv : context -> int -> Expr.expr -> Expr.expr end @@ -1218,7 +1216,7 @@ sig val get_ratio : Expr.expr -> Ratio.ratio (** Returns a string representation in decimal notation. - The result has at most as many decimal places as indicated by the int argument.*) + The result has at most as many decimal places as indicated by the int argument.*) val to_decimal_string : Expr.expr-> int -> string (** Returns a string representation of a numeral. *) @@ -1231,16 +1229,16 @@ sig val mk_const_s : context -> string -> Expr.expr (** Create a real numeral from a fraction. - @return A Term with rational value and sort Real - {!mk_numeral_s} *) + @return A Term with rational value and sort Real + {!mk_numeral_s} *) val mk_numeral_nd : context -> int -> int -> Expr.expr (** Create a real numeral. - @return A Term with the given value and sort Real *) + @return A Term with the given value and sort Real *) val mk_numeral_s : context -> string -> Expr.expr (** Create a real numeral. - @return A Term with the given value and sort Real *) + @return A Term with the given value and sort Real *) val mk_numeral_i : context -> int -> Expr.expr (** Creates an expression that checks whether a real number is an integer. *) @@ -1248,29 +1246,29 @@ sig (** 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. *) + The semantics of this function follows the SMT-LIB standard for the function to_int. + The argument must be of real sort. *) val mk_real2int : context -> Expr.expr -> Expr.expr (** Algebraic Numbers *) module AlgebraicNumber : sig (** Return a upper bound for a given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) val to_upper : Expr.expr -> int -> Expr.expr - + (** Return a lower bound for the given real algebraic number. - The interval isolating the number is smaller than 1/10^precision. - {!is_algebraic_number} - @return A numeral Expr of sort Real *) + The interval isolating the number is smaller than 1/10^precision. + {!is_algebraic_number} + @return A numeral Expr of sort Real *) val to_lower : Expr.expr -> int -> Expr.expr - + (** Returns a string representation in decimal notation. - The result has at most as many decimal places as the int argument provided.*) + The result has at most as many decimal places as the int argument provided.*) val to_decimal_string : Expr.expr -> int -> string - + (** Returns a string representation of a numeral. *) val numeral_to_string : Expr.expr -> string end @@ -1319,10 +1317,10 @@ sig val is_modulus : Expr.expr -> bool (** Indicates whether the term is a coercion of integer to real (unary) *) - val is_inttoreal : Expr.expr -> bool + val is_int2real : Expr.expr -> bool (** Indicates whether the term is a coercion of real to integer (unary) *) - val is_real_to_int : Expr.expr -> bool + val is_real2int : Expr.expr -> bool (** Indicates whether the term is a check that tests whether a real is integral (unary) *) val is_real_is_int : Expr.expr -> bool @@ -1522,19 +1520,15 @@ sig Similar to Z3_OP_ROTATE_RIGHT, but it is a binary operator instead of a parametric one. *) val is_bv_rotaterightextended : Expr.expr -> bool - (** 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. *) - (** 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. *) - val is_int_to_bv : Expr.expr -> bool + val is_int2bv : Expr.expr -> bool (** 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. *) - val is_bv_to_int : Expr.expr -> bool + val is_bv2int : Expr.expr -> bool (** Indicates whether the term is a bit-vector carry Compute the carry bit in a full-adder. The meaning is given by the @@ -1832,339 +1826,339 @@ end (** Floating-Point Arithmetic *) module FloatingPoint : +sig + + (** Rounding Modes *) + module RoundingMode : sig + (** Create the RoundingMode sort. *) + val mk_sort : context -> Sort.sort - (** Rounding Modes *) - module RoundingMode : - sig - (** Create the RoundingMode sort. *) - val mk_sort : context -> Sort.sort + (** Indicates whether the terms is of floating-point rounding mode sort. *) + val is_fprm : Expr.expr -> bool - (** Indicates whether the terms is of floating-point rounding mode sort. *) - val is_fprm : Expr.expr -> bool - - (** Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode. *) - val mk_round_nearest_ties_to_even : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode. *) - val mk_rne : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode. *) - val mk_round_nearest_ties_to_away : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode. *) - val mk_rna : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode. *) - val mk_round_toward_positive : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode. *) - val mk_rtp : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode. *) - val mk_round_toward_negative : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode. *) - val mk_rtn : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the TowardZero rounding mode. *) - val mk_round_toward_zero : context -> Expr.expr - - (** Create a numeral of RoundingMode sort which represents the TowardZero rounding mode. *) - val mk_rtz : context -> Expr.expr - end - - (** Create a FloatingPoint sort. *) - val mk_sort : context -> int -> int -> Sort.sort - - (** Create the half-precision (16-bit) FloatingPoint sort.*) - val mk_sort_half : context -> Sort.sort - - (** Create the half-precision (16-bit) FloatingPoint sort. *) - val mk_sort_16 : context -> Sort.sort - - (** Create the single-precision (32-bit) FloatingPoint sort.*) - val mk_sort_single : context -> Sort.sort - - (** Create the single-precision (32-bit) FloatingPoint sort. *) - val mk_sort_32 : context -> Sort.sort - - (** Create the double-precision (64-bit) FloatingPoint sort. *) - val mk_sort_double : context -> Sort.sort - - (** Create the double-precision (64-bit) FloatingPoint sort. *) - val mk_sort_64 : context -> Sort.sort + (** Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode. *) + val mk_round_nearest_ties_to_even : context -> Expr.expr - (** Create the quadruple-precision (128-bit) FloatingPoint sort. *) - val mk_sort_quadruple : context -> Sort.sort + (** Create a numeral of RoundingMode sort which represents the NearestTiesToEven rounding mode. *) + val mk_rne : context -> Expr.expr - (** Create the quadruple-precision (128-bit) FloatingPoint sort. *) - val mk_sort_128 : context -> Sort.sort - - (** Create a floating-point NaN of a given FloatingPoint sort. *) - val mk_nan : context -> Sort.sort -> Expr.expr - - (** Create a floating-point infinity of a given FloatingPoint sort. *) - val mk_inf : context -> Sort.sort -> bool -> Expr.expr - - (** Create a floating-point zero of a given FloatingPoint sort. *) - val mk_zero : context -> Sort.sort -> bool -> Expr.expr - - (** Create an expression of FloatingPoint sort from three bit-vector expressions. - - This is the operator named `fp' in the SMT FP theory definition. - Note that \c sign is required to be a bit-vector of size 1. Significand and exponent - are required to be greater than 1 and 2 respectively. The FloatingPoint sort - of the resulting expression is automatically determined from the bit-vector sizes - of the arguments. *) - val mk_fp : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Create a numeral of FloatingPoint sort from a float. - - This function is used to create numerals that fit in a float value. - It is slightly faster than #Z3_mk_numeral since it is not necessary to parse a string. *) - val mk_numeral_f : context -> float -> Sort.sort -> Expr.expr - - (** Create a numeral of FloatingPoint sort from a signed integer. *) - val mk_numeral_i : context -> int -> Sort.sort -> Expr.expr + (** Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode. *) + val mk_round_nearest_ties_to_away : context -> Expr.expr - (** Create a numeral of FloatingPoint sort from a sign bit and two integers. *) - val mk_numeral_i_u : context -> bool -> int -> int -> Sort.sort -> Expr.expr - - (** Create a numeral of FloatingPoint sort from a string *) - val mk_numeral_s : context -> string -> Sort.sort -> Expr.expr - - (** Indicates whether the terms is of floating-point sort. *) - val is_fp : Expr.expr -> bool - - - (** Indicates whether an expression is a floating-point abs expression *) - val is_abs : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point neg expression *) - val is_neg : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point add expression *) - val is_add : Expr.expr -> bool + (** Create a numeral of RoundingMode sort which represents the NearestTiesToAway rounding mode. *) + val mk_rna : context -> Expr.expr - (** Indicates whether an expression is a floating-point sub expression *) - val is_sub : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point mul expression *) - val is_mul : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point div expression *) - val is_div : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point fma expression *) - val is_fma : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point sqrt expression *) - val is_sqrt : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point rem expression *) - val is_rem : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point round_to_integral expression *) - val is_round_to_integral : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point min expression *) - val is_min : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point max expression *) - val is_max : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point leq expression *) - val is_leq : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point lt expression *) - val is_lt : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point geqexpression *) - val is_geq : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point gt expression *) - val is_gt : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point eq expression *) - val is_eq : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point is_normal expression *) - val is_is_normal : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point is_subnormal expression *) - val is_is_subnormal : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point is_zero expression *) - val is_is_zero : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point is_infinite expression *) - val is_is_infinite : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point is_nan expression *) - val is_is_nan : Expr.expr -> bool + (** Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode. *) + val mk_round_toward_positive : context -> Expr.expr - (** Indicates whether an expression is a floating-point is_negative expression *) - val is_is_negative : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point is_positive expression *) - val is_is_positive : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point to_fp expression *) - val is_to_fp : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point to_fp_unsigned expression *) - val is_to_fp_unsigned : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point to_ubv expression *) - val is_to_ubv : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point to_sbv expression *) - val is_to_sbv : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point to_real expression *) - val is_to_real : Expr.expr -> bool - - (** Indicates whether an expression is a floating-point to_ieee_bv expression *) - val is_to_ieee_bv : Expr.expr -> bool - - - (** Returns a string representation of a numeral. *) - val numeral_to_string : Expr.expr -> string - - (** Creates a floating-point constant. *) - val mk_const : context -> Symbol.symbol -> Sort.sort -> Expr.expr - - (** Creates a floating-point constant. *) - val mk_const_s : context -> string -> Sort.sort -> Expr.expr - - (** Floating-point absolute value *) - val mk_abs : context -> Expr.expr -> Expr.expr - - (** Floating-point negation *) - val mk_neg : context -> Expr.expr -> Expr.expr - - (** Floating-point addition *) - val mk_add : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point subtraction *) - val mk_sub : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point multiplication *) - val mk_mul : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point division *) - val mk_div : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point fused multiply-add. *) - val mk_fma : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + (** Create a numeral of RoundingMode sort which represents the TowardPositive rounding mode. *) + val mk_rtp : context -> Expr.expr - (** Floating-point square root *) - val mk_sqrt : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point remainder *) - val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr + (** Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode. *) + val mk_round_toward_negative : context -> Expr.expr - (** Floating-point roundToIntegral. - - Rounds a floating-point number to the closest integer, - again represented as a floating-point number. *) - val mk_round_to_integral : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Minimum of floating-point numbers. *) - val mk_min : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Maximum of floating-point numbers. *) - val mk_max : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point less than or equal. *) - val mk_leq : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point less than. *) - val mk_lt : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point greater than or equal. *) - val mk_geq : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point greater than. *) - val mk_gt : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Floating-point equality. *) - val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr - - (** Predicate indicating whether t is a normal floating-point number. *) - val mk_is_normal : context -> Expr.expr -> Expr.expr - - (** Predicate indicating whether t is a subnormal floating-point number. *) - val mk_is_subnormal : context -> Expr.expr -> Expr.expr - - (** Predicate indicating whether t is a floating-point number with zero value, i.e., +zero or -zero. *) - val mk_is_zero : context -> Expr.expr -> Expr.expr - - (** Predicate indicating whether t is a floating-point number representing +oo or -oo. *) - val mk_is_infinite : context -> Expr.expr -> Expr.expr - - (** Predicate indicating whether t is a NaN. *) - val mk_is_nan : context -> Expr.expr -> Expr.expr - - (** Predicate indicating whether t is a negative floating-point number. *) - val mk_is_negative : context -> Expr.expr -> Expr.expr - - (** Predicate indicating whether t is a positive floating-point number. *) - val mk_is_positive : context -> Expr.expr -> Expr.expr - - (** Conversion of a single IEEE 754-2008 bit-vector into a floating-point number. *) - val mk_to_fp_bv : context -> Expr.expr -> Sort.sort -> Expr.expr - - (** Conversion of a FloatingPoint term into another term of different FloatingPoint sort. *) - val mk_to_fp_float : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr - - (** Conversion of a term of real sort into a term of FloatingPoint sort. *) - val mk_to_fp_real : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr - - (** Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort. *) - val mk_to_fp_signed : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr - - (** Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort. *) - val mk_to_fp_unsigned : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr - - (** C1onversion of a floating-point term into an unsigned bit-vector. *) - val mk_to_fp_ubv : context -> Expr.expr -> Expr.expr -> int -> Expr.expr - - (** Conversion of a floating-point term into a signed bit-vector. *) - val mk_to_fp_sbv : context -> Expr.expr -> Expr.expr -> int -> Expr.expr - - (** Conversion of a floating-point term into a real-numbered term. *) - val mk_to_fp_real : context -> Expr.expr -> Expr.expr + (** Create a numeral of RoundingMode sort which represents the TowardNegative rounding mode. *) + val mk_rtn : context -> Expr.expr - (** Retrieves the number of bits reserved for the exponent in a FloatingPoint sort. *) - val get_ebits : context -> Sort.sort -> int - - (** Retrieves the number of bits reserved for the significand in a FloatingPoint sort. *) - val get_sbits : context -> Sort.sort -> int + (** Create a numeral of RoundingMode sort which represents the TowardZero rounding mode. *) + val mk_round_toward_zero : context -> Expr.expr - (** Retrieves the sign of a floating-point literal. *) - val get_numeral_sign : context -> Expr.expr -> bool * int - - (** Return the significand value of a floating-point numeral as a string. *) - val get_numeral_significand_string : context -> Expr.expr -> string - - (** Return the exponent value of a floating-point numeral as a string *) - val get_numeral_exponent_string : context -> Expr.expr -> string - - (** Return the exponent value of a floating-point numeral as a signed integer *) - val get_numeral_exponent_int : context -> Expr.expr -> bool * int - - (** Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format. *) - val mk_to_ieee_bv : context -> Expr.expr -> Expr.expr - - (** Conversion of a real-sorted significand and an integer-sorted exponent into a term of FloatingPoint sort. *) - val mk_to_fp_real_int : context -> Expr.expr -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr - - (** The string representation of a numeral *) - val numeral_to_string : Expr.expr -> string + (** Create a numeral of RoundingMode sort which represents the TowardZero rounding mode. *) + val mk_rtz : context -> Expr.expr end + (** Create a FloatingPoint sort. *) + val mk_sort : context -> int -> int -> Sort.sort + + (** Create the half-precision (16-bit) FloatingPoint sort.*) + val mk_sort_half : context -> Sort.sort + + (** Create the half-precision (16-bit) FloatingPoint sort. *) + val mk_sort_16 : context -> Sort.sort + + (** Create the single-precision (32-bit) FloatingPoint sort.*) + val mk_sort_single : context -> Sort.sort + + (** Create the single-precision (32-bit) FloatingPoint sort. *) + val mk_sort_32 : context -> Sort.sort + + (** Create the double-precision (64-bit) FloatingPoint sort. *) + val mk_sort_double : context -> Sort.sort + + (** Create the double-precision (64-bit) FloatingPoint sort. *) + val mk_sort_64 : context -> Sort.sort + + (** Create the quadruple-precision (128-bit) FloatingPoint sort. *) + val mk_sort_quadruple : context -> Sort.sort + + (** Create the quadruple-precision (128-bit) FloatingPoint sort. *) + val mk_sort_128 : context -> Sort.sort + + (** Create a floating-point NaN of a given FloatingPoint sort. *) + val mk_nan : context -> Sort.sort -> Expr.expr + + (** Create a floating-point infinity of a given FloatingPoint sort. *) + val mk_inf : context -> Sort.sort -> bool -> Expr.expr + + (** Create a floating-point zero of a given FloatingPoint sort. *) + val mk_zero : context -> Sort.sort -> bool -> Expr.expr + + (** Create an expression of FloatingPoint sort from three bit-vector expressions. + + This is the operator named `fp' in the SMT FP theory definition. + Note that \c sign is required to be a bit-vector of size 1. Significand and exponent + are required to be greater than 1 and 2 respectively. The FloatingPoint sort + of the resulting expression is automatically determined from the bit-vector sizes + of the arguments. *) + val mk_fp : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Create a numeral of FloatingPoint sort from a float. + + This function is used to create numerals that fit in a float value. + It is slightly faster than #Z3_mk_numeral since it is not necessary to parse a string. *) + val mk_numeral_f : context -> float -> Sort.sort -> Expr.expr + + (** Create a numeral of FloatingPoint sort from a signed integer. *) + val mk_numeral_i : context -> int -> Sort.sort -> Expr.expr + + (** Create a numeral of FloatingPoint sort from a sign bit and two integers. *) + val mk_numeral_i_u : context -> bool -> int -> int -> Sort.sort -> Expr.expr + + (** Create a numeral of FloatingPoint sort from a string *) + val mk_numeral_s : context -> string -> Sort.sort -> Expr.expr + + (** Indicates whether the terms is of floating-point sort. *) + val is_fp : Expr.expr -> bool + + + (** Indicates whether an expression is a floating-point abs expression *) + val is_abs : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point neg expression *) + val is_neg : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point add expression *) + val is_add : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point sub expression *) + val is_sub : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point mul expression *) + val is_mul : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point div expression *) + val is_div : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point fma expression *) + val is_fma : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point sqrt expression *) + val is_sqrt : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point rem expression *) + val is_rem : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point round_to_integral expression *) + val is_round_to_integral : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point min expression *) + val is_min : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point max expression *) + val is_max : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point leq expression *) + val is_leq : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point lt expression *) + val is_lt : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point geqexpression *) + val is_geq : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point gt expression *) + val is_gt : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point eq expression *) + val is_eq : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_normal expression *) + val is_is_normal : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_subnormal expression *) + val is_is_subnormal : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_zero expression *) + val is_is_zero : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_infinite expression *) + val is_is_infinite : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_nan expression *) + val is_is_nan : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_negative expression *) + val is_is_negative : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point is_positive expression *) + val is_is_positive : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_fp expression *) + val is_to_fp : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_fp_unsigned expression *) + val is_to_fp_unsigned : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_ubv expression *) + val is_to_ubv : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_sbv expression *) + val is_to_sbv : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_real expression *) + val is_to_real : Expr.expr -> bool + + (** Indicates whether an expression is a floating-point to_ieee_bv expression *) + val is_to_ieee_bv : Expr.expr -> bool + + + (** Returns a string representation of a numeral. *) + val numeral_to_string : Expr.expr -> string + + (** Creates a floating-point constant. *) + val mk_const : context -> Symbol.symbol -> Sort.sort -> Expr.expr + + (** Creates a floating-point constant. *) + val mk_const_s : context -> string -> Sort.sort -> Expr.expr + + (** Floating-point absolute value *) + val mk_abs : context -> Expr.expr -> Expr.expr + + (** Floating-point negation *) + val mk_neg : context -> Expr.expr -> Expr.expr + + (** Floating-point addition *) + val mk_add : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point subtraction *) + val mk_sub : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point multiplication *) + val mk_mul : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point division *) + val mk_div : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point fused multiply-add. *) + val mk_fma : context -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point square root *) + val mk_sqrt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point remainder *) + val mk_rem : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point roundToIntegral. + + Rounds a floating-point number to the closest integer, + again represented as a floating-point number. *) + val mk_round_to_integral : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Minimum of floating-point numbers. *) + val mk_min : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Maximum of floating-point numbers. *) + val mk_max : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point less than or equal. *) + val mk_leq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point less than. *) + val mk_lt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point greater than or equal. *) + val mk_geq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point greater than. *) + val mk_gt : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Floating-point equality. *) + val mk_eq : context -> Expr.expr -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a normal floating-point number. *) + val mk_is_normal : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a subnormal floating-point number. *) + val mk_is_subnormal : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a floating-point number with zero value, i.e., +zero or -zero. *) + val mk_is_zero : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a floating-point number representing +oo or -oo. *) + val mk_is_infinite : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a NaN. *) + val mk_is_nan : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a negative floating-point number. *) + val mk_is_negative : context -> Expr.expr -> Expr.expr + + (** Predicate indicating whether t is a positive floating-point number. *) + val mk_is_positive : context -> Expr.expr -> Expr.expr + + (** Conversion of a single IEEE 754-2008 bit-vector into a floating-point number. *) + val mk_to_fp_bv : context -> Expr.expr -> Sort.sort -> Expr.expr + + (** Conversion of a FloatingPoint term into another term of different FloatingPoint sort. *) + val mk_to_fp_float : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** Conversion of a term of real sort into a term of FloatingPoint sort. *) + val mk_to_fp_real : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** Conversion of a 2's complement signed bit-vector term into a term of FloatingPoint sort. *) + val mk_to_fp_signed : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** Conversion of a 2's complement unsigned bit-vector term into a term of FloatingPoint sort. *) + val mk_to_fp_unsigned : context -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** C1onversion of a floating-point term into an unsigned bit-vector. *) + val mk_to_ubv : context -> Expr.expr -> Expr.expr -> int -> Expr.expr + + (** Conversion of a floating-point term into a signed bit-vector. *) + val mk_to_sbv : context -> Expr.expr -> Expr.expr -> int -> Expr.expr + + (** Conversion of a floating-point term into a real-numbered term. *) + val mk_to_real : context -> Expr.expr -> Expr.expr + + (** Retrieves the number of bits reserved for the exponent in a FloatingPoint sort. *) + val get_ebits : context -> Sort.sort -> int + + (** Retrieves the number of bits reserved for the significand in a FloatingPoint sort. *) + val get_sbits : context -> Sort.sort -> int + + (** Retrieves the sign of a floating-point literal. *) + val get_numeral_sign : context -> Expr.expr -> bool * int + + (** Return the significand value of a floating-point numeral as a string. *) + val get_numeral_significand_string : context -> Expr.expr -> string + + (** Return the exponent value of a floating-point numeral as a string *) + val get_numeral_exponent_string : context -> Expr.expr -> string + + (** Return the exponent value of a floating-point numeral as a signed integer *) + val get_numeral_exponent_int : context -> Expr.expr -> bool * int + + (** Conversion of a floating-point term into a bit-vector term in IEEE 754-2008 format. *) + val mk_to_ieee_bv : context -> Expr.expr -> Expr.expr + + (** Conversion of a real-sorted significand and an integer-sorted exponent into a term of FloatingPoint sort. *) + val mk_to_fp_int_real : context -> Expr.expr -> Expr.expr -> Expr.expr -> Sort.sort -> Expr.expr + + (** The string representation of a numeral *) + val numeral_to_string : Expr.expr -> string +end + (** Functions to manipulate proof expressions *) module Proof : @@ -2654,7 +2648,7 @@ sig (** Function interpretations entries - An Entry object represents an element in the finite map used to a function interpretation. *) + An Entry object represents an element in the finite map used to a function interpretation. *) module FuncEntry : sig type func_entry @@ -2844,8 +2838,8 @@ sig val get_subgoal : apply_result -> int -> Goal.goal (** Convert a model for a subgoal into a model for the original - goal [g], that the ApplyResult was obtained from. - #return A model for [g] *) + goal [g], that the ApplyResult was obtained from. + #return A model for [g] *) val convert_model : apply_result -> int -> Model.model -> Model.model (** A string representation of the ApplyResult. *) @@ -2946,7 +2940,7 @@ sig type statistics (** Statistical data is organized into pairs of \[Key, Entry\], where every - Entry is either a floating point or integer value. + Entry is either a floating point or integer value. *) module Entry : sig @@ -2960,16 +2954,16 @@ sig (** The float-value of the entry. *) val get_float : statistics_entry -> float - + (** True if the entry is uint-valued. *) val is_int : statistics_entry -> bool - + (** True if the entry is float-valued. *) val is_float : statistics_entry -> bool - + (** The string representation of the the entry's value. *) val to_string_value : statistics_entry -> string - + (** The string representation of the entry (key and value) *) val to_string : statistics_entry -> string end From e29abefb12330ee4c6a053a95c28f7ab129ae5c0 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 24 Jan 2015 18:44:59 +0000 Subject: [PATCH 246/248] Merge branch 'unstable' of https://git01.codeplex.com/z3 into ml-ng Conflicts: scripts/mk_util.py + Cosmetics Signed-off-by: Christoph M. Wintersteiger --- examples/ml/ml_example.ml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/ml/ml_example.ml b/examples/ml/ml_example.ml index 127a973aa..df062bde4 100644 --- a/examples/ml/ml_example.ml +++ b/examples/ml/ml_example.ml @@ -282,13 +282,11 @@ let fpa_example ( ctx : context ) = Printf.printf "Test passed.\n" ); -(* Show that the following are equal: *) -(* (fp #b0 #b10000000001 #xc000000000000) *) -(* ((_ to_fp 11 53) #x401c000000000000)) *) -(* ((_ to_fp 11 53) RTZ 1.75 2))) *) -(* ((_ to_fp 11 53) RTZ 7.0))) *) - - let solver = (mk_solver ctx None) in + (* Show that the following are equal: *) + (* (fp #b0 #b10000000001 #xc000000000000) *) + (* ((_ to_fp 11 53) #x401c000000000000)) *) + (* ((_ to_fp 11 53) RTZ 1.75 2))) *) + (* ((_ to_fp 11 53) RTZ 7.0))) *) let c1 = (mk_fp ctx (mk_numeral_string ctx "0" (BitVector.mk_sort ctx 1)) (mk_numeral_string ctx "3377699720527872" (BitVector.mk_sort ctx 52)) From 2f3ea1f39d2f700120f34d40fdcc4d4626e8f808 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 24 Jan 2015 18:48:51 +0000 Subject: [PATCH 247/248] removed legacy ML API Signed-off-by: Christoph M. Wintersteiger --- src/api/ml/old/Makefile | 14 - src/api/ml/old/Makefile.build | 69 - src/api/ml/old/README-linux | 22 - src/api/ml/old/README-osx | 22 - src/api/ml/old/README-test-linux | 17 - src/api/ml/old/README-test-osx | 17 - src/api/ml/old/add_error_checking.V3.sed | 2 - src/api/ml/old/add_error_checking.sed | 113 - src/api/ml/old/build-lib.cmd | 3 - src/api/ml/old/build-lib.sh | 31 - src/api/ml/old/build-test.cmd | 19 - src/api/ml/old/build-test.sh | 6 - src/api/ml/old/build.cmd | 53 - src/api/ml/old/clean.cmd | 13 - src/api/ml/old/cleantmp.cmd | 15 - src/api/ml/old/compile_mlapi.cmd | 98 - src/api/ml/old/error_handling.idl | 165 - src/api/ml/old/exec.cmd | 5 - src/api/ml/old/exec.sh | 4 - src/api/ml/old/generate_mlapi.cmd | 72 - src/api/ml/old/generate_mlapi.sh | 53 - src/api/ml/old/import.cmd | 55 - src/api/ml/old/mlx_get_app_args.idl | 11 - src/api/ml/old/mlx_get_array_sort.idl | 11 - src/api/ml/old/mlx_get_datatype_sort.idl | 13 - src/api/ml/old/mlx_get_domains.idl | 11 - src/api/ml/old/mlx_get_error_msg.idl | 6 - src/api/ml/old/mlx_get_pattern_terms.idl | 11 - src/api/ml/old/mlx_get_tuple_sort.idl | 12 - src/api/ml/old/mlx_mk_context_x.idl | 36 - src/api/ml/old/mlx_mk_datatypes.idl | 28 - src/api/ml/old/mlx_mk_numeral.idl | 21 - src/api/ml/old/mlx_mk_sort.idl | 69 - src/api/ml/old/mlx_mk_symbol.idl | 22 - src/api/ml/old/mlx_model.idl | 19 - src/api/ml/old/mlx_numeral_refine.idl | 10 - src/api/ml/old/mlx_parse_smtlib.idl | 40 - src/api/ml/old/mlx_sort_refine.idl | 8 - src/api/ml/old/mlx_statistics.idl | 10 - src/api/ml/old/mlx_symbol_refine.idl | 8 - src/api/ml/old/mlx_term_refine.idl | 37 - src/api/ml/old/postprocess.sed | 8 - src/api/ml/old/preprocess.sed | 82 - src/api/ml/old/queen.ml | 112 - src/api/ml/old/queen.regress.err | 0 src/api/ml/old/queen.regress.out | 1852 -- src/api/ml/old/reverse.sed | 3 - src/api/ml/old/test_mlapi.cmd | 61 - src/api/ml/old/test_mlapi.ml | 209 - src/api/ml/old/test_mlapiV3.ml | 1418 -- src/api/ml/old/test_theory.ml | 42 - src/api/ml/old/update-ml-doc.cmd | 38 - src/api/ml/old/x3.ml | 366 - src/api/ml/old/x3V3.ml | 378 - src/api/ml/old/x3V3.mli | 361 - src/api/ml/old/z3.0.idl | 597 - src/api/ml/old/z3_stubs.c | 19044 --------------------- src/api/ml/old/z3_theory_stubs.c | 339 - 58 files changed, 26161 deletions(-) delete mode 100644 src/api/ml/old/Makefile delete mode 100644 src/api/ml/old/Makefile.build delete mode 100644 src/api/ml/old/README-linux delete mode 100644 src/api/ml/old/README-osx delete mode 100644 src/api/ml/old/README-test-linux delete mode 100644 src/api/ml/old/README-test-osx delete mode 100644 src/api/ml/old/add_error_checking.V3.sed delete mode 100644 src/api/ml/old/add_error_checking.sed delete mode 100755 src/api/ml/old/build-lib.cmd delete mode 100644 src/api/ml/old/build-lib.sh delete mode 100755 src/api/ml/old/build-test.cmd delete mode 100644 src/api/ml/old/build-test.sh delete mode 100755 src/api/ml/old/build.cmd delete mode 100755 src/api/ml/old/clean.cmd delete mode 100755 src/api/ml/old/cleantmp.cmd delete mode 100755 src/api/ml/old/compile_mlapi.cmd delete mode 100644 src/api/ml/old/error_handling.idl delete mode 100755 src/api/ml/old/exec.cmd delete mode 100644 src/api/ml/old/exec.sh delete mode 100755 src/api/ml/old/generate_mlapi.cmd delete mode 100755 src/api/ml/old/generate_mlapi.sh delete mode 100755 src/api/ml/old/import.cmd delete mode 100644 src/api/ml/old/mlx_get_app_args.idl delete mode 100644 src/api/ml/old/mlx_get_array_sort.idl delete mode 100644 src/api/ml/old/mlx_get_datatype_sort.idl delete mode 100644 src/api/ml/old/mlx_get_domains.idl delete mode 100644 src/api/ml/old/mlx_get_error_msg.idl delete mode 100644 src/api/ml/old/mlx_get_pattern_terms.idl delete mode 100644 src/api/ml/old/mlx_get_tuple_sort.idl delete mode 100644 src/api/ml/old/mlx_mk_context_x.idl delete mode 100644 src/api/ml/old/mlx_mk_datatypes.idl delete mode 100644 src/api/ml/old/mlx_mk_numeral.idl delete mode 100644 src/api/ml/old/mlx_mk_sort.idl delete mode 100644 src/api/ml/old/mlx_mk_symbol.idl delete mode 100644 src/api/ml/old/mlx_model.idl delete mode 100644 src/api/ml/old/mlx_numeral_refine.idl delete mode 100644 src/api/ml/old/mlx_parse_smtlib.idl delete mode 100644 src/api/ml/old/mlx_sort_refine.idl delete mode 100644 src/api/ml/old/mlx_statistics.idl delete mode 100644 src/api/ml/old/mlx_symbol_refine.idl delete mode 100644 src/api/ml/old/mlx_term_refine.idl delete mode 100644 src/api/ml/old/postprocess.sed delete mode 100644 src/api/ml/old/preprocess.sed delete mode 100644 src/api/ml/old/queen.ml delete mode 100644 src/api/ml/old/queen.regress.err delete mode 100644 src/api/ml/old/queen.regress.out delete mode 100644 src/api/ml/old/reverse.sed delete mode 100755 src/api/ml/old/test_mlapi.cmd delete mode 100644 src/api/ml/old/test_mlapi.ml delete mode 100644 src/api/ml/old/test_mlapiV3.ml delete mode 100644 src/api/ml/old/test_theory.ml delete mode 100755 src/api/ml/old/update-ml-doc.cmd delete mode 100644 src/api/ml/old/x3.ml delete mode 100644 src/api/ml/old/x3V3.ml delete mode 100644 src/api/ml/old/x3V3.mli delete mode 100644 src/api/ml/old/z3.0.idl delete mode 100644 src/api/ml/old/z3_stubs.c delete mode 100644 src/api/ml/old/z3_theory_stubs.c diff --git a/src/api/ml/old/Makefile b/src/api/ml/old/Makefile deleted file mode 100644 index 55f89fe1c..000000000 --- a/src/api/ml/old/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# to set ARGS, invoke as e.g.: $ make ARGS='-DUNSAFE_ERRORS -DLEAK_CONTEXTS' -ARGS= - - -default: z3.ml z3.mli z3_stubs.c - - -%.ml %.mli %_stubs.c: ../%_api.h %.0.idl x3.ml x3V3.ml x3V3.mli \ - error_handling.idl mlx_get_app_args.idl mlx_get_array_sort.idl mlx_get_datatype_sort.idl mlx_get_domains.idl mlx_get_error_msg.idl mlx_get_pattern_terms.idl mlx_get_tuple_sort.idl mlx_mk_context_x.idl mlx_mk_datatypes.idl mlx_mk_numeral.idl mlx_mk_sort.idl mlx_mk_symbol.idl mlx_model.idl mlx_numeral_refine.idl mlx_parse_smtlib.idl mlx_sort_refine.idl mlx_statistics.idl mlx_symbol_refine.idl mlx_term_refine.idl \ - generate_mlapi.sh add_error_checking.V3.sed add_error_checking.sed preprocess.sed postprocess.sed reverse.sed - ./generate_mlapi.sh $(ARGS) - -clean: - rm -f z3.ml z3.mli z3_stubs.c diff --git a/src/api/ml/old/Makefile.build b/src/api/ml/old/Makefile.build deleted file mode 100644 index 0a737e356..000000000 --- a/src/api/ml/old/Makefile.build +++ /dev/null @@ -1,69 +0,0 @@ -# Makefile to compile OCaml interface to Z3 -# -# Parameters: ARGS and DEPS environment variables -# ARGS is passed through to the Makefile that generates the OCaml interface -# DEPS is a sequence of files that are deleted when the OCaml interface changes - -SRC_ML=../../../src/api/ml -ifeq (${OS}, Windows_NT) -# the BLD_ML path ends up stored in z3.cm{,x}a, so it must be in windows format -BLD_ML=$(shell cygpath -m $(CURDIR)) -CFLAGS=-ccopt -wd4090 -ccopt -I$(SRC_ML)/.. -XCDBG=-g $(CFLAGS) -XCOPT=-ccopt -Ox -ccopt -Oy- $(CFLAGS) -# ole32 is needed by camlidl (COM support) -XLIB=-cclib ole32.lib -AR=lib /nologo /LIBPATH:../../build ../../libz3.lib /out: -O=obj -A=lib -else -BLD_ML=$(CURDIR) -CFLAGS=-ccopt -Wno-discard-qual -ccopt -Wno-unused-variable -ccopt -I$(SRC_ML)/.. -XCDBG=-g -ccopt -g $(CFLAGS) -XCOPT=-ccopt -O3 -ccopt -fomit-frame-pointer $(CFLAGS) -XLIB= -AR=ar rcs # note trailing space is significant -O=o -A=a -endif - - -all: z3.cma z3.cmxa ocamlz3 - - -# keep these files to avoid repeatedly rebuilding them -.PRECIOUS: $(SRC_ML)/z3.ml $(SRC_ML)/z3.mli $(SRC_ML)/z3_stubs.c z3.ml z3.mli z3_stubs.c z3_theory_stubs.c - -# regenerate OCaml API if needed -$(SRC_ML)/%.mli $(SRC_ML)/%.ml $(SRC_ML)/%_stubs.c: $(SRC_ML)/Makefile - make -C $(SRC_ML) z3.mli z3.ml z3_stubs.c - -# copy OCaml API from src to build directories -%.mli %.ml %_stubs.c %_theory_stubs.c: $(SRC_ML)/%.mli $(SRC_ML)/%.ml $(SRC_ML)/%_stubs.c Makefile - cp $(SRC_ML)/z3.mli $(SRC_ML)/z3.ml $(SRC_ML)/z3_stubs.c $(SRC_ML)/z3_theory_stubs.c . - -# OCaml library module for native code clients -%.cmxa %.cmi lib%stubs.a %.a: %.mli %.ml %_stubs.c %_theory_stubs.c Makefile - rm -f $(DEPS) - ocamlopt.opt -c $(XCOPT) z3.mli z3.ml z3_stubs.c z3_theory_stubs.c - $(AR)libz3stubs.$(A) z3.$(O) z3_stubs.$(O) z3_theory_stubs.$(O) - ocamlopt.opt -a -cclib -L$(BLD_ML)/../.. $(XLIB) -cclib -lcamlidl -cclib -lz3 -cclib -lz3stubs z3.cmx -o z3.cmxa - rm -f z3_theory_stubs.$(O) z3_stubs.$(O) z3.$(O) z3.cmx - -# OCaml library module for byte code clients -%.cma %.cmi lib%stubs_dbg.a: %.mli %.ml %_stubs.c %_theory_stubs.c Makefile - rm -f $(DEPS) - ocamlc.opt -c $(XCDBG) z3.mli z3.ml z3_stubs.c z3_theory_stubs.c - $(AR)libz3stubs_dbg.$(A) z3_stubs.$(O) z3_theory_stubs.$(O) - ocamlc.opt -custom -a $(CXDBG) -cclib -L$(BLD_ML)/../.. $(XLIB) -cclib -lcamlidl -cclib -lz3 -cclib -lz3stubs_dbg z3.cmo -o z3.cma - rm -f z3_theory_stubs.$(O) z3_stubs.$(O) z3.cmo - - -# OCaml custom toplevel system pre-linked with Z3 -ocamlz3: z3.cma Makefile - ocamlmktop -o ocamlz3 z3.cma -cclib -L. - - -clean: Makefile - make -C $(SRC_ML) clean - rm -rf Makefile libz3stubs.$(A) libz3stubs_dbg.$(A) ocamlz3 ocamlz3.dSYM z3.$(O) z3.$(A) z3.cma z3.cmi z3.cmo z3.cmx z3.cmxa z3.ml z3.mli z3_stubs.$(O) z3_stubs.c z3_theory_stubs.$(O) z3_theory_stubs.c diff --git a/src/api/ml/old/README-linux b/src/api/ml/old/README-linux deleted file mode 100644 index 5ee20bb27..000000000 --- a/src/api/ml/old/README-linux +++ /dev/null @@ -1,22 +0,0 @@ -The OCaml API for Z3 was tested using OCaml 3.12.1. -You also need CamlIDL to be able to generate the OCaml API. - -- To download OCaml: - http://caml.inria.fr/ocaml/ - -- To download CamlIDL: - http://forge.ocamlcore.org/projects/camlidl/ - -- To build the OCaml API for Z3: - ./build-lib.sh - -Remark: The OCaml and C compiler tool chains must be configured in your environment. - -Remark: Building the OCaml API copies some pathnames into files, -so the OCaml API must be recompiled if the Z3 library files are moved. - -See ../examples/ocaml/build-test.sh for an example of how to compile and link with Z3. - -Acknowledgements: -The OCaml interface for Z3 was written by Josh Berdine and Jakob Lichtenberg. -Many thanks to them! diff --git a/src/api/ml/old/README-osx b/src/api/ml/old/README-osx deleted file mode 100644 index 5ee20bb27..000000000 --- a/src/api/ml/old/README-osx +++ /dev/null @@ -1,22 +0,0 @@ -The OCaml API for Z3 was tested using OCaml 3.12.1. -You also need CamlIDL to be able to generate the OCaml API. - -- To download OCaml: - http://caml.inria.fr/ocaml/ - -- To download CamlIDL: - http://forge.ocamlcore.org/projects/camlidl/ - -- To build the OCaml API for Z3: - ./build-lib.sh - -Remark: The OCaml and C compiler tool chains must be configured in your environment. - -Remark: Building the OCaml API copies some pathnames into files, -so the OCaml API must be recompiled if the Z3 library files are moved. - -See ../examples/ocaml/build-test.sh for an example of how to compile and link with Z3. - -Acknowledgements: -The OCaml interface for Z3 was written by Josh Berdine and Jakob Lichtenberg. -Many thanks to them! diff --git a/src/api/ml/old/README-test-linux b/src/api/ml/old/README-test-linux deleted file mode 100644 index fc15fb2a2..000000000 --- a/src/api/ml/old/README-test-linux +++ /dev/null @@ -1,17 +0,0 @@ -This directory contains scripts to build the test application using -OCaml. You also need CamlIDL to be able to generate the OCaml API. - -- To download OCaml: - http://caml.inria.fr/ocaml/ - -- To download CamlIDL: - http://forge.ocamlcore.org/projects/camlidl/ - -- One must build the OCaml library before compiling the example. - Go to directory ../ocaml - -- Use 'build-test.sh' to build the test application using the OCaml compiler. - -Remark: The OCaml and C compiler tool chains must be configured in your environment. - -- Use 'exec.sh' to execute test_mlapi. The script sets LD_LIBRARY_PATH, and invokes test_mlapi. diff --git a/src/api/ml/old/README-test-osx b/src/api/ml/old/README-test-osx deleted file mode 100644 index 3a20d1f1d..000000000 --- a/src/api/ml/old/README-test-osx +++ /dev/null @@ -1,17 +0,0 @@ -This directory contains scripts to build the test application using -OCaml. You also need CamlIDL to be able to generate the OCaml API. - -- To download OCaml: - http://caml.inria.fr/ocaml/ - -- To download CamlIDL: - http://forge.ocamlcore.org/projects/camlidl/ - -- One must build the OCaml library before compiling the example. - Go to directory ../ocaml - -- Use 'build-test.sh' to build the test application using the OCaml compiler. - -Remark: The OCaml and C compiler tool chains must be configured in your environment. - -- Use 'exec.sh' to execute test_mlapi. The script sets DYLD_LIBRARY_PATH, and invokes test_mlapi. diff --git a/src/api/ml/old/add_error_checking.V3.sed b/src/api/ml/old/add_error_checking.V3.sed deleted file mode 100644 index 7df291520..000000000 --- a/src/api/ml/old/add_error_checking.V3.sed +++ /dev/null @@ -1,2 +0,0 @@ -# Customize error handling for contexts created in ML: -s/Z3_API Z3_mk_context(\(.*\))/Z3_API Z3_mk_context(\1) quote(dealloc,\"Z3_set_error_handler(_res, (void*)caml_z3_error_handler);\")/g diff --git a/src/api/ml/old/add_error_checking.sed b/src/api/ml/old/add_error_checking.sed deleted file mode 100644 index 71c06b9e4..000000000 --- a/src/api/ml/old/add_error_checking.sed +++ /dev/null @@ -1,113 +0,0 @@ -# Do not add epilogue to Z3_del_context -/Z3_API .*Z3_del_context.*/b endt - -# Add error checking epilogue for all Z3_API functions that accept two Z3_contexts -:begincc -# add epilogue for two Z3_context parameters and if a match was found, done with all Z3_contexts and Z3_theorys so jump to endt -s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\(.*\)Z3_context \([a-zA-Z]*\)\([^a-zA-Z].*\));[ ]*$/Z3_API \1(\2Z3_context \3\4Z3_context \5\6) quote(dealloc,\"check_error_code(\3);\");/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\(.*\)Z3_context \([a-zA-Z]*\));[ ]*$/Z3_API \1(\2Z3_context \3\4Z3_context \5) quote(dealloc,\"check_error_code(\3);\");/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\(.*\)Z3_context \([a-zA-Z]*\)\([^a-zA-Z].*\))[ ]*$/Z3_API \1(\2Z3_context \3\4Z3_context \5\6) quote(dealloc,\"check_error_code(\3);\")/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\(.*\)Z3_context \([a-zA-Z]*\))[ ]*$/Z3_API \1(\2Z3_context \3\4Z3_context \5) quote(dealloc,\"check_error_code(\3);\")/g -t endt - -# if complete prototype, done with two Z3_contexts -/Z3_API .*(.*);[ ]*$/b endcc -/Z3_API .*(.*)[ ]*$/b endcc - -# if incomplete prototype -/Z3_API .*(.*/{ - - # read another line - N - - # add epilogue for two Z3_context parameters and if a match was found, done with all Z3_contexts and Z3_theorys so jump to endt - s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\(.*\)Z3_context \([a-zA-Z]*\)\([^a-zA-Z].*\));[ ]*$/Z3_API \1(\2Z3_context \3\4Z3_context \5\6) quote(dealloc,\"check_error_code(\3); check_error_code(\5);\");/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\(.*\)Z3_context \([a-zA-Z]*\));[ ]*$/Z3_API \1(\2Z3_context \3\4Z3_context \5) quote(dealloc,\"check_error_code(\3); check_error_code(\5);\");/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\(.*\)Z3_context \([a-zA-Z]*\)\([^a-zA-Z].*\))[ ]*$/Z3_API \1(\2Z3_context \3\4Z3_context \5\6) quote(dealloc,\"check_error_code(\3); check_error_code(\5);\")/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\(.*\)Z3_context \([a-zA-Z]*\))[ ]*$/Z3_API \1(\2Z3_context \3\4Z3_context \5) quote(dealloc,\"check_error_code(\3); check_error_code(\5);\")/g - t endt - - # else keep looking for two Z3_contexts - b begincc -} -:endcc - -# Add error checking epilogue for all Z3_API functions that accept one Z3_context -:beginc -# add epilogue for one Z3_context parameter and if a match was found, done with all Z3_contexts and Z3_theorys so jump to endt -s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\([^a-zA-Z].*\));[ ]*$/Z3_API \1(\2Z3_context \3\4) quote(dealloc,\"check_error_code(\3);\");/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\));[ ]*$/Z3_API \1(\2Z3_context \3) quote(dealloc,\"check_error_code(\3);\");/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\([^a-zA-Z].*\)[ ]*$/Z3_API \1(\2Z3_context \3\4) quote(dealloc,\"check_error_code(\3);\")/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\))[ ]*$/Z3_API \1(\2Z3_context \3) quote(dealloc,\"check_error_code(\3);\")/g -t endt - -# if complete prototype, done with all Z3_contexts -/Z3_API .*(.*);[ ]*$/b endc -/Z3_API .*(.*)[ ]*$/b endc - -# if incomplete prototype -/Z3_API .*(.*/{ - - # read another line - N - - # add epilogue for one Z3_context parameter and if a match was found, done with all Z3_contexts and Z3_theorys so jump to endt - s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\([^a-zA-Z].*\));[ ]*$/Z3_API \1(\2Z3_context \3\4) quote(dealloc,\"check_error_code(\3);\");/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\));[ ]*$/Z3_API \1(\2Z3_context \3) quote(dealloc,\"check_error_code(\3);\");/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\)\([^a-zA-Z].*\))[ ]*$/Z3_API \1(\2Z3_context \3\4) quote(dealloc,\"check_error_code(\3);\")/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_context \([a-zA-Z]*\))[ ]*$/Z3_API \1(\2Z3_context \3) quote(dealloc,\"check_error_code(\3);\")/g - t endt - - # else keep looking for one Z3_context - b beginc -} -:endc - - -# Add error checking epilogue for all Z3_API functions that accept a Z3_theory -:begint -# add epilogue for one Z3_theory parameter and if a match was found, done with all Z3_contexts and Z3_theorys so jump to endt -s/Z3_API \(.*\)(\(.*\)Z3_theory \([a-zA-Z]*\)\([^a-zA-Z].*\));[ ]*$/Z3_API \1(\2Z3_theory \3\4) quote(dealloc,\"check_error_code(Z3_theory_get_context(\3));\");/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_theory \([a-zA-Z]*\));[ ]*$/Z3_API \1(\2Z3_theory \3) quote(dealloc,\"check_error_code(Z3_theory_get_context(\3));\");/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_theory \([a-zA-Z]*\)\([^a-zA-Z].*\))[ ]*$/Z3_API \1(\2Z3_theory \3\4) quote(dealloc,\"check_error_code(Z3_theory_get_context(\3));\")/g -t endt -s/Z3_API \(.*\)(\(.*\)Z3_theory \([a-zA-Z]*\))[ ]*$/Z3_API \1(\2Z3_theory \3) quote(dealloc,\"check_error_code(Z3_theory_get_context(\3));\")/g -t endt - -# if complete prototype, done with all Z3_theorys -/Z3_API .*(.*);[ ]*$/b endt -/Z3_API .*(.*)[ ]*$/b endt - -/Z3_API .*(.*/{ - - # read another line - N - - # add epilogue for one Z3_theory parameter and if a match was found, done with all Z3_contexts and Z3_theorys so jump to endt - s/Z3_API \(.*\)(\(.*\)Z3_theory \([a-zA-Z]*\)\([^a-zA-Z].*\));[ ]*$/Z3_API \1(\2Z3_theory \3\4) quote(dealloc,\"check_error_code(Z3_theory_get_context(\3));\");/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_theory \([a-zA-Z]*\));[ ]*$/Z3_API \1(\2Z3_theory \3) quote(dealloc,\"check_error_code(Z3_theory_get_context(\3));\");/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_theory \([a-zA-Z]*\)\([^a-zA-Z].*\))[ ]*$/Z3_API \1(\2Z3_theory \3\4) quote(dealloc,\"check_error_code(Z3_theory_get_context(\3));\")/g - t endt - s/Z3_API \(.*\)(\(.*\)Z3_theory \([a-zA-Z]*\))[ ]*$/Z3_API \1(\2Z3_theory \3) quote(dealloc,\"check_error_code(Z3_theory_get_context(\3));\")/g - t endt - - # else keep looking for one Z3_theory - b begint -} -:endt diff --git a/src/api/ml/old/build-lib.cmd b/src/api/ml/old/build-lib.cmd deleted file mode 100755 index 7cf1bbcbd..000000000 --- a/src/api/ml/old/build-lib.cmd +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -call .\compile_mlapi.cmd ..\include ..\bin ..\bin diff --git a/src/api/ml/old/build-lib.sh b/src/api/ml/old/build-lib.sh deleted file mode 100644 index 93c7262b1..000000000 --- a/src/api/ml/old/build-lib.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -# Script to compile the Z3 OCaml API -# Expects to find ../lib/libz3{,_dbg}.{a,so,dylib} - -CFLAGS="-ccopt -Wno-discard-qual -ccopt -I../include" -XCDBG="-g -ccopt -g $CFLAGS" -XCOPT="-ccopt -O3 -ccopt -fomit-frame-pointer $CFLAGS" - - -ocamlc -c $XCDBG z3_stubs.c z3_theory_stubs.c z3.mli z3.ml - -ocamlopt -c $XCDBG z3_stubs.c z3_theory_stubs.c z3.mli z3.ml - -ar rcs libz3stubs_dbg.a z3.o z3_stubs.o z3_theory_stubs.o - -ocamlopt -c $XCOPT z3_stubs.c z3_theory_stubs.c z3.mli z3.ml - -ar rcs libz3stubs.a z3.o z3_stubs.o z3_theory_stubs.o - -ocamlc -custom -a $XCDBG -cclib -L$PWD/../lib -cclib -lz3_dbg -cclib -lcamlidl -cclib -lz3stubs_dbg z3.cmo -o z3_dbg.cma - -ocamlc -custom -a $XCDBG -cclib -L$PWD/../lib -cclib -lz3 -cclib -lcamlidl -cclib -lz3stubs z3.cmo -o z3.cma - -ocamlopt -a $XCDBG -cclib -L$PWD/../lib -cclib -lz3_dbg -cclib -lcamlidl -cclib -lz3stubs_dbg z3.cmx -o z3_dbg.cmxa - -ocamlopt -a $XCOPT -cclib -L$PWD/../lib -cclib -lz3 -cclib -lcamlidl -cclib -lz3stubs z3.cmx -o z3.cmxa - -ocamlmktop -o ocamlz3 z3.cma -cclib -L. - -rm z3.cm{o,x} *.o diff --git a/src/api/ml/old/build-test.cmd b/src/api/ml/old/build-test.cmd deleted file mode 100755 index 13a752dbb..000000000 --- a/src/api/ml/old/build-test.cmd +++ /dev/null @@ -1,19 +0,0 @@ -@echo off - -if not exist ..\..\ocaml\z3.cmxa ( - echo "YOU MUST BUILD OCAML API! Go to directory ..\ocaml" - goto :EOF -) - -REM ocaml (>= 3.11) calls the linker through flexlink -ocamlc -version >> ocaml_version -set /p OCAML_VERSION= NUL z3_stubs.c z3.mli z3.ml z3V3_stubs.*.c z3V3.*.mli z3V3.*.ml - -REM files produced by update-ml-doc.cmd -rd 2>NUL /s /q doc - -exit /B 0 diff --git a/src/api/ml/old/cleantmp.cmd b/src/api/ml/old/cleantmp.cmd deleted file mode 100755 index 257e26a96..000000000 --- a/src/api/ml/old/cleantmp.cmd +++ /dev/null @@ -1,15 +0,0 @@ -@echo off - -REM Script to delete intermediate temporary files from generating Z3 OCaml API - -REM files produced by generate_mlapi.cmd -del /q 2>NUL z3_api.idl - -REM files produced by compile_mlapi.cmd -del /q 2>NUL *.cmi *.cmo *.cmx *.cma *.cmxa *.obj *.lib *.pdb ocamlz3.exe - -REM files produced by test_mlapi.cmd -del /q 2>NUL test*.exe queen*.exe test_*api.out test_*apiV3.out test_*api.err test_*apiV3.err queen.out queen.err z3.log ml.log test_mlapi.log .z3-trace - -REM backup files -del /q 2>NUL *~ diff --git a/src/api/ml/old/compile_mlapi.cmd b/src/api/ml/old/compile_mlapi.cmd deleted file mode 100755 index 17776b6b8..000000000 --- a/src/api/ml/old/compile_mlapi.cmd +++ /dev/null @@ -1,98 +0,0 @@ -@echo off -SETLOCAL - -REM Script to compile the Z3 OCaml API -REM -REM Compiles byte and debug native code versions with debug info, optimized native code versions without -REM -REM Assumes that environment variables are set to provide access to the C and OCaml compilers - -REM directory containing z3_api.h -set Z3SRC=%1 - -REM directory containing z3.dll -set Z3BIN=%2 - -REM directory containing debug z3.dll -set Z3BINDBG=%3 - -REM link Z3 statically or dynamically -set STATIC=false -REM set STATIC=true - -if %STATIC% == true ( - set Z3LIB=z3lib.lib - set Z3DBGLIB=z3lib.lib -) else ( - set Z3LIB=z3.lib - set Z3DBGLIB=z3.lib -) - -REM ocaml 3.11 and later calls the linker through flexlink -ocamlc -version >> ocaml_version -set /p OCAML_VERSION= DBG z3_stubs.obj z3.{cmi,cmo,obj} -ocamlc -c %XCDBG% z3_stubs.c z3_theory_stubs.c z3.mli z3.ml -if errorlevel 1 goto :EOF - -REM z3_stubs.c z3_theory_stubs.c z3.mli z3.ml -> DBG z3_stubs.obj z3.{cmi,cmx,obj} -ocamlopt -c %XCDBG% z3_stubs.c z3_theory_stubs.c z3.mli z3.ml -if errorlevel 1 goto :EOF - -REM %Z3DBGLIB% z3.obj z3_stubs.obj z3_theory_stubs.obj -> libz3_dbg.lib: -lib /nologo %XLIBPATH% /out:libz3_dbg.lib %Z3BINDBG%\%Z3DBGLIB% z3.obj z3_stubs.obj z3_theory_stubs.obj -if errorlevel 1 goto :EOF - -REM z3_stubs.c z3_theory_stubs.c z3.mli z3.ml -> OPT z3_stubs.obj z3.{cmi,cmx,obj} -ocamlopt -c %XCOPT% z3_stubs.c z3_theory_stubs.c z3.mli z3.ml -if errorlevel 1 goto :EOF - -REM %Z3LIB% z3.obj z3_stubs.obj z3_theory_stubs.obj -> libz3.lib: -lib /nologo %XLIBPATH% /out:libz3.lib %Z3BIN%\%Z3LIB% z3.obj z3_stubs.obj z3_theory_stubs.obj -if errorlevel 1 goto :EOF - - -REM ole32.lib is needed by camlidl -REM camlidl.lib is the runtime library for camlidl -REM psapi.lib is needed when statically linking Z3 for process statistics functions - -REM libz3_dbg.lib ole32.lib camlidl.lib z3.cmo -> z3_dbg.cma -ocamlc -custom -a %XCDBG% -cclib -L"%CD%\..\bin" -cclib -lz3_dbg -cclib ole32.lib -cclib -lcamlidl -cclib psapi.lib z3.cmo -o z3_dbg.cma -if errorlevel 1 goto :EOF - -REM libz3.lib ole32.lib camlidl.lib z3.cmo -> z3.cma -ocamlc -custom -a -cclib -L"%CD%\..\bin" -cclib -lz3 -cclib ole32.lib -cclib -lcamlidl -cclib psapi.lib z3.cmo -o z3.cma -if errorlevel 1 goto :EOF - - -REM libz3_dbg.lib ole32.lib camlidl.lib z3.cmx -> z3_dbg.cmxa -ocamlopt -a -cclib -L"%CD%\..\bin" -cclib -lz3_dbg -cclib ole32.lib -cclib -lcamlidl -cclib psapi.lib z3.cmx -o z3_dbg.cmxa -if errorlevel 1 goto :EOF - -REM libz3.lib ole32.lib camlidl.lib z3.cmx -> z3.cmxa -ocamlopt -a -cclib -L"%CD%\..\bin" -cclib -lz3 -cclib ole32.lib -cclib -lcamlidl -cclib psapi.lib z3.cmx -o z3.cmxa -if errorlevel 1 goto :EOF - - -REM build OCaml toplevel 'ocamlz3' pre-linked with Z3 -ocamlmktop -o ocamlz3 z3.cma -if errorlevel 1 goto :EOF - - -del /q 2>NUL z3.cmo z3.cmx *.obj - -ENDLOCAL diff --git a/src/api/ml/old/error_handling.idl b/src/api/ml/old/error_handling.idl deleted file mode 100644 index 5a2ec9915..000000000 --- a/src/api/ml/old/error_handling.idl +++ /dev/null @@ -1,165 +0,0 @@ -/*++ -Copyright (c) Microsoft Corporation - -Module Name: - - error_handling - -Abstract: - - Error handling in the OCaml API for Z3. - - The wrapper of each Z3 API routine that takes a Z3_context or a Z3_theory - argument calls check_error_code before returning. (These calls are added - in generate_mlapi.cmd using the build.sed script.) - - There are two error handling schemes implemented, depending on whether - (UN)SAFE_ERRORS is set. - - - SAFE_ERRORS checks Z3_error_code after each call and raises an OCaml - exception in error conditions. Z3_set_error_handler is not exposed by - the SAFE_ERRORS version. - - - UNSAFE_ERRORS sets a Z3 error handler routine that either calls a - globally registered OCaml function or, by default, raises an OCaml - exception. This avoids overhead of repeatedly checking - Z3_get_error_code, but leaves Z3 in a broken state. - -Notes: - - The current SAFE_ERRORS implementation interacts badly with theory plugin - callbacks. Z3 errors are converted into OCaml exceptions, which the - wrappers of theory plugin callbacks are not expecting. Therefore, if a - theory plugin calls a Z3 API routine that triggers an error, an OCaml - exception will be raised and bypass any C++ destructors pushed onto the - stack by Z3 before the call to the plugin and after the preceding OCaml - exception handler. One solution to this would be to modify the theory - plugin callback registration functions to wrap callbacks in an OCaml - exception handler. Since OCaml exceptions are cheap to raise at the - expense of some cost to install a handler, this may not be desirable. - Another solution would be to modify check_error_code to detect if it is - executing in a plugin callback and simply maintain the Z3_error_code, or - raise a C++ exception, instead of raising an OCaml exception. - -Author: - - Josh Berdine (jjb) 2012-03-21 - ---*/ - - -#if !defined(UNSAFE_ERRORS) && !defined(SAFE_ERRORS) -#define SAFE_ERRORS -#endif - - -// The V3 API uses a single handler irregardless of UNSAFE_ERRORS -quote(c," -/* All contexts share the same handler */ -static value caml_z3_error_handler = 0; -"); - -#ifdef SAFE_ERRORS - -quote(mlmli," -(** Exceptions raised by Z3. It is safe to continue interacting with Z3 after - catching [Error] exceptions. - - - {b See also}: {!get_error_msg} -*) -exception Error of context * error_code -"); -quote(ml," -(* Register dynamically-generated exception tag for use from C *) -let _ = Callback.register_exception \"Z3.Error\" (Error (Obj.magic None, OK)) -"); - -quote(c," -value camlidl_c2ml_z3_Z3_error_code(Z3_error_code * _c2, camlidl_ctx _ctx); - -/* Error checking routine that raises OCaml Error exceptions */ -void check_error_code (Z3_context c) -{ - static struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - value* exn_tag = NULL; - value ctx_err[2]; - Z3_error_code e; - e = Z3_get_error_code(c); - if (e != Z3_OK) { - ctx_err[0] = c2ml_Z3_context(&c); - ctx_err[1] = camlidl_c2ml_z3_Z3_error_code(&e, &_ctxs); - exn_tag = caml_named_value(\"Z3.Error\"); - if (*exn_tag == 0) { - fprintf(stderr, \"Z3.Error not found\"); - exit(1); - } - caml_raise_with_args(*exn_tag, 2, ctx_err); - } -} - -/* Disable default error handler, all error checking is done by check_error_code */ -void* error_handler_static = NULL; -"); - -#else - -quote(mlmli," -(** Exceptions raised by Z3. {b Warning}: It is unsafe to continue - interacting with Z3 after catching [Error] exceptions. To recover from - error conditions, use {!set_error_handler} to set an error handler that - does nothing, and then test {!get_error_code} after every call to Z3. - - - {b See also}: {!get_error_msg} -*) -exception Error of context * error_code -"); -quote(ml," -(* Register dynamically-generated exception tag for use from C *) -let _ = Callback.register_exception \"Z3.Error\" (Error (Obj.magic None, OK)) -"); - -quote(c," -/* Error checking routine that does nothing */ -void check_error_code(Z3_context c) {} - -static void error_handler_static (Z3_context c, Z3_error_code e) -{ - static struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - value* exn_tag = NULL; - value ctx_err[2]; - ctx_err[0] = c2ml_Z3_context(&c); - ctx_err[1] = camlidl_c2ml_z3_Z3_error_code(&e, &_ctxs); - if (caml_z3_error_handler) { - caml_callback2(caml_z3_error_handler, ctx_err[0], ctx_err[1]); - } else { - /* if no handler set, raise OCaml Error exception */ - exn_tag = caml_named_value(\"Z3.Error\"); - if (*exn_tag == 0) { - fprintf(stderr, \"Z3.Error not found\"); - exit(1); - } - caml_raise_with_args(*exn_tag, 2, ctx_err); - } -} - -void ml2c_Z3_error_handler (value ml_handler, void* c_handler) -{ - caml_z3_error_handler = ml_handler; - c_handler = (void*)error_handler_static; -} - -/* Never called */ -value c2ml_Z3_error_handler (void* _) -{ - return 0; -} -"); - -typedef [mltype("context -> error_code -> unit"), - ml2c(ml2c_Z3_error_handler), - c2ml(c2ml_Z3_error_handler) - ] void Z3_error_handler; - -quote(c,"#define Z3_error_handler void*"); - -#endif diff --git a/src/api/ml/old/exec.cmd b/src/api/ml/old/exec.cmd deleted file mode 100755 index 2bb632ef6..000000000 --- a/src/api/ml/old/exec.cmd +++ /dev/null @@ -1,5 +0,0 @@ -@echo off -SETLOCAL -set PATH=..\..\bin;%PATH% -test_mlapi.exe -ENDLOCAL diff --git a/src/api/ml/old/exec.sh b/src/api/ml/old/exec.sh deleted file mode 100644 index 573ec6ddf..000000000 --- a/src/api/ml/old/exec.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -export LD_LIBRARY_PATH=../../lib:$LD_LIBRARY_PATH # for linux -export DYLD_LIBRARY_PATH=../../lib:$DYLD_LIBRARY_PATH # for osx -./test_mlapi diff --git a/src/api/ml/old/generate_mlapi.cmd b/src/api/ml/old/generate_mlapi.cmd deleted file mode 100755 index 6a796a401..000000000 --- a/src/api/ml/old/generate_mlapi.cmd +++ /dev/null @@ -1,72 +0,0 @@ -@echo off - -REM Script to generate the Z3 OCaml API -REM -REM Assumes that environment variables are set to provide access to the following commands: camlidl, dos2unix, grep, sed, unix2dos -REM -REM Invoke with "-D UNSAFE_ERRORS" to build version that does not support recoverable errors, but avoids some error-checking overhead. -REM Invoke with "-D LEAK_CONTEXTS" to build version that leaks Z3_context objects, but avoids some garbage-collection overhead. - -REM ../lib/z3_api.h -> z3V3_api.idl using add_error_checking.V3.sed and build.sed -sed -f add_error_checking.V3.sed ../lib/z3_api.h | sed -f build.sed >z3V3_api.idl -if errorlevel 1 goto :EOF - -REM z3.idl -> z3V3_stubs.c, z3V3.mli, z3V3.ml -camlidl -D MLAPIV3 %* z3.idl -move >NUL z3_stubs.c z3V3_stubs.c -move >NUL z3.ml z3V3.ml -move >NUL z3.mli z3V3.mli -if errorlevel 1 goto :EOF - -REM ../lib/z3_api.h -> z3_api.idl -REM add calls to error checking routine -REM convert from doxygen to ocamldoc markup and other syntactic munging -sed <../lib/z3_api.h -f add_error_checking.sed | ^ -sed -f build.sed >z3_api.idl -if errorlevel 1 goto :EOF - -REM z3.idl -> z3_stubs.c, z3.mli, z3.ml -camlidl %* z3.idl -if errorlevel 1 goto :EOF - -REM sometimes z3_stubs.c can be generated with mixed line endings, which can confuse sed and grep -dos2unix 2>NUL z3V3_stubs.c ; unix2dos 2>NUL z3V3_stubs.c -dos2unix 2>NUL z3_stubs.c ; unix2dos 2>NUL z3_stubs.c - -REM modify generated z3.ml{,i} to remove "Z3_" prefix from names -move >NUL z3V3.mli z3V3.1.mli && sed "s/{\!Z3\./{!/g;s/\<[zZ]3_//g" z3V3.1.mli >z3V3.mli && del z3V3.1.mli -move >NUL z3V3.ml z3V3.1.ml && sed "s/{\!Z3\./{!/g;s/\<[zZ]3_//g" z3V3.1.ml >z3V3.ml && del z3V3.1.ml -move >NUL z3.mli z3.1.mli && sed "s/{\!Z3\./{!/g;s/\<[zZ]3_//g" z3.1.mli >z3.mli && del z3.1.mli -move >NUL z3.ml z3.1.ml && sed "s/{\!Z3\./{!/g;s/\<[zZ]3_//g" z3.1.ml >z3.ml && del z3.1.ml - -REM modify generated z3V3 files to rename z3_ to z3V3_ -move >NUL z3V3.mli z3V3.2.mli && sed "s/camlidl\(.*\)_z3_/camlidl\1_z3V3_/g" z3V3.2.mli >z3V3.mli && del z3V3.2.mli -move >NUL z3V3.ml z3V3.2.ml && sed "s/camlidl\(.*\)_z3_/camlidl\1_z3V3_/g" z3V3.2.ml >z3V3.ml && del z3V3.2.ml -move >NUL z3V3_stubs.c z3V3_stubs.2.c && sed "s/camlidl\(.*\)_z3_/camlidl\1_z3V3_/g" z3V3_stubs.2.c >z3V3_stubs.c && del z3V3_stubs.2.c - - -REM substitute out type equations for enums and options -REM reverse order of substitution of enums to avoid matching prefixes such as enum_1 of enum_10 -grep "^and \([a-z][a-zA-Z_]*\) = \([a-z][a-zA-Z_]*[0-9]*\)$" z3.mli | sed "s|and \([a-zA-Z_]*\) = \([ a-zA-Z_0-9]*\)|s/\2/\1/g|g" | sed "1!G;h;$!d" >rename.sed -grep "^and \([a-z][a-zA-Z_]*\) = \([a-z][a-zA-Z_]* option*\)$" z3.mli | sed "s|and \([a-zA-Z_]*\) = \([ a-zA-Z_0-9]*\)|s/\1/\2/g|g" >>rename.sed -move >NUL z3.mli z3.3.mli && sed -f rename.sed z3.3.mli >z3.mli && del z3.3.mli -move >NUL z3.ml z3.3.ml && sed -f rename.sed z3.3.ml >z3.ml && del z3.3.ml -del rename.sed - -grep "^and \([a-z][a-zA-Z_]*\) = \([a-z][a-zA-Z_]*[0-9]*\)$" z3V3.mli | sed "s|and \([a-zA-Z_]*\) = \([ a-zA-Z_0-9]*\)|s/\2/\1/g|g" | sed "1!G;h;$!d" >rename.sed -grep "^and \([a-z][a-zA-Z_]*\) = \([a-z][a-zA-Z_]* option*\)$" z3V3.mli | sed "s|and \([a-zA-Z_]*\) = \([ a-zA-Z_0-9]*\)|s/\1/\2/g|g" >>rename.sed -move >NUL z3V3.mli z3V3.3.mli && sed -f rename.sed z3V3.3.mli >z3V3.mli && del z3V3.3.mli -move >NUL z3V3.ml z3V3.3.ml && sed -f rename.sed z3V3.3.ml >z3V3.ml && del z3V3.3.ml -del rename.sed - -REM remove cyclic definitions introduced by substituting type equations -move >NUL z3V3.mli z3V3.4.mli && sed "s/^and \([a-z][a-zA-Z_ ]*\) = \1$//g" z3V3.4.mli >z3V3.mli && del z3V3.4.mli -move >NUL z3V3.ml z3V3.4.ml && sed "s/^and \([a-z][a-zA-Z_ ]*\) = \1$//g" z3V3.4.ml >z3V3.ml && del z3V3.4.ml -move >NUL z3.mli z3.4.mli && sed "s/^and \([a-z][a-zA-Z_ ]*\) = \1$//g" z3.4.mli >z3.mli && del z3.4.mli -move >NUL z3.ml z3.4.ml && sed "s/^and \([a-z][a-zA-Z_ ]*\) = \1$//g" z3.4.ml >z3.ml && del z3.4.ml - -REM append Z3.V3 module onto Z3 module -type z3V3.ml >> z3.ml -type z3V3.mli >> z3.mli -sed "1,22d" z3V3_stubs.c >> z3_stubs.c -del /q 2>NUL z3V3_api.idl z3V3.ml z3V3.mli z3V3_stubs.c diff --git a/src/api/ml/old/generate_mlapi.sh b/src/api/ml/old/generate_mlapi.sh deleted file mode 100755 index dd8692833..000000000 --- a/src/api/ml/old/generate_mlapi.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -# Script to generate the Z3 OCaml API -# -# Assumes that environment variables are set to provide access to the following commands: camlidl, gcc, grep, sed -# -# This script uses 'gcc -E' as the C preprocessor, other C preprocessors may work but have not been tested. -# -# Invoke with "-DUNSAFE_ERRORS" to build version that does not support recoverable errors, but avoids some error-checking overhead. -# Invoke with "-DLEAK_CONTEXTS" to build version that leaks Z3_context objects, but avoids some garbage-collection overhead. - - -# add calls to error checking routine -# convert from doxygen to ocamldoc markup and other syntactic munging -# ../z3_api.h -> z3V3_api.idl -sed -f add_error_checking.V3.sed -f preprocess.sed ../z3_api.h > z3V3_api.idl - -# z3.idl (z3V3_api.idl x3V3.mli x3V3.ml) -> z3V3_stubs.c, z3V3.mli, z3V3.ml -gcc -E -w -P -CC -xc -DCAMLIDL -DMLAPIV3 $@ z3.0.idl > z3V3.idl -camlidl -nocpp z3V3.idl - -# reverse.sed to reverse order of substitution of enums to avoid matching prefixes such as enum_1 of enum_10 -grep "^and z3_[a-zA-Z0-9_]* = [a-z][a-zA-Z0-9_]*$" z3V3.mli | sed -e "s|and z3_\([a-zA-Z0-9_]*\) = \([a-zA-Z0-9_]*\)|s/\2/\1/g|g" -f reverse.sed > /tmp/renameV3.sed -grep "^and z3_[a-zA-Z0-9_]* = [a-z][a-zA-Z0-9_ ]* option$" z3V3.mli | sed -e "s|and \(z3_[a-zA-Z0-9_]*\) = \([a-zA-Z0-9_ ]*\)|s/\1/\2/g|g" >> /tmp/renameV3.sed - -# rename.sed to substitute out type equations for enums and options, then postprocess -cp -f z3V3.mli z3V3.ml /tmp -sed -f /tmp/renameV3.sed -f postprocess.sed /tmp/z3V3.mli > z3V3.mli -sed -f /tmp/renameV3.sed -f postprocess.sed /tmp/z3V3.ml > z3V3.ml - -# ../z3_api.h -> z3_api.idl -sed -f add_error_checking.sed -f preprocess.sed ../z3_api.h > z3_api.idl - -# z3.idl (z3_api.idl x3.ml) -> z3_stubs.c, z3.mli, z3.ml -gcc -E -w -P -CC -xc -I. -DCAMLIDL $@ z3.0.idl > z3.idl -camlidl -nocpp z3.idl - -# reverse.sed to reverse order of substitution of enums to avoid matching prefixes such as enum_1 of enum_10 -grep "^and z3_[a-zA-Z0-9_]* = [a-z][a-zA-Z0-9_]*$" z3.mli | sed -e "s|and z3_\([a-zA-Z0-9_]*\) = \([a-zA-Z0-9_]*\)|s/\2/\1/g|g" -f reverse.sed > /tmp/rename.sed -grep "^and z3_[a-zA-Z0-9_]* = [a-z][a-zA-Z0-9_ ]* option$" z3.mli | sed -e "s|and \(z3_[a-zA-Z0-9_]*\) = \([a-zA-Z0-9_ ]*\)|s/\1/\2/g|g" >> /tmp/rename.sed - -# rename.sed to substitute out type equations for enums and options, then postprocess -cp z3.mli z3.ml /tmp -sed -f /tmp/rename.sed -f postprocess.sed /tmp/z3.mli > z3.mli -sed -f /tmp/rename.sed -f postprocess.sed /tmp/z3.ml > z3.ml - - -# append Z3.V3 module onto Z3 module -cat z3V3.mli >> z3.mli -cat z3V3.ml >> z3.ml -sed "1,22d" z3V3_stubs.c >> z3_stubs.c - -rm -f z3V3_api.idl z3V3.idl z3V3.ml z3V3.mli z3V3_stubs.c z3_api.idl z3.idl diff --git a/src/api/ml/old/import.cmd b/src/api/ml/old/import.cmd deleted file mode 100755 index b5239e011..000000000 --- a/src/api/ml/old/import.cmd +++ /dev/null @@ -1,55 +0,0 @@ -@echo off -SETLOCAL - -:CHECKARG1 -if not "%1"=="" ( - set SDTROOT=%1 - goto :CHECKARG2 -) - -goto :FAIL - - -:CHECKARG2 -if "%2"=="" ( - goto :IMPORT -) - -goto :FAIL - - -:IMPORT -cd import -sd edit ... -del z3.h z3_api.h z3_macros.h z3lib.lib msbig_rational.lib z3.exe test_capi.c test_mlapi_header.html z3_mlapi_header.html mldoc_footer.html tabs.css z3.png z3_ml.css -copy %SDTROOT%\lib\z3.h -copy %SDTROOT%\lib\z3_api.h -copy %SDTROOT%\lib\z3_macros.h -copy %SDTROOT%\release_mt\z3lib.lib -copy %SDTROOT%\release_mt\msbig_rational.lib -copy %SDTROOT%\release_mt\z3.exe -copy %SDTROOT%\test_capi\test_capi.c -copy %SDTROOT%\doc\test_mlapi_header.html -copy %SDTROOT%\doc\z3_mlapi_header.html -copy %SDTROOT%\doc\mldoc_footer.html -copy %SDTROOT%\doc\html\tabs.css -copy %SDTROOT%\doc\z3.png -copy %SDTROOT%\doc\z3_ml.css -sd add ... -sd revert -a ... -cd .. -goto :END - -:FAIL -echo "Usage:" -echo " %0 SDTROOT" -echo "" -echo "Examples:" -echo " %0 \\risebuild\drops\z32\2.0.51220.7" -echo " %0 \\risebuild\drops\z32\latest" -echo " %0 J:\SD\other\sdt1\src\z3_2" -echo "" -goto :END - -:END -ENDLOCAL diff --git a/src/api/ml/old/mlx_get_app_args.idl b/src/api/ml/old/mlx_get_app_args.idl deleted file mode 100644 index fe3407af8..000000000 --- a/src/api/ml/old/mlx_get_app_args.idl +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ get_app_args c a ] \] is the array of arguments of an application. If [t] is a constant, then the array is empty. - - - {b See also}: {!get_app_num_args} - - {b See also}: {!get_app_arg} -*) -val get_app_args: context -> app -> ast array -"); diff --git a/src/api/ml/old/mlx_get_array_sort.idl b/src/api/ml/old/mlx_get_array_sort.idl deleted file mode 100644 index 81bf6e00f..000000000 --- a/src/api/ml/old/mlx_get_array_sort.idl +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ get_array_sort c t ] \] is the domain and the range of [t]. - - - {b See also}: {!get_array_sort_domain} - - {b See also}: {!get_array_sort_range} -*) -val get_array_sort: context -> sort -> sort * sort -"); diff --git a/src/api/ml/old/mlx_get_datatype_sort.idl b/src/api/ml/old/mlx_get_datatype_sort.idl deleted file mode 100644 index 3466a9050..000000000 --- a/src/api/ml/old/mlx_get_datatype_sort.idl +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ get_datatype_sort c ty ] \] is the array of triples [(constructor, recognizer, fields)] where [constructor] is the constructor declaration of [ty], [recognizer] is the recognizer for the [constructor], and [fields] is the array of fields in [ty]. - - - {b See also}: {!get_datatype_sort_num_constructors} - - {b See also}: {!get_datatype_sort_constructor} - - {b See also}: {!get_datatype_sort_recognizer} - - {b See also}: {!get_datatype_sort_constructor_accessor} -*) -val get_datatype_sort: context -> sort -> datatype_constructor array -"); diff --git a/src/api/ml/old/mlx_get_domains.idl b/src/api/ml/old/mlx_get_domains.idl deleted file mode 100644 index ebc6d8556..000000000 --- a/src/api/ml/old/mlx_get_domains.idl +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ get_domains c d ] \] is the array of parameters of [d]. - - - {b See also}: {!get_domain_size} - - {b See also}: {!get_domain} -*) -val get_domains: context -> func_decl -> sort array -"); diff --git a/src/api/ml/old/mlx_get_error_msg.idl b/src/api/ml/old/mlx_get_error_msg.idl deleted file mode 100644 index b8ea97e03..000000000 --- a/src/api/ml/old/mlx_get_error_msg.idl +++ /dev/null @@ -1,6 +0,0 @@ -quote(mli," -(** - Summary: Return a string describing the given error code. -*) -val get_error_msg: context -> error_code -> string -"); diff --git a/src/api/ml/old/mlx_get_pattern_terms.idl b/src/api/ml/old/mlx_get_pattern_terms.idl deleted file mode 100644 index 749a90f3a..000000000 --- a/src/api/ml/old/mlx_get_pattern_terms.idl +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ get_pattern_terms c p ] \] is the ast's in pattern. - - - {b See also}: {!get_pattern_num_terms} - - {b See also}: {!get_pattern} -*) -val get_pattern_terms: context -> pattern -> ast array;; -"); diff --git a/src/api/ml/old/mlx_get_tuple_sort.idl b/src/api/ml/old/mlx_get_tuple_sort.idl deleted file mode 100644 index 1555f6c8a..000000000 --- a/src/api/ml/old/mlx_get_tuple_sort.idl +++ /dev/null @@ -1,12 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ get_tuple_sort c ty ] \] is the pair [(mk_decl, fields)] where [mk_decl] is the constructor declaration of [ty], and [fields] is the array of fields in [ty]. - - - {b See also}: {!get_tuple_sort_mk_decl} - - {b See also}: {!get_tuple_sort_num_fields} - - {b See also}: {!get_tuple_sort_field_decl} -*) -val get_tuple_sort: context -> sort -> (func_decl * func_decl array) -"); diff --git a/src/api/ml/old/mlx_mk_context_x.idl b/src/api/ml/old/mlx_mk_context_x.idl deleted file mode 100644 index 7e4fd25c9..000000000 --- a/src/api/ml/old/mlx_mk_context_x.idl +++ /dev/null @@ -1,36 +0,0 @@ -quote(mlmli,"external mk_context: (string * string) list -> context = \"caml_z3_mk_context\" -"); -// Note: lack of whitespace and comments in the previous 2 lines is important for the documentation generation -quote(c," -value caml_z3_mk_context(value key_val_list) -{ - CAMLparam1( key_val_list ); - CAMLlocal4( item, vkey, vval, _vres ); - char * ckey; - char * cval; - Z3_config cfg; - Z3_context _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - - cfg = Z3_mk_config(); - - while (key_val_list != Val_emptylist) - { - item = Field(key_val_list, 0); - vkey = Field(item, 0); - vval = Field(item, 1); - ckey = camlidl_malloc_string(vkey, _ctx); - cval = camlidl_malloc_string(vval, _ctx); - Z3_set_param_value(cfg, ckey, cval); - key_val_list = Field(key_val_list, 1); - } - - _res = Z3_mk_context_rc(cfg); - Z3_del_config(cfg); - _vres = camlidl_c2ml_z3_Z3_context(&_res, _ctx); - camlidl_free(_ctx); - Z3_set_error_handler(_res, error_handler_static); - CAMLreturn(_vres); -} -"); diff --git a/src/api/ml/old/mlx_mk_datatypes.idl b/src/api/ml/old/mlx_mk_datatypes.idl deleted file mode 100644 index 21bdcdbc7..000000000 --- a/src/api/ml/old/mlx_mk_datatypes.idl +++ /dev/null @@ -1,28 +0,0 @@ -quote(mlmli," -(** A constructor of a datatype is described by: *) -type datatype_constructor_desc = { - constructor_desc : symbol; (** name of the constructor function *) - recognizer_desc : symbol; (** name of the recognizer function *) - accessor_descs : (symbol * sort) array; (** names and sorts of the fields *) -} - -(** A datatype is described by a name and constructor descriptors. *) -type datatype_desc = symbol * datatype_constructor_desc array - -(** A constructor of a datatype is represented by: *) -type datatype_constructor = { - constructor : func_decl; (** constructor function *) - recognizer : func_decl; (** recognizer function *) - accessors : func_decl array; (** field accessor functions *) -} - -(** A datatype is represented by a sort and constructors. *) -type datatype = sort * datatype_constructor array -"); - -quote(mli," -(** [mk_datatypes ctx sorts_to_descriptors] creates mutually recursive datatypes described by - [sorts_to_descriptors], which is a function from the sorts of the datatypes to be created to - descriptors of the datatypes' constructors. {b See also}: {!Test_mlapi.forest_example} *) -val mk_datatypes: context -> (sort array -> (datatype_desc array) option) -> datatype array -"); diff --git a/src/api/ml/old/mlx_mk_numeral.idl b/src/api/ml/old/mlx_mk_numeral.idl deleted file mode 100644 index 0fa9caf39..000000000 --- a/src/api/ml/old/mlx_mk_numeral.idl +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mlmli," -(** - Summary: \[ [ numeral_refined ] \] is the refined view of a numeral . -*) -type numeral_refined = - | Numeral_int of int * sort - | Numeral_int64 of int64 * sort - | Numeral_large of string * sort - | Numeral_rational of numeral_refined * numeral_refined -"); - -quote(mli," -(** - Summary: \[ [ embed_numeral c nr ] \] constructs the numeral described by [nr]. - - - {b See also}: {!numeral_refine} -*) -val embed_numeral: context -> numeral_refined -> ast -"); diff --git a/src/api/ml/old/mlx_mk_sort.idl b/src/api/ml/old/mlx_mk_sort.idl deleted file mode 100644 index dd4222f81..000000000 --- a/src/api/ml/old/mlx_mk_sort.idl +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mlmli," -(** - A datatype constructor descriptor. -*) -type datatype_constructor_desc = { - constructor_desc : symbol; (** name of the constructor function *) - recognizer_desc : symbol; (** name of the recognizer function *) - accessor_descs : (symbol * sort) array; (** names and sorts of the fields *) -} - -(** - A datatype is described by a name and constructor descriptors. -*) -type datatype_desc = symbol * datatype_constructor_desc array - -(** - A datatype constructor representation. -*) -type datatype_constructor = { - constructor : func_decl; (** constructor function *) - recognizer : func_decl; (** recognizer function *) - accessors : func_decl array; (** field accessor functions *) -} - -(** - A datatype is represented by a sort and constructors. -*) -type datatype = sort * datatype_constructor array - -(** - Refined view of a {!sort}. - - - {b See also}: {!mk_sort} - - {b See also}: {!sort_refine} -*) -type sort_refined = - | Sort_uninterpreted of symbol - | Sort_bool - | Sort_int - | Sort_bv of int - | Sort_finite_domain of symbol * int64 - | Sort_real - | Sort_array of sort * sort - | Sort_datatype of datatype_constructor array - | Sort_relation of sort array - | Sort_unknown -"); - -quote(mli," -(** - Summary: \[ [ mk_sort c sr ] \] constructs the sort described by [sr]. - - - {b Precondition}: [sr] is not of form [Sort_relation] or [Sort_unknown], which cannot be directly constructed - - {b See also}: {!mk_datatypes} - - {b See also}: {!sort_refine} -*) -val mk_sort: context -> sort_refined -> sort - -(** - \[ [mk_datatypes ctx sorts_to_descriptors] \] creates mutually recursive datatypes described by - [sorts_to_descriptors], which is a function from the sorts of the datatypes to be created to - descriptors of the datatypes' constructors. - - - {b See also}: {!Test_mlapi.forest_example} -*) -val mk_datatypes: context -> (sort array -> (datatype_desc array) option) -> datatype array -"); diff --git a/src/api/ml/old/mlx_mk_symbol.idl b/src/api/ml/old/mlx_mk_symbol.idl deleted file mode 100644 index 6969c7380..000000000 --- a/src/api/ml/old/mlx_mk_symbol.idl +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mlmli," -(** - Refined view of a {!symbol}. - - - {b See also}: {!mk_symbol} - - {b See also}: {!symbol_refine} -*) -type symbol_refined = - | Symbol_int of int - | Symbol_string of string -"); - -quote(mli," -(** - Summary: \[ [ mk_symbol c sr ] \] constructs the symbol described by [sr]. - - - {b See also}: {!symbol_refine} -*) -val mk_symbol: context -> symbol_refined -> symbol -"); diff --git a/src/api/ml/old/mlx_model.idl b/src/api/ml/old/mlx_model.idl deleted file mode 100644 index 192a982b3..000000000 --- a/src/api/ml/old/mlx_model.idl +++ /dev/null @@ -1,19 +0,0 @@ -quote(mlmli," -(** - A model assigns uninterpreted sorts to finite universes of distinct values, constants to values, - and arrays and functions to finite maps from argument values to result values plus a default - value for all other arguments. -*) -type model_refined = { - sorts : (sort, ast_vector) Hashtbl.t; - consts : (func_decl, ast) Hashtbl.t; - arrays : (func_decl, (ast, ast) Hashtbl.t * ast) Hashtbl.t; - funcs : (func_decl, (ast array, ast) Hashtbl.t * ast) Hashtbl.t; -} -"); -quote(mli," -(** - Summary: [model_refine c m] is the refined model of [m]. -*) -val model_refine : context -> model -> model_refined -"); diff --git a/src/api/ml/old/mlx_numeral_refine.idl b/src/api/ml/old/mlx_numeral_refine.idl deleted file mode 100644 index 8b2f0a07f..000000000 --- a/src/api/ml/old/mlx_numeral_refine.idl +++ /dev/null @@ -1,10 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ numeral_refine c a ] \] is the refined view of [a]. - - - {b Precondition}: [get_ast_kind c a = NUMERAL_AST] -*) -val numeral_refine : context -> ast -> numeral_refined -"); diff --git a/src/api/ml/old/mlx_parse_smtlib.idl b/src/api/ml/old/mlx_parse_smtlib.idl deleted file mode 100644 index dbc2e42da..000000000 --- a/src/api/ml/old/mlx_parse_smtlib.idl +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ parse_smtlib_string_x c str sort_names sorts decl_names decls ] \] - - 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 [sort_names] and [decl_names] don't need to match the names - of the sorts and declarations in the arrays [sorts] and [decls]. This is an useful feature - since we can use arbitrary names to reference sorts and declarations defined using the API. - - - {b See also}: {!parse_smtlib_file_x} -*) -val parse_smtlib_string_x: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> (ast array * ast array * func_decl array) - -(** - Summary: Similar to {!parse_smtlib_string_x}, but reads the benchmark from a file. - - - {b See also}: {!parse_smtlib_string_x} -*) -val parse_smtlib_file_x: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> (ast array * ast array * func_decl array) - -(** - Summary: \[ [ parse_smtlib_string_formula c ... ] \] calls [(parse_smtlib_string c ...)] and returns the single formula produced. - - - {b See also}: {!parse_smtlib_file_formula} - - {b See also}: {!parse_smtlib_string_x} -*) -val parse_smtlib_string_formula: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - -(** - Summary: \[ [ parse_smtlib_file_formula c ... ] \] calls [(parse_smtlib_file c ...)] and returns the single formula produced. - - - {b See also}: {!parse_smtlib_string_formula} - - {b See also}: {!parse_smtlib_file_x} -*) -val parse_smtlib_file_formula: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast -"); diff --git a/src/api/ml/old/mlx_sort_refine.idl b/src/api/ml/old/mlx_sort_refine.idl deleted file mode 100644 index 1f2ba8eab..000000000 --- a/src/api/ml/old/mlx_sort_refine.idl +++ /dev/null @@ -1,8 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ sort_refine c s ] \] is the refined view of [s]. -*) -val sort_refine: context -> sort -> sort_refined -"); diff --git a/src/api/ml/old/mlx_statistics.idl b/src/api/ml/old/mlx_statistics.idl deleted file mode 100644 index 47028f012..000000000 --- a/src/api/ml/old/mlx_statistics.idl +++ /dev/null @@ -1,10 +0,0 @@ -quote(mlmli," -type stat_datum = Stat_int of int | Stat_float of float -type stats_refined = (string, stat_datum) Hashtbl.t -"); -quote(mli," -(** - Summary: [stats_refine c s] is the refined stats of [s]. -*) -val stats_refine : context -> stats -> stats_refined -"); diff --git a/src/api/ml/old/mlx_symbol_refine.idl b/src/api/ml/old/mlx_symbol_refine.idl deleted file mode 100644 index 0d74e9cd9..000000000 --- a/src/api/ml/old/mlx_symbol_refine.idl +++ /dev/null @@ -1,8 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mli," -(** - Summary: \[ [ symbol_refine c s ] \] is the refined view of [s]. -*) -val symbol_refine: context -> symbol -> symbol_refined -"); diff --git a/src/api/ml/old/mlx_term_refine.idl b/src/api/ml/old/mlx_term_refine.idl deleted file mode 100644 index 2fa8fd36f..000000000 --- a/src/api/ml/old/mlx_term_refine.idl +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote(mlmli," -(** - Summary: \[ [ binder_type ] \] is a universal or existential quantifier. - - - {b See also}: {!term_refined} -*) -type binder_type = Forall | Exists - -(** - Summary: \[ [ term_refined ] \] is the refinement of a {!ast} . - - - {b See also}: {!term_refine} -*) -type term_refined = - | Term_numeral of numeral_refined - | Term_app of decl_kind * func_decl * ast array - | Term_quantifier of binder_type * int * ast array array * (symbol * sort) array * ast - | Term_var of int * sort -"); - -quote(mli," -(** - Summary: \[ [ mk_term c tr ] \] constructs the term described by [tr]. - - - {b Precondition}: [tr] is not of form - - {b See also}: {!term_refine} -*) -(* val mk_term: context -> term_refined -> ast *) - - -(** - Summary: \[ [ term_refine c a ] \] is the refined view of [a]. -*) -val term_refine : context -> ast -> term_refined -"); diff --git a/src/api/ml/old/postprocess.sed b/src/api/ml/old/postprocess.sed deleted file mode 100644 index f25f70cb7..000000000 --- a/src/api/ml/old/postprocess.sed +++ /dev/null @@ -1,8 +0,0 @@ -# remove 'z3_' and 'Z3_' prefixes on names - -s/{\!Z3\./{\!/g -s/\([^_]\)[zZ]3_/\1/g - -# remove cyclic definitions introduced by substituting type equations - -s/^and \([a-z][a-zA-Z_ ]*\) = \1$//g diff --git a/src/api/ml/old/preprocess.sed b/src/api/ml/old/preprocess.sed deleted file mode 100644 index c7d1fc804..000000000 --- a/src/api/ml/old/preprocess.sed +++ /dev/null @@ -1,82 +0,0 @@ -# attempt to clean up the mess with 'unsigned' -s/ unsigned/ unsigned int/g -s/unsigned int long/unsigned long/g -s/unsigned int __/unsigned __/g - - -# '@name ' -> 'Section: ' -# '\sa ' -> 'See also: ' -# '\brief ' -> 'Summary: ' -# '\remark ' -> 'Remark: ' -# '\pre ' -> 'Precondition: ' -# '\param ' -> '@param' -# '\warning ' -> 'Warning: ' -# '\code' -> 'C Example:' -# '\endcode' -> '' -/\\pre/s/(/ /g;/\\pre/s/,//g;/\\pre/s/)//g;s/\\pre /- {b Precondition}: /g -/\\ccode/s/(/ /g;/\\ccode/s/\\,//g;/\\ccode/s/)//g;s/\\ccode{\(.*\)}/\[\1\]/g -s/\\defgroup .*//g -s/@name \(.*\)/{2 {L \1}}/g -s/\\sa \(.*\)/- {b See also}: {!Z3.\1}/g -s/\\see \(.*\)/- {b See}: {!Z3.\1}/g -s//{e /g -s|| }|g -s/\\nicebox{/{e/g -s/\\brief /Summary: /g -s/\\remark /- {b Remarks}: /g -s/\\pre /- {b Precondition}: /g -s/\\param /@param /g -s/\\conly .*//g -s/\\warning /- {b Warning}: /g -s/\\code/{v /g -s/\\endcode/ v}/g -s/\\verbatim/{v /g -s/\\endverbatim/ v}/g -s/\\mlonly//g -s/\\endmlonly//g -s/\\mlh/\\\[ \[/g -s/\\endmlh/\] \\\]/g -s/\\deprecated/@deprecated/g -s/\\ / /g - -# '\c code ' -> '[code]' -s/\\c \([^ .,:]*\)/[\1]/g - -# '#Z3_' -> 'Z3.' -s/#Z3_\([^ \.,) ]*\)/{!Z3.\1}/g - -# '/*@}*/' -> '' -s/\/\*@{\*\///g - -# '/*@{*/' -> '' -s/\/\*@}\*\///g - -# '/*...*/' -> '' -s/\/\*.*\*\///g - -s|(\*\*/\*\*)|(\*\*%\*\*)|g - -# '/**' -> 'quote(mli,"(**' -s|/\*\*|quote(mli,\"(**|g - -# '...*/' -> '*)");' -s|[ ]*\*/|*)\");|g - -s|(\*\*%\*\*)|(\*\*/\*\*)|g - -# 'extern "C"' -> 'extern ~~C~~' -# 'quote(foo,"bar")' -> quote(foo,~~bar~~) -# mltype("foo") -> mltype(~~foo~~) -s/extern \"C\"/extern ~~C~~/g -s/quote(\(.*\),\"\(.*\)\")/quote(\1,~~\2~~)/g -s/quote(\(.*\),\"/quote(\1,~~/g -s/\")\;/~~);/g -s/\;\"/;~~/g -s/mltype(\"\(.*\)\")/mltype(~~\1~~)/g - -# '"' -> '\"' -s/\\\"/\"/g -s/\"/\\\"/g - -# '~~' -> '"' -s/~~/\"/g diff --git a/src/api/ml/old/queen.ml b/src/api/ml/old/queen.ml deleted file mode 100644 index e22db9cfb..000000000 --- a/src/api/ml/old/queen.ml +++ /dev/null @@ -1,112 +0,0 @@ -(* - queen.exe - JakobL@2007-09-22 - - Demonstration of how Z3 can be used to find solutions to the - N-Queens problem. - - See: http://en.wikipedia.org/wiki/Eight_queens_puzzle - - Problem specification: Is the following constraint system satisfiable, - for increasing n>=1, what are the models? - - constant - n: 8; - - variable - row: array n of [0..n-1]; - - rule - forall i in [0..n-2]: - (forall j in [i+1..n-1]: - ((row[i] <> row[j]) and - (i+row[i]) <> (j+row[j]) and - (i+row[j]) <> (j+row[i]))); - - The answer is yes for n different from 2 and 3. The number of solutions are: - * n=1: 1 - * n=2: 0 - * n=3: 0 - * n=4: 2 - * n=5: 10 - * n=6: 4 - * n=7: 40 - * n=8: 92 - * n=9: 352 - * n=10: 724 - ... -*) - -module Z3 = Z3.V3 - -(* Auxillary functions *) -let ( |> ) x f = f x;; -let printf = Printf.printf;; -let mk_var ctx name ty = Z3.mk_const ctx (Z3.mk_int_symbol ctx name) ty;; -let mk_int_var ctx name = Z3.mk_int_sort ctx |> mk_var ctx name;; -let mk_int ctx v = Z3.mk_int ctx v (Z3.mk_int_sort ctx);; -let checkreturn v = match v with | (true,r) -> r | _ -> failwith "checkreturn";; -let get_numeral_value_int a1 a2 = Z3.get_numeral_int a1 a2 |> checkreturn;; -let iterate_x lower upper f = for i = lower to upper do f i done;; -let forall_x ctx lower upper f = Z3.mk_and ctx (Array.init (1+upper-lower) (fun i->f (i+lower))) -let exist_x ctx lower upper f = Z3.mk_or ctx (Array.init (1+upper-lower) (fun i->f (i+lower))) -let get_value ctx model f = let (ok, v) = Z3.eval_func_decl ctx model f in (assert ok; v) - -let queen_n n = - let ctx = Z3.mk_context_x - [|("MODEL","true"); - ("RELEVANCY","0")|] in - let ( &&& ) x y = Z3.mk_and ctx [|x;y|] in - let ( <~> ) x y = Z3.mk_not ctx (Z3.mk_eq ctx x y) in - let ( <<= ) x y = Z3.mk_le ctx x y in - let ( +++ ) x y = Z3.mk_add ctx [|x;y|] in - let row = Array.init n (fun i->mk_int_var ctx i) in - let c x = mk_int ctx x in (* make constant *) - let v x = row.(x) in (* make variable *) - let constraint_domain=forall_x ctx (0) (n-1) (fun x-> ((c 0) <<= (v x)) &&& ((v x) <<= (c (n-1)))) in - let constraint_queen= - forall_x ctx (0) (n-2) (fun i-> - forall_x ctx (i+1) (n-1) (fun j-> - ((v i) <~> (v j)) &&& - (((c i)+++(v i)) <~> ((c j)+++(v j))) &&& - (((c i)+++(v j)) <~> ((c j)+++(v i))) - ) - ) in - let res = constraint_domain &&& constraint_queen in - Z3.assert_cnstr ctx res; - let rec f i = - (match Z3.check_and_get_model ctx with - | (Z3.L_FALSE,_) -> - printf "queen %d, total models: %d\n" n i; - flush stdout; - | (Z3.L_UNDEF,_) -> failwith "Z3.L_UNDEF" - | (Z3.L_TRUE,model) -> - begin - let model_constants=Z3.get_model_constants ctx model in - let vars=Array.map (fun mc->Z3.mk_app ctx mc [||]) model_constants in - let vals=Array.map (fun mc->get_value ctx model mc |> get_numeral_value_int ctx) model_constants in - Z3.del_model ctx model; - - let line = String.make n '-' in - let q_line i = let r = String.make n ' ' in String.set r i 'Q'; r in - printf "queen %d, model #%d:\n" n (i+1); - printf "\n"; - printf " /%s\\\n" line; - iterate_x 0 (n-1) (fun x->printf " |%s|\n" (q_line (vals.(x)))); - printf " \\%s/\n" line; - printf "\n"; - flush stdout; - let negated_model = exist_x ctx 0 (n-1) (fun x->(vars.(x)) <~> (c (vals.(x)))) in - Z3.assert_cnstr ctx negated_model; - f (i+1); - end - ) in - f 0; - Z3.del_context ctx; - ();; - -let queen() = - for n = 1 to 8 do - queen_n n - done;; - -let _ = queen();; diff --git a/src/api/ml/old/queen.regress.err b/src/api/ml/old/queen.regress.err deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/api/ml/old/queen.regress.out b/src/api/ml/old/queen.regress.out deleted file mode 100644 index 30e713386..000000000 --- a/src/api/ml/old/queen.regress.out +++ /dev/null @@ -1,1852 +0,0 @@ -queen 1, model #1: - - /-\ - |Q| - \-/ - -queen 1, total models: 1 -queen 2, total models: 0 -queen 3, total models: 0 -queen 4, model #1: - - /----\ - | Q | - | Q| - |Q | - | Q | - \----/ - -queen 4, model #2: - - /----\ - | Q | - |Q | - | Q| - | Q | - \----/ - -queen 4, total models: 2 -queen 5, model #1: - - /-----\ - | Q | - | Q | - |Q | - | Q | - | Q| - \-----/ - -queen 5, model #2: - - /-----\ - | Q | - | Q| - | Q | - |Q | - | Q | - \-----/ - -queen 5, model #3: - - /-----\ - | Q| - | Q | - |Q | - | Q | - | Q | - \-----/ - -queen 5, model #4: - - /-----\ - |Q | - | Q | - | Q | - | Q| - | Q | - \-----/ - -queen 5, model #5: - - /-----\ - | Q | - | Q| - | Q | - | Q | - |Q | - \-----/ - -queen 5, model #6: - - /-----\ - | Q | - |Q | - | Q | - | Q| - | Q | - \-----/ - -queen 5, model #7: - - /-----\ - | Q| - | Q | - | Q | - |Q | - | Q | - \-----/ - -queen 5, model #8: - - /-----\ - | Q | - | Q | - | Q| - | Q | - |Q | - \-----/ - -queen 5, model #9: - - /-----\ - |Q | - | Q | - | Q| - | Q | - | Q | - \-----/ - -queen 5, model #10: - - /-----\ - | Q | - |Q | - | Q | - | Q | - | Q| - \-----/ - -queen 5, total models: 10 -queen 6, model #1: - - /------\ - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - \------/ - -queen 6, model #2: - - /------\ - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - \------/ - -queen 6, model #3: - - /------\ - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - \------/ - -queen 6, model #4: - - /------\ - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - \------/ - -queen 6, total models: 4 -queen 7, model #1: - - /-------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - \-------/ - -queen 7, model #2: - - /-------\ - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - \-------/ - -queen 7, model #3: - - /-------\ - | Q | - | Q | - | Q| - | Q | - | Q | - | Q | - |Q | - \-------/ - -queen 7, model #4: - - /-------\ - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - \-------/ - -queen 7, model #5: - - /-------\ - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - \-------/ - -queen 7, model #6: - - /-------\ - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - | Q | - \-------/ - -queen 7, model #7: - - /-------\ - | Q | - | Q| - | Q | - | Q | - | Q | - |Q | - | Q | - \-------/ - -queen 7, model #8: - - /-------\ - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - \-------/ - -queen 7, model #9: - - /-------\ - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - \-------/ - -queen 7, model #10: - - /-------\ - |Q | - | Q | - | Q | - | Q | - | Q | - | Q| - | Q | - \-------/ - -queen 7, model #11: - - /-------\ - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - \-------/ - -queen 7, model #12: - - /-------\ - |Q | - | Q | - | Q | - | Q | - | Q| - | Q | - | Q | - \-------/ - -queen 7, model #13: - - /-------\ - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - | Q | - \-------/ - -queen 7, model #14: - - /-------\ - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \-------/ - -queen 7, model #15: - - /-------\ - | Q | - |Q | - | Q | - | Q | - | Q | - | Q | - | Q| - \-------/ - -queen 7, model #16: - - /-------\ - | Q | - |Q | - | Q | - | Q | - | Q | - | Q| - | Q | - \-------/ - -queen 7, model #17: - - /-------\ - | Q | - |Q | - | Q | - | Q | - | Q | - | Q| - | Q | - \-------/ - -queen 7, model #18: - - /-------\ - | Q | - |Q | - | Q | - | Q | - | Q | - | Q| - | Q | - \-------/ - -queen 7, model #19: - - /-------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - \-------/ - -queen 7, model #20: - - /-------\ - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \-------/ - -queen 7, model #21: - - /-------\ - | Q | - |Q | - | Q | - | Q | - | Q | - | Q| - | Q | - \-------/ - -queen 7, model #22: - - /-------\ - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - \-------/ - -queen 7, model #23: - - /-------\ - | Q | - | Q | - |Q | - | Q | - | Q | - | Q | - | Q| - \-------/ - -queen 7, model #24: - - /-------\ - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - \-------/ - -queen 7, model #25: - - /-------\ - | Q| - | Q | - | Q | - | Q | - |Q | - | Q | - | Q | - \-------/ - -queen 7, model #26: - - /-------\ - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - \-------/ - -queen 7, model #27: - - /-------\ - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - \-------/ - -queen 7, model #28: - - /-------\ - | Q | - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - \-------/ - -queen 7, model #29: - - /-------\ - | Q| - | Q | - | Q | - | Q | - | Q | - |Q | - | Q | - \-------/ - -queen 7, model #30: - - /-------\ - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - \-------/ - -queen 7, model #31: - - /-------\ - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - \-------/ - -queen 7, model #32: - - /-------\ - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - \-------/ - -queen 7, model #33: - - /-------\ - | Q | - | Q| - | Q | - | Q | - | Q | - |Q | - | Q | - \-------/ - -queen 7, model #34: - - /-------\ - | Q | - | Q| - | Q | - | Q | - | Q | - |Q | - | Q | - \-------/ - -queen 7, model #35: - - /-------\ - | Q | - | Q| - | Q | - | Q | - | Q | - |Q | - | Q | - \-------/ - -queen 7, model #36: - - /-------\ - | Q | - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - \-------/ - -queen 7, model #37: - - /-------\ - | Q | - | Q| - | Q | - | Q | - | Q | - | Q | - |Q | - \-------/ - -queen 7, model #38: - - /-------\ - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - \-------/ - -queen 7, model #39: - - /-------\ - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - | Q | - \-------/ - -queen 7, model #40: - - /-------\ - | Q | - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - \-------/ - -queen 7, total models: 40 -queen 8, model #1: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #2: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - \--------/ - -queen 8, model #3: - - /--------\ - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #4: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - \--------/ - -queen 8, model #5: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - \--------/ - -queen 8, model #6: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q | - | Q | - | Q| - \--------/ - -queen 8, model #7: - - /--------\ - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #8: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - \--------/ - -queen 8, model #9: - - /--------\ - |Q | - | Q | - | Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #10: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #11: - - /--------\ - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #12: - - /--------\ - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #13: - - /--------\ - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #14: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - \--------/ - -queen 8, model #15: - - /--------\ - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #16: - - /--------\ - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #17: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #18: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - \--------/ - -queen 8, model #19: - - /--------\ - | Q | - | Q | - | Q | - | Q| - | Q | - | Q | - | Q | - |Q | - \--------/ - -queen 8, model #20: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #21: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - \--------/ - -queen 8, model #22: - - /--------\ - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #23: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - \--------/ - -queen 8, model #24: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #25: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #26: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #27: - - /--------\ - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #28: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #29: - - /--------\ - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #30: - - /--------\ - | Q | - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - \--------/ - -queen 8, model #31: - - /--------\ - | Q| - | Q | - | Q | - | Q | - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #32: - - /--------\ - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #33: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - \--------/ - -queen 8, model #34: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - \--------/ - -queen 8, model #35: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - \--------/ - -queen 8, model #36: - - /--------\ - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #37: - - /--------\ - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #38: - - /--------\ - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #39: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #40: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #41: - - /--------\ - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #42: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #43: - - /--------\ - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #44: - - /--------\ - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #45: - - /--------\ - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #46: - - /--------\ - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #47: - - /--------\ - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #48: - - /--------\ - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #49: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - \--------/ - -queen 8, model #50: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #51: - - /--------\ - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #52: - - /--------\ - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #53: - - /--------\ - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #54: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #55: - - /--------\ - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #56: - - /--------\ - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #57: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #58: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #59: - - /--------\ - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #60: - - /--------\ - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #61: - - /--------\ - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #62: - - /--------\ - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #63: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #64: - - /--------\ - | Q | - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - \--------/ - -queen 8, model #65: - - /--------\ - | Q | - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #66: - - /--------\ - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #67: - - /--------\ - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #68: - - /--------\ - | Q | - |Q | - | Q| - | Q | - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #69: - - /--------\ - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #70: - - /--------\ - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #71: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #72: - - /--------\ - | Q | - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #73: - - /--------\ - | Q | - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #74: - - /--------\ - | Q | - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - \--------/ - -queen 8, model #75: - - /--------\ - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - \--------/ - -queen 8, model #76: - - /--------\ - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #77: - - /--------\ - |Q | - | Q | - | Q | - | Q| - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #78: - - /--------\ - | Q | - |Q | - | Q | - | Q| - | Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #79: - - /--------\ - | Q | - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - \--------/ - -queen 8, model #80: - - /--------\ - | Q | - | Q | - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - \--------/ - -queen 8, model #81: - - /--------\ - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #82: - - /--------\ - | Q | - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - \--------/ - -queen 8, model #83: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - \--------/ - -queen 8, model #84: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q | - |Q | - | Q| - | Q | - \--------/ - -queen 8, model #85: - - /--------\ - | Q | - | Q | - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - \--------/ - -queen 8, model #86: - - /--------\ - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #87: - - /--------\ - | Q | - | Q | - | Q | - | Q | - |Q | - | Q | - | Q| - | Q | - \--------/ - -queen 8, model #88: - - /--------\ - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #89: - - /--------\ - | Q | - | Q| - | Q | - | Q | - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #90: - - /--------\ - | Q | - | Q | - | Q| - | Q | - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, model #91: - - /--------\ - | Q | - | Q | - | Q | - | Q | - |Q | - | Q | - | Q | - | Q| - \--------/ - -queen 8, model #92: - - /--------\ - | Q | - | Q | - | Q | - | Q| - |Q | - | Q | - | Q | - | Q | - \--------/ - -queen 8, total models: 92 diff --git a/src/api/ml/old/reverse.sed b/src/api/ml/old/reverse.sed deleted file mode 100644 index 31ac563d2..000000000 --- a/src/api/ml/old/reverse.sed +++ /dev/null @@ -1,3 +0,0 @@ -# output lines of input in reverse order - -1!G;h;$!d diff --git a/src/api/ml/old/test_mlapi.cmd b/src/api/ml/old/test_mlapi.cmd deleted file mode 100755 index 64315e3f7..000000000 --- a/src/api/ml/old/test_mlapi.cmd +++ /dev/null @@ -1,61 +0,0 @@ -@echo off -SETLOCAL - -REM Script to test the Z3 OCaml API -REM -REM Assumes that environment variables are set to provide access to the C and OCaml compilers, as well as the following commands: diff, dos2unix, sed - -REM directory containing z3_api.h -set Z3SRC=%1 - -REM directory containing z3.dll and z3.lib -set Z3BIN=%2 - -REM directory containing debug z3.dll -set Z3BINDBG=%3 - -set PATH=.;%2;%3;%PATH% - -echo Build test_capi -cl /nologo /I %Z3SRC% %Z3BIN%\z3.lib ..\test_capi\test_capi.c - -echo Build test_mlapi -ocamlc -w -a -o test_mlapi.byte.exe z3.cma test_mlapi.ml -ocamlopt -w -a -o test_mlapi.exe z3.cmxa test_mlapi.ml -ocamlc -g -w -a -o test_mlapi.byte.dbg.exe z3_dbg.cma test_mlapi.ml -ocamlopt -g -w -a -o test_mlapi.dbg.exe z3_dbg.cmxa test_mlapi.ml - -echo Build test_mlapiV3 -ocamlopt -g -w -a -o test_mlapiV3.dbg.exe z3_dbg.cmxa test_mlapiV3.ml - -echo Build test_theory -ocamlopt -g -w -a -o test_theory.dbg.exe z3_dbg.cmxa test_theory.ml - -echo Build queen -ocamlopt -g -w -a -o queen.exe z3_dbg.cmxa queen.ml - -echo Execute test_capi, test_mlapi, test_mlapiV3 and queen -test_capi.exe >test_capi.out 2>test_capi.orig.err -test_mlapi.dbg.exe >test_mlapi.out 2>test_mlapi.orig.err -test_mlapiV3.dbg.exe >test_mlapiV3.out 2>test_mlapiV3.orig.err -queen.exe >queen.out 2>queen.orig.err - -REM Strip pointers as they will always differ -sed test_capi.err "s/ \[.*\]/ [...]/g" -sed test_mlapi.err "s/ \[.*\]/ [...]/g" -sed test_mlapiV3.err "s/ \[.*\]/ [...]/g" -sed queen.err "s/ \[.*\]/ [...]/g" -del test_capi.orig.err test_mlapi.orig.err test_mlapiV3.orig.err queen.orig.err - -REM Compare with regressions -dos2unix *.out *.err 2>NUL -diff test_capi.regress.out test_capi.out >NUL || echo Regression failed, see: diff test_capi.regress.out test_capi.out -diff test_mlapi.regress.out test_mlapi.out >NUL || echo Regression failed, see: diff test_mlapi.regress.out test_mlapi.out -diff test_mlapiV3.regress.out test_mlapiV3.out >NUL || echo Regression failed, see: diff test_mlapiV3.regress.out test_mlapiV3.out -diff test_capi.regress.err test_capi.err >NUL || echo Regression failed, see: diff test_capi.regress.err test_capi.err -diff test_mlapi.regress.err test_mlapi.err >NUL || echo Regression failed, see: diff test_mlapi.regress.err test_mlapi.err -diff test_mlapiV3.regress.err test_mlapiV3.err >NUL || echo Regression failed, see: diff test_mlapiV3.regress.err test_mlapiV3.err -diff queen.regress.out queen.out >NUL || echo Regression failed, see: diff queen.regress.out queen.out -diff queen.regress.err queen.err >NUL || echo Regression failed, see: diff queen.regress.err queen.err - -ENDLOCAL diff --git a/src/api/ml/old/test_mlapi.ml b/src/api/ml/old/test_mlapi.ml deleted file mode 100644 index 149ae27f8..000000000 --- a/src/api/ml/old/test_mlapi.ml +++ /dev/null @@ -1,209 +0,0 @@ -(** Examples of using the OCaml API for Z3. *) - -(**/**) -(* pause documentation *) - -(* - @name Auxiliary Functions -*) - -(** - printf -*) -let printf = Printf.printf -;; - -(** - fprintf -*) -let fprintf = Printf.fprintf -;; - -(** - Exit gracefully in case of error. -*) -let exitf message = fprintf stderr "BUG: %s.\n" message ; exit 1 -;; - -(** - Create and print datatypes -*) -let mk_datatypes ctx generator = - let datatypes = Z3.mk_datatypes ctx generator in - printf "datatype created:\n%!" ; - Array.iter (fun (sort, ctors) -> - printf "sort: %s\n%!" (Z3.sort_to_string ctx sort) ; - Array.iter (fun {Z3.constructor; recognizer; accessors} -> - printf "constructor: %s%! recognizer: %s%! accessors:" - (Z3.func_decl_to_string ctx constructor) - (Z3.func_decl_to_string ctx recognizer) ; - Array.iter (fun accessor -> - printf " %s%!" (Z3.func_decl_to_string ctx accessor) - ) accessors ; - printf "\n" - ) ctors - ) datatypes ; - printf "\n" ; - datatypes -;; - - -(** - Create a variable using the given name and type. -*) -let mk_var ctx name ty = Z3.mk_const ctx (Z3.mk_string_symbol ctx name) ty -;; - -(* resume documentation *) -(**/**) - - -(** - Prove that the constraints already asserted into the logical - context implies the given formula. The result of the proof is - displayed. - Z3 is a satisfiability checker. So, one can prove {e f } by showing - that {e (not f) } is unsatisfiable. - The context {e ctx } is not modified by this function. -*) -let prove ctx slv f is_valid = - (* save the current state of the context *) - Z3.solver_push ctx slv ; - - let not_f = Z3.mk_not ctx f in - Z3.solver_assert ctx slv not_f ; - - (match Z3.solver_check ctx slv with - | Z3.L_FALSE -> - (* proved *) - printf "valid\n" ; - if not is_valid then exitf "unexpected result" - | Z3.L_UNDEF -> - (* Z3 failed to prove/disprove f. *) - printf "unknown\n" ; - let m = Z3.solver_get_model ctx slv in - (* m should be viewed as a potential counterexample. *) - printf "potential counterexample:\n%s\n" (Z3.model_to_string ctx m) ; - if is_valid then exitf "unexpected result" - | Z3.L_TRUE -> - (* disproved *) - printf "invalid\n" ; - let m = Z3.solver_get_model ctx slv in - (* the model returned by Z3 is a counterexample *) - printf "counterexample:\n%s\n" (Z3.model_to_string ctx m) ; - if is_valid then exitf "unexpected result" - ); - (* restore context *) - Z3.solver_pop ctx slv 1 -;; - - -(* n-ary trees and forests in OCaml *) -type tree = Leaf of int | Node of forest -and forest = tree list - -(** - Demonstrates the usage of {!Z3.mk_datatypes} with an example of forests of trees. -*) -let forest_example () = - let ctx = Z3.mk_context [] in - let slv = Z3.mk_solver ctx - in - let int_sort = Z3.mk_int_sort ctx in - let sym name = Z3.mk_string_symbol ctx name - in - (* n-ary trees and forests in Z3 *) - match - mk_datatypes ctx - (function [|tree; forest|] -> Some - [|(sym"tree", - [|{Z3.constructor_desc= sym"leaf"; recognizer_desc= sym"is_leaf"; accessor_descs= [|(sym"data", int_sort)|]}; - {Z3.constructor_desc= sym"node"; recognizer_desc= sym"is_node"; accessor_descs= [|(sym"children", forest)|]}|]); - (sym"forest", - [|{Z3.constructor_desc= sym"nil" ; recognizer_desc= sym"is_nil" ; accessor_descs= [||]}; - {Z3.constructor_desc= sym"cons"; recognizer_desc= sym"is_cons"; accessor_descs= [|(sym"hd", tree); (sym"tl", forest)|]}|])|] - | _ -> None - ) - with - [|(tree, - [|{Z3.constructor= leaf; recognizer= is_leaf; accessors= [|data|]}; - {Z3.constructor= node; recognizer= is_node; accessors= [|children|]}|]); - (forest, - [|{Z3.constructor= nil ; recognizer= is_nil ; accessors= [||]}; - {Z3.constructor= cons; recognizer= is_cons; accessors= [|hd; tl|]}|])|] - -> - (* translate from OCaml to Z3 *) - let rec ml2z3_tree = function - | Leaf(i) -> Z3.mk_app ctx leaf [|Z3.mk_int ctx i (Z3.mk_int_sort ctx)|] - | Node(f) -> Z3.mk_app ctx node [|ml2z3_forest f|] - - and ml2z3_forest = function - | [] -> Z3.mk_app ctx nil [||] - | t :: f -> Z3.mk_app ctx cons [|ml2z3_tree t; ml2z3_forest f|] - in - - (* construct some OCaml trees *) - let t0 = Leaf 0 in - let t12 = Node [Leaf 1; Leaf 2] in - let t123 = Node [t12; Leaf 3] in - let t1212 = Node [t12; t12] in - let t412 = Node [Leaf 4; t12] in - - (* construct some Z3 trees using the translation from OCaml *) - let t1 = ml2z3_tree t12 in printf "t1: %s\n%!" (Z3.ast_to_string ctx t1) ; - let t2 = ml2z3_tree t123 in printf "t2: %s\n%!" (Z3.ast_to_string ctx t2) ; - let t3 = ml2z3_tree t1212 in printf "t3: %s\n%!" (Z3.ast_to_string ctx t3) ; - let t4 = ml2z3_tree t412 in printf "t4: %s\n%!" (Z3.ast_to_string ctx t4) ; - let f1 = ml2z3_forest [t0] in printf "f1: %s\n%!" (Z3.ast_to_string ctx f1) ; - let f2 = ml2z3_forest [t12] in printf "f2: %s\n%!" (Z3.ast_to_string ctx f2) ; - let f3 = ml2z3_forest [t12; t0] in printf "f3: %s\n%!" (Z3.ast_to_string ctx f3) ; - - (* or using the Z3 API *) - let nil = Z3.mk_app ctx nil [||] in - let cons t f = Z3.mk_app ctx cons [|t; f|] in - let leaf i = Z3.mk_app ctx leaf [|Z3.mk_int ctx i (Z3.mk_int_sort ctx)|] in - let node f = Z3.mk_app ctx node [|f|] in - - let t0 = leaf 0 in - let t12 = node (cons (leaf 1) (cons (leaf 2) nil)) in - let t123 = node (cons t12 (cons (leaf 3) nil)) in - let t1212 = node (cons t12 (cons t12 nil)) in - let t412 = node (cons (leaf 4) (cons t12 nil)) in - - let t1 = t12 in printf "t1: %s\n%!" (Z3.ast_to_string ctx t1) ; - let t2 = t123 in printf "t2: %s\n%!" (Z3.ast_to_string ctx t2) ; - let t3 = t1212 in printf "t3: %s\n%!" (Z3.ast_to_string ctx t3) ; - let t4 = t412 in printf "t4: %s\n%!" (Z3.ast_to_string ctx t4) ; - let f1 = cons t0 nil in printf "f1: %s\n%!" (Z3.ast_to_string ctx f1) ; - let f2 = cons t12 nil in printf "f2: %s\n%!" (Z3.ast_to_string ctx f2) ; - let f3 = cons t12 f1 in printf "f3: %s\n%!" (Z3.ast_to_string ctx f3) ; - - (* nil != cons(nil,nil) *) - prove ctx slv (Z3.mk_not ctx (Z3.mk_eq ctx nil f1)) true ; - prove ctx slv (Z3.mk_not ctx (Z3.mk_eq ctx (leaf 5) t1)) true ; - - (* cons(x,u) = cons(x, v) => u = v *) - let u = mk_var ctx "u" forest in - let v = mk_var ctx "v" forest in - let x = mk_var ctx "x" tree in - let y = mk_var ctx "y" tree in - let l1 = cons x u in printf "l1: %s\n%!" (Z3.ast_to_string ctx l1) ; - let l2 = cons y v in printf "l2: %s\n%!" (Z3.ast_to_string ctx l2) ; - - prove ctx slv (Z3.mk_implies ctx (Z3.mk_eq ctx l1 l2) (Z3.mk_eq ctx u v)) true ; - prove ctx slv (Z3.mk_implies ctx (Z3.mk_eq ctx l1 l2) (Z3.mk_eq ctx x y)) true ; - - (* is_nil(u) or is_cons(u) *) - prove ctx slv (Z3.mk_or ctx [|Z3.mk_app ctx is_nil [|u|]; Z3.mk_app ctx is_cons [|u|]|]) true ; - - (* occurs check u != cons(x,u) *) - prove ctx slv (Z3.mk_not ctx (Z3.mk_eq ctx u l1)) true ; - - | _ -> - exitf "unexpected datatype signature" -;; - -let _ = - ignore( Z3.open_log "test_mlapi.log" ); - forest_example () ; -;; diff --git a/src/api/ml/old/test_mlapiV3.ml b/src/api/ml/old/test_mlapiV3.ml deleted file mode 100644 index a88d13000..000000000 --- a/src/api/ml/old/test_mlapiV3.ml +++ /dev/null @@ -1,1418 +0,0 @@ -(** Module test_mlapi - ML test and demo program for Z3. Matches test_capi.ml - JakobL@2007-09-08 *) - -module Z3 = Z3.V3 - -(* - @name Auxiliary Functions -*) - -(** - printf -*) -let printf = Printf.printf;; - -(** - fprintf -*) -let fprintf = Printf.fprintf;; - -(** - Exit gracefully in case of error. -*) -let exitf message = fprintf stderr "BUG: %s.\n" message; exit 1;; - -(** - Create a logical context. Enable model construction. - Also enable tracing to stderr. -*) -let mk_context ctx = - let ctx = Z3.mk_context_x (Array.append [|("MODEL", "true")|] ctx) in - (* You may comment out the following line to disable tracing: *) - (* Z3.trace_to_stderr ctx; *) - ctx;; - -(** - Create a variable using the given name and type. -*) -let mk_var ctx name ty = Z3.mk_const ctx (Z3.mk_string_symbol ctx name) ty;; - -(** - Create a boolean variable using the given name. -*) -let mk_bool_var ctx name = mk_var ctx name (Z3.mk_bool_sort ctx);; - -(** - Create an integer variable using the given name. -*) -let mk_int_var ctx name = mk_var ctx name (Z3.mk_int_sort ctx);; - -(** - Create a Z3 integer node using a C int. -*) -let mk_int ctx v = Z3.mk_int ctx v (Z3.mk_int_sort ctx);; - -(** - Create a real variable using the given name. -*) -let mk_real_var ctx name = mk_var ctx name (Z3.mk_real_sort ctx);; - -(** - Create the unary function application: {e (f x) }. -*) -let mk_unary_app ctx f x = Z3.mk_app ctx f [|x|];; - -(** - Create the binary function application: {e (f x y) }. -*) -let mk_binary_app ctx f x y = Z3.mk_app ctx f [|x;y|];; - -(** - Auxiliary function to check whether two Z3 types are equal or not. -*) -let equal_sorts ctx t1 t2 = Z3.is_eq_sort ctx t1 t2;; - -(** - Check whether the logical context is satisfiable, and compare the result with the expected result. - If the context is satisfiable, then display the model. -*) -let check ctx expected_result = - begin - let (result, m) = Z3.check_and_get_model ctx in - (match result with - | Z3.L_FALSE -> printf "unsat\n"; - | Z3.L_UNDEF -> - printf "unknown\n"; - printf "potential model:\n%s\n" (Z3.model_to_string ctx m); - (Z3.del_model ctx m); - | Z3.L_TRUE -> printf "sat\n%s\n" (Z3.model_to_string ctx m); - (Z3.del_model ctx m); - ); - if result != expected_result then exitf "unexpected result"; - end;; - -(** - Prove that the constraints already asserted into the logical - context implies the given formula. The result of the proof is - displayed. - Z3 is a satisfiability checker. So, one can prove {e f } by showing - that {e (not f) } is unsatisfiable. - The context {e ctx } is not modified by this function. -*) -let prove ctx f is_valid = - begin - (* save the current state of the context *) - Z3.push ctx; - - let not_f = Z3.mk_not ctx f in - Z3.assert_cnstr ctx not_f; - - (match Z3.check_and_get_model ctx with - | (Z3.L_FALSE,_) -> - (* proved *) - printf "valid\n"; - if not is_valid then exitf "unexpected result"; - | (Z3.L_UNDEF,m) -> - (* Z3 failed to prove/disprove f. *) - printf "unknown\n"; - (* m should be viewed as a potential counterexample. *) - printf "potential counterexample:\n%s\n" (Z3.model_to_string ctx m); - if is_valid then exitf "unexpected result"; - (Z3.del_model ctx m); - | (Z3.L_TRUE,m) -> - (* disproved *) - printf "invalid\n"; - (* the model returned by Z3 is a counterexample *) - printf "counterexample:\n%s\n" (Z3.model_to_string ctx m); - if is_valid then exitf "unexpected result"; - (Z3.del_model ctx m); - ); - (* restore context *) - Z3.pop ctx 1; - end;; - -(** - Assert the axiom: function f is injective in the i-th argument. - - The following axiom is asserted into the logical context: - - forall (x_1, ..., x_n) finv(f(x_1, ..., x_i, ..., x_n)) = x_i - - Where, {e finv } is a fresh function declaration. -*) -let assert_inj_axiom ctx f i = - begin - let sz = Z3.get_domain_size ctx f in - if i >= sz then exitf "failed to create inj axiom"; - - (* declare the i-th inverse of f: finv *) - let finv_domain = Z3.get_range ctx f in - let finv_range = Z3.get_domain ctx f i in - let finv = Z3.mk_fresh_func_decl ctx "inv" [|finv_domain|] finv_range in - - (* allocate temporary arrays *) - (* fill types, names and xs *) - let types = Z3.get_domains ctx f in - let names = Array.init sz (Z3.mk_int_symbol ctx) in - let xs = Array.init sz (fun j->Z3.mk_bound ctx j (types.(j))) in - - (* create f(x_0, ..., x_i, ..., x_{n-1}) *) - let fxs = Z3.mk_app ctx f xs in - - (* create f_inv(f(x_0, ..., x_i, ..., x_{n-1})) *) - let finv_fxs = mk_unary_app ctx finv fxs in - - (* create finv(f(x_0, ..., x_i, ..., x_{n-1})) = x_i *) - let eq = Z3.mk_eq ctx finv_fxs (xs.(i)) in - - (* use f(x_0, ..., x_i, ..., x_{n-1}) as the pattern for the quantifier *) - let p = Z3.mk_pattern ctx [|fxs|] in - printf "pattern: %s\n" (Z3.pattern_to_string ctx p); - printf "\n"; - - (* create & assert quantifier *) - let q = Z3.mk_forall ctx - 0 (* using default weight *) - [|p|] (* the "array" of patterns *) - types - names - eq - in - printf "assert axiom:\n%s\n" (Z3.ast_to_string ctx q); - Z3.assert_cnstr ctx q; - end;; - -(** - Assert the axiom: function f is commutative. - - This example uses the SMT-LIB parser to simplify the axiom construction. -*) -let assert_comm_axiom ctx f = - begin - let t = Z3.get_range ctx f in - if Z3.get_domain_size ctx f != 2 || not (equal_sorts ctx (Z3.get_domain ctx f 0) t) || not (equal_sorts ctx (Z3.get_domain ctx f 1) t) then - exitf "function must be binary, and argument types must be equal to return type"; - (* Inside the parser, function f will be referenced using the symbol 'f'. *) - let f_name = Z3.mk_string_symbol ctx "f" in - (* Inside the parser, type t will be referenced using the symbol 'T'. *) - let t_name = Z3.mk_string_symbol ctx "T" in - let str = "(benchmark comm :formula (forall (x T) (y T) (= (f x y) (f y x))))" in - let q = Z3.parse_smtlib_string_formula ctx str [|t_name|] [|t|] [|f_name|] [|f|] in - printf "assert axiom:\n%s\n" (Z3.ast_to_string ctx q); - Z3.assert_cnstr ctx q; - end;; - -(** - Z3 does not support explicitly tuple updates. They can be easily implemented - as macros. The argument {e t } must have tuple type. - A tuple update is a new tuple where field {e i } has value {e new_val }, and all - other fields have the value of the respective field of {e t }. - - {e update(t, i, new_val) } is equivalent to - {e mk_tuple(proj_0(t), ..., new_val, ..., proj_n(t)) } -*) -let mk_tuple_update c t i new_val = - begin - let ty = Z3.get_sort c t in - let (mk_tuple_decl,fields)=Z3.get_tuple_sort c ty in - if i>=Array.length fields then exitf "invalid tuple update, index is too big"; - let f j = - if i = j then (* use new_val at position i: *) new_val - else (* use field j of t: *) (mk_unary_app c (fields.(j)) t) - in let new_fields = Array.init (Array.length fields) f in - Z3.mk_app c (Z3.get_tuple_sort_mk_decl c ty) new_fields; - end;; - -(** - Display a symbol in the given output stream. -*) -let display_symbol c out s = - match Z3.symbol_refine c s with - | Z3.Symbol_int i -> fprintf out "#%d" i; - | Z3.Symbol_string r ->fprintf out "%s" r; - | Z3.Symbol_unknown -> ();; - -(** - Display the given type. -*) -let rec display_sort c out ty = - begin - match Z3.sort_refine c ty with - | Z3.Sort_uninterpreted s -> display_symbol c out s; - | Z3.Sort_bool -> fprintf out "bool"; - | Z3.Sort_int -> fprintf out "int"; - | Z3.Sort_real -> fprintf out "real"; - | Z3.Sort_relation -> fprintf out "relation"; - | Z3.Sort_finite_domain -> fprintf out "finite-domain"; - | Z3.Sort_bv sz -> fprintf out "bv%d" sz; - | Z3.Sort_array (domain, range) -> - fprintf out "["; - display_sort c out domain; - fprintf out "->"; - display_sort c out range; - fprintf out "]"; - | Z3.Sort_datatype cons -> - Array.iter (fun (dt_con : Z3.datatype_constructor_refined) -> - let fields = dt_con.Z3.accessors in - fprintf out "("; - let f i v = - if i>0 then fprintf out ", "; - display_sort c out (Z3.get_range c v); - in Array.iteri f fields; - fprintf out ")") cons - | Z3.Sort_unknown s -> - fprintf out "unknown["; - display_symbol c out s; - fprintf out "unknown]"; - end;; - -(** - Custom ast pretty printer. - - This function demonstrates how to use the API to navigate terms. -*) - -let rec display_numeral c out nm = - match nm with - | Z3.Numeral_small(n,1L) -> - Printf.fprintf out "%Ld" n - | Z3.Numeral_small(n,d) -> - Printf.fprintf out "%Ld/%Ld" n d - | Z3.Numeral_large s -> - Printf.fprintf out "%s" s - -let rec display_ast c out v = - begin - match Z3.term_refine c v with - | Z3.Term_app(k, f, args) -> - let num_fields = Array.length args in - let a = Z3.to_app c v in - let d = Z3.get_app_decl c a in - Printf.fprintf out "%s" (Z3.func_decl_to_string c d); - if num_fields > 0 then - begin - Printf.fprintf out "["; - for i = 0 to num_fields - 1 do - if i > 0 then Printf.fprintf out ", "; - display_ast c out (Z3.get_app_arg c a i) - done; - Printf.fprintf out "]" - end - | Z3.Term_numeral(nm, s) -> - display_numeral c out nm; - Printf.fprintf out ":"; - display_sort c out s - | Z3.Term_var(idx, s) -> - printf "#unknown" - | Z3.Term_quantifier(b, w, pats, bound, body) -> - printf "quantifier" - end;; - -(** - Custom function for traversing a term and replacing the constant - 'x' by the bound variable having index 'idx'. - This function illustrates how to walk Z3 terms and - reconstruct them. -**) - -let rec abstract c x idx term = - if Z3.is_eq_ast c term x then Z3.mk_bound c idx (Z3.get_sort c x) else - match Z3.term_refine c term with - | Z3.Term_app(k, f, args) -> Z3.mk_app c f (Array.map (abstract c x idx) args) - | Z3.Term_numeral(nm, s) -> term - | Z3.Term_var(idx, s) -> term - | Z3.Term_quantifier(b, w, pats, bound, body) -> - let idx = (idx + Array.length bound) in - let body = abstract c x idx body in - let is_forall = b = Z3.Forall in - let mk_pattern terms = Z3.mk_pattern c (Array.map (abstract c x idx) terms) in - let patterns = Array.map mk_pattern pats in - Z3.mk_quantifier c is_forall w patterns - (Array.map snd bound) (Array.map fst bound) body - -(** - Example abstraction function. -**) - - -let abstract_example() = - begin - printf "\nabstract_example\n"; - let ctx = mk_context [||] in - let x = mk_int_var ctx "x" in - let x_decl = Z3.get_app_decl ctx (Z3.to_app ctx x) in - let y = mk_int_var ctx "y" in - let y_decl = Z3.get_app_decl ctx (Z3.to_app ctx y) in - let decls = [| x_decl; y_decl |] in - let a = Z3.mk_string_symbol ctx "a" in - let b = Z3.mk_string_symbol ctx "b" in - let names = [| a; b |] in - let str = "(benchmark tst :formula (> a b))" in - let f = Z3.parse_smtlib_string_formula ctx str [||] [||] names decls in - printf "formula: %s\n" (Z3.ast_to_string ctx f); - - let f2 = abstract ctx x 0 f in - - printf "abstracted formula: %s\n" (Z3.ast_to_string ctx f2); - (* delete logical context *) - Z3.del_context ctx; - - end;; - -(** - Custom function interpretations pretty printer. -*) -let display_function_interpretations c out m = - begin - fprintf out "function interpretations:\n"; - let display_function (name, entries, func_else) = - begin - display_symbol c out name; - fprintf out " = {"; - let display_entry j (args,valu) = - if j > 0 then fprintf out ", "; - fprintf out "("; - let f k arg = - if k > 0 then fprintf out ", "; - display_ast c out arg - in Array.iteri f args; - fprintf out "|->"; - display_ast c out valu; - fprintf out ")"; - in Array.iteri display_entry entries; - if Array.length entries > 0 then fprintf out ", "; - fprintf out "(else|->"; - display_ast c out func_else; - fprintf out ")}\n"; - end; - in - Array.iter display_function (Z3.get_model_funcs c m); - end;; - -(** - Custom model pretty printer. -*) -let display_model c out m = - begin - let constants=Z3.get_model_constants c m in - let f i e = - let name = Z3.get_decl_name c e in - let (ok, v) = Z3.eval_func_decl c m e in - display_symbol c out name; - fprintf out " = "; - display_ast c out v; - fprintf out "\n" - in Array.iteri f constants; - display_function_interpretations c out m; - end;; - -(** - Similar to #check, but uses #display_model instead of #Z3_model_to_string. -*) -let check2 ctx expected_result = - begin - let (result,m) = Z3.check_and_get_model ctx in - (match result with - | Z3.L_FALSE -> - printf "unsat\n"; - | Z3.L_UNDEF -> - printf "unknown\n"; - printf "potential model:\n"; - display_model ctx stdout m; - (Z3.del_model ctx m); - | Z3.L_TRUE -> - printf "sat\n"; - display_model ctx stdout m; - (Z3.del_model ctx m); - ); - if result != expected_result then exitf "unexpected result"; - end;; - -(** - Display Z3 version in the standard output. -*) -let display_version() = - begin - let (major, minor, build, revision)=Z3.get_version() in - printf "Z3 %d.%d.%d.%d\n" major minor build revision; - end;; - -(* - @name Examples -*) - -(** - "Hello world" example: create a Z3 logical context, and delete it. -*) -let simple_example() = - begin - printf "\nsimple_example\n"; - let ctx = mk_context [||] in - (* do something with the context *) - printf "CONTEXT:\n%sEND OF CONTEXT\n" (Z3.context_to_string ctx); - (* delete logical context *) - Z3.del_context ctx; - end;; - -(** - Demonstration of how Z3 can be used to prove validity of - De Morgan's Duality Law: {e not(x and y) <-> (not x) or ( not y) } -*) -let demorgan() = - begin - printf "\nDeMorgan\n"; - let ctx = mk_context [||] in - let bool_sort = Z3.mk_bool_sort ctx in - let symbol_x = Z3.mk_int_symbol ctx 0 in - let symbol_y = Z3.mk_int_symbol ctx 1 in - let x = Z3.mk_const ctx symbol_x bool_sort in - let y = Z3.mk_const ctx symbol_y bool_sort in - - (* De Morgan - with a negation around: *) - (* !(!(x && y) <-> (!x || !y)) *) - let not_x = Z3.mk_not ctx x in - let not_y = Z3.mk_not ctx y in - let x_and_y = Z3.mk_and ctx [|x;y|] in - let ls = Z3.mk_not ctx x_and_y in - let rs = Z3.mk_or ctx [|not_x;not_y|] in - let conjecture = Z3.mk_iff ctx ls rs in - let negated_conjecture = Z3.mk_not ctx conjecture in - - Z3.assert_cnstr ctx negated_conjecture; - (match Z3.check ctx with - | Z3.L_FALSE -> - (* The negated conjecture was unsatisfiable, hence the conjecture is valid *) - printf "DeMorgan is valid\n" - | Z3.L_UNDEF -> - (* Check returned undef *) - printf "Undef\n" - | Z3.L_TRUE -> - (* The negated conjecture was satisfiable, hence the conjecture is not valid *) - Printf.printf "DeMorgan is not valid\n"); - Z3.del_context ctx; - end;; - -(** - Find a model for {e x xor y }. -*) -let find_model_example1() = - begin - printf "\nfind_model_example1\n"; - let ctx = mk_context [||] in - let x = mk_bool_var ctx "x" in - let y = mk_bool_var ctx "y" in - let x_xor_y = Z3.mk_xor ctx x y in - Z3.assert_cnstr ctx x_xor_y; - printf "model for: x xor y\n"; - check ctx Z3.L_TRUE; - Z3.del_context ctx; - end;; - -(** - Find a model for {e x < y + 1, x > 2 }. - Then, assert {e not(x = y) }, and find another model. -*) -let find_model_example2() = - begin - printf "\nfind_model_example2\n"; - let ctx = mk_context [||] in - let x = mk_int_var ctx "x" in - let y = mk_int_var ctx "y" in - let one = mk_int ctx 1 in - let two = mk_int ctx 2 in - let y_plus_one = Z3.mk_add ctx [|y;one|] in - let c1 = Z3.mk_lt ctx x y_plus_one in - let c2 = Z3.mk_gt ctx x two in - Z3.assert_cnstr ctx c1; - Z3.assert_cnstr ctx c2; - printf "model for: x < y + 1, x > 2\n"; - check ctx Z3.L_TRUE; - - (* assert not(x = y) *) - let x_eq_y = Z3.mk_eq ctx x y in - let c3 = Z3.mk_not ctx x_eq_y in - Z3.assert_cnstr ctx c3; - printf "model for: x < y + 1, x > 2, not(x = y)\n"; - check ctx Z3.L_TRUE; - Z3.del_context ctx; - end;; - -(** - Prove {e x = y implies g(x) = g(y) }, and - disprove {e x = y implies g(g(x)) = g(y) }. - - This function demonstrates how to create uninterpreted types and - functions. -*) -let prove_example1() = - begin - printf "\nprove_example1\n"; - - let ctx = mk_context [||] in - - (* create uninterpreted type. *) - let u_name = Z3.mk_string_symbol ctx "U" in - let u = Z3.mk_uninterpreted_sort ctx u_name in - - (* declare function g *) - let g_name = Z3.mk_string_symbol ctx "g" in - let g = Z3.mk_func_decl ctx g_name [|u|] u in - - (* create x and y *) - let x_name = Z3.mk_string_symbol ctx "x" in - let y_name = Z3.mk_string_symbol ctx "y" in - let x = Z3.mk_const ctx x_name u in - let y = Z3.mk_const ctx y_name u in - (* create g(x), g(y) *) - let gx = mk_unary_app ctx g x in - let gy = mk_unary_app ctx g y in - - (* assert x = y *) - let eq = Z3.mk_eq ctx x y in - Z3.assert_cnstr ctx eq; - - (* prove g(x) = g(y) *) - let f = Z3.mk_eq ctx gx gy in - printf "prove: x = y implies g(x) = g(y)\n"; - prove ctx f true; - - (* create g(g(x)) *) - let ggx = mk_unary_app ctx g gx in - - (* disprove g(g(x)) = g(y) *) - let f = Z3.mk_eq ctx ggx gy in - printf "disprove: x = y implies g(g(x)) = g(y)\n"; - prove ctx f false; - - Z3.del_context ctx; - end;; - -(** - Prove {e not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0 }. - Then, show that {e z < -1 } is not implied. - - This example demonstrates how to combine uninterpreted functions and arithmetic. -*) -let prove_example2() = - begin - printf "\nprove_example2\n"; - - let ctx = mk_context [||] in - - (* declare function g *) - let int_sort = Z3.mk_int_sort ctx in - let g_name = Z3.mk_string_symbol ctx "g" in - let g = Z3.mk_func_decl ctx g_name [|int_sort|] int_sort in - - (* create x, y, and z *) - let x = mk_int_var ctx "x" in - let y = mk_int_var ctx "y" in - let z = mk_int_var ctx "z" in - - (* create gx, gy, gz *) - let gx = mk_unary_app ctx g x in - let gy = mk_unary_app ctx g y in - let gz = mk_unary_app ctx g z in - - (* create zero *) - let zero = mk_int ctx 0 in - - (* assert not(g(g(x) - g(y)) = g(z)) *) - let gx_gy = Z3.mk_sub ctx [|gx;gy|] in - let ggx_gy = mk_unary_app ctx g gx_gy in - let eq = Z3.mk_eq ctx ggx_gy gz in - let c1 = Z3.mk_not ctx eq in - Z3.assert_cnstr ctx c1; - - (* assert x + z <= y *) - let x_plus_z = Z3.mk_add ctx [|x;z|] in - let c2 = Z3.mk_le ctx x_plus_z y in - Z3.assert_cnstr ctx c2; - - (* assert y <= x *) - let c3 = Z3.mk_le ctx y x in - Z3.assert_cnstr ctx c3; - - (* prove z < 0 *) - let f = Z3.mk_lt ctx z zero in - printf "prove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < 0\n"; - prove ctx f true; - - (* disprove z < -1 *) - let minus_one = mk_int ctx (-1) in - let f = Z3.mk_lt ctx z minus_one in - printf "disprove: not(g(g(x) - g(y)) = g(z)), x + z <= y <= x implies z < -1\n"; - prove ctx f false; - - Z3.del_context ctx; - end;; - -(** - Show how push & pop can be used to create "backtracking" - points. - - This example also demonstrates how big numbers can be created in Z3. -*) -let push_pop_example1() = - begin - printf "\npush_pop_example1\n"; - let ctx = mk_context [||] in - - (* create a big number *) - let int_sort = Z3.mk_int_sort ctx in - let big_number = Z3.mk_numeral ctx "1000000000000000000000000000000000000000000000000000000" int_sort in - - (* create number 3 *) - let three = Z3.mk_numeral ctx "3" int_sort in - - (* create x *) - let x_sym = Z3.mk_string_symbol ctx "x" in - let x = Z3.mk_const ctx x_sym int_sort in - - (* assert x >= "big number" *) - let c1 = Z3.mk_ge ctx x big_number in - printf "assert: x >= 'big number'\n"; - Z3.assert_cnstr ctx c1; - - (* create a backtracking point *) - printf "push\n"; - Z3.push ctx; - - printf "number of scopes: %d\n" (Z3.get_num_scopes ctx); - - (* assert x <= 3 *) - let c2 = Z3.mk_le ctx x three in - printf "assert: x <= 3\n"; - Z3.assert_cnstr ctx c2; - - (* context is inconsistent at this point *) - check2 ctx Z3.L_FALSE; - - (* backtrack: the constraint x <= 3 will be removed, since it was - asserted after the last push. *) - printf "pop\n"; - Z3.pop ctx 1; - - printf "number of scopes: %d\n" (Z3.get_num_scopes ctx); - - (* the context is consistent again. *) - check2 ctx Z3.L_TRUE; - - (* new constraints can be asserted... *) - - (* create y *) - let y_sym = Z3.mk_string_symbol ctx "y" in - let y = Z3.mk_const ctx y_sym int_sort in - - (* assert y > x *) - let c3 = Z3.mk_gt ctx y x in - printf "assert: y > x\n"; - Z3.assert_cnstr ctx c3; - - (* the context is still consistent. *) - check2 ctx Z3.L_TRUE; - - Z3.del_context ctx; - end;; - -(** - Prove that {e f(x, y) = f(w, v) implies y = v } when - {e f } is injective in the second argument. -*) -let quantifier_example1() = - begin - printf "\nquantifier_example1\n"; - - (* If quantified formulas are asserted in a logical context, then - Z3 may return L_UNDEF. In this case, the model produced by Z3 should be viewed as a potential/candidate model. - Limiting the number of iterations of the model finder for quantified formulas. - *) - let ctx = mk_context [|("MBQI_MAX_ITERATIONS", "10")|] in - - (* declare function f *) - let int_sort = Z3.mk_int_sort ctx in - let f_name = Z3.mk_string_symbol ctx "f" in - let f = Z3.mk_func_decl ctx f_name [|int_sort; int_sort|] int_sort in - - (* assert that f is injective in the second argument. *) - assert_inj_axiom ctx f 1; - - (* create x, y, v, w, fxy, fwv *) - let x = mk_int_var ctx "x" in - let y = mk_int_var ctx "y" in - let v = mk_int_var ctx "v" in - let w = mk_int_var ctx "w" in - let fxy = mk_binary_app ctx f x y in - let fwv = mk_binary_app ctx f w v in - - (* assert f(x, y) = f(w, v) *) - let p1 = Z3.mk_eq ctx fxy fwv in - Z3.assert_cnstr ctx p1; - - (* prove f(x, y) = f(w, v) implies y = v *) - let p2 = Z3.mk_eq ctx y v in - printf "prove: f(x, y) = f(w, v) implies y = v\n"; - prove ctx p2 true; - - (* disprove f(x, y) = f(w, v) implies x = w *) - (* using check2 instead of prove *) - let p3 = Z3.mk_eq ctx x w in - let not_p3 = Z3.mk_not ctx p3 in - Z3.assert_cnstr ctx not_p3; - printf "disprove: f(x, y) = f(w, v) implies x = w\n"; - printf "that is: not(f(x, y) = f(w, v) implies x = w) is satisfiable\n"; - check2 ctx Z3.L_UNDEF; - Printf.printf - "reason for last failure: %d (7 = quantifiers)\n" - (if Z3.get_search_failure(ctx) = Z3.QUANTIFIERS then 7 else -1); - - - Z3.del_context ctx; - end;; - -(** - Prove {e store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3)) }. - - This example demonstrates how to use the array theory. -*) -let array_example1() = - begin - printf "\narray_example1\n"; - - let ctx = mk_context [||] in - - let int_sort = Z3.mk_int_sort ctx in - let array_sort = Z3.mk_array_sort ctx int_sort int_sort in - - let a1 = mk_var ctx "a1" array_sort in - let a2 = mk_var ctx "a2" array_sort in - let i1 = mk_var ctx "i1" int_sort in - let i2 = mk_var ctx "i2" int_sort in - let i3 = mk_var ctx "i3" int_sort in - let v1 = mk_var ctx "v1" int_sort in - let v2 = mk_var ctx "v2" int_sort in - - let st1 = Z3.mk_store ctx a1 i1 v1 in - let st2 = Z3.mk_store ctx a2 i2 v2 in - - let sel1 = Z3.mk_select ctx a1 i3 in - let sel2 = Z3.mk_select ctx a2 i3 in - - (* create antecedent *) - let antecedent = Z3.mk_eq ctx st1 st2 in - - (* create consequent: i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3) *) - let ds = [| - Z3.mk_eq ctx i1 i3; - Z3.mk_eq ctx i2 i3; - Z3.mk_eq ctx sel1 sel2; - |] in - - let consequent = Z3.mk_or ctx ds in - - (* prove store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3)) *) - let thm = Z3.mk_implies ctx antecedent consequent in - printf "prove: store(a1, i1, v1) = store(a2, i2, v2) implies (i1 = i3 or i2 = i3 or select(a1, i3) = select(a2, i3))\n"; - printf "%s\n" (Z3.ast_to_string ctx thm); - prove ctx thm true; - - Z3.del_context ctx; - end;; - -(** - Show that {e distinct(a_0, ... , a_n) } is - unsatisfiable when {e a_i's } are arrays from boolean to - boolean and n > 4. - - This example also shows how to use the {e distinct } construct. -*) -let array_example2() = - begin - printf "\narray_example2\n"; - - for n = 2 to 5 do - printf "n = %d\n" n; - let ctx = mk_context [||] in - - let bool_sort = Z3.mk_bool_sort ctx in - let array_sort = Z3.mk_array_sort ctx bool_sort bool_sort in - - (* create arrays *) - let a = Array.init n - (fun i->Z3.mk_const ctx (Z3.mk_int_symbol ctx i) array_sort) in - - (* assert distinct(a[0], ..., a[n]) *) - let d = Z3.mk_distinct ctx a in - printf "%s\n" (Z3.ast_to_string ctx d); - Z3.assert_cnstr ctx d; - - (* context is satisfiable if n < 5 *) - check2 ctx (if n < 5 then Z3.L_TRUE else Z3.L_FALSE); - - Z3.del_context ctx; - done - end;; - -(** - Simple array type construction/deconstruction example. -*) -let array_example3() = - begin - printf "\narray_example3\n"; - - let ctx = mk_context [||] in - - let bool_sort = Z3.mk_bool_sort ctx in - let int_sort = Z3.mk_int_sort ctx in - let array_sort = Z3.mk_array_sort ctx int_sort bool_sort in - - let (domain,range) = Z3.get_array_sort ctx array_sort in - printf "domain: "; - display_sort ctx stdout domain; - printf "\n"; - printf "range: "; - display_sort ctx stdout range; - printf "\n"; - - if (not (Z3.is_eq_sort ctx int_sort domain)) || - (not (Z3.is_eq_sort ctx bool_sort range)) then - exitf "invalid array type"; - Z3.del_context ctx; - end;; - -(** - Simple tuple type example. It creates a tuple that is a pair of real numbers. -*) -let tuple_example1() = - begin - printf "\ntuple_example1\n"; - let ctx = mk_context [||] in - - let real_sort = Z3.mk_real_sort ctx in - - (* Create pair (tuple) type *) - let mk_tuple_name = Z3.mk_string_symbol ctx "mk_pair" in - let proj_names_0 = Z3.mk_string_symbol ctx "get_x" in - let proj_names_1 = Z3.mk_string_symbol ctx "get_y" in - let proj_names = [|proj_names_0; proj_names_1|] in - let proj_sorts = [|real_sort;real_sort|] in - (* Z3_mk_tuple_sort will set mk_tuple_decl and proj_decls *) - let (pair_sort,mk_tuple_decl,proj_decls) = Z3.mk_tuple_sort ctx mk_tuple_name proj_names proj_sorts in - let get_x_decl = proj_decls.(0) in (* function that extracts the first element of a tuple. *) - let get_y_decl = proj_decls.(1) in (* function that extracts the second element of a tuple. *) - - printf "tuple_sort: "; - display_sort ctx stdout pair_sort; - printf "\n"; - - begin - (* prove that get_x(mk_pair(x,y)) == 1 implies x = 1*) - let x = mk_real_var ctx "x" in - let y = mk_real_var ctx "y" in - let app1 = mk_binary_app ctx mk_tuple_decl x y in - let app2 = mk_unary_app ctx get_x_decl app1 in - let one = Z3.mk_numeral ctx "1" real_sort in - let eq1 = Z3.mk_eq ctx app2 one in - let eq2 = Z3.mk_eq ctx x one in - let thm = Z3.mk_implies ctx eq1 eq2 in - printf "prove: get_x(mk_pair(x, y)) = 1 implies x = 1\n"; - prove ctx thm true; - - (* disprove that get_x(mk_pair(x,y)) == 1 implies y = 1*) - let eq3 = Z3.mk_eq ctx y one in - let thm = Z3.mk_implies ctx eq1 eq3 in - printf "disprove: get_x(mk_pair(x, y)) = 1 implies y = 1\n"; - prove ctx thm false; - end; - - begin - (* prove that get_x(p1) = get_x(p2) and get_y(p1) = get_y(p2) implies p1 = p2 *) - let p1 = mk_var ctx "p1" pair_sort in - let p2 = mk_var ctx "p2" pair_sort in - let x1 = mk_unary_app ctx get_x_decl p1 in - let y1 = mk_unary_app ctx get_y_decl p1 in - let x2 = mk_unary_app ctx get_x_decl p2 in - let y2 = mk_unary_app ctx get_y_decl p2 in - let antecedents_0 = Z3.mk_eq ctx x1 x2 in - let antecedents_1 = Z3.mk_eq ctx y1 y2 in - let antecedents = [|antecedents_0; antecedents_1|] in - let antecedent = Z3.mk_and ctx antecedents in - let consequent = Z3.mk_eq ctx p1 p2 in - let thm = Z3.mk_implies ctx antecedent consequent in - printf "prove: get_x(p1) = get_x(p2) and get_y(p1) = get_y(p2) implies p1 = p2\n"; - prove ctx thm true; - - (* disprove that get_x(p1) = get_x(p2) implies p1 = p2 *) - let thm = Z3.mk_implies ctx (antecedents.(0)) consequent in - printf "disprove: get_x(p1) = get_x(p2) implies p1 = p2\n"; - prove ctx thm false; - end; - - begin - (* demonstrate how to use the mk_tuple_update function *) - (* prove that p2 = update(p1, 0, 10) implies get_x(p2) = 10 *) - let p1 = mk_var ctx "p1" pair_sort in - let p2 = mk_var ctx "p2" pair_sort in - let one = Z3.mk_numeral ctx "1" real_sort in - let ten = Z3.mk_numeral ctx "10" real_sort in - let updt = mk_tuple_update ctx p1 0 ten in - let antecedent = Z3.mk_eq ctx p2 updt in - let x = mk_unary_app ctx get_x_decl p2 in - let consequent = Z3.mk_eq ctx x ten in - let thm = Z3.mk_implies ctx antecedent consequent in - printf "prove: p2 = update(p1, 0, 10) implies get_x(p2) = 10\n"; - prove ctx thm true; - - (* disprove that p2 = update(p1, 0, 10) implies get_y(p2) = 10 *) - let y = mk_unary_app ctx get_y_decl p2 in - let consequent = Z3.mk_eq ctx y ten in - let thm = Z3.mk_implies ctx antecedent consequent in - printf "disprove: p2 = update(p1, 0, 10) implies get_y(p2) = 10\n"; - prove ctx thm false; - end; - - Z3.del_context ctx; - end;; - -(** - Simple bit-vector example. This example disproves that x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers - *) -let bitvector_example1() = - begin - printf "\nbitvector_example1\n"; - - let ctx = mk_context [||] in - - let bv_sort = Z3.mk_bv_sort ctx 32 in - - let x = mk_var ctx "x" bv_sort in - let zero = Z3.mk_numeral ctx "0" bv_sort in - let ten = Z3.mk_numeral ctx "10" bv_sort in - let x_minus_ten = Z3.mk_bvsub ctx x ten in - (* bvsle is signed less than or equal to *) - let c1 = Z3.mk_bvsle ctx x ten in - let c2 = Z3.mk_bvsle ctx x_minus_ten zero in - let thm = Z3.mk_iff ctx c1 c2 in - printf "disprove: x - 10 <= 0 IFF x <= 10 for (32-bit) machine integers\n"; - prove ctx thm false; - - Z3.del_context ctx; - end;; - -(** - Find x and y such that: x ^ y - 103 == x * y - *) -let bitvector_example2() = - begin - printf "\nbitvector_example2\n"; - let ctx = mk_context [||] in - (* construct x ^ y - 103 == x * y *) - let bv_sort = Z3.mk_bv_sort ctx 32 in - let x = mk_var ctx "x" bv_sort in - let y = mk_var ctx "y" bv_sort in - let x_xor_y = Z3.mk_bvxor ctx x y in - let c103 = Z3.mk_numeral ctx "103" bv_sort in - let lhs = Z3.mk_bvsub ctx x_xor_y c103 in - let rhs = Z3.mk_bvmul ctx x y in - let ctr = Z3.mk_eq ctx lhs rhs in - printf "find values of x and y, such that x ^ y - 103 == x * y\n"; - Z3.assert_cnstr ctx ctr; - check ctx Z3.L_TRUE; - Z3.del_context ctx; - end;; - -(** - Demonstrate how to use #Z3_eval. -*) -let eval_example1() = - begin - printf "\neval_example1\n"; - - let ctx = mk_context [||] in - let x = mk_int_var ctx "x" in - let y = mk_int_var ctx "y" in - let two = mk_int ctx 2 in - - (* assert x < y *) - let c1 = Z3.mk_lt ctx x y in - Z3.assert_cnstr ctx c1; - - (* assert x > 2 *) - let c2 = Z3.mk_gt ctx x two in - Z3.assert_cnstr ctx c2; - - (* find model for the constraints above *) - (match Z3.check_and_get_model ctx with - | (Z3.L_TRUE, m) -> - begin - let args = [|x; y|] in - printf "MODEL:\n%s" (Z3.model_to_string ctx m); - let x_plus_y = Z3.mk_add ctx args in - printf "\nevaluating x+y\n"; - (match Z3.eval ctx m x_plus_y with - | (true,v) -> - printf "result = "; - display_ast ctx stdout v; - printf "\n"; - | _ -> - exitf "failed to evaluate: x+y"; - ); - (Z3.del_model ctx m); - end; - | (_,_) -> - exitf "the constraints are satisfiable"; - ); - Z3.del_context ctx; - end;; - -(** - Several logical context can be used simultaneously. -*) -let two_contexts_example1() = - begin - printf "\ntwo_contexts_example1\n"; - (* using the same (default) configuration to initialized both logical contexts. *) - let ctx1 = mk_context [||] in - let ctx2 = mk_context [||] in - let x1 = Z3.mk_const ctx1 (Z3.mk_int_symbol ctx1 0) (Z3.mk_bool_sort ctx1) in - let x2 = Z3.mk_const ctx2 (Z3.mk_int_symbol ctx2 0) (Z3.mk_bool_sort ctx2) in - Z3.del_context ctx1; - (* ctx2 can still be used. *) - printf "%s\n" (Z3.ast_to_string ctx2 x2); - Z3.del_context ctx2; - end;; - -(** - Demonstrates how error codes can be read insted of registering an error handler. - *) -let error_code_example1() = - begin - printf "\nerror_code_example1\n"; - - let ctx = mk_context [||] in - let x = mk_bool_var ctx "x" in - let x_decl = Z3.get_app_decl ctx (Z3.to_app ctx x) in - Z3.assert_cnstr ctx x; - - match Z3.check_and_get_model ctx with - | (Z3.L_TRUE,m) -> - begin - let (ok, v) = Z3.eval_func_decl ctx m x_decl in - printf "last call succeeded.\n"; - - (* The following call will fail since the value of x is a boolean *) - (try ignore(Z3.get_numeral_string ctx v) - with | _ -> printf "last call failed.\n"); - (Z3.del_model ctx m); - Z3.del_context ctx; - end - | (_,_) -> exitf "unexpected result"; - end;; - -(** - Demonstrates how Z3 exceptions can be used. -*) -let error_code_example2() = - begin - printf "\nerror_code_example2\n%!"; - - let ctx = mk_context [||] in - try - let x = mk_int_var ctx "x" in - let y = mk_bool_var ctx "y" in - printf "before Z3_mk_iff\n"; - let app = Z3.mk_iff ctx x y in - printf "unreachable"; - with | _ -> printf "Z3 error: type error.\n"; - Z3.del_context ctx; - end;; - -(** - Demonstrates how to use the SMTLIB parser. - *) -let parser_example1() = - begin - printf "\nparser_example1\n"; - - let ctx = mk_context [||] in - let str = "(benchmark tst :extrafuns ((x Int) (y Int)) :formula (> x y) :formula (> x 0))" in - let (formulas,_,_) = Z3.parse_smtlib_string_x ctx str [||] [||] [||] [||] in - let f i c = - printf "formula %d: %s\n" i (Z3.ast_to_string ctx c); - Z3.assert_cnstr ctx c; - in Array.iteri f formulas; - check ctx Z3.L_TRUE; - Z3.del_context ctx; - end;; - -(** - Demonstrates how to initialize the parser symbol table. - *) -let parser_example2() = - begin - printf "\nparser_example2\n%!"; - - let ctx = mk_context [||] in - let x = mk_int_var ctx "x" in - let x_decl = Z3.get_app_decl ctx (Z3.to_app ctx x) in - let y = mk_int_var ctx "y" in - let y_decl = Z3.get_app_decl ctx (Z3.to_app ctx y) in - let decls = [| x_decl; y_decl |] in - let a = Z3.mk_string_symbol ctx "a" in - let b = Z3.mk_string_symbol ctx "b" in - let names = [| a; b |] in - let str = "(benchmark tst :formula (> a b))" in - let f = Z3.parse_smtlib_string_formula ctx str [||] [||] names decls in - printf "formula: %s\n" (Z3.ast_to_string ctx f); - Z3.assert_cnstr ctx f; - check ctx Z3.L_TRUE; - Z3.del_context ctx; - end;; - -(** - Demonstrates how to initialize the parser symbol table. - *) -let parser_example3() = - begin - printf "\nparser_example3\n%!"; - - let ctx = mk_context [| |] in - let int_sort = Z3.mk_int_sort ctx in - let g_name = Z3.mk_string_symbol ctx "g" in - let g = Z3.mk_func_decl ctx g_name [| int_sort; int_sort |] int_sort in - let str = "(benchmark tst :formula (forall (x Int) (y Int) (implies (= x y) (= (g x 0) (g 0 y)))))" in - assert_comm_axiom ctx g; - let thm = Z3.parse_smtlib_string_formula ctx str [||] [||] [|g_name|] [|g|] in - printf "formula: %s\n" (Z3.ast_to_string ctx thm); - prove ctx thm true; - Z3.del_context ctx; - end;; - -(** - Display the declarations, assumptions and formulas in a SMT-LIB string. - *) -let parser_example4() = - begin - printf "\nparser_example4\n%!"; - - let ctx = mk_context [||] in - let str = "(benchmark tst :extrafuns ((x Int) (y Int)) :assumption (= x 20) :formula (> x y) :formula (> x 0))" in - (* arithmetic theory is automatically initialized, when an - int/real variable or arith operation is created using the API. - Since no such function is invoked in this example, we should do - that manually. - *) - let (formulas, assumptions, decls) = Z3.parse_smtlib_string_x ctx str [||] [||] [||] [||] in - let f prefix i n = printf "%s %d: %s\n" prefix i (Z3.ast_to_string ctx n) in - Array.iteri (fun i n -> printf "declaration %d: %s\n" i (Z3.func_decl_to_string ctx n)) decls; - Array.iteri (f "assumption") assumptions; - Array.iteri (f "formula") formulas; - Z3.del_context ctx; - end;; - -(** - Demonstrates how to handle parser errors using Z3 exceptions. - *) -let parser_example5() = - begin - printf "\nparser_example5\n"; - let ctx = mk_context [||] in - try - (* the following string has a parsing error: missing parenthesis *) - let str = "(benchmark tst :extrafuns ((x Int (y Int)) :formula (> x y) :formula (> x 0))" in - ignore(Z3.parse_smtlib_string_x ctx str [||] [||] [||] [||]); - with | _ -> (printf "Z3 error: parser error.\n"; - printf "Error message: '%s'.\n" (Z3.get_smtlib_error ctx) - ); - Z3.del_context ctx; - end;; - -(** - Example for creating an if-then-else expression. - *) -let ite_example() = - begin - printf "\nite_example\n%!"; - let ctx = mk_context [||] in - let f = Z3.mk_false ctx in - let one = mk_int ctx 1 in - let zero = mk_int ctx 0 in - let ite = Z3.mk_ite ctx f one zero in - printf "term: %s\n" (Z3.ast_to_string ctx ite); - Z3.del_context ctx; - end;; - - -(** - Create an enumeration data type. - - Several more examples of creating and using data-types (lists, trees, records) - are provided for the C-based API. - The translation from the examples in C to use the OCaml API follow the same pattern - that is used here. -*) -let enum_example() = - begin - printf "\nenum_example\n"; - let ctx = mk_context [||] in - let name = Z3.mk_string_symbol ctx "fruit" in - let enum_names = [| Z3.mk_string_symbol ctx "apple"; - Z3.mk_string_symbol ctx "banana"; - Z3.mk_string_symbol ctx "orange" |] in - let (fruit, enum_consts, enum_testers) = Z3.mk_enumeration_sort ctx name enum_names in - - printf "%s\n" (Z3.func_decl_to_string ctx enum_consts.(0)); - printf "%s\n" (Z3.func_decl_to_string ctx enum_consts.(1)); - printf "%s\n" (Z3.func_decl_to_string ctx enum_consts.(2)); - printf "%s\n" (Z3.func_decl_to_string ctx enum_testers.(0)); - printf "%s\n" (Z3.func_decl_to_string ctx enum_testers.(1)); - printf "%s\n" (Z3.func_decl_to_string ctx enum_testers.(2)); - - let apple = Z3.mk_app ctx (enum_consts.(0)) [||] in - let banana = Z3.mk_app ctx (enum_consts.(1)) [||] in - let orange = Z3.mk_app ctx (enum_consts.(2)) [||] in - - (* Apples are different from oranges *) - prove ctx (Z3.mk_not ctx (Z3.mk_eq ctx apple orange)) true; - - (* Apples pass the apple test *) - prove ctx (Z3.mk_app ctx enum_testers.(0) [| apple |]) true; - - (* Oranges fail the apple test *) - prove ctx (Z3.mk_app ctx enum_testers.(0) [| orange |]) false; - prove ctx (Z3.mk_not ctx (Z3.mk_app ctx enum_testers.(0) [| orange |])) true; - - let fruity = mk_var ctx "fruity" fruit in - - (* If something is fruity, then it is an apple, banana, or orange *) - let ors = [| Z3.mk_eq ctx fruity apple; - Z3.mk_eq ctx fruity banana; - Z3.mk_eq ctx fruity orange |] in - - prove ctx (Z3.mk_or ctx ors) true; - Z3.del_context ctx; - end;; - -(** - Example for extracting unsatisfiable core and proof. - The example uses the function check_assumptions which allows passing in additional - hypotheses. The unsatisfiable core is a subset of these additional hypotheses. - *) -let unsat_core_and_proof_example() = - begin - printf "\nunsat_core_and_proof_example\n%!"; - let ctx = mk_context [| ("PROOF_MODE","2") |] in - let pa = mk_bool_var ctx "PredA" in - let pb = mk_bool_var ctx "PredB" in - let pc = mk_bool_var ctx "PredC" in - let pd = mk_bool_var ctx "PredD" in - let p1 = mk_bool_var ctx "P1" in - let p2 = mk_bool_var ctx "P2" in - let p3 = mk_bool_var ctx "P3" in - let p4 = mk_bool_var ctx "P4" in - let assumptions = [| Z3.mk_not ctx p1; Z3.mk_not ctx p2; Z3.mk_not ctx p3; Z3.mk_not ctx p4 |] in - let f1 = Z3.mk_and ctx [| pa; pb; pc |] in - let f2 = Z3.mk_and ctx [| pa; Z3.mk_not ctx pc; pb |] in - let f3 = Z3.mk_or ctx [| Z3.mk_not ctx pa; Z3.mk_not ctx pc |] in - let f4 = pd in - let core_dummy = [| pa; pa; pa; pa |] in - Z3.assert_cnstr ctx (Z3.mk_or ctx [| f1; p1 |]); - Z3.assert_cnstr ctx (Z3.mk_or ctx [| f2; p2 |]); - Z3.assert_cnstr ctx (Z3.mk_or ctx [| f3; p3 |]); - Z3.assert_cnstr ctx (Z3.mk_or ctx [| f4; p4 |]); - let result = Z3.check_assumptions ctx assumptions 4 core_dummy in - (match result with - | (Z3.L_FALSE, _, proof, core_size, core) -> - printf "unsat\n"; - printf "proof: %s\n" (Z3.ast_to_string ctx proof); - printf("\ncore:\n"); - for i = 0 to core_size - 1 do - printf "%s\n" (Z3.ast_to_string ctx (core.(i))); - done; - printf("\n") - | (_,_,_,_,_)-> assert false; - ); - (* delete logical context *) - Z3.del_context(ctx); - end - -(** - -*) - -let get_implied_equalities_example() = - begin - printf "\nget_implied_equalities example\n%!"; - let ctx = mk_context [| |] in - let int_ty = Z3.mk_int_sort ctx in - let a = mk_int_var ctx "a" in - let b = mk_int_var ctx "b" in - let c = mk_int_var ctx "c" in - let d = mk_int_var ctx "d" in - let f = Z3.mk_func_decl ctx (Z3.mk_string_symbol ctx "f") [| int_ty |] int_ty in - let fa = Z3.mk_app ctx f [| a |] in - let fb = Z3.mk_app ctx f [| b |] in - let fc = Z3.mk_app ctx f [| c |] in - let terms = [| a; b; c; d; fa; fb; fc |] in - Z3.assert_cnstr ctx (Z3.mk_eq ctx a b); - Z3.assert_cnstr ctx (Z3.mk_eq ctx b c); - Z3.assert_cnstr ctx (Z3.mk_le ctx fc b); - Z3.assert_cnstr ctx (Z3.mk_le ctx b fa); - let is_sat, class_ids = Z3.get_implied_equalities ctx terms in - for i = 0 to 6 do - printf "Class %s |-> %d\n" (Z3.ast_to_string ctx (terms.(i))) (class_ids.(i)); - done; - printf "asserting f(a) <= b\n"; - Z3.assert_cnstr ctx (Z3.mk_le ctx fa b); - let is_sat, class_ids = Z3.get_implied_equalities ctx terms in - for i = 0 to 6 do - printf "Class %s |-> %d\n" (Z3.ast_to_string ctx (terms.(i))) (class_ids.(i)); - done; - (* delete logical context *) - Z3.del_context(ctx) - end;; - -let main() = - begin - ignore (Z3.open_log("ml.log")); - display_version(); - simple_example(); - demorgan(); - find_model_example1(); - find_model_example2(); - prove_example1(); - prove_example2(); - push_pop_example1(); - quantifier_example1(); - array_example1(); - array_example2(); - array_example3(); - tuple_example1(); - bitvector_example1(); - bitvector_example2(); - eval_example1(); - two_contexts_example1(); - error_code_example1(); - error_code_example2(); - parser_example1(); - parser_example2(); - parser_example3(); - parser_example4(); - parser_example5(); -(* numeral_example(); *) - ite_example(); -(* list_example(); *) -(* tree_example(); *) -(* forest_example(); *) -(* binary_tree_example(); *) - enum_example(); - unsat_core_and_proof_example(); - abstract_example(); - get_implied_equalities_example(); -(* incremental_example1(); *) -(* reference_counter_example(); *) -(* smt2parser_example(); *) -(* substitute_example(); *) -(* substitute_vars_example(); *) - end;; - -let _ = main();; diff --git a/src/api/ml/old/test_theory.ml b/src/api/ml/old/test_theory.ml deleted file mode 100644 index 8732bf220..000000000 --- a/src/api/ml/old/test_theory.ml +++ /dev/null @@ -1,42 +0,0 @@ -module Z3 = Z3.V3 - -let print_lbool lb = - match lb with - | Z3.L_FALSE -> Printf.printf "false\n" - | Z3.L_TRUE -> Printf.printf "true\n" - | Z3.L_UNDEF -> Printf.printf "undef\n" - -(* simple sanity test of theory plugin *) -let test_theory() = - let ctx = Z3.mk_context_x [| |] in - let th = Z3.mk_theory ctx "test-theory" in - let _ = Z3.set_push_callback th (fun () -> Printf.printf "push\n") in - let _ = Z3.set_pop_callback th (fun () -> Printf.printf "pop\n") in - let _ = Z3.set_delete_callback th (fun () -> Printf.printf "delete\n") in - let _ = Z3.set_final_check_callback th (fun () -> (Printf.printf "final\n"; true)) in - let _ = Z3.set_delete_callback th (fun () -> Printf.printf "deleted\n") in - let f_sym = Z3.mk_string_symbol ctx "f" in - let a_sym = Z3.mk_string_symbol ctx "a" in - let b_sym = Z3.mk_string_symbol ctx "b" in - let int_sort = Z3.mk_int_sort ctx in - let f = Z3.theory_mk_func_decl ctx th f_sym [|int_sort |] int_sort in - let a = Z3.theory_mk_constant ctx th a_sym int_sort in - let b = Z3.theory_mk_constant ctx th b_sym int_sort in - let reduce_f g args = - Printf.printf "reduce %s\n" (Z3.func_decl_to_string ctx g); - match g, args with - | _, [| a' |] when Z3.is_eq_func_decl ctx g f && Z3.is_eq_ast ctx a' a -> Some b - | _, _ -> None - in - let _ = Z3.set_reduce_app_callback th reduce_f in - (* b != f(b) is consistent *) - let _ = Z3.assert_cnstr ctx (Z3.mk_not ctx (Z3.mk_eq ctx b (Z3.mk_app ctx f [| b |]))) in - let res = Z3.check ctx in - print_lbool res; - (* b != f(a) is not consistent *) - let _ = Z3.assert_cnstr ctx (Z3.mk_not ctx (Z3.mk_eq ctx b (Z3.mk_app ctx f [| a |]))) in - let res = Z3.check ctx in - print_lbool res; - Z3.del_context ctx - -let _ = test_theory() diff --git a/src/api/ml/old/update-ml-doc.cmd b/src/api/ml/old/update-ml-doc.cmd deleted file mode 100755 index 32c39109e..000000000 --- a/src/api/ml/old/update-ml-doc.cmd +++ /dev/null @@ -1,38 +0,0 @@ -@echo off -SETLOCAL - -REM Script to generate Z3 OCaml API documentation -REM -REM Assumes that environment variables are set to provide access to the OCaml compilers, as well as the following commands: sed - -rd 2>NUL /s /q doc -md doc -cd doc -set MLDIR=.. -set DOCDIR=..\%1 - -ocamldoc.opt -hide Z3,Z3.V3,Test_mlapi -html -css-style z3_ml.css -I %MLDIR% %MLDIR%\test_mlapi.ml %MLDIR%\z3.mli - -sed "s|
val\(.*\)
|
val\1
|g;s|
type\(.*\)
|
type\1
|g;s|type\(.*\) = |
type\1 =
|g" Z3.html > Z3.new.html -move >NUL Z3.new.html Z3.html - -sed "s|
val\(.*\)
|
val\1
|g" Test_mlapi.html > Test_mlapi.new.html -move >NUL Test_mlapi.new.html Test_mlapi.html - -sed "s|

Index of values

|

OCaml: Index

|" Index_values.html > Index_values.new.html -move >NUL Index_values.new.html Index_values.html - -copy >NUL %DOCDIR%\tabs.css -copy >NUL %DOCDIR%\z3.png -copy >NUL %DOCDIR%\z3_ml.css - -sed "1,23d" Test_mlapi.html | sed "$d" > Test_mlapi.new.html - -type 2>NUL %DOCDIR%\test_mlapi_header.html Test_mlapi.new.html %DOCDIR%\mldoc_footer.html >Test_mlapi.html - -sed "1,37d" Z3.html > Z3.new.html - -type 2>NUL %DOCDIR%\z3_mlapi_header.html Z3.new.html >Z3.html - -exit /B 0 -ENDLOCAL diff --git a/src/api/ml/old/x3.ml b/src/api/ml/old/x3.ml deleted file mode 100644 index 6ca5d49eb..000000000 --- a/src/api/ml/old/x3.ml +++ /dev/null @@ -1,366 +0,0 @@ -/* Copyright (c) Microsoft Corporation */ - -quote (ml," - -(* Internal auxiliary functions: *) -(* -(* Transform a pair of arrays into an array of pairs *) -let array_combine a b = - if Array.length a <> Array.length b then raise (Invalid_argument \"array_combine\"); - Array.init (Array.length a) (fun i -> (a.(i), b.(i))) - -(* [a |> b] is the pipeline operator for [b(a)] *) -let ( |> ) x f = f x -*) - -(* Find the index of an element in an array, raises Not_found is missing *) -let find equal x a = - let len = Array.length a in - let rec find_ i = - if i >= len then - raise Not_found - else - if equal x a.(i) then - i - else - find_ (i+1) - in - find_ 0 - - -(* Symbols *) - -let symbol_refine c s = - match get_symbol_kind c s with - | INT_SYMBOL -> Symbol_int (get_symbol_int c s) - | STRING_SYMBOL -> Symbol_string (get_symbol_string c s) - -let mk_symbol c = function - | Symbol_int(i) -> mk_int_symbol c i - | Symbol_string(s) -> mk_string_symbol c s - - -(* Sorts *) - -let get_datatype_sort c s = - Array.init (get_datatype_sort_num_constructors c s) (fun i -> - let constructor = get_datatype_sort_constructor c s i in - let recognizer = get_datatype_sort_recognizer c s i in - let accessors = - Array.init (get_domain_size c constructor) (fun j -> - get_datatype_sort_constructor_accessor c s i j - ) in - {constructor; recognizer; accessors} - ) - -let sort_refine c s = - match get_sort_kind c s with - | UNINTERPRETED_SORT -> Sort_uninterpreted (get_sort_name c s) - | BOOL_SORT -> Sort_bool - | INT_SORT -> Sort_int - | BV_SORT -> Sort_bv (get_bv_sort_size c s) - | FINITE_DOMAIN_SORT -> - (match get_finite_domain_sort_size c s with - | Some(sz) -> Sort_finite_domain (get_sort_name c s, sz) - | None -> failwith \"Z3.sort_refine: failed to get size of finite-domain sort\" - ) - | REAL_SORT -> Sort_real - | ARRAY_SORT -> Sort_array (get_array_sort_domain c s, get_array_sort_range c s) - | DATATYPE_SORT -> Sort_datatype (get_datatype_sort c s) - | RELATION_SORT -> Sort_relation (Array.init (get_relation_arity c s) (fun i -> get_relation_column c s i)) - | UNKNOWN_SORT -> Sort_unknown - -let mk_sort c = function - | Sort_uninterpreted(s) -> mk_uninterpreted_sort c s - | Sort_bool -> mk_bool_sort c - | Sort_int -> mk_int_sort c - | Sort_bv(size) -> mk_bv_sort c size - | Sort_finite_domain(name,size) -> mk_finite_domain_sort c name size - | Sort_real -> mk_real_sort c - | Sort_array(domain,range) -> mk_array_sort c domain range - | Sort_datatype(constructors) -> get_range c constructors.(0).constructor - | Sort_relation(_) -> invalid_arg \"Z3.mk_sort: cannot construct relation sorts\" - | Sort_unknown(_) -> invalid_arg \"Z3.mk_sort: cannot construct unknown sorts\" - - -(* Replacement datatypes creation API *) - -let mk_datatypes ctx generator = - let usort0 = mk_uninterpreted_sort ctx (mk_int_symbol ctx 0) - in - let rec find_num_sorts i = - if i = max_int then invalid_arg \"mk_datatypes: too many sorts\" - else - match generator (Array.make i usort0) with - | None -> find_num_sorts (i+1) - | Some(a) when Array.length a = i -> i - | Some _ -> invalid_arg \"mk_datatypes: number of sorts and datatype descriptors must be equal\" - in - let num_sorts = find_num_sorts 0 - in - let sorts0 = Array.init num_sorts (fun i -> mk_uninterpreted_sort ctx (mk_int_symbol ctx i)) - in - let ctorss_descriptors = - match generator sorts0 with - | Some(ctorss_descriptors) -> ctorss_descriptors - | None -> invalid_arg \"mk_datatypes: generator failed\" - in - let names = Array.map fst ctorss_descriptors - in - let ctorss = - Array.map (fun (_, ctors_descriptor) -> - Array.map (fun {constructor_desc; recognizer_desc; accessor_descs} -> - let field_names = Array.map fst accessor_descs - in - let sort_refs = Array.make (Array.length accessor_descs) 0 - in - let field_sorts = - Array.mapi (fun i (_, sort) -> - try - let j = find (fun s t -> is_eq_sort ctx s t) sort sorts0 in - sort_refs.(i) <- j ; - None - with Not_found -> - Some(sort) - ) accessor_descs - in - mk_constructor ctx constructor_desc recognizer_desc field_names field_sorts sort_refs - ) ctors_descriptor - ) ctorss_descriptors - in - let constructor_lists = Array.map (mk_constructor_list ctx) ctorss - in - let sorts,_ = mk_datatypes ctx names constructor_lists - in - let datatypes = - Array.mapi (fun i sort -> - (sort, - Array.mapi (fun j ctor -> - let num_fields = Array.length (snd ctorss_descriptors.(i)).(j).accessor_descs in - let constructor, recognizer, accessors = query_constructor ctx ctor num_fields in - {constructor; recognizer; accessors} - ) ctorss.(i)) - ) sorts - in - Array.iter (fun ctor_list -> - del_constructor_list ctx ctor_list - ) constructor_lists - ; - Array.iter (fun ctors -> - Array.iter (fun ctor -> - del_constructor ctx ctor - ) ctors - ) ctorss - ; - datatypes - - -(* Numerals *) - -let rec numeral_refine c t = - assert( get_ast_kind c t = NUMERAL_AST ); - let sort = get_sort c t in - let is_int, i = get_numeral_int c t in - if is_int then - Numeral_int (i, sort) - else - let is_int64, i = get_numeral_int64 c t in - if is_int64 then - Numeral_int64 (i, sort) - else - if get_sort_kind c sort <> REAL_SORT then - Numeral_large (get_numeral_string c t, sort) - else - let n = numeral_refine c (get_numerator c t) in - let d = numeral_refine c (get_denominator c t) in - Numeral_rational (n, d) - - -let to_real c x = - if get_sort_kind c (get_sort c x) = REAL_SORT then - x - else - mk_int2real c x - -let rec embed_numeral c = function - | Numeral_int (i, s) -> mk_int c i s - | Numeral_int64 (i, s) -> mk_int64 c i s - | Numeral_large (l, s) -> mk_numeral c l s - | Numeral_rational (Numeral_int(n,_), Numeral_int(d,_)) -> mk_real c n d - | Numeral_rational (n, d) -> - mk_div c (to_real c (embed_numeral c n)) (to_real c (embed_numeral c d)) - (* Or should the following be used instead? - let n_str = get_numeral_string c (embed_numeral c n) in - let d_str = get_numeral_string c (embed_numeral c d) in - mk_numeral c (n_str ^ \" / \" ^ d_str) (mk_real_sort c) - *) - -(* Terms *) - -let get_app_args c a = - Array.init (get_app_num_args c a) (get_app_arg c a);; - -let get_domains c d = - Array.init (get_domain_size c d) (get_domain c d);; - - -let get_pattern_terms c p = - Array.init (get_pattern_num_terms c p) (get_pattern c p) - - -let term_refine c t = - match get_ast_kind c t with - | NUMERAL_AST -> - Term_numeral (numeral_refine c t) - | APP_AST -> - let t' = to_app c t in - let f = get_app_decl c t' in - let num_args = get_app_num_args c t' in - let args = Array.init num_args (get_app_arg c t') in - let k = get_decl_kind c f in - Term_app (k, f, args) - | QUANTIFIER_AST -> - let bt = if is_quantifier_forall c t then Forall else Exists in - let w = get_quantifier_weight c t in - let np = get_quantifier_num_patterns c t in - let pats = Array.init np (get_quantifier_pattern_ast c t) in - let pats = Array.map (get_pattern_terms c) pats in - let nb = get_quantifier_num_bound c t in - let bound = - Array.init nb (fun i -> - (get_quantifier_bound_name c t i, get_quantifier_bound_sort c t i) - ) in - let body = get_quantifier_body c t in - Term_quantifier (bt, w, pats, bound, body) - | VAR_AST -> - Term_var (get_index_value c t, get_sort c t) - | _ -> - assert false - - -(* let mk_term c = function *) -(* | Term_numeral (numeral, sort) -> mk_numeral c numeral sort *) -(* | Term_app (kind, decl, args) -> *) -(* | Term_quantifier (strength, weight, pats, bound, body) -> *) -(* | Term_var (index, sort) -> *) - - - -(* Refined model API *) - -let model_refine c m = - let num_sorts = model_get_num_sorts c m in - let sorts = Hashtbl.create num_sorts in - for i = 0 to num_sorts - 1 do - let sort = model_get_sort c m i in - let universe = model_get_sort_universe c m sort in - Hashtbl.add sorts sort universe - done; - let num_consts = model_get_num_consts c m in - let consts = Hashtbl.create num_consts in - let arrays = Hashtbl.create 0 in - for i = 0 to num_consts - 1 do - let const_decl = model_get_const_decl c m i in - match model_get_const_interp c m const_decl with - | Some(const_interp) -> - if is_as_array c const_interp then - let array_decl = get_as_array_func_decl c const_interp in - match model_get_func_interp c m array_decl with - | Some(array_interp) -> - let num_entries = func_interp_get_num_entries c array_interp in - let tbl = Hashtbl.create num_entries in - for i = 0 to num_entries - 1 do - let entry = func_interp_get_entry c array_interp i in - assert( func_entry_get_num_args c entry = 1 ); - let arg = func_entry_get_arg c entry 0 in - let value = func_entry_get_value c entry in - Hashtbl.add tbl arg value - done; - let default = func_interp_get_else c array_interp in - Hashtbl.add arrays const_decl (tbl, default) - | None -> - () - else - Hashtbl.add consts const_decl const_interp - | None -> - () - done; - let num_funcs = model_get_num_funcs c m in - let funcs = Hashtbl.create num_funcs in - for i = 0 to num_funcs - 1 do - let func_decl = model_get_func_decl c m i in - if not (Hashtbl.mem arrays func_decl) then - match model_get_func_interp c m func_decl with - | Some(func_interp) -> - let num_entries = func_interp_get_num_entries c func_interp in - let tbl = Hashtbl.create num_entries in - for i = 0 to num_entries - 1 do - let entry = func_interp_get_entry c func_interp i in - let num_args = func_entry_get_num_args c entry in - let args = Array.init num_args (fun i -> func_entry_get_arg c entry i) in - let value = func_entry_get_value c entry in - Hashtbl.add tbl args value - done; - let default = func_interp_get_else c func_interp in - Hashtbl.add funcs func_decl (tbl, default) - | None -> - () - done; - {sorts; consts; arrays; funcs} - - -(* Extended parser API *) - -let get_smtlib_formulas c = - Array.init (get_smtlib_num_formulas c) (get_smtlib_formula c) - -let get_smtlib_assumptions c = - Array.init (get_smtlib_num_assumptions c) (get_smtlib_assumption c) - -let get_smtlib_decls c = - Array.init (get_smtlib_num_decls c) (get_smtlib_decl c) - -let get_smtlib_parse_results c = - (get_smtlib_formulas c, get_smtlib_assumptions c, get_smtlib_decls c) - -let parse_smtlib_string_x c a1 a2 a3 a4 a5 = - parse_smtlib_string c a1 a2 a3 a4 a5 ; - get_smtlib_parse_results c - -let parse_smtlib_file_x c a1 a2 a3 a4 a5 = - parse_smtlib_file c a1 a2 a3 a4 a5 ; - get_smtlib_parse_results c - -let parse_smtlib_string_formula c a1 a2 a3 a4 a5 = - parse_smtlib_string c a1 a2 a3 a4 a5 ; - match get_smtlib_formulas c with [|f|] -> f | _ -> failwith \"Z3: parse_smtlib_string_formula\" - -let parse_smtlib_file_formula c a1 a2 a3 a4 a5 = - parse_smtlib_file c a1 a2 a3 a4 a5 ; - match get_smtlib_formulas c with [|f|] -> f | _ -> failwith \"Z3: parse_smtlib_file_formula\" - - -(* Error handling *) - -let get_error_msg c e = - match e with - | PARSER_ERROR -> (get_error_msg_ex c e) ^ \": \" ^ (get_smtlib_error c) - | _ -> get_error_msg_ex c e - - -(* Refined stats API *) - -let stats_refine c s = - let num_stats = stats_size c s in - let tbl = Hashtbl.create num_stats in - for i = 0 to num_stats - 1 do - let key = stats_get_key c s i in - let datum = - if stats_is_uint c s i then - Stat_int(stats_get_uint_value c s i) - else - Stat_float(stats_get_double_value c s i) in - Hashtbl.add tbl key datum - done; - tbl -"); diff --git a/src/api/ml/old/x3V3.ml b/src/api/ml/old/x3V3.ml deleted file mode 100644 index 96156f0a8..000000000 --- a/src/api/ml/old/x3V3.ml +++ /dev/null @@ -1,378 +0,0 @@ -quote (ml," - - -(* Internal auxillary functions: *) - -(* Transform a pair of arrays into an array of pairs *) -let array_combine a b = - if Array.length a <> Array.length b then raise (Invalid_argument \"array_combine\"); - Array.init (Array.length a) (fun i->(a.(i),b.(i)));; - -(* [a |> b] is the pipeline operator for [b(a)] *) -let ( |> ) x f = f x;; - - -(* Extensions, except for refinement: *) -let mk_context_x configs = - let config = mk_config() in - let f(param_id,param_value) = set_param_value config param_id param_value in - Array.iter f configs; - let context = mk_context config in - del_config config; - context;; - -let get_app_args c a = - Array.init (get_app_num_args c a) (get_app_arg c a);; - -let get_domains c d = - Array.init (get_domain_size c d) (get_domain c d);; - -let get_array_sort c t = (get_array_sort_domain c t, get_array_sort_range c t);; - -let get_tuple_sort c ty = - (get_tuple_sort_mk_decl c ty, - Array.init (get_tuple_sort_num_fields c ty) (get_tuple_sort_field_decl c ty));; - -type datatype_constructor_refined = { - constructor : func_decl; - recognizer : func_decl; - accessors : func_decl array -} - -let get_datatype_sort c ty = - Array.init (get_datatype_sort_num_constructors c ty) - (fun idx_c -> - let constr = get_datatype_sort_constructor c ty idx_c in - let recog = get_datatype_sort_recognizer c ty idx_c in - let num_acc = get_domain_size c constr in - { constructor = constr; - recognizer = recog; - accessors = Array.init num_acc (get_datatype_sort_constructor_accessor c ty idx_c); - }) - -let get_model_constants c m = - Array.init (get_model_num_constants c m) (get_model_constant c m);; - - -let get_model_func_entry c m i j = - (Array.init - (get_model_func_entry_num_args c m i j) - (get_model_func_entry_arg c m i j), - get_model_func_entry_value c m i j);; - -let get_model_func_entries c m i = - Array.init (get_model_func_num_entries c m i) (get_model_func_entry c m i);; - -let get_model_funcs c m = - Array.init (get_model_num_funcs c m) - (fun i->(get_model_func_decl c m i |> get_decl_name c, - get_model_func_entries c m i, - get_model_func_else c m i));; - -let get_smtlib_formulas c = - Array.init (get_smtlib_num_formulas c) (get_smtlib_formula c);; - -let get_smtlib_assumptions c = - Array.init (get_smtlib_num_assumptions c) (get_smtlib_assumption c);; - -let get_smtlib_decls c = - Array.init (get_smtlib_num_decls c) (get_smtlib_decl c);; - -let get_smtlib_parse_results c = - (get_smtlib_formulas c, get_smtlib_assumptions c, get_smtlib_decls c);; - -let parse_smtlib_string_formula c a1 a2 a3 a4 a5 = - (parse_smtlib_string c a1 a2 a3 a4 a5; - match get_smtlib_formulas c with [|f|] -> f | _ -> failwith \"Z3: parse_smtlib_string_formula\");; - -let parse_smtlib_file_formula c a1 a2 a3 a4 a5 = - (parse_smtlib_file c a1 a2 a3 a4 a5; - match get_smtlib_formulas c with [|f|] -> f | _ -> failwith \"Z3: parse_smtlib_file_formula\");; - -let parse_smtlib_string_x c a1 a2 a3 a4 a5 = - (parse_smtlib_string c a1 a2 a3 a4 a5; get_smtlib_parse_results c);; - -let parse_smtlib_file_x c a1 a2 a3 a4 a5 = - (parse_smtlib_file c a1 a2 a3 a4 a5; get_smtlib_parse_results c);; - -(* Refinement: *) - -type symbol_refined = - | Symbol_int of int - | Symbol_string of string - | Symbol_unknown;; - -let symbol_refine c s = - match get_symbol_kind c s with - | INT_SYMBOL -> Symbol_int (get_symbol_int c s) - | STRING_SYMBOL -> Symbol_string (get_symbol_string c s);; - -type sort_refined = - | Sort_uninterpreted of symbol - | Sort_bool - | Sort_int - | Sort_real - | Sort_bv of int - | Sort_array of (sort * sort) - | Sort_datatype of datatype_constructor_refined array - | Sort_relation - | Sort_finite_domain - | Sort_unknown of symbol;; - -let sort_refine c ty = - match get_sort_kind c ty with - | UNINTERPRETED_SORT -> Sort_uninterpreted (get_sort_name c ty) - | BOOL_SORT -> Sort_bool - | INT_SORT -> Sort_int - | REAL_SORT -> Sort_real - | BV_SORT -> Sort_bv (get_bv_sort_size c ty) - | ARRAY_SORT -> Sort_array (get_array_sort_domain c ty, get_array_sort_range c ty) - | DATATYPE_SORT -> Sort_datatype (get_datatype_sort c ty) - | RELATION_SORT -> Sort_relation - | FINITE_DOMAIN_SORT -> Sort_finite_domain - | UNKNOWN_SORT -> Sort_unknown (get_sort_name c ty);; - -let get_pattern_terms c p = - Array.init (get_pattern_num_terms c p) (get_pattern c p) - -type binder_type = | Forall | Exists - -type numeral_refined = - | Numeral_small of int64 * int64 - | Numeral_large of string - -type term_refined = - | Term_app of decl_kind * func_decl * ast array - | Term_quantifier of binder_type * int * ast array array * (symbol *sort) array * ast - | Term_numeral of numeral_refined * sort - | Term_var of int * sort - -let term_refine c t = - match get_ast_kind c t with - | NUMERAL_AST -> - let (is_small, n, d) = get_numeral_small c t in - if is_small then - Term_numeral(Numeral_small(n,d), get_sort c t) - else - Term_numeral(Numeral_large(get_numeral_string c t), get_sort c t) - | APP_AST -> - let t' = to_app c t in - let f = get_app_decl c t' in - let num_args = get_app_num_args c t' in - let args = Array.init num_args (get_app_arg c t') in - let k = get_decl_kind c f in - Term_app (k, f, args) - | QUANTIFIER_AST -> - let bt = if is_quantifier_forall c t then Forall else Exists in - let w = get_quantifier_weight c t in - let np = get_quantifier_num_patterns c t in - let pats = Array.init np (get_quantifier_pattern_ast c t) in - let pats = Array.map (get_pattern_terms c) pats in - let nb = get_quantifier_num_bound c t in - let bound = Array.init nb - (fun i -> (get_quantifier_bound_name c t i, get_quantifier_bound_sort c t i)) in - let body = get_quantifier_body c t in - Term_quantifier(bt, w, pats, bound, body) - | VAR_AST -> - Term_var(get_index_value c t, get_sort c t) - | _ -> assert false - -type theory_callbacks = - { - mutable delete_theory : unit -> unit; - mutable reduce_eq : ast -> ast -> ast option; - mutable reduce_app : func_decl -> ast array -> ast option; - mutable reduce_distinct : ast array -> ast option; - mutable final_check : unit -> bool; - mutable new_app : ast -> unit; - mutable new_elem : ast -> unit; - mutable init_search: unit -> unit; - mutable push: unit -> unit; - mutable pop: unit -> unit; - mutable restart : unit -> unit; - mutable reset: unit -> unit; - mutable new_eq : ast -> ast -> unit; - mutable new_diseq : ast -> ast -> unit; - mutable new_assignment: ast -> bool -> unit; - mutable new_relevant : ast -> unit; - } - -let mk_theory_callbacks() = - { - delete_theory = (fun () -> ()); - reduce_eq = (fun _ _ -> None); - reduce_app = (fun _ _ -> None); - reduce_distinct = (fun _ -> None); - final_check = (fun _ -> true); - new_app = (fun _ -> ()); - new_elem = (fun _ -> ()); - init_search= (fun () -> ()); - push= (fun () -> ()); - pop= (fun () -> ()); - restart = (fun () -> ()); - reset= (fun () -> ()); - new_eq = (fun _ _ -> ()); - new_diseq = (fun _ _ -> ()); - new_assignment = (fun _ _ -> ()); - new_relevant = (fun _ -> ()); - } - - -external get_theory_callbacks : theory -> theory_callbacks = \"get_theory_callbacks\" -external mk_theory_register : context -> string -> theory_callbacks -> theory = \"mk_theory_register\" -external set_delete_callback_register : theory -> unit = \"set_delete_callback_register\" -external set_reduce_app_callback_register : theory -> unit = \"set_reduce_app_callback_register\" -external set_reduce_eq_callback_register : theory -> unit = \"set_reduce_eq_callback_register\" -external set_reduce_distinct_callback_register : theory -> unit = \"set_reduce_distinct_callback_register\" -external set_new_app_callback_register : theory -> unit = \"set_new_app_callback_register\" -external set_new_elem_callback_register : theory -> unit = \"set_new_elem_callback_register\" -external set_init_search_callback_register : theory -> unit = \"set_init_search_callback_register\" -external set_push_callback_register : theory -> unit = \"set_push_callback_register\" -external set_pop_callback_register : theory -> unit = \"set_pop_callback_register\" -external set_restart_callback_register : theory -> unit = \"set_restart_callback_register\" -external set_reset_callback_register : theory -> unit = \"set_reset_callback_register\" -external set_final_check_callback_register : theory -> unit = \"set_final_check_callback_register\" -external set_new_eq_callback_register : theory -> unit = \"set_new_eq_callback_register\" -external set_new_diseq_callback_register : theory -> unit = \"set_new_diseq_callback_register\" -external set_new_assignment_callback_register : theory -> unit = \"set_new_assignment_callback_register\" -external set_new_relevant_callback_register : theory -> unit = \"set_new_relevant_callback_register\" - -let is_some opt = - match opt with - | Some v -> true - | None -> false - -let get_some opt = - match opt with - | Some v -> v - | None -> failwith \"None unexpected\" - - - - -let apply_delete (th:theory_callbacks) = th.delete_theory () -let set_delete_callback th cb = - let cbs = get_theory_callbacks th in - cbs.delete_theory <- cb; - set_delete_callback_register th - -let mk_theory context name = - Callback.register \"is_some\" is_some; - Callback.register \"get_some\" get_some; - Callback.register \"apply_delete\" apply_delete; - let cbs = mk_theory_callbacks() in - mk_theory_register context name cbs - - -let apply_reduce_app (th:theory_callbacks) f args = th.reduce_app f args -let set_reduce_app_callback th cb = - Callback.register \"apply_reduce_app\" apply_reduce_app; - let cbs = get_theory_callbacks th in - cbs.reduce_app <- cb; - set_reduce_app_callback_register th - -let apply_reduce_eq (th:theory_callbacks) a b = th.reduce_eq a b -let set_reduce_eq_callback th cb = - Callback.register \"apply_reduce_eq\" apply_reduce_eq; - let cbs = get_theory_callbacks th in - cbs.reduce_eq <- cb; - set_reduce_eq_callback_register th - -let apply_reduce_distinct (th:theory_callbacks) args = th.reduce_distinct args -let set_reduce_distinct_callback th cb = - Callback.register \"apply_reduce_distinct\" apply_reduce_distinct; - let cbs = get_theory_callbacks th in - cbs.reduce_distinct <- cb; - set_reduce_distinct_callback_register th - - -let apply_new_app (th:theory_callbacks) a = th.new_app a -let set_new_app_callback th cb = - Callback.register \"apply_new_app\" apply_new_app; - let cbs = get_theory_callbacks th in - cbs.new_app <- cb; - set_new_app_callback_register th - -let apply_new_elem (th:theory_callbacks) a = th.new_elem a -let set_new_elem_callback th cb = - Callback.register \"apply_new_elem\" apply_new_elem; - let cbs = get_theory_callbacks th in - cbs.new_elem <- cb; - set_new_elem_callback_register th - - -let apply_init_search (th:theory_callbacks) = th.init_search() -let set_init_search_callback th cb = - Callback.register \"apply_init_search\" apply_init_search; - let cbs = get_theory_callbacks th in - cbs.init_search <- cb; - set_init_search_callback_register th - - -let apply_push (th:theory_callbacks) = th.push() -let set_push_callback th cb = - Callback.register \"apply_push\" apply_push; - let cbs = get_theory_callbacks th in - cbs.push <- cb; - set_push_callback_register th - -let apply_pop (th:theory_callbacks) = th.pop() -let set_pop_callback th cb = - Callback.register \"apply_pop\" apply_pop; - let cbs = get_theory_callbacks th in - cbs.pop <- cb; - set_pop_callback_register th - - -let apply_restart (th:theory_callbacks) = th.restart() -let set_restart_callback th cb = - Callback.register \"apply_restart\" apply_restart; - let cbs = get_theory_callbacks th in - cbs.restart <- cb; - set_restart_callback_register th - - -let apply_reset (th:theory_callbacks) = th.reset() -let set_reset_callback th cb = - Callback.register \"apply_reset\" apply_reset; - let cbs = get_theory_callbacks th in - cbs.reset <- cb; - set_reset_callback_register th - -let apply_final_check (th:theory_callbacks) = th.final_check() -let set_final_check_callback th cb = - Callback.register \"apply_final_check\" apply_final_check; - let cbs = get_theory_callbacks th in - cbs.final_check <- cb; - set_final_check_callback_register th - -let apply_new_eq (th:theory_callbacks) a b = th.new_eq a b -let set_new_eq_callback th cb = - Callback.register \"apply_new_eq\" apply_new_eq; - let cbs = get_theory_callbacks th in - cbs.new_eq <- cb; - set_new_eq_callback_register th - - -let apply_new_diseq (th:theory_callbacks) a b = th.new_diseq a b -let set_new_diseq_callback th cb = - Callback.register \"apply_new_diseq\" apply_new_diseq; - let cbs = get_theory_callbacks th in - cbs.new_diseq <- cb; - set_new_diseq_callback_register th - -let apply_new_assignment (th:theory_callbacks) a b = th.new_assignment a b -let set_new_assignment_callback th cb = - Callback.register \"apply_new_assignment\" apply_new_assignment; - let cbs = get_theory_callbacks th in - cbs.new_assignment <- cb; - set_new_assignment_callback_register th - -let apply_new_relevant (th:theory_callbacks) a = th.new_relevant a -let set_new_relevant_callback th cb = - Callback.register \"apply_new_relevant\" apply_new_relevant; - let cbs = get_theory_callbacks th in - cbs.new_relevant <- cb; - set_new_relevant_callback_register th - -"); diff --git a/src/api/ml/old/x3V3.mli b/src/api/ml/old/x3V3.mli deleted file mode 100644 index 2aa2ba4e7..000000000 --- a/src/api/ml/old/x3V3.mli +++ /dev/null @@ -1,361 +0,0 @@ - -quote (mli," - -(** {2 {L ML Extensions}} *) - -(** - \[ [ mk_context_x configs] \] is a shorthand for the context with configurations in [configs]. -*) -val mk_context_x: (string * string) array -> context;; - -(** - \[ [ get_app_args c a ] \] is the array of arguments of an application. If [t] is a constant, then the array is empty. - - - {b See also}: {!Z3.get_app_num_args} - - {b See also}: {!Z3.get_app_arg} -*) -val get_app_args: context -> app -> ast array - -(** - \[ [ get_app_args c d ] \] is the array of parameters of [d]. - - - {b See also}: {!Z3.get_domain_size} - - {b See also}: {!Z3.get_domain} -*) -val get_domains: context -> func_decl -> sort array - -(** - \[ [ get_array_sort c t ] \] is the domain and the range of [t]. - - - {b See also}: {!Z3.get_array_sort_domain} - - {b See also}: {!Z3.get_array_sort_range} -*) -val get_array_sort: context -> sort -> sort * sort - -(** - \[ [ get_tuple_sort c ty ] \] is the pair [(mk_decl, fields)] where [mk_decl] is the constructor declaration of [ty], and [fields] is the array of fields in [ty]. - - - {b See also}: {!Z3.get_tuple_sort_mk_decl} - - {b See also}: {!Z3.get_tuple_sort_num_fields} - - {b See also}: {!Z3.get_tuple_sort_field_decl} -*) -val get_tuple_sort: context -> sort -> (func_decl * func_decl array) - -(** - \[ [ datatype_constructor_refined ] \] is the refinement of a datatype constructor. - - It contains the constructor declaration, recognizer, and list of accessor functions. -*) -type datatype_constructor_refined = { - constructor : func_decl; - recognizer : func_decl; - accessors : func_decl array -} - -(** - \[ [ get_datatype_sort c ty ] \] is the array of triples [(constructor, recognizer, fields)] where [constructor] is the constructor declaration of [ty], [recognizer] is the recognizer for the [constructor], and [fields] is the array of fields in [ty]. - - - {b See also}: {!Z3.get_datatype_sort_num_constructors} - - {b See also}: {!Z3.get_datatype_sort_constructor} - - {b See also}: {!Z3.get_datatype_sort_recognizer} - - {b See also}: {!Z3.get_datatype_sort_constructor_accessor} -*) - - -val get_datatype_sort: context -> sort -> datatype_constructor_refined array - -(** - \[ [ get_model_constants c m ] \] is the array of constants in the model [m]. - - - {b See also}: {!Z3.get_model_num_constants} - - {b See also}: {!Z3.get_model_constant} -*) -val get_model_constants: context -> model -> func_decl array - - -(** - \[ [ get_model_func_entry c m i j ] \] is the [j]'th entry in the [i]'th function in the model [m]. - - - {b See also}: {!Z3.get_model_func_entry_num_args} - - {b See also}: {!Z3.get_model_func_entry_arg} - - {b See also}: {!Z3.get_model_func_entry_value} -*) -val get_model_func_entry: context -> model -> int -> int -> (ast array * ast);; - -(** - \[ [ get_model_func_entries c m i ] \] is the array of entries in the [i]'th function in the model [m]. - - - {b See also}: {!Z3.get_model_func_num_entries} - - {b See also}: {!Z3.get_model_func_entry} -*) -val get_model_func_entries: context -> model -> int -> (ast array * ast) array;; - -(** - \[ [ get_model_funcs c m ] \] is the array of functions in the model [m]. Each function is represented by the triple [(decl, entries, else)], where [decl] is the declaration name for the function, [entries] is the array of entries in the function, and [else] is the default (else) value for the function. - - - {b See also}: {!Z3.get_model_num_funcs} - - {b See also}: {!Z3.get_model_func_decl} - - {b See also}: {!Z3.get_model_func_entries} - - {b See also}: {!Z3.get_model_func_else} -*) -val get_model_funcs: context -> model -> - (symbol * - (ast array * ast) array * - ast) array - -(** - \[ [ get_smtlib_formulas c ] \] is the array of formulas created by a preceding call to {!Z3.parse_smtlib_string} or {!Z3.parse_smtlib_file}. - - Recommend use {!Z3.parse_smtlib_string_x} or {!Z3.parse_smtlib_file_x} for functional style interface to the SMT-LIB parser. - - - {b See also}: {!Z3.parse_smtlib_string_x} - - {b See also}: {!Z3.parse_smtlib_file_x} - - {b See also}: {!Z3.parse_smtlib_string} - - {b See also}: {!Z3.parse_smtlib_file} - - {b See also}: {!Z3.get_smtlib_num_formulas} - - {b See also}: {!Z3.get_smtlib_formula} -*) -val get_smtlib_formulas: context -> ast array - -(** - \[ [get_smtlib_assumptions c] \] is the array of assumptions created by a preceding call to {!Z3.parse_smtlib_string} or {!Z3.parse_smtlib_file}. - - Recommend use {!Z3.parse_smtlib_string_x} or {!Z3.parse_smtlib_file_x} for functional style interface to the SMT-LIB parser. - - - - {b See also}: {!Z3.parse_smtlib_string_x} - - {b See also}: {!Z3.parse_smtlib_file_x} - - {b See also}: {!Z3.parse_smtlib_string} - - {b See also}: {!Z3.parse_smtlib_file} - - {b See also}: {!Z3.get_smtlib_num_assumptions} - - {b See also}: {!Z3.get_smtlib_assumption} -*) -val get_smtlib_assumptions: context -> ast array - -(** - \[ [ get_smtlib_decls c ] \] is the array of declarations created by a preceding call to {!Z3.parse_smtlib_string} or {!Z3.parse_smtlib_file}. - - Recommend use {!Z3.parse_smtlib_string_x} or {!Z3.parse_smtlib_file_x} for functional style interface to the SMT-LIB parser. - - - - {b See also}: {!Z3.parse_smtlib_string_x} - - {b See also}: {!Z3.parse_smtlib_file_x} - - {b See also}: {!Z3.parse_smtlib_string} - - {b See also}: {!Z3.parse_smtlib_file} - - {b See also}: {!Z3.get_smtlib_num_decls} - - {b See also}: {!Z3.get_smtlib_decl} -*) -val get_smtlib_decls: context -> func_decl array - -(** - \[ [ get_smtlib_parse_results c ] \] is the triple [(get_smtlib_formulas c, get_smtlib_assumptions c, get_smtlib_decls c)]. - - Recommend use {!Z3.parse_smtlib_string_x} or {!Z3.parse_smtlib_file_x} for functional style interface to the SMT-LIB parser. - - - - {b See also}: {!Z3.parse_smtlib_string_x} - - {b See also}: {!Z3.parse_smtlib_file_x} - - {b See also}: {!Z3.parse_smtlib_string} - - {b See also}: {!Z3.parse_smtlib_file} - - {b See also}: {!Z3.get_smtlib_formulas} - - {b See also}: {!Z3.get_smtlib_assumptions} - - {b See also}: {!Z3.get_smtlib_decls} -*) -val get_smtlib_parse_results: context -> (ast array * ast array * func_decl array) - -(** - \[ [ parse_smtlib_string_formula c ... ] \] calls [(parse_smtlib_string c ...)] and returns the single formula produced. - - Recommended for functional style interface to the SMT-LIB parser. - - - {b See also}: {!Z3.parse_smtlib_file_formula} - - {b See also}: {!Z3.parse_smtlib_string_x} -*) -val parse_smtlib_string_formula: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - -(** - \[ [ parse_smtlib_file_formula c ... ] \] calls [(parse_smtlib_file c ...)] and returns the single formula produced. - - Recommended for functional style interface to the SMT-LIB parser. - - - {b See also}: {!Z3.parse_smtlib_file_formula} - - {b See also}: {!Z3.parse_smtlib_file_x} -*) -val parse_smtlib_file_formula: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> ast - -(** - \[ [ parse_smtlib_string_x c ... ] \] is [(parse_smtlib_string c ...; get_smtlib_parse_results c)] - - Recommended for functional style interface to the SMT-LIB parser. - - - {b See also}: {!Z3.parse_smtlib_file_x} - - {b See also}: {!Z3.parse_smtlib_string} - - {b See also}: {!Z3.get_smtlib_parse_results} -*) -val parse_smtlib_string_x: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> (ast array * ast array * func_decl array) - -(** - \[ [ parse_smtlib_file_x c ... ] \] is [(parse_smtlib_file c ...; get_smtlib_parse_results c)] - - Recommended for functional style interface to the SMT-LIB parser. - - - {b See also}: {!Z3.parse_smtlib_string_x} - - {b See also}: {!Z3.parse_smtlib_file} - - {b See also}: {!Z3.get_smtlib_parse_results} -*) -val parse_smtlib_file_x: context -> string -> symbol array -> sort array -> symbol array -> func_decl array -> (ast array * ast array * func_decl array) - -(** - \[ [ symbol_refined ] \] is the refinement of a {!Z3.symbol} . - - - {b See also}: {!Z3.symbol_refine} - - {b See also}: {!Z3.get_symbol_kind} -*) -type symbol_refined = - | Symbol_int of int - | Symbol_string of string - | Symbol_unknown;; - -(** - \[ [ symbol_refine c s ] \] is the refined symbol of [s]. - - - {b See also}: {!Z3.symbol_refined} - - {b See also}: {!Z3.get_symbol_kind} -*) -val symbol_refine: context -> symbol -> symbol_refined;; - -(** - \[ [ sort_refined ] \] is the refinement of a {!Z3.sort} . - - - {b See also}: {!Z3.sort_refine} - - {b See also}: {!Z3.get_sort_kind} -*) - - -type sort_refined = - | Sort_uninterpreted of symbol - | Sort_bool - | Sort_int - | Sort_real - | Sort_bv of int - | Sort_array of (sort * sort) - | Sort_datatype of datatype_constructor_refined array - | Sort_relation - | Sort_finite_domain - | Sort_unknown of symbol - -(** - \[ [ sort_refine c t ] \] is the refined sort of [t]. - - - {b See also}: {!Z3.sort_refined} - - {b See also}: {!Z3.get_sort_kind} -*) -val sort_refine: context -> sort -> sort_refined;; - -(** - \[ [ binder_type ] \] is a universal or existential quantifier. - - - {b See also}: {!Z3.term_refined} -*) -type binder_type = | Forall | Exists - -(** - \[ [ numeral_refined ] \] is the refinement of a numeral . - - Numerals whose fractional representation can be fit with - 64 bit integers are treated as small. - -*) -type numeral_refined = - | Numeral_small of int64 * int64 - | Numeral_large of string - -(** - \[ [ term_refined ] \] is the refinement of a {!Z3.ast} . - - - {b See also}: {!Z3.term_refine} -*) -type term_refined = - | Term_app of decl_kind * func_decl * ast array - | Term_quantifier of binder_type * int * ast array array * (symbol * sort) array * ast - | Term_numeral of numeral_refined * sort - | Term_var of int * sort - -(** - \[ [ term_refine c a ] \] is the refined term of [a]. - - - {b See also}: {!Z3.term_refined} -*) -val term_refine : context -> ast -> term_refined - -(** - \[ [mk_theory c name ] \] create a custom theory. - -*) -val mk_theory : context -> string -> theory - -(** - \[ [set_delete_callback th cb] \] set callback when theory gets deleted. -*) -val set_delete_callback : theory -> (unit -> unit) -> unit - -(** - \[ [set_reduce_app_callback th cb] \] set callback for simplifying theory terms. -*) -val set_reduce_app_callback : theory -> (func_decl -> ast array -> ast option) -> unit - -(** - \[ [set_reduce_eq_callback th cb] \] set callback for simplifying equalities over theory terms. -*) -val set_reduce_eq_callback : theory -> (ast -> ast -> ast option) -> unit - -(** - \[ [set_reduce_distinct_callback th cb] \] set callback for simplifying disequalities over theory terms. -*) -val set_reduce_distinct_callback : theory -> (ast array -> ast option) -> unit - -(** - \[ [set_new_app_callback th cb] \] set callback for registering new application. -*) -val set_new_app_callback : theory -> (ast -> unit) -> unit - -(** - \[ [set_new_elem_callback th cb] \] set callback for registering new element. - - - {b See also}: the help for the corresponding C API function. -*) -val set_new_elem_callback : theory -> (ast -> unit) -> unit - -(** - \[ [set_init_search_callback th cb] \] set callback when Z3 starts searching for a satisfying assignment. -*) -val set_init_search_callback : theory -> (unit -> unit) -> unit - -(** - \[ [set_push_callback th cb] \] set callback for a logical context push. -*) -val set_push_callback : theory -> (unit -> unit) -> unit - -(** - \[ [set_pop_callback th cb] \] set callback for a logical context pop. -*) -val set_pop_callback : theory -> (unit -> unit) -> unit - -(** - \[ [set_restart_callback th cb] \] set callback for search restart. -*) -val set_restart_callback : theory -> (unit -> unit) -> unit - -val set_reset_callback : theory -> (unit -> unit) -> unit - -val set_final_check_callback : theory -> (unit -> bool) -> unit - -val set_new_eq_callback : theory -> (ast -> ast -> unit) -> unit - -val set_new_diseq_callback : theory -> (ast -> ast -> unit) -> unit - -val set_new_assignment_callback : theory -> (ast -> bool -> unit) -> unit - -val set_new_relevant_callback : theory -> (ast -> unit) -> unit - -"); diff --git a/src/api/ml/old/z3.0.idl b/src/api/ml/old/z3.0.idl deleted file mode 100644 index 3773a28e3..000000000 --- a/src/api/ml/old/z3.0.idl +++ /dev/null @@ -1,597 +0,0 @@ -/*++ -Copyright (c) Microsoft Corporation - -Module Name: - - Z3 - -Abstract: - - OCaml API for Z3. - - The following design is used for the treatment of reference counting: - - - The conversion of Z3_context from ML to C remembers the Z3 context, and - registers a finalizer using Gc.finalize that calls Z3_del_context. - - - The conversion of Z3_ast and other reference counted types from C to ML: - - + stores the last translated context with the Z3_ast in the wrapper - object; - - + registers a finalizer using Gc.finalize that decrements the reference - counter of the Z3_ast; - - + increments the reference count of the Z3_ast. - - The finalizers are registered using (the C interface to) Gc.finalize, - not attaching a finalizer to a custom block. The finalizers registered - by Gc.finalize are guaranteed to be called in reverse - registration-order, which is necessary to ensure that Z3_context's are - finalized only after all the Z3_ast's within them. - - - ML Z3.ast (and subtypes) are given generic hash and comparison - operations using Z3_get_ast_hash and Z3_get_ast_id. Other types could - be handled similarly if analogous hash and id operations were exported - by the C API. - - - The wrapper for Z3_mk_context is customized (using quote(call,...) in - z3_api.patched.h) to call Z3_mk_context_rc, and the ML API does not - include mk_context_rc. - - This scheme relies on the property that all reference counted values - returned from C to ML are in the Z3_context that was last sent from ML to - C. This is normally straightforward, but note that it depends on the - argument order of e.g. the Z3_*translate functions. - - Non-reference counted Z3 types that have delete operations have finalizers - that call the delete operations. The exposed delete operations are - shadowed by nop functions. The types whose delete operation accepts a - context use Gc.finalize while those that do not use custom block - finalizers. - - Custom c2ml functions check the Z3 error code prior to allocating ML - values or registering finalizers. Other functions check the Z3 error code - after making a Z3 library call. - - Some operations return NULL pointers when operations fail, or accept NULL - pointers. To handle these cases Z3_{ast,func_interp,sort}_opt types are - introduced. These are synonyms of Z3_{ast,func_interp,sort} but are - translated into OCaml option types. If the NULL pointers were passed to - ML, even if the user does not access them, they will have finalizers - registered, so when they die the OCaml GC will crash trying to call - dec_ref on NULL. - - There is an alternate implementation, enabled by setting LEAK_CONTEXTS, - that avoids the overhead of Gc.finalize finalizers, but at the price of - leaking Z3_context objects. - -Notes: - - OCaml does not support unsigned types, so CamlIDL conflates signed and - unsigned types of the same size. Therefore, functions in the C API - operating on unsigned values that become redundant after this conflation - are excluded from the ML API using [#ifndef CAMLIDL] in z3_api.h. - - CamlIDL does not support function pointers, so functions in the C API with - function pointer arguments are handled manually. - -Author: - - Jakob Lichtenberg (JakobL) 2007-08-08 - Josh Berdine (jjb) 2012-03-21 - ---*/ - - -// cpp trick to include expanded macro arguments in string literals -#define xstr(s) str(s) -#define str(s) #s -quote(c,"#define xstr(s) str(s)"); -quote(c,"#define str(s) #s"); - - -#ifndef MLAPIV3 - -#define DEFINE_TYPE(T) typedef [abstract] void* T -#define DEFINE_VOID(T) typedef [abstract] void* T - -#define BEGIN_MLAPI_EXCLUDE quote(mli,"(*"); -#define END_MLAPI_EXCLUDE quote(mli,"*)"); - -#ifdef LEAK_CONTEXTS - - // Declare pointer type with custom conversion functions. - #define DEFINE_CUST_TYPE(T) \ - typedef [abstract, ml2c(ml2c_Z3_ ## T), c2ml(c2ml_Z3_ ## T)] void* Z3_ ## T - -#else - - // Declare pointer type with custom conversion functions. - // Register an OCaml closure that just calls a C finalization function. - #define DEFINE_CUST_TYPE(T) \ - quote(ml,xstr(\ - external finalize_Z3_ ## T : T -> unit = xstr(finalize_Z3_ ## T);; \ - let _ = Callback.register xstr(finalize_Z3_ ## T) finalize_Z3_ ## T \ - )); \ - typedef [abstract, ml2c(ml2c_Z3_ ## T), c2ml(c2ml_Z3_ ## T)] void* Z3_ ## T - -#endif - - -// Z3_context -quote(c," -void check_error_code (Z3_context c); - -Z3_context last_ctx; -"); - -#ifdef LEAK_CONTEXTS - - quote(c," - value c2ml_Z3_context(Z3_context* c) - { - value v; - v = caml_alloc_small(1, Abstract_tag); - *((Z3_context *) Bp_val(v)) = *c; - return v; - } - - void ml2c_Z3_context(value v, Z3_context* c) - { - *c = *((Z3_context *) Bp_val(v)); - last_ctx = *c; - } - "); - -#else - - quote(c," - // caml_final_register is the implementation of Gc.finalize - value caml_final_register (value f, value v); - - void register_finalizer(value** closure, char* name, Z3_context ctx, value v) - { - if (*closure == NULL) { - *closure = caml_named_value(name); - if (*closure == NULL) { - Z3_set_error(ctx, Z3_INTERNAL_FATAL); - return; - } - } - caml_final_register(**closure, v); - } - - value c2ml_Z3_context (Z3_context* c) - { - static value* finalize_Z3_context_closure = NULL; - value v; - v = caml_alloc_small(1, Abstract_tag); - Field(v, 0) = (value) *c; - register_finalizer(&finalize_Z3_context_closure, \"finalize_Z3_context\", - (Z3_context) *c, v); - return v; - } - - void ml2c_Z3_context (value v, Z3_context* c) - { - *c = (Z3_context) Field(v, 0); - last_ctx = *c; - } - - value finalize_Z3_context (value v) - { - Z3_context c; - c = (Z3_context) Field(v, 0); - Z3_del_context(c); - return Val_unit; - } - "); - -#endif - -DEFINE_CUST_TYPE(context); - - -// Z3_symbol -typedef [abstract] void* Z3_symbol; - - -// Z3_ast: reference counted type with hashing and comparison -quote(c," -typedef struct _Z3_ast_context { - Z3_ast ast; - Z3_context ctx; -} Z3_ast_context; - -void ml2c_Z3_ast (value v, Z3_ast* c) -{ - *c = ((Z3_ast_context*) Data_custom_val(v))->ast; -} - -static int compare_Z3_ast (value v1, value v2) -{ - Z3_ast_context* ac1; - Z3_ast_context* ac2; - unsigned id1, id2; - ac1 = Data_custom_val(v1); - ac2 = Data_custom_val(v2); - id1 = Z3_get_ast_id(ac1->ctx, ac1->ast); - check_error_code(ac1->ctx); - id2 = Z3_get_ast_id(ac2->ctx, ac2->ast); - check_error_code(ac2->ctx); - return id2 - id1; -} - -static intnat hash_Z3_ast (value v) -{ - Z3_ast_context* ac; - unsigned hash; - ac = Data_custom_val(v); - hash = Z3_get_ast_hash(ac->ctx, ac->ast); - check_error_code(ac->ctx); - return hash; -} -"); - -#ifdef LEAK_CONTEXTS - - quote(c," - static void finalize_Z3_ast (value v) - { - Z3_ast_context* ac; - ac = Data_custom_val(v); - Z3_dec_ref(ac->ctx, ac->ast); - check_error_code(ac->ctx); - } - - static struct custom_operations cops_Z3_ast = { - NULL, - finalize_Z3_ast, - compare_Z3_ast, - hash_Z3_ast, - custom_serialize_default, - custom_deserialize_default - }; - - value c2ml_Z3_ast (Z3_ast* c) - { - value v; - Z3_ast_context* ac; - check_error_code(last_ctx); - v = alloc_custom(&cops_Z3_ast, sizeof(Z3_ast_context), 0, 1); - ac = Data_custom_val(v); - ac->ctx = last_ctx; - ac->ast = *c; - Z3_inc_ref(ac->ctx, ac->ast); - return v; - } - "); - -#else - - quote(c," - value finalize_Z3_ast (value v) - { - Z3_ast_context* ac; - ac = Data_custom_val(v); - Z3_dec_ref(ac->ctx, ac->ast); - check_error_code(ac->ctx); - return Val_unit; - } - - static struct custom_operations cops_Z3_ast = { - NULL, - custom_finalize_default, - compare_Z3_ast, - hash_Z3_ast, - custom_serialize_default, - custom_deserialize_default - }; - - value c2ml_Z3_ast (Z3_ast* c) - { - static value* finalize_Z3_ast_closure = NULL; - value v; - Z3_ast_context* ac; - check_error_code(last_ctx); - v = caml_alloc_custom(&cops_Z3_ast, sizeof(Z3_ast_context), 0, 1); - ac = Data_custom_val(v); - ac->ast = *c; - ac->ctx = last_ctx; - register_finalizer(&finalize_Z3_ast_closure, \"finalize_Z3_ast\", - (Z3_context) *c, v); - Z3_inc_ref(last_ctx, *c); - return v; - } - "); - -#endif - -DEFINE_CUST_TYPE(ast); - - -// subtypes of Z3_ast -quote(c,"\ -#define DEFINE_SUBAST_OPS(T) \ - void ml2c_ ## T (value v, T * a) \ - { \ - ml2c_Z3_ast(v, (Z3_ast*) a); \ - } \ - \ - value c2ml_ ## T (T * a) \ - { \ - return c2ml_Z3_ast((Z3_ast*) a); \ - } \ -"); - -#define DEFINE_SUBAST(T) \ - typedef [mltype("private ast"), ml2c(ml2c_ ## T), c2ml(c2ml_ ## T)] Z3_ast T - -quote(c,"DEFINE_SUBAST_OPS(Z3_sort)"); DEFINE_SUBAST(Z3_sort); -quote(c,"DEFINE_SUBAST_OPS(Z3_func_decl)"); DEFINE_SUBAST(Z3_func_decl); -quote(c,"DEFINE_SUBAST_OPS(Z3_app)"); DEFINE_SUBAST(Z3_app); -quote(c,"DEFINE_SUBAST_OPS(Z3_pattern)"); DEFINE_SUBAST(Z3_pattern); - - -// reference counted types without hashing and comparison -#ifdef LEAK_CONTEXTS - - quote(c,"\ - #define DEFINE_RC_OPS(T) \ - typedef struct _ ## T ## _context { \ - T dat; \ - Z3_context ctx; \ - } T ## _context; \ - \ - static void finalize_ ## T (value v) \ - { \ - T ## _context* ac; \ - ac = Data_custom_val(v); \ - T ## _dec_ref(ac->ctx, ac->dat); \ - check_error_code(ac->ctx); \ - } \ - \ - static struct custom_operations cops_ ## T = { \ - NULL, \ - finalize_ ## T, \ - custom_compare_default, \ - custom_hash_default, \ - custom_serialize_default, \ - custom_deserialize_default \ - }; \ - \ - value c2ml_ ## T (T * c) \ - { \ - value v; \ - T ## _context* ac; \ - check_error_code(last_ctx); \ - v = alloc_custom(&cops_ ## T, sizeof(T ## _context), 0, 1); \ - ac = Data_custom_val(v); \ - ac->dat = *c; \ - ac->ctx = last_ctx; \ - T ## _inc_ref(ac->ctx, ac->dat); \ - return v; \ - } \ - \ - void ml2c_ ## T (value v, T * c) \ - { \ - *c = ((T ## _context*) Data_custom_val(v))->dat; \ - } \ - "); - -#else - - quote(c,"\ - #define DEFINE_RC_OPS(T) \ - value c2ml_ ## T (T * c) \ - { \ - static value* finalize_ ## T ## _closure = NULL; \ - value v; \ - check_error_code(last_ctx); \ - v = caml_alloc_small(2, Abstract_tag); \ - Field(v, 0) = (value) *c; \ - Field(v, 1) = (value) last_ctx; \ - register_finalizer(&finalize_ ## T ## _closure, xstr(finalize_ ## T), \ - (Z3_context) *c, v); \ - T ## _inc_ref(last_ctx, *c); \ - return v; \ - } \ - \ - void ml2c_ ## T (value v, T * c) \ - { \ - *c = (T) Field(v, 0); \ - } \ - \ - value finalize_ ## T (value v) \ - { \ - Z3_context c; \ - c = (Z3_context) Field(v, 1); \ - T ## _dec_ref(c, (T) Field(v, 0)); \ - check_error_code(c); \ - return Val_unit; \ - } \ - "); - -#endif - -quote(c,"DEFINE_RC_OPS(Z3_params)"); DEFINE_CUST_TYPE(params); -quote(c,"DEFINE_RC_OPS(Z3_param_descrs)"); DEFINE_CUST_TYPE(param_descrs); -quote(c,"DEFINE_RC_OPS(Z3_model)"); DEFINE_CUST_TYPE(model); -quote(c,"DEFINE_RC_OPS(Z3_func_interp)"); DEFINE_CUST_TYPE(func_interp); -quote(c,"DEFINE_RC_OPS(Z3_func_entry)"); DEFINE_CUST_TYPE(func_entry); -quote(c,"DEFINE_RC_OPS(Z3_fixedpoint)"); DEFINE_CUST_TYPE(fixedpoint); -quote(c,"DEFINE_RC_OPS(Z3_ast_vector)"); DEFINE_CUST_TYPE(ast_vector); -quote(c,"DEFINE_RC_OPS(Z3_ast_map)"); DEFINE_CUST_TYPE(ast_map); -quote(c,"DEFINE_RC_OPS(Z3_goal)"); DEFINE_CUST_TYPE(goal); -quote(c,"DEFINE_RC_OPS(Z3_tactic)"); DEFINE_CUST_TYPE(tactic); -quote(c,"DEFINE_RC_OPS(Z3_probe)"); DEFINE_CUST_TYPE(probe); -quote(c,"DEFINE_RC_OPS(Z3_apply_result)"); DEFINE_CUST_TYPE(apply_result); -quote(c,"DEFINE_RC_OPS(Z3_solver)"); DEFINE_CUST_TYPE(solver); -quote(c,"DEFINE_RC_OPS(Z3_stats)"); DEFINE_CUST_TYPE(stats); - - -// possibly-NULL pointer types, translated to OCaml option types -quote(c,"\ -#define DEFINE_OPT_OPS(T) \ - void ml2c_ ## T ## _opt (value v, T* c) \ - { \ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; \ - camlidl_ctx _ctx = &_ctxs; \ - if (v != Val_int(0)) { \ - camlidl_ml2c_z3_ ## T(Field(v, 0), c, _ctx); \ - } else { \ - *c = NULL; \ - } \ - } \ - \ - value c2ml_ ## T ## _opt (T* c) \ - { \ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; \ - camlidl_ctx _ctx = &_ctxs; \ - value v; \ - value a; \ - if (*c) { \ - a = camlidl_c2ml_z3_ ## T(c, _ctx); \ - Begin_root(a) \ - v = caml_alloc_small(1, 0); \ - Field(v, 0) = a; \ - End_roots(); \ - } else { \ - v = Val_int(0); \ - } \ - return v; \ - } -"); - -#define DEFINE_OPT_TYPE(T) \ - typedef [mltype(xstr(T option)), \ - ml2c(ml2c_Z3_ ## T ## _opt), \ - c2ml(c2ml_Z3_ ## T ## _opt) \ - ] Z3_ ## T Z3_ ## T ## _opt - -quote(c,"DEFINE_OPT_OPS(Z3_ast)"); -DEFINE_OPT_TYPE(ast); - -quote(c,"DEFINE_OPT_OPS(Z3_sort)"); -DEFINE_OPT_TYPE(sort); - -quote(c,"DEFINE_OPT_OPS(Z3_func_interp)"); -DEFINE_OPT_TYPE(func_interp); - - -// ToDo: these unnecessarily appear in the API documentation -DEFINE_TYPE(Z3_constructor); -DEFINE_TYPE(Z3_constructor_list); - - -// shadow delete operations with nops -quote(ml," -let del_constructor _ _ = () -let del_constructor_list _ _ = () -let del_model _ _ = () -let del_context _ = () -let reset_memory () = () -"); - - -#else // MLAPIV3 - -// Provide custom error handler: -quote (c,"Z3_error_handler caml_z3_error_handler;"); -quote (c,"void caml_z3_error_handler(Z3_context c, Z3_error_code e) { static char buffer[128]; char * msg = Z3_get_error_msg_ex(c, e); if (strlen(msg) > 100) { failwith(\"Z3: error message is too big to fit in buffer\"); } else { sprintf(buffer, \"Z3: %s\", msg); failwith(buffer); } }"); - - -#define DEFINE_TYPE(T) typedef [abstract] void* T -#define DEFINE_VOID(T) typedef [abstract] void* T - -#define BEGIN_MLAPI_EXCLUDE -#define END_MLAPI_EXCLUDE - -#endif // MLAPIV3 - - - -#ifndef __in -#define __in [in] -#endif - -#ifndef __out -#define __out [out] -#endif - -#ifndef __out_opt -#define __out_opt [out,unique] -#endif - -#ifndef __ecount -#define __ecount(num_args) [NOT_SUPPORTED] -#endif - -#ifndef __in_ecount -#define __in_ecount(num_args) [in, size_is(num_args), length_is(num_args)] -#endif - -#ifndef __out_ecount -#define __out_ecount(num_args) [out, size_is(num_args), length_is(num_args)] -#endif - -#ifndef __inout_ecount -#define __inout_ecount(num_args) [in, out, size_is(num_args), length_is(num_args)] -#endif - -#ifndef __inout -#define __inout [in, out] -#endif - -#ifndef Z3_bool_opt -#define Z3_bool_opt void -#endif - - -#define Z3_API - -#ifdef MLAPIV3 - -#include "z3V3_api.idl" -#include "x3V3.mli" -#include "x3V3.ml" - -#else - -#include "z3_api.idl" -#include "x3.ml" - -quote(ml," -let _ = - Printexc.register_printer (function - | Error(c,e) -> Some (\"Z3 \"^(get_error_msg c e)) - | _ -> None - ) -"); - - -quote(mli," -(** - {2 {L Legacy V3 API}} -*) - -module V3 : sig -(** - {2 {L Legacy V3 API}} -*) -"); - -quote(ml," -module V3 = struct -"); - -#endif - -#ifdef MLAPIV3 - -quote(mlmli," -end -"); - -#endif diff --git a/src/api/ml/old/z3_stubs.c b/src/api/ml/old/z3_stubs.c deleted file mode 100644 index bad4338de..000000000 --- a/src/api/ml/old/z3_stubs.c +++ /dev/null @@ -1,19044 +0,0 @@ -/* File generated from z3.idl */ - -#include -#include -#include -#include -#include -#include -#include -#ifdef Custom_tag -#include -#include -#endif -#include - - -#include "z3.h" - -#define xstr(s) str(s) -#define str(s) #s - -void check_error_code (Z3_context c); -Z3_context last_ctx; - - - // caml_final_register is the implementation of Gc.finalize - value caml_final_register (value f, value v); - void register_finalizer(value** closure, char* name, Z3_context ctx, value v) - { - if (*closure == NULL) { - *closure = caml_named_value(name); - if (*closure == NULL) { - Z3_set_error(ctx, Z3_INTERNAL_FATAL); - return; - } - } - caml_final_register(**closure, v); - } - value c2ml_Z3_context (Z3_context* c) - { - static value* finalize_Z3_context_closure = NULL; - value v; - v = caml_alloc_small(1, Abstract_tag); - Field(v, 0) = (value) *c; - register_finalizer(&finalize_Z3_context_closure, "finalize_Z3_context", - (Z3_context) *c, v); - return v; - } - void ml2c_Z3_context (value v, Z3_context* c) - { - *c = (Z3_context) Field(v, 0); - last_ctx = *c; - } - value finalize_Z3_context (value v) - { - Z3_context c; - c = (Z3_context) Field(v, 0); - Z3_del_context(c); - return Val_unit; - } - -#define camlidl_ml2c_z3_Z3_context(v,c,ctx) ml2c_Z3_context(v,c) - -#define camlidl_c2ml_z3_Z3_context(c,ctx) c2ml_Z3_context(c) - -void camlidl_ml2c_z3_Z3_symbol(value _v1, Z3_symbol * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_symbol *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3_Z3_symbol(Z3_symbol * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_symbol) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_symbol *) Bp_val(_v1)) = *_c2; - return _v1; -} - - -typedef struct _Z3_ast_context { - Z3_ast ast; - Z3_context ctx; -} Z3_ast_context; -void ml2c_Z3_ast (value v, Z3_ast* c) -{ - *c = ((Z3_ast_context*) Data_custom_val(v))->ast; -} -static int compare_Z3_ast (value v1, value v2) -{ - Z3_ast_context* ac1; - Z3_ast_context* ac2; - unsigned id1, id2; - ac1 = Data_custom_val(v1); - ac2 = Data_custom_val(v2); - id1 = Z3_get_ast_id(ac1->ctx, ac1->ast); - check_error_code(ac1->ctx); - id2 = Z3_get_ast_id(ac2->ctx, ac2->ast); - check_error_code(ac2->ctx); - return id2 - id1; -} -static intnat hash_Z3_ast (value v) -{ - Z3_ast_context* ac; - unsigned hash; - ac = Data_custom_val(v); - hash = Z3_get_ast_hash(ac->ctx, ac->ast); - check_error_code(ac->ctx); - return hash; -} - - - value finalize_Z3_ast (value v) - { - Z3_ast_context* ac; - ac = Data_custom_val(v); - Z3_dec_ref(ac->ctx, ac->ast); - check_error_code(ac->ctx); - return Val_unit; - } - static struct custom_operations cops_Z3_ast = { - NULL, - custom_finalize_default, - compare_Z3_ast, - hash_Z3_ast, - custom_serialize_default, - custom_deserialize_default - }; - value c2ml_Z3_ast (Z3_ast* c) - { - static value* finalize_Z3_ast_closure = NULL; - value v; - Z3_ast_context* ac; - check_error_code(last_ctx); - v = caml_alloc_custom(&cops_Z3_ast, sizeof(Z3_ast_context), 0, 1); - ac = Data_custom_val(v); - ac->ast = *c; - ac->ctx = last_ctx; - register_finalizer(&finalize_Z3_ast_closure, "finalize_Z3_ast", - (Z3_context) *c, v); - Z3_inc_ref(last_ctx, *c); - return v; - } - -#define camlidl_ml2c_z3_Z3_ast(v,c,ctx) ml2c_Z3_ast(v,c) - -#define camlidl_c2ml_z3_Z3_ast(c,ctx) c2ml_Z3_ast(c) - -#define DEFINE_SUBAST_OPS(T) void ml2c_ ## T (value v, T * a) { ml2c_Z3_ast(v, (Z3_ast*) a); } value c2ml_ ## T (T * a) { return c2ml_Z3_ast((Z3_ast*) a); } -DEFINE_SUBAST_OPS(Z3_sort) -#define camlidl_ml2c_z3_Z3_sort(v,c,ctx) ml2c_Z3_sort(v,c) - -#define camlidl_c2ml_z3_Z3_sort(c,ctx) c2ml_Z3_sort(c) - -DEFINE_SUBAST_OPS(Z3_func_decl) -#define camlidl_ml2c_z3_Z3_func_decl(v,c,ctx) ml2c_Z3_func_decl(v,c) - -#define camlidl_c2ml_z3_Z3_func_decl(c,ctx) c2ml_Z3_func_decl(c) - -DEFINE_SUBAST_OPS(Z3_app) -#define camlidl_ml2c_z3_Z3_app(v,c,ctx) ml2c_Z3_app(v,c) - -#define camlidl_c2ml_z3_Z3_app(c,ctx) c2ml_Z3_app(c) - -DEFINE_SUBAST_OPS(Z3_pattern) -#define camlidl_ml2c_z3_Z3_pattern(v,c,ctx) ml2c_Z3_pattern(v,c) - -#define camlidl_c2ml_z3_Z3_pattern(c,ctx) c2ml_Z3_pattern(c) - - #define DEFINE_RC_OPS(T) value c2ml_ ## T (T * c) { static value* finalize_ ## T ## _closure = NULL; value v; check_error_code(last_ctx); v = caml_alloc_small(2, Abstract_tag); Field(v, 0) = (value) *c; Field(v, 1) = (value) last_ctx; register_finalizer(&finalize_ ## T ## _closure, xstr(finalize_ ## T), (Z3_context) *c, v); T ## _inc_ref(last_ctx, *c); return v; } void ml2c_ ## T (value v, T * c) { *c = (T) Field(v, 0); } value finalize_ ## T (value v) { Z3_context c; c = (Z3_context) Field(v, 1); T ## _dec_ref(c, (T) Field(v, 0)); check_error_code(c); return Val_unit; } -DEFINE_RC_OPS(Z3_params) -#define camlidl_ml2c_z3_Z3_params(v,c,ctx) ml2c_Z3_params(v,c) - -#define camlidl_c2ml_z3_Z3_params(c,ctx) c2ml_Z3_params(c) - -DEFINE_RC_OPS(Z3_param_descrs) -#define camlidl_ml2c_z3_Z3_param_descrs(v,c,ctx) ml2c_Z3_param_descrs(v,c) - -#define camlidl_c2ml_z3_Z3_param_descrs(c,ctx) c2ml_Z3_param_descrs(c) - -DEFINE_RC_OPS(Z3_model) -#define camlidl_ml2c_z3_Z3_model(v,c,ctx) ml2c_Z3_model(v,c) - -#define camlidl_c2ml_z3_Z3_model(c,ctx) c2ml_Z3_model(c) - -DEFINE_RC_OPS(Z3_func_interp) -#define camlidl_ml2c_z3_Z3_func_interp(v,c,ctx) ml2c_Z3_func_interp(v,c) - -#define camlidl_c2ml_z3_Z3_func_interp(c,ctx) c2ml_Z3_func_interp(c) - -DEFINE_RC_OPS(Z3_func_entry) -#define camlidl_ml2c_z3_Z3_func_entry(v,c,ctx) ml2c_Z3_func_entry(v,c) - -#define camlidl_c2ml_z3_Z3_func_entry(c,ctx) c2ml_Z3_func_entry(c) - -DEFINE_RC_OPS(Z3_fixedpoint) -#define camlidl_ml2c_z3_Z3_fixedpoint(v,c,ctx) ml2c_Z3_fixedpoint(v,c) - -#define camlidl_c2ml_z3_Z3_fixedpoint(c,ctx) c2ml_Z3_fixedpoint(c) - -DEFINE_RC_OPS(Z3_ast_vector) -#define camlidl_ml2c_z3_Z3_ast_vector(v,c,ctx) ml2c_Z3_ast_vector(v,c) - -#define camlidl_c2ml_z3_Z3_ast_vector(c,ctx) c2ml_Z3_ast_vector(c) - -DEFINE_RC_OPS(Z3_ast_map) -#define camlidl_ml2c_z3_Z3_ast_map(v,c,ctx) ml2c_Z3_ast_map(v,c) - -#define camlidl_c2ml_z3_Z3_ast_map(c,ctx) c2ml_Z3_ast_map(c) - -DEFINE_RC_OPS(Z3_goal) -#define camlidl_ml2c_z3_Z3_goal(v,c,ctx) ml2c_Z3_goal(v,c) - -#define camlidl_c2ml_z3_Z3_goal(c,ctx) c2ml_Z3_goal(c) - -DEFINE_RC_OPS(Z3_tactic) -#define camlidl_ml2c_z3_Z3_tactic(v,c,ctx) ml2c_Z3_tactic(v,c) - -#define camlidl_c2ml_z3_Z3_tactic(c,ctx) c2ml_Z3_tactic(c) - -DEFINE_RC_OPS(Z3_probe) -#define camlidl_ml2c_z3_Z3_probe(v,c,ctx) ml2c_Z3_probe(v,c) - -#define camlidl_c2ml_z3_Z3_probe(c,ctx) c2ml_Z3_probe(c) - -DEFINE_RC_OPS(Z3_apply_result) -#define camlidl_ml2c_z3_Z3_apply_result(v,c,ctx) ml2c_Z3_apply_result(v,c) - -#define camlidl_c2ml_z3_Z3_apply_result(c,ctx) c2ml_Z3_apply_result(c) - -DEFINE_RC_OPS(Z3_solver) -#define camlidl_ml2c_z3_Z3_solver(v,c,ctx) ml2c_Z3_solver(v,c) - -#define camlidl_c2ml_z3_Z3_solver(c,ctx) c2ml_Z3_solver(c) - -DEFINE_RC_OPS(Z3_stats) -#define camlidl_ml2c_z3_Z3_stats(v,c,ctx) ml2c_Z3_stats(v,c) - -#define camlidl_c2ml_z3_Z3_stats(c,ctx) c2ml_Z3_stats(c) - -#define DEFINE_OPT_OPS(T) void ml2c_ ## T ## _opt (value v, T* c) { struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; if (v != Val_int(0)) { camlidl_ml2c_z3_ ## T(Field(v, 0), c, _ctx); } else { *c = NULL; } } value c2ml_ ## T ## _opt (T* c) { struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; camlidl_ctx _ctx = &_ctxs; value v; value a; if (*c) { a = camlidl_c2ml_z3_ ## T(c, _ctx); Begin_root(a) v = caml_alloc_small(1, 0); Field(v, 0) = a; End_roots(); } else { v = Val_int(0); } return v; } - -DEFINE_OPT_OPS(Z3_ast) -#define camlidl_ml2c_z3_Z3_ast_opt(v,c,ctx) ml2c_Z3_ast_opt(v,c) - -#define camlidl_c2ml_z3_Z3_ast_opt(c,ctx) c2ml_Z3_ast_opt(c) - -DEFINE_OPT_OPS(Z3_sort) -#define camlidl_ml2c_z3_Z3_sort_opt(v,c,ctx) ml2c_Z3_sort_opt(v,c) - -#define camlidl_c2ml_z3_Z3_sort_opt(c,ctx) c2ml_Z3_sort_opt(c) - -DEFINE_OPT_OPS(Z3_func_interp) -#define camlidl_ml2c_z3_Z3_func_interp_opt(v,c,ctx) ml2c_Z3_func_interp_opt(v,c) - -#define camlidl_c2ml_z3_Z3_func_interp_opt(c,ctx) c2ml_Z3_func_interp_opt(c) - -void camlidl_ml2c_z3_Z3_constructor(value _v1, Z3_constructor * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_constructor *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3_Z3_constructor(Z3_constructor * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_constructor) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_constructor *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3_Z3_constructor_list(value _v1, Z3_constructor_list * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_constructor_list *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3_Z3_constructor_list(Z3_constructor_list * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_constructor_list) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_constructor_list *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3_Z3_string(value _v1, Z3_string * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_malloc_string(_v1, _ctx); -} - -value camlidl_c2ml_z3_Z3_string(Z3_string * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = copy_string((*_c2)); - return _v1; -} - -int camlidl_transl_table_z3_enum_1[3] = { - Z3_L_FALSE, - Z3_L_UNDEF, - Z3_L_TRUE, -}; - -void camlidl_ml2c_z3_Z3_lbool(value _v1, Z3_lbool * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_1[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_lbool(Z3_lbool * _c2, camlidl_ctx _ctx) -{ -value _v1; - switch((*_c2)) { - case Z3_L_FALSE: _v1 = Val_int(0); break; - case Z3_L_UNDEF: _v1 = Val_int(1); break; - case Z3_L_TRUE: _v1 = Val_int(2); break; - default: invalid_argument("typedef Z3_lbool: bad enum value"); - } - return _v1; -} - -int camlidl_transl_table_z3_enum_2[2] = { - Z3_INT_SYMBOL, - Z3_STRING_SYMBOL, -}; - -void camlidl_ml2c_z3_Z3_symbol_kind(value _v1, Z3_symbol_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_2[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_symbol_kind(Z3_symbol_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - switch((*_c2)) { - case Z3_INT_SYMBOL: _v1 = Val_int(0); break; - case Z3_STRING_SYMBOL: _v1 = Val_int(1); break; - default: invalid_argument("typedef Z3_symbol_kind: bad enum value"); - } - return _v1; -} - -int camlidl_transl_table_z3_enum_3[7] = { - Z3_PARAMETER_INT, - Z3_PARAMETER_DOUBLE, - Z3_PARAMETER_RATIONAL, - Z3_PARAMETER_SYMBOL, - Z3_PARAMETER_SORT, - Z3_PARAMETER_AST, - Z3_PARAMETER_FUNC_DECL, -}; - -void camlidl_ml2c_z3_Z3_parameter_kind(value _v1, Z3_parameter_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_3[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_parameter_kind(Z3_parameter_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_3, 7, "typedef Z3_parameter_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3_enum_4[10] = { - Z3_UNINTERPRETED_SORT, - Z3_BOOL_SORT, - Z3_INT_SORT, - Z3_REAL_SORT, - Z3_BV_SORT, - Z3_ARRAY_SORT, - Z3_DATATYPE_SORT, - Z3_RELATION_SORT, - Z3_FINITE_DOMAIN_SORT, - Z3_UNKNOWN_SORT, -}; - -void camlidl_ml2c_z3_Z3_sort_kind(value _v1, Z3_sort_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_4[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_sort_kind(Z3_sort_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_4, 10, "typedef Z3_sort_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3_enum_5[7] = { - Z3_NUMERAL_AST, - Z3_APP_AST, - Z3_VAR_AST, - Z3_QUANTIFIER_AST, - Z3_SORT_AST, - Z3_FUNC_DECL_AST, - Z3_UNKNOWN_AST, -}; - -void camlidl_ml2c_z3_Z3_ast_kind(value _v1, Z3_ast_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_5[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_ast_kind(Z3_ast_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_5, 7, "typedef Z3_ast_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3_enum_6[152] = { - Z3_OP_TRUE, - Z3_OP_FALSE, - Z3_OP_EQ, - Z3_OP_DISTINCT, - Z3_OP_ITE, - Z3_OP_AND, - Z3_OP_OR, - Z3_OP_IFF, - Z3_OP_XOR, - Z3_OP_NOT, - Z3_OP_IMPLIES, - Z3_OP_OEQ, - Z3_OP_ANUM, - Z3_OP_AGNUM, - Z3_OP_LE, - Z3_OP_GE, - Z3_OP_LT, - Z3_OP_GT, - Z3_OP_ADD, - Z3_OP_SUB, - Z3_OP_UMINUS, - Z3_OP_MUL, - Z3_OP_DIV, - Z3_OP_IDIV, - Z3_OP_REM, - Z3_OP_MOD, - Z3_OP_TO_REAL, - Z3_OP_TO_INT, - Z3_OP_IS_INT, - Z3_OP_POWER, - Z3_OP_STORE, - Z3_OP_SELECT, - Z3_OP_CONST_ARRAY, - Z3_OP_ARRAY_MAP, - Z3_OP_ARRAY_DEFAULT, - Z3_OP_SET_UNION, - Z3_OP_SET_INTERSECT, - Z3_OP_SET_DIFFERENCE, - Z3_OP_SET_COMPLEMENT, - Z3_OP_SET_SUBSET, - Z3_OP_AS_ARRAY, - Z3_OP_BNUM, - Z3_OP_BIT1, - Z3_OP_BIT0, - Z3_OP_BNEG, - Z3_OP_BADD, - Z3_OP_BSUB, - Z3_OP_BMUL, - Z3_OP_BSDIV, - Z3_OP_BUDIV, - Z3_OP_BSREM, - Z3_OP_BUREM, - Z3_OP_BSMOD, - Z3_OP_BSDIV0, - Z3_OP_BUDIV0, - Z3_OP_BSREM0, - Z3_OP_BUREM0, - Z3_OP_BSMOD0, - Z3_OP_ULEQ, - Z3_OP_SLEQ, - Z3_OP_UGEQ, - Z3_OP_SGEQ, - Z3_OP_ULT, - Z3_OP_SLT, - Z3_OP_UGT, - Z3_OP_SGT, - Z3_OP_BAND, - Z3_OP_BOR, - Z3_OP_BNOT, - Z3_OP_BXOR, - Z3_OP_BNAND, - Z3_OP_BNOR, - Z3_OP_BXNOR, - Z3_OP_CONCAT, - Z3_OP_SIGN_EXT, - Z3_OP_ZERO_EXT, - Z3_OP_EXTRACT, - Z3_OP_REPEAT, - Z3_OP_BREDOR, - Z3_OP_BREDAND, - Z3_OP_BCOMP, - Z3_OP_BSHL, - Z3_OP_BLSHR, - Z3_OP_BASHR, - Z3_OP_ROTATE_LEFT, - Z3_OP_ROTATE_RIGHT, - Z3_OP_EXT_ROTATE_LEFT, - Z3_OP_EXT_ROTATE_RIGHT, - Z3_OP_INT2BV, - Z3_OP_BV2INT, - Z3_OP_CARRY, - Z3_OP_XOR3, - Z3_OP_PR_UNDEF, - Z3_OP_PR_TRUE, - Z3_OP_PR_ASSERTED, - Z3_OP_PR_GOAL, - Z3_OP_PR_MODUS_PONENS, - Z3_OP_PR_REFLEXIVITY, - Z3_OP_PR_SYMMETRY, - Z3_OP_PR_TRANSITIVITY, - Z3_OP_PR_TRANSITIVITY_STAR, - Z3_OP_PR_MONOTONICITY, - Z3_OP_PR_QUANT_INTRO, - Z3_OP_PR_DISTRIBUTIVITY, - Z3_OP_PR_AND_ELIM, - Z3_OP_PR_NOT_OR_ELIM, - Z3_OP_PR_REWRITE, - Z3_OP_PR_REWRITE_STAR, - Z3_OP_PR_PULL_QUANT, - Z3_OP_PR_PULL_QUANT_STAR, - Z3_OP_PR_PUSH_QUANT, - Z3_OP_PR_ELIM_UNUSED_VARS, - Z3_OP_PR_DER, - Z3_OP_PR_QUANT_INST, - Z3_OP_PR_HYPOTHESIS, - Z3_OP_PR_LEMMA, - Z3_OP_PR_UNIT_RESOLUTION, - Z3_OP_PR_IFF_TRUE, - Z3_OP_PR_IFF_FALSE, - Z3_OP_PR_COMMUTATIVITY, - Z3_OP_PR_DEF_AXIOM, - Z3_OP_PR_DEF_INTRO, - Z3_OP_PR_APPLY_DEF, - Z3_OP_PR_IFF_OEQ, - Z3_OP_PR_NNF_POS, - Z3_OP_PR_NNF_NEG, - Z3_OP_PR_NNF_STAR, - Z3_OP_PR_CNF_STAR, - Z3_OP_PR_SKOLEMIZE, - Z3_OP_PR_MODUS_PONENS_OEQ, - Z3_OP_PR_TH_LEMMA, - Z3_OP_PR_HYPER_RESOLVE, - Z3_OP_RA_STORE, - Z3_OP_RA_EMPTY, - Z3_OP_RA_IS_EMPTY, - Z3_OP_RA_JOIN, - Z3_OP_RA_UNION, - Z3_OP_RA_WIDEN, - Z3_OP_RA_PROJECT, - Z3_OP_RA_FILTER, - Z3_OP_RA_NEGATION_FILTER, - Z3_OP_RA_RENAME, - Z3_OP_RA_COMPLEMENT, - Z3_OP_RA_SELECT, - Z3_OP_RA_CLONE, - Z3_OP_FD_LT, - Z3_OP_LABEL, - Z3_OP_LABEL_LIT, - Z3_OP_DT_CONSTRUCTOR, - Z3_OP_DT_RECOGNISER, - Z3_OP_DT_ACCESSOR, - Z3_OP_UNINTERPRETED, -}; - -void camlidl_ml2c_z3_Z3_decl_kind(value _v1, Z3_decl_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_6[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_decl_kind(Z3_decl_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_6, 152, "typedef Z3_decl_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3_enum_7[7] = { - Z3_PK_UINT, - Z3_PK_BOOL, - Z3_PK_DOUBLE, - Z3_PK_SYMBOL, - Z3_PK_STRING, - Z3_PK_OTHER, - Z3_PK_INVALID, -}; - -void camlidl_ml2c_z3_Z3_param_kind(value _v1, Z3_param_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_7[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_param_kind(Z3_param_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_7, 7, "typedef Z3_param_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3_enum_8[4] = { - Z3_PRINT_SMTLIB_FULL, - Z3_PRINT_LOW_LEVEL, - Z3_PRINT_SMTLIB_COMPLIANT, - Z3_PRINT_SMTLIB2_COMPLIANT, -}; - -void camlidl_ml2c_z3_Z3_ast_print_mode(value _v1, Z3_ast_print_mode * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_8[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_ast_print_mode(Z3_ast_print_mode * _c2, camlidl_ctx _ctx) -{ -value _v1; - switch((*_c2)) { - case Z3_PRINT_SMTLIB_FULL: _v1 = Val_int(0); break; - case Z3_PRINT_LOW_LEVEL: _v1 = Val_int(1); break; - case Z3_PRINT_SMTLIB_COMPLIANT: _v1 = Val_int(2); break; - case Z3_PRINT_SMTLIB2_COMPLIANT: _v1 = Val_int(3); break; - default: invalid_argument("typedef Z3_ast_print_mode: bad enum value"); - } - return _v1; -} - -int camlidl_transl_table_z3_enum_9[13] = { - Z3_OK, - Z3_SORT_ERROR, - Z3_IOB, - Z3_INVALID_ARG, - Z3_PARSER_ERROR, - Z3_NO_PARSER, - Z3_INVALID_PATTERN, - Z3_MEMOUT_FAIL, - Z3_FILE_ACCESS_ERROR, - Z3_INTERNAL_FATAL, - Z3_INVALID_USAGE, - Z3_DEC_REF_ERROR, - Z3_EXCEPTION, -}; - -void camlidl_ml2c_z3_Z3_error_code(value _v1, Z3_error_code * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_9[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_error_code(Z3_error_code * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3_enum_9, 13, "typedef Z3_error_code: bad enum value"); - return _v1; -} - - -/* All contexts share the same handler */ -static value caml_z3_error_handler = 0; - - -value camlidl_c2ml_z3_Z3_error_code(Z3_error_code * _c2, camlidl_ctx _ctx); -/* Error checking routine that raises OCaml Error exceptions */ -void check_error_code (Z3_context c) -{ - static struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - value* exn_tag = NULL; - value ctx_err[2]; - Z3_error_code e; - e = Z3_get_error_code(c); - if (e != Z3_OK) { - ctx_err[0] = c2ml_Z3_context(&c); - ctx_err[1] = camlidl_c2ml_z3_Z3_error_code(&e, &_ctxs); - exn_tag = caml_named_value("Z3.Error"); - if (*exn_tag == 0) { - fprintf(stderr, "Z3.Error not found"); - exit(1); - } - caml_raise_with_args(*exn_tag, 2, ctx_err); - } -} -/* Disable default error handler, all error checking is done by check_error_code */ -void* error_handler_static = NULL; - -int camlidl_transl_table_z3_enum_10[4] = { - Z3_GOAL_PRECISE, - Z3_GOAL_UNDER, - Z3_GOAL_OVER, - Z3_GOAL_UNDER_OVER, -}; - -void camlidl_ml2c_z3_Z3_goal_prec(value _v1, Z3_goal_prec * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3_enum_10[Int_val(_v1)]; -} - -value camlidl_c2ml_z3_Z3_goal_prec(Z3_goal_prec * _c2, camlidl_ctx _ctx) -{ -value _v1; - switch((*_c2)) { - case Z3_GOAL_PRECISE: _v1 = Val_int(0); break; - case Z3_GOAL_UNDER: _v1 = Val_int(1); break; - case Z3_GOAL_OVER: _v1 = Val_int(2); break; - case Z3_GOAL_UNDER_OVER: _v1 = Val_int(3); break; - default: invalid_argument("typedef Z3_goal_prec: bad enum value"); - } - return _v1; -} - - -value caml_z3_mk_context(value key_val_list) -{ - CAMLparam1( key_val_list ); - CAMLlocal4( item, vkey, vval, _vres ); - char * ckey; - char * cval; - Z3_config cfg; - Z3_context _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - cfg = Z3_mk_config(); - while (key_val_list != Val_emptylist) - { - item = Field(key_val_list, 0); - vkey = Field(item, 0); - vval = Field(item, 1); - ckey = camlidl_malloc_string(vkey, _ctx); - cval = camlidl_malloc_string(vval, _ctx); - Z3_set_param_value(cfg, ckey, cval); - key_val_list = Field(key_val_list, 1); - } - _res = Z3_mk_context_rc(cfg); - Z3_del_config(cfg); - _vres = camlidl_c2ml_z3_Z3_context(&_res, _ctx); - camlidl_free(_ctx); - Z3_set_error_handler(_res, error_handler_static); - CAMLreturn(_vres); -} - -value camlidl_z3_Z3_update_param_value( - value _v_c, - value _v_param_id, - value _v_param_value) -{ - Z3_context c; /*in*/ - Z3_string param_id; /*in*/ - Z3_string param_value; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_param_id, ¶m_id, _ctx); - camlidl_ml2c_z3_Z3_string(_v_param_value, ¶m_value, _ctx); - Z3_update_param_value(c, param_id, param_value); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_get_param_value( - value _v_c, - value _v_param_id) -{ - Z3_context c; /*in*/ - Z3_string param_id; /*in*/ - Z3_string *param_value; /*out*/ - Z3_string _c1; - value _v2; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_param_id, ¶m_id, _ctx); - param_value = &_c1; - Z3_get_param_value(c, param_id, param_value); - if (param_value == NULL) { - _vres = Val_int(0); - } else { - _v2 = camlidl_c2ml_z3_Z3_string(&*param_value, _ctx); - Begin_root(_v2) - _vres = camlidl_alloc_small(1, 0); - Field(_vres, 0) = _v2; - End_roots(); - } - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_interrupt( - value _v_c) -{ - Z3_context c; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - Z3_interrupt(c); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_mk_params( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_params _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_params(c); - _vres = camlidl_c2ml_z3_Z3_params(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_params_set_bool( - value _v_c, - value _v_p, - value _v_k, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_params p; /*in*/ - Z3_symbol k; /*in*/ - int v; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_k, &k, _ctx); - v = Int_val(_v_v); - Z3_params_set_bool(c, p, k, v); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_params_set_uint( - value _v_c, - value _v_p, - value _v_k, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_params p; /*in*/ - Z3_symbol k; /*in*/ - unsigned int v; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_k, &k, _ctx); - v = Int_val(_v_v); - Z3_params_set_uint(c, p, k, v); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_params_set_double( - value _v_c, - value _v_p, - value _v_k, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_params p; /*in*/ - Z3_symbol k; /*in*/ - double v; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_k, &k, _ctx); - v = Double_val(_v_v); - Z3_params_set_double(c, p, k, v); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_params_set_symbol( - value _v_c, - value _v_p, - value _v_k, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_params p; /*in*/ - Z3_symbol k; /*in*/ - Z3_symbol v; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_k, &k, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_v, &v, _ctx); - Z3_params_set_symbol(c, p, k, v); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_params_to_string( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_params p; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - _res = Z3_params_to_string(c, p); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_params_validate( - value _v_c, - value _v_p, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_params p; /*in*/ - Z3_param_descrs d; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_param_descrs(_v_d, &d, _ctx); - Z3_params_validate(c, p, d); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_param_descrs_get_kind( - value _v_c, - value _v_p, - value _v_n) -{ - Z3_context c; /*in*/ - Z3_param_descrs p; /*in*/ - Z3_symbol n; /*in*/ - Z3_param_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_param_descrs(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_n, &n, _ctx); - _res = Z3_param_descrs_get_kind(c, p, n); - _vres = camlidl_c2ml_z3_Z3_param_kind(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_param_descrs_size( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_param_descrs p; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_param_descrs(_v_p, &p, _ctx); - _res = Z3_param_descrs_size(c, p); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_param_descrs_get_name( - value _v_c, - value _v_p, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_param_descrs p; /*in*/ - unsigned int i; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_param_descrs(_v_p, &p, _ctx); - i = Int_val(_v_i); - _res = Z3_param_descrs_get_name(c, p, i); - _vres = camlidl_c2ml_z3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_param_descrs_to_string( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_param_descrs p; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_param_descrs(_v_p, &p, _ctx); - _res = Z3_param_descrs_to_string(c, p); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_int_symbol( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - int i; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_mk_int_symbol(c, i); - _vres = camlidl_c2ml_z3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_string_symbol( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_string s; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_s, &s, _ctx); - _res = Z3_mk_string_symbol(c, s); - _vres = camlidl_c2ml_z3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_uninterpreted_sort( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_mk_uninterpreted_sort(c, s); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bool_sort( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_bool_sort(c); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_int_sort( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_int_sort(c); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_real_sort( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_real_sort(c); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bv_sort( - value _v_c, - value _v_sz) -{ - Z3_context c; /*in*/ - unsigned int sz; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - sz = Int_val(_v_sz); - _res = Z3_mk_bv_sort(c, sz); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_finite_domain_sort( - value _v_c, - value _v_name, - value _v_size) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - unsigned long long size; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_name, &name, _ctx); - size = Int64_val(_v_size); - _res = Z3_mk_finite_domain_sort(c, name, size); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_array_sort( - value _v_c, - value _v_domain, - value _v_range) -{ - Z3_context c; /*in*/ - Z3_sort domain; /*in*/ - Z3_sort range; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_domain, &domain, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_range, &range, _ctx); - _res = Z3_mk_array_sort(c, domain, range); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_tuple_sort( - value _v_c, - value _v_mk_tuple_name, - value _v_field_names, - value _v_field_sorts) -{ - Z3_context c; /*in*/ - Z3_symbol mk_tuple_name; /*in*/ - unsigned int num_fields; /*in*/ - Z3_symbol const *field_names; /*in*/ - Z3_sort const *field_sorts; /*in*/ - Z3_func_decl *mk_tuple_decl; /*out*/ - Z3_func_decl *proj_decl; /*out*/ - Z3_sort _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - Z3_func_decl _c7; - mlsize_t _c8; - value _v9; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_mk_tuple_name, &mk_tuple_name, _ctx); - _c1 = Wosize_val(_v_field_names); - field_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_field_names, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &field_names[_c2], _ctx); - } - num_fields = _c1; - _c4 = Wosize_val(_v_field_sorts); - field_sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_field_sorts, _c5); - camlidl_ml2c_z3_Z3_sort(_v6, &field_sorts[_c5], _ctx); - } - num_fields = _c4; - mk_tuple_decl = &_c7; - proj_decl = camlidl_malloc(num_fields * sizeof(Z3_func_decl ), _ctx); - _res = Z3_mk_tuple_sort(c, mk_tuple_name, num_fields, field_names, field_sorts, mk_tuple_decl, proj_decl); - Begin_roots_block(_vres, 3) - _vres[0] = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - _vres[1] = camlidl_c2ml_z3_Z3_func_decl(&*mk_tuple_decl, _ctx); - _vres[2] = camlidl_alloc(num_fields, 0); - Begin_root(_vres[2]) - for (_c8 = 0; _c8 < num_fields; _c8++) { - _v9 = camlidl_c2ml_z3_Z3_func_decl(&proj_decl[_c8], _ctx); - modify(&Field(_vres[2], _c8), _v9); - } - End_roots() - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_mk_enumeration_sort( - value _v_c, - value _v_name, - value _v_enum_names) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - unsigned int n; /*in*/ - Z3_symbol const *enum_names; /*in*/ - Z3_func_decl *enum_consts; /*out*/ - Z3_func_decl *enum_testers; /*out*/ - Z3_sort _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - value _v5; - mlsize_t _c6; - value _v7; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_name, &name, _ctx); - _c1 = Wosize_val(_v_enum_names); - enum_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_enum_names, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &enum_names[_c2], _ctx); - } - n = _c1; - enum_consts = camlidl_malloc(n * sizeof(Z3_func_decl ), _ctx); - enum_testers = camlidl_malloc(n * sizeof(Z3_func_decl ), _ctx); - _res = Z3_mk_enumeration_sort(c, name, n, enum_names, enum_consts, enum_testers); - Begin_roots_block(_vres, 3) - _vres[0] = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - _vres[1] = camlidl_alloc(n, 0); - Begin_root(_vres[1]) - for (_c4 = 0; _c4 < n; _c4++) { - _v5 = camlidl_c2ml_z3_Z3_func_decl(&enum_consts[_c4], _ctx); - modify(&Field(_vres[1], _c4), _v5); - } - End_roots() - _vres[2] = camlidl_alloc(n, 0); - Begin_root(_vres[2]) - for (_c6 = 0; _c6 < n; _c6++) { - _v7 = camlidl_c2ml_z3_Z3_func_decl(&enum_testers[_c6], _ctx); - modify(&Field(_vres[2], _c6), _v7); - } - End_roots() - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_mk_list_sort( - value _v_c, - value _v_name, - value _v_elem_sort) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - Z3_sort elem_sort; /*in*/ - Z3_func_decl *nil_decl; /*out*/ - Z3_func_decl *is_nil_decl; /*out*/ - Z3_func_decl *cons_decl; /*out*/ - Z3_func_decl *is_cons_decl; /*out*/ - Z3_func_decl *head_decl; /*out*/ - Z3_func_decl *tail_decl; /*out*/ - Z3_sort _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - Z3_func_decl _c1; - Z3_func_decl _c2; - Z3_func_decl _c3; - Z3_func_decl _c4; - Z3_func_decl _c5; - Z3_func_decl _c6; - value _vresult; - value _vres[7] = { 0, 0, 0, 0, 0, 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_name, &name, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_elem_sort, &elem_sort, _ctx); - nil_decl = &_c1; - is_nil_decl = &_c2; - cons_decl = &_c3; - is_cons_decl = &_c4; - head_decl = &_c5; - tail_decl = &_c6; - _res = Z3_mk_list_sort(c, name, elem_sort, nil_decl, is_nil_decl, cons_decl, is_cons_decl, head_decl, tail_decl); - Begin_roots_block(_vres, 7) - _vres[0] = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - _vres[1] = camlidl_c2ml_z3_Z3_func_decl(&*nil_decl, _ctx); - _vres[2] = camlidl_c2ml_z3_Z3_func_decl(&*is_nil_decl, _ctx); - _vres[3] = camlidl_c2ml_z3_Z3_func_decl(&*cons_decl, _ctx); - _vres[4] = camlidl_c2ml_z3_Z3_func_decl(&*is_cons_decl, _ctx); - _vres[5] = camlidl_c2ml_z3_Z3_func_decl(&*head_decl, _ctx); - _vres[6] = camlidl_c2ml_z3_Z3_func_decl(&*tail_decl, _ctx); - _vresult = camlidl_alloc_small(7, 0); - { mlsize_t _c7; - for (_c7 = 0; _c7 < 7; _c7++) Field(_vresult, _c7) = _vres[_c7]; - } - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_mk_constructor( - value _v_c, - value _v_name, - value _v_recognizer, - value _v_field_names, - value _v_sorts, - value _v_sort_refs) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - Z3_symbol recognizer; /*in*/ - unsigned int num_fields; /*in*/ - Z3_symbol const *field_names; /*in*/ - Z3_sort_opt const *sorts; /*in*/ - unsigned int *sort_refs; /*in*/ - Z3_constructor _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_name, &name, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_recognizer, &recognizer, _ctx); - _c1 = Wosize_val(_v_field_names); - field_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_field_names, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &field_names[_c2], _ctx); - } - num_fields = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort_opt const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3_Z3_sort_opt(_v6, &sorts[_c5], _ctx); - } - num_fields = _c4; - _c7 = Wosize_val(_v_sort_refs); - sort_refs = camlidl_malloc(_c7 * sizeof(unsigned int ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_sort_refs, _c8); - sort_refs[_c8] = Int_val(_v9); - } - num_fields = _c7; - _res = Z3_mk_constructor(c, name, recognizer, num_fields, field_names, sorts, sort_refs); - _vres = camlidl_c2ml_z3_Z3_constructor(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_constructor_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_mk_constructor(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3_Z3_del_constructor( - value _v_c, - value _v_constr) -{ - Z3_context c; /*in*/ - Z3_constructor constr; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_constructor(_v_constr, &constr, _ctx); - Z3_del_constructor(c, constr); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_mk_datatype( - value _v_c, - value _v_name, - value _v_constructors) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - unsigned int num_constructors; /*in*/ - Z3_constructor *constructors; /*in,out*/ - Z3_sort _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - value _v5; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_name, &name, _ctx); - _c1 = Wosize_val(_v_constructors); - constructors = camlidl_malloc(_c1 * sizeof(Z3_constructor ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_constructors, _c2); - camlidl_ml2c_z3_Z3_constructor(_v3, &constructors[_c2], _ctx); - } - num_constructors = _c1; - _res = Z3_mk_datatype(c, name, num_constructors, constructors); - Begin_roots_block(_vres, 2) - _vres[0] = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - _vres[1] = camlidl_alloc(num_constructors, 0); - Begin_root(_vres[1]) - for (_c4 = 0; _c4 < num_constructors; _c4++) { - _v5 = camlidl_c2ml_z3_Z3_constructor(&constructors[_c4], _ctx); - modify(&Field(_vres[1], _c4), _v5); - } - End_roots() - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_mk_constructor_list( - value _v_c, - value _v_constructors) -{ - Z3_context c; /*in*/ - unsigned int num_constructors; /*in*/ - Z3_constructor const *constructors; /*in*/ - Z3_constructor_list _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_constructors); - constructors = camlidl_malloc(_c1 * sizeof(Z3_constructor const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_constructors, _c2); - camlidl_ml2c_z3_Z3_constructor(_v3, &constructors[_c2], _ctx); - } - num_constructors = _c1; - _res = Z3_mk_constructor_list(c, num_constructors, constructors); - _vres = camlidl_c2ml_z3_Z3_constructor_list(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_del_constructor_list( - value _v_c, - value _v_clist) -{ - Z3_context c; /*in*/ - Z3_constructor_list clist; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_constructor_list(_v_clist, &clist, _ctx); - Z3_del_constructor_list(c, clist); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_mk_datatypes( - value _v_c, - value _v_sort_names, - value _v_constructor_lists) -{ - Z3_context c; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort *sorts; /*out*/ - Z3_constructor_list *constructor_lists; /*in,out*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - value _v8; - mlsize_t _c9; - value _v10; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_constructor_lists); - constructor_lists = camlidl_malloc(_c4 * sizeof(Z3_constructor_list ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_constructor_lists, _c5); - camlidl_ml2c_z3_Z3_constructor_list(_v6, &constructor_lists[_c5], _ctx); - } - num_sorts = _c4; - sorts = camlidl_malloc(num_sorts * sizeof(Z3_sort ), _ctx); - Z3_mk_datatypes(c, num_sorts, sort_names, sorts, constructor_lists); - Begin_roots_block(_vres, 2) - _vres[0] = camlidl_alloc(num_sorts, 0); - Begin_root(_vres[0]) - for (_c7 = 0; _c7 < num_sorts; _c7++) { - _v8 = camlidl_c2ml_z3_Z3_sort(&sorts[_c7], _ctx); - modify(&Field(_vres[0], _c7), _v8); - } - End_roots() - _vres[1] = camlidl_alloc(num_sorts, 0); - Begin_root(_vres[1]) - for (_c9 = 0; _c9 < num_sorts; _c9++) { - _v10 = camlidl_c2ml_z3_Z3_constructor_list(&constructor_lists[_c9], _ctx); - modify(&Field(_vres[1], _c9), _v10); - } - End_roots() - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_query_constructor( - value _v_c, - value _v_constr, - value _v_num_fields) -{ - Z3_context c; /*in*/ - Z3_constructor constr; /*in*/ - unsigned int num_fields; /*in*/ - Z3_func_decl *constructor; /*out*/ - Z3_func_decl *tester; /*out*/ - Z3_func_decl *accessors; /*out*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - Z3_func_decl _c1; - Z3_func_decl _c2; - mlsize_t _c3; - value _v4; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_constructor(_v_constr, &constr, _ctx); - num_fields = Int_val(_v_num_fields); - constructor = &_c1; - tester = &_c2; - accessors = camlidl_malloc(num_fields * sizeof(Z3_func_decl ), _ctx); - Z3_query_constructor(c, constr, num_fields, constructor, tester, accessors); - Begin_roots_block(_vres, 3) - _vres[0] = camlidl_c2ml_z3_Z3_func_decl(&*constructor, _ctx); - _vres[1] = camlidl_c2ml_z3_Z3_func_decl(&*tester, _ctx); - _vres[2] = camlidl_alloc(num_fields, 0); - Begin_root(_vres[2]) - for (_c3 = 0; _c3 < num_fields; _c3++) { - _v4 = camlidl_c2ml_z3_Z3_func_decl(&accessors[_c3], _ctx); - modify(&Field(_vres[2], _c3), _v4); - } - End_roots() - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_mk_func_decl( - value _v_c, - value _v_s, - value _v_domain, - value _v_range) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - unsigned int domain_size; /*in*/ - Z3_sort const *domain; /*in*/ - Z3_sort range; /*in*/ - Z3_func_decl _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_s, &s, _ctx); - _c1 = Wosize_val(_v_domain); - domain = camlidl_malloc(_c1 * sizeof(Z3_sort const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_domain, _c2); - camlidl_ml2c_z3_Z3_sort(_v3, &domain[_c2], _ctx); - } - domain_size = _c1; - camlidl_ml2c_z3_Z3_sort(_v_range, &range, _ctx); - _res = Z3_mk_func_decl(c, s, domain_size, domain, range); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_app( - value _v_c, - value _v_d, - value _v_args) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_app(c, d, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_const( - value _v_c, - value _v_s, - value _v_ty) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_s, &s, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_const(c, s, ty); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_fresh_func_decl( - value _v_c, - value _v_prefix, - value _v_domain, - value _v_range) -{ - Z3_context c; /*in*/ - Z3_string prefix; /*in*/ - unsigned int domain_size; /*in*/ - Z3_sort const *domain; /*in*/ - Z3_sort range; /*in*/ - Z3_func_decl _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_prefix, &prefix, _ctx); - _c1 = Wosize_val(_v_domain); - domain = camlidl_malloc(_c1 * sizeof(Z3_sort const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_domain, _c2); - camlidl_ml2c_z3_Z3_sort(_v3, &domain[_c2], _ctx); - } - domain_size = _c1; - camlidl_ml2c_z3_Z3_sort(_v_range, &range, _ctx); - _res = Z3_mk_fresh_func_decl(c, prefix, domain_size, domain, range); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_fresh_const( - value _v_c, - value _v_prefix, - value _v_ty) -{ - Z3_context c; /*in*/ - Z3_string prefix; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_prefix, &prefix, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_fresh_const(c, prefix, ty); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_true( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_true(c); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_false( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_false(c); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_eq( - value _v_c, - value _v_l, - value _v_r) -{ - Z3_context c; /*in*/ - Z3_ast l; /*in*/ - Z3_ast r; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_l, &l, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_r, &r, _ctx); - _res = Z3_mk_eq(c, l, r); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_distinct( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_distinct(c, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_not( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_mk_not(c, a); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_ite( - value _v_c, - value _v_t1, - value _v_t2, - value _v_t3) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast t3; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t3, &t3, _ctx); - _res = Z3_mk_ite(c, t1, t2, t3); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_iff( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_iff(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_implies( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_implies(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_xor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_xor(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_and( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_and(c, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_or( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_or(c, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_add( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_add(c, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_mul( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_mul(c, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_sub( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_sub(c, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_unary_minus( - value _v_c, - value _v_arg) -{ - Z3_context c; /*in*/ - Z3_ast arg; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg, &arg, _ctx); - _res = Z3_mk_unary_minus(c, arg); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_div( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_div(c, arg1, arg2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_mod( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_mod(c, arg1, arg2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_rem( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_rem(c, arg1, arg2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_power( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_power(c, arg1, arg2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_lt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_lt(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_le( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_le(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_gt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_gt(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_ge( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_ge(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_int2real( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_int2real(c, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_real2int( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_real2int(c, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_is_int( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_is_int(c, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvnot( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvnot(c, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvredand( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvredand(c, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvredor( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvredor(c, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvand( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvand(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvor(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvxor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvxor(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvnand( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvnand(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvnor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvnor(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvxnor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvxnor(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvneg( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvneg(c, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvadd( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvadd(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsub( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsub(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvmul( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvmul(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvudiv( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvudiv(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsdiv( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsdiv(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvurem( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvurem(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsrem( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsrem(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsmod( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsmod(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvult( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvult(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvslt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvslt(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvule( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvule(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsle( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsle(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvuge( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvuge(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsge( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsge(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvugt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvugt(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsgt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsgt(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_concat( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_concat(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_extract( - value _v_c, - value _v_high, - value _v_low, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int high; /*in*/ - unsigned int low; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - high = Int_val(_v_high); - low = Int_val(_v_low); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_extract(c, high, low, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_sign_ext( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_sign_ext(c, i, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_zero_ext( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_zero_ext(c, i, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_repeat( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_repeat(c, i, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvshl( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvshl(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvlshr( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvlshr(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvashr( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvashr(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_rotate_left( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_rotate_left(c, i, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_rotate_right( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_rotate_right(c, i, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_ext_rotate_left( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_ext_rotate_left(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_ext_rotate_right( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_ext_rotate_right(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_int2bv( - value _v_c, - value _v_n, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int n; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - n = Int_val(_v_n); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_int2bv(c, n, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bv2int( - value _v_c, - value _v_t1, - value _v_is_signed) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - int is_signed; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - is_signed = Int_val(_v_is_signed); - _res = Z3_mk_bv2int(c, t1, is_signed); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvadd_no_overflow( - value _v_c, - value _v_t1, - value _v_t2, - value _v_is_signed) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - int is_signed; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - is_signed = Int_val(_v_is_signed); - _res = Z3_mk_bvadd_no_overflow(c, t1, t2, is_signed); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvadd_no_underflow( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvadd_no_underflow(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsub_no_overflow( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsub_no_overflow(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsub_no_underflow( - value _v_c, - value _v_t1, - value _v_t2, - value _v_is_signed) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - int is_signed; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - is_signed = Int_val(_v_is_signed); - _res = Z3_mk_bvsub_no_underflow(c, t1, t2, is_signed); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvsdiv_no_overflow( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsdiv_no_overflow(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvneg_no_overflow( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvneg_no_overflow(c, t1); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvmul_no_overflow( - value _v_c, - value _v_t1, - value _v_t2, - value _v_is_signed) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - int is_signed; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - is_signed = Int_val(_v_is_signed); - _res = Z3_mk_bvmul_no_overflow(c, t1, t2, is_signed); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bvmul_no_underflow( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvmul_no_underflow(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_select( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_i, &i, _ctx); - _res = Z3_mk_select(c, a, i); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_store( - value _v_c, - value _v_a, - value _v_i, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast i; /*in*/ - Z3_ast v; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_i, &i, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_v, &v, _ctx); - _res = Z3_mk_store(c, a, i, v); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_const_array( - value _v_c, - value _v_domain, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_sort domain; /*in*/ - Z3_ast v; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_domain, &domain, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_v, &v, _ctx); - _res = Z3_mk_const_array(c, domain, v); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_map( - value _v_c, - value _v_f, - value _v_n, - value _v_args) -{ - Z3_context c; /*in*/ - Z3_func_decl f; /*in*/ - unsigned int n; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - Z3_ast _c1; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_f, &f, _ctx); - n = Int_val(_v_n); - args = &_c1; - camlidl_ml2c_z3_Z3_ast(_v_args, &_c1, _ctx); - _res = Z3_mk_map(c, f, n, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_array_default( - value _v_c, - value _v_array) -{ - Z3_context c; /*in*/ - Z3_ast array; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_array, &array, _ctx); - _res = Z3_mk_array_default(c, array); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_sort( - value _v_c, - value _v_ty) -{ - Z3_context c; /*in*/ - Z3_sort ty; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_set_sort(c, ty); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_empty_set( - value _v_c, - value _v_domain) -{ - Z3_context c; /*in*/ - Z3_sort domain; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_domain, &domain, _ctx); - _res = Z3_mk_empty_set(c, domain); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_full_set( - value _v_c, - value _v_domain) -{ - Z3_context c; /*in*/ - Z3_sort domain; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_domain, &domain, _ctx); - _res = Z3_mk_full_set(c, domain); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_add( - value _v_c, - value _v_set, - value _v_elem) -{ - Z3_context c; /*in*/ - Z3_ast set; /*in*/ - Z3_ast elem; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_set, &set, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_elem, &elem, _ctx); - _res = Z3_mk_set_add(c, set, elem); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_del( - value _v_c, - value _v_set, - value _v_elem) -{ - Z3_context c; /*in*/ - Z3_ast set; /*in*/ - Z3_ast elem; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_set, &set, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_elem, &elem, _ctx); - _res = Z3_mk_set_del(c, set, elem); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_union( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_set_union(c, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_intersect( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_set_intersect(c, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_difference( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_set_difference(c, arg1, arg2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_complement( - value _v_c, - value _v_arg) -{ - Z3_context c; /*in*/ - Z3_ast arg; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg, &arg, _ctx); - _res = Z3_mk_set_complement(c, arg); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_member( - value _v_c, - value _v_elem, - value _v_set) -{ - Z3_context c; /*in*/ - Z3_ast elem; /*in*/ - Z3_ast set; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_elem, &elem, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_set, &set, _ctx); - _res = Z3_mk_set_member(c, elem, set); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_set_subset( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_set_subset(c, arg1, arg2); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_numeral( - value _v_c, - value _v_numeral, - value _v_ty) -{ - Z3_context c; /*in*/ - Z3_string numeral; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_numeral, &numeral, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_numeral(c, numeral, ty); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_real( - value _v_c, - value _v_num, - value _v_den) -{ - Z3_context c; /*in*/ - int num; /*in*/ - int den; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - num = Int_val(_v_num); - den = Int_val(_v_den); - _res = Z3_mk_real(c, num, den); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_int( - value _v_c, - value _v_v, - value _v_ty) -{ - Z3_context c; /*in*/ - int v; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - v = Int_val(_v_v); - camlidl_ml2c_z3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_int(c, v, ty); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_int64( - value _v_c, - value _v_v, - value _v_ty) -{ - Z3_context c; /*in*/ - long long v; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - v = Int64_val(_v_v); - camlidl_ml2c_z3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_int64(c, v, ty); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_pattern( - value _v_c, - value _v_terms) -{ - Z3_context c; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_ast const *terms; /*in*/ - Z3_pattern _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_terms); - terms = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_terms, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &terms[_c2], _ctx); - } - num_patterns = _c1; - _res = Z3_mk_pattern(c, num_patterns, terms); - _vres = camlidl_c2ml_z3_Z3_pattern(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_bound( - value _v_c, - value _v_index, - value _v_ty) -{ - Z3_context c; /*in*/ - unsigned int index; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - index = Int_val(_v_index); - camlidl_ml2c_z3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_bound(c, index, ty); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_forall( - value _v_c, - value _v_weight, - value _v_patterns, - value _v_sorts, - value _v_decl_names, - value _v_body) -{ - Z3_context c; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_decls; /*in*/ - Z3_sort const *sorts; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c1 * sizeof(Z3_pattern const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_patterns, _c2); - camlidl_ml2c_z3_Z3_pattern(_v3, &patterns[_c2], _ctx); - } - num_patterns = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_decls = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - camlidl_ml2c_z3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_forall(c, weight, num_patterns, patterns, num_decls, sorts, decl_names, body); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_forall_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_mk_forall(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3_Z3_mk_exists( - value _v_c, - value _v_weight, - value _v_patterns, - value _v_sorts, - value _v_decl_names, - value _v_body) -{ - Z3_context c; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_decls; /*in*/ - Z3_sort const *sorts; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c1 * sizeof(Z3_pattern const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_patterns, _c2); - camlidl_ml2c_z3_Z3_pattern(_v3, &patterns[_c2], _ctx); - } - num_patterns = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_decls = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - camlidl_ml2c_z3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_exists(c, weight, num_patterns, patterns, num_decls, sorts, decl_names, body); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_exists_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_mk_exists(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3_Z3_mk_quantifier( - value _v_c, - value _v_is_forall, - value _v_weight, - value _v_patterns, - value _v_sorts, - value _v_decl_names, - value _v_body) -{ - Z3_context c; /*in*/ - int is_forall; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_decls; /*in*/ - Z3_sort const *sorts; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - is_forall = Int_val(_v_is_forall); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c1 * sizeof(Z3_pattern const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_patterns, _c2); - camlidl_ml2c_z3_Z3_pattern(_v3, &patterns[_c2], _ctx); - } - num_patterns = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_decls = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - camlidl_ml2c_z3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_quantifier(c, is_forall, weight, num_patterns, patterns, num_decls, sorts, decl_names, body); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_quantifier_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_mk_quantifier(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); -} - -value camlidl_z3_Z3_mk_quantifier_ex( - value _v_c, - value _v_is_forall, - value _v_weight, - value _v_quantifier_id, - value _v_skolem_id, - value _v_patterns, - value _v_no_patterns, - value _v_sorts, - value _v_decl_names, - value _v_body) -{ - Z3_context c; /*in*/ - int is_forall; /*in*/ - unsigned int weight; /*in*/ - Z3_symbol quantifier_id; /*in*/ - Z3_symbol skolem_id; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_no_patterns; /*in*/ - Z3_ast const *no_patterns; /*in*/ - unsigned int num_decls; /*in*/ - Z3_sort const *sorts; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - is_forall = Int_val(_v_is_forall); - weight = Int_val(_v_weight); - camlidl_ml2c_z3_Z3_symbol(_v_quantifier_id, &quantifier_id, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_skolem_id, &skolem_id, _ctx); - _c1 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c1 * sizeof(Z3_pattern const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_patterns, _c2); - camlidl_ml2c_z3_Z3_pattern(_v3, &patterns[_c2], _ctx); - } - num_patterns = _c1; - _c4 = Wosize_val(_v_no_patterns); - no_patterns = camlidl_malloc(_c4 * sizeof(Z3_ast const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_no_patterns, _c5); - camlidl_ml2c_z3_Z3_ast(_v6, &no_patterns[_c5], _ctx); - } - num_no_patterns = _c4; - _c7 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c7 * sizeof(Z3_sort const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_sorts, _c8); - camlidl_ml2c_z3_Z3_sort(_v9, &sorts[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c10 * sizeof(Z3_symbol const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decl_names, _c11); - camlidl_ml2c_z3_Z3_symbol(_v12, &decl_names[_c11], _ctx); - } - num_decls = _c10; - camlidl_ml2c_z3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_quantifier_ex(c, is_forall, weight, quantifier_id, skolem_id, num_patterns, patterns, num_no_patterns, no_patterns, num_decls, sorts, decl_names, body); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_quantifier_ex_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_mk_quantifier_ex(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); -} - -value camlidl_z3_Z3_mk_forall_const( - value _v_c, - value _v_weight, - value _v_bound, - value _v_patterns, - value _v_body) -{ - Z3_context c; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_bound; /*in*/ - Z3_app const *bound; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_bound); - bound = camlidl_malloc(_c1 * sizeof(Z3_app const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_bound, _c2); - camlidl_ml2c_z3_Z3_app(_v3, &bound[_c2], _ctx); - } - num_bound = _c1; - _c4 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c4 * sizeof(Z3_pattern const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_patterns, _c5); - camlidl_ml2c_z3_Z3_pattern(_v6, &patterns[_c5], _ctx); - } - num_patterns = _c4; - camlidl_ml2c_z3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_forall_const(c, weight, num_bound, bound, num_patterns, patterns, body); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_exists_const( - value _v_c, - value _v_weight, - value _v_bound, - value _v_patterns, - value _v_body) -{ - Z3_context c; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_bound; /*in*/ - Z3_app const *bound; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_bound); - bound = camlidl_malloc(_c1 * sizeof(Z3_app const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_bound, _c2); - camlidl_ml2c_z3_Z3_app(_v3, &bound[_c2], _ctx); - } - num_bound = _c1; - _c4 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c4 * sizeof(Z3_pattern const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_patterns, _c5); - camlidl_ml2c_z3_Z3_pattern(_v6, &patterns[_c5], _ctx); - } - num_patterns = _c4; - camlidl_ml2c_z3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_exists_const(c, weight, num_bound, bound, num_patterns, patterns, body); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_quantifier_const( - value _v_c, - value _v_is_forall, - value _v_weight, - value _v_bound, - value _v_patterns, - value _v_body) -{ - Z3_context c; /*in*/ - int is_forall; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_bound; /*in*/ - Z3_app const *bound; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - is_forall = Int_val(_v_is_forall); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_bound); - bound = camlidl_malloc(_c1 * sizeof(Z3_app const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_bound, _c2); - camlidl_ml2c_z3_Z3_app(_v3, &bound[_c2], _ctx); - } - num_bound = _c1; - _c4 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c4 * sizeof(Z3_pattern const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_patterns, _c5); - camlidl_ml2c_z3_Z3_pattern(_v6, &patterns[_c5], _ctx); - } - num_patterns = _c4; - camlidl_ml2c_z3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_quantifier_const(c, is_forall, weight, num_bound, bound, num_patterns, patterns, body); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_quantifier_const_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_mk_quantifier_const(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3_Z3_mk_quantifier_const_ex( - value _v_c, - value _v_is_forall, - value _v_weight, - value _v_quantifier_id, - value _v_skolem_id, - value _v_bound, - value _v_patterns, - value _v_no_patterns, - value _v_body) -{ - Z3_context c; /*in*/ - int is_forall; /*in*/ - unsigned int weight; /*in*/ - Z3_symbol quantifier_id; /*in*/ - Z3_symbol skolem_id; /*in*/ - unsigned int num_bound; /*in*/ - Z3_app const *bound; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_no_patterns; /*in*/ - Z3_ast const *no_patterns; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - is_forall = Int_val(_v_is_forall); - weight = Int_val(_v_weight); - camlidl_ml2c_z3_Z3_symbol(_v_quantifier_id, &quantifier_id, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_skolem_id, &skolem_id, _ctx); - _c1 = Wosize_val(_v_bound); - bound = camlidl_malloc(_c1 * sizeof(Z3_app const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_bound, _c2); - camlidl_ml2c_z3_Z3_app(_v3, &bound[_c2], _ctx); - } - num_bound = _c1; - _c4 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c4 * sizeof(Z3_pattern const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_patterns, _c5); - camlidl_ml2c_z3_Z3_pattern(_v6, &patterns[_c5], _ctx); - } - num_patterns = _c4; - _c7 = Wosize_val(_v_no_patterns); - no_patterns = camlidl_malloc(_c7 * sizeof(Z3_ast const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_no_patterns, _c8); - camlidl_ml2c_z3_Z3_ast(_v9, &no_patterns[_c8], _ctx); - } - num_no_patterns = _c7; - camlidl_ml2c_z3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_quantifier_const_ex(c, is_forall, weight, quantifier_id, skolem_id, num_bound, bound, num_patterns, patterns, num_no_patterns, no_patterns, body); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_quantifier_const_ex_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_mk_quantifier_const_ex(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); -} - -value camlidl_z3_Z3_get_symbol_kind( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - Z3_symbol_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_get_symbol_kind(c, s); - _vres = camlidl_c2ml_z3_Z3_symbol_kind(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_symbol_int( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_get_symbol_int(c, s); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_symbol_string( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_get_symbol_string(c, s); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_sort_name( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_sort d; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_d, &d, _ctx); - _res = Z3_get_sort_name(c, d); - _vres = camlidl_c2ml_z3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_sort_id( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_get_sort_id(c, s); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_sort_to_ast( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_sort_to_ast(c, s); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_eq_sort( - value _v_c, - value _v_s1, - value _v_s2) -{ - Z3_context c; /*in*/ - Z3_sort s1; /*in*/ - Z3_sort s2; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s1, &s1, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s2, &s2, _ctx); - _res = Z3_is_eq_sort(c, s1, s2); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_sort_kind( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - Z3_sort_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_sort_kind(c, t); - _vres = camlidl_c2ml_z3_Z3_sort_kind(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_bv_sort_size( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_bv_sort_size(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_finite_domain_sort_size( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - unsigned long long *r; /*out*/ - unsigned long long _c1; - value _v2; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s, &s, _ctx); - r = &_c1; - Z3_get_finite_domain_sort_size(c, s, r); - if (r == NULL) { - _vres = Val_int(0); - } else { - _v2 = copy_int64(*r); - Begin_root(_v2) - _vres = camlidl_alloc_small(1, 0); - Field(_vres, 0) = _v2; - End_roots(); - } - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_array_sort_domain( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_array_sort_domain(c, t); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_array_sort_range( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_array_sort_range(c, t); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_tuple_sort_mk_decl( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_tuple_sort_mk_decl(c, t); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_tuple_sort_num_fields( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_tuple_sort_num_fields(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_tuple_sort_field_decl( - value _v_c, - value _v_t, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int i; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - i = Int_val(_v_i); - _res = Z3_get_tuple_sort_field_decl(c, t, i); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_datatype_sort_num_constructors( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_datatype_sort_num_constructors(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_datatype_sort_constructor( - value _v_c, - value _v_t, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int idx; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_datatype_sort_constructor(c, t, idx); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_datatype_sort_recognizer( - value _v_c, - value _v_t, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int idx; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_datatype_sort_recognizer(c, t, idx); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_datatype_sort_constructor_accessor( - value _v_c, - value _v_t, - value _v_idx_c, - value _v_idx_a) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int idx_c; /*in*/ - unsigned int idx_a; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_t, &t, _ctx); - idx_c = Int_val(_v_idx_c); - idx_a = Int_val(_v_idx_a); - _res = Z3_get_datatype_sort_constructor_accessor(c, t, idx_c, idx_a); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_relation_arity( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_get_relation_arity(c, s); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_relation_column( - value _v_c, - value _v_s, - value _v_col) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - unsigned int col; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s, &s, _ctx); - col = Int_val(_v_col); - _res = Z3_get_relation_column(c, s, col); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_decl_to_ast( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_func_decl f; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_f, &f, _ctx); - _res = Z3_func_decl_to_ast(c, f); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_eq_func_decl( - value _v_c, - value _v_f1, - value _v_f2) -{ - Z3_context c; /*in*/ - Z3_func_decl f1; /*in*/ - Z3_func_decl f2; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_f1, &f1, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_f2, &f2, _ctx); - _res = Z3_is_eq_func_decl(c, f1, f2); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_func_decl_id( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_func_decl f; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_f, &f, _ctx); - _res = Z3_get_func_decl_id(c, f); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_name( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_decl_name(c, d); - _vres = camlidl_c2ml_z3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_kind( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - Z3_decl_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_decl_kind(c, d); - _vres = camlidl_c2ml_z3_Z3_decl_kind(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_domain_size( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_domain_size(c, d); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_arity( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_arity(c, d); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_domain( - value _v_c, - value _v_d, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int i; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - i = Int_val(_v_i); - _res = Z3_get_domain(c, d, i); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_range( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_range(c, d); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_num_parameters( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_decl_num_parameters(c, d); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_parameter_kind( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_parameter_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_parameter_kind(c, d, idx); - _vres = camlidl_c2ml_z3_Z3_parameter_kind(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_int_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_int_parameter(c, d, idx); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_double_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - double _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_double_parameter(c, d, idx); - _vres = copy_double(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_symbol_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_symbol_parameter(c, d, idx); - _vres = camlidl_c2ml_z3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_sort_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_sort_parameter(c, d, idx); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_ast_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_ast_parameter(c, d, idx); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_func_decl_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_func_decl_parameter(c, d, idx); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_decl_rational_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_rational_parameter(c, d, idx); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_app_to_ast( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_app a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_app(_v_a, &a, _ctx); - _res = Z3_app_to_ast(c, a); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_app_decl( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_app a; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_app(_v_a, &a, _ctx); - _res = Z3_get_app_decl(c, a); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_app_num_args( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_app a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_app(_v_a, &a, _ctx); - _res = Z3_get_app_num_args(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_app_arg( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_app a; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_app(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_app_arg(c, a, i); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_eq_ast( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_is_eq_ast(c, t1, t2); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_ast_id( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_ast t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t, &t, _ctx); - _res = Z3_get_ast_id(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_ast_hash( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_ast_hash(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_sort( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_sort(c, a); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_well_sorted( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_ast t; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t, &t, _ctx); - _res = Z3_is_well_sorted(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_bool_value( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_lbool _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_bool_value(c, a); - _vres = camlidl_c2ml_z3_Z3_lbool(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_ast_kind( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_ast_kind(c, a); - _vres = camlidl_c2ml_z3_Z3_ast_kind(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_app( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_app(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_numeral_ast( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_numeral_ast(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_algebraic_number( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_algebraic_number(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_to_app( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_app _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_to_app(c, a); - _vres = camlidl_c2ml_z3_Z3_app(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_to_func_decl( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_to_func_decl(c, a); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_numeral_string( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_numeral_string(c, a); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_numeral_decimal_string( - value _v_c, - value _v_a, - value _v_precision) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int precision; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - precision = Int_val(_v_precision); - _res = Z3_get_numeral_decimal_string(c, a, precision); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_numerator( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_numerator(c, a); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_denominator( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_denominator(c, a); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_numeral_small( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - long long *num; /*out*/ - long long *den; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - long long _c1; - long long _c2; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - num = &_c1; - den = &_c2; - _res = Z3_get_numeral_small(c, a, num, den); - Begin_roots_block(_vres, 3) - _vres[0] = Val_int(_res); - _vres[1] = copy_int64(*num); - _vres[2] = copy_int64(*den); - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_get_numeral_int( - value _v_c, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast v; /*in*/ - int *i; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - int _c1; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_v, &v, _ctx); - i = &_c1; - _res = Z3_get_numeral_int(c, v, i); - Begin_roots_block(_vres, 2) - _vres[0] = Val_int(_res); - _vres[1] = Val_int(*i); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_get_numeral_int64( - value _v_c, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast v; /*in*/ - long long *i; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - long long _c1; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_v, &v, _ctx); - i = &_c1; - _res = Z3_get_numeral_int64(c, v, i); - Begin_roots_block(_vres, 2) - _vres[0] = Val_int(_res); - _vres[1] = copy_int64(*i); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_get_numeral_rational_int64( - value _v_c, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast v; /*in*/ - long long *num; /*out*/ - long long *den; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - long long _c1; - long long _c2; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_v, &v, _ctx); - num = &_c1; - den = &_c2; - _res = Z3_get_numeral_rational_int64(c, v, num, den); - Begin_roots_block(_vres, 3) - _vres[0] = Val_int(_res); - _vres[1] = copy_int64(*num); - _vres[2] = copy_int64(*den); - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -value camlidl_z3_Z3_get_algebraic_number_lower( - value _v_c, - value _v_a, - value _v_precision) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int precision; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - precision = Int_val(_v_precision); - _res = Z3_get_algebraic_number_lower(c, a, precision); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_algebraic_number_upper( - value _v_c, - value _v_a, - value _v_precision) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int precision; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - precision = Int_val(_v_precision); - _res = Z3_get_algebraic_number_upper(c, a, precision); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_pattern_to_ast( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_pattern p; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_pattern(_v_p, &p, _ctx); - _res = Z3_pattern_to_ast(c, p); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_pattern_num_terms( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_pattern p; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_pattern(_v_p, &p, _ctx); - _res = Z3_get_pattern_num_terms(c, p); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_pattern( - value _v_c, - value _v_p, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_pattern p; /*in*/ - unsigned int idx; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_pattern(_v_p, &p, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_pattern(c, p, idx); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_index_value( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_index_value(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_quantifier_forall( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_quantifier_forall(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_weight( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_weight(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_num_patterns( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_num_patterns(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_pattern_ast( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int i; /*in*/ - Z3_pattern _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_quantifier_pattern_ast(c, a, i); - _vres = camlidl_c2ml_z3_Z3_pattern(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_num_no_patterns( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_num_no_patterns(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_no_pattern_ast( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_quantifier_no_pattern_ast(c, a, i); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_num_bound( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_num_bound(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_bound_name( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int i; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_quantifier_bound_name(c, a, i); - _vres = camlidl_c2ml_z3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_bound_sort( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int i; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_quantifier_bound_sort(c, a, i); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_quantifier_body( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_body(c, a); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_simplify( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_simplify(c, a); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_simplify_ex( - value _v_c, - value _v_a, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_params p; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - _res = Z3_simplify_ex(c, a, p); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_simplify_get_help( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_simplify_get_help(c); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_simplify_get_param_descrs( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_param_descrs _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_simplify_get_param_descrs(c); - _vres = camlidl_c2ml_z3_Z3_param_descrs(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_update_term( - value _v_c, - value _v_a, - value _v_args) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_update_term(c, a, num_args, args); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_substitute( - value _v_c, - value _v_a, - value _v_from, - value _v_to) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int num_exprs; /*in*/ - Z3_ast const *from; /*in*/ - Z3_ast const *to; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _c1 = Wosize_val(_v_from); - from = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_from, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &from[_c2], _ctx); - } - num_exprs = _c1; - _c4 = Wosize_val(_v_to); - to = camlidl_malloc(_c4 * sizeof(Z3_ast const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_to, _c5); - camlidl_ml2c_z3_Z3_ast(_v6, &to[_c5], _ctx); - } - num_exprs = _c4; - _res = Z3_substitute(c, a, num_exprs, from, to); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_substitute_vars( - value _v_c, - value _v_a, - value _v_to) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int num_exprs; /*in*/ - Z3_ast const *to; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _c1 = Wosize_val(_v_to); - to = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_to, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &to[_c2], _ctx); - } - num_exprs = _c1; - _res = Z3_substitute_vars(c, a, num_exprs, to); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_translate( - value _v_source, - value _v_a, - value _v_target) -{ - Z3_context source; /*in*/ - Z3_ast a; /*in*/ - Z3_context target; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_source, &source, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - camlidl_ml2c_z3_Z3_context(_v_target, &target, _ctx); - _res = Z3_translate(source, a, target); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(source); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_eval( - value _v_c, - value _v_m, - value _v_t, - value _v_model_completion) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_ast t; /*in*/ - int model_completion; /*in*/ - Z3_ast *v; /*out*/ - Z3_ast _c1; - value _v2; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_t, &t, _ctx); - model_completion = Int_val(_v_model_completion); - v = &_c1; - Z3_model_eval(c, m, t, model_completion, v); - if (v == NULL) { - _vres = Val_int(0); - } else { - _v2 = camlidl_c2ml_z3_Z3_ast(&*v, _ctx); - Begin_root(_v2) - _vres = camlidl_alloc_small(1, 0); - Field(_vres, 0) = _v2; - End_roots(); - } - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_const_interp( - value _v_c, - value _v_m, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_func_decl a; /*in*/ - Z3_ast_opt _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_a, &a, _ctx); - _res = Z3_model_get_const_interp(c, m, a); - _vres = camlidl_c2ml_z3_Z3_ast_opt(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_func_interp( - value _v_c, - value _v_m, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_func_decl f; /*in*/ - Z3_func_interp_opt _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_f, &f, _ctx); - _res = Z3_model_get_func_interp(c, m, f); - _vres = camlidl_c2ml_z3_Z3_func_interp_opt(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_num_consts( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - _res = Z3_model_get_num_consts(c, m); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_const_decl( - value _v_c, - value _v_m, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - _res = Z3_model_get_const_decl(c, m, i); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_num_funcs( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - _res = Z3_model_get_num_funcs(c, m); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_func_decl( - value _v_c, - value _v_m, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - _res = Z3_model_get_func_decl(c, m, i); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_num_sorts( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - _res = Z3_model_get_num_sorts(c, m); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_sort( - value _v_c, - value _v_m, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - _res = Z3_model_get_sort(c, m, i); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_get_sort_universe( - value _v_c, - value _v_m, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_sort s; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_model_get_sort_universe(c, m, s); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_is_as_array( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_as_array(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_as_array_func_decl( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_as_array_func_decl(c, a); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_interp_get_num_entries( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_func_interp f; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_interp(_v_f, &f, _ctx); - _res = Z3_func_interp_get_num_entries(c, f); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_interp_get_entry( - value _v_c, - value _v_f, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_func_interp f; /*in*/ - unsigned int i; /*in*/ - Z3_func_entry _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_interp(_v_f, &f, _ctx); - i = Int_val(_v_i); - _res = Z3_func_interp_get_entry(c, f, i); - _vres = camlidl_c2ml_z3_Z3_func_entry(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_interp_get_else( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_func_interp f; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_interp(_v_f, &f, _ctx); - _res = Z3_func_interp_get_else(c, f); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_interp_get_arity( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_func_interp f; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_interp(_v_f, &f, _ctx); - _res = Z3_func_interp_get_arity(c, f); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_entry_get_value( - value _v_c, - value _v_e) -{ - Z3_context c; /*in*/ - Z3_func_entry e; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_entry(_v_e, &e, _ctx); - _res = Z3_func_entry_get_value(c, e); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_entry_get_num_args( - value _v_c, - value _v_e) -{ - Z3_context c; /*in*/ - Z3_func_entry e; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_entry(_v_e, &e, _ctx); - _res = Z3_func_entry_get_num_args(c, e); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_entry_get_arg( - value _v_c, - value _v_e, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_func_entry e; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_entry(_v_e, &e, _ctx); - i = Int_val(_v_i); - _res = Z3_func_entry_get_arg(c, e, i); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_open_log( - value _v_filename) -{ - Z3_string filename; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_string(_v_filename, &filename, _ctx); - _res = Z3_open_log(filename); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3_Z3_append_log( - value _v_string) -{ - Z3_string string; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_string(_v_string, &string, _ctx); - Z3_append_log(string); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3_Z3_close_log(value _unit) -{ - Z3_close_log(); - return Val_unit; -} - -value camlidl_z3_Z3_toggle_warning_messages( - value _v_enabled) -{ - int enabled; /*in*/ - enabled = Int_val(_v_enabled); - Z3_toggle_warning_messages(enabled); - return Val_unit; -} - -value camlidl_z3_Z3_set_ast_print_mode( - value _v_c, - value _v_mode) -{ - Z3_context c; /*in*/ - Z3_ast_print_mode mode; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_print_mode(_v_mode, &mode, _ctx); - Z3_set_ast_print_mode(c, mode); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_ast_to_string( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_ast_to_string(c, a); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_pattern_to_string( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_pattern p; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_pattern(_v_p, &p, _ctx); - _res = Z3_pattern_to_string(c, p); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_sort_to_string( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_sort_to_string(c, s); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_func_decl_to_string( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_func_decl_to_string(c, d); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_model_to_string( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - _res = Z3_model_to_string(c, m); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_benchmark_to_smtlib_string( - value _v_c, - value _v_name, - value _v_logic, - value _v_status, - value _v_attributes, - value _v_assumptions, - value _v_formula) -{ - Z3_context c; /*in*/ - Z3_string name; /*in*/ - Z3_string logic; /*in*/ - Z3_string status; /*in*/ - Z3_string attributes; /*in*/ - unsigned int num_assumptions; /*in*/ - Z3_ast const *assumptions; /*in*/ - Z3_ast formula; /*in*/ - Z3_string _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_name, &name, _ctx); - camlidl_ml2c_z3_Z3_string(_v_logic, &logic, _ctx); - camlidl_ml2c_z3_Z3_string(_v_status, &status, _ctx); - camlidl_ml2c_z3_Z3_string(_v_attributes, &attributes, _ctx); - _c1 = Wosize_val(_v_assumptions); - assumptions = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_assumptions, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &assumptions[_c2], _ctx); - } - num_assumptions = _c1; - camlidl_ml2c_z3_Z3_ast(_v_formula, &formula, _ctx); - _res = Z3_benchmark_to_smtlib_string(c, name, logic, status, attributes, num_assumptions, assumptions, formula); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_benchmark_to_smtlib_string_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_benchmark_to_smtlib_string(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); -} - -value camlidl_z3_Z3_parse_smtlib2_string( - value _v_c, - value _v_str, - value _v_sort_names, - value _v_sorts, - value _v_decl_names, - value _v_decls) -{ - Z3_context c; /*in*/ - Z3_string str; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int num_decls; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_func_decl const *decls; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_str, &str, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_sorts = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decls); - decls = camlidl_malloc(_c10 * sizeof(Z3_func_decl const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decls, _c11); - camlidl_ml2c_z3_Z3_func_decl(_v12, &decls[_c11], _ctx); - } - num_decls = _c10; - _res = Z3_parse_smtlib2_string(c, str, num_sorts, sort_names, sorts, num_decls, decl_names, decls); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_parse_smtlib2_string_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_parse_smtlib2_string(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3_Z3_parse_smtlib2_file( - value _v_c, - value _v_file_name, - value _v_sort_names, - value _v_sorts, - value _v_decl_names, - value _v_decls) -{ - Z3_context c; /*in*/ - Z3_string file_name; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int num_decls; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_func_decl const *decls; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_file_name, &file_name, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_sorts = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decls); - decls = camlidl_malloc(_c10 * sizeof(Z3_func_decl const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decls, _c11); - camlidl_ml2c_z3_Z3_func_decl(_v12, &decls[_c11], _ctx); - } - num_decls = _c10; - _res = Z3_parse_smtlib2_file(c, file_name, num_sorts, sort_names, sorts, num_decls, decl_names, decls); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_parse_smtlib2_file_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_parse_smtlib2_file(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3_Z3_parse_smtlib_string( - value _v_c, - value _v_str, - value _v_sort_names, - value _v_sorts, - value _v_decl_names, - value _v_decls) -{ - Z3_context c; /*in*/ - Z3_string str; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int num_decls; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_func_decl const *decls; /*in*/ - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_str, &str, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_sorts = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decls); - decls = camlidl_malloc(_c10 * sizeof(Z3_func_decl const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decls, _c11); - camlidl_ml2c_z3_Z3_func_decl(_v12, &decls[_c11], _ctx); - } - num_decls = _c10; - Z3_parse_smtlib_string(c, str, num_sorts, sort_names, sorts, num_decls, decl_names, decls); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_parse_smtlib_string_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_parse_smtlib_string(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3_Z3_parse_smtlib_file( - value _v_c, - value _v_file_name, - value _v_sort_names, - value _v_sorts, - value _v_decl_names, - value _v_decls) -{ - Z3_context c; /*in*/ - Z3_string file_name; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int num_decls; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_func_decl const *decls; /*in*/ - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_file_name, &file_name, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_sorts = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decls); - decls = camlidl_malloc(_c10 * sizeof(Z3_func_decl const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decls, _c11); - camlidl_ml2c_z3_Z3_func_decl(_v12, &decls[_c11], _ctx); - } - num_decls = _c10; - Z3_parse_smtlib_file(c, file_name, num_sorts, sort_names, sorts, num_decls, decl_names, decls); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_parse_smtlib_file_bytecode(value * argv, int argn) -{ - return camlidl_z3_Z3_parse_smtlib_file(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3_Z3_get_smtlib_num_formulas( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_num_formulas(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_smtlib_formula( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_smtlib_formula(c, i); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_smtlib_num_assumptions( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_num_assumptions(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_smtlib_assumption( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_smtlib_assumption(c, i); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_smtlib_num_decls( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_num_decls(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_smtlib_decl( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_smtlib_decl(c, i); - _vres = camlidl_c2ml_z3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_smtlib_num_sorts( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_num_sorts(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_smtlib_sort( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_smtlib_sort(c, i); - _vres = camlidl_c2ml_z3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_smtlib_error( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_error(c); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_set_error( - value _v_c, - value _v_e) -{ - Z3_context c; /*in*/ - Z3_error_code e; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_error_code(_v_e, &e, _ctx); - Z3_set_error(c, e); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_get_error_msg_ex( - value _v_c, - value _v_err) -{ - Z3_context c; /*in*/ - Z3_error_code err; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_error_code(_v_err, &err, _ctx); - _res = Z3_get_error_msg_ex(c, err); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_version(value _unit) -{ - unsigned int *major; /*out*/ - unsigned int *minor; /*out*/ - unsigned int *build_number; /*out*/ - unsigned int *revision_number; /*out*/ - unsigned int _c1; - unsigned int _c2; - unsigned int _c3; - unsigned int _c4; - value _vresult; - value _vres[4] = { 0, 0, 0, 0, }; - - major = &_c1; - minor = &_c2; - build_number = &_c3; - revision_number = &_c4; - Z3_get_version(major, minor, build_number, revision_number); - Begin_roots_block(_vres, 4) - _vres[0] = Val_int(*major); - _vres[1] = Val_int(*minor); - _vres[2] = Val_int(*build_number); - _vres[3] = Val_int(*revision_number); - _vresult = camlidl_alloc_small(4, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - Field(_vresult, 3) = _vres[3]; - End_roots() - return _vresult; -} - -value camlidl_z3_Z3_enable_trace( - value _v_tag) -{ - Z3_string tag; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_string(_v_tag, &tag, _ctx); - Z3_enable_trace(tag); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3_Z3_disable_trace( - value _v_tag) -{ - Z3_string tag; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_string(_v_tag, &tag, _ctx); - Z3_disable_trace(tag); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3_Z3_mk_fixedpoint( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_fixedpoint _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_fixedpoint(c); - _vres = camlidl_c2ml_z3_Z3_fixedpoint(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_add_rule( - value _v_c, - value _v_d, - value _v_rule, - value _v_name) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_ast rule; /*in*/ - Z3_symbol name; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_rule, &rule, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_name, &name, _ctx); - Z3_fixedpoint_add_rule(c, d, rule, name); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_add_fact( - value _v_c, - value _v_d, - value _v_r, - value _v_args) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_func_decl r; /*in*/ - unsigned int num_args; /*in*/ - unsigned int *args; /*in*/ - mlsize_t _c1; - mlsize_t _c2; - value _v3; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_r, &r, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(unsigned int ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - args[_c2] = Int_val(_v3); - } - num_args = _c1; - Z3_fixedpoint_add_fact(c, d, r, num_args, args); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_assert( - value _v_c, - value _v_d, - value _v_axiom) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_ast axiom; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_axiom, &axiom, _ctx); - Z3_fixedpoint_assert(c, d, axiom); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_query( - value _v_c, - value _v_d, - value _v_query) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_ast query; /*in*/ - Z3_lbool _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_query, &query, _ctx); - _res = Z3_fixedpoint_query(c, d, query); - _vres = camlidl_c2ml_z3_Z3_lbool(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_query_relations( - value _v_c, - value _v_d, - value _v_relations) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - unsigned int num_relations; /*in*/ - Z3_func_decl const *relations; /*in*/ - Z3_lbool _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - _c1 = Wosize_val(_v_relations); - relations = camlidl_malloc(_c1 * sizeof(Z3_func_decl const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_relations, _c2); - camlidl_ml2c_z3_Z3_func_decl(_v3, &relations[_c2], _ctx); - } - num_relations = _c1; - _res = Z3_fixedpoint_query_relations(c, d, num_relations, relations); - _vres = camlidl_c2ml_z3_Z3_lbool(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_get_answer( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - _res = Z3_fixedpoint_get_answer(c, d); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_get_reason_unknown( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - _res = Z3_fixedpoint_get_reason_unknown(c, d); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_update_rule( - value _v_c, - value _v_d, - value _v_a, - value _v_name) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_ast a; /*in*/ - Z3_symbol name; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_name, &name, _ctx); - Z3_fixedpoint_update_rule(c, d, a, name); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_get_num_levels( - value _v_c, - value _v_d, - value _v_pred) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_func_decl pred; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_pred, &pred, _ctx); - _res = Z3_fixedpoint_get_num_levels(c, d, pred); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_get_cover_delta( - value _v_c, - value _v_d, - value _v_level, - value _v_pred) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - int level; /*in*/ - Z3_func_decl pred; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - level = Int_val(_v_level); - camlidl_ml2c_z3_Z3_func_decl(_v_pred, &pred, _ctx); - _res = Z3_fixedpoint_get_cover_delta(c, d, level, pred); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_add_cover( - value _v_c, - value _v_d, - value _v_level, - value _v_pred, - value _v_property) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - int level; /*in*/ - Z3_func_decl pred; /*in*/ - Z3_ast property; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - level = Int_val(_v_level); - camlidl_ml2c_z3_Z3_func_decl(_v_pred, &pred, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_property, &property, _ctx); - Z3_fixedpoint_add_cover(c, d, level, pred, property); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_get_statistics( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_stats _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - _res = Z3_fixedpoint_get_statistics(c, d); - _vres = camlidl_c2ml_z3_Z3_stats(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_register_relation( - value _v_c, - value _v_d, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_func_decl f; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_f, &f, _ctx); - Z3_fixedpoint_register_relation(c, d, f); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_set_predicate_representation( - value _v_c, - value _v_d, - value _v_f, - value _v_relation_kinds) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - Z3_func_decl f; /*in*/ - unsigned int num_relations; /*in*/ - Z3_symbol const *relation_kinds; /*in*/ - mlsize_t _c1; - mlsize_t _c2; - value _v3; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - camlidl_ml2c_z3_Z3_func_decl(_v_f, &f, _ctx); - _c1 = Wosize_val(_v_relation_kinds); - relation_kinds = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_relation_kinds, _c2); - camlidl_ml2c_z3_Z3_symbol(_v3, &relation_kinds[_c2], _ctx); - } - num_relations = _c1; - Z3_fixedpoint_set_predicate_representation(c, d, f, num_relations, relation_kinds); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_get_rules( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_fixedpoint f; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_f, &f, _ctx); - _res = Z3_fixedpoint_get_rules(c, f); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_get_assertions( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_fixedpoint f; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_f, &f, _ctx); - _res = Z3_fixedpoint_get_assertions(c, f); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_set_params( - value _v_c, - value _v_f, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_fixedpoint f; /*in*/ - Z3_params p; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_f, &f, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - Z3_fixedpoint_set_params(c, f, p); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_get_help( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_fixedpoint f; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_f, &f, _ctx); - _res = Z3_fixedpoint_get_help(c, f); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_get_param_descrs( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_fixedpoint f; /*in*/ - Z3_param_descrs _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_f, &f, _ctx); - _res = Z3_fixedpoint_get_param_descrs(c, f); - _vres = camlidl_c2ml_z3_Z3_param_descrs(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_to_string( - value _v_c, - value _v_f, - value _v_queries) -{ - Z3_context c; /*in*/ - Z3_fixedpoint f; /*in*/ - unsigned int num_queries; /*in*/ - Z3_ast *queries; /*in*/ - Z3_string _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_f, &f, _ctx); - _c1 = Wosize_val(_v_queries); - queries = camlidl_malloc(_c1 * sizeof(Z3_ast ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_queries, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &queries[_c2], _ctx); - } - num_queries = _c1; - _res = Z3_fixedpoint_to_string(c, f, num_queries, queries); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_from_string( - value _v_c, - value _v_f, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_fixedpoint f; /*in*/ - Z3_string s; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_f, &f, _ctx); - camlidl_ml2c_z3_Z3_string(_v_s, &s, _ctx); - _res = Z3_fixedpoint_from_string(c, f, s); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_from_file( - value _v_c, - value _v_f, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_fixedpoint f; /*in*/ - Z3_string s; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_f, &f, _ctx); - camlidl_ml2c_z3_Z3_string(_v_s, &s, _ctx); - _res = Z3_fixedpoint_from_file(c, f, s); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_fixedpoint_push( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - Z3_fixedpoint_push(c, d); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_fixedpoint_pop( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_fixedpoint d; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_fixedpoint(_v_d, &d, _ctx); - Z3_fixedpoint_pop(c, d); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_mk_ast_vector( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_ast_vector(c); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_vector_size( - value _v_c, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast_vector v; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_vector(_v_v, &v, _ctx); - _res = Z3_ast_vector_size(c, v); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_vector_get( - value _v_c, - value _v_v, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast_vector v; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_vector(_v_v, &v, _ctx); - i = Int_val(_v_i); - _res = Z3_ast_vector_get(c, v, i); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_vector_set( - value _v_c, - value _v_v, - value _v_i, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast_vector v; /*in*/ - unsigned int i; /*in*/ - Z3_ast a; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_vector(_v_v, &v, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - Z3_ast_vector_set(c, v, i, a); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_ast_vector_resize( - value _v_c, - value _v_v, - value _v_n) -{ - Z3_context c; /*in*/ - Z3_ast_vector v; /*in*/ - unsigned int n; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_vector(_v_v, &v, _ctx); - n = Int_val(_v_n); - Z3_ast_vector_resize(c, v, n); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_ast_vector_push( - value _v_c, - value _v_v, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast_vector v; /*in*/ - Z3_ast a; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_vector(_v_v, &v, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - Z3_ast_vector_push(c, v, a); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_ast_vector_translate( - value _v_s, - value _v_v, - value _v_t) -{ - Z3_context s; /*in*/ - Z3_ast_vector v; /*in*/ - Z3_context t; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_s, &s, _ctx); - camlidl_ml2c_z3_Z3_ast_vector(_v_v, &v, _ctx); - camlidl_ml2c_z3_Z3_context(_v_t, &t, _ctx); - _res = Z3_ast_vector_translate(s, v, t); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(s); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_vector_to_string( - value _v_c, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast_vector v; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_vector(_v_v, &v, _ctx); - _res = Z3_ast_vector_to_string(c, v); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_ast_map( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_ast_map _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_ast_map(c); - _vres = camlidl_c2ml_z3_Z3_ast_map(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_map_contains( - value _v_c, - value _v_m, - value _v_k) -{ - Z3_context c; /*in*/ - Z3_ast_map m; /*in*/ - Z3_ast k; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_map(_v_m, &m, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_k, &k, _ctx); - _res = Z3_ast_map_contains(c, m, k); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_map_find( - value _v_c, - value _v_m, - value _v_k) -{ - Z3_context c; /*in*/ - Z3_ast_map m; /*in*/ - Z3_ast k; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_map(_v_m, &m, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_k, &k, _ctx); - _res = Z3_ast_map_find(c, m, k); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_map_insert( - value _v_c, - value _v_m, - value _v_k, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast_map m; /*in*/ - Z3_ast k; /*in*/ - Z3_ast v; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_map(_v_m, &m, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_k, &k, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_v, &v, _ctx); - Z3_ast_map_insert(c, m, k, v); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_ast_map_erase( - value _v_c, - value _v_m, - value _v_k) -{ - Z3_context c; /*in*/ - Z3_ast_map m; /*in*/ - Z3_ast k; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_map(_v_m, &m, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_k, &k, _ctx); - Z3_ast_map_erase(c, m, k); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_ast_map_reset( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_ast_map m; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_map(_v_m, &m, _ctx); - Z3_ast_map_reset(c, m); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_ast_map_size( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_ast_map m; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_map(_v_m, &m, _ctx); - _res = Z3_ast_map_size(c, m); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_map_keys( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_ast_map m; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_map(_v_m, &m, _ctx); - _res = Z3_ast_map_keys(c, m); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_ast_map_to_string( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_ast_map m; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_ast_map(_v_m, &m, _ctx); - _res = Z3_ast_map_to_string(c, m); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_goal( - value _v_c, - value _v_models, - value _v_unsat_cores, - value _v_proofs) -{ - Z3_context c; /*in*/ - int models; /*in*/ - int unsat_cores; /*in*/ - int proofs; /*in*/ - Z3_goal _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - models = Int_val(_v_models); - unsat_cores = Int_val(_v_unsat_cores); - proofs = Int_val(_v_proofs); - _res = Z3_mk_goal(c, models, unsat_cores, proofs); - _vres = camlidl_c2ml_z3_Z3_goal(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_precision( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - Z3_goal_prec _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_goal_precision(c, g); - _vres = camlidl_c2ml_z3_Z3_goal_prec(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_assert( - value _v_c, - value _v_g, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - Z3_ast a; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - Z3_goal_assert(c, g, a); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_goal_inconsistent( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_goal_inconsistent(c, g); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_depth( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_goal_depth(c, g); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_reset( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - Z3_goal_reset(c, g); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_goal_size( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_goal_size(c, g); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_formula( - value _v_c, - value _v_g, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - unsigned int idx; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - idx = Int_val(_v_idx); - _res = Z3_goal_formula(c, g, idx); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_num_exprs( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_goal_num_exprs(c, g); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_is_decided_sat( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_goal_is_decided_sat(c, g); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_is_decided_unsat( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_goal_is_decided_unsat(c, g); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_translate( - value _v_source, - value _v_g, - value _v_target) -{ - Z3_context source; /*in*/ - Z3_goal g; /*in*/ - Z3_context target; /*in*/ - Z3_goal _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_source, &source, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - camlidl_ml2c_z3_Z3_context(_v_target, &target, _ctx); - _res = Z3_goal_translate(source, g, target); - _vres = camlidl_c2ml_z3_Z3_goal(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(source); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_goal_to_string( - value _v_c, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_goal g; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_goal_to_string(c, g); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_tactic( - value _v_c, - value _v_name) -{ - Z3_context c; /*in*/ - Z3_string name; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_name, &name, _ctx); - _res = Z3_mk_tactic(c, name); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_probe( - value _v_c, - value _v_name) -{ - Z3_context c; /*in*/ - Z3_string name; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_name, &name, _ctx); - _res = Z3_mk_probe(c, name); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_and_then( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_tactic t1; /*in*/ - Z3_tactic t2; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t2, &t2, _ctx); - _res = Z3_tactic_and_then(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_or_else( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_tactic t1; /*in*/ - Z3_tactic t2; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t2, &t2, _ctx); - _res = Z3_tactic_or_else(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_par_or( - value _v_c, - value _v_ts) -{ - Z3_context c; /*in*/ - unsigned int num; /*in*/ - Z3_tactic const *ts; /*in*/ - Z3_tactic _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_ts); - ts = camlidl_malloc(_c1 * sizeof(Z3_tactic const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_ts, _c2); - camlidl_ml2c_z3_Z3_tactic(_v3, &ts[_c2], _ctx); - } - num = _c1; - _res = Z3_tactic_par_or(c, num, ts); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_par_and_then( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_tactic t1; /*in*/ - Z3_tactic t2; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t2, &t2, _ctx); - _res = Z3_tactic_par_and_then(c, t1, t2); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_try_for( - value _v_c, - value _v_t, - value _v_ms) -{ - Z3_context c; /*in*/ - Z3_tactic t; /*in*/ - unsigned int ms; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - ms = Int_val(_v_ms); - _res = Z3_tactic_try_for(c, t, ms); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_when( - value _v_c, - value _v_p, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_probe p; /*in*/ - Z3_tactic t; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - _res = Z3_tactic_when(c, p, t); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_cond( - value _v_c, - value _v_p, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_probe p; /*in*/ - Z3_tactic t1; /*in*/ - Z3_tactic t2; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t1, &t1, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t2, &t2, _ctx); - _res = Z3_tactic_cond(c, p, t1, t2); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_repeat( - value _v_c, - value _v_t, - value _v_max) -{ - Z3_context c; /*in*/ - Z3_tactic t; /*in*/ - unsigned int max; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - max = Int_val(_v_max); - _res = Z3_tactic_repeat(c, t, max); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_skip( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_tactic_skip(c); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_fail( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_tactic_fail(c); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_fail_if( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_probe p; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p, &p, _ctx); - _res = Z3_tactic_fail_if(c, p); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_fail_if_not_decided( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_tactic_fail_if_not_decided(c); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_using_params( - value _v_c, - value _v_t, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_tactic t; /*in*/ - Z3_params p; /*in*/ - Z3_tactic _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - _res = Z3_tactic_using_params(c, t, p); - _vres = camlidl_c2ml_z3_Z3_tactic(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_const( - value _v_x, - value _v_val) -{ - Z3_context x; /*in*/ - double val; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - val = Double_val(_v_val); - _res = Z3_probe_const(x, val); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_lt( - value _v_x, - value _v_p1, - value _v_p2) -{ - Z3_context x; /*in*/ - Z3_probe p1; /*in*/ - Z3_probe p2; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p1, &p1, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p2, &p2, _ctx); - _res = Z3_probe_lt(x, p1, p2); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_gt( - value _v_x, - value _v_p1, - value _v_p2) -{ - Z3_context x; /*in*/ - Z3_probe p1; /*in*/ - Z3_probe p2; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p1, &p1, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p2, &p2, _ctx); - _res = Z3_probe_gt(x, p1, p2); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_le( - value _v_x, - value _v_p1, - value _v_p2) -{ - Z3_context x; /*in*/ - Z3_probe p1; /*in*/ - Z3_probe p2; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p1, &p1, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p2, &p2, _ctx); - _res = Z3_probe_le(x, p1, p2); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_ge( - value _v_x, - value _v_p1, - value _v_p2) -{ - Z3_context x; /*in*/ - Z3_probe p1; /*in*/ - Z3_probe p2; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p1, &p1, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p2, &p2, _ctx); - _res = Z3_probe_ge(x, p1, p2); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_eq( - value _v_x, - value _v_p1, - value _v_p2) -{ - Z3_context x; /*in*/ - Z3_probe p1; /*in*/ - Z3_probe p2; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p1, &p1, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p2, &p2, _ctx); - _res = Z3_probe_eq(x, p1, p2); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_and( - value _v_x, - value _v_p1, - value _v_p2) -{ - Z3_context x; /*in*/ - Z3_probe p1; /*in*/ - Z3_probe p2; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p1, &p1, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p2, &p2, _ctx); - _res = Z3_probe_and(x, p1, p2); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_or( - value _v_x, - value _v_p1, - value _v_p2) -{ - Z3_context x; /*in*/ - Z3_probe p1; /*in*/ - Z3_probe p2; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p1, &p1, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p2, &p2, _ctx); - _res = Z3_probe_or(x, p1, p2); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_not( - value _v_x, - value _v_p) -{ - Z3_context x; /*in*/ - Z3_probe p; /*in*/ - Z3_probe _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_x, &x, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p, &p, _ctx); - _res = Z3_probe_not(x, p); - _vres = camlidl_c2ml_z3_Z3_probe(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(x); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_num_tactics( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_num_tactics(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_tactic_name( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_tactic_name(c, i); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_num_probes( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_num_probes(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_probe_name( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_probe_name(c, i); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_get_help( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_tactic t; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - _res = Z3_tactic_get_help(c, t); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_get_param_descrs( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_tactic t; /*in*/ - Z3_param_descrs _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - _res = Z3_tactic_get_param_descrs(c, t); - _vres = camlidl_c2ml_z3_Z3_param_descrs(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_get_descr( - value _v_c, - value _v_name) -{ - Z3_context c; /*in*/ - Z3_string name; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_name, &name, _ctx); - _res = Z3_tactic_get_descr(c, name); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_get_descr( - value _v_c, - value _v_name) -{ - Z3_context c; /*in*/ - Z3_string name; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_string(_v_name, &name, _ctx); - _res = Z3_probe_get_descr(c, name); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_probe_apply( - value _v_c, - value _v_p, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_probe p; /*in*/ - Z3_goal g; /*in*/ - double _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_probe(_v_p, &p, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_probe_apply(c, p, g); - _vres = copy_double(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_apply( - value _v_c, - value _v_t, - value _v_g) -{ - Z3_context c; /*in*/ - Z3_tactic t; /*in*/ - Z3_goal g; /*in*/ - Z3_apply_result _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - _res = Z3_tactic_apply(c, t, g); - _vres = camlidl_c2ml_z3_Z3_apply_result(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_tactic_apply_ex( - value _v_c, - value _v_t, - value _v_g, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_tactic t; /*in*/ - Z3_goal g; /*in*/ - Z3_params p; /*in*/ - Z3_apply_result _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - camlidl_ml2c_z3_Z3_goal(_v_g, &g, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - _res = Z3_tactic_apply_ex(c, t, g, p); - _vres = camlidl_c2ml_z3_Z3_apply_result(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_apply_result_to_string( - value _v_c, - value _v_r) -{ - Z3_context c; /*in*/ - Z3_apply_result r; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_apply_result(_v_r, &r, _ctx); - _res = Z3_apply_result_to_string(c, r); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_apply_result_get_num_subgoals( - value _v_c, - value _v_r) -{ - Z3_context c; /*in*/ - Z3_apply_result r; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_apply_result(_v_r, &r, _ctx); - _res = Z3_apply_result_get_num_subgoals(c, r); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_apply_result_get_subgoal( - value _v_c, - value _v_r, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_apply_result r; /*in*/ - unsigned int i; /*in*/ - Z3_goal _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_apply_result(_v_r, &r, _ctx); - i = Int_val(_v_i); - _res = Z3_apply_result_get_subgoal(c, r, i); - _vres = camlidl_c2ml_z3_Z3_goal(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_apply_result_convert_model( - value _v_c, - value _v_r, - value _v_i, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_apply_result r; /*in*/ - unsigned int i; /*in*/ - Z3_model m; /*in*/ - Z3_model _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_apply_result(_v_r, &r, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3_Z3_model(_v_m, &m, _ctx); - _res = Z3_apply_result_convert_model(c, r, i, m); - _vres = camlidl_c2ml_z3_Z3_model(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_solver( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_solver _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_solver(c); - _vres = camlidl_c2ml_z3_Z3_solver(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_simple_solver( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_solver _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_simple_solver(c); - _vres = camlidl_c2ml_z3_Z3_solver(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_solver_for_logic( - value _v_c, - value _v_logic) -{ - Z3_context c; /*in*/ - Z3_symbol logic; /*in*/ - Z3_solver _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_symbol(_v_logic, &logic, _ctx); - _res = Z3_mk_solver_for_logic(c, logic); - _vres = camlidl_c2ml_z3_Z3_solver(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_mk_solver_from_tactic( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_tactic t; /*in*/ - Z3_solver _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_tactic(_v_t, &t, _ctx); - _res = Z3_mk_solver_from_tactic(c, t); - _vres = camlidl_c2ml_z3_Z3_solver(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_get_help( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_help(c, s); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_get_param_descrs( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_param_descrs _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_param_descrs(c, s); - _vres = camlidl_c2ml_z3_Z3_param_descrs(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_set_params( - value _v_c, - value _v_s, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_params p; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - camlidl_ml2c_z3_Z3_params(_v_p, &p, _ctx); - Z3_solver_set_params(c, s, p); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_solver_push( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - Z3_solver_push(c, s); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_solver_pop( - value _v_c, - value _v_s, - value _v_n) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - unsigned int n; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - n = Int_val(_v_n); - Z3_solver_pop(c, s, n); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_solver_reset( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - Z3_solver_reset(c, s); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_solver_get_num_scopes( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_num_scopes(c, s); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_assert( - value _v_c, - value _v_s, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_ast a; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - Z3_solver_assert(c, s, a); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_solver_assert_and_track( - value _v_c, - value _v_s, - value _v_a, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_ast a; /*in*/ - Z3_ast p; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_a, &a, _ctx); - camlidl_ml2c_z3_Z3_ast(_v_p, &p, _ctx); - Z3_solver_assert_and_track(c, s, a, p); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return Val_unit; -} - -value camlidl_z3_Z3_solver_get_assertions( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_assertions(c, s); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_check( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_lbool _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_check(c, s); - _vres = camlidl_c2ml_z3_Z3_lbool(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_check_assumptions( - value _v_c, - value _v_s, - value _v_assumptions) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - unsigned int num_assumptions; /*in*/ - Z3_ast const *assumptions; /*in*/ - Z3_lbool _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _c1 = Wosize_val(_v_assumptions); - assumptions = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_assumptions, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &assumptions[_c2], _ctx); - } - num_assumptions = _c1; - _res = Z3_solver_check_assumptions(c, s, num_assumptions, assumptions); - _vres = camlidl_c2ml_z3_Z3_lbool(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_get_model( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_model _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_model(c, s); - _vres = camlidl_c2ml_z3_Z3_model(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_get_proof( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_proof(c, s); - _vres = camlidl_c2ml_z3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_get_unsat_core( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_ast_vector _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_unsat_core(c, s); - _vres = camlidl_c2ml_z3_Z3_ast_vector(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_get_reason_unknown( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_reason_unknown(c, s); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_get_statistics( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_stats _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_get_statistics(c, s); - _vres = camlidl_c2ml_z3_Z3_stats(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_solver_to_string( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _res = Z3_solver_to_string(c, s); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_stats_to_string( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_stats s; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_stats(_v_s, &s, _ctx); - _res = Z3_stats_to_string(c, s); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_stats_size( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_stats s; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_stats(_v_s, &s, _ctx); - _res = Z3_stats_size(c, s); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_stats_get_key( - value _v_c, - value _v_s, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_stats s; /*in*/ - unsigned int idx; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_stats(_v_s, &s, _ctx); - idx = Int_val(_v_idx); - _res = Z3_stats_get_key(c, s, idx); - _vres = camlidl_c2ml_z3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_stats_is_uint( - value _v_c, - value _v_s, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_stats s; /*in*/ - unsigned int idx; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_stats(_v_s, &s, _ctx); - idx = Int_val(_v_idx); - _res = Z3_stats_is_uint(c, s, idx); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_stats_is_double( - value _v_c, - value _v_s, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_stats s; /*in*/ - unsigned int idx; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_stats(_v_s, &s, _ctx); - idx = Int_val(_v_idx); - _res = Z3_stats_is_double(c, s, idx); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_stats_get_uint_value( - value _v_c, - value _v_s, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_stats s; /*in*/ - unsigned int idx; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_stats(_v_s, &s, _ctx); - idx = Int_val(_v_idx); - _res = Z3_stats_get_uint_value(c, s, idx); - _vres = Val_int(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_stats_get_double_value( - value _v_c, - value _v_s, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_stats s; /*in*/ - unsigned int idx; /*in*/ - double _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_stats(_v_s, &s, _ctx); - idx = Int_val(_v_idx); - _res = Z3_stats_get_double_value(c, s, idx); - _vres = copy_double(_res); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3_Z3_get_implied_equalities( - value _v_c, - value _v_s, - value _v_terms) -{ - Z3_context c; /*in*/ - Z3_solver s; /*in*/ - unsigned int num_terms; /*in*/ - Z3_ast const *terms; /*in*/ - unsigned int *class_ids; /*out*/ - Z3_lbool _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - value _v5; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3_Z3_solver(_v_s, &s, _ctx); - _c1 = Wosize_val(_v_terms); - terms = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_terms, _c2); - camlidl_ml2c_z3_Z3_ast(_v3, &terms[_c2], _ctx); - } - num_terms = _c1; - class_ids = camlidl_malloc(num_terms * sizeof(unsigned int ), _ctx); - _res = Z3_get_implied_equalities(c, s, num_terms, terms, class_ids); - Begin_roots_block(_vres, 2) - _vres[0] = camlidl_c2ml_z3_Z3_lbool(&_res, _ctx); - _vres[1] = camlidl_alloc(num_terms, 0); - for (_c4 = 0; _c4 < num_terms; _c4++) { - _v5 = Val_int(class_ids[_c4]); - modify(&Field(_vres[1], _c4), _v5); - } - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -check_error_code(c); - /* end user-supplied deallocation sequence */ - return _vresult; -} - -void camlidl_ml2c_z3V3_Z3_symbol(value _v1, Z3_symbol * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_symbol *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_symbol(Z3_symbol * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_symbol) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_symbol *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_literals(value _v1, Z3_literals * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_literals *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_literals(Z3_literals * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_literals) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_literals *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_theory(value _v1, Z3_theory * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_theory *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_theory(Z3_theory * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_theory) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_theory *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_config(value _v1, Z3_config * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_config *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_config(Z3_config * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_config) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_config *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_context(value _v1, Z3_context * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_context *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_context(Z3_context * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_context) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_context *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_sort(value _v1, Z3_sort * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_sort *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_sort(Z3_sort * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_sort) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_sort *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_func_decl(value _v1, Z3_func_decl * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_func_decl *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_func_decl(Z3_func_decl * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_func_decl) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_func_decl *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_ast(value _v1, Z3_ast * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_ast *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_ast(Z3_ast * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_ast) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_ast *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_app(value _v1, Z3_app * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_app *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_app(Z3_app * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_app) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_app *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_pattern(value _v1, Z3_pattern * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_pattern *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_pattern(Z3_pattern * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_pattern) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_pattern *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_model(value _v1, Z3_model * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_model *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_model(Z3_model * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_model) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_model *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_constructor(value _v1, Z3_constructor * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_constructor *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_constructor(Z3_constructor * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_constructor) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_constructor *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_constructor_list(value _v1, Z3_constructor_list * _c2, camlidl_ctx _ctx) -{ - *_c2 = *((Z3_constructor_list *) Bp_val(_v1)); -} - -value camlidl_c2ml_z3V3_Z3_constructor_list(Z3_constructor_list * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_alloc((sizeof(Z3_constructor_list) + sizeof(value) - 1) / sizeof(value), Abstract_tag); - *((Z3_constructor_list *) Bp_val(_v1)) = *_c2; - return _v1; -} - -void camlidl_ml2c_z3V3_Z3_string(value _v1, Z3_string * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_malloc_string(_v1, _ctx); -} - -value camlidl_c2ml_z3V3_Z3_string(Z3_string * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = copy_string((*_c2)); - return _v1; -} - -int camlidl_transl_table_z3V3_enum_1[3] = { - Z3_L_FALSE, - Z3_L_UNDEF, - Z3_L_TRUE, -}; - -void camlidl_ml2c_z3V3_Z3_lbool(value _v1, Z3_lbool * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_1[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_lbool(Z3_lbool * _c2, camlidl_ctx _ctx) -{ -value _v1; - switch((*_c2)) { - case Z3_L_FALSE: _v1 = Val_int(0); break; - case Z3_L_UNDEF: _v1 = Val_int(1); break; - case Z3_L_TRUE: _v1 = Val_int(2); break; - default: invalid_argument("typedef Z3_lbool: bad enum value"); - } - return _v1; -} - -int camlidl_transl_table_z3V3_enum_2[2] = { - Z3_INT_SYMBOL, - Z3_STRING_SYMBOL, -}; - -void camlidl_ml2c_z3V3_Z3_symbol_kind(value _v1, Z3_symbol_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_2[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_symbol_kind(Z3_symbol_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - switch((*_c2)) { - case Z3_INT_SYMBOL: _v1 = Val_int(0); break; - case Z3_STRING_SYMBOL: _v1 = Val_int(1); break; - default: invalid_argument("typedef Z3_symbol_kind: bad enum value"); - } - return _v1; -} - -int camlidl_transl_table_z3V3_enum_3[7] = { - Z3_PARAMETER_INT, - Z3_PARAMETER_DOUBLE, - Z3_PARAMETER_RATIONAL, - Z3_PARAMETER_SYMBOL, - Z3_PARAMETER_SORT, - Z3_PARAMETER_AST, - Z3_PARAMETER_FUNC_DECL, -}; - -void camlidl_ml2c_z3V3_Z3_parameter_kind(value _v1, Z3_parameter_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_3[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_parameter_kind(Z3_parameter_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3V3_enum_3, 7, "typedef Z3_parameter_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3V3_enum_4[10] = { - Z3_UNINTERPRETED_SORT, - Z3_BOOL_SORT, - Z3_INT_SORT, - Z3_REAL_SORT, - Z3_BV_SORT, - Z3_ARRAY_SORT, - Z3_DATATYPE_SORT, - Z3_RELATION_SORT, - Z3_FINITE_DOMAIN_SORT, - Z3_UNKNOWN_SORT, -}; - -void camlidl_ml2c_z3V3_Z3_sort_kind(value _v1, Z3_sort_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_4[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_sort_kind(Z3_sort_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3V3_enum_4, 10, "typedef Z3_sort_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3V3_enum_5[7] = { - Z3_NUMERAL_AST, - Z3_APP_AST, - Z3_VAR_AST, - Z3_QUANTIFIER_AST, - Z3_SORT_AST, - Z3_FUNC_DECL_AST, - Z3_UNKNOWN_AST, -}; - -void camlidl_ml2c_z3V3_Z3_ast_kind(value _v1, Z3_ast_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_5[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_ast_kind(Z3_ast_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3V3_enum_5, 7, "typedef Z3_ast_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3V3_enum_6[152] = { - Z3_OP_TRUE, - Z3_OP_FALSE, - Z3_OP_EQ, - Z3_OP_DISTINCT, - Z3_OP_ITE, - Z3_OP_AND, - Z3_OP_OR, - Z3_OP_IFF, - Z3_OP_XOR, - Z3_OP_NOT, - Z3_OP_IMPLIES, - Z3_OP_OEQ, - Z3_OP_ANUM, - Z3_OP_AGNUM, - Z3_OP_LE, - Z3_OP_GE, - Z3_OP_LT, - Z3_OP_GT, - Z3_OP_ADD, - Z3_OP_SUB, - Z3_OP_UMINUS, - Z3_OP_MUL, - Z3_OP_DIV, - Z3_OP_IDIV, - Z3_OP_REM, - Z3_OP_MOD, - Z3_OP_TO_REAL, - Z3_OP_TO_INT, - Z3_OP_IS_INT, - Z3_OP_POWER, - Z3_OP_STORE, - Z3_OP_SELECT, - Z3_OP_CONST_ARRAY, - Z3_OP_ARRAY_MAP, - Z3_OP_ARRAY_DEFAULT, - Z3_OP_SET_UNION, - Z3_OP_SET_INTERSECT, - Z3_OP_SET_DIFFERENCE, - Z3_OP_SET_COMPLEMENT, - Z3_OP_SET_SUBSET, - Z3_OP_AS_ARRAY, - Z3_OP_BNUM, - Z3_OP_BIT1, - Z3_OP_BIT0, - Z3_OP_BNEG, - Z3_OP_BADD, - Z3_OP_BSUB, - Z3_OP_BMUL, - Z3_OP_BSDIV, - Z3_OP_BUDIV, - Z3_OP_BSREM, - Z3_OP_BUREM, - Z3_OP_BSMOD, - Z3_OP_BSDIV0, - Z3_OP_BUDIV0, - Z3_OP_BSREM0, - Z3_OP_BUREM0, - Z3_OP_BSMOD0, - Z3_OP_ULEQ, - Z3_OP_SLEQ, - Z3_OP_UGEQ, - Z3_OP_SGEQ, - Z3_OP_ULT, - Z3_OP_SLT, - Z3_OP_UGT, - Z3_OP_SGT, - Z3_OP_BAND, - Z3_OP_BOR, - Z3_OP_BNOT, - Z3_OP_BXOR, - Z3_OP_BNAND, - Z3_OP_BNOR, - Z3_OP_BXNOR, - Z3_OP_CONCAT, - Z3_OP_SIGN_EXT, - Z3_OP_ZERO_EXT, - Z3_OP_EXTRACT, - Z3_OP_REPEAT, - Z3_OP_BREDOR, - Z3_OP_BREDAND, - Z3_OP_BCOMP, - Z3_OP_BSHL, - Z3_OP_BLSHR, - Z3_OP_BASHR, - Z3_OP_ROTATE_LEFT, - Z3_OP_ROTATE_RIGHT, - Z3_OP_EXT_ROTATE_LEFT, - Z3_OP_EXT_ROTATE_RIGHT, - Z3_OP_INT2BV, - Z3_OP_BV2INT, - Z3_OP_CARRY, - Z3_OP_XOR3, - Z3_OP_PR_UNDEF, - Z3_OP_PR_TRUE, - Z3_OP_PR_ASSERTED, - Z3_OP_PR_GOAL, - Z3_OP_PR_MODUS_PONENS, - Z3_OP_PR_REFLEXIVITY, - Z3_OP_PR_SYMMETRY, - Z3_OP_PR_TRANSITIVITY, - Z3_OP_PR_TRANSITIVITY_STAR, - Z3_OP_PR_MONOTONICITY, - Z3_OP_PR_QUANT_INTRO, - Z3_OP_PR_DISTRIBUTIVITY, - Z3_OP_PR_AND_ELIM, - Z3_OP_PR_NOT_OR_ELIM, - Z3_OP_PR_REWRITE, - Z3_OP_PR_REWRITE_STAR, - Z3_OP_PR_PULL_QUANT, - Z3_OP_PR_PULL_QUANT_STAR, - Z3_OP_PR_PUSH_QUANT, - Z3_OP_PR_ELIM_UNUSED_VARS, - Z3_OP_PR_DER, - Z3_OP_PR_QUANT_INST, - Z3_OP_PR_HYPOTHESIS, - Z3_OP_PR_LEMMA, - Z3_OP_PR_UNIT_RESOLUTION, - Z3_OP_PR_IFF_TRUE, - Z3_OP_PR_IFF_FALSE, - Z3_OP_PR_COMMUTATIVITY, - Z3_OP_PR_DEF_AXIOM, - Z3_OP_PR_DEF_INTRO, - Z3_OP_PR_APPLY_DEF, - Z3_OP_PR_IFF_OEQ, - Z3_OP_PR_NNF_POS, - Z3_OP_PR_NNF_NEG, - Z3_OP_PR_NNF_STAR, - Z3_OP_PR_CNF_STAR, - Z3_OP_PR_SKOLEMIZE, - Z3_OP_PR_MODUS_PONENS_OEQ, - Z3_OP_PR_TH_LEMMA, - Z3_OP_PR_HYPER_RESOLVE, - Z3_OP_RA_STORE, - Z3_OP_RA_EMPTY, - Z3_OP_RA_IS_EMPTY, - Z3_OP_RA_JOIN, - Z3_OP_RA_UNION, - Z3_OP_RA_WIDEN, - Z3_OP_RA_PROJECT, - Z3_OP_RA_FILTER, - Z3_OP_RA_NEGATION_FILTER, - Z3_OP_RA_RENAME, - Z3_OP_RA_COMPLEMENT, - Z3_OP_RA_SELECT, - Z3_OP_RA_CLONE, - Z3_OP_FD_LT, - Z3_OP_LABEL, - Z3_OP_LABEL_LIT, - Z3_OP_DT_CONSTRUCTOR, - Z3_OP_DT_RECOGNISER, - Z3_OP_DT_ACCESSOR, - Z3_OP_UNINTERPRETED, -}; - -void camlidl_ml2c_z3V3_Z3_decl_kind(value _v1, Z3_decl_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_6[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_decl_kind(Z3_decl_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3V3_enum_6, 152, "typedef Z3_decl_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3V3_enum_7[7] = { - Z3_PK_UINT, - Z3_PK_BOOL, - Z3_PK_DOUBLE, - Z3_PK_SYMBOL, - Z3_PK_STRING, - Z3_PK_OTHER, - Z3_PK_INVALID, -}; - -void camlidl_ml2c_z3V3_Z3_param_kind(value _v1, Z3_param_kind * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_7[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_param_kind(Z3_param_kind * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3V3_enum_7, 7, "typedef Z3_param_kind: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3V3_enum_8[8] = { - Z3_NO_FAILURE, - Z3_UNKNOWN, - Z3_TIMEOUT, - Z3_MEMOUT_WATERMARK, - Z3_CANCELED, - Z3_NUM_CONFLICTS, - Z3_THEORY, - Z3_QUANTIFIERS, -}; - -void camlidl_ml2c_z3V3_Z3_search_failure(value _v1, Z3_search_failure * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_8[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_search_failure(Z3_search_failure * _c2, camlidl_ctx _ctx) -{ -value _v1; - _v1 = camlidl_find_enum((*_c2), camlidl_transl_table_z3V3_enum_8, 8, "typedef Z3_search_failure: bad enum value"); - return _v1; -} - -int camlidl_transl_table_z3V3_enum_9[4] = { - Z3_PRINT_SMTLIB_FULL, - Z3_PRINT_LOW_LEVEL, - Z3_PRINT_SMTLIB_COMPLIANT, - Z3_PRINT_SMTLIB2_COMPLIANT, -}; - -void camlidl_ml2c_z3V3_Z3_ast_print_mode(value _v1, Z3_ast_print_mode * _c2, camlidl_ctx _ctx) -{ - (*_c2) = camlidl_transl_table_z3V3_enum_9[Int_val(_v1)]; -} - -value camlidl_c2ml_z3V3_Z3_ast_print_mode(Z3_ast_print_mode * _c2, camlidl_ctx _ctx) -{ -value _v1; - switch((*_c2)) { - case Z3_PRINT_SMTLIB_FULL: _v1 = Val_int(0); break; - case Z3_PRINT_LOW_LEVEL: _v1 = Val_int(1); break; - case Z3_PRINT_SMTLIB_COMPLIANT: _v1 = Val_int(2); break; - case Z3_PRINT_SMTLIB2_COMPLIANT: _v1 = Val_int(3); break; - default: invalid_argument("typedef Z3_ast_print_mode: bad enum value"); - } - return _v1; -} - -value camlidl_z3V3_Z3_global_param_set( - value _v_param_id, - value _v_param_value) -{ - Z3_string param_id; /*in*/ - Z3_string param_value; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_string(_v_param_id, ¶m_id, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_param_value, ¶m_value, _ctx); - Z3_global_param_set(param_id, param_value); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_global_param_reset_all(value _unit) -{ - Z3_global_param_reset_all(); - return Val_unit; -} - -value camlidl_z3V3_Z3_global_param_get( - value _v_param_id) -{ - Z3_string param_id; /*in*/ - Z3_string *param_value; /*out*/ - Z3_string _c1; - value _v2; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_string(_v_param_id, ¶m_id, _ctx); - param_value = &_c1; - Z3_global_param_get(param_id, param_value); - if (param_value == NULL) { - _vres = Val_int(0); - } else { - _v2 = camlidl_c2ml_z3V3_Z3_string(&*param_value, _ctx); - Begin_root(_v2) - _vres = camlidl_alloc_small(1, 0); - Field(_vres, 0) = _v2; - End_roots(); - } - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_config(value _unit) -{ - Z3_config _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - _res = Z3_mk_config(); - _vres = camlidl_c2ml_z3V3_Z3_config(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_del_config( - value _v_c) -{ - Z3_config c; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_config(_v_c, &c, _ctx); - Z3_del_config(c); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_set_param_value( - value _v_c, - value _v_param_id, - value _v_param_value) -{ - Z3_config c; /*in*/ - Z3_string param_id; /*in*/ - Z3_string param_value; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_config(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_param_id, ¶m_id, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_param_value, ¶m_value, _ctx); - Z3_set_param_value(c, param_id, param_value); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_mk_context( - value _v_c) -{ - Z3_config c; /*in*/ - Z3_context _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_config(_v_c, &c, _ctx); - _res = Z3_mk_context(c); - _vres = camlidl_c2ml_z3V3_Z3_context(&_res, _ctx); - camlidl_free(_ctx); - /* begin user-supplied deallocation sequence */ -Z3_set_error_handler(_res, (void*)caml_z3_error_handler); - /* end user-supplied deallocation sequence */ - return _vres; -} - -value camlidl_z3V3_Z3_del_context( - value _v_c) -{ - Z3_context c; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - Z3_del_context(c); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_update_param_value( - value _v_c, - value _v_param_id, - value _v_param_value) -{ - Z3_context c; /*in*/ - Z3_string param_id; /*in*/ - Z3_string param_value; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_param_id, ¶m_id, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_param_value, ¶m_value, _ctx); - Z3_update_param_value(c, param_id, param_value); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_get_param_value( - value _v_c, - value _v_param_id) -{ - Z3_context c; /*in*/ - Z3_string param_id; /*in*/ - Z3_string *param_value; /*out*/ - Z3_string _c1; - value _v2; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_param_id, ¶m_id, _ctx); - param_value = &_c1; - Z3_get_param_value(c, param_id, param_value); - if (param_value == NULL) { - _vres = Val_int(0); - } else { - _v2 = camlidl_c2ml_z3V3_Z3_string(&*param_value, _ctx); - Begin_root(_v2) - _vres = camlidl_alloc_small(1, 0); - Field(_vres, 0) = _v2; - End_roots(); - } - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_int_symbol( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - int i; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_mk_int_symbol(c, i); - _vres = camlidl_c2ml_z3V3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_string_symbol( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_string s; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_s, &s, _ctx); - _res = Z3_mk_string_symbol(c, s); - _vres = camlidl_c2ml_z3V3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_uninterpreted_sort( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_mk_uninterpreted_sort(c, s); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bool_sort( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_bool_sort(c); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_int_sort( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_int_sort(c); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_real_sort( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_real_sort(c); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bv_sort( - value _v_c, - value _v_sz) -{ - Z3_context c; /*in*/ - unsigned int sz; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - sz = Int_val(_v_sz); - _res = Z3_mk_bv_sort(c, sz); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_finite_domain_sort( - value _v_c, - value _v_name, - value _v_size) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - unsigned long long size; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_name, &name, _ctx); - size = Int64_val(_v_size); - _res = Z3_mk_finite_domain_sort(c, name, size); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_array_sort( - value _v_c, - value _v_domain, - value _v_range) -{ - Z3_context c; /*in*/ - Z3_sort domain; /*in*/ - Z3_sort range; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_domain, &domain, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_range, &range, _ctx); - _res = Z3_mk_array_sort(c, domain, range); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_tuple_sort( - value _v_c, - value _v_mk_tuple_name, - value _v_field_names, - value _v_field_sorts) -{ - Z3_context c; /*in*/ - Z3_symbol mk_tuple_name; /*in*/ - unsigned int num_fields; /*in*/ - Z3_symbol const *field_names; /*in*/ - Z3_sort const *field_sorts; /*in*/ - Z3_func_decl *mk_tuple_decl; /*out*/ - Z3_func_decl *proj_decl; /*out*/ - Z3_sort _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - Z3_func_decl _c7; - mlsize_t _c8; - value _v9; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_mk_tuple_name, &mk_tuple_name, _ctx); - _c1 = Wosize_val(_v_field_names); - field_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_field_names, _c2); - camlidl_ml2c_z3V3_Z3_symbol(_v3, &field_names[_c2], _ctx); - } - num_fields = _c1; - _c4 = Wosize_val(_v_field_sorts); - field_sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_field_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &field_sorts[_c5], _ctx); - } - num_fields = _c4; - mk_tuple_decl = &_c7; - proj_decl = camlidl_malloc(num_fields * sizeof(Z3_func_decl ), _ctx); - _res = Z3_mk_tuple_sort(c, mk_tuple_name, num_fields, field_names, field_sorts, mk_tuple_decl, proj_decl); - Begin_roots_block(_vres, 3) - _vres[0] = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - _vres[1] = camlidl_c2ml_z3V3_Z3_func_decl(&*mk_tuple_decl, _ctx); - _vres[2] = camlidl_alloc(num_fields, 0); - Begin_root(_vres[2]) - for (_c8 = 0; _c8 < num_fields; _c8++) { - _v9 = camlidl_c2ml_z3V3_Z3_func_decl(&proj_decl[_c8], _ctx); - modify(&Field(_vres[2], _c8), _v9); - } - End_roots() - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_mk_enumeration_sort( - value _v_c, - value _v_name, - value _v_enum_names) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - unsigned int n; /*in*/ - Z3_symbol const *enum_names; /*in*/ - Z3_func_decl *enum_consts; /*out*/ - Z3_func_decl *enum_testers; /*out*/ - Z3_sort _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - value _v5; - mlsize_t _c6; - value _v7; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_name, &name, _ctx); - _c1 = Wosize_val(_v_enum_names); - enum_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_enum_names, _c2); - camlidl_ml2c_z3V3_Z3_symbol(_v3, &enum_names[_c2], _ctx); - } - n = _c1; - enum_consts = camlidl_malloc(n * sizeof(Z3_func_decl ), _ctx); - enum_testers = camlidl_malloc(n * sizeof(Z3_func_decl ), _ctx); - _res = Z3_mk_enumeration_sort(c, name, n, enum_names, enum_consts, enum_testers); - Begin_roots_block(_vres, 3) - _vres[0] = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - _vres[1] = camlidl_alloc(n, 0); - Begin_root(_vres[1]) - for (_c4 = 0; _c4 < n; _c4++) { - _v5 = camlidl_c2ml_z3V3_Z3_func_decl(&enum_consts[_c4], _ctx); - modify(&Field(_vres[1], _c4), _v5); - } - End_roots() - _vres[2] = camlidl_alloc(n, 0); - Begin_root(_vres[2]) - for (_c6 = 0; _c6 < n; _c6++) { - _v7 = camlidl_c2ml_z3V3_Z3_func_decl(&enum_testers[_c6], _ctx); - modify(&Field(_vres[2], _c6), _v7); - } - End_roots() - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_mk_list_sort( - value _v_c, - value _v_name, - value _v_elem_sort) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - Z3_sort elem_sort; /*in*/ - Z3_func_decl *nil_decl; /*out*/ - Z3_func_decl *is_nil_decl; /*out*/ - Z3_func_decl *cons_decl; /*out*/ - Z3_func_decl *is_cons_decl; /*out*/ - Z3_func_decl *head_decl; /*out*/ - Z3_func_decl *tail_decl; /*out*/ - Z3_sort _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - Z3_func_decl _c1; - Z3_func_decl _c2; - Z3_func_decl _c3; - Z3_func_decl _c4; - Z3_func_decl _c5; - Z3_func_decl _c6; - value _vresult; - value _vres[7] = { 0, 0, 0, 0, 0, 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_name, &name, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_elem_sort, &elem_sort, _ctx); - nil_decl = &_c1; - is_nil_decl = &_c2; - cons_decl = &_c3; - is_cons_decl = &_c4; - head_decl = &_c5; - tail_decl = &_c6; - _res = Z3_mk_list_sort(c, name, elem_sort, nil_decl, is_nil_decl, cons_decl, is_cons_decl, head_decl, tail_decl); - Begin_roots_block(_vres, 7) - _vres[0] = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - _vres[1] = camlidl_c2ml_z3V3_Z3_func_decl(&*nil_decl, _ctx); - _vres[2] = camlidl_c2ml_z3V3_Z3_func_decl(&*is_nil_decl, _ctx); - _vres[3] = camlidl_c2ml_z3V3_Z3_func_decl(&*cons_decl, _ctx); - _vres[4] = camlidl_c2ml_z3V3_Z3_func_decl(&*is_cons_decl, _ctx); - _vres[5] = camlidl_c2ml_z3V3_Z3_func_decl(&*head_decl, _ctx); - _vres[6] = camlidl_c2ml_z3V3_Z3_func_decl(&*tail_decl, _ctx); - _vresult = camlidl_alloc_small(7, 0); - { mlsize_t _c7; - for (_c7 = 0; _c7 < 7; _c7++) Field(_vresult, _c7) = _vres[_c7]; - } - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_mk_constructor( - value _v_c, - value _v_name, - value _v_recognizer, - value _v_field_names, - value _v_sorts, - value _v_sort_refs) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - Z3_symbol recognizer; /*in*/ - unsigned int num_fields; /*in*/ - Z3_symbol const *field_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int *sort_refs; /*in*/ - Z3_constructor _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_name, &name, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_recognizer, &recognizer, _ctx); - _c1 = Wosize_val(_v_field_names); - field_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_field_names, _c2); - camlidl_ml2c_z3V3_Z3_symbol(_v3, &field_names[_c2], _ctx); - } - num_fields = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_fields = _c4; - _c7 = Wosize_val(_v_sort_refs); - sort_refs = camlidl_malloc(_c7 * sizeof(unsigned int ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_sort_refs, _c8); - sort_refs[_c8] = Int_val(_v9); - } - num_fields = _c7; - _res = Z3_mk_constructor(c, name, recognizer, num_fields, field_names, sorts, sort_refs); - _vres = camlidl_c2ml_z3V3_Z3_constructor(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_constructor_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_mk_constructor(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3V3_Z3_del_constructor( - value _v_c, - value _v_constr) -{ - Z3_context c; /*in*/ - Z3_constructor constr; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_constructor(_v_constr, &constr, _ctx); - Z3_del_constructor(c, constr); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_mk_datatype( - value _v_c, - value _v_name, - value _v_constructors) -{ - Z3_context c; /*in*/ - Z3_symbol name; /*in*/ - unsigned int num_constructors; /*in*/ - Z3_constructor *constructors; /*in,out*/ - Z3_sort _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - value _v5; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_name, &name, _ctx); - _c1 = Wosize_val(_v_constructors); - constructors = camlidl_malloc(_c1 * sizeof(Z3_constructor ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_constructors, _c2); - camlidl_ml2c_z3V3_Z3_constructor(_v3, &constructors[_c2], _ctx); - } - num_constructors = _c1; - _res = Z3_mk_datatype(c, name, num_constructors, constructors); - Begin_roots_block(_vres, 2) - _vres[0] = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - _vres[1] = camlidl_alloc(num_constructors, 0); - Begin_root(_vres[1]) - for (_c4 = 0; _c4 < num_constructors; _c4++) { - _v5 = camlidl_c2ml_z3V3_Z3_constructor(&constructors[_c4], _ctx); - modify(&Field(_vres[1], _c4), _v5); - } - End_roots() - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_mk_constructor_list( - value _v_c, - value _v_constructors) -{ - Z3_context c; /*in*/ - unsigned int num_constructors; /*in*/ - Z3_constructor const *constructors; /*in*/ - Z3_constructor_list _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_constructors); - constructors = camlidl_malloc(_c1 * sizeof(Z3_constructor const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_constructors, _c2); - camlidl_ml2c_z3V3_Z3_constructor(_v3, &constructors[_c2], _ctx); - } - num_constructors = _c1; - _res = Z3_mk_constructor_list(c, num_constructors, constructors); - _vres = camlidl_c2ml_z3V3_Z3_constructor_list(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_del_constructor_list( - value _v_c, - value _v_clist) -{ - Z3_context c; /*in*/ - Z3_constructor_list clist; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_constructor_list(_v_clist, &clist, _ctx); - Z3_del_constructor_list(c, clist); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_mk_datatypes( - value _v_c, - value _v_sort_names, - value _v_constructor_lists) -{ - Z3_context c; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort *sorts; /*out*/ - Z3_constructor_list *constructor_lists; /*in,out*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - value _v8; - mlsize_t _c9; - value _v10; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3V3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_constructor_lists); - constructor_lists = camlidl_malloc(_c4 * sizeof(Z3_constructor_list ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_constructor_lists, _c5); - camlidl_ml2c_z3V3_Z3_constructor_list(_v6, &constructor_lists[_c5], _ctx); - } - num_sorts = _c4; - sorts = camlidl_malloc(num_sorts * sizeof(Z3_sort ), _ctx); - Z3_mk_datatypes(c, num_sorts, sort_names, sorts, constructor_lists); - Begin_roots_block(_vres, 2) - _vres[0] = camlidl_alloc(num_sorts, 0); - Begin_root(_vres[0]) - for (_c7 = 0; _c7 < num_sorts; _c7++) { - _v8 = camlidl_c2ml_z3V3_Z3_sort(&sorts[_c7], _ctx); - modify(&Field(_vres[0], _c7), _v8); - } - End_roots() - _vres[1] = camlidl_alloc(num_sorts, 0); - Begin_root(_vres[1]) - for (_c9 = 0; _c9 < num_sorts; _c9++) { - _v10 = camlidl_c2ml_z3V3_Z3_constructor_list(&constructor_lists[_c9], _ctx); - modify(&Field(_vres[1], _c9), _v10); - } - End_roots() - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_query_constructor( - value _v_c, - value _v_constr, - value _v_num_fields) -{ - Z3_context c; /*in*/ - Z3_constructor constr; /*in*/ - unsigned int num_fields; /*in*/ - Z3_func_decl *constructor; /*out*/ - Z3_func_decl *tester; /*out*/ - Z3_func_decl *accessors; /*out*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - Z3_func_decl _c1; - Z3_func_decl _c2; - mlsize_t _c3; - value _v4; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_constructor(_v_constr, &constr, _ctx); - num_fields = Int_val(_v_num_fields); - constructor = &_c1; - tester = &_c2; - accessors = camlidl_malloc(num_fields * sizeof(Z3_func_decl ), _ctx); - Z3_query_constructor(c, constr, num_fields, constructor, tester, accessors); - Begin_roots_block(_vres, 3) - _vres[0] = camlidl_c2ml_z3V3_Z3_func_decl(&*constructor, _ctx); - _vres[1] = camlidl_c2ml_z3V3_Z3_func_decl(&*tester, _ctx); - _vres[2] = camlidl_alloc(num_fields, 0); - Begin_root(_vres[2]) - for (_c3 = 0; _c3 < num_fields; _c3++) { - _v4 = camlidl_c2ml_z3V3_Z3_func_decl(&accessors[_c3], _ctx); - modify(&Field(_vres[2], _c3), _v4); - } - End_roots() - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_mk_func_decl( - value _v_c, - value _v_s, - value _v_domain, - value _v_range) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - unsigned int domain_size; /*in*/ - Z3_sort const *domain; /*in*/ - Z3_sort range; /*in*/ - Z3_func_decl _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - _c1 = Wosize_val(_v_domain); - domain = camlidl_malloc(_c1 * sizeof(Z3_sort const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_domain, _c2); - camlidl_ml2c_z3V3_Z3_sort(_v3, &domain[_c2], _ctx); - } - domain_size = _c1; - camlidl_ml2c_z3V3_Z3_sort(_v_range, &range, _ctx); - _res = Z3_mk_func_decl(c, s, domain_size, domain, range); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_app( - value _v_c, - value _v_d, - value _v_args) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_app(c, d, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_const( - value _v_c, - value _v_s, - value _v_ty) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_const(c, s, ty); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_fresh_func_decl( - value _v_c, - value _v_prefix, - value _v_domain, - value _v_range) -{ - Z3_context c; /*in*/ - Z3_string prefix; /*in*/ - unsigned int domain_size; /*in*/ - Z3_sort const *domain; /*in*/ - Z3_sort range; /*in*/ - Z3_func_decl _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_prefix, &prefix, _ctx); - _c1 = Wosize_val(_v_domain); - domain = camlidl_malloc(_c1 * sizeof(Z3_sort const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_domain, _c2); - camlidl_ml2c_z3V3_Z3_sort(_v3, &domain[_c2], _ctx); - } - domain_size = _c1; - camlidl_ml2c_z3V3_Z3_sort(_v_range, &range, _ctx); - _res = Z3_mk_fresh_func_decl(c, prefix, domain_size, domain, range); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_fresh_const( - value _v_c, - value _v_prefix, - value _v_ty) -{ - Z3_context c; /*in*/ - Z3_string prefix; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_prefix, &prefix, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_fresh_const(c, prefix, ty); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_true( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_true(c); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_false( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_mk_false(c); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_eq( - value _v_c, - value _v_l, - value _v_r) -{ - Z3_context c; /*in*/ - Z3_ast l; /*in*/ - Z3_ast r; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_l, &l, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_r, &r, _ctx); - _res = Z3_mk_eq(c, l, r); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_distinct( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_distinct(c, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_not( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_mk_not(c, a); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_ite( - value _v_c, - value _v_t1, - value _v_t2, - value _v_t3) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast t3; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t3, &t3, _ctx); - _res = Z3_mk_ite(c, t1, t2, t3); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_iff( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_iff(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_implies( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_implies(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_xor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_xor(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_and( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_and(c, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_or( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_or(c, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_add( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_add(c, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_mul( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_mul(c, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_sub( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_sub(c, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_unary_minus( - value _v_c, - value _v_arg) -{ - Z3_context c; /*in*/ - Z3_ast arg; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg, &arg, _ctx); - _res = Z3_mk_unary_minus(c, arg); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_div( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_div(c, arg1, arg2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_mod( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_mod(c, arg1, arg2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_rem( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_rem(c, arg1, arg2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_power( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_power(c, arg1, arg2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_lt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_lt(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_le( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_le(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_gt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_gt(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_ge( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_ge(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_int2real( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_int2real(c, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_real2int( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_real2int(c, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_is_int( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_is_int(c, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvnot( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvnot(c, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvredand( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvredand(c, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvredor( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvredor(c, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvand( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvand(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvor(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvxor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvxor(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvnand( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvnand(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvnor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvnor(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvxnor( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvxnor(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvneg( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvneg(c, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvadd( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvadd(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsub( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsub(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvmul( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvmul(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvudiv( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvudiv(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsdiv( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsdiv(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvurem( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvurem(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsrem( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsrem(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsmod( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsmod(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvult( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvult(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvslt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvslt(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvule( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvule(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsle( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsle(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvuge( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvuge(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsge( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsge(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvugt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvugt(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsgt( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsgt(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_concat( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_concat(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_extract( - value _v_c, - value _v_high, - value _v_low, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int high; /*in*/ - unsigned int low; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - high = Int_val(_v_high); - low = Int_val(_v_low); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_extract(c, high, low, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_sign_ext( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_sign_ext(c, i, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_zero_ext( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_zero_ext(c, i, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_repeat( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_repeat(c, i, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvshl( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvshl(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvlshr( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvlshr(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvashr( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvashr(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_rotate_left( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_rotate_left(c, i, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_rotate_right( - value _v_c, - value _v_i, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_rotate_right(c, i, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_ext_rotate_left( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_ext_rotate_left(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_ext_rotate_right( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_ext_rotate_right(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_int2bv( - value _v_c, - value _v_n, - value _v_t1) -{ - Z3_context c; /*in*/ - unsigned int n; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - n = Int_val(_v_n); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_int2bv(c, n, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bv2int( - value _v_c, - value _v_t1, - value _v_is_signed) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - int is_signed; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - is_signed = Int_val(_v_is_signed); - _res = Z3_mk_bv2int(c, t1, is_signed); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvadd_no_overflow( - value _v_c, - value _v_t1, - value _v_t2, - value _v_is_signed) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - int is_signed; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - is_signed = Int_val(_v_is_signed); - _res = Z3_mk_bvadd_no_overflow(c, t1, t2, is_signed); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvadd_no_underflow( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvadd_no_underflow(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsub_no_overflow( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsub_no_overflow(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsub_no_underflow( - value _v_c, - value _v_t1, - value _v_t2, - value _v_is_signed) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - int is_signed; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - is_signed = Int_val(_v_is_signed); - _res = Z3_mk_bvsub_no_underflow(c, t1, t2, is_signed); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvsdiv_no_overflow( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvsdiv_no_overflow(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvneg_no_overflow( - value _v_c, - value _v_t1) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - _res = Z3_mk_bvneg_no_overflow(c, t1); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvmul_no_overflow( - value _v_c, - value _v_t1, - value _v_t2, - value _v_is_signed) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - int is_signed; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - is_signed = Int_val(_v_is_signed); - _res = Z3_mk_bvmul_no_overflow(c, t1, t2, is_signed); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bvmul_no_underflow( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_mk_bvmul_no_underflow(c, t1, t2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_select( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_i, &i, _ctx); - _res = Z3_mk_select(c, a, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_store( - value _v_c, - value _v_a, - value _v_i, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast i; /*in*/ - Z3_ast v; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_i, &i, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_v, &v, _ctx); - _res = Z3_mk_store(c, a, i, v); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_const_array( - value _v_c, - value _v_domain, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_sort domain; /*in*/ - Z3_ast v; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_domain, &domain, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_v, &v, _ctx); - _res = Z3_mk_const_array(c, domain, v); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_map( - value _v_c, - value _v_f, - value _v_n, - value _v_args) -{ - Z3_context c; /*in*/ - Z3_func_decl f; /*in*/ - unsigned int n; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - Z3_ast _c1; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_f, &f, _ctx); - n = Int_val(_v_n); - args = &_c1; - camlidl_ml2c_z3V3_Z3_ast(_v_args, &_c1, _ctx); - _res = Z3_mk_map(c, f, n, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_array_default( - value _v_c, - value _v_array) -{ - Z3_context c; /*in*/ - Z3_ast array; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_array, &array, _ctx); - _res = Z3_mk_array_default(c, array); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_sort( - value _v_c, - value _v_ty) -{ - Z3_context c; /*in*/ - Z3_sort ty; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_set_sort(c, ty); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_empty_set( - value _v_c, - value _v_domain) -{ - Z3_context c; /*in*/ - Z3_sort domain; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_domain, &domain, _ctx); - _res = Z3_mk_empty_set(c, domain); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_full_set( - value _v_c, - value _v_domain) -{ - Z3_context c; /*in*/ - Z3_sort domain; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_domain, &domain, _ctx); - _res = Z3_mk_full_set(c, domain); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_add( - value _v_c, - value _v_set, - value _v_elem) -{ - Z3_context c; /*in*/ - Z3_ast set; /*in*/ - Z3_ast elem; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_set, &set, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_elem, &elem, _ctx); - _res = Z3_mk_set_add(c, set, elem); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_del( - value _v_c, - value _v_set, - value _v_elem) -{ - Z3_context c; /*in*/ - Z3_ast set; /*in*/ - Z3_ast elem; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_set, &set, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_elem, &elem, _ctx); - _res = Z3_mk_set_del(c, set, elem); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_union( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_set_union(c, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_intersect( - value _v_c, - value _v_args) -{ - Z3_context c; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_mk_set_intersect(c, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_difference( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_set_difference(c, arg1, arg2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_complement( - value _v_c, - value _v_arg) -{ - Z3_context c; /*in*/ - Z3_ast arg; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg, &arg, _ctx); - _res = Z3_mk_set_complement(c, arg); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_member( - value _v_c, - value _v_elem, - value _v_set) -{ - Z3_context c; /*in*/ - Z3_ast elem; /*in*/ - Z3_ast set; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_elem, &elem, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_set, &set, _ctx); - _res = Z3_mk_set_member(c, elem, set); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_set_subset( - value _v_c, - value _v_arg1, - value _v_arg2) -{ - Z3_context c; /*in*/ - Z3_ast arg1; /*in*/ - Z3_ast arg2; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg1, &arg1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_arg2, &arg2, _ctx); - _res = Z3_mk_set_subset(c, arg1, arg2); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_numeral( - value _v_c, - value _v_numeral, - value _v_ty) -{ - Z3_context c; /*in*/ - Z3_string numeral; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_numeral, &numeral, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_numeral(c, numeral, ty); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_real( - value _v_c, - value _v_num, - value _v_den) -{ - Z3_context c; /*in*/ - int num; /*in*/ - int den; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - num = Int_val(_v_num); - den = Int_val(_v_den); - _res = Z3_mk_real(c, num, den); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_int( - value _v_c, - value _v_v, - value _v_ty) -{ - Z3_context c; /*in*/ - int v; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - v = Int_val(_v_v); - camlidl_ml2c_z3V3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_int(c, v, ty); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_int64( - value _v_c, - value _v_v, - value _v_ty) -{ - Z3_context c; /*in*/ - long long v; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - v = Int64_val(_v_v); - camlidl_ml2c_z3V3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_int64(c, v, ty); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_pattern( - value _v_c, - value _v_terms) -{ - Z3_context c; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_ast const *terms; /*in*/ - Z3_pattern _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_terms); - terms = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_terms, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &terms[_c2], _ctx); - } - num_patterns = _c1; - _res = Z3_mk_pattern(c, num_patterns, terms); - _vres = camlidl_c2ml_z3V3_Z3_pattern(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_bound( - value _v_c, - value _v_index, - value _v_ty) -{ - Z3_context c; /*in*/ - unsigned int index; /*in*/ - Z3_sort ty; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - index = Int_val(_v_index); - camlidl_ml2c_z3V3_Z3_sort(_v_ty, &ty, _ctx); - _res = Z3_mk_bound(c, index, ty); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_forall( - value _v_c, - value _v_weight, - value _v_patterns, - value _v_sorts, - value _v_decl_names, - value _v_body) -{ - Z3_context c; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_decls; /*in*/ - Z3_sort const *sorts; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c1 * sizeof(Z3_pattern const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_patterns, _c2); - camlidl_ml2c_z3V3_Z3_pattern(_v3, &patterns[_c2], _ctx); - } - num_patterns = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_decls = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3V3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - camlidl_ml2c_z3V3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_forall(c, weight, num_patterns, patterns, num_decls, sorts, decl_names, body); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_forall_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_mk_forall(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3V3_Z3_mk_exists( - value _v_c, - value _v_weight, - value _v_patterns, - value _v_sorts, - value _v_decl_names, - value _v_body) -{ - Z3_context c; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_decls; /*in*/ - Z3_sort const *sorts; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c1 * sizeof(Z3_pattern const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_patterns, _c2); - camlidl_ml2c_z3V3_Z3_pattern(_v3, &patterns[_c2], _ctx); - } - num_patterns = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_decls = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3V3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - camlidl_ml2c_z3V3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_exists(c, weight, num_patterns, patterns, num_decls, sorts, decl_names, body); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_exists_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_mk_exists(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3V3_Z3_mk_quantifier( - value _v_c, - value _v_is_forall, - value _v_weight, - value _v_patterns, - value _v_sorts, - value _v_decl_names, - value _v_body) -{ - Z3_context c; /*in*/ - int is_forall; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_decls; /*in*/ - Z3_sort const *sorts; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - is_forall = Int_val(_v_is_forall); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c1 * sizeof(Z3_pattern const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_patterns, _c2); - camlidl_ml2c_z3V3_Z3_pattern(_v3, &patterns[_c2], _ctx); - } - num_patterns = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_decls = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3V3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - camlidl_ml2c_z3V3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_quantifier(c, is_forall, weight, num_patterns, patterns, num_decls, sorts, decl_names, body); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_quantifier_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_mk_quantifier(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); -} - -value camlidl_z3V3_Z3_mk_quantifier_ex( - value _v_c, - value _v_is_forall, - value _v_weight, - value _v_quantifier_id, - value _v_skolem_id, - value _v_patterns, - value _v_no_patterns, - value _v_sorts, - value _v_decl_names, - value _v_body) -{ - Z3_context c; /*in*/ - int is_forall; /*in*/ - unsigned int weight; /*in*/ - Z3_symbol quantifier_id; /*in*/ - Z3_symbol skolem_id; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_no_patterns; /*in*/ - Z3_ast const *no_patterns; /*in*/ - unsigned int num_decls; /*in*/ - Z3_sort const *sorts; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - is_forall = Int_val(_v_is_forall); - weight = Int_val(_v_weight); - camlidl_ml2c_z3V3_Z3_symbol(_v_quantifier_id, &quantifier_id, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_skolem_id, &skolem_id, _ctx); - _c1 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c1 * sizeof(Z3_pattern const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_patterns, _c2); - camlidl_ml2c_z3V3_Z3_pattern(_v3, &patterns[_c2], _ctx); - } - num_patterns = _c1; - _c4 = Wosize_val(_v_no_patterns); - no_patterns = camlidl_malloc(_c4 * sizeof(Z3_ast const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_no_patterns, _c5); - camlidl_ml2c_z3V3_Z3_ast(_v6, &no_patterns[_c5], _ctx); - } - num_no_patterns = _c4; - _c7 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c7 * sizeof(Z3_sort const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_sorts, _c8); - camlidl_ml2c_z3V3_Z3_sort(_v9, &sorts[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c10 * sizeof(Z3_symbol const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decl_names, _c11); - camlidl_ml2c_z3V3_Z3_symbol(_v12, &decl_names[_c11], _ctx); - } - num_decls = _c10; - camlidl_ml2c_z3V3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_quantifier_ex(c, is_forall, weight, quantifier_id, skolem_id, num_patterns, patterns, num_no_patterns, no_patterns, num_decls, sorts, decl_names, body); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_quantifier_ex_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_mk_quantifier_ex(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8], argv[9]); -} - -value camlidl_z3V3_Z3_mk_forall_const( - value _v_c, - value _v_weight, - value _v_bound, - value _v_patterns, - value _v_body) -{ - Z3_context c; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_bound; /*in*/ - Z3_app const *bound; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_bound); - bound = camlidl_malloc(_c1 * sizeof(Z3_app const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_bound, _c2); - camlidl_ml2c_z3V3_Z3_app(_v3, &bound[_c2], _ctx); - } - num_bound = _c1; - _c4 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c4 * sizeof(Z3_pattern const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_patterns, _c5); - camlidl_ml2c_z3V3_Z3_pattern(_v6, &patterns[_c5], _ctx); - } - num_patterns = _c4; - camlidl_ml2c_z3V3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_forall_const(c, weight, num_bound, bound, num_patterns, patterns, body); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_exists_const( - value _v_c, - value _v_weight, - value _v_bound, - value _v_patterns, - value _v_body) -{ - Z3_context c; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_bound; /*in*/ - Z3_app const *bound; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_bound); - bound = camlidl_malloc(_c1 * sizeof(Z3_app const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_bound, _c2); - camlidl_ml2c_z3V3_Z3_app(_v3, &bound[_c2], _ctx); - } - num_bound = _c1; - _c4 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c4 * sizeof(Z3_pattern const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_patterns, _c5); - camlidl_ml2c_z3V3_Z3_pattern(_v6, &patterns[_c5], _ctx); - } - num_patterns = _c4; - camlidl_ml2c_z3V3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_exists_const(c, weight, num_bound, bound, num_patterns, patterns, body); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_quantifier_const( - value _v_c, - value _v_is_forall, - value _v_weight, - value _v_bound, - value _v_patterns, - value _v_body) -{ - Z3_context c; /*in*/ - int is_forall; /*in*/ - unsigned int weight; /*in*/ - unsigned int num_bound; /*in*/ - Z3_app const *bound; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - is_forall = Int_val(_v_is_forall); - weight = Int_val(_v_weight); - _c1 = Wosize_val(_v_bound); - bound = camlidl_malloc(_c1 * sizeof(Z3_app const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_bound, _c2); - camlidl_ml2c_z3V3_Z3_app(_v3, &bound[_c2], _ctx); - } - num_bound = _c1; - _c4 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c4 * sizeof(Z3_pattern const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_patterns, _c5); - camlidl_ml2c_z3V3_Z3_pattern(_v6, &patterns[_c5], _ctx); - } - num_patterns = _c4; - camlidl_ml2c_z3V3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_quantifier_const(c, is_forall, weight, num_bound, bound, num_patterns, patterns, body); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_quantifier_const_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_mk_quantifier_const(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3V3_Z3_mk_quantifier_const_ex( - value _v_c, - value _v_is_forall, - value _v_weight, - value _v_quantifier_id, - value _v_skolem_id, - value _v_bound, - value _v_patterns, - value _v_no_patterns, - value _v_body) -{ - Z3_context c; /*in*/ - int is_forall; /*in*/ - unsigned int weight; /*in*/ - Z3_symbol quantifier_id; /*in*/ - Z3_symbol skolem_id; /*in*/ - unsigned int num_bound; /*in*/ - Z3_app const *bound; /*in*/ - unsigned int num_patterns; /*in*/ - Z3_pattern const *patterns; /*in*/ - unsigned int num_no_patterns; /*in*/ - Z3_ast const *no_patterns; /*in*/ - Z3_ast body; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - is_forall = Int_val(_v_is_forall); - weight = Int_val(_v_weight); - camlidl_ml2c_z3V3_Z3_symbol(_v_quantifier_id, &quantifier_id, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_skolem_id, &skolem_id, _ctx); - _c1 = Wosize_val(_v_bound); - bound = camlidl_malloc(_c1 * sizeof(Z3_app const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_bound, _c2); - camlidl_ml2c_z3V3_Z3_app(_v3, &bound[_c2], _ctx); - } - num_bound = _c1; - _c4 = Wosize_val(_v_patterns); - patterns = camlidl_malloc(_c4 * sizeof(Z3_pattern const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_patterns, _c5); - camlidl_ml2c_z3V3_Z3_pattern(_v6, &patterns[_c5], _ctx); - } - num_patterns = _c4; - _c7 = Wosize_val(_v_no_patterns); - no_patterns = camlidl_malloc(_c7 * sizeof(Z3_ast const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_no_patterns, _c8); - camlidl_ml2c_z3V3_Z3_ast(_v9, &no_patterns[_c8], _ctx); - } - num_no_patterns = _c7; - camlidl_ml2c_z3V3_Z3_ast(_v_body, &body, _ctx); - _res = Z3_mk_quantifier_const_ex(c, is_forall, weight, quantifier_id, skolem_id, num_bound, bound, num_patterns, patterns, num_no_patterns, no_patterns, body); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_quantifier_const_ex_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_mk_quantifier_const_ex(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]); -} - -value camlidl_z3V3_Z3_get_symbol_kind( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - Z3_symbol_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_get_symbol_kind(c, s); - _vres = camlidl_c2ml_z3V3_Z3_symbol_kind(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_symbol_int( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_get_symbol_int(c, s); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_symbol_string( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_get_symbol_string(c, s); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_sort_name( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_sort d; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_d, &d, _ctx); - _res = Z3_get_sort_name(c, d); - _vres = camlidl_c2ml_z3V3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_sort_id( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_get_sort_id(c, s); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_sort_to_ast( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_sort_to_ast(c, s); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_is_eq_sort( - value _v_c, - value _v_s1, - value _v_s2) -{ - Z3_context c; /*in*/ - Z3_sort s1; /*in*/ - Z3_sort s2; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s1, &s1, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s2, &s2, _ctx); - _res = Z3_is_eq_sort(c, s1, s2); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_sort_kind( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - Z3_sort_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_sort_kind(c, t); - _vres = camlidl_c2ml_z3V3_Z3_sort_kind(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_bv_sort_size( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_bv_sort_size(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_finite_domain_sort_size( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - unsigned long long *r; /*out*/ - unsigned long long _c1; - value _v2; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s, &s, _ctx); - r = &_c1; - Z3_get_finite_domain_sort_size(c, s, r); - if (r == NULL) { - _vres = Val_int(0); - } else { - _v2 = copy_int64(*r); - Begin_root(_v2) - _vres = camlidl_alloc_small(1, 0); - Field(_vres, 0) = _v2; - End_roots(); - } - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_array_sort_domain( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_array_sort_domain(c, t); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_array_sort_range( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_array_sort_range(c, t); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_tuple_sort_mk_decl( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_tuple_sort_mk_decl(c, t); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_tuple_sort_num_fields( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_tuple_sort_num_fields(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_tuple_sort_field_decl( - value _v_c, - value _v_t, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int i; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - i = Int_val(_v_i); - _res = Z3_get_tuple_sort_field_decl(c, t, i); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_datatype_sort_num_constructors( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - _res = Z3_get_datatype_sort_num_constructors(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_datatype_sort_constructor( - value _v_c, - value _v_t, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int idx; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_datatype_sort_constructor(c, t, idx); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_datatype_sort_recognizer( - value _v_c, - value _v_t, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int idx; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_datatype_sort_recognizer(c, t, idx); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_datatype_sort_constructor_accessor( - value _v_c, - value _v_t, - value _v_idx_c, - value _v_idx_a) -{ - Z3_context c; /*in*/ - Z3_sort t; /*in*/ - unsigned int idx_c; /*in*/ - unsigned int idx_a; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_t, &t, _ctx); - idx_c = Int_val(_v_idx_c); - idx_a = Int_val(_v_idx_a); - _res = Z3_get_datatype_sort_constructor_accessor(c, t, idx_c, idx_a); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_relation_arity( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_get_relation_arity(c, s); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_relation_column( - value _v_c, - value _v_s, - value _v_col) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - unsigned int col; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s, &s, _ctx); - col = Int_val(_v_col); - _res = Z3_get_relation_column(c, s, col); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_func_decl_to_ast( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_func_decl f; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_f, &f, _ctx); - _res = Z3_func_decl_to_ast(c, f); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_is_eq_func_decl( - value _v_c, - value _v_f1, - value _v_f2) -{ - Z3_context c; /*in*/ - Z3_func_decl f1; /*in*/ - Z3_func_decl f2; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_f1, &f1, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_f2, &f2, _ctx); - _res = Z3_is_eq_func_decl(c, f1, f2); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_func_decl_id( - value _v_c, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_func_decl f; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_f, &f, _ctx); - _res = Z3_get_func_decl_id(c, f); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_name( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_decl_name(c, d); - _vres = camlidl_c2ml_z3V3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_kind( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - Z3_decl_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_decl_kind(c, d); - _vres = camlidl_c2ml_z3V3_Z3_decl_kind(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_domain_size( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_domain_size(c, d); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_arity( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_arity(c, d); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_domain( - value _v_c, - value _v_d, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int i; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - i = Int_val(_v_i); - _res = Z3_get_domain(c, d, i); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_range( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_range(c, d); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_num_parameters( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_get_decl_num_parameters(c, d); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_parameter_kind( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_parameter_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_parameter_kind(c, d, idx); - _vres = camlidl_c2ml_z3V3_Z3_parameter_kind(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_int_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_int_parameter(c, d, idx); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_double_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - double _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_double_parameter(c, d, idx); - _vres = copy_double(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_symbol_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_symbol_parameter(c, d, idx); - _vres = camlidl_c2ml_z3V3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_sort_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_sort_parameter(c, d, idx); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_ast_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_ast_parameter(c, d, idx); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_func_decl_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_func_decl_parameter(c, d, idx); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_decl_rational_parameter( - value _v_c, - value _v_d, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int idx; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_decl_rational_parameter(c, d, idx); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_app_to_ast( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_app a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_app(_v_a, &a, _ctx); - _res = Z3_app_to_ast(c, a); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_app_decl( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_app a; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_app(_v_a, &a, _ctx); - _res = Z3_get_app_decl(c, a); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_app_num_args( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_app a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_app(_v_a, &a, _ctx); - _res = Z3_get_app_num_args(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_app_arg( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_app a; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_app(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_app_arg(c, a, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_is_eq_ast( - value _v_c, - value _v_t1, - value _v_t2) -{ - Z3_context c; /*in*/ - Z3_ast t1; /*in*/ - Z3_ast t2; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t1, &t1, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t2, &t2, _ctx); - _res = Z3_is_eq_ast(c, t1, t2); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_ast_id( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_ast t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t, &t, _ctx); - _res = Z3_get_ast_id(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_ast_hash( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_ast_hash(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_sort( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_sort(c, a); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_is_well_sorted( - value _v_c, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_ast t; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t, &t, _ctx); - _res = Z3_is_well_sorted(c, t); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_bool_value( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_lbool _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_bool_value(c, a); - _vres = camlidl_c2ml_z3V3_Z3_lbool(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_ast_kind( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast_kind _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_ast_kind(c, a); - _vres = camlidl_c2ml_z3V3_Z3_ast_kind(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_is_app( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_app(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_is_numeral_ast( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_numeral_ast(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_is_algebraic_number( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_algebraic_number(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_to_app( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_app _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_to_app(c, a); - _vres = camlidl_c2ml_z3V3_Z3_app(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_to_func_decl( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_to_func_decl(c, a); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_numeral_string( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_numeral_string(c, a); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_numeral_decimal_string( - value _v_c, - value _v_a, - value _v_precision) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int precision; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - precision = Int_val(_v_precision); - _res = Z3_get_numeral_decimal_string(c, a, precision); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_numerator( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_numerator(c, a); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_denominator( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_denominator(c, a); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_numeral_small( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - long long *num; /*out*/ - long long *den; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - long long _c1; - long long _c2; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - num = &_c1; - den = &_c2; - _res = Z3_get_numeral_small(c, a, num, den); - Begin_roots_block(_vres, 3) - _vres[0] = Val_int(_res); - _vres[1] = copy_int64(*num); - _vres[2] = copy_int64(*den); - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_get_numeral_int( - value _v_c, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast v; /*in*/ - int *i; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - int _c1; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_v, &v, _ctx); - i = &_c1; - _res = Z3_get_numeral_int(c, v, i); - Begin_roots_block(_vres, 2) - _vres[0] = Val_int(_res); - _vres[1] = Val_int(*i); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_get_numeral_int64( - value _v_c, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast v; /*in*/ - long long *i; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - long long _c1; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_v, &v, _ctx); - i = &_c1; - _res = Z3_get_numeral_int64(c, v, i); - Begin_roots_block(_vres, 2) - _vres[0] = Val_int(_res); - _vres[1] = copy_int64(*i); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_get_numeral_rational_int64( - value _v_c, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_ast v; /*in*/ - long long *num; /*out*/ - long long *den; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - long long _c1; - long long _c2; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_v, &v, _ctx); - num = &_c1; - den = &_c2; - _res = Z3_get_numeral_rational_int64(c, v, num, den); - Begin_roots_block(_vres, 3) - _vres[0] = Val_int(_res); - _vres[1] = copy_int64(*num); - _vres[2] = copy_int64(*den); - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_get_algebraic_number_lower( - value _v_c, - value _v_a, - value _v_precision) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int precision; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - precision = Int_val(_v_precision); - _res = Z3_get_algebraic_number_lower(c, a, precision); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_algebraic_number_upper( - value _v_c, - value _v_a, - value _v_precision) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int precision; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - precision = Int_val(_v_precision); - _res = Z3_get_algebraic_number_upper(c, a, precision); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_pattern_to_ast( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_pattern p; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_pattern(_v_p, &p, _ctx); - _res = Z3_pattern_to_ast(c, p); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_pattern_num_terms( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_pattern p; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_pattern(_v_p, &p, _ctx); - _res = Z3_get_pattern_num_terms(c, p); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_pattern( - value _v_c, - value _v_p, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_pattern p; /*in*/ - unsigned int idx; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_pattern(_v_p, &p, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_pattern(c, p, idx); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_index_value( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_index_value(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_is_quantifier_forall( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_is_quantifier_forall(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_weight( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_weight(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_num_patterns( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_num_patterns(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_pattern_ast( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int i; /*in*/ - Z3_pattern _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_quantifier_pattern_ast(c, a, i); - _vres = camlidl_c2ml_z3V3_Z3_pattern(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_num_no_patterns( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_num_no_patterns(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_no_pattern_ast( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_quantifier_no_pattern_ast(c, a, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_num_bound( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_num_bound(c, a); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_bound_name( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int i; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_quantifier_bound_name(c, a, i); - _vres = camlidl_c2ml_z3V3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_bound_sort( - value _v_c, - value _v_a, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int i; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - i = Int_val(_v_i); - _res = Z3_get_quantifier_bound_sort(c, a, i); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_quantifier_body( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_get_quantifier_body(c, a); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_simplify( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_simplify(c, a); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_update_term( - value _v_c, - value _v_a, - value _v_args) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - _res = Z3_update_term(c, a, num_args, args); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_substitute( - value _v_c, - value _v_a, - value _v_from, - value _v_to) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int num_exprs; /*in*/ - Z3_ast const *from; /*in*/ - Z3_ast const *to; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _c1 = Wosize_val(_v_from); - from = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_from, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &from[_c2], _ctx); - } - num_exprs = _c1; - _c4 = Wosize_val(_v_to); - to = camlidl_malloc(_c4 * sizeof(Z3_ast const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_to, _c5); - camlidl_ml2c_z3V3_Z3_ast(_v6, &to[_c5], _ctx); - } - num_exprs = _c4; - _res = Z3_substitute(c, a, num_exprs, from, to); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_substitute_vars( - value _v_c, - value _v_a, - value _v_to) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int num_exprs; /*in*/ - Z3_ast const *to; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _c1 = Wosize_val(_v_to); - to = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_to, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &to[_c2], _ctx); - } - num_exprs = _c1; - _res = Z3_substitute_vars(c, a, num_exprs, to); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_open_log( - value _v_filename) -{ - Z3_string filename; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_string(_v_filename, &filename, _ctx); - _res = Z3_open_log(filename); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_append_log( - value _v_string) -{ - Z3_string string; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_string(_v_string, &string, _ctx); - Z3_append_log(string); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_close_log(value _unit) -{ - Z3_close_log(); - return Val_unit; -} - -value camlidl_z3V3_Z3_toggle_warning_messages( - value _v_enabled) -{ - int enabled; /*in*/ - enabled = Int_val(_v_enabled); - Z3_toggle_warning_messages(enabled); - return Val_unit; -} - -value camlidl_z3V3_Z3_set_ast_print_mode( - value _v_c, - value _v_mode) -{ - Z3_context c; /*in*/ - Z3_ast_print_mode mode; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast_print_mode(_v_mode, &mode, _ctx); - Z3_set_ast_print_mode(c, mode); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_ast_to_string( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - _res = Z3_ast_to_string(c, a); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_pattern_to_string( - value _v_c, - value _v_p) -{ - Z3_context c; /*in*/ - Z3_pattern p; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_pattern(_v_p, &p, _ctx); - _res = Z3_pattern_to_string(c, p); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_sort_to_string( - value _v_c, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_sort s; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_sort_to_string(c, s); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_func_decl_to_string( - value _v_c, - value _v_d) -{ - Z3_context c; /*in*/ - Z3_func_decl d; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_func_decl_to_string(c, d); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_model_to_string( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - _res = Z3_model_to_string(c, m); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_benchmark_to_smtlib_string( - value _v_c, - value _v_name, - value _v_logic, - value _v_status, - value _v_attributes, - value _v_assumptions, - value _v_formula) -{ - Z3_context c; /*in*/ - Z3_string name; /*in*/ - Z3_string logic; /*in*/ - Z3_string status; /*in*/ - Z3_string attributes; /*in*/ - unsigned int num_assumptions; /*in*/ - Z3_ast const *assumptions; /*in*/ - Z3_ast formula; /*in*/ - Z3_string _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_name, &name, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_logic, &logic, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_status, &status, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_attributes, &attributes, _ctx); - _c1 = Wosize_val(_v_assumptions); - assumptions = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_assumptions, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &assumptions[_c2], _ctx); - } - num_assumptions = _c1; - camlidl_ml2c_z3V3_Z3_ast(_v_formula, &formula, _ctx); - _res = Z3_benchmark_to_smtlib_string(c, name, logic, status, attributes, num_assumptions, assumptions, formula); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_benchmark_to_smtlib_string_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_benchmark_to_smtlib_string(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]); -} - -value camlidl_z3V3_Z3_parse_smtlib2_string( - value _v_c, - value _v_str, - value _v_sort_names, - value _v_sorts, - value _v_decl_names, - value _v_decls) -{ - Z3_context c; /*in*/ - Z3_string str; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int num_decls; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_func_decl const *decls; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_str, &str, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3V3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_sorts = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3V3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decls); - decls = camlidl_malloc(_c10 * sizeof(Z3_func_decl const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decls, _c11); - camlidl_ml2c_z3V3_Z3_func_decl(_v12, &decls[_c11], _ctx); - } - num_decls = _c10; - _res = Z3_parse_smtlib2_string(c, str, num_sorts, sort_names, sorts, num_decls, decl_names, decls); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_parse_smtlib2_string_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_parse_smtlib2_string(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3V3_Z3_parse_smtlib2_file( - value _v_c, - value _v_file_name, - value _v_sort_names, - value _v_sorts, - value _v_decl_names, - value _v_decls) -{ - Z3_context c; /*in*/ - Z3_string file_name; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int num_decls; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_func_decl const *decls; /*in*/ - Z3_ast _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_file_name, &file_name, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3V3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_sorts = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3V3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decls); - decls = camlidl_malloc(_c10 * sizeof(Z3_func_decl const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decls, _c11); - camlidl_ml2c_z3V3_Z3_func_decl(_v12, &decls[_c11], _ctx); - } - num_decls = _c10; - _res = Z3_parse_smtlib2_file(c, file_name, num_sorts, sort_names, sorts, num_decls, decl_names, decls); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_parse_smtlib2_file_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_parse_smtlib2_file(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3V3_Z3_parse_smtlib_string( - value _v_c, - value _v_str, - value _v_sort_names, - value _v_sorts, - value _v_decl_names, - value _v_decls) -{ - Z3_context c; /*in*/ - Z3_string str; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int num_decls; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_func_decl const *decls; /*in*/ - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_str, &str, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3V3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_sorts = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3V3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decls); - decls = camlidl_malloc(_c10 * sizeof(Z3_func_decl const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decls, _c11); - camlidl_ml2c_z3V3_Z3_func_decl(_v12, &decls[_c11], _ctx); - } - num_decls = _c10; - Z3_parse_smtlib_string(c, str, num_sorts, sort_names, sorts, num_decls, decl_names, decls); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_parse_smtlib_string_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_parse_smtlib_string(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3V3_Z3_parse_smtlib_file( - value _v_c, - value _v_file_name, - value _v_sort_names, - value _v_sorts, - value _v_decl_names, - value _v_decls) -{ - Z3_context c; /*in*/ - Z3_string file_name; /*in*/ - unsigned int num_sorts; /*in*/ - Z3_symbol const *sort_names; /*in*/ - Z3_sort const *sorts; /*in*/ - unsigned int num_decls; /*in*/ - Z3_symbol const *decl_names; /*in*/ - Z3_func_decl const *decls; /*in*/ - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - mlsize_t _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - mlsize_t _c11; - value _v12; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_file_name, &file_name, _ctx); - _c1 = Wosize_val(_v_sort_names); - sort_names = camlidl_malloc(_c1 * sizeof(Z3_symbol const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_sort_names, _c2); - camlidl_ml2c_z3V3_Z3_symbol(_v3, &sort_names[_c2], _ctx); - } - num_sorts = _c1; - _c4 = Wosize_val(_v_sorts); - sorts = camlidl_malloc(_c4 * sizeof(Z3_sort const ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_sorts, _c5); - camlidl_ml2c_z3V3_Z3_sort(_v6, &sorts[_c5], _ctx); - } - num_sorts = _c4; - _c7 = Wosize_val(_v_decl_names); - decl_names = camlidl_malloc(_c7 * sizeof(Z3_symbol const ), _ctx); - for (_c8 = 0; _c8 < _c7; _c8++) { - _v9 = Field(_v_decl_names, _c8); - camlidl_ml2c_z3V3_Z3_symbol(_v9, &decl_names[_c8], _ctx); - } - num_decls = _c7; - _c10 = Wosize_val(_v_decls); - decls = camlidl_malloc(_c10 * sizeof(Z3_func_decl const ), _ctx); - for (_c11 = 0; _c11 < _c10; _c11++) { - _v12 = Field(_v_decls, _c11); - camlidl_ml2c_z3V3_Z3_func_decl(_v12, &decls[_c11], _ctx); - } - num_decls = _c10; - Z3_parse_smtlib_file(c, file_name, num_sorts, sort_names, sorts, num_decls, decl_names, decls); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_parse_smtlib_file_bytecode(value * argv, int argn) -{ - return camlidl_z3V3_Z3_parse_smtlib_file(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); -} - -value camlidl_z3V3_Z3_get_smtlib_num_formulas( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_num_formulas(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_smtlib_formula( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_smtlib_formula(c, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_smtlib_num_assumptions( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_num_assumptions(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_smtlib_assumption( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_smtlib_assumption(c, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_smtlib_num_decls( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_num_decls(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_smtlib_decl( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_smtlib_decl(c, i); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_smtlib_num_sorts( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_num_sorts(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_smtlib_sort( - value _v_c, - value _v_i) -{ - Z3_context c; /*in*/ - unsigned int i; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - i = Int_val(_v_i); - _res = Z3_get_smtlib_sort(c, i); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_smtlib_error( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_smtlib_error(c); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_version(value _unit) -{ - unsigned int *major; /*out*/ - unsigned int *minor; /*out*/ - unsigned int *build_number; /*out*/ - unsigned int *revision_number; /*out*/ - unsigned int _c1; - unsigned int _c2; - unsigned int _c3; - unsigned int _c4; - value _vresult; - value _vres[4] = { 0, 0, 0, 0, }; - - major = &_c1; - minor = &_c2; - build_number = &_c3; - revision_number = &_c4; - Z3_get_version(major, minor, build_number, revision_number); - Begin_roots_block(_vres, 4) - _vres[0] = Val_int(*major); - _vres[1] = Val_int(*minor); - _vres[2] = Val_int(*build_number); - _vres[3] = Val_int(*revision_number); - _vresult = camlidl_alloc_small(4, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - Field(_vresult, 3) = _vres[3]; - End_roots() - return _vresult; -} - -value camlidl_z3V3_Z3_enable_trace( - value _v_tag) -{ - Z3_string tag; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_string(_v_tag, &tag, _ctx); - Z3_enable_trace(tag); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_disable_trace( - value _v_tag) -{ - Z3_string tag; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_string(_v_tag, &tag, _ctx); - Z3_disable_trace(tag); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_reset_memory(value _unit) -{ - Z3_reset_memory(); - return Val_unit; -} - -value camlidl_z3V3_Z3_theory_mk_sort( - value _v_c, - value _v_t, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_theory t; /*in*/ - Z3_symbol s; /*in*/ - Z3_sort _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - _res = Z3_theory_mk_sort(c, t, s); - _vres = camlidl_c2ml_z3V3_Z3_sort(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_mk_value( - value _v_c, - value _v_t, - value _v_n, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_theory t; /*in*/ - Z3_symbol n; /*in*/ - Z3_sort s; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_n, &n, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_theory_mk_value(c, t, n, s); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_mk_constant( - value _v_c, - value _v_t, - value _v_n, - value _v_s) -{ - Z3_context c; /*in*/ - Z3_theory t; /*in*/ - Z3_symbol n; /*in*/ - Z3_sort s; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_n, &n, _ctx); - camlidl_ml2c_z3V3_Z3_sort(_v_s, &s, _ctx); - _res = Z3_theory_mk_constant(c, t, n, s); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_mk_func_decl( - value _v_c, - value _v_t, - value _v_n, - value _v_domain, - value _v_range) -{ - Z3_context c; /*in*/ - Z3_theory t; /*in*/ - Z3_symbol n; /*in*/ - unsigned int domain_size; /*in*/ - Z3_sort const *domain; /*in*/ - Z3_sort range; /*in*/ - Z3_func_decl _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_n, &n, _ctx); - _c1 = Wosize_val(_v_domain); - domain = camlidl_malloc(_c1 * sizeof(Z3_sort const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_domain, _c2); - camlidl_ml2c_z3V3_Z3_sort(_v3, &domain[_c2], _ctx); - } - domain_size = _c1; - camlidl_ml2c_z3V3_Z3_sort(_v_range, &range, _ctx); - _res = Z3_theory_mk_func_decl(c, t, n, domain_size, domain, range); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_get_context( - value _v_t) -{ - Z3_theory t; /*in*/ - Z3_context _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - _res = Z3_theory_get_context(t); - _vres = camlidl_c2ml_z3V3_Z3_context(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_assert_axiom( - value _v_t, - value _v_ax) -{ - Z3_theory t; /*in*/ - Z3_ast ax; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_ax, &ax, _ctx); - Z3_theory_assert_axiom(t, ax); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_theory_assume_eq( - value _v_t, - value _v_lhs, - value _v_rhs) -{ - Z3_theory t; /*in*/ - Z3_ast lhs; /*in*/ - Z3_ast rhs; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_lhs, &lhs, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_rhs, &rhs, _ctx); - Z3_theory_assume_eq(t, lhs, rhs); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_theory_enable_axiom_simplification( - value _v_t, - value _v_flag) -{ - Z3_theory t; /*in*/ - int flag; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - flag = Int_val(_v_flag); - Z3_theory_enable_axiom_simplification(t, flag); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_theory_get_eqc_root( - value _v_t, - value _v_n) -{ - Z3_theory t; /*in*/ - Z3_ast n; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_n, &n, _ctx); - _res = Z3_theory_get_eqc_root(t, n); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_get_eqc_next( - value _v_t, - value _v_n) -{ - Z3_theory t; /*in*/ - Z3_ast n; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_n, &n, _ctx); - _res = Z3_theory_get_eqc_next(t, n); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_get_num_parents( - value _v_t, - value _v_n) -{ - Z3_theory t; /*in*/ - Z3_ast n; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_n, &n, _ctx); - _res = Z3_theory_get_num_parents(t, n); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_get_parent( - value _v_t, - value _v_n, - value _v_i) -{ - Z3_theory t; /*in*/ - Z3_ast n; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_n, &n, _ctx); - i = Int_val(_v_i); - _res = Z3_theory_get_parent(t, n, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_is_value( - value _v_t, - value _v_n) -{ - Z3_theory t; /*in*/ - Z3_ast n; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_n, &n, _ctx); - _res = Z3_theory_is_value(t, n); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_is_decl( - value _v_t, - value _v_d) -{ - Z3_theory t; /*in*/ - Z3_func_decl d; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _res = Z3_theory_is_decl(t, d); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_get_num_elems( - value _v_t) -{ - Z3_theory t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - _res = Z3_theory_get_num_elems(t); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_get_elem( - value _v_t, - value _v_i) -{ - Z3_theory t; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - i = Int_val(_v_i); - _res = Z3_theory_get_elem(t, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_get_num_apps( - value _v_t) -{ - Z3_theory t; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - _res = Z3_theory_get_num_apps(t); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_theory_get_app( - value _v_t, - value _v_i) -{ - Z3_theory t; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_theory(_v_t, &t, _ctx); - i = Int_val(_v_i); - _res = Z3_theory_get_app(t, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_injective_function( - value _v_c, - value _v_s, - value _v_domain, - value _v_range) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - unsigned int domain_size; /*in*/ - Z3_sort const *domain; /*in*/ - Z3_sort range; /*in*/ - Z3_func_decl _res; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - _c1 = Wosize_val(_v_domain); - domain = camlidl_malloc(_c1 * sizeof(Z3_sort const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_domain, _c2); - camlidl_ml2c_z3V3_Z3_sort(_v3, &domain[_c2], _ctx); - } - domain_size = _c1; - camlidl_ml2c_z3V3_Z3_sort(_v_range, &range, _ctx); - _res = Z3_mk_injective_function(c, s, domain_size, domain, range); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_set_logic( - value _v_c, - value _v_logic) -{ - Z3_context c; /*in*/ - Z3_string logic; /*in*/ - int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_string(_v_logic, &logic, _ctx); - _res = Z3_set_logic(c, logic); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_push( - value _v_c) -{ - Z3_context c; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - Z3_push(c); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_pop( - value _v_c, - value _v_num_scopes) -{ - Z3_context c; /*in*/ - unsigned int num_scopes; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - num_scopes = Int_val(_v_num_scopes); - Z3_pop(c, num_scopes); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_get_num_scopes( - value _v_c) -{ - Z3_context c; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_num_scopes(c); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_persist_ast( - value _v_c, - value _v_a, - value _v_num_scopes) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - unsigned int num_scopes; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - num_scopes = Int_val(_v_num_scopes); - Z3_persist_ast(c, a, num_scopes); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_assert_cnstr( - value _v_c, - value _v_a) -{ - Z3_context c; /*in*/ - Z3_ast a; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_a, &a, _ctx); - Z3_assert_cnstr(c, a); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_check_and_get_model( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_model *m; /*out*/ - Z3_lbool _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - Z3_model _c1; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - m = &_c1; - _res = Z3_check_and_get_model(c, m); - Begin_roots_block(_vres, 2) - _vres[0] = camlidl_c2ml_z3V3_Z3_lbool(&_res, _ctx); - _vres[1] = camlidl_c2ml_z3V3_Z3_model(&*m, _ctx); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_check( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_lbool _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_check(c); - _vres = camlidl_c2ml_z3V3_Z3_lbool(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_check_assumptions( - value _v_c, - value _v_assumptions, - value _v_core_size, - value _v_core) -{ - Z3_context c; /*in*/ - unsigned int num_assumptions; /*in*/ - Z3_ast const *assumptions; /*in*/ - Z3_model *m; /*out*/ - Z3_ast *proof; /*out*/ - unsigned int *core_size; /*in,out*/ - Z3_ast *core; /*in,out*/ - Z3_lbool _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - unsigned int _c4; - mlsize_t _c5; - mlsize_t _c6; - value _v7; - Z3_model _c8; - Z3_ast _c9; - mlsize_t _c10; - value _v11; - value _vresult; - value _vres[5] = { 0, 0, 0, 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _c1 = Wosize_val(_v_assumptions); - assumptions = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_assumptions, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &assumptions[_c2], _ctx); - } - num_assumptions = _c1; - core_size = &_c4; - _c4 = Int_val(_v_core_size); - _c5 = Wosize_val(_v_core); - core = camlidl_malloc(_c5 * sizeof(Z3_ast ), _ctx); - for (_c6 = 0; _c6 < _c5; _c6++) { - _v7 = Field(_v_core, _c6); - camlidl_ml2c_z3V3_Z3_ast(_v7, &core[_c6], _ctx); - } - num_assumptions = _c5; - m = &_c8; - proof = &_c9; - _res = Z3_check_assumptions(c, num_assumptions, assumptions, m, proof, core_size, core); - Begin_roots_block(_vres, 5) - _vres[0] = camlidl_c2ml_z3V3_Z3_lbool(&_res, _ctx); - _vres[1] = camlidl_c2ml_z3V3_Z3_model(&*m, _ctx); - _vres[2] = camlidl_c2ml_z3V3_Z3_ast(&*proof, _ctx); - _vres[3] = Val_int(*core_size); - _vres[4] = camlidl_alloc(num_assumptions, 0); - Begin_root(_vres[4]) - for (_c10 = 0; _c10 < num_assumptions; _c10++) { - _v11 = camlidl_c2ml_z3V3_Z3_ast(&core[_c10], _ctx); - modify(&Field(_vres[4], _c10), _v11); - } - End_roots() - _vresult = camlidl_alloc_small(5, 0); - { mlsize_t _c12; - for (_c12 = 0; _c12 < 5; _c12++) Field(_vresult, _c12) = _vres[_c12]; - } - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_del_model( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - Z3_del_model(c, m); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_soft_check_cancel( - value _v_c) -{ - Z3_context c; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - Z3_soft_check_cancel(c); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_get_search_failure( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_search_failure _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_search_failure(c); - _vres = camlidl_c2ml_z3V3_Z3_search_failure(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_mk_label( - value _v_c, - value _v_s, - value _v_is_pos, - value _v_f) -{ - Z3_context c; /*in*/ - Z3_symbol s; /*in*/ - int is_pos; /*in*/ - Z3_ast f; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_symbol(_v_s, &s, _ctx); - is_pos = Int_val(_v_is_pos); - camlidl_ml2c_z3V3_Z3_ast(_v_f, &f, _ctx); - _res = Z3_mk_label(c, s, is_pos, f); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_relevant_labels( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_literals _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_relevant_labels(c); - _vres = camlidl_c2ml_z3V3_Z3_literals(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_relevant_literals( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_literals _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_relevant_literals(c); - _vres = camlidl_c2ml_z3V3_Z3_literals(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_guessed_literals( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_literals _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_guessed_literals(c); - _vres = camlidl_c2ml_z3V3_Z3_literals(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_del_literals( - value _v_c, - value _v_lbls) -{ - Z3_context c; /*in*/ - Z3_literals lbls; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_literals(_v_lbls, &lbls, _ctx); - Z3_del_literals(c, lbls); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_get_num_literals( - value _v_c, - value _v_lbls) -{ - Z3_context c; /*in*/ - Z3_literals lbls; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_literals(_v_lbls, &lbls, _ctx); - _res = Z3_get_num_literals(c, lbls); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_label_symbol( - value _v_c, - value _v_lbls, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_literals lbls; /*in*/ - unsigned int idx; /*in*/ - Z3_symbol _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_literals(_v_lbls, &lbls, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_label_symbol(c, lbls, idx); - _vres = camlidl_c2ml_z3V3_Z3_symbol(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_literal( - value _v_c, - value _v_lbls, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_literals lbls; /*in*/ - unsigned int idx; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_literals(_v_lbls, &lbls, _ctx); - idx = Int_val(_v_idx); - _res = Z3_get_literal(c, lbls, idx); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_disable_literal( - value _v_c, - value _v_lbls, - value _v_idx) -{ - Z3_context c; /*in*/ - Z3_literals lbls; /*in*/ - unsigned int idx; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_literals(_v_lbls, &lbls, _ctx); - idx = Int_val(_v_idx); - Z3_disable_literal(c, lbls, idx); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_block_literals( - value _v_c, - value _v_lbls) -{ - Z3_context c; /*in*/ - Z3_literals lbls; /*in*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_literals(_v_lbls, &lbls, _ctx); - Z3_block_literals(c, lbls); - camlidl_free(_ctx); - return Val_unit; -} - -value camlidl_z3V3_Z3_get_model_num_constants( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - _res = Z3_get_model_num_constants(c, m); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_model_constant( - value _v_c, - value _v_m, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - _res = Z3_get_model_constant(c, m, i); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_model_num_funcs( - value _v_c, - value _v_m) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - _res = Z3_get_model_num_funcs(c, m); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_model_func_decl( - value _v_c, - value _v_m, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - Z3_func_decl _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - _res = Z3_get_model_func_decl(c, m, i); - _vres = camlidl_c2ml_z3V3_Z3_func_decl(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_eval_func_decl( - value _v_c, - value _v_m, - value _v_decl) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_func_decl decl; /*in*/ - Z3_ast *v; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - Z3_ast _c1; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_decl, &decl, _ctx); - v = &_c1; - _res = Z3_eval_func_decl(c, m, decl, v); - Begin_roots_block(_vres, 2) - _vres[0] = Val_int(_res); - _vres[1] = camlidl_c2ml_z3V3_Z3_ast(&*v, _ctx); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_is_array_value( - value _v_c, - value _v_m, - value _v_v) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_ast v; /*in*/ - unsigned int *num_entries; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - unsigned int _c1; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_v, &v, _ctx); - num_entries = &_c1; - _res = Z3_is_array_value(c, m, v, num_entries); - Begin_roots_block(_vres, 2) - _vres[0] = Val_int(_res); - _vres[1] = Val_int(*num_entries); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_get_array_value( - value _v_c, - value _v_m, - value _v_v, - value _v_indices, - value _v_values) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_ast v; /*in*/ - unsigned int num_entries; /*in*/ - Z3_ast *indices; /*in,out*/ - Z3_ast *values; /*in,out*/ - Z3_ast *else_value; /*out*/ - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - mlsize_t _c4; - mlsize_t _c5; - value _v6; - Z3_ast _c7; - mlsize_t _c8; - value _v9; - mlsize_t _c10; - value _v11; - value _vresult; - value _vres[3] = { 0, 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_v, &v, _ctx); - _c1 = Wosize_val(_v_indices); - indices = camlidl_malloc(_c1 * sizeof(Z3_ast ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_indices, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &indices[_c2], _ctx); - } - num_entries = _c1; - _c4 = Wosize_val(_v_values); - values = camlidl_malloc(_c4 * sizeof(Z3_ast ), _ctx); - for (_c5 = 0; _c5 < _c4; _c5++) { - _v6 = Field(_v_values, _c5); - camlidl_ml2c_z3V3_Z3_ast(_v6, &values[_c5], _ctx); - } - num_entries = _c4; - else_value = &_c7; - Z3_get_array_value(c, m, v, num_entries, indices, values, else_value); - Begin_roots_block(_vres, 3) - _vres[0] = camlidl_alloc(num_entries, 0); - Begin_root(_vres[0]) - for (_c8 = 0; _c8 < num_entries; _c8++) { - _v9 = camlidl_c2ml_z3V3_Z3_ast(&indices[_c8], _ctx); - modify(&Field(_vres[0], _c8), _v9); - } - End_roots() - _vres[1] = camlidl_alloc(num_entries, 0); - Begin_root(_vres[1]) - for (_c10 = 0; _c10 < num_entries; _c10++) { - _v11 = camlidl_c2ml_z3V3_Z3_ast(&values[_c10], _ctx); - modify(&Field(_vres[1], _c10), _v11); - } - End_roots() - _vres[2] = camlidl_c2ml_z3V3_Z3_ast(&*else_value, _ctx); - _vresult = camlidl_alloc_small(3, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - Field(_vresult, 2) = _vres[2]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_get_model_func_else( - value _v_c, - value _v_m, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - _res = Z3_get_model_func_else(c, m, i); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_model_func_num_entries( - value _v_c, - value _v_m, - value _v_i) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - _res = Z3_get_model_func_num_entries(c, m, i); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_model_func_entry_num_args( - value _v_c, - value _v_m, - value _v_i, - value _v_j) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - unsigned int j; /*in*/ - unsigned int _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - j = Int_val(_v_j); - _res = Z3_get_model_func_entry_num_args(c, m, i, j); - _vres = Val_int(_res); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_model_func_entry_arg( - value _v_c, - value _v_m, - value _v_i, - value _v_j, - value _v_k) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - unsigned int j; /*in*/ - unsigned int k; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - j = Int_val(_v_j); - k = Int_val(_v_k); - _res = Z3_get_model_func_entry_arg(c, m, i, j, k); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_model_func_entry_value( - value _v_c, - value _v_m, - value _v_i, - value _v_j) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - unsigned int i; /*in*/ - unsigned int j; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - i = Int_val(_v_i); - j = Int_val(_v_j); - _res = Z3_get_model_func_entry_value(c, m, i, j); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_eval( - value _v_c, - value _v_m, - value _v_t) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_ast t; /*in*/ - Z3_ast *v; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - Z3_ast _c1; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3V3_Z3_ast(_v_t, &t, _ctx); - v = &_c1; - _res = Z3_eval(c, m, t, v); - Begin_roots_block(_vres, 2) - _vres[0] = Val_int(_res); - _vres[1] = camlidl_c2ml_z3V3_Z3_ast(&*v, _ctx); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_eval_decl( - value _v_c, - value _v_m, - value _v_d, - value _v_args) -{ - Z3_context c; /*in*/ - Z3_model m; /*in*/ - Z3_func_decl d; /*in*/ - unsigned int num_args; /*in*/ - Z3_ast const *args; /*in*/ - Z3_ast *v; /*out*/ - int _res; - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - mlsize_t _c1; - mlsize_t _c2; - value _v3; - Z3_ast _c4; - value _vresult; - value _vres[2] = { 0, 0, }; - - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - camlidl_ml2c_z3V3_Z3_model(_v_m, &m, _ctx); - camlidl_ml2c_z3V3_Z3_func_decl(_v_d, &d, _ctx); - _c1 = Wosize_val(_v_args); - args = camlidl_malloc(_c1 * sizeof(Z3_ast const ), _ctx); - for (_c2 = 0; _c2 < _c1; _c2++) { - _v3 = Field(_v_args, _c2); - camlidl_ml2c_z3V3_Z3_ast(_v3, &args[_c2], _ctx); - } - num_args = _c1; - v = &_c4; - _res = Z3_eval_decl(c, m, d, num_args, args, v); - Begin_roots_block(_vres, 2) - _vres[0] = Val_int(_res); - _vres[1] = camlidl_c2ml_z3V3_Z3_ast(&*v, _ctx); - _vresult = camlidl_alloc_small(2, 0); - Field(_vresult, 0) = _vres[0]; - Field(_vresult, 1) = _vres[1]; - End_roots() - camlidl_free(_ctx); - return _vresult; -} - -value camlidl_z3V3_Z3_context_to_string( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_context_to_string(c); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_statistics_to_string( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_string _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_statistics_to_string(c); - _vres = camlidl_c2ml_z3V3_Z3_string(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - -value camlidl_z3V3_Z3_get_context_assignment( - value _v_c) -{ - Z3_context c; /*in*/ - Z3_ast _res; - value _vres; - - struct camlidl_ctx_struct _ctxs = { CAMLIDL_TRANSIENT, NULL }; - camlidl_ctx _ctx = &_ctxs; - camlidl_ml2c_z3V3_Z3_context(_v_c, &c, _ctx); - _res = Z3_get_context_assignment(c); - _vres = camlidl_c2ml_z3V3_Z3_ast(&_res, _ctx); - camlidl_free(_ctx); - return _vres; -} - diff --git a/src/api/ml/old/z3_theory_stubs.c b/src/api/ml/old/z3_theory_stubs.c deleted file mode 100644 index a48b94553..000000000 --- a/src/api/ml/old/z3_theory_stubs.c +++ /dev/null @@ -1,339 +0,0 @@ -/*++ -Copyright (c) Microsoft Corporation - -Module Name: - - z3_theory_stubs.c - -Abstract: - - OCaml C bindings for callbacks between OCaml and C for - theory plugins. - The API for theory plugins require associating a set of - callbacks as C function pointers. - We use the following strategy: - - - store in the user_ext_data blob that theory constructors allow - a record of callback functions. - - - define catch-all static callback functions that access the - ML record with the callbacks. It then invokes these through user-registered - application functions that apply the callback stored in the record to the - actual parameters. - It is tempting to avoid this user-registered callback and directly access - the record of callback functions and apply the proper field. - However, the layout of records appears to be opaque, or at least we assume it is - so, from the C runtime. - -Author: - - -Revision History: ---*/ - -#include -#include -#include -#include -#include -#include -#include -#ifdef Custom_tag -#include -#include -#endif - -#include "z3.h" - -#define ML_SIZE(_ty) ((sizeof(_ty) + sizeof(value) - 1)/ sizeof(value)) - -static value mk_func_decl(Z3_func_decl f) { - value _f = alloc(ML_SIZE(Z3_func_decl), Abstract_tag); - *((Z3_func_decl*) Bp_val(_f)) = f; - return _f; -} - -static value Val_ast(Z3_ast a) { - value _a = alloc(ML_SIZE(Z3_ast), Abstract_tag); - *((Z3_ast*) Bp_val(_a)) = a; - return _a; -} - - -static value Val_ast_array(unsigned int sz, Z3_ast const args[]) { - value res; - Z3_ast* args1; - unsigned int i; - args1 = malloc((sz+1)*sizeof(Z3_ast)); - for (i = 0; i < sz; ++i) { - args1[i] = args[i]; - } - args1[sz] = 0; - res = alloc_array((value (*)(char const*))Val_ast, (const char**)args1); - free(args1); - return res; -} - -// ------------------ -// get_theory_callbacks -// - -value get_theory_callbacks(value th) -{ - Z3_theory _th = *((Z3_theory*) Bp_val(th)); - return (value) Z3_theory_get_ext_data(_th); -} - -// ------------------ -// delete_theory -// -static void delete_callback_static(Z3_theory th) -{ - CAMLparam0(); - CAMLlocal1(f); - value user_data = (value) Z3_theory_get_ext_data(th); - f = *(caml_named_value("apply_delete")) ; - callback(f, user_data); - remove_global_root(&user_data); - CAMLreturn0; -} - -#define SET_CALLBACK(_cb_name) \ - value set_ ## _cb_name ## _callback_register(value th) \ - { \ - CAMLparam1(th); \ - Z3_theory _th = *((Z3_theory*) Bp_val(th)); \ - Z3_set_ ## _cb_name ## _callback(_th, _cb_name ## _callback_static); \ - CAMLreturn(Val_unit); \ - } \ - -SET_CALLBACK(delete); - - -// ------------------ -// mk_theory -// - -value mk_theory_register(value context, value name, value user_data) -{ - CAMLparam3(context, name, user_data); - Z3_context _context = *((Z3_context *) Bp_val(context)); - value _th; - Z3_theory th; - register_global_root(&user_data); - th = Z3_mk_theory(_context, String_val(name), (void*)user_data); - // jjb: test th == NULL ? - Z3_set_delete_callback(th, delete_callback_static); - _th = alloc(ML_SIZE(Z3_context), Abstract_tag); - *((Z3_theory*) Bp_val(_th)) = th; - CAMLreturn(_th); -} - - -// ------------------- -// reduce_app_callback - -static Z3_bool reduce_app_callback_static(Z3_theory th, Z3_func_decl f, unsigned num_args, Z3_ast const args[], Z3_ast* r) { - CAMLparam0(); - CAMLlocal4(cb, _r, _v, _args); - value user_data; - Z3_bool result; - - _args = Val_ast_array(num_args, args); - - user_data = (value) Z3_theory_get_ext_data(th); - - cb = *(caml_named_value("apply_reduce_app")); - _r = callback3(cb, user_data, mk_func_decl(f), _args); - - cb = *(caml_named_value("is_some")); - _v = callback(cb, _r); - result = 0 != Bool_val(_v); - - if (result && r) { - cb = *(caml_named_value("get_some")); - _v = callback(cb, _r); - *r = *((Z3_ast*) Bp_val(_v)); - } - - CAMLreturn (result); -} - -SET_CALLBACK(reduce_app); - -// ------------------- -// reduce_eq_callback - -static Z3_bool reduce_eq_callback_static(Z3_theory th, Z3_ast a, Z3_ast b, Z3_ast * r) -{ - CAMLparam0(); - CAMLlocal5(cb, _r, _a, _b, _v); - value user_data; - Z3_bool result; - - _a = Val_ast(a); - _b = Val_ast(b); - - user_data = (value) Z3_theory_get_ext_data(th); - - cb = *(caml_named_value("apply_reduce_eq")); - _r = callback3(cb, user_data, _a, _b); - - cb = *(caml_named_value("is_some")); - _v = callback(cb, _r); - result = 0 != Bool_val(_v); - - if (result && r) { - cb = *(caml_named_value("get_some")); - _v = callback(cb, _r); - *r = *((Z3_ast*) Bp_val(_v)); - } - - CAMLreturn (result); -} - -SET_CALLBACK(reduce_eq); - - -// ------------------- -// reduce_distinct - -static Z3_bool reduce_distinct_callback_static(Z3_theory th, unsigned n, Z3_ast const args[], Z3_ast * r) -{ - CAMLparam0(); - CAMLlocal4(cb, _r, _args, _v); - value user_data; - Z3_bool result; - - _args = Val_ast_array(n, args); - - user_data = (value) Z3_theory_get_ext_data(th); - - cb = *(caml_named_value("apply_reduce_distinct")); - _r = callback2(cb, user_data, _args); - - cb = *(caml_named_value("is_some")); - _v = callback(cb, _r); - result = 0 != Bool_val(_v); - - if (result && r) { - cb = *(caml_named_value("get_some")); - _v = callback(cb, _r); - *r = *((Z3_ast*) Bp_val(_v)); - } - - CAMLreturn (result); -} - -SET_CALLBACK(reduce_distinct); - -// ------------------- -// new_app - -#define AST_CALLBACK(_cb_name) \ -static void _cb_name##_callback_static(Z3_theory th, Z3_ast a) \ -{ \ - CAMLparam0(); \ - CAMLlocal3(cb, _a, user_data); \ - _a = Val_ast(a); \ - user_data = (value) Z3_theory_get_ext_data(th); \ - cb = *(caml_named_value("apply_" #_cb_name)); \ - callback2(cb, user_data, _a); \ - CAMLreturn0; \ -} \ - -AST_CALLBACK(new_app); -SET_CALLBACK(new_app); - -// ------------------- -// new_elem - -AST_CALLBACK(new_elem); -SET_CALLBACK(new_elem); - -// ------------------- -// init_search - -#define TH_CALLBACK(_cb_name) \ -static void _cb_name##_callback_static(Z3_theory th) \ -{ \ - CAMLparam0(); \ - CAMLlocal2(cb, user_data); \ - user_data = (value) Z3_theory_get_ext_data(th); \ - cb = *(caml_named_value("apply_" #_cb_name)); \ - callback(cb, user_data); \ - CAMLreturn0; \ -} \ - -TH_CALLBACK(init_search); -SET_CALLBACK(init_search); - -// ------------------- -// push - -TH_CALLBACK(push); -SET_CALLBACK(push); - -TH_CALLBACK(pop); -SET_CALLBACK(pop); - -TH_CALLBACK(restart); -SET_CALLBACK(restart); - -TH_CALLBACK(reset); -SET_CALLBACK(reset); - - -#define FC_CALLBACK(_cb_name) \ - static Z3_bool _cb_name##_callback_static(Z3_theory th) \ - { \ - CAMLparam0(); \ - CAMLlocal3(cb, r, user_data); \ - user_data = (value) Z3_theory_get_ext_data(th); \ - cb = *(caml_named_value("apply_" #_cb_name)); \ - r = callback(cb, user_data); \ - CAMLreturn (Bool_val(r) != 0); \ - } \ - -FC_CALLBACK(final_check); -SET_CALLBACK(final_check); - -#define AST_AST_CALLBACK(_cb_name) \ - static void _cb_name##_callback_static(Z3_theory th, Z3_ast a, Z3_ast b) \ - { \ - CAMLparam0(); \ - CAMLlocal4(cb, _a, _b, user_data); \ - _a = Val_ast(a); \ - _b = Val_ast(b); \ - user_data = (value) Z3_theory_get_ext_data(th); \ - cb = *(caml_named_value("apply_" #_cb_name)); \ - callback3(cb, user_data, _a, _b); \ - CAMLreturn0; \ - } \ - -AST_AST_CALLBACK(new_eq); -SET_CALLBACK(new_eq); - -AST_AST_CALLBACK(new_diseq); -SET_CALLBACK(new_diseq); - -#define AST_BOOL_CALLBACK(_cb_name) \ - static void _cb_name##_callback_static(Z3_theory th, Z3_ast a, Z3_bool b) \ - { \ - CAMLparam0(); \ - CAMLlocal4(cb, _a, _b, user_data); \ - _a = Val_ast(a); \ - _b = Val_bool(b); \ - user_data = (value) Z3_theory_get_ext_data(th); \ - cb = *(caml_named_value("apply_" #_cb_name)); \ - callback3(cb, user_data, _a, _b); \ - CAMLreturn0; \ - } \ - - -AST_BOOL_CALLBACK(new_assignment); -SET_CALLBACK(new_assignment); - -AST_CALLBACK(new_relevant); -SET_CALLBACK(new_relevant); - From b92bdaeebe9cedb3191d2c5e30abf95dcee72e82 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Sat, 24 Jan 2015 18:51:47 +0000 Subject: [PATCH 248/248] ML API readme fixes Signed-off-by: Christoph M. Wintersteiger --- examples/ml/README | 2 -- src/api/ml/README | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/ml/README b/examples/ml/README index b7aa187fa..562e9fe46 100644 --- a/examples/ml/README +++ b/examples/ml/README @@ -1,5 +1,3 @@ -### This is work-in-progress. - Small example using the Z3 ML bindings. To build the example execute make examples diff --git a/src/api/ml/README b/src/api/ml/README index f697e5ff4..ffdd3e709 100644 --- a/src/api/ml/README +++ b/src/api/ml/README @@ -1,6 +1,5 @@ -This directory is work in progress. - -We are currently working on a brand new ML API. +This is the new ML API introduced with Z3 4.4. For the legacy bindings, please +refer to previous releases of Z3. On Windows, there are no less than four different ports of OCaml. The Z3 build system assumes that either the win32 or the win64 port is installed. This means